Exemplo n.º 1
0
        public static GeometryRenderer <Vertex> NewQuad(Shader shader)
        {
            Vertex[] quad = new Vertex[4]
            {
                // Texture coords - top is 0, bottom is 1
                new Vertex(new Vector3(-0.5f, -0.5f, 0.0f), new Vector2(0, 1), Color4.White),
                new Vertex(new Vector3(0.5f, -0.5f, 0.0f), new Vector2(1, 1), Color4.White),
                new Vertex(new Vector3(-0.5f, 0.5f, 0.0f), new Vector2(0, 0), Color4.White),
                new Vertex(new Vector3(0.5f, 0.5f, 0.0f), new Vector2(1, 0), Color4.White),
            };
            uint[] indices = new uint[6]
            {
                0, 1, 2, 2, 1, 3
            };
            var m  = new Mesh <Vertex>(quad);
            var g  = new Geometry <Vertex>(m, indices);
            var gr = new GeometryRenderer <Vertex>(g, shader);

            return(gr);
        }
Exemplo n.º 2
0
        void CreateScene(object sender, GameWindow.SceneCreatedEventArgs e)
        {
            world    = new World();
            colorMap = (int)world.WorldColor;

            scene = e.scene;
            scene.SceneUpdatedEvent += UpdateScene;

            ambientColor = Math2.ToVec3(Color4.Aquamarine) * 0.25f;

            eventHandler = new EventHandler(world, scene);
            var window = sender as GameWindow;

            if (window != null)
            {
                window.EventHandler = eventHandler;
            }
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.Space, RelaxTriangles));
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.D, TweakTriangles));
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.R, ResetSphere));
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.D1, DistortTriangles));
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.C, Recolor));
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.I, InitPlates));
            eventHandler.keyHandlers.Add(new KeyHandler(Keys.P, GrowPlates));


            Shader  quadShader   = new Shader(GameWindow.SHADER_PATH + "quadVertShader.glsl", GameWindow.SHADER_PATH + "4ChannelFragShader.glsl");
            Shader  shader       = new Shader(GameWindow.SHADER_PATH + "Vert3DColorUVShader.glsl", GameWindow.SHADER_PATH + "shadedFragShader.glsl");
            Shader  pointShader  = new Shader(GameWindow.SHADER_PATH + "pointVertShader.glsl", GameWindow.SHADER_PATH + "pointFragShader.glsl");
            Shader  lineShader   = new Shader(GameWindow.SHADER_PATH + "pointColorVertShader.glsl", GameWindow.SHADER_PATH + "pointFragShader.glsl");
            Shader  texShader2   = new Shader(GameWindow.SHADER_PATH + "Vert3DColorUVShader.glsl", GameWindow.SHADER_PATH + "texFragShader.glsl");
            Shader  borderShader = new Shader(GameWindow.SHADER_PATH + "Vert3DColorShader.glsl", GameWindow.SHADER_PATH + "pointFragShader.glsl");
            Texture cellTexture  = new Texture("Edge.png");
            Texture arrowTexture = new Texture("Arrow.png");

            var node = new Node
            {
                Position = new Vector3(0, 0, -3)
            };

            node.Model = Matrix4.CreateTranslation(node.Position);
            scene.Add(node);

            worldRenderGeometry = world.RegenerateMesh();

            worldRenderer = new GeometryRenderer <Vertex3DColorUV>(worldRenderGeometry as Geometry <Vertex3DColorUV>, shader);
            worldRenderer.renderer.AddUniform(new UniformProperty("lightPosition", lightPosition));
            worldRenderer.renderer.AddUniform(new UniformProperty("ambientColor", ambientColor));
            worldRenderer.renderer.AddTexture(cellTexture);
            worldRenderer.renderer.CullFaceFlag = true;
            node.Add(worldRenderer.renderer);

            borderGeometry = world.plates.GenerateBorderGeometry <Vertex3DColor>();
            borderRenderer = new GeometryRenderer <Vertex3DColor>(borderGeometry as Geometry <Vertex3DColor>, borderShader);
            borderRenderer.renderer.DepthTestFlag = true;
            borderRenderer.renderer.CullFaceFlag  = true;
            borderRenderer.renderer.CullFaceMode  = CullFaceMode.Back;
            node.Add(borderRenderer.renderer);

            worldVertsDebugRenderer = new GeometryRenderer <Vertex3DColor>(world.geometry as Geometry <Vertex3DColor>, pointShader);
            worldVertsDebugRenderer.renderer.AddUniform(new UniformProperty("color", new Vector4(0, 0.2f, 0.7f, 1)));
            worldVertsDebugRenderer.renderer.AddUniform(new UniformProperty("pointSize", 3f));
            worldVertsDebugRenderer.renderer.AddUniform(new UniformProperty("zCutoff", -2.0f));
            worldVertsDebugRenderer.renderer.Visible = false;
            node.Add(worldVertsDebugRenderer.renderer);

            Geometry <Vertex3D> centroidGeom = new Geometry <Vertex3D>(world.geometry.GenerateCentroidPointMesh())
            {
                PrimitiveType = PrimitiveType.Points
            };

            worldCentroidDebugRenderer = new GeometryRenderer <Vertex3D>(centroidGeom, pointShader);
            worldCentroidDebugRenderer.renderer.DepthTestFlag = false;
            worldCentroidDebugRenderer.renderer.CullFaceFlag  = false;
            worldCentroidDebugRenderer.renderer.AddUniform(new UniformProperty("color", new Vector4(0.5f, 0.5f, 0.5f, 1)));
            worldCentroidDebugRenderer.renderer.AddUniform(new UniformProperty("pointSize", 3f));
            worldCentroidDebugRenderer.renderer.AddUniform(new UniformProperty("zCutoff", -2.0f));
            worldCentroidDebugRenderer.renderer.Visible = false;
            node.Add(worldCentroidDebugRenderer.renderer);

            var spinGeom = world.plates.GenerateSpinDriftDebugGeom(true);

            worldPlateSpinDebugRenderer = new GeometryRenderer <Vertex3DColorUV>(spinGeom, texShader2);
            worldPlateSpinDebugRenderer.renderer.DepthTestFlag = false;
            worldPlateSpinDebugRenderer.renderer.CullFaceFlag  = false;
            worldPlateSpinDebugRenderer.renderer.BlendingFlag  = true;
            worldPlateSpinDebugRenderer.renderer.AddTexture(arrowTexture);
            worldPlateSpinDebugRenderer.renderer.AddUniform(new UniformProperty("color", new Vector4(1, 1, 1, 1.0f)));
            node.Add(worldPlateSpinDebugRenderer.renderer);

            var driftGeom = world.plates.GenerateSpinDriftDebugGeom(false);

            worldPlateDriftDebugRenderer = new GeometryRenderer <Vertex3DColorUV>(driftGeom, texShader2);
            worldPlateDriftDebugRenderer.renderer.DepthTestFlag = false;
            worldPlateDriftDebugRenderer.renderer.CullFaceFlag  = false;
            worldPlateDriftDebugRenderer.renderer.BlendingFlag  = true;
            worldPlateDriftDebugRenderer.renderer.AddTexture(arrowTexture);
            worldPlateDriftDebugRenderer.renderer.AddUniform(new UniformProperty("color", new Vector4(.75f, 0.75f, 0.0f, 1.0f)));
            node.Add(worldPlateDriftDebugRenderer.renderer);

            var equatorGeom     = GeometryFactory.GenerateCircle(Vector3.Zero, Vector3.UnitY, 1.001f, new Vector4(1.0f, 0, 0, 1.0f));
            var equatorRenderer = NewRenderer <Vertex3DColor>(equatorGeom, lineShader);

            equatorRenderer.AddUniform(new UniformProperty("zCutoff", -2.8f));
            node.Add(equatorRenderer);
        }