added some smoothness to the camera

This commit is contained in:
Jeffrey Ventrella 2013-04-12 18:06:11 -07:00
parent 6ddebd523c
commit ca05823010
5 changed files with 47 additions and 35 deletions

View file

@ -8,10 +8,13 @@
#include "Camera.h"
#include "Util.h"
//------------------------
Camera::Camera()
{
mode = CAMERA_MODE_THIRD_PERSON;
tightness = DEFAULT_CAMERA_TIGHTNESS;
fieldOfView = 60.0; // default
yaw = 0.0;
pitch = 0.0;
@ -20,13 +23,15 @@ Camera::Camera()
distance = 0.0;
targetPosition = glm::vec3( 0.0, 0.0, 0.0 );
position = glm::vec3( 0.0, 0.0, 0.0 );
idealPosition = glm::vec3( 0.0, 0.0, 0.0 );
orientation.setToIdentity();
}
//------------------------
void Camera::update()
//------------------------------------
void Camera::update( float deltaTime )
{
double radian = ( yaw / 180.0 ) * PIE;
@ -35,11 +40,19 @@ void Camera::update()
double z = distance * cos( radian );
double y = up;
position = targetPosition + glm::vec3( x, y, z );
idealPosition = targetPosition + glm::vec3( x, y, z );
//------------------------------------------------------------------------
float t = tightness * deltaTime;
if ( t > 1.0 ){
t = 1.0;
}
position += ( idealPosition - position ) * t;
//-------------------------------------------------------------------------
//geterate the ortho-normals for the orientation based on the Euler angles
//------------------------------------------------------------------------
//-------------------------------------------------------------------------
orientation.setToIdentity();
orientation.yaw ( yaw );
orientation.pitch ( pitch );

View file

@ -20,13 +20,14 @@ enum CameraMode
NUM_CAMERA_MODES
};
static const float DEFAULT_CAMERA_TIGHTNESS = 10.0f;
class Camera
{
public:
Camera();
void update();
void update( float deltaTime );
void setMode ( CameraMode m ) { mode = m; }
void setYaw ( float y ) { yaw = y; }
@ -34,8 +35,9 @@ public:
void setRoll ( float r ) { roll = r; }
void setUp ( float u ) { up = u; }
void setDistance ( float d ) { distance = d; }
void setTargetPosition ( glm::vec3 t ) { targetPosition = t; };
void setPosition ( glm::vec3 p ) { position = p; };
void setTargetPosition ( glm::vec3 t ) { targetPosition = t; }
void setPosition ( glm::vec3 p ) { position = p; }
void setTightness ( float t ) { tightness = t; }
void setOrientation ( Orientation o ) { orientation.set(o); }
float getYaw () { return yaw; }
@ -49,6 +51,7 @@ private:
CameraMode mode;
glm::vec3 position;
glm::vec3 idealPosition;
glm::vec3 targetPosition;
float fieldOfView;
float yaw;
@ -56,6 +59,7 @@ private:
float roll;
float up;
float distance;
float tightness;
Orientation orientation;
};

View file

@ -3,7 +3,7 @@
// interface
//
// Created by Philip Rosedale on 9/11/12.
// adapted by Jeffrey Ventrella, starting on April 2, 2013
// adapted by Jeffrey Ventrella
// Copyright (c) 2012 Physical, Inc.. All rights reserved.
//
@ -47,10 +47,6 @@ unsigned int iris_texture_height = 256;
Head::Head() {
initializeAvatar();
//position = glm::vec3(0,0,0);
//velocity = glm::vec3(0,0,0);
//thrust = glm::vec3(0,0,0);
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false;
@ -573,9 +569,9 @@ void Head::render(int faceToFace, int isMine) {
void Head::renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) {
glm::vec3 pRight = position + orientation.right * size;
glm::vec3 pUp = position + orientation.getUp () * size;
glm::vec3 pFront = position + orientation.getFront () * size;
glm::vec3 pRight = position + orientation.right * size;
glm::vec3 pUp = position + orientation.up * size;
glm::vec3 pFront = position + orientation.front * size;
glColor3f( 1.0f, 0.0f, 0.0f );
glBegin( GL_LINE_STRIP );

View file

@ -250,13 +250,11 @@ class Head : public AgentData {
bool handBeingMoved;
bool previousHandBeingMoved;
glm::vec3 movedHandOffset;
//glm::vec3 movedHandPosition;
int driveKeys[MAX_DRIVE_KEYS];
float springVelocityDecay;
float springForce;
//float springToBodyTightness;
int eyeContact;
eyeContactTargets eyeContactTarget;

View file

@ -729,29 +729,30 @@ void display(void)
//--------------------------------------------------------
// camera settings
//--------------------------------------------------------
myCamera.setTargetPosition( myAvatar.getPos() );
if ( displayHead ) {
//-----------------------------------------------
// set the camera to looking at my own face
//-----------------------------------------------
myCamera.setYaw ( - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.4 );
myCamera.setDistance( 0.03 );
myCamera.update();
//-----------------------------------------------
myCamera.setTargetPosition ( myAvatar.getPos() );
myCamera.setYaw ( - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.4 );
myCamera.setDistance ( 0.03 );
myCamera.setTightness ( 100.0f );
myCamera.update ( 1.f/FPS );
} else {
//----------------------------------------------------
// set the camera to third-person view behind my av
//----------------------------------------------------
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.2 );
myCamera.setDistance( 1.6 );
myCamera.setDistance( 0.5 );
myCamera.update();
myCamera.setTargetPosition ( myAvatar.getPos() );
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.2 );
myCamera.setDistance ( 0.5 );
myCamera.setTightness ( 10.0f );
myCamera.update ( 1.f/FPS );
}
// Note: whichCamera is used to pick between the normal camera myCamera for our
// main camera, vs, an alternate camera. The alternate camera we support right now
@ -773,7 +774,7 @@ void display(void)
viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll );
viewFrustumOffsetCamera.setUp ( 0.2 + 0.2 );
viewFrustumOffsetCamera.setDistance( 0.5 + 0.2 );
viewFrustumOffsetCamera.update();
viewFrustumOffsetCamera.update( 1.f/FPS );
whichCamera = viewFrustumOffsetCamera;
}