public static Matrix ToXNA(Body body, Transform transform)
 {
     Vector3 rot = transform.GetRotation();
     Matrix mat = body.Orientation * Matrix.CreateRotationY(rot.Y);
     mat.Translation = body.Position;
     return mat;
 }
示例#2
0
 public void GetLandmarkTransform(MapLandmark marker, Transform transform, BoundingBox meshBounds)
 {
     Vector4 param = landmarks[(int)marker];
     Vector3 pos = new Vector3(param.X, param.Y, param.Z);
     transform.SetPosition(pos);
     Vector3 rotation = transform.GetRotation();
     rotation.Y = param.W;
     transform.SetRotation(rotation);
     List<TriangleGraph> triangles;
     BoundingBox region = meshBounds;
     Vector3 sides = (meshBounds.Max - meshBounds.Min)*0.5f;
     region.Min = pos - sides;
     region.Max = pos + sides;
     region.Min.Y = this.Transformation.GetBounds().Min.Y;
     region.Max.Y = this.Transformation.GetBounds().Max.Y;
     if (GetTrianglesInRegion(RandomHelper.RandomGen, out triangles, region, true))
     {
         TriangleGraph bestTri = triangles[0];
         float bestDist = Vector3.DistanceSquared(bestTri.Centroid, pos);
         for (int i = 1; i < triangles.Count; i++)
         {
             float dist = Vector3.DistanceSquared(triangles[i].Centroid, pos);
             if (dist < bestDist)
             {
                 bestTri = triangles[i];
                 bestDist = dist;
             }
         }
         transform.SetPosition(bestTri.GeneratePointInTriangle(RandomHelper.RandomGen));
         BoundingBox newRegion = transform.TransformBounds(meshBounds);
         Vector3 offsetVector = Vector3.One * 5.0f;
         newRegion.Min = newRegion.Min - offsetVector;
         newRegion.Max = newRegion.Max + offsetVector;
         triangles = null;
         if (GetTrianglesInRegion(RandomHelper.RandomGen, out triangles, newRegion, true))
         {
             for (int i = 0; i < triangles.Count; i++)
             {
                 if(!usedLandmarkTriangles.ContainsKey(triangles[i].ID))
                     usedLandmarkTriangles.Add(triangles[i].ID, (char)1);
             }
         }
     }
 }