Esempio n. 1
0
        private void CreateHelicopterForestScene()
        {
            baseLightPosition = new Vector3(0.3f, 1, 0.3f);

            // Tree scene
            for (int i = 0; i < numberOfTrees; i++)
            {
                if (numberOfTrees == 1)
                {
                    // Debugging: single tree
                    GetRoot().AddChild(CreateTree(new Vector3(0, 0, 0)));
                }
                else
                {
                    GetRoot().AddChild(CreateTree(new Vector3((float)(random.NextDouble() * 2 - 1), 0, (float)(random.NextDouble() * 2 - 1))));
                }
            }
            GetRoot().AddChild(CreatePlane());

            // Helicopter
            INode        helicopter   = new Helicopter(new Vector3(0.3f, 0.3f, 0.3f), new Vector3(0.7f, 0.4f, 0));
            RotationNode heliRotation = new RotationNode(0, new Vector3(0, 1, 0));

            heliRotation.Animated       = true;
            heliRotation.AnimationSpeed = 0.005f;
            heliRotation.AddChild(helicopter);
            GetRoot().AddChild(heliRotation);

            GetRoot().LightPosition = baseLightPosition;
            GetRoot().Animated      = false;
        }
Esempio n. 2
0
        private INode CreateRotor(Vector3 offset)
        {
            var          bar1      = CreateBar(new Vector3(1, 0.03f, 0.03f), Color.DarkGray);
            var          bar2      = CreateBar(new Vector3(0.03f, 0.03f, 1), Color.DarkGray);
            RotationNode rotorNode = new RotationNode();

            rotorNode.Animated = true;
            rotorNode.AddChild(bar1);
            rotorNode.AddChild(bar2);
            TranslationNode offsetNode = new TranslationNode(offset);

            offsetNode.AddChild(rotorNode);
            return(offsetNode);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private INode CreateBackRotor(Vector3 offset)
        {
            INode     rotor     = CreateRotor(new Vector3(0, 0, 0));
            ScaleNode scaleNode = new ScaleNode(new Vector3(0.5f, 0.5f, 0.5f));

            scaleNode.AddChild(rotor);
            RotationNode rotationNode = new RotationNode(90.0f, new Vector3(0, 0, 1));

            rotationNode.Animated = false;
            rotationNode.AddChild(scaleNode);
            TranslationNode offsetNode = new TranslationNode(offset);

            offsetNode.AddChild(rotationNode);
            return(offsetNode);
        }