private void CreateObjects() { // Create our ground plane GeometryNode groundNode = new GeometryNode("Ground"); groundNode.Model = new Box(Vector3.One); // Make this ground plane collidable, so other collidable objects can collide // with this ground groundNode.Physics.Collidable = true; groundNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; groundNode.AddToPhysicsEngine = true; // Create a material for the ground Material groundMat = new Material(); groundMat.Diffuse = Color.LightGreen.ToVector4(); groundMat.Specular = Color.White.ToVector4(); groundMat.SpecularPower = 20; groundNode.Material = groundMat; // Create a parent transformation for both the ground and the sphere models TransformNode parentTransNode = new TransformNode(); parentTransNode.Translation = new Vector3(0, -10, -20); // Create a scale transformation for the ground to make it bigger TransformNode groundScaleNode = new TransformNode(); groundScaleNode.Scale = new Vector3(100, 1, 100); // Add this ground model to the scene scene.RootNode.AddChild(parentTransNode); parentTransNode.AddChild(groundScaleNode); groundScaleNode.AddChild(groundNode); // Add a rope-like object using ball and socket joint JointCreator.AddRope(scene, parentTransNode); // Add a door-like object using hinge joint JointCreator.AddDoubleSwingDoors(scene, parentTransNode); JointCreator.AddRollingBeats(scene, parentTransNode); // Add a race car car = VehicleCreator.AddRaceCar(scene, parentTransNode); // Create a camera that chases the car CreateChasingCamera((GeometryNode)car.Container); }
public static RaceCar AddRaceCar(Scene scene, TransformNode parentTrans) { TransformNode transNode = new TransformNode(); transNode.Translation = new Vector3(0, 10, 10); Material carMat = new Material(); carMat.Diffuse = Color.Pink.ToVector4(); carMat.Specular = Color.White.ToVector4(); carMat.SpecularPower = 10; GeometryNode carNode = new GeometryNode("Race Car"); carNode.Model = new Box(3, 1.0f, 2); carNode.Material = carMat; carNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; NewtonPhysics physicsEngine = (NewtonPhysics)scene.PhysicsEngine; RaceCar car = new RaceCar(carNode, physicsEngine); for (int i = 0; i < 4; i++) { car.Tires[i] = CreateTire((TireID)Enum.ToObject(typeof(TireID), i), car.TireTransformNode[i], carNode, scene.PhysicsEngine.Gravity); } car.Collidable = true; car.Interactable = true; carNode.Physics = car; carNode.Physics.NeverDeactivate = true; carNode.AddToPhysicsEngine = true; parentTrans.AddChild(transNode); transNode.AddChild(carNode); Newton.NewtonSetBodyLeaveWorldEvent(physicsEngine.NewtonWorld, car.LeaveWorldCallback); return(car); }
public static RaceCar AddRaceCar(Scene scene, TransformNode parentTrans) { TransformNode transNode = new TransformNode(); transNode.Translation = new Vector3(0, 10, 10); Material carMat = new Material(); carMat.Diffuse = Color.Pink.ToVector4(); carMat.Specular = Color.White.ToVector4(); carMat.SpecularPower = 10; GeometryNode carNode = new GeometryNode("Race Car"); carNode.Model = new Box(3, 1.0f, 2); carNode.Material = carMat; carNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; NewtonPhysics physicsEngine = (NewtonPhysics)scene.PhysicsEngine; RaceCar car = new RaceCar(carNode, physicsEngine); for (int i = 0; i < 4; i++) car.Tires[i] = CreateTire((TireID)Enum.ToObject(typeof(TireID), i), car.TireTransformNode[i], carNode, scene.PhysicsEngine.Gravity); car.Collidable = true; car.Interactable = true; carNode.Physics = car; carNode.Physics.NeverDeactivate = true; carNode.AddToPhysicsEngine = true; parentTrans.AddChild(transNode); transNode.AddChild(carNode); Newton.NewtonSetBodyLeaveWorldEvent(physicsEngine.NewtonWorld, car.LeaveWorldCallback); return car; }