Search in sources :

Example 1 with Vector2d

use of javax.vecmath.Vector2d in project narchy by automenta.

the class RaytracerFrame method changeScene.

/**
 * �ndert die Szene.
 *
 * @param sceneId ID der neuen Szene.
 */
public void changeScene(int sceneId) {
    Scene scene;
    switch(sceneId) {
        case // FlatShader
        0:
            final Sphere s = new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ColorShader(ColorEx.RED));
            scene = new EfficientScene() {

                final double start = System.currentTimeMillis();

                @Override
                public boolean update(double t) {
                    // add(s);
                    return false;
                }
            };
            scene.add(s);
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new ColorShader(ColorEx.GREEN)));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new ColorShader(ColorEx.BLUE)));
            scene.add(new InfinitePlane(new Vector3d(0.0, -1.0, 0.0), new Vector3d(0.0, 1.0, 0.0), new ColorShader(ColorEx.YELLOW)));
            // scene.add(new InfinitePlane(new Vector3d(0.0, -1.0, 0.0), new Vector3d(0.0, 1.0, 0.0), new WallShader(ColorEx.WHITE)));
            break;
        case // EyeLightShader
        1:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new EyeLightShader(new ColorShader(ColorEx.RED))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new EyeLightShader(new ColorShader(ColorEx.GREEN))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new EyeLightShader(new ColorShader(ColorEx.BLUE))));
            scene.add(new InfinitePlane(new Vector3d(0.0, -1.0, 0.0), new Vector3d(0.0, 1.0, 0.0), new EyeLightShader(new ColorShader(ColorEx.YELLOW))));
            break;
        case // FirstPhongShader
        2:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new InfinitePlane(new Vector3d(0.0, -1.0, 0.0), new Vector3d(0.0, 1.0, 0.0), new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            break;
        case // Dreiecke
        3:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            break;
        case // DirectionalLight
        4:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
            scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
            break;
        case // PointLight
        5:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
            scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(20.0f, 20.0f, 20.0f)));
            break;
        case // Shadow
        6:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
            scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
            scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(20.0f, 20.0f, 20.0f)));
            break;
        case // MirrorShader
        7:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new MirrorShader()));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
            scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
            scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
            scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(20.0f, 20.0f, 20.0f)));
            break;
        case // ReflectiveShader
        8:
            scene = new EfficientScene();
            scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ReflectiveShader(0.2f, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
            scene.add(new Sphere(new Vector3d(1.0, -1.0, -1.0), 2.2, new ReflectiveShader(0.2f, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.0f, 0.9f, 0.0f), new Vector3f(0.0f, 0.4f, 0.2f), new Vector3f(0.05f, 0.05f, 0.05f)))));
            scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new ReflectiveShader(0.2f, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
            scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new ReflectiveShader(0.2f, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
            scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new ReflectiveShader(0.2f, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
            scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
            scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
            scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(20.0f, 20.0f, 20.0f)));
            break;
        case // Diamant (FirstPhongShader)
        9:
            try {
                Transformation t = new Transformation();
                t.scale(0.9, 0.9, 0.9);
                t.move(1.0, 1.0, -3.0);
                OffObject off = new OffObject("off/dodecahedron.off", new ConcatShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.3f, 0.7f, 0.4f), new Vector3f(0.4f, 1.0f, 0.5f), new Vector3f(0.0f, 0.0f, 0.0f)), 0.7f, new RefractionShader(RefractionShader.INDEX_DIAMOND, new ColorEx(0.85f, 0.99f, 0.85f))));
                off.transform(t);
                scene = new EfficientScene();
                scene.add(off);
                scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ReflectionShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
                scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new ReflectionShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new ReflectionShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        case // Diamant
        10:
            try {
                Transformation t = new Transformation();
                t.scale(0.9, 0.9, 0.9);
                t.move(1.0, 1.0, -3.0);
                OffObject off = new OffObject("off/dodecahedron.off", new ConcatShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.3f, 0.7f, 0.4f), new Vector3f(0.4f, 1.0f, 0.5f), new Vector3f(0.0f, 0.0f, 0.0f)), 0.7f, new RefractionShader(RefractionShader.INDEX_DIAMOND, new ColorEx(0.85f, 0.99f, 0.85f))));
                off.transform(t);
                scene = new EfficientScene();
                scene.add(off);
                scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new ReflectionShader(new PhongShader(new TextureShader("texture/earth.jpg"), new Vector3f(0.2f, 0.2f, 0.2f), new Vector3f(0.6f, 0.6f, 0.6f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.0f, 0.0f, 0.0f)))));
                scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
                scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
                scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(20.0f, 20.0f, 20.0f)));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        case // Venus
        11:
            try {
                Transformation t = new Transformation();
                t.rotate(90.0, 0.0, 1.0, 0.0);
                t.scale(2.0, 2.0, 2.0);
                t.move(2.0, 2.0, -2.0);
                OffObject off = new OffObject("off/venus.off", new ConcatShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.3f, 0.7f, 0.4f), new Vector3f(0.4f, 1.0f, 0.5f), new Vector3f(0.0f, 0.0f, 0.0f)), 0.7f, new RefractionShader(RefractionShader.INDEX_DIAMOND, new ColorEx(0.85f, 0.99f, 0.85f))));
                off.transform(t);
                scene = new EfficientScene();
                scene.add(off);
                scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.5f, 0.2f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
                scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.05f, 0.05f, 0.05f)))));
                scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
                scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
                scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(20.0f, 20.0f, 20.0f)));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        case // Hase
        12:
            try {
                Transformation t = new Transformation();
                String texture = "texture/synth11.jpg";
                Triangle t1 = new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new ReflectionShader(new PhongShader(new TextureShader(texture), new Vector3f(0.1f, 0.1f, 0.1f), new Vector3f(0.5f, 0.5f, 0.5f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.0f, 0.0f, 0.0f))));
                Triangle t2 = new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new ReflectionShader(new PhongShader(new TextureShader(texture), new Vector3f(0.1f, 0.1f, 0.1f), new Vector3f(0.5f, 0.5f, 0.5f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.0f, 0.0f, 0.0f))));
                t1.setTextureCoords(new Vector2d(1.0, 1.0), new Vector2d(1.0, 0.0), new Vector2d(0.0, 0.0));
                t2.setTextureCoords(new Vector2d(0.0, 0.0), new Vector2d(0.0, 1.0), new Vector2d(1.0, 1.0));
                t.reset();
                t.scale(1.5, 1.5, 0.0);
                t1.transformTexture(t);
                t2.transformTexture(t);
                PlyObject ply = new PlyObject("ply/bunny.ply", new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.1f, 0.0f), new Vector3f(0.0f, 0.4f, 0.0f), new Vector3f(0.0f, 0.7f, 0.2f), new Vector3f(0.0f, 0.0f, 0.0f)));
                ply.normalize();
                t.reset();
                t.scale(3.0, 3.0, 3.0);
                t.move(2.0, 1.3, -3.5);
                ply.transform(t);
                scene = new EfficientScene();
                scene.add(new Sphere(new Vector3d(), 30.0, new TextureShader("texture/univ02.jpg")));
                scene.add(ply);
                scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ConcatShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.1f, 0.0f, 0.0f), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(1.0f, 0.4f, 0.2f), new Vector3f(0.0f, 0.0f, 0.0f)), 0.8f, new RefractionShader(RefractionShader.INDEX_GLASS, new ColorEx(0.95f, 0.85f, 0.85f)))));
                scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.05f, 0.05f, 0.05f))));
                scene.add(t1);
                scene.add(t2);
                scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
                // scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
                scene.add(new PointLight(new Vector3d(-7.0, 4.0, -7.0), new ColorEx(10.0f, 10.0f, 10.0f)));
                scene.add(new PointLight(new Vector3d(-7.0, 4.0, 7.0), new ColorEx(6.0f, 6.0f, 6.0f)));
                scene.add(new PointLight(new Vector3d(7.0, 4.0, 7.0), new ColorEx(8.0f, 8.0f, 8.0f)));
                scene.add(new PointLight(new Vector3d(7.0, 4.0, -7.0), new ColorEx(11.0f, 11.0f, 11.0f)));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        case // Soft-Shadows
        13:
            try {
                Transformation t = new Transformation();
                t.scale(0.9, 0.9, 0.9);
                t.move(1.0, 1.0, -3.0);
                // OffObject off = new OffObject("off/cube.off", new ConcatShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(1.0f, 1.0f, 1.0f)), 1.0f, new RefractionShader(RefractionShader.INDEX_DIAMOND, new ColorEx(ColorEx.WHITE))));
                OffObject off = new OffObject("off/cube.off", new ConcatShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.3f, 0.7f, 0.4f), new Vector3f(0.4f, 0.4f, 0.4f), new Vector3f(0.0f, 0.0f, 0.0f), 5.0F), 0.0f, new RefractionShader(RefractionShader.INDEX_DIAMOND, new ColorEx(ColorEx.WHITE))));
                // OffObject off = new OffObject("off/dodecahedron.off", new ConcatShader(new FirstPhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.3f, 0.0f), new Vector3f(0.3f, 0.7f, 0.4f), new Vector3f(0.4f, 1.0f, 0.5f), new Vector3f(0.0f, 0.0f, 0.0f)), 0.7f, new RefractionShader(RefractionShader.SOL_DIAMOND, new ColorEx(0.85f, 0.99f, 0.85f))));
                off.transform(t);
                scene = new EfficientScene();
                // scene.add(off);
                scene.add(new Sphere(new Vector3d(-2.0, 1.7, 0.0), 2.0, new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.5f, 0.0f, 0.0f), new Vector3f(0.7f, 0.0f, 0.0f), new Vector3f(0.7f, 0.7f, 0.7f), new Vector3f(0.05f, 0.05f, 0.05f), 10.0F))));
                scene.add(new Sphere(new Vector3d(3.0, 0.8, 2.0), 2.0, new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.3f), new Vector3f(0.0f, 0.0f, 0.5f), new Vector3f(0.7f, 0.7f, 0.7f), new Vector3f(0.05f, 0.05f, 0.05f), 10.0F)));
                scene.add(new Triangle(new Vector3d(-7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, -7.0), new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.4f, 0.4f, 0.4f), new Vector3f(0.05f, 0.05f, 0.05f), 5.0F))));
                scene.add(new Triangle(new Vector3d(7.0, -1.0, -7.0), new Vector3d(7.0, -1.0, 7.0), new Vector3d(-7.0, -1.0, 7.0), new ReflectionShader(new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.9f, 0.9f, 0.0f), new Vector3f(0.4f, 0.4f, 0.4f), new Vector3f(0.05f, 0.05f, 0.05f), 5.0F))));
                scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
                // scene.add(new DirectionalLight(new Vector3d(1.0,-1.0,0.0), new ColorEx(0.1f, 0.1f, 0.1f)));
                // scene.add(new PointLight(new Vector3d(-7.0,4.0,-7.0), new ColorEx(10.0f, 10.0f, 10.0f)));
                // scene.add(new AreaLight(new Vector3d(0.0,8.0,0.0),new Vector3d(1.5,0.0,0.0),new Vector3d(0.0,0.0,1.5), new ColorEx(0.8f, 0.8f, 0.8f)));
                // scene.add(new Sphere(new Vector3d(1.0,2.0,0.0), 0.25 , new LightSourceShader(new ColorEx(1.0f, 1.0f, 1.0f))));
                // scene.add(new AreaLight(new Vector3d(1.0, 3.0, 0.0), new Vector3d(0.5, 0.0, 0.0), new Vector3d(0.0, 0.0, 3.0), new ColorEx(12.0f, 12.0f, 12.0f)));
                scene.add(new SphereLight(new Vector3d(1.0, 3.0, 0.0), 0.7, new ColorEx(12.0f, 12.0f, 12.0f)));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        case // Lichtbrechungs-Test
        14:
            try {
                scene = new EfficientScene();
                Shader wallRed = new PhongShader(new ColorShader(ColorEx.RED), new Vector3f(0.5f, 0.5f, 0.5f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.7f, 0.7f, 0.7f));
                Shader wallBlue = new PhongShader(new ColorShader(ColorEx.BLUE), new Vector3f(0.5f, 0.5f, 0.5f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.7f, 0.7f, 0.7f));
                Shader wallGray = new PhongShader(new ColorShader(ColorEx.GRAY), new Vector3f(0.5f, 0.5f, 0.5f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.7f, 0.7f, 0.7f));
                // Linke Wand:
                scene.add(new Triangle(new Vector3d(-1.0, -1.0, 1.0), new Vector3d(-1.0, -1.0, -1.0), new Vector3d(-1.0, 1.0, 1.0), wallRed));
                scene.add(new Triangle(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(-1.0, -1.0, -1.0), new Vector3d(-1.0, 1.0, -1.0), wallRed));
                // Rechte Wand:
                scene.add(new Triangle(new Vector3d(1.0, -1.0, -1.0), new Vector3d(1.0, -1.0, 1.0), new Vector3d(1.0, 1.0, 1.0), wallBlue));
                scene.add(new Triangle(new Vector3d(1.0, 1.0, 1.0), new Vector3d(1.0, 1.0, -1.0), new Vector3d(1.0, -1.0, -1.0), wallBlue));
                // Hintere Wand:
                scene.add(new Triangle(new Vector3d(-1.0, -1.0, -1.0), new Vector3d(1.0, -1.0, -1.0), new Vector3d(-1.0, 1.0, -1.0), wallGray));
                scene.add(new Triangle(new Vector3d(-1.0, 1.0, -1.0), new Vector3d(1.0, -1.0, -1.0), new Vector3d(1.0, 1.0, -1.0), wallGray));
                // Obere Wand:
                scene.add(new Triangle(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(-1.0, 1.0, -1.0), new Vector3d(1.0, 1.0, 1.0), wallGray));
                scene.add(new Triangle(new Vector3d(1.0, 1.0, 1.0), new Vector3d(-1.0, 1.0, -1.0), new Vector3d(1.0, 1.0, -1.0), wallGray));
                // Untere Wand:
                scene.add(new Triangle(new Vector3d(-1.0, -1.0, 1.0), new Vector3d(1.0, -1.0, 1.0), new Vector3d(-1.0, -1.0, -1.0), wallGray));
                scene.add(new Triangle(new Vector3d(-1.0, -1.0, -1.0), new Vector3d(1.0, -1.0, 1.0), new Vector3d(1.0, -1.0, -1.0), wallGray));
                // Licht:
                scene.add(new AreaLight(new Vector3d(0.0, 0.999999, 0.0), new Vector3d(0.2, 0.0, 0.0), new Vector3d(0.0, 0.0, 0.2), new ColorEx(3.0f, 3.0f, 3.0f)));
                // Kugel mit Spiegelung:
                Sphere rs = new Sphere(new Vector3d(-0.5, -0.65, -0.5), 0.35, new MirrorShader());
                rs.setNormalEffect(new RoughNormalEffect(0.03f));
                scene.add(rs);
                // Kugel mit Lichtbrechung:
                rs = new Sphere(new Vector3d(0.5, -0.65, 0.0), 0.35, new RefractionShader(RefractionShader.INDEX_GLASS, new ColorEx(0.9f, 0.9f, 0.9f)));
                rs.setNormalEffect(new RoughNormalEffect(0.1f));
                scene.add(rs);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        case // Bowling-Szene
        15:
            scene = new BowlingScene();
            break;
        case // Bowling-Kugel
        16:
            try {
                Transformation t = new Transformation();
                t.scale(3.0, 3.0, 3.0);
                t.rotate(190.0, 1.0, 0.0, 0.0);
                PlyObject ply = new PlyObject("ply/bowl.ply", new PhongShader(new ColorShader(ColorEx.WHITE), new Vector3f(0.1f, 0.1f, 0.1f), new Vector3f(0.4f, 0.4f, 0.4f), new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(0.0f, 0.0f, 0.0f)), true, new RoughNormalEffect(0.2f));
                ply.center();
                ply.transform(t);
                scene = new EfficientScene();
                scene.add(ply);
                scene.setAmbientLight(new ColorEx(0.2f, 0.2f, 0.2f));
                // scene.add(new DirectionalLight(new Vector3d(1.0, -1.0, 0.0), new ColorEx(0.8f, 0.8f, 0.8f)));
                scene.add(new PointLight(new Vector3d(-7.0, 1.0, -7.0), new ColorEx(5.0f, 5.0f, 5.0f)));
                scene.add(new PointLight(new Vector3d(-7.0, 1.0, 7.0), new ColorEx(3.0f, 3.0f, 3.0f)));
                scene.add(new PointLight(new Vector3d(7.0, 1.0, 7.0), new ColorEx(4.0f, 4.0f, 4.0f)));
                scene.add(new PointLight(new Vector3d(7.0, 1.0, -7.0), new ColorEx(5.5f, 5.5f, 5.5f)));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            break;
        default:
            throw new IllegalArgumentException();
    }
    // Szene setzen:
    setCameraScene(this.camera, scene);
    this.sceneId = sceneId;
}
Also used : SphereLight(raytracer.lights.SphereLight) AreaLight(raytracer.lights.AreaLight) Vector2d(javax.vecmath.Vector2d) DirectionalLight(raytracer.lights.DirectionalLight) RoughNormalEffect(raytracer.effects.RoughNormalEffect) InvalidFormatException(raytracer.exception.InvalidFormatException) Vector3d(javax.vecmath.Vector3d) Vector3f(javax.vecmath.Vector3f) PointLight(raytracer.lights.PointLight)

Example 2 with Vector2d

use of javax.vecmath.Vector2d in project narchy by automenta.

the class Triangle method getTextureCoords.

@Override
public Vector2d getTextureCoords(Vector3d point) {
    Vector3d ab = new Vector3d();
    ab.sub(b, a);
    Vector3d ac = new Vector3d();
    ac.sub(c, a);
    // Linearfaktorzerlegung des Punktes:
    double cTy = ac.dot(normalPlaneC);
    double pTy = normalPlaneC.dot(point) - normalPlaneC.dot(a);
    double lambda1 = ((ab.dot(point) - ab.dot(a)) * cTy - ac.dot(ab) * pTy) / (ab.dot(ab) * cTy);
    double lambda2 = pTy / cTy;
    // Texturkoodinate berechnen und zur�ckgeben:
    Vector2d coords = new Vector2d(textureA);
    coords.scaleAdd(lambda1, textureAB, coords);
    coords.scaleAdd(lambda2, textureAC, coords);
    return coords;
}
Also used : Vector2d(javax.vecmath.Vector2d) Vector3d(javax.vecmath.Vector3d)

Example 3 with Vector2d

use of javax.vecmath.Vector2d in project narchy by automenta.

the class PlyObject method loadPlyFile.

/**
 * Liest die Informationen aus einer PLY-Datei und erzeugt daraus
 * Dreiecke.
 *
 * @param fileName Dateiname der OFF-Datei.
 * @param smoothNormals Gibt an, ob die Normalen interpoliert werden
 *        sollen, falls die PLY-Datei Informationen zu den Normalenvektoren
 *        enth�lt.
 *
 * @throws java.io.IOException
 * @throws raytracer.exception.InvalidFormatException
 */
