private void CreateObject() { SynchronizedGeometryNode sphereNode = new SynchronizedGeometryNode("Sphere"); sphereNode.Model = new Sphere(3, 20, 20); sphereNode.Model.ShowBoundingBox = true; Material sphereMaterial = new Material(); sphereMaterial.Diffuse = Color.Red.ToVector4(); sphereMaterial.Ambient = Color.Blue.ToVector4(); sphereMaterial.Emissive = Color.Green.ToVector4(); sphereNode.Material = sphereMaterial; TransformNode transNode = new TransformNode(); SynchronizedGeometryNode cylinderNode = new SynchronizedGeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(3, 3, 8, 20); cylinderNode.Model.ShowBoundingBox = true; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Cyan.ToVector4(); cylinderMat.Specular = Color.Yellow.ToVector4(); cylinderMat.SpecularPower = 5; cylinderNode.Material = cylinderMat; TransformNode parentTrans = new TransformNode(); parentTrans.Translation = new Vector3(0, -2, -10); cylinderNode.Physics.Collidable = true; cylinderNode.Physics.Interactable = true; cylinderNode.AddToPhysicsEngine = true; cylinderNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Cylinder; cylinderNode.Physics.Mass = 200; sphereNode.Physics.Collidable = true; sphereNode.Physics.Interactable = true; sphereNode.AddToPhysicsEngine = true; sphereNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Sphere; sphereNode.Physics.Mass = 0; transNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), -MathHelper.PiOver2); transNode.Translation = new Vector3(0, 12, 0); scene.RootNode.AddChild(parentTrans); parentTrans.AddChild(sphereNode); parentTrans.AddChild(transNode); transNode.AddChild(cylinderNode); shootMat = new Material(); shootMat.Diffuse = Color.Pink.ToVector4(); shootMat.Specular = Color.Yellow.ToVector4(); shootMat.SpecularPower = 10; boxModel = new Box(1); }
/// <summary> /// Shoot a box from the clicked mouse location /// </summary> /// <param name="near"></param> /// <param name="far"></param> private void ShootBox(Vector3 near, Vector3 far) { Vector3 camPos = scene.CameraNode.Camera.Translation; SynchronizedGeometryNode shootBox = new SynchronizedGeometryNode("ShooterBox" + shooterID++); shootBox.Model = boxModel; shootBox.Material = shootMat; shootBox.Physics.Interactable = true; shootBox.Physics.Collidable = true; shootBox.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; shootBox.Physics.Mass = 20f; shootBox.AddToPhysicsEngine = true; // Calculate the direction to shoot the box based on the near and far point Vector3 linVel = far - near; linVel.Normalize(); // Multiply the direction with the velocity of 20 linVel *= 60f; // Assign the initial velocity to this shooting box shootBox.Physics.InitialLinearVelocity = linVel; TransformNode shooterTrans = new TransformNode(); shooterTrans.Translation = near; scene.RootNode.AddChild(shooterTrans); shooterTrans.AddChild(shootBox); }
private void CreateObjects() { // Loads a textured model of the Sun. ModelLoader loader = new ModelLoader(); Model mySunModel = (Model)loader.Load("", "sun1"); // Loaded Sun model to the geometry node mySun mySun = new GeometryNode("Sun"); mySun.Model = mySunModel; mySun.Material.Diffuse = new Vector4(mySun.Material.Diffuse.X, mySun.Material.Diffuse.Y, mySun.Material.Diffuse.Z, 0.7f); // Use its internal materials ((Model)mySun.Model).UseInternalMaterials = true; ((Model)mySun.Model).ContainsTransparency = true; //Transforme node for the Sun node. TransformNode mySunTransNode = new TransformNode(); mySunTransNode.Translation = new Vector3(0, 0, 0); mySunTransNode.Scale = new Vector3(0.01f, 0.01f, 0.01f); //mySunTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90)); mySunRotationParentNode = new TransformNode(); mySunRotationParentNode.Translation = Vector3.Zero; mySun.Physics.Pickable = true; mySun.AddToPhysicsEngine = true; // Loads a textured model of the Earth. Model myEarthModel = (Model)loader.Load("", "planet2"); // Loaded Sun model to the geometry node myEarth myEarth = new GeometryNode("Earth"); myEarth.Model = myEarthModel; // Use its internal materials ((Model)myEarth.Model).UseInternalMaterials = true; //Transforme node for the Earth node. TransformNode myEarthTransNode = new TransformNode(); myEarthTransNode.Translation = new Vector3(0, 0, 2); myEarthTransNode.Scale = new Vector3(0.003f, 0.003f, 0.003f); myEarthRotationParentNode1 = new TransformNode(); myEarthRotationParentNode1.Translation = Vector3.Zero; myEarthRotationParentNode2 = new TransformNode(); myEarthRotationParentNode2.Translation = Vector3.Zero; earthControlPanel = new TransformNode(); earthControlPanel.Translation = Vector3.Zero; earthControlPanel1 = new TransformNode(); earthControlPanel1.Translation = Vector3.Zero; earthControlPanel2 = new TransformNode(); earthControlPanel2.Translation = Vector3.Zero; myEarth.Physics.Pickable = true; myEarth.AddToPhysicsEngine = true; // Loads a textured model of the Moon. Model myMoonModel = (Model)loader.Load("", "moon1"); // Loaded Sun model to the geometry node myMoon myMoon = new GeometryNode("Moon"); myMoon.Model = myMoonModel; // Use its internal materials ((Model)myMoon.Model).UseInternalMaterials = true; //Transforme node for the Moon node. TransformNode myMoonTransNode = new TransformNode(); myMoonTransNode.Translation = new Vector3(0, 0, (float)0.5); myMoonTransNode.Scale = new Vector3(0.0008f, 0.0008f, 0.0008f); myMoonRotationParentNode1 = new TransformNode(); myMoonRotationParentNode1.Translation = Vector3.Zero; myMoonRotationParentNode2 = new TransformNode(); myMoonRotationParentNode2.Translation = Vector3.Zero; myMoonRotationParentNode3 = new TransformNode(); myMoonRotationParentNode3.Translation = Vector3.Zero; myMoonRotationParentNode4 = new TransformNode(); myMoonRotationParentNode4.Translation = Vector3.Zero; moonControlPanel = new TransformNode(); moonControlPanel.Translation = Vector3.Zero; moonControlPanel1 = new TransformNode(); moonControlPanel1.Translation = Vector3.Zero; moonControlPanel2 = new TransformNode(); moonControlPanel2.Translation = Vector3.Zero; myMoon.Physics.Pickable = true; myMoon.AddToPhysicsEngine = true; // Loads a textured model of the Mercury. Model myMercuryModel = (Model)loader.Load("", "planet4"); // Loaded Sun model to the geometry node myMercury myMercury = new GeometryNode("Mercury"); myMercury.Model = myMercuryModel; // Use its internal materials ((Model)myMercury.Model).UseInternalMaterials = true; //Transforme node for the Mercury node. TransformNode myMercuryTransNode = new TransformNode(); myMercuryTransNode.Translation = new Vector3(0, 0, 1); myMercuryTransNode.Scale = new Vector3(0.001f, 0.001f, 0.001f); myMercuryRotationParentNode1 = new TransformNode(); myMercuryRotationParentNode1.Translation = Vector3.Zero; myMercuryRotationParentNode2 = new TransformNode(); myMercuryRotationParentNode2.Translation = Vector3.Zero; mercuryControlPanel = new TransformNode(); mercuryControlPanel.Translation = Vector3.Zero; mercuryControlPanel1 = new TransformNode(); mercuryControlPanel1.Translation = Vector3.Zero; mercuryControlPanel2 = new TransformNode(); mercuryControlPanel2.Translation = Vector3.Zero; myMercury.Physics.Pickable = true; myMercury.AddToPhysicsEngine = true; // Loads a textured model of the Mars. Model myMarsModel = (Model)loader.Load("", "planet3"); // Loaded Sun model to the geometry node myMars myMars = new GeometryNode("Mars"); myMars.Model = myMarsModel; // Use its internal materials ((Model)myMars.Model).UseInternalMaterials = true; //Transforme node for the Mars node. TransformNode myMarsTransNode = new TransformNode(); myMarsTransNode.Translation = new Vector3(0, 0, 3); myMarsTransNode.Scale = new Vector3(0.0015f, 0.0015f, 0.0015f); myMarsRotationParentNode1 = new TransformNode(); myMarsRotationParentNode1.Translation = Vector3.Zero; myMarsRotationParentNode2 = new TransformNode(); myMarsRotationParentNode2.Translation = Vector3.Zero; marsControlPanel = new TransformNode(); marsControlPanel.Translation = Vector3.Zero; marsControlPanel1 = new TransformNode(); marsControlPanel1.Translation = Vector3.Zero; marsControlPanel2 = new TransformNode(); marsControlPanel2.Translation = Vector3.Zero; myMars.Physics.Pickable = true; myMars.AddToPhysicsEngine = true; // Loads a textured model of the myJupiter. Model myJupiterModel = (Model)loader.Load("", "planet1"); // Loaded Sun model to the geometry node myJupiter myJupiter = new GeometryNode("Jupiter"); myJupiter.Model = myJupiterModel; // Use its internal materials ((Model)myJupiter.Model).UseInternalMaterials = true; //Transforme node for the Jupiter box node. TransformNode myJupiterTransNode = new TransformNode(); myJupiterTransNode.Translation = new Vector3(0, 0, 4); myJupiterTransNode.Scale = new Vector3(0.004f, 0.004f, 0.004f); myJupiterRotationParentNode1 = new TransformNode(); myJupiterRotationParentNode1.Translation = Vector3.Zero; myJupiterRotationParentNode2 = new TransformNode(); myJupiterRotationParentNode2.Translation = Vector3.Zero; jupiterControlPanel = new TransformNode(); jupiterControlPanel.Translation = Vector3.Zero; jupiterControlPanel1 = new TransformNode(); jupiterControlPanel1.Translation = Vector3.Zero; jupiterControlPanel2 = new TransformNode(); jupiterControlPanel2.Translation = Vector3.Zero; myJupiter.Physics.Pickable = true; myJupiter.AddToPhysicsEngine = true; //Space Debris Fields //Create a geometry node with a model of cylinder. cylinderNode = new SynchronizedGeometryNode("Dubris-Cylinder"); cylinderNode.Model = new Cylinder(1.5f, 1.5f, 4f, 20); //Initializing materials for cylinder. Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Indigo.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 4; //Set cylinder materials cylinderNode.Material = cylinderMat; //Transforme node for the cylinder node. TransformNode cylinderTransNode = new TransformNode(); cylinderTransNode.Scale = new Vector3(0.03f, 0.03f, 0.03f); cylinderTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(60)); cylinderTransNode.Translation = new Vector3(0, (float) 0.6, 3); cylinderRotationParentNode = new TransformNode(); cylinderRotationParentNode.Translation = Vector3.Zero; cylinderRotationParentNode = new TransformNode(); cylinderControlPanel = new TransformNode(); cylinderControlPanel.Translation = Vector3.Zero; cylinderControlPanel1 = new TransformNode(); cylinderControlPanel1.Translation = Vector3.Zero; cylinderControlPanel2 = new TransformNode(); cylinderControlPanel2.Translation = Vector3.Zero; cylinderRotateSunNode = new TransformNode(); cylinderRotateSunNode.Translation = Vector3.Zero; cylinderNode.Physics.Pickable = true; cylinderNode.AddToPhysicsEngine = true; // Create a geometry node with a model of cone. coneNode = new SynchronizedGeometryNode("Dubris-Cone"); coneNode.Model = new Cylinder(1.5f, 0, 4f, 20); //Initializing materials for cone. Material coneMat = new Material(); coneMat.Diffuse = Color.Lime.ToVector4(); coneMat.Specular = Color.White.ToVector4(); coneMat.SpecularPower = 5; coneNode.Material = coneMat; //Transforme node for the cone node. TransformNode coneTransNode = new TransformNode(); coneTransNode.Scale = new Vector3(0.03f, 0.03f, 0.03f); coneTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 1, 0), MathHelper.ToRadians(45)); coneTransNode.Translation = new Vector3(0, (float)0.4, (float)3.2); coneRotationParentNode = new TransformNode(); coneRotationParentNode.Translation = Vector3.Zero; coneControlPanel = new TransformNode(); coneControlPanel.Translation = Vector3.Zero; coneControlPanel1 = new TransformNode(); coneControlPanel1.Translation = Vector3.Zero; coneControlPanel2 = new TransformNode(); coneControlPanel2.Translation = Vector3.Zero; coneRotateSunNode = new TransformNode(); coneRotateSunNode.Translation = Vector3.Zero; coneNode.Physics.Pickable = true; coneNode.AddToPhysicsEngine = true; // Create a geometry node with a model of torus. torusNode = new SynchronizedGeometryNode("Dubris-Torus"); torusNode.Model = new Torus(0.7f, 1.5f, 30, 30); //Initializing materials for torus. Material torusMat = new Material(); torusMat.Diffuse = Color.Magenta.ToVector4(); torusMat.Specular = Color.White.ToVector4(); torusMat.SpecularPower = 10; torusNode.Material = torusMat; //Transforme node for the torus node. TransformNode torusTransNode = new TransformNode(); torusTransNode.Scale = new Vector3(0.03f, 0.03f, 0.03f); torusTransNode.Translation = new Vector3(0, (float)0.6, (float)3.4); torusTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.ToRadians(60)); torusRotationParentNode = new TransformNode(); torusRotationParentNode.Translation = Vector3.Zero; torusControlPanel = new TransformNode(); torusControlPanel.Translation = Vector3.Zero; torusControlPanel1 = new TransformNode(); torusControlPanel1.Translation = Vector3.Zero; torusControlPanel2 = new TransformNode(); torusControlPanel2.Translation = Vector3.Zero; torusRotateSunNode = new TransformNode(); torusRotateSunNode.Translation = Vector3.Zero; torusNode.Physics.Pickable = true; torusNode.AddToPhysicsEngine = true; // Create a geometry node with a model of box boxNode = new SynchronizedGeometryNode("Dubris-Box"); boxNode.Model = new Box(1, 4, 4); //Initiallizing materials for box. Material boxMat = new Material(); boxMat.Diffuse = Color.Crimson.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 5; boxNode.Material = boxMat; //Transforme node for the box node. TransformNode boxTransNode = new TransformNode(); boxTransNode.Scale = new Vector3(0.03f, 0.03f, 0.03f); boxTransNode.Translation = new Vector3(0, (float)0.45, (float)3.3); boxTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.ToRadians(30)); boxRotationParentNode = new TransformNode(); boxRotationParentNode.Translation = Vector3.Zero; boxControlPanel = new TransformNode(); boxControlPanel.Translation = Vector3.Zero; boxControlPanel1 = new TransformNode(); boxControlPanel1.Translation = Vector3.Zero; boxControlPanel2 = new TransformNode(); boxControlPanel2.Translation = Vector3.Zero; boxRotateSunNode = new TransformNode(); boxRotateSunNode.Translation = Vector3.Zero; boxNode.Physics.Pickable = true; boxNode.AddToPhysicsEngine = true; //Add the Sun node to the scene graph scene.RootNode.AddChild(mySunRotationParentNode); mySunRotationParentNode.AddChild(mySunTransNode); mySunTransNode.AddChild(mySun); //Add the Earth node to the scene graph scene.RootNode.AddChild(myEarthRotationParentNode1); myEarthRotationParentNode1.AddChild(myEarthTransNode); myEarthTransNode.AddChild(myEarthRotationParentNode2); myEarthRotationParentNode2.AddChild(earthControlPanel); earthControlPanel.AddChild(earthControlPanel1); earthControlPanel1.AddChild(earthControlPanel2); earthControlPanel2.AddChild(myEarth); //Add the Mercury to the scene graph scene.RootNode.AddChild(myMercuryRotationParentNode1); myMercuryRotationParentNode1.AddChild(myMercuryTransNode); myMercuryTransNode.AddChild(myMercuryRotationParentNode2); myMercuryRotationParentNode2.AddChild(mercuryControlPanel); mercuryControlPanel.AddChild(mercuryControlPanel1); mercuryControlPanel1.AddChild(mercuryControlPanel2); mercuryControlPanel2.AddChild(myMercury); //Add the Mars to the scene graph scene.RootNode.AddChild(myMarsRotationParentNode1); myMarsRotationParentNode1.AddChild(myMarsTransNode); myMarsTransNode.AddChild(myMarsRotationParentNode2); myMarsRotationParentNode2.AddChild(marsControlPanel); marsControlPanel.AddChild(marsControlPanel1); marsControlPanel1.AddChild(marsControlPanel2); marsControlPanel2.AddChild(myMars); //Add the Jupiter node to the scene graph scene.RootNode.AddChild(myJupiterRotationParentNode1); myJupiterRotationParentNode1.AddChild(myJupiterTransNode); myJupiterTransNode.AddChild(myJupiterRotationParentNode2); myJupiterRotationParentNode2.AddChild(jupiterControlPanel); jupiterControlPanel.AddChild(jupiterControlPanel1); jupiterControlPanel1.AddChild(jupiterControlPanel2); jupiterControlPanel2.AddChild(myJupiter); //Add the Moon node to the scene graph scene.RootNode.AddChild(myMoonRotationParentNode1); myMoonRotationParentNode1.AddChild(myMoonRotationParentNode2); myMoonRotationParentNode2.AddChild(myMoonRotationParentNode3); myMoonRotationParentNode3.AddChild(myMoonTransNode); myMoonTransNode.AddChild(myMoonRotationParentNode4); myMoonRotationParentNode4.AddChild(moonControlPanel); moonControlPanel.AddChild(moonControlPanel1); moonControlPanel1.AddChild(moonControlPanel2); moonControlPanel2.AddChild(myMoon); //Add the cylinder node to the scene graph scene.RootNode.AddChild(cylinderRotationParentNode); cylinderRotationParentNode.AddChild(cylinderTransNode); cylinderTransNode.AddChild(cylinderControlPanel); cylinderControlPanel.AddChild(cylinderControlPanel1); cylinderControlPanel1.AddChild(cylinderControlPanel2); cylinderControlPanel2.AddChild(cylinderRotateSunNode); cylinderRotateSunNode.AddChild(cylinderNode); //Add the cone node to the scene graph scene.RootNode.AddChild(coneRotationParentNode); coneRotationParentNode.AddChild(coneTransNode); coneTransNode.AddChild(coneControlPanel); coneControlPanel.AddChild(coneControlPanel1); coneControlPanel1.AddChild(coneControlPanel2); coneControlPanel2.AddChild(coneRotateSunNode); coneRotateSunNode.AddChild(coneNode); //Add the torus node to the scene graph scene.RootNode.AddChild(torusRotationParentNode); torusRotationParentNode.AddChild(torusTransNode); torusTransNode.AddChild(torusControlPanel); torusControlPanel.AddChild(torusControlPanel1); torusControlPanel1.AddChild(torusControlPanel2); torusControlPanel2.AddChild(torusRotateSunNode); torusRotateSunNode.AddChild(torusNode); //Add the box node to the scene graph scene.RootNode.AddChild(boxRotationParentNode); boxRotationParentNode.AddChild(boxTransNode); boxTransNode.AddChild(boxControlPanel); boxControlPanel.AddChild(boxControlPanel1); boxControlPanel1.AddChild(boxControlPanel2); boxControlPanel2.AddChild(boxRotateSunNode); boxRotateSunNode.AddChild(boxNode); }