/// <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); }
// A static player used mainly as an obstable to // bounce the ball back. Typically used in the practice // mode. public WallPlayer(Level level, string name) : base(level) { Node = new SynchronizedGeometryNode(name); Node.Model = new Box(Tunnel.Width, WallThickness, Tunnel.Height); Node.Material.Ambient = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); Node.Material.Diffuse = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); Node.Material.Specular = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); Node.Material.SpecularPower = 100.0f; // TODO Add physics for the wall. }
// A teammate or opponent controlled by someone on the // other side of the network. // Data to update its paddle should be retrieved from // the game server. public RemotePlayer(Level level) : base(level) { // Blue... Node = new SynchronizedGeometryNode(); Node.Model = new Box(30, 30, 30); Node.Material.Ambient = new Vector4(0.0f, 0.0f, 1.0f, 1.0f); Node.Material.Diffuse = new Vector4(0.0f, 0.0f, 1.0f, 1.0f); Node.Material.Specular = new Vector4(0.0f, 0.0f, 1.0f, 1.0f); Node.Material.SpecularPower = 100.0f; }
// This is the player conntrolled by the camera. // It should be able to update its paddle according to // the ground node of the scene. public MainPlayer(Level level, string name) : base(level) { // Green... Node = new SynchronizedGeometryNode(name); Node.Model = new Box(30, 30, 30); Node.Material.Ambient = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); Node.Material.Diffuse = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); Node.Material.Specular = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); Node.Material.SpecularPower = 100.0f; // TODO Add physics for the paddle. }
public Ball(Level level, string name) { _level = level; // TODO Set its node (model and transformation). Node = new SynchronizedGeometryNode(name); Node.Model = new Sphere(5, 32, 32); Node.Material.Ambient = new Vector4(0.5f, 0.5f, 0.5f, 1.0f); Node.Material.Diffuse = new Vector4(0.5f, 0.5f, 0.5f, 1.0f); Node.Material.Specular = new Vector4(0.5f, 0.5f, 0.5f, 1.0f); Node.Material.SpecularPower = 100.0f; // TODO Add physics for the ball. }
public Tunnel(Level level, string name) { _level = level; // TODO Set its node (model and transformation). Node = new SynchronizedGeometryNode(name); Node.Model = new Box(Width, Length, Height); Node.Material.Ambient = new Vector4(1.0f, 1.0f, 1.0f, 0.6f); Node.Material.Diffuse = new Vector4(1.0f, 1.0f, 1.0f, 0.6f); Node.Material.Specular = new Vector4(1.0f, 1.0f, 1.0f, 0.6f); Node.Material.SpecularPower = 100.0f; // TODO Add physics for the tunnel. Node.Physics.Collidable = true; Node.Physics.Interactable = true; Node.AddToPhysicsEngine = true; Node.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; Node.Physics.Mass = 10; }
private void CreateObject() { SynchronizedGeometryNode wall = new SynchronizedGeometryNode("wall"); wall.Model = new Box(WALL_WIDTH, WALL_HEIGHT, WALL_DEPTH); wall.Model.ShowBoundingBox = true; Material wallMaterial = new Material(); wallMaterial.Diffuse = Color.Gray.ToVector4(); wallMaterial.Ambient = Color.Blue.ToVector4(); wallMaterial.Emissive = Color.Green.ToVector4(); wall.Material = wallMaterial; TransformNode wallTrans = new TransformNode(); wallTrans.Translation = new Vector3(0, 0, -20); wall.Physics.Collidable = true; wall.Physics.Interactable = true; wall.AddToPhysicsEngine = true; wall.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; wall.Physics.Mass = 0; TransformNode groundMarkerNode = new TransformNode(); scene.RootNode.AddChild(groundMarkerNode); groundMarkerNode.AddChild(wallTrans); wallTrans.AddChild(wall); ///////////////////////////////////////////////////////////////////////// ball = new SynchronizedGeometryNode("ball"); ball.Model = new Sphere(SPHERE_RADIUS, 20, 20); ball.Model.ShowBoundingBox = true; Material ballMaterial = new Material(); ballMaterial.Diffuse = Color.Yellow.ToVector4(); //ballMaterial.Ambient = Color.Maroon.ToVector4(); //ballMaterial.Emissive = Color.LightCoral.ToVector4(); ball.Material = ballMaterial; TransformNode ballTrans = new TransformNode(); ballTrans.Translation = new Vector3(0, 0, 200); //ball.Physics = new PhysicsObject(ball); ball.Physics.Collidable = true; ball.Physics.Interactable = true; ball.Physics.AngularDamping = Vector3.Zero; ball.Physics.LinearDamping = 0f; ball.Physics.Shape = GoblinXNA.Physics.ShapeType.Sphere; ball.Physics.Mass = 10; ball.AddToPhysicsEngine = true; ballTrans.AddChild(ball); groundMarkerNode.AddChild(ballTrans); //////////////////////////////////////////////////////////////////////////// paddleNode = new SynchronizedGeometryNode("paddle"); paddleNode.Model = new Box(PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_DEPTH); paddleNode.Model.ShowBoundingBox = true; Material paddleMaterial = new Material(); paddleMaterial.Diffuse = Color.Orange.ToVector4(); paddleMaterial.Specular = Color.White.ToVector4(); paddleMaterial.SpecularPower = 10; paddleNode.Material = paddleMaterial; paddleNode.Physics.Collidable = true; paddleNode.Physics.Interactable = true; paddleNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; paddleNode.Physics.Mass = 10; paddleNode.AddToPhysicsEngine = true; groundMarkerNode.AddChild(paddleNode); }
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); }
private void CreateObjects() { // Create a marker node to track a ground marker array. #if USE_PATTERN_MARKER if (useSingleMarker) { groundMarkerNode = new MarkerNode(scene.MarkerTracker, "patt.hiro", 16, 16, markerSize, 0.7f); } else { groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitGroundArray.xml", NyARToolkitTracker.ComputationMethod.Average); } #else groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitIDGroundArray.xml", NyARToolkitTracker.ComputationMethod.Average); #endif scene.RootNode.AddChild(groundMarkerNode); //toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitIDToolbar1.xml", // NyARToolkitTracker.ComputationMethod.Average); //scene.RootNode.AddChild(toolbarMarkerNode); SynchronizedGeometryNode wall = new SynchronizedGeometryNode("wall"); wall.Model = new Box(WALL_WIDTH, WALL_HEIGHT, WALL_DEPTH); wall.Model.ShowBoundingBox = true; Material wallMaterial = new Material(); wallMaterial.Diffuse = Color.Gray.ToVector4(); wallMaterial.Ambient = Color.Blue.ToVector4(); wallMaterial.Emissive = Color.Green.ToVector4(); wall.Material = wallMaterial; TransformNode wallTrans = new TransformNode(); wallTrans.Translation = new Vector3(0, 0, -20); wall.Physics.Collidable = true; wall.Physics.Interactable = true; wall.AddToPhysicsEngine = true; wall.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; wall.Physics.Mass = 0; //scene.RootNode.AddChild(wall); groundMarkerNode.AddChild(wallTrans); wallTrans.AddChild(wall); ///////////////////////////////////////////////////// SynchronizedGeometryNode ball = new SynchronizedGeometryNode("ball"); ball.Model = new Sphere(SPHERE_RADIUS, 20, 20); ball.Model.ShowBoundingBox = true; Material ballMaterial = new Material(); ballMaterial.Diffuse = Color.Yellow.ToVector4(); //ballMaterial.Ambient = Color.Maroon.ToVector4(); //ballMaterial.Emissive = Color.LightCoral.ToVector4(); ball.Material = ballMaterial; TransformNode ballTrans = new TransformNode(); ballTrans.Translation = new Vector3(0, 0, 200); //ball.Physics = new PhysicsObject(ball); ball.Physics.Collidable = true; ball.Physics.Interactable = true; ball.Physics.AngularDamping = Vector3.Zero; ball.Physics.LinearDamping = 0f; ball.Physics.Shape = GoblinXNA.Physics.ShapeType.Sphere; ball.Physics.Mass = 10; ball.AddToPhysicsEngine = true; ballTrans.AddChild(ball); groundMarkerNode.AddChild(ballTrans); ///////////////////////////////////////////////////////////////// paddleNode = new SynchronizedGeometryNode("paddle"); paddleNode.Model = new Box(PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_DEPTH); Material paddleMaterial = new Material(); paddleMaterial.Diffuse = Color.Orange.ToVector4(); paddleMaterial.Specular = Color.White.ToVector4(); paddleMaterial.SpecularPower = 10; paddleNode.Material = paddleMaterial; paddleNode.Physics.Collidable = true; paddleNode.Physics.Interactable = true; paddleNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; paddleNode.Physics.Mass = 10; paddleNode.AddToPhysicsEngine = true; groundMarkerNode.AddChild(paddleNode); }