void calcRay(int x,int y,D3DVECTOR &p1,D3DVECTOR &p2)
{
float dx,dy;
D3DMATRIX invMatrix,viewMatrix;
dx=tanf(FOV*0.5f)*(x/WIDTH_DIV_2-1.0f)/ASPECT;
dy=tanf(FOV*0.5f)*(1.0f-y/HEIGHT_DIV_2);
lpDevice->GetTransform(D3DTRANSFORMSTATE_VIEW,&viewMatrix);
D3DMath_MatrixInvert(invMatrix,viewMatrix);
p1=D3DVECTOR(dx*NEAR,dy*NEAR,NEAR);
p2=D3DVECTOR(dx*FAR,dy*FAR,FAR);
D3DMath_VectorMatrixMultiply(p1,p1,invMatrix);
D3DMath_VectorMatrixMultiply(p2,p2,invMatrix);
}
Ray pick (again) ?
Hi all, i ran into a new problem with my ray picker.
Normal source :
This works nicely for a "*LEFT HAND" system, but how would i change it, to work in a "*RIGHT HAND" system ?
*LEFT HAND = D3DXMatrixLookAtLH + D3DXMatrixPerspectiveFovLH
*RIGHT HAND = D3DXMatrixLookAtRH + D3DXMatrixPerspectiveFovRH
For a right handed coordinate system you need to negate the Z components of your direction vector.
Thx that worked :)
btw, i just ran into another problem, what about "Ortho" views (both Left and Right Hand) ?
btw, i just ran into another problem, what about "Ortho" views (both Left and Right Hand) ?
Any know how to do the Ray when using D3DMatrixOrthoLH, D3DMatrixOrthoRH, please ?
edit : hmm, guess I need to use D3DXVec3Unproject , only problem is ; i dont use D3DX, and I wont use it until MS includes it (25/26) in the retail ver. of DX.
Any have the source for D3DXVec3Unproject ? or another way of doing it ?
[Edited by - Mythar on October 24, 2005 8:06:09 AM]
edit : hmm, guess I need to use D3DXVec3Unproject , only problem is ; i dont use D3DX, and I wont use it until MS includes it (25/26) in the retail ver. of DX.
Any have the source for D3DXVec3Unproject ? or another way of doing it ?
[Edited by - Mythar on October 24, 2005 8:06:09 AM]
Quote:Original post by Mythar
Any know how to do the Ray when using D3DMatrixOrthoLH, D3DMatrixOrthoRH, please ?
Umm, well unless I'm misunderstanding what you are trying to do, there is no need to ray pick objects drawn in ortho view: they are already in screen coordinates.
Matt
huh? if I dont use ray pick, how would I, pick objects in a view like this ? :
Edit : above image made with D3DMatrixOrthoRH
Edit : above image made with D3DMatrixOrthoRH
It depends on how you setup your ortho view. Two popular ways are as follows:
Width = Height = 1.0f
or
Width = 800, Height = 600 (for an 800x600 screen)
Either way you do it, you have to scale the vertices of the objects you draw. Taking your sphere as an example, and using an ortho of 0.0 to 1.0, you would have the vertices such that the left tangent of the sphere would reside at around 0.4f and the right around 0.6f. If you check the sphere's bounding sphere radius off center against the scaled mouse position (scaled from screen coords to 0.0 to 1.0 coords), you should determine if the sphere was clicked on.
In other words, the mouse click exactly at the center of the screen would yield 0.5f, 0.5f in coordinates of 0.0 to 1.0 or would yield 400x300 in pixel coordinates. Depending on how you setup your ortho projection, you'll have to scale from one to the other, which is simple. Then just take your mouse point, turn it into a vector with the origin at the center of the sphere, then see if it's magnitude is larger than the sphere's radius. There's probably a simpler way too, that doesn't require a square root. You could square the radius and compare that to the vector's squared magnitude.
Width = Height = 1.0f
or
Width = 800, Height = 600 (for an 800x600 screen)
Either way you do it, you have to scale the vertices of the objects you draw. Taking your sphere as an example, and using an ortho of 0.0 to 1.0, you would have the vertices such that the left tangent of the sphere would reside at around 0.4f and the right around 0.6f. If you check the sphere's bounding sphere radius off center against the scaled mouse position (scaled from screen coords to 0.0 to 1.0 coords), you should determine if the sphere was clicked on.
In other words, the mouse click exactly at the center of the screen would yield 0.5f, 0.5f in coordinates of 0.0 to 1.0 or would yield 400x300 in pixel coordinates. Depending on how you setup your ortho projection, you'll have to scale from one to the other, which is simple. Then just take your mouse point, turn it into a vector with the origin at the center of the sphere, then see if it's magnitude is larger than the sphere's radius. There's probably a simpler way too, that doesn't require a square root. You could square the radius and compare that to the vector's squared magnitude.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement