/// <summary> /// Builds a planar collision skin for the entity. /// </summary> /// <param name="normal">Normal of the plane.</param> /// <param name="distance"> /// Distance along the normal to the plane. For instance, if the normal is (0,1,0), that /// is, the Y axis, the created plane will be y = distance. /// </param> public void BuildCollisionPlane(Vector3 normal, float distance) { JigLibX.Geometry.Plane plane = new JigLibX.Geometry.Plane(normal, distance); mCollisionSkin.RemoveAllPrimitives(); mCollisionSkin.AddPrimitive(plane, mMaterialProperties); UpdateMaterialPropsOnCollisionSkin(); UpdateMass(); }
/// <summary> /// Set the dimensions of the chassis, specified by the extreme corner points. /// This will also call Car.SetupDefaultWheels(); /// </summary> /// <param name="min"></param> /// <param name="max"></param> public virtual void SetDims(Vector3 min, Vector3 max) { dimsMin = min; dimsMax = max; Vector3 sides = max - min; // ratio of top/bottom depths float topBotRatio = 0.4f; // the bottom box Vector3 min1 = min - new Vector3(-.5f, 0f, -0.2f); Vector3 max1 = max - new Vector3(+.5f, .0f, 0.2f); max1.Y -= topBotRatio * sides.Y; Box box1 = new Box(min1, Matrix.Identity, max1 - min1); // the top box Vector3 min2 = min; min2.Y += topBotRatio * sides.Y; Vector3 max2 = max; min2.X += 1.5f; max2.X -= 3f; min2.Z *= 0.5f; max2.Z *= 0.5f; Box box2 = new Box(min2, Matrix.Identity, max2 - min2); // the skid box Vector3 min3 = min1; Vector3 max3 = max1; max3.Y = min1.Y; min3.Y += -.1f; Box box3 = new Box(min3, Matrix.Identity, max3 - min3); // the waist box Vector3 min4 = min1; Vector3 max4 = max1; max4.Y = min1.Y + .45f; min4.Y += -.1f + .45f; max4.Z = max1.Z + .2f; min4.Z = min1.Z - .2f; max4.X = max1.X + .4f; min4.X = min1.X - .4f; Box box4 = new Box(min4, Matrix.Identity, max4 - min4); collisionSkin.RemoveAllPrimitives(); collisionSkin.AddPrimitive(box1, new MaterialProperties(0.3f, 0.9f, 0.9f)); collisionSkin.AddPrimitive(box2, new MaterialProperties(0.3f, 0.9f, 0.9f)); collisionSkin.AddPrimitive(box3, new MaterialProperties(0.0f, 0.0f, 0.0f)); collisionSkin.AddPrimitive(box4, new MaterialProperties(0.3f, 0.9f, 0.9f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collisionSkin); body.Car.SetupDefaultWheels(); }
/// <summary> /// Set the dimensions of the chassis, specified by the extreme corner points. /// This will also call Car.SetupDefaultWheels(); /// </summary> /// <param name="min"></param> /// <param name="max"></param> public virtual void SetDims(Vector3 min, Vector3 max) { dimsMin = min; dimsMax = max; Vector3 sides = max - min; // ratio of top/bottom depths float topBotRatio = 0.4f; // the bottom box Vector3 max1 = max; max1.Y -= topBotRatio * sides.Y; Box box1 = new Box(min, Matrix.Identity, max1 - min); // the top box Vector3 min2 = min; min2.Y += topBotRatio * sides.Y; Vector3 max2 = max; min2.X += sides.X * 0.05f; max2.X -= sides.X * 0.3f; min2.Z *= 0.9f; max2.Z *= 0.9f; Box box2 = new Box(min2, Matrix.Identity, max2 - min2); collisionSkin.RemoveAllPrimitives(); collisionSkin.AddPrimitive(box1, (int)MaterialTable.MaterialID.NormalNormal, new MaterialProperties(0.3f, 0.5f, 0.3f)); collisionSkin.AddPrimitive(box2, (int)MaterialTable.MaterialID.NormalNormal, new MaterialProperties(0.3f, 0.5f, 0.3f)); body.Car.SetupDefaultWheels(); }