Gizmo3D

gzCamera.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzCamera.h
00003 // Module       : 
00004 // Description  : Class definition of the gzCamera class
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden   
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  990101  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_CAMERA_H__
00023 #define __GZ_CAMERA_H__
00024 
00031 #include "gzObject.h"
00032 #include "gzScene.h"
00033 #include "gzMutex.h"
00034 
00035 class gzCamera : public gzObject , public gzNameInterface ,public gzMutex
00036 {
00037 public:
00038 
00040 
00045     GZ_GRAPH_EXPORT gzCamera( const gzString &name=GZ_EMPTY_STRING);
00046     
00048     GZ_GRAPH_EXPORT virtual ~gzCamera(){};
00049 
00050     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00051 
00052     // ------------------- default positioning ------------------------------------
00054 
00059     GZ_GRAPH_EXPORT gzVoid  setHPR( gzReal heading , gzReal pitch , gzReal roll );
00061 
00066     GZ_GRAPH_EXPORT gzVoid  setHPR( const gzVec3 &hpr );
00067     
00069 
00073     GZ_GRAPH_EXPORT gzVoid  getHPR( gzReal &heading , gzReal &pitch , gzReal &roll );
00075     GZ_GRAPH_EXPORT gzVec3  getHPR();
00076 
00078 
00081     GZ_GRAPH_EXPORT gzVoid  setPosition( gzReal x , gzReal y , gzReal z );
00082     
00084 
00088     GZ_GRAPH_EXPORT gzVoid  lookAt( gzReal x , gzReal y , gzReal z , gzReal roll=0 , const gzVec3 &up=gzVec3(0,1,0));
00089 
00091 
00094     GZ_GRAPH_EXPORT gzVoid  setPosition( const gzVec3 &position );
00095     
00097 
00101     GZ_GRAPH_EXPORT gzVoid  lookAt( const gzVec3 &position , gzReal roll=0 , const gzVec3 &up=gzVec3(0,1,0));
00102 
00103     GZ_GRAPH_EXPORT gzVoid  useRoiPosition(gzBool on);
00104 
00105     // ------------------- distance and scene viewbox management ------------------
00107 
00113     GZ_GRAPH_EXPORT gzVoid  setNearClipPlane( gzReal distance );
00114 
00116 
00122     GZ_GRAPH_EXPORT gzVoid  setFarClipPlane( gzReal distance );
00123 
00124     GZ_GRAPH_EXPORT gzVoid  flipVerticalView(gzBool on);
00125     GZ_GRAPH_EXPORT gzVoid  flipHorizontalView(gzBool on);
00126 
00128 
00131     GZ_GRAPH_EXPORT gzVoid  setScene( gzScene *scene );
00132     
00134     GZ_GRAPH_EXPORT gzScene *getScene() { return m_scene.get(); }
00135 
00137     GZ_GRAPH_EXPORT gzVec3  getPosition() { return m_eye; }
00138 
00140     GZ_GRAPH_EXPORT gzVec3  getDirection();
00141     GZ_GRAPH_EXPORT gzVec3  getNormal();
00142 
00143     // ------------------- pure transform control ---------------------------------
00144 
00146     GZ_GRAPH_EXPORT gzVoid  setTransform( const gzMatrix4 &transform);
00147 
00149     GZ_GRAPH_EXPORT const gzMatrix4 &getTransform() const;
00150 
00152 
00155     GZ_GRAPH_EXPORT virtual gzMatrix4 getProjectionTransform() const =0;
00156 
00157     // ------------------- utility methods used by external renderers -----------------
00158 
00160     GZ_GRAPH_EXPORT virtual gzVoid render(gzContext *context , gzULong size_x , gzULong size_y, gzULong screen_width);
00161 
00163     GZ_GRAPH_EXPORT virtual gzBool isVisible( gzContext *context , gzNode *node  )=0;
00164 
00166 
00171     GZ_GRAPH_EXPORT virtual gzBool isBeyondFarPlane( gzContext *context , gzNode *node  )=0;
00172 
00173 protected:
00174     
00175     GZ_GRAPH_EXPORT gzVoid  calculateTransform();
00176 
00177     gzReal  m_near_clip_distance;
00178     gzReal  m_far_clip_distance;
00179 
00180     gzVec3  m_eye;
00181 
00182     gzReal  m_eye_heading;
00183     gzReal  m_eye_pitch;
00184     gzReal  m_eye_roll;
00185 
00186     gzMatrix4               m_cameraMatrix;
00187 
00188     gzMatrix4               m_invCameraMatrix;
00189 
00190     gzRefPointer<gzScene>   m_scene;
00191 
00192     gzBool  m_useRoiPosition:1;
00193     gzBool  m_flipHorizontal:1;
00194     gzBool  m_flipVertical:1;
00195     
00196 
00197 };
00198 
00199 class gzPerspCamera : public gzCamera
00200 {
00201 public:
00202 
00204 
00214     GZ_GRAPH_EXPORT gzPerspCamera(const gzString &name=GZ_EMPTY_STRING);
00215 
00217     GZ_GRAPH_EXPORT virtual ~gzPerspCamera(){};
00218 
00219     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00220 
00221     // ---------- Clone interface ---------------------------------------
00223     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00224 
00226     GZ_GRAPH_EXPORT virtual gzVoid render(gzContext *context , gzULong size_x , gzULong size_y, gzULong screen_width);
00227 
00229 
00233     GZ_GRAPH_EXPORT gzVoid setVerticalFOV( gzReal fov );    
00235 
00239     GZ_GRAPH_EXPORT gzVoid setHorizontalFOV( gzReal fov );
00240 
00242     GZ_GRAPH_EXPORT gzReal getVerticalFOV();    
00244     GZ_GRAPH_EXPORT gzReal getHorizontalFOV();
00245 
00247     GZ_GRAPH_EXPORT gzVoid setWidth( gzReal width );
00249     GZ_GRAPH_EXPORT gzVoid setHeight( gzReal height );
00250 
00252 
00260     GZ_GRAPH_EXPORT virtual gzBool isVisible( gzContext *context , gzNode *node );
00261 
00263 
00268     GZ_GRAPH_EXPORT virtual gzBool isBeyondFarPlane( gzContext *context , gzNode *node  );
00269 
00271 
00274     GZ_GRAPH_EXPORT gzVoid  useInfiniteFarPlane(gzBool on);
00275 
00277 
00280     GZ_GRAPH_EXPORT virtual gzMatrix4 getProjectionTransform() const;
00281 
00282 protected:
00283     
00284     gzReal      m_width;
00285     gzReal      m_height;
00286 
00287     gzReal      m_vertical_FOV;
00288     gzReal      m_horizontal_FOV;
00289 
00290     gzReal      m_widthFactor;
00291     gzReal      m_heightFactor;
00292 
00293     gzBool      m_useInfiniteFarPlane;
00294 };
00295 
00296 class gzOrthoCamera : public gzCamera
00297 {
00298 public:
00299 
00301 
00307     GZ_GRAPH_EXPORT gzOrthoCamera(const gzString &name=GZ_EMPTY_STRING);
00308 
00310     GZ_GRAPH_EXPORT virtual ~gzOrthoCamera(){};
00311 
00312     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00313 
00314     // ---------- Clone interface ---------------------------------------
00316     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00317 
00319     GZ_GRAPH_EXPORT virtual gzVoid render(gzContext *context , gzULong size_x , gzULong size_y, gzULong screen_width);
00320 
00322 
00330     GZ_GRAPH_EXPORT virtual gzBool isVisible( gzContext *context , gzNode *node );
00331 
00333 
00338     GZ_GRAPH_EXPORT virtual gzBool isBeyondFarPlane( gzContext *context , gzNode *node  );
00339 
00341     GZ_GRAPH_EXPORT gzVoid setWidth( gzReal width );    
00343     GZ_GRAPH_EXPORT gzVoid setHeight( gzReal height );
00344 
00346     GZ_GRAPH_EXPORT gzVoid setMagnification( gzReal mag );
00347 
00349 
00352     GZ_GRAPH_EXPORT virtual gzMatrix4 getProjectionTransform() const;
00353 
00354 protected:
00355 
00356     gzReal  m_width;
00357     gzReal  m_height;
00358 
00359     gzReal m_mag;
00360 
00361 };
00362 
00363 // ---------------- gzGenericCamera ------------------
00364 
00365 class gzGenericCamera : public gzCamera
00366 {
00367 public:
00368 
00370 
00375     GZ_GRAPH_EXPORT gzGenericCamera(const gzString &name=GZ_EMPTY_STRING);
00376 
00378     GZ_GRAPH_EXPORT virtual ~gzGenericCamera(){};
00379 
00380     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00381 
00382     // ---------- Clone interface ---------------------------------------
00384     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00385 
00387     GZ_GRAPH_EXPORT virtual gzVoid render(gzContext *context , gzULong size_x , gzULong size_y, gzULong screen_width);
00388 
00390     GZ_GRAPH_EXPORT virtual gzBool isVisible( gzContext *context , gzNode *node );
00391 
00393 
00398     GZ_GRAPH_EXPORT virtual gzBool isBeyondFarPlane( gzContext *context , gzNode *node  );
00399 
00401     GZ_GRAPH_EXPORT gzVoid setProjectionTransform( const gzMatrix4 &projMat );
00402 
00404 
00407     GZ_GRAPH_EXPORT virtual gzMatrix4 getProjectionTransform() const;
00408 
00409 protected:
00410 
00411     gzMatrix4   m_projectionMatrix;
00412 };
00413 
00414 // ---------------- gzStereoCamera ------------------
00415 
00416 class gzStereoCamera : public gzCamera
00417 {
00418 public:
00419 
00421 
00424     GZ_GRAPH_EXPORT gzStereoCamera(const gzString &name=GZ_EMPTY_STRING);
00425 
00427     GZ_GRAPH_EXPORT virtual ~gzStereoCamera(){};
00428 
00429     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00430 
00431     // ---------- Clone interface ---------------------------------------
00433     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00434 
00436     GZ_GRAPH_EXPORT virtual gzVoid render(gzContext *context , gzULong size_x , gzULong size_y, gzULong screen_width);
00437 
00439     GZ_GRAPH_EXPORT virtual gzBool isVisible( gzContext *context , gzNode *node );
00440 
00442 
00447     GZ_GRAPH_EXPORT virtual gzBool isBeyondFarPlane( gzContext *context , gzNode *node  );
00448 
00449     // ---------- Stereo specific methods -------------------------------
00450 
00452     GZ_GRAPH_EXPORT gzCamera *getLeftEyeCamera();
00454     GZ_GRAPH_EXPORT gzCamera *getRightEyeCamera();
00455 
00457     GZ_GRAPH_EXPORT gzVoid  setLeftEyeCamera(gzCamera *camera);
00459     GZ_GRAPH_EXPORT gzVoid  setRightEyeCamera(gzCamera *camera);
00460 
00462 
00465     GZ_GRAPH_EXPORT gzVoid  setCamera(gzCamera *camera);
00466 
00468     GZ_GRAPH_EXPORT gzVoid  setEyeDistance(gzReal dist);
00470     GZ_GRAPH_EXPORT gzVoid  setFocusDistance(gzReal dist);
00471 
00473 
00476     GZ_GRAPH_EXPORT virtual gzMatrix4 getProjectionTransform() const;
00477 
00478 protected:
00479 
00480     gzRefPointer<gzCamera>      m_leftEyeCamera;
00481     gzRefPointer<gzCamera>      m_rightEyeCamera;
00482 
00483     gzReal                      m_eyeDistance;
00484     gzReal                      m_focusDistance;
00485 
00486 private:
00487 
00488     gzCamera    *m_currentRenderCamera;
00489 };
00490 
00491 // ---------------- gzMultiLayerCamera ------------------
00492 
00493 class gzMultiLayerInfo
00494 {
00495 public:
00496 
00497     gzMultiLayerInfo(): size(GZ_FLOAT_ONE,GZ_FLOAT_ONE),
00498                         offset(GZ_FLOAT_ZERO,GZ_FLOAT_ZERO),
00499                         clearStencil(TRUE),
00500                         clearDepth(TRUE),
00501                         clearColor(FALSE){}
00502 
00503     gzFloatXY               size;
00504     gzFloatXY               offset;
00505     gzBool                  clearStencil;
00506     gzBool                  clearDepth;
00507     gzBool                  clearColor;
00508 
00509     gzRefPointer<gzCamera>  camera;
00510 };
00511 
00512 class gzMultiLayerCamera : public gzCamera
00513 {
00514 public:
00515 
00516     GZ_GRAPH_EXPORT gzMultiLayerCamera(const gzString &name=GZ_EMPTY_STRING);
00517 
00518     GZ_GRAPH_EXPORT virtual ~gzMultiLayerCamera(){};
00519 
00520     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00521 
00522     // ---------- Clone interface ---------------------------------------
00524     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00525 
00527     GZ_GRAPH_EXPORT virtual gzVoid render(gzContext *context , gzULong size_x , gzULong size_y, gzULong screen_width);
00528 
00530     GZ_GRAPH_EXPORT virtual gzBool isVisible( gzContext *context , gzNode *node );
00531 
00532     GZ_GRAPH_EXPORT virtual gzBool isBeyondFarPlane( gzContext *context , gzNode *node  );
00533 
00534     GZ_GRAPH_EXPORT virtual gzMatrix4 getProjectionTransform() const;
00535 
00536     // ---------- gzMultiLayerCamera specific methods -------------------------------
00537 
00538     GZ_GRAPH_EXPORT gzVoid      setLayerCamera(gzULong layer,gzCamera *camera);
00539     GZ_GRAPH_EXPORT gzCamera*   getLayerCamera(gzULong layer);
00540 
00542     GZ_GRAPH_EXPORT gzVoid      setLayerViewportOffset(gzULong layer,gzFloat x , gzFloat y);
00543 
00545     GZ_GRAPH_EXPORT gzVoid      setLayerViewportScale(gzULong layer,gzFloat sx , gzFloat sy);
00546 
00547     GZ_GRAPH_EXPORT gzVoid      clearLayerDepthBuffer(gzULong layer,gzBool on);
00548     GZ_GRAPH_EXPORT gzVoid      clearLayerStencilBuffer(gzULong layer,gzBool on);
00549     GZ_GRAPH_EXPORT gzVoid      clearLayerColorBuffer(gzULong layer,gzBool on);
00550 
00551 protected:
00552 
00553     gzDynamicArray<gzMultiLayerInfo>        m_layerInfo;
00554 
00555 private:
00556 
00557     gzCamera    *m_currentRenderCamera;
00558 };
00559 
00560 #endif

Documentation for Gizmo3D generated at Wed Feb 20 11:54:03 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond