World Ray problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

World Ray problem

Postby KingSnail » Thu Jan 07, 2010 7:11 am

Code: Select all
                        D3DXVECTOR3 v;
         D3DXMATRIX matProj = GetCamera().proj(); //Projection matrix
         v.x =  ( ( ( 2.0f * sx ) / ClientWidth  ) - 1 ) / matProj._11;
         v.y = -( ( ( 2.0f * sy ) / ClientHeight ) - 1 ) / matProj._22;
         v.z =  1.0f;

         D3DXMATRIX m;
         D3DXVECTOR3 rayOrigin,rayDir;

         D3DXMatrixInverse(&m, NULL, &Renderer.V);

         // Transform the screen space pick ray into 3D space
         rayDir.x  = v.x*m._11 + v.y*m._21 + v.z*m._31;
         rayDir.y  = v.x*m._12 + v.y*m._22 + v.z*m._32;
         rayDir.z  = v.x*m._13 + v.y*m._23 + v.z*m._33;
         rayOrigin.x = m._41;
         rayOrigin.y = m._42;
         rayOrigin.z = m._43;

         NewtonWorldRayCast(World, &rayOrigin[0], &rayDir[0], RayCastFilter, NULL, RayCastPrefilter);


I cant get the ray cast to work properly, Is the way I did it correct?
Right now it selects the objects in a place where its not meant to be, and detects more more then one where theres clearly only one object, or nothing at all (towards middle of the world)

Please help :cry:
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: World Ray problem

Postby KingSnail » Tue Jan 12, 2010 7:04 am

I am still struggling with this problem, hes some more info:

Code: Select all
+      _D3DVECTOR   {x=-0.65088683 y=-0.73363835 z=0.19524600 }   _D3DVECTOR //Ray direction
+      _D3DVECTOR   {x=158.53841 y=68.788170 z=10.339884 }   _D3DVECTOR //Ray Origin
+      _D3DVECTOR   {x=158.53841 y=68.788162 z=10.339886 }   _D3DVECTOR //Camera Pos


I want to send a ray from middle of screen which is 1920 / 2 width and 1200 / 2 height.
It ends up with those values above. The code I use is in the post above.

Please could someone have a look for me and try to identify why the ray is having strange problems as described in previous post.
Thanks
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: World Ray problem

Postby adam450 » Sat Jan 30, 2010 4:57 pm

When I first tested bullet rays, I had a camera, when I hit space, it captured the ray start and end. Then I could move around and see if that ray way correct. Make sure it draws right through the center of what you saw.
adam450
 
Posts: 21
Joined: Fri Jan 16, 2009 11:11 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 417 guests

cron