00001 //=========================================================================== 00002 /* 00003 This file is part of the CHAI 3D visualization and haptics libraries. 00004 Copyright (C) 2003-2009 by CHAI 3D. All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License("GPL") version 2 00008 as published by the Free Software Foundation. 00009 00010 For using the CHAI 3D libraries with software that can not be combined 00011 with the GNU GPL, and for taking advantage of the additional benefits 00012 of our support services, please contact CHAI 3D about acquiring a 00013 Professional Edition License. 00014 00015 \author <http://www.chai3d.org> 00016 \author Francois Conti 00017 \author Dan Morris 00018 \version 2.0.0 $Rev: 251 $ 00019 */ 00020 //=========================================================================== 00021 00022 //--------------------------------------------------------------------------- 00023 #ifndef CCameraH 00024 #define CCameraH 00025 //--------------------------------------------------------------------------- 00026 #include "scenegraph/CGenericObject.h" 00027 #include "math/CMaths.h" 00028 #include "files/CImageLoader.h" 00029 //--------------------------------------------------------------------------- 00030 class cWorld; 00031 //--------------------------------------------------------------------------- 00032 00034 const int CHAI_MONO = 0; 00035 00037 const int CHAI_STEREO_LEFT = -1; 00038 00040 const int CHAI_STEREO_RIGHT = 1; 00041 00047 const int CHAI_STEREO_DEFAULT = -1000; 00048 00050 #define CHAI_MAX_CLIP_PLANES 6 00051 00052 //--------------------------------------------------------------------------- 00053 00054 //=========================================================================== 00062 //=========================================================================== 00063 00064 //=========================================================================== 00071 //=========================================================================== 00072 struct cClippingPlane 00073 { 00074 //----------------------------------------------------------------------- 00075 // CONSTRUCTOR & DESTRUCTOR: 00076 //----------------------------------------------------------------------- 00077 00079 cClippingPlane() 00080 { 00081 enabled = -1; 00082 peqn[0] = peqn[1] = peqn[2] = peqn[3] = 0.0f; 00083 } 00084 00085 00086 //----------------------------------------------------------------------- 00087 // MEMBERS: 00088 //----------------------------------------------------------------------- 00089 00096 int enabled; 00097 00099 double peqn[4]; 00100 }; 00101 00102 00103 //=========================================================================== 00115 //=========================================================================== 00116 class cCamera : public cGenericObject 00117 { 00118 friend class cWorld; 00119 00120 public: 00121 00122 //----------------------------------------------------------------------- 00123 // CONSTRUCTOR & DESTRUCTOR: 00124 //----------------------------------------------------------------------- 00125 00127 cCamera(cWorld* iParent); 00128 00130 virtual ~cCamera() {}; 00131 00132 00133 //----------------------------------------------------------------------- 00134 // METHODS - MOUSE SELECTION: 00135 //----------------------------------------------------------------------- 00136 00138 cWorld* getParentWorld() { return (m_parentWorld); } 00139 00141 virtual bool select(const int a_windowPosX, const int a_windowPosY, 00142 const int a_windowWidth, const int a_windowHeight, 00143 cCollisionRecorder& a_collisionRecorder, 00144 cCollisionSettings& a_collisionSettings); 00145 00146 00147 //----------------------------------------------------------------------- 00148 // METHODS - POSITION & ORIENTATION: 00149 //----------------------------------------------------------------------- 00150 00152 virtual bool set(const cVector3d& a_localPosition, 00153 const cVector3d& a_localLookAt, 00154 const cVector3d& a_localUp); 00155 00157 cVector3d getLookVector() const { return m_localRot.getCol0(); } 00158 00160 cVector3d getUpVector() const { return m_localRot.getCol2(); } 00161 00163 cVector3d getRightVector() const { return m_localRot.getCol1(); } 00164 00166 double m_projectionMatrix[16]; 00167 00168 00169 //----------------------------------------------------------------------- 00170 // METHODS - CLIPPING PLANES: 00171 //----------------------------------------------------------------------- 00172 00174 void setClippingPlanes(const double a_distanceNear, const double a_distanceFar); 00175 00177 double getNearClippingPlane() { return (m_distanceNear); } 00178 00180 double getFarClippingPlane() { return (m_distanceFar); } 00181 00183 void adjustClippingPlanes(); 00184 00186 void enableClipPlane(const unsigned int& index, const int& enable, const double* peqn=0); 00187 00188 00189 //----------------------------------------------------------------------- 00190 // METHODS - FIELD OF VIEW & OPTICS: 00191 //----------------------------------------------------------------------- 00192 00194 void setFieldViewAngle(double a_fieldViewAngle); 00195 00197 double getFieldViewAngle() { return (m_fieldViewAngle); } 00198 00200 int setStereoFocalLength(double a_stereoFocalLength); 00201 00203 double getStereoFocalLength() { return (m_stereoFocalLength); } 00204 00206 int setStereoEyeSeparation(double a_stereoEyeSeparation); 00207 00209 double getStereoEyeSeparation() { return (m_stereoEyeSeparation); } 00210 00211 00212 //----------------------------------------------------------------------- 00213 // METHODS - RENDERING AND IMAGING: 00214 //----------------------------------------------------------------------- 00215 00217 virtual void renderView(const int a_windowWidth, const int a_windowHeight, const int a_imageIndex = CHAI_MONO); 00218 00220 void copyImageData(cImageLoader* a_image); 00221 00223 virtual void enableMultipassTransparency(bool enable); 00224 00226 virtual void onDisplayReset(const bool a_affectChildren = true); 00227 00228 00229 //----------------------------------------------------------------------- 00230 // MEMBERS - FRONT AND BACK PLANES: 00231 //----------------------------------------------------------------------- 00232 00233 /* 00234 These are special 'children' of the camera that are rendered independently of 00235 all other objects, intended to contain 2d objects only. The 'back' scene is 00236 rendered before the 3d objects; the 'front' scene is rendered after the 00237 3d object. These are made public variables to allow convenient access to 00238 the scenegraph management functions. 00239 00240 These objects are rendered through an orthographic projection matrix, so the 00241 positive z axis faces the camera. Depth is currently not used. Lighting 00242 is disabled during rendering. 00243 */ 00244 00246 cGenericObject m_front_2Dscene; 00247 00249 cGenericObject m_back_2Dscene; 00250 00251 00252 protected: 00253 00254 //----------------------------------------------------------------------- 00255 // MEMBERS: 00256 //----------------------------------------------------------------------- 00257 00259 cWorld *m_parentWorld; 00260 00262 double m_distanceNear; 00263 00265 double m_distanceFar; 00266 00268 cClippingPlane m_clipPlanes[CHAI_MAX_CLIP_PLANES]; 00269 00271 double m_fieldViewAngle; 00272 00273 // Stereo Parameters: 00274 00276 double m_stereoFocalLength; 00277 00279 double m_stereoEyeSeparation; 00280 00282 bool m_useMultipassTransparency; 00283 00285 void render2dSceneGraph(cGenericObject* a_graph, int a_width, int a_height); 00286 00288 bool m_performingDisplayReset; 00289 00291 unsigned int m_lastDisplayWidth; 00292 00294 unsigned int m_lastDisplayHeight; 00295 }; 00296 00297 //--------------------------------------------------------------------------- 00298 #endif 00299 //--------------------------------------------------------------------------- 00300