Jump to content

  • Log In with Google      Sign In   
  • Create Account


Camera Collision


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 12 November 2012 - 02:57 AM

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.

Edited by Medo3337, 12 November 2012 - 07:44 PM.


Sponsor:

#2 Krohm   Crossbones+   -  Reputation: 3016

Like
0Likes
Like

Posted 12 November 2012 - 07:18 AM

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.

#3 C0lumbo   Crossbones+   -  Reputation: 2162

Like
0Likes
Like

Posted 12 November 2012 - 08:33 AM

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.

#4 Prototype   Members   -  Reputation: 1303

Like
0Likes
Like

Posted 12 November 2012 - 04:20 PM

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.

#5 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 12 November 2012 - 07:49 PM

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?

Edited by Medo3337, 12 November 2012 - 09:01 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS