public static RaceCar AddRaceCar(Scene scene, TransformNode Marke, Vector3 CarPos, GeometryNode CModel, int IdPlayer) { TransformNode transNode = new TransformNode(); transNode.Name = "Tcar:" + IdPlayer; transNode.Translation = CarPos; CModel.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; NewtonPhysics physicsEngine = (NewtonPhysics)scene.PhysicsEngine; RaceCar car = new RaceCar(CModel, physicsEngine); for (int i = 0; i < 4; i++) car.Tires[i] = CreateTire((TireID)Enum.ToObject(typeof(TireID), i), car.TireTransformNode[i], CModel, scene.PhysicsEngine.Gravity); car.Collidable = true; car.Interactable = true; car.StartPos = CarPos; //Physic material Name car.MaterialName = "Car" + IdPlayer; CModel.Physics = car; CModel.Physics.NeverDeactivate = true; CModel.AddToPhysicsEngine = true; //Add To node transNode.AddChild(CModel); Marke.AddChild(transNode); Newton.NewtonSetBodyLeaveWorldEvent(physicsEngine.NewtonWorld, car.LeaveWorldCallback); return car; }
private GeometryNode ShootBullet; //Geometry for Bullet #endregion Fields #region Constructors public Bullet(Vector3 InitPos, PrimitiveModel BulletModel, Material Material, Vector3 DirBullet, MarkerNode grdMarkerNode) { //Create Bullet ShootBullet = new GeometryNode(); ShootBullet.Name = "ShootBullet" + ShootBullet.ID; ShootBullet.Model = BulletModel; ShootBullet.Material = Material; ShootBullet.Physics.Interactable = true; ShootBullet.Physics.Collidable = true; ShootBullet.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; ShootBullet.Physics.Mass = 60f; ShootBullet.Physics.MaterialName = "Bullet"; ShootBullet.AddToPhysicsEngine = true; // Assign the initial velocity to this shooting box ShootBullet.Physics.InitialLinearVelocity = new Vector3(DirBullet.X * 80, DirBullet.Y * 80, DirBullet.Z * 50); BulletTrans = new TransformNode(); BulletTrans.Translation = InitPos; grdMarkerNode.AddChild(BulletTrans); BulletTrans.AddChild(ShootBullet); //Normal asignament isvisible = true; //Agrego Segundo desde que se creo livetime = Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds) + BULLET_TIMELIVE; }
public override Node CloneNode() { TransformNode clone = (TransformNode)base.CloneNode(); clone.PostTranslation = postTranslation; clone.PreTranslation = preTranslation; clone.Rotation = rotation; clone.Scale = scaling; clone.WorldTransformation = WorldTransformation; clone.UseUserDefinedTransform = useUserDefinedTransform; clone.ComposedTransform = composedTransform; clone.IsWorldTransformationDirty = isWorldTransformationDirty; clone.IsReadOnly = isReadOnly; return(clone); }
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 TransformNode getPatientNameNode(Object markerID) { if (markerID.Equals("PatientMarkerConfig.txt")) { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new Sphere(3.5f, 20, 20); sphereNode.Model.CastShadows = true; sphereNode.Model.ReceiveShadows = true; Material sphereMat = new Material(); sphereMat.Diffuse = Color.Red.ToVector4(); sphereMat.Specular = Color.White.ToVector4(); sphereMat.SpecularPower = 20; sphereNode.Material = sphereMat; //sphereNode.Physics.Interactable = false; TransformNode sphereTrans = new TransformNode(); sphereTrans.Translation = new Vector3(0, 0, 5); sphereTrans.AddChild(sphereNode); return sphereTrans; } return null; }
private void SetupMarkerTracking() { DirectShowCapture2 captureDevice = new DirectShowCapture2(); captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); // Add this video capture device to the scene so that it can be used for // the marker tracker scene.AddVideoCaptureDevice(captureDevice); // if we're using Wrap920AR, then we need to add another capture device for // processing stereo camera if (iTracker.ProductID == iWearDllBridge.IWRProductID.IWR_PROD_WRAP920) { DirectShowCapture2 captureDevice2 = new DirectShowCapture2(); captureDevice2.InitVideoCapture(1, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); scene.AddVideoCaptureDevice(captureDevice2); } IMarkerTracker tracker = null; #if USE_ARTAG // Create an optical marker tracker that uses ARTag library tracker = new ARTagTracker(); // Set the configuration file to look for the marker specifications tracker.InitTracker(638.052f, 633.673f, captureDevice.Width, captureDevice.Height, false, "ARTag.cf"); #else // Create an optical marker tracker that uses ALVAR library tracker = new ALVARMarkerTracker(); ((ALVARMarkerTracker)tracker).MaxMarkerError = 0.02f; tracker.InitTracker(captureDevice.Width, captureDevice.Height, "calib.xml", 9.0); #endif scene.MarkerTracker = tracker; if (iTracker.ProductID == iWearDllBridge.IWRProductID.IWR_PROD_WRAP920) { scene.LeftEyeVideoID = 0; scene.RightEyeVideoID = 1; scene.TrackerVideoID = 0; } // Create a marker node to track a ground marker array. #if USE_ARTAG groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ground"); scene.RootNode.AddChild(groundMarkerNode); #else // Create an array to hold a list of marker IDs that are used in the marker // array configuration (even though these are already specified in the configuration // file, ALVAR still requires this array) int[] ids = new int[28]; for (int i = 0; i < ids.Length; i++) ids[i] = i; groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.txt", ids); // Add a transform node to tranlate the objects to be centered around the // marker board. TransformNode transNode = new TransformNode(); scene.RootNode.AddChild(groundMarkerNode); #endif scene.ShowCameraImage = true; }
public static void AddRollingBeats(Scene scene, TransformNode parentTrans) { Vector3 size = new Vector3(10.0f, 0.25f, 0.25f); Vector3 location = new Vector3(0, 3, 3); GeometryNode bar; // ////////////////////////////////////////////////////////////////// // // Create a bar and attach it to the world with a hinge with limits // // ////////////////////////////////////////////////////////////////// { TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; pileTrans.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2); Material barMat = new Material(); barMat.Diffuse = Color.Purple.ToVector4(); barMat.Specular = Color.White.ToVector4(); barMat.SpecularPower = 10; bar = new GeometryNode("Bar"); bar.Model = new Cylinder(size.Y, size.Y, size.X, 20); bar.Material = barMat; bar.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; bar.AddToPhysicsEngine = true; bar.Physics.Interactable = true; bar.Physics.Collidable = true; bar.Physics.Shape = ShapeType.Cylinder; bar.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(bar); Vector3 pivot = location + parentTrans.Translation; Vector3 pin = Vector3.UnitY; pivot.X -= size.X * 0.5f; HingeJoint joint = new HingeJoint(pivot, pin); joint.NewtonHingeCallback = doubleDoor; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(bar.Physics, null, joint); } // ///////////////////////////////////////////////////////////////// // // Add a sliding visualObject with limits // //////////////////////////////////////////////////////////////////// { Vector3 beatLocation = location; Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f); beatLocation.X += size.X * 0.25f; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = beatLocation; Material beatMat = new Material(); beatMat.Diffuse = Color.Red.ToVector4(); beatMat.Specular = Color.White.ToVector4(); beatMat.SpecularPower = 10; GeometryNode beat = new GeometryNode("Beat Slider"); beat.Model = new Box(beatSize); beat.Material = beatMat; beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; beat.AddToPhysicsEngine = true; beat.Physics.Interactable = true; beat.Physics.Collidable = true; beat.Physics.Shape = ShapeType.Box; beat.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(beat); Vector3 pivot = beatLocation + parentTrans.Translation; Vector3 pin = Vector3.UnitX; sliderLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f); sliderLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f); SliderJoint joint = new SliderJoint(pivot, pin); sliderUpdate = delegate(IntPtr slider, ref Newton.NewtonHingeSliderUpdateDesc desc) { float distance = Newton.NewtonSliderGetJointPosit(slider); if (distance < sliderLimit.X) { // if the distance is smaller than the predefine interval, stop the slider desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.X); return 1; } else if (distance > sliderLimit.Y) { // if the distance is larger than the predefine interval, stop the slider desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.Y); return 1; } // no action need it if the joint angle is with the limits return 0; }; joint.NewtonSliderCallback = sliderUpdate; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint); } // ///////////////////////////////////////////////////////////////// // // Add a corkscrew visualObject with limits // // ///////////////////////////////////////////////////////////////// { Vector3 beatLocation = location; Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f); beatLocation.X -= size.X * 0.25f; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = beatLocation; Material beatMat = new Material(); beatMat.Diffuse = Color.YellowGreen.ToVector4(); beatMat.Specular = Color.White.ToVector4(); beatMat.SpecularPower = 10; GeometryNode beat = new GeometryNode("Beat Corkscrew"); beat.Model = new Box(beatSize); beat.Material = beatMat; beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; beat.AddToPhysicsEngine = true; beat.Physics.Interactable = true; beat.Physics.Collidable = true; beat.Physics.Shape = ShapeType.Box; beat.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(beat); Vector3 pivot = beatLocation + parentTrans.Translation; Vector3 pin = Vector3.UnitX; corkscrewLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f); corkscrewLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f); CorkscrewJoint joint = new CorkscrewJoint(pivot, pin); corkscrewUpdate = delegate(IntPtr corkscrew, Newton.NewtonHingeSliderUpdateDesc[] desc) { // no action need it if the joint angle is with the limits uint retCode = 0; float distance = Newton.NewtonCorkscrewGetJointPosit(corkscrew); // The first entry in NewtonHingeSliderUpdateDesc control the screw linear acceleration if (distance < corkscrewLimit.X) { // if the distance is smaller than the predefine interval, stop the slider desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew, ref desc[0], corkscrewLimit.X); retCode |= 1; } else if (distance > corkscrewLimit.Y) { // if the distance is larger than the predefine interval, stop the slider desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew, ref desc[0], corkscrewLimit.Y); retCode |= 1; } // The second entry in NewtonHingeSliderUpdateDesc control the screw angular acceleration. // Make s small screw motor by setting the angular acceleration of the screw axis // We are not going to limit the angular rotation of the screw, but is we did we should // or return code with 2 float omega = Newton.NewtonCorkscrewGetJointOmega(corkscrew); desc[1].m_Accel = 1.5f - 0.2f * omega; // or with 0x10 to tell newton this axis is active retCode |= 2; // return the code return retCode; }; joint.NewtonCorkscrewCallback = corkscrewUpdate; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint); } // ///////////////////////////////////////////////////////////////// // // Add a universal joint visualObject with limits // // ///////////////////////////////////////////////////////////////// { Vector3 beatLocation = location; Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f); beatLocation.X -= size.X * 0.45f; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = beatLocation; Material beatMat = new Material(); beatMat.Diffuse = Color.YellowGreen.ToVector4(); beatMat.Specular = Color.White.ToVector4(); beatMat.SpecularPower = 10; GeometryNode beat = new GeometryNode("Beat Universal"); beat.Model = new Box(beatSize); beat.Material = beatMat; beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; beat.AddToPhysicsEngine = true; beat.Physics.Interactable = true; beat.Physics.Collidable = true; beat.Physics.Shape = ShapeType.Box; beat.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(beat); Vector3 pivot = beatLocation + parentTrans.Translation; Vector3 pin0 = Vector3.UnitX; Vector3 pin1 = Vector3.UnitY; universalLimit.X = -30.0f * MathHelper.Pi / 180.0f; universalLimit.Y = 30.0f * MathHelper.Pi / 180.0f; UniversalJoint joint = new UniversalJoint(pivot, pin0, pin1); universalUpdate = delegate(IntPtr universal, Newton.NewtonHingeSliderUpdateDesc[] desc) { // no action need it if the joint angle is with the limits uint retCode = 0; float omega = Newton.NewtonUniversalGetJointOmega0(universal); desc[0].m_Accel = -1.5f - 0.2f * omega; retCode |= 1; float angle = Newton.NewtonUniversalGetJointAngle1(universal); if (angle < universalLimit.X) { desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1], universalLimit.X); retCode |= 2; } else if (angle > universalLimit.Y) { desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1], universalLimit.Y); retCode |= 2; } // return the code return retCode; }; joint.NewtonUniversalCallback = universalUpdate; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint); } }
private void CreateObjects() { // Create a sphere geometry { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new Sphere(3.5f, 20, 20); sphereNode.Model.CastShadows = true; sphereNode.Model.ReceiveShadows = true; Material sphereMat = new Material(); sphereMat.Diffuse = Color.Red.ToVector4(); sphereMat.Specular = Color.White.ToVector4(); sphereMat.SpecularPower = 20; sphereNode.Material = sphereMat; TransformNode sphereTrans = new TransformNode(); sphereTrans.Translation = new Vector3(0, 0, 5); groundMarkerNode.AddChild(sphereTrans); sphereTrans.AddChild(sphereNode); } // Create a box geometry { GeometryNode boxNode = new GeometryNode("Box"); boxNode.Model = new Box(6); boxNode.Model.CastShadows = true; boxNode.Model.ReceiveShadows = true; Material boxMat = new Material(); boxMat.Diffuse = Color.Blue.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 20; boxNode.Material = boxMat; TransformNode boxTrans = new TransformNode(); boxTrans.Translation = new Vector3(-35, -18, 8); groundMarkerNode.AddChild(boxTrans); boxTrans.AddChild(boxNode); } // Create a cylinder geometry { GeometryNode cylinderNode = new GeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(3.5f, 3.5f, 10, 20); cylinderNode.Model.CastShadows = true; cylinderNode.Model.ReceiveShadows = true; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Green.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 20; cylinderNode.Material = cylinderMat; TransformNode cylinderTrans = new TransformNode(); cylinderTrans.Translation = new Vector3(35, -18, 8); groundMarkerNode.AddChild(cylinderTrans); cylinderTrans.AddChild(cylinderNode); } // Create a torus geometry { GeometryNode torusNode = new GeometryNode("Torus"); torusNode.Model = new Torus(2.5f, 6.0f, 20, 20); torusNode.Model.CastShadows = true; torusNode.Model.ReceiveShadows = true; Material torusMat = new Material(); torusMat.Diffuse = Color.Yellow.ToVector4(); torusMat.Specular = Color.White.ToVector4(); torusMat.SpecularPower = 20; torusNode.Material = torusMat; TransformNode torusTrans = new TransformNode(); torusTrans.Translation = new Vector3(-35, 18, 8); groundMarkerNode.AddChild(torusTrans); torusTrans.AddChild(torusNode); } // Create a capsule geometry { GeometryNode capsuleNode = new GeometryNode("Capsule"); capsuleNode.Model = new Capsule(3, 12, 20); capsuleNode.Model.CastShadows = true; capsuleNode.Model.ReceiveShadows = true; Material capsuleMat = new Material(); capsuleMat.Diffuse = Color.Cyan.ToVector4(); capsuleMat.Specular = Color.White.ToVector4(); capsuleMat.SpecularPower = 20; capsuleNode.Material = capsuleMat; TransformNode capsuleTrans = new TransformNode(); capsuleTrans.Translation = new Vector3(35, 18, 8); groundMarkerNode.AddChild(capsuleTrans); capsuleTrans.AddChild(capsuleNode); } }
private void CreateMarkerTracking() { Console.WriteLine(DateTime.Now.ToString() + " Setup Markers\n"); // Create a marker node to track a ground marker array. groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml"); //Add marker to Scene scene.RootNode.AddChild(groundMarkerNode); /***** For Weapons *****/ //Add Big Parent for All Weapons parentTNodeWeapon = new TransformNode(); parentTNodeWeapon.Name = "Weapons"; groundMarkerNode.AddChild(parentTNodeWeapon); /***** For Cars *****/ parentTNodeCars = new TransformNode(); parentTNodeCars.Name = "TCars"; groundMarkerNode.AddChild(parentTNodeCars); /************** Array of markers **************/ int HinIdx, MarkIdx = 29; //Add Markers with the Code Index between 29 - 32 for the Weapons (one for player) for (HinIdx = 0; HinIdx < Max_palyer; HinIdx++) { WeaponMarkeNodes[HinIdx] = new MarkerNode(scene.MarkerTracker, MarkIdx); scene.RootNode.AddChild(WeaponMarkeNodes[HinIdx]); MarkIdx++; } //Add Markers with the Code Index between 33 - 38 for the Obstacles for (HinIdx = 0; HinIdx < Max_Markers; HinIdx++) { HinderMarkeNodes[HinIdx] = new MarkerNode(scene.MarkerTracker, MarkIdx); scene.RootNode.AddChild(HinderMarkeNodes[HinIdx]); MarkIdx++; } }
public RaceCar(Object container, NewtonPhysics engine) : base(container) { this.engine = engine; //Crea los cuatro nodos de transformacion para las 4 Ruedas tireTransNode = new TransformNode[4]; for (int i = 0; i < 4; i++) tireTransNode[i] = new TransformNode(); // set the mass of the race car - Propiedad heredada mass = VEHICLE_MASS; // lower the center of the mass for a race car centerOfMass = -Vector3.UnitY * 1.5f; // sets up the callback function when body moves in the simulation transformCallback = delegate(IntPtr body, float[] matrix) { Matrix mat = MatrixHelper.FloatsToMatrix(matrix); // set the transformation of the vehicle body PhysicsWorldTransform = mat; Matrix invMat = Matrix.Invert(mat); float[] tireMatrix = new float[16]; NewtonTire tire = null; float sign = 0; float angle = 0; float brakePosition = 0; // set the global matrix for each tire for (IntPtr tyreId = Newton.NewtonVehicleGetFirstTireID(joint); tyreId != IntPtr.Zero; tyreId = Newton.NewtonVehicleGetNextTireID(joint, tyreId)) { int tireID = (int)GetTireID(tyreId); tire = tires[tireID]; Newton.NewtonVehicleGetTireMatrix(joint, tyreId, tireMatrix); // calculate the local matrix Matrix tireMat = MatrixHelper.GetRotationMatrix( MatrixHelper.FloatsToMatrix(tireMatrix) * invMat) * tire.TireOffsetMatrix; tire.TireMatrix = tireMat; tireTransNode[tireID].WorldTransformation = Matrix.CreateRotationX(MathHelper.PiOver2) * tireMat; // calcualte the parametric brake position brakePosition = tireMat.Translation.Y - tire.TireRefHeight; tire.BrakeMatrix = Matrix.CreateTranslation(0, tire.BrakeRefPosition.Y + brakePosition, 0); // set suspensionMatrix sign = (tire.BrakeRefPosition.Z > 0) ? 1 : -1; angle = (float)Math.Atan2(sign * brakePosition, Math.Abs(tire.BrakeRefPosition.Z)); Matrix rotationMatrix = new Matrix( 1, 0, 0, 0, 0, (float)Math.Cos(angle), (float)Math.Sin(angle), 0, 0, -(float)Math.Sin(angle), (float)Math.Cos(angle), 0, 0, 0, 0, 1); tire.AxelMatrix = rotationMatrix * tire.AxelMatrix; tire.SuspensionTopMatrix = rotationMatrix * tire.SuspensionTopMatrix; tire.SuspensionBottomMatrix = rotationMatrix * tire.SuspensionBottomMatrix; } }; forceCallback = delegate(IntPtr body) { float Ixx = 0, Iyy = 0, Izz = 0, tmpMass = 0; Newton.NewtonBodyGetMassMatrix(body, ref tmpMass, ref Ixx, ref Iyy, ref Izz); tmpMass *= (1.0f + (float)Math.Abs(GetSpeed()) / 20.0f); float[] force = Vector3Helper.ToFloats(engine.GravityDirection * engine.Gravity * tmpMass); Newton.NewtonBodySetForce(body, force); }; tireUpdate = delegate(IntPtr vehicleJoint) { NewtonTire tire = null; for (IntPtr tyreId = Newton.NewtonVehicleGetFirstTireID(vehicleJoint); tyreId != IntPtr.Zero; tyreId = Newton.NewtonVehicleGetNextTireID(vehicleJoint, tyreId)) { tire = tires[(int)GetTireID(tyreId)]; // If the tire is a front tire if ((tire == tires[(int)TireID.FrontLeft]) || (tire == tires[(int)TireID.FrontRight])) { float currSteerAngle = Newton.NewtonVehicleGetTireSteerAngle(vehicleJoint, tyreId); Newton.NewtonVehicleSetTireSteerAngle(vehicleJoint, tyreId, currSteerAngle + (tire.Steer - currSteerAngle) * 0.035f); } else // if the tire is a rear tire { Newton.NewtonVehicleSetTireTorque(vehicleJoint, tyreId, tire.Torque); if (tire.Brakes > 0) { // ask Newton for the precise acceleration needed to stop the tire float brakeAcceleration = Newton.NewtonVehicleTireCalculateMaxBrakeAcceleration(vehicleJoint, tyreId); // tell Newton you want this tire stoped but only if the torque need it is less than // the brakes pad can withstand (assume max brake pad torque is 500 newton * meter) Newton.NewtonVehicleTireSetBrakeAcceleration(vehicleJoint, tyreId, brakeAcceleration, 10000.0f); // set some side slip as function of the linear speed float speed = Newton.NewtonVehicleGetTireLongitudinalSpeed(vehicleJoint, tyreId); Newton.NewtonVehicleSetTireMaxSideSleepSpeed(vehicleJoint, tyreId, speed * 0.1f); } } } }; bodyLeaveCallback = delegate(IntPtr body) { Respawn(body); }; }
public void CreateSceneObj(string Folder, string ObjName, Vector3 ObjPos, Vector3 ObjScale) { GeometryNode ObjNode; ObjNode = LoadModel("Models/" + Folder, ObjName, true); //Setup Physics Aspecte ObjNode.Physics.Collidable = false; ObjNode.AddToPhysicsEngine = false; TransformNode parentTransNode = new TransformNode(ObjName); parentTransNode.Scale = ObjScale; parentTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90)); parentTransNode.Translation = ObjPos; parentTransNode.AddChild(ObjNode); //Add Model in the Scene parentTNodeGrd.AddChild(parentTransNode); }
TransformNode parentTNodeGrd; //Parent for all Scene Objects #endregion Fields #region Constructors public Graphics3D(MarkerNode MarkerNode, IShadowMap ShadowMap) { //Asignation Ground Node this.groundMarkerNode = MarkerNode; //Asignation Shadow Map this.GShadowMap = ShadowMap; //Add Big Parent for All Scenary Elements parentTNodeGrd = new TransformNode(); parentTNodeGrd.Name = "Level"; groundMarkerNode.AddChild(parentTNodeGrd); // Create a material for the model BulletrMat = new Material(); BulletrMat.Diffuse = Color.Blue.ToVector4(); BulletrMat.Specular = Color.White.ToVector4(); BulletrMat.SpecularPower = 10; //create Bullet Model BulletModel = new TexturedBox(2.0f); LoadLevel = false; LoadCars = false; }
public static GeometryNode AddModel(MarkerNode Marker, String Folder, String Model, bool IntMaterial, float Scala) { GeometryNode ObstNode; if (Model == "null") return ObstNode = new GeometryNode(); ObstNode = Graphics3D.LoadModel("Models/" + Folder, Model, IntMaterial); //define the Physic Material name ObstNode.Physics.MaterialName = "Obstacle"; TransformNode parentTransNode = new TransformNode(); parentTransNode.Name = Model; parentTransNode.Scale = new Vector3(Scala, Scala + 2, Scala); parentTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90)); //Add Rotation because Blender Axis parentTransNode.AddChild(ObstNode); // Add this box model node to the ground marker node if(Marker != null) Marker.AddChild(parentTransNode); return ObstNode; }
public void AddLapida(Vector3 PosCar, int LevelHeight, float Scala) { GeometryNode LapidaNode = LoadModel("Models", "lapida", true); LapidaNode.Physics.Collidable = true; TransformNode parentTransNode = new TransformNode("Lapida"); parentTransNode.Scale = new Vector3(Scala, Scala + 2, Scala); parentTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90)); parentTransNode.Translation = new Vector3(PosCar.X, PosCar.Y, LevelHeight + 10); //Add Rotation because Blender Axis parentTransNode.AddChild(LapidaNode); //Add Model in the Scene groundMarkerNode.AddChild(parentTransNode); }
private void CreateObject() { // Loads a textured model of a ship ModelLoader loader = new ModelLoader(); Model shipModel = (Model)loader.Load("", "p1_wedge"); // Create a geometry node of a loaded ship model GeometryNode shipNode = new GeometryNode("Ship"); shipNode.Model = shipModel; ((Model)shipNode.Model).UseInternalMaterials = true; // Create a transform node to define the transformation for the ship TransformNode shipTransNode = new TransformNode(); shipTransNode.Translation = new Vector3(0, 0, -50); shipTransNode.Scale = new Vector3(0.01f, 0.01f, 0.01f); // It's huge! shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), MathHelper.ToRadians(90)); shipTransParentNode = new TransformNode(); shipTransParentNode.Translation = Vector3.Zero; // Create a geometry node with model of a torus GeometryNode torusNode = new GeometryNode("Torus"); torusNode.Model = new Torus(12f, 15.5f, 20, 20); TransformNode torusTransNode = new TransformNode(); torusTransNode.Translation = new Vector3(-50, 0, 0); torusTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90)); // Create a material node for this torus model Material torusMaterial = new Material(); torusMaterial.Diffuse = Color.DarkGoldenrod.ToVector4(); torusMaterial.Specular = Color.White.ToVector4(); torusMaterial.SpecularPower = 5; torusNode.Material = torusMaterial; // Now add the above nodes to the scene graph in appropriate order scene.RootNode.AddChild(shipTransParentNode); shipTransParentNode.AddChild(shipTransNode); shipTransNode.AddChild(shipNode); scene.RootNode.AddChild(torusTransNode); torusTransNode.AddChild(torusNode); // Now create couple of particle effects to attach to the models // Create a smoke particle effect and fire particle effect to simulate a // ring of fire around the torus model #if WINDOWS_PHONE SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(20, spriteBatch); FireParticleEffect fireParticles = new FireParticleEffect(40, spriteBatch); #else SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(); FireParticleEffect fireParticles = new FireParticleEffect(); // The order defines which particle effect to render first. Since we want // to show the fire particles in front of the smoke particles, we make // the smoke particles to be rendered first, and then fire particles smokeParticles.DrawOrder = 200; fireParticles.DrawOrder = 300; #endif // Create a particle node to hold these two particle effects ParticleNode fireRingEffectNode = new ParticleNode(); fireRingEffectNode.ParticleEffects.Add(smokeParticles); fireRingEffectNode.ParticleEffects.Add(fireParticles); // Implement an update handler for each of the particle effects which will be called // every "Update" call fireRingEffectNode.UpdateHandler += new ParticleUpdateHandler(UpdateRingOfFire); torusNode.AddChild(fireRingEffectNode); // Create another set of fire and smoke particle effects to simulate the fire // the ship catches when the ship passes the ring of fire #if WINDOWS_PHONE FireParticleEffect shipFireEffect = new FireParticleEffect(150, spriteBatch); SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(80, spriteBatch); shipFireEffect.MinScale *= 1.5f; shipFireEffect.MaxScale *= 1.5f; #else FireParticleEffect shipFireEffect = new FireParticleEffect(); SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(); shipSmokeEffect.DrawOrder = 400; shipFireEffect.DrawOrder = 500; #endif ParticleNode shipFireNode = new ParticleNode(); shipFireNode.ParticleEffects.Add(shipFireEffect); shipFireNode.ParticleEffects.Add(shipSmokeEffect); shipFireNode.UpdateHandler += new ParticleUpdateHandler(UpdateShipFire); shipNode.AddChild(shipFireNode); }
private void CreateObject() { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new Box(60); sphereTransNode = new TransformNode(); sphereTransNode.Translation = new Vector3(0, 0, 0); Material sphereMaterial = new Material(); sphereMaterial.Diffuse = new Vector4(0.5f, 0, 0, 1); sphereMaterial.Specular = Color.White.ToVector4(); sphereMaterial.SpecularPower = 10; // Apply this material to the sphere model sphereNode.Material = sphereMaterial; sphereTransNode.AddChild(sphereNode); scene.RootNode.AddChild(sphereTransNode); }
private void createCorderBackground() { cornerPanelTransformNode = new TransformNode("Corner Panel Trans"); scene.RootNode.AddChild(cornerPanelTransformNode); cornerPanelNode = new GeometryNode("Corner Panel"); cornerPanelNode.Model = new TexturedLayer(new Vector2(250, 250));//new Box(300, 250, 1); cornerPanelTransformNode.AddChild(cornerPanelNode); cornerPanelTransformNode.Translation = new Vector3(2.3f, -1.58f, -5); cornerPanelTransformNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90)); //cornerPanelTransformNode.Translation = new Vector3(0, .06f, -1); cornerPanelTransformNode.Scale = new Vector3(0.005f, 0.005f, 0.005f); Material pointerLabelMaterial = new Material(); pointerLabelMaterial.Diffuse = Color.White.ToVector4(); ;// new Vector4(0, 0.5f, 0, 1); // pointerLabelMaterial.Specular = Color.White.ToVector4(); // pointerLabelMaterial.SpecularPower = 50; pointerLabelMaterial.Texture = Content.Load<Texture2D>("hud/cornerPanel"); cornerPanelNode.Material = pointerLabelMaterial; //cornerPanelTransformNode.SetAlpha(0.55f); Vector4 tempColor = cornerPanelNode.Material.Diffuse; Vector3 tempVec = new Vector3(tempColor.X, tempColor.Y, tempColor.Z); cornerPanelNode.Material.Diffuse = new Vector4(tempVec, 0.7f); }
private void CreateObject() { // Loads a textured model of a ship ModelLoader loader = new ModelLoader(); Model shipModel = (Model)loader.Load("", "p1_wedge"); // Create a geometry node of a loaded ship model GeometryNode shipNode = new GeometryNode("Ship"); shipNode.Model = shipModel; // This ship model has material definitions in the model file, so instead // of creating a material node for this ship model, we simply use its internal materials shipNode.Model.UseInternalMaterials = true; // Create a transform node to define the transformation for the ship shipTransNode = new TransformNode(); shipTransNode.Translation = new Vector3(0, 0, 0); shipTransNode.Scale = new Vector3(0.002f, 0.002f, 0.002f); // It's huge! shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(0)); scene.RootNode.AddChild(shipTransNode); shipTransNode.AddChild(shipNode); }
private static NewtonTire CreateTire(TireID tireID, TransformNode tireTrans, GeometryNode carNode, float gravity) { NewtonTire tire = new NewtonTire(); Material tireMat = new Material(); tireMat.Diffuse = Color.Orange.ToVector4(); tireMat.Specular = Color.White.ToVector4(); tireMat.SpecularPower = 10; float tireRadius = 0.7f; GeometryNode tireNode = new GeometryNode("Race Car " + tireID + " Tire"); tireNode.Model = new Cylinder(tireRadius, tireRadius, 0.3f, 20); tireNode.Material = tireMat; carNode.AddChild(tireTrans); tireTrans.AddChild(tireNode); tire.Mass = 5.0f; tire.Width = 0.3f * 1.25f; tire.Radius = tireRadius; switch (tireID) { case TireID.FrontLeft: tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(-1.5f, 0, -1f)); break; case TireID.FrontRight: tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(-1.5f, 0, 1f)); break; case TireID.RearLeft: tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(1.5f, 0, -1f)); break; case TireID.RearRight: tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(1.5f, 0, 1f)); break; } // the tire will spin around the lateral axis of the same tire space tire.Pin = Vector3.UnitZ; tire.SuspensionLength = RaceCar.SUSPENSION_LENGTH; // calculate the spring and damper contact for the subquestion // // from the equation of a simple spring the force is given by // a = k * x // where k is a spring constant and x is the displacement and a is the spring acceleration. // we desire that a rest length the acceleration generated by the spring equal that of the gravity // several gravity forces // m * gravity = k * SUSPENSION_LENGTH * 0.5f, float x = RaceCar.SUSPENSION_LENGTH; tire.SuspensionSpring = (200.0f * (float)Math.Abs(gravity)) / x; //tireSuspesionSpring = (100.0f * dAbs (GRAVITY)) / x; // from the equation of a simple spring / damper system // the system resonate at a frequency // w^2 = ks // // and the damping attenuation is given by // d = ks / 2.0f // where: // if d = w = 2 * pi * f -> the system is critically damped // if d > w < 2 * pi * f -> the system is super critically damped // if d < w < 2 * pi * f -> the system is under damped damped // for a vehicle we usually want a suspension that is about 10% super critically damped float w = (float)Math.Sqrt(tire.SuspensionSpring); // a critically damped suspension act too jumpy for a race car tire.SuspensionShock = 1.0f * w; // make it a little super critical y damped //tireSuspesionShock = 2.0f * w; tire.CollisionID = 0x100; return tire; }
private void build(IModel model, string name) { this.name = name; this.instanceNumber = instance; restrictedDimension = new Vector3(1,1,0); geo = new GeometryNode(this.Label); trans = new TransformNode(this.Label + "_Trans"); instance++; trans.AddChild(geo); geo.Model = model; geo.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; geo.Physics.Pickable = true; geo.AddToPhysicsEngine = true; trans.Rotation = Quaternion.CreateFromYawPitchRoll((float)Math.PI / 2, 0, (float)Math.PI / 2); }
private void CreateCamera() { // Set up the camera of the scene graph Camera camera = new Camera(); // Put the camera at (0, 3, 7) camera.Translation = new Vector3(0, 3, 7); // Rotate the camera -15 degrees along the X axis camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-15)); // Set the vertical field of view to be 45 degrees camera.FieldOfViewY = MathHelper.ToRadians(45); // Set the near clipping plane to be 0.1f unit away from the camera camera.ZNearPlane = 0.1f; // Set the far clipping plane to be 1000 units away from the camera camera.ZFarPlane = 1000; // Set the initial translation and rotation of the generic input which controls // the camera transform in this application GenericInput.Instance.InitialTranslation = camera.Translation; GenericInput.Instance.InitialRotation = camera.Rotation; // Adjust the speed of the camera control GenericInput.Instance.PanSpeed = 0.05f; GenericInput.Instance.ZoomSpeed = 0.5f; GenericInput.Instance.RotateSpeed = 0.02f; // Now assign this camera to a camera node CameraNode cameraNode = new CameraNode(camera); // Add a transform node which will be updated based on GenericInput class // which implements simple camera rotation and translation based on mouse // drag and key presses. // To rotate the camera, hold right mouse button and drag around genericInputNode = new TransformNode(); scene.RootNode.AddChild(genericInputNode); genericInputNode.AddChild(cameraNode); // Assign the camera node to be our scene graph's current camera node scene.CameraNode = cameraNode; }
public static void CreateBall(MarkerNode Marker) { // Create a geometry node for Sphere PrimitiveModel PsphereModel = new Sphere(15f, 20, 20); // Create a material to apply to the sphere model Material sphereMaterial = new Material(); sphereMaterial.Diffuse = new Vector4(0, 0.5f, 0, 1); sphereMaterial.Specular = Color.White.ToVector4(); sphereMaterial.SpecularPower = 10; GeometryNode sphereNode = new GeometryNode("Sphere"); //sphereNode.Model = new TexturedSphere(16, 20, 20); sphereNode.Model = PsphereModel; sphereNode.Material = sphereMaterial; // Add this sphere model to the physics engine for collision detection sphereNode.Physics.Interactable = true; sphereNode.Physics.Collidable = true; sphereNode.Physics.Shape = ShapeType.Sphere; sphereNode.Physics.Mass = 30; //sphereNode.Physics.ApplyGravity = false; sphereNode.Physics.InitialLinearVelocity = new Vector3(30, 0, 0); //sphereNode.Physics.MaterialName = "Sphere"; //sphereNode.Physics.ApplyGravity = true; sphereNode.AddToPhysicsEngine = true; // Make this sphere model cast and receive shadows //sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene //sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); TransformNode sphereTransNode = new TransformNode(); sphereTransNode.Translation = new Vector3(50, 0, 50); // Now add the above nodes to the scene graph in the appropriate order. // Note that only the nodes added below the marker node are affected by // the marker transformation. Marker.AddChild(sphereTransNode); sphereTransNode.AddChild(sphereNode); }
private void SetupMarkerTracking() { DirectShowCapture2 captureDevice = new DirectShowCapture2(); captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); // Add this video capture device to the scene so that it can be used for // the marker tracker scene.AddVideoCaptureDevice(captureDevice); // if we're using Wrap920AR, then we need to add another capture device for // processing stereo camera DirectShowCapture2 captureDevice2 = null; if (iTracker.ProductID == iWearDllBridge.IWRProductID.IWR_PROD_WRAP920) { captureDevice2 = new DirectShowCapture2(); captureDevice2.InitVideoCapture(1, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); scene.AddVideoCaptureDevice(captureDevice2); // Calculate the right projection matrix using the camera intrinsic parameters for the // right camera ((StereoCamera)scene.CameraNode.Camera).RightProjection = ALVARDllBridge.GetCameraProjection("Wrap920_1_Right.xml", captureDevice2.Width, captureDevice2.Height, 0.1f, 1000); } // Create an optical marker tracker that uses ALVAR library ALVARMarkerTracker tracker = new ALVARMarkerTracker(); tracker.MaxMarkerError = 0.02f; tracker.ZNearPlane = 0.1f; tracker.ZFarPlane = 1000; tracker.InitTracker(captureDevice.Width, captureDevice.Height, "Wrap920_1_Left.xml", markerSize); ((StereoCamera)scene.CameraNode.Camera).LeftProjection = tracker.CameraProjection; scene.MarkerTracker = tracker; if (iTracker.ProductID == iWearDllBridge.IWRProductID.IWR_PROD_WRAP920) { scene.LeftEyeVideoID = 0; scene.RightEyeVideoID = 1; scene.TrackerVideoID = 0; } else { scene.LeftEyeVideoID = 0; scene.RightEyeVideoID = 0; scene.TrackerVideoID = 0; } // Create a marker node to track a ground marker array. groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml"); // Add a transform node to tranlate the objects to be centered around the // marker board. TransformNode transNode = new TransformNode(); scene.RootNode.AddChild(groundMarkerNode); scene.ShowCameraImage = true; }
public void CreateGroundLevel(string Folder, String Model, Vector3 ObjPos, Vector3 Scala) { GeometryNode groundNode; groundNode = LoadModel("Models/" + Folder, Model, true); //Setup Physics Aspecte groundNode.Physics.Collidable = true; // Make the ground model to receive shadow casted by other objects //groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly; // Assign a shadow shader //groundNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); TransformNode parentTransNode = new TransformNode("ground"); parentTransNode.Scale = Scala; parentTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90)); //Add Rotation because Blender Axis parentTransNode.Translation = ObjPos; parentTransNode.AddChild(groundNode); //Add Model in the Scene parentTNodeGrd.AddChild(parentTransNode); }
private void CreateObjects() { // Create a sphere geometry { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new TexturedSphere(14, 20, 20); sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); Material sphereMat = new Material(); sphereMat.Diffuse = Color.Red.ToVector4(); sphereMat.Specular = Color.White.ToVector4(); sphereMat.SpecularPower = 20; sphereNode.Material = sphereMat; TransformNode sphereTrans = new TransformNode(); sphereTrans.Translation = new Vector3(0, 0, 20); groundMarkerNode.AddChild(sphereTrans); sphereTrans.AddChild(sphereNode); } // Create a box geometry { GeometryNode boxNode = new GeometryNode("Box"); boxNode.Model = new TexturedBox(24); boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; boxNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); Material boxMat = new Material(); boxMat.Diffuse = Color.Blue.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 20; boxNode.Material = boxMat; TransformNode boxTrans = new TransformNode(); boxTrans.Translation = new Vector3(-140, -72, 32); groundMarkerNode.AddChild(boxTrans); boxTrans.AddChild(boxNode); } // Create a cylinder geometry { GeometryNode cylinderNode = new GeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(14, 14, 10, 20); cylinderNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Green.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 20; cylinderNode.Material = cylinderMat; TransformNode cylinderTrans = new TransformNode(); cylinderTrans.Translation = new Vector3(140, -72, 32); groundMarkerNode.AddChild(cylinderTrans); cylinderTrans.AddChild(cylinderNode); } // Create a torus geometry { GeometryNode torusNode = new GeometryNode("Torus"); torusNode.Model = new Torus(10, 24, 20, 20); torusNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; Material torusMat = new Material(); torusMat.Diffuse = Color.Yellow.ToVector4(); torusMat.Specular = Color.White.ToVector4(); torusMat.SpecularPower = 20; torusNode.Material = torusMat; TransformNode torusTrans = new TransformNode(); torusTrans.Translation = new Vector3(-140, 72, 32); groundMarkerNode.AddChild(torusTrans); torusTrans.AddChild(torusNode); } // Create a capsule geometry { GeometryNode capsuleNode = new GeometryNode("Capsule"); capsuleNode.Model = new Capsule(12, 48, 20); capsuleNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; Material capsuleMat = new Material(); capsuleMat.Diffuse = Color.Cyan.ToVector4(); capsuleMat.Specular = Color.White.ToVector4(); capsuleMat.SpecularPower = 20; capsuleNode.Material = capsuleMat; TransformNode capsuleTrans = new TransformNode(); capsuleTrans.Translation = new Vector3(140, 72, 32); groundMarkerNode.AddChild(capsuleTrans); capsuleTrans.AddChild(capsuleNode); } }
public void CreateShootBullet(Vector3 InitPos, Vector3 DirBullet, Color BulletColor) { if (BulletID == 20) return; GeometryNode ShootBullet = new GeometryNode("ShootBullet" + BulletID++); ShootBullet.Model = BulletModel; BulletrMat.Diffuse = BulletColor.ToVector4(); ShootBullet.Material = BulletrMat; ShootBullet.Physics.Interactable = true; ShootBullet.Physics.Collidable = true; ShootBullet.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; ShootBullet.Physics.Mass = 60f; ShootBullet.Physics.MaterialName = "Bullet"; ShootBullet.AddToPhysicsEngine = true; // Assign the initial velocity to this shooting box ShootBullet.Physics.InitialLinearVelocity = new Vector3(DirBullet.X * 80, DirBullet.Y * 80, DirBullet.Z * 50); TransformNode BulletTrans = new TransformNode(); BulletTrans.Translation = InitPos; groundMarkerNode.AddChild(BulletTrans); BulletTrans.AddChild(ShootBullet); }
private void CreateObjects() { // Loads a textured model of a ship ModelLoader loader = new ModelLoader(); Model shipModel = (Model)loader.Load("", "p1_wedge"); // Create a geometry node of a loaded ship model GeometryNode shipNode = new GeometryNode("Ship"); shipNode.Model = shipModel; // This ship model has material definitions in the model file, so instead // of creating a material node for this ship model, we simply use its internal materials ((Model)shipNode.Model).UseInternalMaterials = true; ((Model)shipNode.Model).ContainsTransparency = true; // Create a transform node to define the transformation for the ship TransformNode shipTransNode = new TransformNode(); // shipTransNode.Translation = new Vector3(0, 5, -12); shipTransNode.Scale = new Vector3(0.002f, 0.002f, 0.002f); // It's huge! shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), MathHelper.ToRadians(-90)); shipTransParentNode = new TransformNode(); //Set our rotation animation to ease in initially animationRotation = new AnimationHelper(Easing.EaseIn); startPosition = new Vector3(-10, 0, -10); endPosition = new Vector3(5, 2, -5); startRotationVector = new Vector3(0, 0, 0); endRotationVector = new Vector3(MathHelper.ToRadians(0), MathHelper.ToRadians(180), MathHelper.ToRadians(180)); //Set our translation animation to ease in initially animationTranslation = new AnimationHelper(Easing.EaseIn); //Define what kind of interpolation to use. animationTranslation.Animate(arrayOfTransitions[currentInterpolation], startPosition, endPosition, 2); // animationTranslation.SetLooping(true, 5); // Use if you want to loop through an animation. // Set an action to take place once the animation concludes. animationTranslation.SetEndAction(delegate() { animationRotation.Animate(arrayOfTransitions[currentInterpolation], startRotationVector, endRotationVector, 2.0); }); // Note: if you loop and set this animation, it'll occur after the end of the first loop, not after the end of all loops! textToPrint = "Linear interpolation"; // Now add the above nodes to the scene graph in appropriate order scene.RootNode.AddChild(shipTransParentNode); shipTransParentNode.AddChild(shipTransNode); shipTransNode.AddChild(shipNode); }
public List<TransformNode> getListTransformNodes(Object PtID, Object EqID) { //create Box GeometryNode boxNode = new GeometryNode("Box"); boxNode.Model = new Box(6); boxNode.Model.CastShadows = true; boxNode.Model.ReceiveShadows = true; Material boxMat = new Material(); boxMat.Diffuse = Color.Blue.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 20; boxNode.Material = boxMat; TransformNode boxTrans = new TransformNode(); boxTrans.Translation = new Vector3(-35, -18, 8); boxTrans.AddChild(boxNode); //Create cylinder GeometryNode cylinderNode = new GeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(3.5f, 3.5f, 10, 20); cylinderNode.Model.CastShadows = true; cylinderNode.Model.ReceiveShadows = true; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Green.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 20; cylinderNode.Material = cylinderMat; TransformNode cylinderTrans = new TransformNode(); cylinderTrans.Translation = new Vector3(35, -18, 8); cylinderTrans.AddChild(cylinderNode); List<TransformNode> nodes = new List<TransformNode>(); nodes.Add(boxTrans); nodes.Add(cylinderTrans); return nodes; }
/// <summary> /// Creates a rope-like object by connecting several ball and socket joints. /// </summary> /// <param name="scene"></param> /// <param name="parentTrans"></param> public static void AddRope(Scene scene, TransformNode parentTrans) { Vector3 size = new Vector3(1.5f, 0.25f, 0.25f); Vector3 location = new Vector3(0, 9, 0); IPhysicsObject link0 = null; Color[] colors = {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet}; PrimitiveModel capsule = new Capsule(size.Y, size.X, 12); for (int i = 0; i < 7; i++) { TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; Material linkMat = new Material(); linkMat.Diffuse = colors[i].ToVector4(); linkMat.Specular = Color.White.ToVector4(); linkMat.SpecularPower = 10; GeometryNode link1 = new GeometryNode("Link " + i); link1.Model = capsule; link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; link1.Material = linkMat; link1.AddToPhysicsEngine = true; link1.Physics.Interactable = true; link1.Physics.Collidable = true; link1.Physics.Shape = ShapeType.Capsule; link1.Physics.Mass = 2.0f; link1.Physics.LinearDamping = 1f; link1.Physics.AngularDamping = new Vector3(1f, 1f, 1f); parentTrans.AddChild(pileTrans); pileTrans.AddChild(link1); Vector3 pivot = location + parentTrans.Translation; pivot.Y += (size.X - size.Y) * 0.5f; BallAndSocketJoint joint = new BallAndSocketJoint(pivot); joint.Pin = -Vector3.UnitY; joint.MaxConeAngle = 0.0f; joint.MaxTwistAngle = 10.0f * MathHelper.Pi / 180; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, link0, joint); link0 = link1.Physics; location = new Vector3(location.X, location.Y - (size.X - size.Y), location.Z); } }
private void CreateObjects() { // Create a geometry node with a model of a sphere that will be overlaid on // top of the ground marker array GeometryNode sphereNode = new GeometryNode("Sphere"); // We will use TexturedSphere instead of regular Box class since we will need the // texture coordinates elements for passing the vertices to the SimpleShadowShader // we will be using sphereNode.Model = new TexturedSphere(16, 20, 20); // Add this sphere model to the physics engine for collision detection sphereNode.AddToPhysicsEngine = true; sphereNode.Physics.Shape = ShapeType.Sphere; // Make this sphere model cast and receive shadows sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); // Create a marker node to track a ground marker array. #if USE_NYARTOOLKIT groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitGroundArray.xml", NyARToolkitTracker.ComputationMethod.Average); #else groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml"); #endif TransformNode sphereTransNode = new TransformNode(); sphereTransNode.Translation = new Vector3(0, 0, 50); // Create a material to apply to the sphere model Material sphereMaterial = new Material(); sphereMaterial.Diffuse = new Vector4(0, 0.5f, 0, 1); sphereMaterial.Specular = Color.White.ToVector4(); sphereMaterial.SpecularPower = 10; sphereNode.Material = sphereMaterial; // Now add the above nodes to the scene graph in the appropriate order. // Note that only the nodes added below the marker node are affected by // the marker transformation. scene.RootNode.AddChild(groundMarkerNode); groundMarkerNode.AddChild(sphereTransNode); sphereTransNode.AddChild(sphereNode); // Create a geometry node with a model of a box that will be overlaid on // top of the ground marker array initially. (When the toolbar marker array is // detected, it will be overlaid on top of the toolbar marker array.) boxNode = new GeometryNode("Box"); // We will use TexturedBox instead of regular Box class since we will need the // texture coordinates elements for passing the vertices to the SimpleShadowShader // we will be using boxNode.Model = new TexturedBox(32.4f); // Add this box model to the physics engine for collision detection boxNode.AddToPhysicsEngine = true; boxNode.Physics.Shape = ShapeType.Box; // Make this box model cast and receive shadows boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene boxNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); // Create a marker node to track a toolbar marker array. #if USE_NYARTOOLKIT toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ToolbarNyARToolkit.xml", NyARToolkitTracker.ComputationMethod.Average); #else toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARToolbar.xml"); #endif scene.RootNode.AddChild(toolbarMarkerNode); // Create a material to apply to the box model Material boxMaterial = new Material(); boxMaterial.Diffuse = new Vector4(0.5f, 0, 0, 1); boxMaterial.Specular = Color.White.ToVector4(); boxMaterial.SpecularPower = 10; boxNode.Material = boxMaterial; // Add this box model node to the ground marker node groundMarkerNode.AddChild(boxNode); // Create a collision pair and add a collision callback function that will be // called when the pair collides NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(boxNode.Physics, sphereNode.Physics); ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision); }
public static void AddDoubleSwingDoors(Scene scene, TransformNode parentTrans) { Vector3 size = new Vector3(2.0f, 5.0f, 0.5f); Vector3 location = new Vector3(0, 3.5f, -3); Material linkMat = new Material(); linkMat.Diffuse = Color.Cyan.ToVector4(); linkMat.Specular = Color.White.ToVector4(); linkMat.SpecularPower = 10; GeometryNode link1 = null; // Make first wing { TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; link1 = new GeometryNode("Door 1"); link1.Model = new Box(size.X, size.Y, size.Z); link1.Material = linkMat; link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; link1.AddToPhysicsEngine = true; link1.Physics.Interactable = true; link1.Physics.Collidable = true; link1.Physics.Shape = ShapeType.Box; link1.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(link1); Vector3 pivot = location + parentTrans.Translation; Vector3 pin = Vector3.UnitY; pivot.X += size.X * 0.5f; pivot.Y -= size.Y * 0.5f; HingeJoint joint = new HingeJoint(pivot, pin); joint.NewtonHingeCallback = doubleDoor; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, null, joint); } // Make second wing { location.X -= size.X; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; GeometryNode link2 = new GeometryNode("Door 2"); link2.Model = new Box(size.X, size.Y, size.Z); link2.Material = linkMat; link2.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; link2.AddToPhysicsEngine = true; link2.Physics.Interactable = true; link2.Physics.Collidable = true; link2.Physics.Shape = ShapeType.Box; link2.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(link2); Vector3 pivot = location + parentTrans.Translation; Vector3 pin = Vector3.UnitY; pivot.X += size.X * 0.5f; pivot.Y -= size.Y * 0.5f; HingeJoint joint = new HingeJoint(pivot, pin); joint.NewtonHingeCallback = doubleDoor; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link2.Physics, link1.Physics, joint); } }