Exemplo n.º 1
0
        private void CreateSimpleScene()
        {
            // Plane
            TriangleMesh planeMesh = new TriangleMesh();

            TriangleMeshFactory.CreateSquare(planeMesh, 2);
            TriangleMeshNode planeMeshNode = new TriangleMeshNode(planeMesh);

            planeMeshNode.SetColor(Color.Green);
            GetRoot().AddChild(planeMeshNode);

            // Sphere
            TriangleMesh mesh = new TriangleMesh();

            TriangleMeshFactory.CreateSphere(mesh, 0.25f, 10);
            TriangleMeshNode meshNode = new TriangleMeshNode(mesh);

            meshNode.SetColor(Color.Red);
            TranslationNode translationNode =
                new TranslationNode(new Vector3(0.5f, 0.5f, 0.5f));

            translationNode.AddChild(meshNode);
            GetRoot().AddChild(translationNode);

            GetRoot().LightPosition = new Vector3(0.25f, 1, 0.25f);
            GetRoot().Animated      = false;
        }
Exemplo n.º 2
0
        public INode CreateTree(Vector3 position)
        {
            TriangleMesh sphereMesh = new TriangleMesh();

            TriangleMeshFactory.CreateSphere(sphereMesh, 1.0f, sphereResolution);
            TriangleMeshNode sphereNode = new TriangleMeshNode(sphereMesh);

            sphereNode.ShowNormals = false;
            sphereNode.SetColor(Color.DarkGreen);
            ScaleNode sphereScale = new ScaleNode(new Vector3(treeSize / 1.5f, treeSize / 1.5f, treeSize / 1.5f));

            sphereScale.AddChild(sphereNode);
            TranslationNode sphereTranslation = new TranslationNode(new Vector3(0, 1.5f * treeSize, 0));

            sphereTranslation.AddChild(sphereScale);

            TriangleMesh cubeMesh = new TriangleMesh();

            TriangleMeshFactory.CreateCube(cubeMesh, 1.0f);
            TriangleMeshNode cubeNode = new TriangleMeshNode(cubeMesh);

            cubeNode.SetColor(Color.Brown);
            ScaleNode cubeScale = new ScaleNode(new Vector3(treeSize / 3.0f, treeSize, treeSize / 3.0f));

            cubeScale.AddChild(cubeNode);
            TranslationNode cubeTranslation = new TranslationNode(new Vector3(0, treeSize / 2.0f, 0));

            cubeTranslation.AddChild(cubeScale);

            TranslationNode treeNode = new TranslationNode(position);

            treeNode.AddChild(sphereTranslation);
            treeNode.AddChild(cubeTranslation);
            return(treeNode);
        }
Exemplo n.º 3
0
        private INode CreateBar(Vector3 orientation, Color color)
        {
            ScaleNode    bar1Scale = new ScaleNode(orientation);
            TriangleMesh bar1Mesh  = new TriangleMesh();

            TriangleMeshFactory.CreateCube(bar1Mesh, 1.0f);
            TriangleMeshNode bar1Node = new TriangleMeshNode(bar1Mesh);

            bar1Node.SetColor(color);
            bar1Scale.AddChild(bar1Node);
            return(bar1Scale);
        }
Exemplo n.º 4
0
        public INode CreatePlane()
        {
            TriangleMesh mesh = new TriangleMesh();

            TriangleMeshFactory.CreateCube(mesh, 1.0f);
            TriangleMeshNode node = new TriangleMeshNode(mesh);

            node.SetColor(Color.DarkGreen);
            ScaleNode scaleNode = new ScaleNode(new Vector3(3, 0.02f, 3));

            scaleNode.AddChild(node);
            return(scaleNode);
        }
Exemplo n.º 5
0
        private ITriangleMesh CreateMiddle(ITriangleMesh mesh, List <Hexagon> borderHexagons, float sideLength)
        {
            ITriangleMesh bottomMesh = new TriangleMesh();

            foreach (Hexagon hex in borderHexagons)
            {
                ITriangleMesh hexMesh = hex.GenerateMesh();
                TriangleMeshFactory.Flip(hexMesh);
                TriangleMeshFactory.Unite(bottomMesh, hexMesh);
            }
            TriangleMeshFactory.Translate(bottomMesh, new Vector3(0, 0, -sideLength));
            return(bottomMesh);
        }
Exemplo n.º 6
0
        private INode CreateObject()
        {
            InnerNode objectNode = new InnerNode();

            TriangleMesh mesh        = new TriangleMesh();
            double       randomValue = random.NextDouble();

            if (randomValue < 1 / 3.0)
            {
                TriangleMeshFactory.CreateSphere(mesh, 0.25f, 10);
            }
            else if (randomValue < 2 / 3.0)
            {
                TriangleMeshFactory.CreateCube(mesh, 0.25f);
            }
            else
            {
                ObjReader reader = new ObjReader();
                reader.Read("meshes/cow.obj", mesh);
            }

            TriangleMeshNode meshNode = new TriangleMeshNode(mesh);

            meshNode.SetColor(CreateColor());
            ScaleNode scaleNode = new ScaleNode(new Vector3(0.4f, 0.4f, 0.4f));

            scaleNode.AddChild(meshNode);
            objectNode.AddChild(scaleNode);

            float   posMin = -0.4f;
            Vector3 t      = new Vector3((float)(random.NextDouble() * posMin * 2 - posMin),
                                         (float)(random.NextDouble() * posMin * 2 - posMin),
                                         (float)(random.NextDouble() * posMin * 2 - posMin));
            TranslationNode translationNode = new TranslationNode(t);

            translationNode.AddChild(objectNode);

            Vector3 axis = new Vector3((float)(random.NextDouble()) + 0.2f,
                                       (float)(random.NextDouble()) + 0.2f,
                                       (float)(random.NextDouble()) + 0.2f).Normalized();
            RotationNode rotationNode = new RotationNode(0, axis);

            rotationNode.Animated       = true;
            rotationNode.AnimationSpeed = 0.01f;
            rotationNode.AddChild(translationNode);

            Console.WriteLine("Created object: " + t);

            return(rotationNode);
        }
