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); }
private void CreateCubeRoomScene() { baseLightPosition = new Vector3(0, 0, -0.4f); ObjReader reader = new ObjReader(); TriangleMesh roomMesh = new TriangleMesh(); reader.Read("meshes/inverse_cube.obj", roomMesh); TriangleMeshNode roomNode = new TriangleMeshNode(roomMesh); roomNode.SetColor(Color.Khaki); roomNode.ShowNormals = false; ScaleNode roomScale = new ScaleNode(new Vector3(1, 1, 1)); roomScale.AddChild(roomNode); GetRoot().AddChild(roomScale); int numberOfObjects = 5; for (int i = 0; i < numberOfObjects; i++) { INode objectNode = CreateObject(); GetRoot().AddChild(objectNode); } GetRoot().LightPosition = baseLightPosition; GetRoot().Animated = false; }
public Helicopter(Vector3 scale, Vector3 offset) { ScaleNode scaleNode = new ScaleNode(scale); scaleNode.AddChild(CreateCabin(new Vector3(0, 0, 0))); scaleNode.AddChild(CreateBase(new Vector3(0, -0.19f, 0))); scaleNode.AddChild(CreateBack(new Vector3(0, 0.1f, 0.35f))); scaleNode.AddChild(CreateRotor(new Vector3(0, 0.2f, 0))); scaleNode.AddChild(CreateBackRotor(new Vector3(-0.05f, 0.1f, 0.65f))); TranslationNode offsetNode = new TranslationNode(offset); offsetNode.AddChild(scaleNode); //TriangleMesh dummyCubeMesh = new TriangleMesh(); //TriangleMeshFactory.CreateCube(dummyCubeMesh, 1.0f); //TriangleMeshNode dummyCubeMeshNode = new TriangleMeshNode(dummyCubeMesh); //dummyCubeMeshNode.SetColor(Color.Aqua); //ScaleNode dummyCubeScale = new ScaleNode(new Vector3(0.2f, 0.2f, 0.2f)); //dummyCubeScale.AddChild(dummyCubeMeshNode); //offsetNode.AddChild(dummyCubeScale); AddChild(offsetNode); }
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); }
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); }
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); }
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); }