# Problem with bounding box in model space and intersection with ray

I have a bounding box in model space and I want to intersect it with a ray. I have tried to transform the ray like this. Rotating and scaling works well, but transition does not.

Here is my code:

Xbouding = new BoundingBox(new Vector3(50, 10, 10), new Vector3(120, -10, -10));

ray.Position = Vector3.Transform(ray.Position, Matrix.Invert(MathUtil.CreateWorldMatrix(Position, Rotation, Scale)));
ray.Direction= Vector3.Transform(ray.Direction, Matrix.Invert(MathUtil.CreateWorldMatrix(Position, Rotation, Scale)));
float? dist = ray.Intersects(Xbouding);


I have this:

I want to know if the ray from the mouse intersects with the boxes shown in the image. Pick works fine unless the model is translated (rotating and scaling works).

Another little question: what does float? mean? What's the difference between float and float??

• Position- and direction-vectors must be transformed differently. ray.Direction must be transformed using Vector3.TransformNormal, the position however must be transformed with Vector3.Transform as you already did. – Maik Semder Aug 9 '11 at 18:29

float? (or any typename appended with ?) is what's called a nullable type. Without that ? you would not be able to set the variable to null. Of course, nullable types incur an overhead -- if they didn't, all types would be nullable by default.