Sign in to follow this  
caesar4

lookat transformation

Recommended Posts

for my 3d project, i have 2 render windows, in one i have the main camera, in the other i want to see the frustum of the main camera the frustum is a pyramid calculated from the FOV, and near&far planes and the eye is at <0,0,0> looking into the z-axis (negative or positive, doesnt matter) the camera has 3 components, a position, a look at point, and an up vector my question is: how to construct a transfromation matrix for the renderable view frustum? i dont need any1 telling me this:
Quote:
zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y zaxis.y 0 xaxis.z yaxis.z zaxis.z 0 -dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) 1
because that doesnt do wut i need

Share this post


Link to post
Share on other sites
not wut i meant,

i want to transform a couple lines representing the view frustum in world space, not any later stage in the transform pipe

Share this post


Link to post
Share on other sites
woops, i had a typo

heres my finishd code, to save someone the headache ive been havin


int CCamera::DrawFrustum(){
if(!this->ppDev)
return 0;

IDirect3DDevice9 *dev = (IDirect3DDevice9 *)this->ppDev->GetDevice();
if(!dev)
return 0;

CMatrix mat;
CVector dir = this->cfCurrent.vecPosition-this->cfCurrent.vecLookAt;
dir.Normalize();

float cx = sqrtf(dir.z*dir.z+dir.x*dir.x);
float cy = dir.z/cx

float roll = acosf(vecYP.Dot(this->cfCurrent.vecUp));
float elevation = acosf(cx);
float heading = acosf(cy);

if(dir.y > 0.f)
elevation=-elevation;
if(dir.x < 0.f)
heading = -heading;

mat = matIdentity.GetRotateAxisZ(roll);
mat.RotateAxisX(elevation);
mat.RotateAxisY(heading);
mat.Translate(this->cfCurrent.vecPosition.x,this->cfCurrent.vecPosition.y,this->cfCurrent.vecPosition.z);

this->Frustum[8].vecPosition = this->cfCurrent.vecLookAt;
this->Frustum[9].vecPosition = this->cfCurrent.vecPosition;

dev->SetTransform(D3DTS_WORLD,&matIdentity);
dev->SetFVF(this->Frustum->FVF);
dev->DrawPrimitiveUP(D3DPT_LINELIST,1,&this->Frustum[8],sizeof(this->Frustum[0]));

dev->SetTransform(D3DTS_WORLD,&mat);

dev->SetStreamSource(0,this->vbf,0,sizeof(this->Frustum[0]));
dev->SetIndices(this->ibf);
dev->DrawIndexedPrimitive(D3DPT_LINELIST,0,0,8,0,12);

return 1;
}

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