Tweaks to Camera class

- added lens attributes
- coding standard cleanup
This commit is contained in:
ZappoMan 2013-04-15 17:56:52 -07:00
parent 3b994cbdcf
commit c2c36e6cea
2 changed files with 68 additions and 53 deletions

View file

@ -11,16 +11,18 @@
//------------------------ //------------------------
Camera::Camera() Camera::Camera()
{ {
mode = CAMERA_MODE_THIRD_PERSON; _mode = CAMERA_MODE_THIRD_PERSON;
fieldOfView = 60.0; // default _fieldOfView = 60.0; // default
yaw = 0.0; _nearClip = 0.1; // default
pitch = 0.0; _farClip = 50.0; // default
roll = 0.0; _yaw = 0.0;
up = 0.0; _pitch = 0.0;
distance = 0.0; _roll = 0.0;
targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); _up = 0.0;
position = glm::vec3( 0.0, 0.0, 0.0 ); _distance = 0.0;
orientation.setToIdentity(); _targetPosition = glm::vec3( 0.0, 0.0, 0.0 );
_position = glm::vec3( 0.0, 0.0, 0.0 );
_orientation.setToIdentity();
} }
@ -28,21 +30,21 @@ Camera::Camera()
//------------------------ //------------------------
void Camera::update() void Camera::update()
{ {
double radian = ( yaw / 180.0 ) * PIE; float radian = ( _yaw / 180.0 ) * PIE;
//these need to be checked to make sure they correspond to the cordinate system. //these need to be checked to make sure they correspond to the cordinate system.
double x = distance * -sin( radian ); float x = _distance * -sin( radian );
double z = distance * cos( radian ); float z = _distance * cos( radian );
double y = up; float y = _up;
position = targetPosition + glm::vec3( x, y, z ); _position = _targetPosition + glm::vec3( x, y, z );
//------------------------------------------------------------------------ //------------------------------------------------------------------------
//geterate the ortho-normals for the orientation based on the Euler angles //geterate the ortho-normals for the orientation based on the Euler angles
//------------------------------------------------------------------------ //------------------------------------------------------------------------
orientation.setToIdentity(); _orientation.setToIdentity();
orientation.yaw ( yaw ); _orientation.yaw ( _yaw );
orientation.pitch ( pitch ); _orientation.pitch ( _pitch );
orientation.roll ( roll ); _orientation.roll ( _roll );
} }

View file

@ -13,50 +13,63 @@
enum CameraMode enum CameraMode
{ {
CAMERA_MODE_NULL = -1, CAMERA_MODE_NULL = -1,
CAMERA_MODE_FIRST_PERSON, CAMERA_MODE_FIRST_PERSON,
CAMERA_MODE_THIRD_PERSON, CAMERA_MODE_THIRD_PERSON,
CAMERA_MODE_MY_OWN_FACE, CAMERA_MODE_MY_OWN_FACE,
NUM_CAMERA_MODES NUM_CAMERA_MODES
}; };
class Camera class Camera
{ {
public: public:
Camera(); Camera();
void update();
void setMode ( CameraMode m ) { mode = m; }
void setYaw ( float y ) { yaw = y; }
void setPitch ( float p ) { pitch = p; }
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 setOrientation ( Orientation o ) { orientation.set(o); }
float getYaw () { return yaw; } void update();
float getPitch () { return pitch; }
float getRoll () { return roll; } void setMode ( CameraMode m ) { _mode = m; }
glm::vec3 getPosition () { return position; } void setYaw ( float y ) { _yaw = y; }
Orientation getOrientation () { return orientation; } void setPitch ( float p ) { _pitch = p; }
CameraMode getMode () { return mode; } 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 setOrientation ( Orientation o ) { _orientation.set(o); }
void setFieldOfView ( float f ) { _fieldOfView = f; }
void setAspectRatio ( float a ) { _aspectRatio = a; }
void setNearClip ( float n ) { _nearClip = n; }
void setFarClip ( float f ) { _farClip = f; }
float getYaw () { return _yaw; }
float getPitch () { return _pitch; }
float getRoll () { return _roll; }
glm::vec3 getPosition () { return _position; }
Orientation getOrientation () { return _orientation; }
CameraMode getMode () { return _mode; }
float getFieldOfView () { return _fieldOfView; }
float getAspectRatio () { return _aspectRatio; }
float getNearClip () { return _nearClip; }
float getFarClip () { return _farClip; }
private: private:
CameraMode mode; CameraMode _mode;
glm::vec3 position; glm::vec3 _position;
glm::vec3 targetPosition; glm::vec3 _targetPosition;
float fieldOfView; float _yaw;
float yaw; float _pitch;
float pitch; float _roll;
float roll; float _up;
float up; float _distance;
float distance; Orientation _orientation;
Orientation orientation;
// Lens attributes
float _fieldOfView; // in degrees
float _aspectRatio; // width/height
float _nearClip; // in world units? - XXXBHG - we need to think about this!
float _farClip; // in world units?
}; };
#endif #endif