Examples of Percent


Examples of barsuift.simLife.Percent

     * Test that the sun3D is observable : it notifies its observers when the color change
     */
    public void testObservable() {
        observerHelper.addObserver(sun3D);
        // force computation of angles in the sun, and so for color in sun3D
        mockSun.setZenithAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);

        assertEquals(1, observerHelper.nbUpdated());
        assertEquals(SunUpdateCode.color, observerHelper.getUpdateObjects().get(0));
    }
View Full Code Here

Examples of barsuift.simLife.Percent

        assertEquals(1, observerHelper.nbUpdated());
        assertEquals(SunUpdateCode.color, observerHelper.getUpdateObjects().get(0));
    }

    public void testUpdateLuminosity() {
        mockSun.setRiseAngle(new Percent(50));
        mockSun.setZenithAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);

        Color3f actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(1, 1, 1), actualSunColor);

        mockSun.setLuminosity(new Percent(40));
        sun3D.update(mockSun, SunUpdateCode.luminosity);
        actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(0.4f, 0.4f, 0.4f), actualSunColor);

        mockSun.setLuminosity(new Percent(70));
        sun3D.update(mockSun, SunUpdateCode.luminosity);
        actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(0.7f, 0.7f, 0.7f), actualSunColor);
    }
View Full Code Here

Examples of barsuift.simLife.Percent

    public void testUpdateColor() {
        Color3f actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(1f, (float) Math.sqrt(2) / 2, (float) Math.sqrt(2) / 2), actualSunColor);

        mockSun.setLuminosity(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.luminosity);
        actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(0.5f, (float) (0.5 * Math.sqrt(2) / 2), (float) (0.5 * Math.sqrt(2) / 2)),
                actualSunColor);

        mockSun.setLuminosity(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.luminosity);
        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(1f, 0f, 0f), actualSunColor);

        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(1f, (float) Math.sqrt(Math.sqrt(2) / 2), (float) Math.sqrt(Math.sqrt(2) / 2)),
                actualSunColor);

        mockSun.setZenithAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        actualSunColor = new Color3f();
        sunLight.getColor(actualSunColor);
        assertEquals(new Color3f(1f, 1f, 1f), actualSunColor);
    }
View Full Code Here

Examples of barsuift.simLife.Percent

    }

    public void testUpdateRiseAngle1() {
        // rise = Pi/4
        // zenith = Pi/4
        assertEquals(new Percent(25), mockSun.getRiseAngle());
        assertEquals(new Percent(50), mockSun.getZenithAngle());
        Vector3f actualDirection = new Vector3f();
        sunLight.getDirection(actualDirection);
        Vector3f expectedDirection = new Vector3f((float) Math.sqrt(2) / 2, -0.5f, -0.5f);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(1, 0, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(0, -(float) Math.sqrt(2) / 2, -(float) Math.sqrt(2) / 2);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        mockSun.setRiseAngle(new Percent(75));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(-(float) Math.sqrt(2) / 2, -0.5f, -0.5f);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        mockSun.setRiseAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(-1, 0, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);
View Full Code Here

Examples of barsuift.simLife.Percent

    /**
     * Test rise angle with zenith angle set to 0
     */
    public void testUpdateRiseAngle2() {
        mockSun.setZenithAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        // Pi/4
        assertEquals(new Percent(25), mockSun.getRiseAngle());
        Vector3f actualDirection = new Vector3f();
        sunLight.getDirection(actualDirection);
        Vector3f expectedDirection = new Vector3f((float) Math.sqrt(2) / 2, 0f, (float) -Math.sqrt(2) / 2);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // 0 Pi
        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(1, 0, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // Pi/2
        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(0, 0, -1);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // 3Pi/4
        mockSun.setRiseAngle(new Percent(75));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(-(float) Math.sqrt(2) / 2, 0, -(float) Math.sqrt(2) / 2);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // Pi
        mockSun.setRiseAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(-1, 0, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);
View Full Code Here

Examples of barsuift.simLife.Percent

    /**
     * Test rise angle with zenith angle set to 100% (Pi/2)
     */
    public void testUpdateRiseAngle3() {
        mockSun.setZenithAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        // Pi/4
        assertEquals(new Percent(25), mockSun.getRiseAngle());
        Vector3f actualDirection = new Vector3f();
        sunLight.getDirection(actualDirection);
        Vector3f expectedDirection = new Vector3f((float) Math.sqrt(2) / 2, -(float) Math.sqrt(2) / 2, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // 0 Pi
        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(1, 0, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // Pi/2
        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(0, -1, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // 3Pi/4
        mockSun.setRiseAngle(new Percent(75));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(-(float) Math.sqrt(2) / 2, -(float) Math.sqrt(2) / 2, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        // Pi
        mockSun.setRiseAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f(-1, 0, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);
View Full Code Here

Examples of barsuift.simLife.Percent

        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);
    }

    public void testUpdateZenithAngle() {
        assertEquals(new Percent(25), mockSun.getRiseAngle());
        assertEquals(new Percent(50), mockSun.getZenithAngle());
        Vector3f actualDirection = new Vector3f();
        sunLight.getDirection(actualDirection);
        Vector3f expectedDirection = new Vector3f((float) Math.sqrt(2) / 2, -0.5f, -0.5f);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        mockSun.setZenithAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f((float) Math.sqrt(2) / 2, 0f, (float) -Math.sqrt(2) / 2);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);

        mockSun.setZenithAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        sunLight.getDirection(actualDirection);
        expectedDirection = new Vector3f((float) Math.sqrt(2) / 2, -(float) Math.sqrt(2) / 2, 0);
        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);
View Full Code Here

Examples of barsuift.simLife.Percent

        expectedDirection.normalize();
        VectorTestHelper.assertVectorEquals(expectedDirection, actualDirection);
    }

    public void testGetWhiteFactor() {
        assertEquals(new Percent(25), mockSun.getRiseAngle());
        assertEquals(new Percent(50), mockSun.getZenithAngle());
        assertEquals((float) Math.sqrt(2) / 2, sun3D.getWhiteFactor().getValue().floatValue());

        mockSun.setZenithAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(25));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(75));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);

        mockSun.setZenithAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(25));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals((float) Math.sqrt(2) / 2, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals((float) Math.sqrt(Math.sqrt(2) / 2), sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(75));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals((float) Math.sqrt(2) / 2, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);


        mockSun.setZenithAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.zenithAngle);
        mockSun.setRiseAngle(new Percent(0));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(25));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals((float) Math.sqrt(Math.sqrt(2) / 2), sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(50));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(1f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(75));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals((float) Math.sqrt(Math.sqrt(2) / 2), sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
        mockSun.setRiseAngle(new Percent(100));
        sun3D.update(mockSun, SunUpdateCode.riseAngle);
        assertEquals(0f, sun3D.getWhiteFactor().getValue().floatValue(), 0.001f);
    }
View Full Code Here

Examples of barsuift.simLife.Percent

    @Override
    public void stateChanged(ChangeEvent e) {
        JSlider source = (JSlider) e.getSource();
        int zenithAngle = (int) source.getValue();
        sun.setZenithAngle(new Percent(zenithAngle));
    }
View Full Code Here

Examples of barsuift.simLife.Percent

    @Override
    public void stateChanged(ChangeEvent e) {
        JSlider source = (JSlider) e.getSource();
        int riseAngle = (int) source.getValue();
        sun.setRiseAngle(new Percent(riseAngle));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.