Exemplo n.º 7
0
        public ITriangleMesh GenerateIslandMesh()
        {
            HexagonField field = new HexagonField();

            field.GenerateField();

            ITriangleMesh mesh = new TriangleMesh();

            // Top
            ITriangleMesh topMesh = CreateTopSurface(field.GetAllHexagons());

            TriangleMeshFactory.Unite(mesh, topMesh);

            // Grass
            float grassBorderHeight = field.SideLength * 0.1f;

            Vector2[]     grassBoundaryTexCoords = { new Vector2(0.1f, 0.1f), new Vector2(0.1f, 0.2f), new Vector2(0.2f, 0.1f), new Vector2(0.2f, 0.2f) };
            ITriangleMesh grassBoundary          = CreateBoundary(mesh, field.SideLength, grassBorderHeight, grassBorderHeight, new Vector3(0, 0, 0), grassBoundaryTexCoords);

            TriangleMeshFactory.Unite(mesh, grassBoundary);

            // Middle-bottom
            ITriangleMesh middleMesh = CreateMiddle(mesh, field.GetBorderHexagons(), field.SideLength);

            TriangleMeshFactory.Unite(mesh, middleMesh);

            ITriangleMesh bottomMesh = CreateTopSurface(field.GetNonBorderHexagons());

            // Mud
            float mudHeight       = 2 * field.SideLength;
            float mudBorderHeight = field.SideLength * 0.3f;

            Vector2[]     mudBoundaryTexCoords = { new Vector2(0.7f, 0.1f), new Vector2(0.7f, 0.2f), new Vector2(0.8f, 0.1f), new Vector2(0.8f, 0.2f) };
            ITriangleMesh mudBoundary          = CreateBoundary(bottomMesh, mudHeight, 0, mudBorderHeight, new Vector3(0, 0, 0), mudBoundaryTexCoords);

            TriangleMeshFactory.Translate(mudBoundary, new Vector3(0, 0, -field.SideLength));
            TriangleMeshFactory.Unite(mesh, mudBoundary);

            // Bottom
            TriangleMeshFactory.Flip(bottomMesh);
            TriangleMeshFactory.Translate(bottomMesh, new Vector3(0, 0, -(mudHeight + field.SideLength)));
            TriangleMeshFactory.Unite(mesh, bottomMesh);

            mesh = TriangleMeshFactory.Snap(mesh, 1e-5f);

            mesh.ComputeTriangleNormals();
            mesh.SetTexture(new Texture("textures/island.png"));
            return(mesh);
        }
Exemplo n.º 8
0
        /**
         * Create the mesh for the top.
         * */
        private ITriangleMesh CreateTopSurface(List <Hexagon> hexagons)
        {
            ITriangleMesh mesh = new TriangleMesh();

            foreach (Hexagon hex in hexagons)
            {
                if (!hex.ConsistencyCheck())
                {
                    Console.WriteLine("Inconsistency detected!");
                }
                ITriangleMesh hexMesh = hex.GenerateMesh();
                TriangleMeshFactory.Unite(mesh, hexMesh);
            }
            mesh = TriangleMeshFactory.Snap(mesh, 1e-5f);
            return(mesh);
        }
Exemplo n.º 9
0
        // Base constructor: Timer timeout between two TimerTick events and shader mode (PHONG, TEXTURE, NO_LIGHTING)
        public ShadowScene() : base(100, Shader.ShaderMode.PHONG, RenderMode.SHADOW_VOLUME)
        {
            //CreateCubeRoomScene();
            //CreateTriangleMeshScene();
            CreateHelicopterForestScene();
            //CreateSimpleScene();

            //Light
            TriangleMesh lightMesh = new TriangleMesh();

            TriangleMeshFactory.CreateSphere(lightMesh, 0.02f, 10);
            TriangleMeshNode lightMeshNode = new TriangleMeshNode(lightMesh);

            lightMeshNode.SetColor(Color.Yellow);
            lightMeshNode.CastsShadow = false;
            lightNode.AddChild(lightMeshNode);
            lightNode.Translation = GetRoot().LightPosition;
            GetRoot().AddChild(lightNode);
        }
Exemplo n.º 10
0
        private INode CreateCabin(Vector3 offset)
        {
            TriangleMesh mesh = new TriangleMesh();

            TriangleMeshFactory.CreateSphere(mesh, 0.2f, 20);
            TriangleMeshNode node = new TriangleMeshNode(mesh);

            TriangleMesh windowMesh = new TriangleMesh();

            TriangleMeshFactory.CreateSphere(windowMesh, 0.17f, 20);
            TriangleMeshNode windowNode = new TriangleMeshNode(windowMesh);

            windowNode.SetColor(Color.LightBlue);
            TranslationNode windowTranslation = new TranslationNode(new Vector3(0, 0.01f, -0.05f));

            windowTranslation.AddChild(windowNode);

            TranslationNode cabin = new TranslationNode(offset);

            cabin.AddChild(node);
            cabin.AddChild(windowTranslation);
            return(cabin);
        }