PDA

View Full Version : Camera collision detection



settra88
10-31-2012, 03:22 PM
Hello everybody, I need your help.

I've made a 3d House, the only thing that I need is to make some camera based collision detection, but I really don't know how to do this, even after searching throw the internet.

This the code for the camera:


if (freelook_flag)
{
Matrix4x4 m;

//Changing visualization with mouse
buildRotationMatrix(camera.frame.Yaxis, deg2rad(-yrot), m);
transform(m, camera.frame.Xaxis);
transform(m, camera.frame.Yaxis);
transform(m, camera.frame.Zaxis);

//Keyboard moving

if (up_key)
{
camera.position.x += -camera.frame.Zaxis.x * speed;
camera.position.y += -camera.frame.Zaxis.y * speed;
camera.position.z += -camera.frame.Zaxis.z * speed;
}

if (down_key)
{
camera.position.x += camera.frame.Zaxis.x * speed;
camera.position.y += camera.frame.Zaxis.y * speed;
camera.position.z += camera.frame.Zaxis.z * speed;
}

if (left_key)
{
camera.position.x += -camera.frame.Xaxis.x * speed;
camera.position.y += -camera.frame.Xaxis.y * speed;
camera.position.z += -camera.frame.Xaxis.z * speed;
}

if (right_key)
{
camera.position.x += camera.frame.Xaxis.x * speed;
camera.position.y += camera.frame.Xaxis.y * speed;
camera.position.z += camera.frame.Xaxis.z * speed;
}

if (UPElevation_key)
{
camera.position.x += camera.frame.Yaxis.x * speed;
camera.position.y += camera.frame.Yaxis.y * speed;
camera.position.z += camera.frame.Yaxis.z * speed;
}

if (DownElevation_key)
{
camera.position.x += -camera.frame.Yaxis.x * speed;
camera.position.y += -camera.frame.Yaxis.y * speed;
camera.position.z += -camera.frame.Yaxis.z * speed;
}
}// fine if (freelook_flag)

pitch+=xrot;
if (pitch>90) pitch=90;
if (pitch<-90) pitch=-90;

Camera temp(camera);
Matrix4x4 m2;
buildRotationMatrix(temp.frame.Xaxis, deg2rad(pitch), m2);
transform(m2, temp.frame.Xaxis);
transform(m2, temp.frame.Yaxis);
transform(m2, temp.frame.Zaxis);

Matrix4x4 c;
buildCameraMatrix(temp,c);
glMultMatrixf(c.GL_array());

if (freelook_flag)
if(mouse_moved)
{
// pointer at the center of the window
mouse_moved=false;
glutWarpPointer(width/2, height/2);
}

And I have a method that changes the boolean for every key from true to false...

Can you help me?

tonyo_au
11-01-2012, 03:30 PM
Do you mean collision detection or camera movement? You don't seem to be moving anything.

uwi2k2
11-02-2012, 02:09 AM
hi,

pls give us some more info.
but basicly you camera has a position, so use this one to detect collission.
Yoi may need to take care of you near clipping plane, so you do not get display errors.

cu
uwi

settra88
11-02-2012, 02:42 AM
Yeah I mean the detection of the collision between the camera moviment and the environment