private void loadPlyFile(String fileName, boolean smoothNormals) throws InvalidFormatException {
    // Datei �ffnen:
    Scanner scanner = new Scanner(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(fileName)));
    scanner.useLocale(Locale.US);
    Tokenizer tokenizer = new Tokenizer(scanner);
    Vector<Element> elements = new Vector<Element>();
    try {
        // PLY-Kennung pr�fen:
        if (tokenizer.token() != Tokenizer.TOKEN_PLY)
            throw new InvalidFormatException();
        tokenizer.next();
        // Format-Kennung pr�fen:
        if (tokenizer.token() != Tokenizer.TOKEN_FORMAT)
            throw new InvalidFormatException();
        tokenizer.next();
        if (tokenizer.token() != Tokenizer.TOKEN_ASCII)
            throw new InvalidFormatException();
        tokenizer.next();
        if (tokenizer.token() != Tokenizer.TOKEN_NUMBER)
            throw new InvalidFormatException();
        if (tokenizer.doubleValue() != 1.0)
            throw new InvalidFormatException();
        tokenizer.next();
        // Header-Informationen der PLY-Datei auslesen:
        Property property = null;
        Element currentElement = null;
        loop: do {
            switch(tokenizer.token()) {
                case Tokenizer.TOKEN_COMMENT:
                    tokenizer.endLine();
                    tokenizer.next();
                    continue;
                case Tokenizer.TOKEN_ELEMENT:
                    tokenizer.next();
                    // Neues Element erstellen:
                    currentElement = new Element();
                    elements.add(currentElement);
                    // Eigenschaften des Elements lesen:
                    if (tokenizer.token() != Tokenizer.TOKEN_NAME)
                        throw new InvalidFormatException();
                    currentElement.name = tokenizer.stringValue();
                    tokenizer.next();
                    if (tokenizer.token() != Tokenizer.TOKEN_NUMBER)
                        throw new InvalidFormatException();
                    currentElement.count = tokenizer.intValue();
                    tokenizer.next();
                    break;
                case Tokenizer.TOKEN_PROPERTY:
                    if (currentElement == null)
                        throw new InvalidFormatException();
                    tokenizer.next();
                    // Neue Eigenschaft erstellen:
                    property = new Property();
                    currentElement.properties.add(property);
                    // Eigenschaften der Eigenschaft lesen:
                    if (!Tokenizer.isType(tokenizer.token()))
                        throw new InvalidFormatException();
                    property.type = tokenizer.token();
                    tokenizer.next();
                    if (Tokenizer.isTypeList(property.type)) {
                        if (!Tokenizer.isTypeInt(tokenizer.token()))
                            throw new InvalidFormatException();
                        property.listCountType = tokenizer.token();
                        tokenizer.next();
                        if (!Tokenizer.isType(tokenizer.token()))
                            throw new InvalidFormatException();
                        property.listDataType = tokenizer.token();
                        tokenizer.next();
                    }
                    if (tokenizer.token() != Tokenizer.TOKEN_NAME)
                        throw new InvalidFormatException();
                    property.name = tokenizer.stringValue();
                    tokenizer.next();
                    break;
                case Tokenizer.TOKEN_END_HEADER:
                    break loop;
                default:
                    throw new InvalidFormatException();
            }
        } while (true);
        Vector<Vector3d> vertices = new Vector<Vector3d>();
        Vector<Vector3d> normals = new Vector<Vector3d>();
        Vector<Vector2d> textures = new Vector<Vector2d>();
        Vector<Integer> faces = new Vector<Integer>();
        // Daten auslesen und verarbeiten:
        for (Element element : elements) {
            currentElement = element;
            switch(currentElement.name) {
                case "vertex":
                    readVertices(scanner, currentElement, vertices, normals, textures);
                    break;
                case "face":
                    readFaces(scanner, currentElement, faces);
                    break;
                default:
                    readElement(scanner, currentElement);
                    break;
            }
        }
        // Fl�chen der PLY-Datei triangulieren und Dreiecke daraus erzeugen:
        Iterator<Integer> itFaces = faces.iterator();
        while (itFaces.hasNext()) {
            int count = -itFaces.next();
            if (count < 3)
                throw new InvalidFormatException();
            // Ersten beiden Punkte ermitteln:
            int firstId = itFaces.next();
            int previousId = itFaces.next();
            // Aus den restlichen Punkten der Fl�che Dreiecke erzeugen:
            count -= 2;
            do {
                int currentId = itFaces.next();
                try {
                    Triangle triangle = new Triangle(vertices.get(firstId), vertices.get(previousId), vertices.get(currentId), shader);
                    triangle.setNormalEffect(normalEffect);
                    // Normalenvektoren setzen:
                    if (smoothNormals) {
                        Vector3d normalA = normals.get(firstId);
                        Vector3d normalB = normals.get(previousId);
                        Vector3d normalC = normals.get(currentId);
                        if ((normalA != null) && (normalB != null) && (normalC != null))
                            triangle.setNormals(normalA, normalB, normalC);
                    }
                    // Texturkoordinaten setzen:
                    Vector2d textureA = textures.get(firstId);
                    Vector2d textureB = textures.get(previousId);
                    Vector2d textureC = textures.get(currentId);
                    if ((textureA != null) && (textureB != null) && (textureC != null))
                        triangle.setTextureCoords(textureA, textureB, textureC);
                    shapes.add(triangle);
                } catch (LinearlyDependentException e) {
                // Falls bei den Koordinaten lineare Abh�ngigkeit besteht,
                // verwerfe deises Dreieck.
                }
                previousId = currentId;
            } while (--count > 0);
        }
    } finally {
        scanner.close();
    }
}
Also used : LinearlyDependentException(raytracer.exception.LinearlyDependentException) InvalidFormatException(raytracer.exception.InvalidFormatException) Vector2d(javax.vecmath.Vector2d) BufferedInputStream(java.io.BufferedInputStream) Vector3d(javax.vecmath.Vector3d)

Example 4 with Vector2d

use of javax.vecmath.Vector2d in project narchy by automenta.

the class Sphere method getTextureCoords.

@Override
public Vector2d getTextureCoords(Vector3d point) {
    // Normale am Punkt berechnen:
    Vector3d normal = new Vector3d();
    normal.sub(point, center);
    Vector3d temp = new Vector3d();
    temp.cross(normal, textureUp);
    double alpha = Math.acos((double) (float) (-normal.dot(textureUp) / (normal.length() * textureUp.length())));
    normal.cross(textureUp, normal);
    normal.cross(normal, textureUp);
    temp.cross(textureStart, textureUp);
    double beta = Math.acos((double) (float) (normal.dot(textureStart) / (normal.length() * textureStart.length())));
    if (Math.signum(temp.dot(normal)) < 0.0) {
        beta = 2.0 * Math.PI - beta;
    }
    double y = alpha / Math.PI;
    double x = (2.0 * Math.PI - beta) / (2.0 * Math.PI);
    return new Vector2d(x, y);
}
Also used : Vector2d(javax.vecmath.Vector2d) Vector3d(javax.vecmath.Vector3d)

Example 5 with Vector2d

use of javax.vecmath.Vector2d in project Solar by Martacus.

the class StructAncientMenhir method generateOverworld.

