Today I wasted some time by doing this simple task.
I was following this article:
http:
There are several odd things here:
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);
}
Basically it's about the tanf and the ASPECT division:
It's supposed I want to get a value between 0..1 in dx and dy, but tanf was messing the stuff...
I think the aspect is assuming the width is bigger than height, which is not my case, since I am developing for mobile phones...
Well, now it's working so it's time to relax... :D
Comentarios
Publicar un comentario