Original Post
Hello, Recently I've been getting used to the whole polymorphic/OOP concept. I just wanted some criticism for my base camera class. Enjoy :)
#ifndef __IBASECAMERA_INCLUDED__
#define __IBASECAMERA_INCLUDED__
/**********************************************************************************************/
interface IBaseCamera
{
protected :
D3DXMATRIX _mProj ; // Projection matrix.
float _fFov, // Field of view, in the y-direction, in radians.
_fAspect, // Aspect ratio, defined as view space width divided by height.
_fNear, // Z-Value of the near plane.
_fFar ; // Z-Value of the far plane.
D3DXMATRIX _mView ; // View space matrix.
D3DXVECTOR3 _vEye, // Defines the camera's position in world space.
_vAt, // Defines where the camera is looking at.
_vRight, // Defines where right is in view space.
_vUp, // Defines where up is in view space.
_vView ; // Line segment influenced by camera's position and view target.
D3DXMATRIX _mWorld ; // World space matrix.
float _fPitch, // Rotation about the x-axis.
_fYaw, // Rotation about the y-axis.
_fRoll ; // Rotation about the z-axis.
public :
IBaseCamera() {
_mProj = D3DXMATRIX( 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f ) ;
_fFov = _fAspect = _fNear = _fFar = 0.0f ;
_mView = D3DXMATRIX( 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f ) ;
_vEye = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
_vAt = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ),
_vRight = D3DXVECTOR3( 1.0f, 0.0f, 0.0f ),
_vUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ),
_vView = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ) ;
_mWorld = D3DXMATRIX( 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f ) ;
_fPitch = _fYaw = _fRoll = 0.0f ;
}
virtual ~IBaseCamera() { }
// Sets the projection matrix by passing a pointer to an already created one.
virtual void SetProjection(LPD3DXMATRIX pmProj) { _mProj = (*pmProj) ; }
// Sets the properties of a projection matrix.
virtual void SetProjection(FLOAT fFov, FLOAT fAspect, FLOAT fNear, FLOAT fFar) {
_fFov = fFov,
_fAspect = fAspect,
_fNear = fNear,
_fFar = fFar ;
}
// Sets the view matrix by passing a pointer to an already created one.
virtual void SetView(LPD3DXMATRIX pmView) { _mView = (*pmView) ; }
// Sets the properties of the view space matrix.
virtual void SetView(LPD3DXVECTOR3 pvEye, LPD3DXVECTOR3 pvAt, LPD3DXVECTOR3 pvUp) {
_vEye = *pvEye,
_vAt = *pvAt,
_vUp = *pvUp,
_vView = (*pvAt) - (*pvEye),
_vRight = *D3DXVec3Cross( &_vRight, &_vUp, &_vView ) ;
D3DXVec3Normalize( &_vView, &_vView ) ;
D3DXVec3Normalize( &_vRight, &_vRight ) ;
}
// Sets the world matrix by passing a pointer to an already created one.
virtual void SetWorld(LPD3DXMATRIX pmWorld) { _mWorld = (*pmWorld) ; }
// Using known variables, this method constructs the projection, view, and world matrix.
virtual void Ready(void) = 0 ;
// This method updates the camera's view as many times as it's called.
virtual void Focus(LPDIRECT3DDEVICE9 pDevice) = 0 ;
// Retrieves the projection matrix.
virtual LPD3DXMATRIX GetProj(void) { return &_mProj ; }
// Retrieves the view matrix.
virtual LPD3DXMATRIX GetView(void) { return &_mView ; }
// Retrieves the world matrix.
virtual LPD3DXMATRIX GetWorld(void) { return &_mWorld ; }
// Retrieves the camera's position.
virtual LPD3DXVECTOR3 GetEyeVector(void) { return &_vEye ; }
// Retrieves the view target vector.
virtual LPD3DXVECTOR3 GetViewTarget(void) { return &_vAt ; }
// Retrieves the camera's up orientation.
virtual LPD3DXVECTOR3 GetUpVector(void) { return &_vUp ; }
// Retrieves the camera's view vector.
virtual LPD3DXVECTOR3 GetViewVector(void) { return &_vView ; }
// Retrieves the camera's right/strafe orientation.
virtual LPD3DXVECTOR3 GetRightVector(void) { return &_vRight ; }
// Retrieves camera's rotation about the x-axis.
virtual float GetPitch(void) CONST{ return _fPitch ; }
// Retrieves camera's rotation about the y-axis.
virtual float GetYaw(void) CONST{ return _fYaw ; }
// Retrieves camera's rotation about the z-axis.
virtual float GetRoll(void) CONST{ return _fRoll ; }
} ;
/**********************************************************************************************/
#endif