Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DMonaghan

Need Orbit feature for 3rd person camera

This topic is 5333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a working 3rd person camera, which allows me to follow a character around, however i want to add a mouse look feature to this also, which will allow me to look around (360 degrees) the character, while keeping the model (car) in the center, can anyone help me with this? void FollowCamera(void)() { // Get the position of the thing we are looking at, and the orientation of it vec3_Copy(cg.car.position, carpos); vec3_Copy(cg.car.axis[1], cary); // Work out the 2D direction from the car to the camera vec3_Sub(cg.camerapos, carpos, viewdir); viewdir[2] = 0; vec3_Normalise(viewdir); // move out along this vector the correct distance vec3_AddScale(carpos, viewdir, cipher_cvar_Float(cg_thirdpersonrange), cg.camerapos); cg.camerapos[2] += cipher_cvar_Float(cg_thirdpersonheight); // Set the camera orientation // Set the camera up vector vec3_Set(0,0,1, up); // figure out a focus position ( a point ahead of the car) cary[2] = 0; vec3_Normalise(cary); vec3_AddScale(carpos, cary, cipher_cvar_Float(cg_thirdpersonfocus), focus); vec3_AddScale(focus, up, cipher_cvar_Float(cg_thirdpersonfocusheight), focus); // set the view info structure with the camera position and axis vec3_Copy(focus, cg.camerafocus); cg_LookAtToAxisUp(cg.camerapos, focus, up, cg.view.axis[0], cg.view.axis[1], cg.view.axis[2]); }

Share this post


Link to post
Share on other sites
Advertisement
Use sin/cos to place the camera on an arc at the angle determined by the movement, the rotate the camera back toward the main character at the same angle.

It''s all sin/cos pythagorean stuff.

Share this post


Link to post
Share on other sites
Use this, with graph :

Car -( 0, Rorbit, 0 )-> CameraOrbitCenter -( Tcam, Rcam, Scam )-> Camera

Use Rorbit to rotate the camera around. Tcam, Rcam and Scam should be positioning the camera behind the car when the car is at (0,0,0).

Share this post


Link to post
Share on other sites

rotation += mousex_speed;
elevation += mousey_speed;

float cos_rot = (float) cos(rotation);
float sin_rot = (float)-sin(rotation);
float cos_elv = (float)cos(elevation);
float sin_elv = (float)sin(elevation);

//--------------------------------------

// Limit elevation to an angle

//--------------------------------------

float elv_limit = RadToDeg(85.0f);
elevation = (elevation < -elv_limit)? -elv_limit : (elevation > elv_limit)? elv_limit : elevation;

//--------------------------------------

// calcualte camera position (on the spehre around the player)

//--------------------------------------

camera_position = player_position - Vector(cos_rot*sin_elv, cos_elv, sinrot*sin_elv) * camera_radius;

camera_target = player_position; // camera position

camera_up = Vector(0, 1, 0); // requested up vector

camera_dir = camera_target - camera_pos; // calculate dir

camera_dir /= camera_dir.Length(); // normalise

camera_side = camera_up.Cross(camera_dir); // calculate side vector

camera_side /= camera_side.Length(); // normalise

camera_up = camera_dir.Cross(camera_side); // recompute up vector




so, for you....

//--------------------------------------
// rotate angles with mouse
//--------------------------------------
rotation += mousex_speed;
elevation += mousey_speed;

float cos_rot = (float) cos(rotation);
float sin_rot = (float)-sin(rotation);
float cos_elv = (float)cos(elevation);
float sin_elv = (float)sin(elevation);

//--------------------------------------
// Limit elevation to an angle
//--------------------------------------
float elv_limit = RadToDeg(85.0f);
elevation = (elevation < -elv_limit)? -elv_limit : (elevation > elv_limit)? elv_limit : elevation;

// set the view vector
vec3_Set((cos_rot*sin_elv), (cos_elv), (sinrot*sin_elv), viewdir);

vec3_AddScale(carpos, viewdir, cipher_cvar_Float(cg_thirdpersonrange), cg.camerapos);

vec3_Set(0,0,1, up);

cg_LookAtToAxisUp(cg.camerapos, carpos, up, cg.view.axis[0], cg.view.axis[1], cg.view.axis[2]);


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!