public void HitTest(Ray ray, ref CollisionModelHitTestResult result) { if (this.Model.Mesh == null) { return; } if (this.Model.Mesh.Groups == null) { return; } var invTrans = Matrix.Invert(this.Transform); ray.Position = invTrans.TransformCoord(ray.Position); ray.Direction = invTrans.TransformNormal(ray.Direction); ray.Direction.Normalize(); var collisionGroup = this.Model.Mesh.Groups.ToArray(); foreach (var group in collisionGroup) { foreach (var theTriangle in group.Triangles) { var triangle = theTriangle; float distance; if (ray.Intersects(ref triangle.v1, ref triangle.v2, ref triangle.v3, out distance)) { var normal = HangarScene.CalculateNormal(ref triangle.v1, ref triangle.v2, ref triangle.v3); normal.Normalize(); var dot = Math.Abs(Vector3.Dot(ray.Direction, -normal)); result.Hits.Add(new CollisionModelHit() { Distance = distance, Armor = group.ArmorGroup, InjectionCosine = dot, Mesh = this.Model.Mesh }); } } } }
public ModuleModelRenderer(HangarScene owner) { _owner = owner; }