@Override
public void generateOverworld(World world, Random rand, int x, int z) {
    int randomX = x + rand.nextInt(16);
    int randomZ = z + rand.nextInt(16);
    int chunkX = x / 16;
    int chunkZ = z / 16;
    chunksNotSpawned++;
    if (chunksNotSpawned < 80) {
        return;
    }
    chunksNotSpawned = 0;
    this.lastChunkGenerated = new Vector2d(chunkX, chunkZ);
    for (int y = 255; y > 0; y--) {
        Block block = world.getBlockState(new BlockPos(randomX, y, randomZ)).getBlock();
        if (block != Blocks.AIR && block != Blocks.WATER && block != Blocks.FLOWING_WATER && block != Blocks.LEAVES && block != Blocks.LEAVES2 && block != Blocks.LAVA && block != Blocks.TALLGRASS) {
            world.setBlockState(new BlockPos(randomX, y + 1, randomZ), ModBlocks.ANCIENT_MENHIR.getStateFromMeta(0));
            world.setBlockState(new BlockPos(randomX, y + 2, randomZ), ModBlocks.ANCIENT_MENHIR.getStateFromMeta(1));
            world.setBlockState(new BlockPos(randomX, y + 3, randomZ), ModBlocks.ANCIENT_MENHIR.getStateFromMeta(1));
            world.setBlockState(new BlockPos(randomX, y + 4, randomZ), ModBlocks.ANCIENT_MENHIR.getStateFromMeta(1));
            world.setBlockState(new BlockPos(randomX, y + 5, randomZ), ModBlocks.ANCIENT_MENHIR.getStateFromMeta(2));
            return;
        }
    }
}
Also used : Vector2d(javax.vecmath.Vector2d) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Vector2d (javax.vecmath.Vector2d)29 Point2d (javax.vecmath.Point2d)15 Vector3d (javax.vecmath.Vector3d)12 ArrayList (java.util.ArrayList)9 Point3d (javax.vecmath.Point3d)8 List (java.util.List)7 Line (org.twak.utils.Line)7 SuperLine (org.twak.viewTrace.SuperLine)6 Line3d (org.twak.utils.geom.Line3d)5 LinearForm3D (org.twak.utils.geom.LinearForm3D)5 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Mesh (com.jme3.scene.Mesh)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ColorRGBA (com.jme3.math.ColorRGBA)3 Node (com.jme3.scene.Node)3 VertexBuffer (com.jme3.scene.VertexBuffer)3 Graphics2D (java.awt.Graphics2D)3 Collection (java.util.Collection)3