Camera Collision

Started by
3 comments, last by Medo Mex 11 years, 5 months ago
I'm trying to create first person shooter camera and the problem I'm having is that the camera is intersecting with all the meshes, I'm trying to make the camera act like in physical world (it should never intersect with any mesh).

Can I do that using Bullet Physics?

Any help will be greatly appreciated.
Advertisement
Yes, but it's not "built in".
You will need to either use sweeping or a ghost object to predict if a camera can move in a certain direction or not.

Actually, I don't suggest to do that. I suggest to track the position of a given entity instead, resolve entity movement independently and then figure out where to put the camera relative to the entity.
As far as I can remember, Quake 1-2-3 used this method. They first moved the avatar and then rendered from avatar's position, offset by a vector.
If you stop thinking at it, this is really what you are concerned with.

Previously "Krohm"

In general, the movement control for a character in a game follows a pretty different set of rules than general physics objects. IIRC, there are character controller classes in Bullet designed for this. I think you might want to look at btKinematicCharacterController.

Once your character is moving correctly, your camera in a first person game is a trivial offset.
Also be aware that the intersection may be the result of clipping. First person cameras are usually inside some mesh which will prevent it from intersecting any other geometry (if the mesh has proper collision detection assigned, of course). One possible solution would be to decrease the distance of the near clipping plane.
That's nice, now I'm trying to make the camera move according to the invisible mesh, so I tried the following:

D3DXMATRIX matRot, matView;
D3DXVECTOR3 eye, at;
D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
D3DXVECTOR3 right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
D3DXVECTOR3 position = dynamicModel->GetPosition();
D3DXVECTOR3 rotation = dynamicModel->GetRotation();

// Rotate yaw/pitch/roll
D3DXMatrixRotationYawPitchRoll(&matRot, rotation.y, rotation.x, rotation.z);

// Transform vectors
D3DXVec3TransformNormal(&look, &look, &matRot); // Look same direction as model
D3DXVec3TransformNormal(&up, &up, &matRot); // Up same orientation as model

if (Orientation == ORIENTATION_FIRSTPERSON)
{
position.y = 15.0f;

eye = position;
at = position + 1.0f * look;
}
else
{
eye = position - 100.0f * look;
at = eye + look;
}

D3DXMatrixLookAtLH(&matView, &eye, &at, &up);
return matView;


Not working exactly as expected, any code sample/correction?

This topic is closed to new replies.

Advertisement