Jump to content

  • Log In with Google      Sign In   
  • Create Account

Perspective to Ortho Collision fails.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 BornToCode   Members   -  Reputation: 925

Like
0Likes
Like

Posted 07 September 2012 - 10:50 PM

I guess the topic says it all. The problem that i am having is that i am creating a 3d editor, where you can switch from perspective to ortho or ortho to perspective however you see fit. Now the problem that i am having is that my collision code for the RayToOOBB works fine as long as i have a perspective matrix set up. As soon as i change the matrix to Ortho. The algorithm does not work, How does tool like 3d max handles that. I kind of figure that the same algorithm would work in ortho mode. If anyone have any idea on how to solve that problem i would be greatly appreciated. Here is the piece of code that is converting my mouse from 2d to 3d.

GLGXVECTOR3 mouseInWorld;
GLGXVECTOR3 rayPosition;
GLGXVECTOR3 rayDirection;

GLint viewport[4];glGetIntegerv(GL_VIEWPORT,viewport);

mouseInWorld.x = ((((2.0f*mousex)/(float)viewport[2])-1.0f)/perspectiveMatrix._11);
mouseInWorld.y = ((((2.0f*((float)viewport[3]-mousey))/(float)viewport[3])-1.0f)/perspectiveMatrix._22);
mouseInWorld.z = -1.0f;

GLGXMATRIX IViewInverse;
GLGXMatrixInverse(&IViewInverse,NULL,&cameraMatrix);
GLGXVec3TransformNormal(&rayDirection,&mouseInWorld,&IViewInverse);
rayPosition.x = IViewInverse._41;
rayPosition.y = IViewInverse._42;
rayPosition.z = IViewInverse._43;

Edited by BornToCode, 07 September 2012 - 10:52 PM.


Sponsor:

#2 Lauris Kaplinski   Members   -  Reputation: 841

Like
0Likes
Like

Posted 08 September 2012 - 03:27 AM

My matrix math is a bit rusty, but I think the problem is your calculation of rayposition.
For perspective projection viewray indeed starts from the point of camera and you only have to calculate the endpoint of ray.
For orthographic projection you have to calculate both the starting and endpoint of viewray from screen coordinates because each ray starts from different point.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

#3 BornToCode   Members   -  Reputation: 925

Like
0Likes
Like

Posted 08 September 2012 - 07:47 AM

So I need to convert my ray position to screen space correct.

#4 FLeBlanc   Crossbones+   -  Reputation: 3101

Like
2Likes
Like

Posted 08 September 2012 - 08:22 AM

It's not a matter of converting ray position to screen space. It's a matter of generating a ray for every screen position. For perspective, imagine the rays as streams of water squirting from a single nozzle and fanning out in a cone shape. The rays start from a common point and diverge. For orthographic, imagine the rays as coming from one of those fancy shower heads with hundreds of little nozzles all in a neat array. All the streams are parallel to each other, and the resulting spray shape is more cylindrical than conic. The rays never start from the same point, and in fact never cross each other (barring gravity, of course). It's the same idea with an ortho matrix. The idea of a single ray start position really makes no sense for an ortho projection. If you move your camera straight back, things on the screen remain exactly the same; there is no dwindling in size with distance, as there would be with rays that diverge from a single point.

#5 BornToCode   Members   -  Reputation: 925

Like
0Likes
Like

Posted 08 September 2012 - 09:59 AM

From what I understood from your post is that I need to figure out two different points in screen space. One at the camera position And one at the object position. If that is bot the case can you show me an example on how you would do it. Or do you mean I need to test multiple rays per object. If that is the case how do I compute those rays then.

Thanks.

#6 Lauris Kaplinski   Members   -  Reputation: 841

Like
2Likes
Like

Posted 08 September 2012 - 04:37 PM

No, you have to start from two points in screen space:
One at mouse position (x,y) and near plane (1) - this will be ray starting point if transformed to world space
Another at mouse position (x,y) and far plane (-1) - this will be ray endpoint if transformed to world space
Now after transforming these points to world space use these to construct your view ray.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

#7 BornToCode   Members   -  Reputation: 925

Like
0Likes
Like

Posted 11 September 2012 - 09:56 AM

Thanks alot. I got it working. Lauris Kaplinski i tried to give you a thumbs up but it was not letting me boost your reputation.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS