VRUT::Camera Class Reference

Camera scene graph node. More...

#include <camera.h>

Inheritance diagram for VRUT::Camera:

VRUT::SceneNode VRUT::ReadWriteMutex

List of all members.

Public Types

enum  VFC_RESULT { OUTSIDE = 0, INSIDE, INTERSECT }
 Intersection result. More...
enum  FRUSTUM_PLANE {
  FRUSTUM_NEAR = 0, FRUSTUM_FAR, FRUSTUM_LEFT, FRUSTUM_RIGHT,
  FRUSTUM_TOP, FRUSTUM_BOTTOM
}
 Frustum plane enumerator. More...

Public Member Functions

 Camera (const wxString &_uid, const wxString &_name)
 Class constructor.
 Camera (const Camera &c)
 Copy contructor.
virtual ~Camera ()
 Class destructor.
VECTOR3 GetCenterPoint () const
 Get center point (world).
float GetCenterDist () const
 Get center distance from eye position.
void SetCenterDist (float dist)
 Set center distance from eye position.
float GetFOV () const
 Get FOV.
float GetFarPlane () const
 Get farPlane.
float GetNearPlane () const
 Get nearPlane.
VECTOR3 GetView () const
 Extract view direction.
VECTOR3 GetUp () const
 Extract up vector.
const BSphereGetBSphere () const
 Get bounding sphere.
void GetWidthHeight (unsigned *width, unsigned *height) const
 Get last screen width and height for which projection matrix is built.
const MATRIXGetProjectionMatrix () const
 Get projection matrix.
VFC_RESULT InFrustum (const AABB &aabb, int *lastOut, unsigned *planeMask) const
 For frusutm plane normals pointing into the frustum (positive inside frustum).
virtual wxString ToString () const
 Get string with node's properties - SceneNode overload.
virtual SceneNodeClone () const
 Get copy of instance - SceneNode overload.

Private Member Functions

