And the tests are straightforward and fast compute
302 |
|
|
---|
discriminant = (float)Math.Sqrt((double)discriminant);
float s0 = (-b + discriminant) / 2.0F;
float s1 = (-b - discriminant) / 2.0F;The picking ray extends infinitely, so there is a possibility that multiple objects can be intersected. The object closest to the camera is the one the user selected because it will always occlude the other selected objects.
Improving Intersection Accuracy
private bool IntersectRayMesh(Entity entity, int x, int y) {
PickingRay ray = ComputePickingRay(entity, x, y);
return entity.Mesh.Intersect(ray.Origin, ray.Direction); }
Using Built-In D3DX Functionality
near = new Vector3(x, y, 0);
far = new Vector3(x, y, 1);Matrix world = Matrix.Identity;
world.Translate(entity.Position);