Sign in to follow this  

ray picking problems

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 );

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this