Public Group

# ray picking problems

This topic is 4186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a XY plane mesh, made from two triangles. Plane is a square 10x10 centered on the world's space origin. I'm trying to draw on plane and place objects on it. First the entire plane wont produce a collision, only the up left of the plane will produce a collision ( mustly negitive x values and positive y values only ) the camera is ortho position on positive z axis. i'm drawing a line form ray.origin to collision, debug. Anyways the ray origin doesnt appear to be in the right place, some times the entire ray does not appear on the screen, it lower right area of plane. Im not sure what the deal is, Placement of my objects. Or the actual ray picking code Near Clip Plane: 1.0 Far Clip Plane : 2000.0 Raypick code
      Matrix World =
Matrix.Scaling( _vScaling ) *
Matrix.RotationYawPitchRoll( _vRotation.Y, _vRotation.X, _vRotation.Z ) *
Matrix.Translation( _vPosition.GetDxVector3() );

Matrix projection = camera.ProjectionMatrix;
Matrix view = camera.ViewMatrix;

// Transform points to world space
Vector3 WorldNear = Vector3.Unproject( near, device.Viewport, projection , view , World );
Vector3 WorldFar = Vector3.Unproject( far, device.Viewport, projection , view , World );

IntersectInformation intInf = new IntersectInformation();
bool intersects = _Mesh.Intersect( WorldNear, WorldFar, out intInf );

if (intersects == true){
// save ray & IntersectInformation
_ray = new Ray( WorldNear, WorldFar - WorldNear );
}
Render plane
      Matrix matWorld =
Matrix.Scaling( _vScaling ) *
Matrix.RotationYawPitchRoll( _vRotation.Y, _vRotation.X, _vRotation.Z ) *
Matrix.Translation( _vPosition );

device.Transform.World = matWorld;
device.Transform.View = _viewport.Camera.ViewMatrix;
device.Transform.Projection = _viewport.Camera.ProjectionMatrix;

draw mesh code

line code
          Vector3 endpt = select._ray.Origin + select._ray.Direction * select.Hit.Dist;

Lines line = new Lines();
int c1 = Color.Red.ToArgb();
int c2 = c1;
line.CreateLine( select._ray.Origin, endpt, c1, c2 );


• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 12
• 13
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015482
×