public BowlingPin(Game game, Model model, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(body); // add a capsule for the main corpus Primitive capsule = new Capsule(Vector3.Zero, Matrix.Identity, 0.1f, 1.3f); // add a small box at the buttom Primitive box = new Box(new Vector3(-0.1f,-0.1f,-0.1f), Matrix.Identity, Vector3.One * 0.2f); // add a sphere in the middle Primitive sphere = new Sphere(new Vector3(0.0f, 0.0f, 0.3f), 0.3f); collision.AddPrimitive(capsule, new MaterialProperties(0.1f, 0.5f, 0.5f)); collision.AddPrimitive(box, new MaterialProperties(0.1f, 0.5f, 0.5f)); collision.AddPrimitive(sphere, new MaterialProperties(0.1f, 0.5f, 0.5f)); body.CollisionSkin = this.collision; Vector3 com = SetMass(0.5f); body.MoveTo(position, orientation); collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); body.EnableBody(); this.scale = Vector3.One * 10.0f; }
public CylinderObject(Game game, float radius, float length, Vector3 position, Model model) : base(game, model) { body = new Body(); collision = new CollisionSkin(body); if (length - 2.0f * radius < 0.0f) throw new ArgumentException("Radius must be at least half length"); Capsule middle = new Capsule(Vector3.Zero, Matrix.Identity, radius, length - 2.0f * radius); float sideLength = 2.0f * radius / (float) Math.Sqrt(2.0d); Vector3 sides = new Vector3(-0.5f * sideLength, -0.5f * sideLength, -radius); Box supply0 = new Box(sides, Matrix.Identity, new Vector3(sideLength, sideLength, length)); Box supply1 = new Box(Vector3.Transform(sides,Matrix.CreateRotationZ(MathHelper.PiOver4)), Matrix.CreateRotationZ(MathHelper.PiOver4), new Vector3(sideLength, sideLength, length)); collision.AddPrimitive(middle, new MaterialProperties(0.8f, 0.8f, 0.7f)); collision.AddPrimitive(supply0, new MaterialProperties(0.8f, 0.8f, 0.7f)); collision.AddPrimitive(supply1, new MaterialProperties(0.8f, 0.8f, 0.7f)); body.CollisionSkin = this.collision; Vector3 com = SetMass(1.0f); collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); #region Manually set body inertia float cylinderMass = body.Mass; float comOffs = (length - 2.0f * radius) * 0.5f; ; float Ixx = 0.5f * cylinderMass * radius * radius + cylinderMass * comOffs * comOffs; float Iyy = 0.25f * cylinderMass * radius * radius + (1.0f / 12.0f) * cylinderMass * length * length + cylinderMass * comOffs * comOffs; float Izz = Iyy; body.SetBodyInertia(Ixx, Iyy, Izz); #endregion body.MoveTo(position, Matrix.CreateRotationX(MathHelper.PiOver2)); body.EnableBody(); this.scale = new Vector3(radius, radius, length * 0.5f); }
// TODO: Need to add png parameter public HeightMapModel(Game game, Model m, Boolean t, Vector3 pos, float scale) : base(game, m, t, pos, scale, true) { Body = new Body(); // just a dummy. The PhysicObject uses its position to get the draw pos Skin = new CollisionSkin(null); HeightMapInfo heightMapInfo = this.model.Tag as HeightMapInfo; Array2D field = new Array2D(heightMapInfo.heights.GetUpperBound(0), heightMapInfo.heights.GetUpperBound(1)); for (int x = 0; x < heightMapInfo.heights.GetUpperBound(0); x++) { for (int z = 0; z < heightMapInfo.heights.GetUpperBound(1); z++) { field.SetAt(x, z, heightMapInfo.heights[x, z]); } } // move the body. The body (because its not connected to the collision // skin) is just a dummy. But the base class shoudl know where to // draw the model. Body.MoveTo(this.Position, Matrix.Identity); Skin.AddPrimitive(new Heightmap(field, 0f, 0f, 1, 1), new MaterialProperties(0.7f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(this.Skin); }
public TriangleMeshActor(Game game, Vector3 position, float scale, Texture2D heightMap, float[,] heightData) : base(game) { this.position = position; this.scale = new Vector3(1,1,1); _body = new Body(); _body.MoveTo(position, Matrix.Identity); Array2D field = new Array2D(heightData.GetUpperBound(0), heightData.GetUpperBound(1)); int upperZ = heightData.GetUpperBound(1); for (int x = 0; x < heightData.GetUpperBound(0); x++) { for (int z = 0; z < upperZ; z++) { field.SetAt(x, z, heightData[x, upperZ - 1 - z]); } } _skin = new CollisionSkin(null); float X = heightMap.Width / 2 * scale; float Z = heightMap.Height / 2 * scale; _skin.AddPrimitive(new Heightmap(field, X, -Z, scale, scale), new MaterialProperties(0.7f, 0.7f, 0.6f)); _skin.ExternalData = this; PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(_skin); }
public override void OnAdd(Scene scene) { this.scene = scene; this.interactTrigger.OnAdd(scene); if (useCollisionTransform) { Transform oldTransform = Transformation; if (mesh.GetCollisionMesh() != null) { collision = new CollisionSkin(null); collision.AddPrimitive(mesh.GetCollisionMesh(), (int)MaterialTable.MaterialID.NotBouncyRough); scene.GetPhysicsEngine().CollisionSystem.AddCollisionSkin(collision); } Transformation = new CollisionTransform(this.collision, scene); Transformation.SetPosition(oldTransform.GetPosition()); Transformation.SetRotation(oldTransform.GetRotation()); Transformation.SetScale(oldTransform.GetScale()); oldTransform = null; } else base.OnAdd(scene); }
public HeightmapObject(Game game, Model model,Vector2 shift) : base(game, model) { body = new Body(); // just a dummy. The PhysicObject uses its position to get the draw pos collision = new CollisionSkin(null); HeightMapInfo heightMapInfo = model.Tag as HeightMapInfo; Array2D field = new Array2D(heightMapInfo.heights.GetUpperBound(0), heightMapInfo.heights.GetUpperBound(1)); for (int x = 0; x < heightMapInfo.heights.GetUpperBound(0); x++) { for (int z = 0; z < heightMapInfo.heights.GetUpperBound(1); z++) { field.SetAt(x,z,heightMapInfo.heights[x,z]); } } // move the body. The body (because its not connected to the collision // skin) is just a dummy. But the base class shoudl know where to // draw the model. body.MoveTo(new Vector3(shift.X,0,shift.Y), Matrix.Identity); collision.AddPrimitive(new Heightmap(field, shift.X, shift.Y, 1, 1), new MaterialProperties(0.7f,0.7f,0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision); }
void Setup(HeightMapInfo heightMapInfo, Vector2 shift) { // A dummy. The physics object uses its position to get draw pos Body = new Body(); CollisionSkin = new CollisionSkin(null); info = heightMapInfo; Array2D field = new Array2D(heightMapInfo.Heights.GetUpperBound(0), heightMapInfo.Heights.GetUpperBound(1)); for (int x = 0; x < heightMapInfo.Heights.GetUpperBound(0); ++x) { for (int z = 0; z < heightMapInfo.Heights.GetUpperBound(1); ++z) { field.SetAt(x, z, heightMapInfo.Heights[x, z]); } } // Move dummy body. The body isn't connected to the collision skin. // But the base class should know where to draw the model. Body.MoveTo(new Vector3(shift.X, 0, shift.Y), Matrix.Identity); CollisionSkin.AddPrimitive(new Heightmap(field, shift.X, shift.Y, 1, 1), new MaterialProperties(0.7f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(CollisionSkin); }
public override void Initialise() { base.Initialise(); // Create new bodey and collision skin m_Body = new Body(); m_Skin = new CollisionSkin(m_Body); if (m_Body != null) { // Set skin to the body m_Body.CollisionSkin = m_Skin; // Check the skin was successfully created and add this // custom dice as a primitive to the collision skin if (m_Skin != null) { Box box = new Box(Vector3.Zero, Matrix.Identity, transform.Scale); m_Skin.AddPrimitive(box, (int)MaterialTable.MaterialID.BouncyNormal); // Set mass m_Mass = SetMass(1.0f); // Move the body to correct position initially m_Body.MoveTo(transform.Position, Matrix.Identity); // Apply transform to skin m_Skin.ApplyLocalTransform(new JigLibX.Math.Transform(-m_Mass, Matrix.Identity)); // Enable body EnableBody(); } } }
public HeightmapObject(Model model,Vector2 shift, Vector3 position) : base() { Body = new Body(); // just a dummy. The PhysicObject uses its position to get the draw pos Skin = new CollisionSkin(null); HeightMapInfo heightMapInfo = model.Tag as HeightMapInfo; Array2D field = new Array2D(heightMapInfo.heights.GetLength(0), heightMapInfo.heights.GetLength(1)); for (int x = 0; x < heightMapInfo.heights.GetLength(0); x++) { for (int z = 0; z < heightMapInfo.heights.GetLength(1); z++) { field.SetAt(x,z,heightMapInfo.heights[x,z]); } } // move the body. The body (because its not connected to the collision // skin) is just a dummy. But the base class shoudl know where to // draw the model. Body.MoveTo(new Vector3(shift.X,0,shift.Y), Matrix.Identity); Skin.AddPrimitive(new Heightmap(field, shift.X, shift.Y, heightMapInfo.terrainScale, heightMapInfo.terrainScale), new MaterialProperties(0.7f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(Skin); CommonInit(position, new Vector3(1,1,1), model, false, 0); }
public override void SetSkinAndBody() { Body = new Body(); Skin = new CollisionSkin(null); Skin.AddPrimitive(new JigLibX.Geometry.Plane(Vector3.Up, 0f), new MaterialProperties(0.2f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(Skin); }
public HeightMapModel2(Game game, HeightMap info, Boolean t, Vector3 pos, float scale) : base(game , null, t, pos, scale) { // Game game, Model m, Boolean t, Vector3 pos, float scale, Boolean solid //Game game, HeightMap m, Boolean t, Vector3 pos, float scale this.Visible = false; Body = new Body(); Skin = new CollisionSkin(null); //Skin.CollisionType = (int)CollisionTypes.Terrain; Array2D field = new Array2D(info.heights.GetUpperBound(0), info.heights.GetUpperBound(1)); for (int x = 0; x < info.heights.GetUpperBound(0); x++) { for (int z = 0; z < info.heights.GetUpperBound(1); z++) { field.SetAt(x, z, info.heights[x, z]); } } Body.MoveTo(new Vector3(info.heightmapPosition.X, info.heightmapPosition.Y, info.heightmapPosition.Y), Matrix.Identity); Skin.AddPrimitive(new Heightmap(field, info.heightmapPosition.X, info.heightmapPosition.Y, scale, scale), (int)MaterialTable.MaterialID.NotBouncyRough); Body.Immovable = true; PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(Skin); }
public Missile(ParentGame game, Model modelObj, Texture2D[] modelTextures, DrawingClass drawClass, GameplayScreen Screen) : base(game, modelObj, modelTextures) { this.drawClass = drawClass; this.Screen = Screen; _body = new Body(); _skin = new CollisionSkin(_body); _body.CollisionSkin = _skin; Box box = new Box(Vector3.Zero, Matrix.Identity, new Vector3(1f,1f,4f)); _skin.AddPrimitive(box, new MaterialProperties(0.8f, 0.8f, 0.7f)); Vector3 com = SetMass(2.0f); _body.MoveTo(position, Matrix.Identity); _skin.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); _body.EnableBody(); Body.ExternalData = this; Vector3 pos = position; Vector3 forwardVec = Body.Orientation.Forward; forwardVec.Normalize(); pos -= forwardVec * 10; // Use the particle emitter helper to output our trail particles. trailEmitter = new ParticleEmitter(drawClass.projectileTrailParticles, trailParticlesPerSecond, position); rgob = new RagdollObject(parentGame, null, null, null, RagdollObject.RagdollType.Simple, 1.0f, 3); rgob.Position = position; //rgob.PutToSleep(); //rgob.limbs[0].PhysicsBody.AngularVelocity = (new Vector3(1, 1, 0) * 2000); RagdollTransforms = new List<Matrix>(); RagdollTransforms = rgob.GetWorldMatrix(); foreach (JigLibX.Objects.PhysicObject lim in rgob.limbs) DisableCollisions(lim.PhysicsBody, Body); foreach (JigLibX.Objects.PhysicObject lim in rgob.limbs) foreach (BuildingPiece pic in Screen.PieceList) DisableCollisions(lim.PhysicsBody, pic.Body); foreach (JigLibX.Objects.PhysicObject lim in rgob.limbs) foreach (Building bld in Screen.Buildings) DisableCollisions(lim.PhysicsBody, bld.Body); foreach (JigLibX.Objects.PhysicObject lim in rgob.limbs) DisableCollisions(lim.PhysicsBody, Screen.terrainActor.Body); foreach (JigLibX.Objects.PhysicObject limb0 in rgob.limbs) foreach (Missile mis in Screen.BulletList) foreach (JigLibX.Objects.PhysicObject limb1 in mis.rgob.limbs) DisableCollisions(limb1.PhysicsBody, limb0.PhysicsBody); }
public PlaneObject(Game game, Model model, float d) : base(game, model) { body = new Body(); collision = new CollisionSkin(null); collision.AddPrimitive(new JigLibX.Geometry.Plane(Vector3.Up, d), new MaterialProperties(0.2f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision); }
public PlaneObject(Model model,float d, Vector3 position, int asset) : base() { Body = new Body(); Skin = new CollisionSkin(null); Skin.AddPrimitive(new JigLibX.Geometry.Plane(Vector3.Up, d), new MaterialProperties(0.2f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(Skin); CommonInit(position, new Vector3(1,1,1), model, false, asset); }
// Setup everything void Setup() { // We can't use InitializeBody() here because we want to add a // plane and not have it fall Body = new Body(); CollisionSkin = new CollisionSkin(null); CollisionSkin.AddPrimitive( new JigLibX.Geometry.Plane(Vector3.Up, 0.0f), new MaterialProperties(0.2f, 0.7f, 0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(CollisionSkin); }
public SphereObject(Game game, Model model,float radius, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(body); collision.AddPrimitive(new Sphere(Vector3.Zero * 5.0f,radius), new MaterialProperties(0.5f,0.7f,0.6f)); body.CollisionSkin = this.collision; Vector3 com = SetMass(10.0f); body.MoveTo(position + com, orientation); // collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); body.EnableBody(); this.scale = Vector3.One * radius; }
public BoxObject(Game game,Model model,Vector3 sideLengths, Matrix orientation, Vector3 position) : base(game,model) { body = new Body(); collision = new CollisionSkin(body); collision.AddPrimitive(new Box(- 0.5f * sideLengths, orientation, sideLengths), new MaterialProperties(0.8f, 0.8f, 0.7f)); body.CollisionSkin = this.collision; Vector3 com = SetMass(1.0f); body.MoveTo(position, Matrix.Identity); collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); body.EnableBody(); this.scale = sideLengths; }
public TestObject(Game game,Model model) : base(game,model) { body = new Body(); collision = new CollisionSkin(body); Box boxMiddle = new Box(new Vector3(-3, 0 ,-0.5f), Matrix.Identity, new Vector3(6,1,1)); Box boxLeft = new Box(new Vector3(-3, -3f, -0.5f), Matrix.Identity, new Vector3(1, 4, 1)); Box boxRight = new Box(new Vector3(2, -3f, -0.5f), Matrix.Identity, new Vector3(1, 4, 1)); collision.AddPrimitive(boxMiddle, new MaterialProperties(0.2f, 0.7f, 0.6f)); collision.AddPrimitive(boxLeft, new MaterialProperties(0.2f, 0.7f, 0.6f)); collision.AddPrimitive(boxRight, new MaterialProperties(0.2f, 0.7f, 0.6f)); body.CollisionSkin = this.collision; Vector3 com = SetMass(1.0f); // collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); body.MoveTo(Vector3.Up * 10, Matrix.Identity); //body.Immovable = true; body.EnableBody(); }
public override void OnAdd(Scene scene) { base.OnAdd(scene); if (false == true && mesh.GetCollisionMesh() != null) { Matrix currOrientation = Transformation.GetTransform(); currOrientation.Translation = Vector3.Zero; Vector3 currPosition = Transformation.GetPosition(); collisionTransform = new JigLibX.Math.Transform(currPosition, currOrientation); collision = new CollisionSkin(null); collision.AddPrimitive(mesh.GetCollisionMesh(), (int)MaterialTable.MaterialID.NotBouncyRough); scene.GetPhysicsEngine().CollisionSystem.AddCollisionSkin(collision); collision.SetNewTransform(ref collisionTransform); } }
public CapsuleObject(Game game, Model model,float radius,float length, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(body); collision.AddPrimitive(new Capsule(Vector3.Transform(new Vector3(-0.5f,0,0), orientation),orientation,radius,length),(int)MaterialTable.MaterialID.BouncyNormal); body.CollisionSkin = this.collision; Vector3 com = SetMass(10.0f); body.MoveTo(position + com, Matrix.Identity); collision.ApplyLocalTransform(new Transform(-com,Matrix.Identity)); body.EnableBody(); this.scale = new Vector3(radius, radius, length / 2); }
public Cuboid(Vector dimension) { Dimension = dimension; PhysicsBody = new Body(); collisionSkin = new CollisionSkin(PhysicsBody); PhysicsBody.CollisionSkin = collisionSkin; var box = new Box(Vector3.Zero, Microsoft.Xna.Framework.Matrix.Identity, Dimension.ToXna()); collisionSkin.AddPrimitive(box, new MaterialProperties(0.1f, 0.4f, 0.9f)); var com = ApplyMass(1.0f); // PhysicsBody.MoveTo(Utils.VectorBalderToXna(this.Position), Microsoft.Xna.Framework.Matrix.Identity); collisionSkin.ApplyLocalTransform(new JigLibX.Math.Transform(-com, Microsoft.Xna.Framework.Matrix.Identity)); PhysicsBody.EnableBody(); }
public BuildingPiece(ParentGame game, Model modelObj, Texture2D[] modelTextures, DrawingClass drawClass, GameplayScreen Screen, float Length, float Width, float Height) : base(game, modelObj, modelTextures) { // Use the particle emitter helper to output our trail particles. trailEmitter = new ParticleEmitter(drawClass.smokePlumeParticles, 3, position); fireEmitter = new ParticleEmitter(drawClass.fireParticles, 30, position); this.Screen = Screen; this.drawClass = drawClass; _body = new Body(); _skin = new CollisionSkin(_body); _body.CollisionSkin = _skin; //Box box = new Box(Vector3.Zero, Matrix.Identity, new Vector3(10f, 7f, 7f)); Box box = new Box(Vector3.Zero, Matrix.Identity, new Vector3(Length, Width, Height)); if (Length > Width && Length > Height) boundSphere.Radius = Length; else if (Width > Length && Width > Height) boundSphere.Radius = Width; else boundSphere.Radius = Height; _skin.AddPrimitive(box, new MaterialProperties(0.8f, 0.8f, 0.7f)); Vector3 com = SetMass(3.0f); _body.MoveTo(position, Matrix.Identity); _skin.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); _body.EnableBody(); Body.ExternalData = this; SetBody(rotation); Body.AllowFreezing = true; Body.SetDeactivationTime(1); foreach (BuildingPiece pic in Screen.PieceList) DisableCollisions(this.Body, pic.Body); foreach (Building bld in Screen.Buildings) DisableCollisions(this.Body, bld.Body); }
public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(null); triangleMesh = new TriangleMesh(); List<Vector3> vertexList = new List<Vector3>(); List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>(); ExtractData(vertexList, indexList, model); triangleMesh.CreateMesh(vertexList,indexList, 4, 1.0f); collision.AddPrimitive(triangleMesh,new MaterialProperties(0.8f,0.7f,0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision); }
public BoxActor(Game game, Vector3 position, Vector3 scale) : base(game) { this.position = position; this.scale = scale; _body = new Body(); _skin = new CollisionSkin(_body); _body.CollisionSkin = _skin; Box box = new Box(Vector3.Zero, Matrix.Identity, scale); _skin.AddPrimitive(box, new MaterialProperties(0.8f, 0.8f, 0.7f)); Vector3 com = SetMass(1.0f); _body.MoveTo(position, Matrix.Identity); _skin.ApplyLocalTransform(new JigLibX.Math.Transform(-com, Matrix.Identity)); _body.EnableBody(); }
protected override void LoadSpecific() { base.LoadSpecific(); // Create new bodey and collision skin m_Body = new Body(); m_Skin = new CollisionSkin(m_Body); if (m_Body != null) { // Set skin to the body m_Body.CollisionSkin = m_Skin; // Check the skin was successfully created and add this // custom dice as a primitive to the collision skin if (m_Skin != null) { Vector3 sideLengths = (m_BoundingBox.Max - m_BoundingBox.Min); if (sideLengths.Y <= 0) sideLengths.Y = 0.1f; Matrix rotMat = Matrix.CreateFromQuaternion(transform.Rotation); Box box = new Box(Vector3.Zero, Matrix.Identity, sideLengths); m_Skin.AddPrimitive(box, (int)MaterialTable.MaterialID.BouncyNormal); // Set mass m_Mass = SetMass(1.0f); // Move the body to correct position initially m_Body.MoveTo(transform.Position, Matrix.Identity); // Apply transform to skin m_Skin.ApplyLocalTransform(new JigLibX.Math.Transform(-m_Mass, Matrix.Identity)); // Enable it Enable(); // Set to immovable m_Body.Immovable = true; } } }
public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(null); triangleMesh = new TriangleMesh(); List<Vector3> vertexList = new List<Vector3>(); List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>(); ExtractData(vertexList, indexList, model); triangleMesh.CreateMesh(vertexList,indexList, 4, 1.0f); collision.AddPrimitive(triangleMesh,new MaterialProperties(0.8f,0.7f,0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision); // Transform collision.ApplyLocalTransform(new JigLibX.Math.Transform(position, orientation)); // we also need to move this dummy, so the object is *rendered* at the correct positiob body.MoveTo(position, orientation); }
public override void OnAdd(Scene scene) { base.OnAdd(scene); scene.AddActor(this); PhysicsSystem world = scene.GetPhysicsEngine(); Vector3 pos = Vector3.Up * 256 + 15*(new Vector3((float)RandomHelper.RandomGen.NextDouble(), (float)RandomHelper.RandomGen.NextDouble(), (float)RandomHelper.RandomGen.NextDouble())*2-Vector3.One); //pos.X += (scene.MainTerrain as TerrainHeightmap).GetWidth()*0.5f; //pos.Z += (scene.MainTerrain as TerrainHeightmap).GetDepth() * 0.5f; Vector3 normal = Vector3.Up; //scene.MainTerrain.GenerateRandomTransform(RandomHelper.RandomGen, out pos, out normal); //pos = pos + Vector3.Up * 5; body = new CharacterBody(); collision = new CollisionSkin(body); standCapsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.778f); crouchCapsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.0f); SetupPosture(false); collision.AddPrimitive(standCapsule, (int)MaterialTable.MaterialID.NormalRough); body.CollisionSkin = collision; Vector3 com = PhysicsHelper.SetMass(75.0f, body, collision); body.MoveTo(pos + com, Matrix.Identity); collision.ApplyLocalTransform(new JigLibX.Math.Transform(-com, Matrix.Identity)); body.SetBodyInvInertia(0.0f, 0.0f, 0.0f); body.AllowFreezing = false; body.EnableBody(); Transformation = new Transform(body); ResetState(); }
void GenerateCollisionMesh(VoxelGeometry geometry) { List<Vector3> vertices = new List<Vector3>(geometry.verts.Length); List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>(geometry.ib.Length / 3); Matrix transform = this.Transformation.GetTransform(); for (int i = 0; i < geometry.verts.Length; i++) vertices.Add(Vector3.Transform(geometry.verts[i].Position, transform)); for (int i = 0; i < geometry.ib.Length; i += 3) { TriangleVertexIndices tri = new TriangleVertexIndices(geometry.ib[i + 2], geometry.ib[i + 1], geometry.ib[i]); indices.Add(tri); } TriangleMesh collisionMesh = new TriangleMesh(vertices, indices); CollisionSkin collision = new CollisionSkin(null); collision.AddPrimitive(collisionMesh, (int)MaterialTable.MaterialID.NotBouncyRough); CollisionSkin collision2 = new CollisionSkin(null); collision2.AddPrimitive(new JigLibX.Geometry.Plane(Vector3.Up, Transformation.GetBounds().Min.Y-3f), (int)MaterialTable.MaterialID.NotBouncyRough); scene.GetPhysicsEngine().CollisionSystem.AddCollisionSkin(collision); //scene.GetPhysicsEngine().CollisionSystem.AddCollisionSkin(collision2); }
void CreateCollisionMesh() { collision = new CollisionSkin(null); Array2D field = new Array2D(width, depth); for (int x = 0; x < width; x++) { for (int z = 0; z < depth; z++) { field.SetAt(x, z, heightValues[x + z * width]); } } collision.AddPrimitive(new Heightmap(field, width*0.5f, depth*0.5f, 1, 1), new MaterialProperties(0.1f, 0.02f, 0.9f)); scene.GetPhysicsEngine().CollisionSystem.AddCollisionSkin(collision); }
public override void Initialize() { Body = new Body(); Skin = new CollisionSkin(Body); Body.CollisionSkin = Skin; radius = 12; float length = 3; //Capsule middle = new Capsule(Vector3.Zero, Matrix.Identity, radius, length - 2.0f * radius); float sideLength = 2.0f * radius / (float)Math.Sqrt(2.0d); Vector3 sides = new Vector3(-0.5f * sideLength, -0.5f * sideLength, -radius); Box supply0 = new Box(sides, Matrix.Identity, new Vector3(sideLength, sideLength, length)); Box supply1 = new Box(Vector3.Transform(sides, Matrix.CreateRotationZ(MathHelper.PiOver4)), Matrix.CreateRotationZ(MathHelper.PiOver4), new Vector3(sideLength, sideLength, length)); Box supply2 = new Box(Vector3.Transform(sides, Matrix.CreateRotationZ( (MathHelper.PiOver4 * 0.5f) )), Matrix.CreateRotationZ( (MathHelper.PiOver4 * 0.5f) ), new Vector3(sideLength, sideLength, length)); Box supply3 = new Box(Vector3.Transform(sides, Matrix.CreateRotationZ((MathHelper.PiOver4 * 1.5f))), Matrix.CreateRotationZ((MathHelper.PiOver4 * 1.5f)), new Vector3(sideLength, sideLength, length)); //Skin.AddPrimitive(middle, new MaterialProperties(0.8f, 0.8f, 0.7f)); Skin.AddPrimitive(supply0, new MaterialProperties(0.8f, 0.8f, 0.7f)); Skin.AddPrimitive(supply1, new MaterialProperties(0.8f, 0.8f, 0.7f)); Skin.AddPrimitive(supply2, new MaterialProperties(0.8f, 0.8f, 0.7f)); Skin.AddPrimitive(supply3, new MaterialProperties(0.8f, 0.8f, 0.7f)); Vector3 com = SetMass(1.0f); Body.MoveTo(position, Matrix.Identity); Skin.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); #region Manually set body inertia float cylinderMass = Body.Mass; float comOffs = (length - 2.0f * radius) * 0.5f; ; float Ixx = 0.5f * cylinderMass * radius * radius + cylinderMass * comOffs * comOffs; float Iyy = 0.25f * cylinderMass * radius * radius + (1.0f / 12.0f) * cylinderMass * length * length + cylinderMass * comOffs * comOffs; float Izz = Iyy; Body.SetBodyInertia(Ixx, Iyy, Izz); #endregion Body.EnableBody(); Body.ExternalData = this; SetBody(rotation); }