void extractFrustum ()
 Extract frustum planes and update bounding volumes (don't call directly, use Scene::UpdateTransformation instead).
void updateProjection ()
 Update projection matrix (don't call directly, use Scene::UpdateTransformation instead).

Private Attributes

MATRIX projMat
 Projection matrix.
PLANE frustumPlanes [6]
 Camera frustum planes.
BSphere bSphere
 Bounding sphere.
float nearPlane
 Near plane distance.
float farPlane
 Far plane distance.
float fov
 Field of view (angles).
unsigned lastWidth
 Auxiliary - last viewport width.
unsigned lastHeight
 Auxiliary - last viewport width.
float centerDist
 Center point (look at point) distance from eye position.

Friends

class Scene


Detailed Description

Camera scene graph node.

Definition at line 26 of file camera.h.


Member Enumeration Documentation

Intersection result.

Enumerator:
OUTSIDE  Object is outside VF.
INSIDE  Object is inside VF.
INTERSECT  Object is partially inside and partially outside.

Definition at line 55 of file camera.h.

00056               {
00057                      OUTSIDE = 0,    
00058                      INSIDE,         
00059                      INTERSECT       
00060               };

Frustum plane enumerator.

Enumerator:
FRUSTUM_NEAR  Near plane index.
FRUSTUM_FAR  Far plane index.
FRUSTUM_LEFT  Left plane index.
FRUSTUM_RIGHT  Right plane index.
FRUSTUM_TOP  Top plane index.
FRUSTUM_BOTTOM  Bottom plane index.

Definition at line 63 of file camera.h.

00064               {
00065                      FRUSTUM_NEAR = 0,  
00066                      FRUSTUM_FAR,       
00067                      FRUSTUM_LEFT,      
00068                      FRUSTUM_RIGHT,     
00069                      FRUSTUM_TOP,       
00070                      FRUSTUM_BOTTOM     
00071               };


Constructor & Destructor Documentation

Camera::Camera ( const wxString &  _uid,
const wxString &  _name 
)

Class constructor.

Definition at line 8 of file camera.cpp.

00009 : SceneNode(_uid, _name, SceneNode::CAMERA)
00010 {
00011        nearPlane = 1.0f;
00012        farPlane = 10000.0f;
00013        fov = 45.0f;
00014        lastWidth = 640;
00015        lastHeight = 480;
00016 }

VRUT::Camera::Camera ( const Camera c  )  [inline]

Copy contructor.

Definition at line 76 of file camera.h.

00077                      : SceneNode(c), projMat(c.projMat), bSphere(c.bSphere),
00078                      nearPlane(c.nearPlane), farPlane(c.farPlane), fov(c.fov),
00079                      lastWidth(c.lastWidth), lastHeight(c.lastHeight), centerDist(c.centerDist)
00080               {
00081                      for (int i = 0; i < 6; i++)
00082                             frustumPlanes[i] = c.frustumPlanes[i];
00083               }

Camera::~Camera (  )  [virtual]

Class destructor.

Definition at line 19 of file camera.cpp.

00020 {
00021 }


Member Function Documentation

void Camera::extractFrustum (  )  [private]

Extract frustum planes and update bounding volumes (don't call directly, use Scene::UpdateTransformation instead).

Update bounding sphere

Definition at line 24 of file camera.cpp.

00025 {
00026        MATRIX mat = projMat.Transpose() * GetWorldTransMatrix()->Inverse().Transpose();
00027 
00028        frustumPlanes[FRUSTUM_NEAR]   = PLANE(mat._m41 + mat._m31, mat._m42 + mat._m32, mat._m43 + mat._m33, mat._m44 + mat._m34).Normalize();
00029        frustumPlanes[FRUSTUM_FAR]    = PLANE(mat._m41 - mat._m31, mat._m42 - mat._m32, mat._m43 - mat._m33, mat._m44 - mat._m34).Normalize();
00030        frustumPlanes[FRUSTUM_LEFT]   = PLANE(mat._m41 + mat._m11, mat._m42 + mat._m12, mat._m43 + mat._m13, mat._m44 + mat._m14).Normalize();
00031        frustumPlanes[FRUSTUM_RIGHT]  = PLANE(mat._m41 - mat._m11, mat._m42 - mat._m12, mat._m43 - mat._m13, mat._m44 - mat._m14).Normalize();
00032        frustumPlanes[FRUSTUM_TOP]    = PLANE(mat._m41 - mat._m21, mat._m42 - mat._m22, mat._m43 - mat._m23, mat._m44 - mat._m24).Normalize();
00033        frustumPlanes[FRUSTUM_BOTTOM] = PLANE(mat._m41 + mat._m21, mat._m42 + mat._m22, mat._m43 + mat._m23, mat._m44 + mat._m24).Normalize();
00034 
00035        float tanHFov = tanf( fov * 0.5f * DEG2RAD );
00036        float aspect = float(lastWidth) / float(lastHeight);
00037        float hFarWidth = tanHFov * farPlane * aspect;
00038        float hFarHeight = tanHFov * farPlane;
00039 
00041        VECTOR3 lowCorner( -hFarWidth, -hFarHeight, -farPlane );
00042        VECTOR3 highCorner( hFarWidth, hFarHeight, -farPlane );
00043        lowCorner = GetWorldTransMatrix()->TransformCoord(lowCorner);
00044        highCorner = GetWorldTransMatrix()->TransformCoord(highCorner);
00045        bSphere.Center = (((lowCorner + highCorner) * 0.5f) + GetWorldTransMatrix()->ExtractTranslation()) * 0.5f;
00046        bSphere.Radius = (highCorner - bSphere.Center).Length();
00047 }

void Camera::updateProjection (  )  [private]

Update projection matrix (don't call directly, use Scene::UpdateTransformation instead).

Definition at line 50 of file camera.cpp.

00051 {
00052        float top = nearPlane * tan(fov * M_PI / 360.0);
00053        float bottom = -top;
00054        float aspect = float(lastWidth)/float(lastHeight);
00055        float left = bottom * aspect;
00056        float right = top * aspect;
00057 
00058        projMat = MATRIX();
00059        projMat._m11 = (2 * nearPlane) / (right - left);
00060        projMat._m31 = (right + left) / (right - left);
00061        projMat._m22 = (2 * nearPlane) / (top - bottom);
00062        projMat._m32 = (top + bottom) / (top - bottom);
00063        projMat._m33 = -(farPlane + nearPlane) / (farPlane - nearPlane);
00064        projMat._m43 = -(2 * farPlane * nearPlane) / (farPlane - nearPlane);
00065        projMat._m34 = -1;
00066        projMat._m44 = 0;
00067 }

VECTOR3 VRUT::Camera::GetCenterPoint (  )  const [inline]

Get center point (world).

Definition at line 88 of file camera.h.

00089               {
00090                      return GetWorldTransMatrix()->ExtractTranslation() + GetCenterDist() * GetView();
00091               }

float VRUT::Camera::GetCenterDist (  )  const [inline]

Get center distance from eye position.

Definition at line 94 of file camera.h.

00095               {
00096                      return centerDist;
00097               }

void VRUT::Camera::SetCenterDist ( float  dist  )  [inline]

Set center distance from eye position.

Definition at line 100 of file camera.h.

00101               {
00102                      centerDist = dist;
00103               }

float VRUT::Camera::GetFOV (  )  const [inline]

Get FOV.

Definition at line 106 of file camera.h.

00107               {
00108                      return fov;
00109               }

float VRUT::Camera::GetFarPlane (  )  const [inline]

Get farPlane.

Definition at line 112 of file camera.h.

00113               {
00114                      return farPlane;
00115               }

float VRUT::Camera::GetNearPlane (  )  const [inline]

Get nearPlane.

Definition at line 118 of file camera.h.

00119               {
00120                      return nearPlane;
00121               }

VECTOR3 VRUT::Camera::GetView (  )  const [inline]

Extract view direction.

Definition at line 124 of file camera.h.

00125               {
00126                      return (GetWorldTransMatrix()->TransformNormal(VECTOR3(0,0,-1)));
00127               }

VECTOR3 VRUT::Camera::GetUp (  )  const [inline]

Extract up vector.

Definition at line 130 of file camera.h.

00131               {
00132                      return (GetWorldTransMatrix()->TransformNormal(VECTOR3(0,1,0)));
00133               }

const BSphere* VRUT::Camera::GetBSphere (  )  const [inline]

Get bounding sphere.

Definition at line 136 of file camera.h.

00137               {
00138                      return &bSphere;
00139               }

void VRUT::Camera::GetWidthHeight ( unsigned *  width,
unsigned *  height 
) const [inline]

Get last screen width and height for which projection matrix is built.

Definition at line 142 of file camera.h.

00143               {
00144                      *width = lastWidth;
00145                      *height = lastHeight;
00146               }

const MATRIX* VRUT::Camera::GetProjectionMatrix (  )  const [inline]

Get projection matrix.

Definition at line 149 of file camera.h.

00150               {
00151                      if (!IsValid())
00152                             LOGWARNING(wxT("<Camera>Getting invalid projection matrix - update first"));
00153                      return &projMat;
00154               }

Camera::VFC_RESULT Camera::InFrustum ( const AABB aabb,
int *  lastOut,
unsigned *  planeMask 
) const

For frusutm plane normals pointing into the frustum (positive inside frustum).

AABB and VF intersection test

Parameters:
[in] aabb Tested AABB
[out] lastOut Index of plane for which test result is OUTSIDE
[in,out] planeMask Bitmask telling algorithm planes to include/exclude in test, after test bitmask is updated for subnodes
Returns:
VFC_RESULT enumeration

Does this plane really need to be tested?

Definition at line 71 of file camera.cpp.

00072 {
00073        VFC_RESULT ret = INSIDE;
00074        int plane = *lastOut % 6;
00075        for (int cnt = 0; cnt < 6; plane = (plane + 1) % 6, cnt++)
00076        {
00078               if (*planeMask & (1 << plane))
00079                      continue;
00080 
00081               VECTOR3 nv, pv;
00082               aabb.ComputeNPvertices(&frustumPlanes[plane], &nv, &pv);
00083 
00084               if (frustumPlanes[plane].DotCoord(pv) < 0.0f)
00085               {
00086                      *lastOut = plane;
00087                      return OUTSIDE;
00088               }
00089               if (frustumPlanes[plane].DotCoord(nv) < 0.0f)
00090                      ret = INTERSECT;
00091               else
00092                      *planeMask |= (1 << plane);
00093        }
00094 
00095        return ret;
00096 }

virtual wxString VRUT::Camera::ToString (  )  const [inline, virtual]

Get string with node's properties - SceneNode overload.

Reimplemented from VRUT::SceneNode.

Definition at line 165 of file camera.h.

00166               {
00167                      wxString ret = SceneNode::ToString();
00168                      ret << wxString::Format(wxT("Projection: \n%s\n"), projMat.ToString().c_str());
00169                      for (int i = 0; i < 6; i++)
00170                             ret << wxString::Format(wxT("Frustum plane %i: %s\n"), i, frustumPlanes[i].ToString().c_str());
00171                      ret << wxString::Format(wxT("Bound sphere:\n%s\n"), bSphere.ToString().c_str());
00172                      ret << wxString::Format(wxT("Near plane: %f\nFar plane: %f\nCenter distance: %f\n"), nearPlane, farPlane, centerDist);
00173                      return ret;
00174               }

virtual SceneNode* VRUT::Camera::Clone (  )  const [inline, virtual]

Get copy of instance - SceneNode overload.

Reimplemented from VRUT::SceneNode.

Definition at line 177 of file camera.h.

00178               {
00179                      return new Camera(*this);
00180               }


Friends And Related Function Documentation

friend class Scene [friend]

Reimplemented from VRUT::SceneNode.

Definition at line 182 of file camera.h.


Member Data Documentation

Projection matrix.

Definition at line 30 of file camera.h.

Camera frustum planes.

Definition at line 32 of file camera.h.

Bounding sphere.

Definition at line 34 of file camera.h.

float VRUT::Camera::nearPlane [private]

Near plane distance.

Definition at line 36 of file camera.h.

float VRUT::Camera::farPlane [private]

Far plane distance.

Definition at line 38 of file camera.h.

float VRUT::Camera::fov [private]

Field of view (angles).

Definition at line 40 of file camera.h.

unsigned VRUT::Camera::lastWidth [private]

Auxiliary - last viewport width.

Definition at line 42 of file camera.h.

unsigned VRUT::Camera::lastHeight [private]

Auxiliary - last viewport width.

Definition at line 44 of file camera.h.

float VRUT::Camera::centerDist [private]

Center point (look at point) distance from eye position.

Definition at line 46 of file camera.h.


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:41 2009 for VRUT by  doxygen 1.5.5