/// <summary> /// only used for the model /// </summary> /// <returns></returns> public Matrix GetWorldMatrix() { Matrix m = Matrix.Identity; //if(fParentPart!=null) //m = fParentPart.GetWorldMatrix(); /* * //ORIGINAL * if(Skin.NumPrimitives==0) * return m * Matrix.CreateScale(Scale) * body.Orientation * Matrix.CreateTranslation(body.Position); * else * return m * Matrix.CreateScale(Scale) * Skin.GetPrimitiveLocal(0).Transform.Orientation * body.Orientation * Matrix.CreateTranslation(body.Position) * Matrix.CreateTranslation(RelativeOrigin); */ if (Skin.NumPrimitives == 0) { return(m * Matrix.CreateScale(Scale) * body.Orientation * Matrix.CreateTranslation(body.Position)); } else { return(m * Matrix.CreateScale(Scale) * Skin.GetPrimitiveLocal(0).Transform.Orientation *body.Orientation *Matrix.CreateTranslation(body.Position)); } /* * no good * if (Skin.NumPrimitives == 0) * return m * body.Orientation * Matrix.CreateTranslation(body.Position); * else * return m * Skin.GetPrimitiveLocal(0).Transform.Orientation * body.Orientation * Matrix.CreateTranslation(body.Position) * Matrix.CreateTranslation(RelativeOrigin); */ }
//we will only add this method in a class that sub-classes CollidableObject e.g. PickupCollidableObject or PlayerCollidableObject //private bool CollisionSkin_callbackFn(CollisionSkin skin0, CollisionSkin skin1) //{ // return true; //} public override Matrix GetWorldMatrix() { return(Matrix.CreateScale(Transform3D.Scale) * collision.GetPrimitiveLocal(0).Transform.Orientation * body.Orientation * Transform3D.Orientation * Matrix.CreateTranslation(body.Position)); }
private Matrix GetWorldMatrix() { return (Matrix.CreateScale(scale) * _skin.GetPrimitiveLocal(0).Transform.Orientation * _body.Orientation * Matrix.CreateTranslation(_body.Position)); }
/// <summary> /// GetLocalSkinWireframe /// </summary> /// <param name="skin"></param> /// <returns>VertexPositionColor[]</returns> public static VertexPositionColor[] GetLocalSkinWireframe(this CollisionSkin skin) { List <VertexPositionColor> wireframe = new List <VertexPositionColor>(); // skip if there is no collision skin if (skin == null) { return(wireframe.ToArray()); } for (int i = 0; i < skin.NumPrimitives; i++) { Primitive p = skin.GetPrimitiveLocal(i); Matrix trans = p.TransformMatrix; if (p is Sphere) { Sphere np = (Sphere)p; List <Vector3> SpherePoints = calcCirclePoints(np.Radius); AddShapeToWireframe(SpherePoints, wireframe, trans, Color.Blue); AddShapeToWireframe(SpherePoints, wireframe, Matrix.CreateRotationY(MathHelper.PiOver2) * trans, Color.Red); AddShapeToWireframe(SpherePoints, wireframe, Matrix.CreateRotationX(MathHelper.PiOver2) * trans, Color.Green); } else if (p is Capsule) { Capsule np = (Capsule)p; List <Vector3> Ball = calcCirclePoints(np.Radius); List <Vector3> CylPoints = new List <Vector3>(); List <Vector3> CirclePoints = new List <Vector3>(); List <Vector3> SidePoints = new List <Vector3>(); // Create LongWays profile slice foreach (Vector3 v in Ball) { Vector3 t = Vector3.Transform(v, Matrix.CreateRotationX(MathHelper.PiOver2)); CylPoints.Add(t); } float len = np.Length; SidePoints.Add(Vector3.Transform(new Vector3(np.Radius, len, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); SidePoints.Add(Vector3.Transform(new Vector3(np.Radius, 0, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); SidePoints.Add(Vector3.Transform(new Vector3(-np.Radius, 0, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); SidePoints.Add(Vector3.Transform(new Vector3(-np.Radius, len, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); // Create Y Rungs AddShapeToWireframe(Ball, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0.0f * len)) * trans, Color.Green); AddShapeToWireframe(Ball, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0.5f * np.Length)) * trans, Color.Green); AddShapeToWireframe(Ball, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 1.0f * np.Length)) * trans, Color.Green); // Create Z Profile Matrix Zmat = Matrix.CreateRotationZ(MathHelper.PiOver2); AddShapeToWireframe(CylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, np.Length)) * Zmat * trans, Color.Blue); AddShapeToWireframe(CylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0)) * Zmat * trans, Color.Blue); AddLineToWireframe(SidePoints[0], SidePoints[1], wireframe, Zmat * trans, Color.Blue); AddLineToWireframe(SidePoints[2], SidePoints[3], wireframe, Zmat * trans, Color.Blue); //// Create X Profile Matrix Xmat = Matrix.Identity; AddShapeToWireframe(CylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, np.Length)) * Xmat * trans, Color.Red); AddShapeToWireframe(CylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0)) * Xmat * trans, Color.Red); AddLineToWireframe(SidePoints[0], SidePoints[1], wireframe, Xmat * trans, Color.Red); AddLineToWireframe(SidePoints[2], SidePoints[3], wireframe, Xmat * trans, Color.Red); } else if (p is Box) { Box np = (Box)p; List <Vector3> xPoints = new List <Vector3>(); List <Vector3> yPoints = new List <Vector3>(); List <Vector3> zPoints = new List <Vector3>(); Vector3 slen = np.SideLengths; xPoints.Add(new Vector3(slen.X, slen.Y, slen.Z)); xPoints.Add(new Vector3(0, slen.Y, slen.Z)); xPoints.Add(new Vector3(slen.X, 0, slen.Z)); xPoints.Add(new Vector3(0, 0, slen.Z)); xPoints.Add(new Vector3(slen.X, slen.Y, 0)); xPoints.Add(new Vector3(0, slen.Y, 0)); xPoints.Add(new Vector3(slen.X, 0, 0)); xPoints.Add(new Vector3(0, 0, 0)); yPoints.Add(new Vector3(slen.X, slen.Y, slen.Z)); yPoints.Add(new Vector3(slen.X, 0, slen.Z)); yPoints.Add(new Vector3(0, slen.Y, slen.Z)); yPoints.Add(new Vector3(0, 0, slen.Z)); yPoints.Add(new Vector3(slen.X, slen.Y, 0)); yPoints.Add(new Vector3(slen.X, 0, 0)); yPoints.Add(new Vector3(0, slen.Y, 0)); yPoints.Add(new Vector3(0, 0, 0)); zPoints.Add(new Vector3(slen.X, slen.Y, slen.Z)); zPoints.Add(new Vector3(slen.X, slen.Y, 0)); zPoints.Add(new Vector3(0, slen.Y, slen.Z)); zPoints.Add(new Vector3(0, slen.Y, 0)); zPoints.Add(new Vector3(slen.X, 0, slen.Z)); zPoints.Add(new Vector3(slen.X, 0, 0)); zPoints.Add(new Vector3(0, 0, slen.Z)); zPoints.Add(new Vector3(0, 0, 0)); AddLinesToWireframe(xPoints, wireframe, trans, Color.Red); AddLinesToWireframe(yPoints, wireframe, trans, Color.Green); AddLinesToWireframe(zPoints, wireframe, trans, Color.Blue); } else if (p is AABox) { } else if (p is Heightmap) { Heightmap hm = (Heightmap)p; Vector3 point, normal; for (int e = 0; e < hm.Heights.Nx; e += 5) { for (int j = 0; j < hm.Heights.Nz; j += 5) { hm.GetSurfacePosAndNormal(out point, out normal, e, j); AddLineToWireframe(point, point - 0.5f * normal, wireframe, trans, Color.GreenYellow); } } } else if (p is JigLibX.Geometry.Plane) { } else if (p is TriangleMesh) { TriangleMesh np = (TriangleMesh)p; for (int j = 0; j < np.GetNumTriangles(); j++) { IndexedTriangle t = np.GetTriangle(j); Vector3 p1 = np.GetVertex(t.GetVertexIndex(0)); Vector3 p2 = np.GetVertex(t.GetVertexIndex(1)); Vector3 p3 = np.GetVertex(t.GetVertexIndex(2)); List <Vector3> tPoints = new List <Vector3>(); tPoints.Add(p1); tPoints.Add(p2); tPoints.Add(p3); tPoints.Add(p1); AddShapeToWireframe(tPoints, wireframe, trans, Color.Red); } } } return(wireframe.ToArray()); }
public static VertexPositionColor[] GetLocalSkinWireframe(this CollisionSkin skin) { var wireframe = new List <VertexPositionColor>(); for (var i = 0; i < skin.NumPrimitives; i++) { var p = skin.GetPrimitiveLocal(i); var trans = p.TransformMatrix; if (p is Sphere) { var np = (Sphere)p; var spherePoints = CalcCirclePoints(np.Radius); AddShapeToWireframe(spherePoints, wireframe, trans, Color.Blue); AddShapeToWireframe(spherePoints, wireframe, Matrix.CreateRotationY(MathHelper.PiOver2) * trans, Color.Red); AddShapeToWireframe(spherePoints, wireframe, Matrix.CreateRotationX(MathHelper.PiOver2) * trans, Color.Green); } else if (p is Capsule) { var np = (Capsule)p; var ball = CalcCirclePoints(np.Radius); var cylPoints = new List <Vector3>(); var circlePoints = new List <Vector3>(); var sidePoints = new List <Vector3>(); foreach (var v in ball) { var t = Vector3.Transform(v, Matrix.CreateRotationX(MathHelper.PiOver2)); cylPoints.Add(t); } var len = np.Length; sidePoints.Add(Vector3.Transform(new Vector3(np.Radius, len, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); sidePoints.Add(Vector3.Transform(new Vector3(np.Radius, 0, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); sidePoints.Add(Vector3.Transform(new Vector3(-np.Radius, 0, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); sidePoints.Add(Vector3.Transform(new Vector3(-np.Radius, len, 0), Matrix.CreateRotationX(MathHelper.PiOver2))); AddShapeToWireframe(ball, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0.0f * len)) * trans, Color.Green); AddShapeToWireframe(ball, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0.5f * np.Length)) * trans, Color.Green); AddShapeToWireframe(ball, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 1.0f * np.Length)) * trans, Color.Green); var zmat = Matrix.CreateRotationZ(MathHelper.PiOver2); AddShapeToWireframe(cylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, np.Length)) * zmat * trans, Color.Blue); AddShapeToWireframe(cylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0)) * zmat * trans, Color.Blue); AddLineToWireframe(sidePoints[0], sidePoints[1], wireframe, zmat * trans, Color.Blue); AddLineToWireframe(sidePoints[2], sidePoints[3], wireframe, zmat * trans, Color.Blue); var xmat = Matrix.Identity; AddShapeToWireframe(cylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, np.Length)) * xmat * trans, Color.Red); AddShapeToWireframe(cylPoints, wireframe, Matrix.CreateTranslation(new Vector3(0, 0, 0)) * xmat * trans, Color.Red); AddLineToWireframe(sidePoints[0], sidePoints[1], wireframe, xmat * trans, Color.Red); AddLineToWireframe(sidePoints[2], sidePoints[3], wireframe, xmat * trans, Color.Red); } else if (p is Box) { var np = (Box)p; var xPoints = new List <Vector3>(); var yPoints = new List <Vector3>(); var zPoints = new List <Vector3>(); var slen = np.SideLengths; xPoints.Add(new Vector3(slen.X, slen.Y, slen.Z)); xPoints.Add(new Vector3(0, slen.Y, slen.Z)); xPoints.Add(new Vector3(slen.X, 0, slen.Z)); xPoints.Add(new Vector3(0, 0, slen.Z)); xPoints.Add(new Vector3(slen.X, slen.Y, 0)); xPoints.Add(new Vector3(0, slen.Y, 0)); xPoints.Add(new Vector3(slen.X, 0, 0)); xPoints.Add(new Vector3(0, 0, 0)); yPoints.Add(new Vector3(slen.X, slen.Y, slen.Z)); yPoints.Add(new Vector3(slen.X, 0, slen.Z)); yPoints.Add(new Vector3(0, slen.Y, slen.Z)); yPoints.Add(new Vector3(0, 0, slen.Z)); yPoints.Add(new Vector3(slen.X, slen.Y, 0)); yPoints.Add(new Vector3(slen.X, 0, 0)); yPoints.Add(new Vector3(0, slen.Y, 0)); yPoints.Add(new Vector3(0, 0, 0)); zPoints.Add(new Vector3(slen.X, slen.Y, slen.Z)); zPoints.Add(new Vector3(slen.X, slen.Y, 0)); zPoints.Add(new Vector3(0, slen.Y, slen.Z)); zPoints.Add(new Vector3(0, slen.Y, 0)); zPoints.Add(new Vector3(slen.X, 0, slen.Z)); zPoints.Add(new Vector3(slen.X, 0, 0)); zPoints.Add(new Vector3(0, 0, slen.Z)); zPoints.Add(new Vector3(0, 0, 0)); AddLinesToWireframe(xPoints, wireframe, trans, Color.Red); AddLinesToWireframe(yPoints, wireframe, trans, Color.Green); AddLinesToWireframe(zPoints, wireframe, trans, Color.Blue); } else if (p is AABox) { } else if (p is Heightmap) { var hm = (Heightmap)p; for (var e = 0; e < hm.Heights.Nx; e += 5) { for (var j = 0; j < hm.Heights.Nz; j += 5) { hm.GetSurfacePosAndNormal(out var point, out var normal, e, j); AddLineToWireframe(point, point - 0.5f * normal, wireframe, trans, Color.GreenYellow); } } } else if (p is Plane) { } else if (p is TriangleMesh) { var np = (TriangleMesh)p; for (var j = 0; j < np.GetNumTriangles(); j++) { var t = np.GetTriangle(j); var p1 = np.GetVertex(t.GetVertexIndex(0)); var p2 = np.GetVertex(t.GetVertexIndex(1)); var p3 = np.GetVertex(t.GetVertexIndex(2)); var tPoints = new List <Vector3>(); tPoints.Add(p1); tPoints.Add(p2); tPoints.Add(p3); tPoints.Add(p1); AddShapeToWireframe(tPoints, wireframe, trans, Color.Red); } } } return(wireframe.ToArray()); }