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 CViewportH 00024 #define CViewportH 00025 //--------------------------------------------------------------------------- 00026 #if defined(_WIN32) 00027 //--------------------------------------------------------------------------- 00028 #include "scenegraph/CWorld.h" 00029 #include "scenegraph/CCamera.h" 00030 #include "math/CMatrix3d.h" 00031 #include "math/CVector3d.h" 00032 //--------------------------------------------------------------------------- 00033 00034 //=========================================================================== 00041 //=========================================================================== 00042 00043 //=========================================================================== 00060 //=========================================================================== 00061 class cViewport 00062 { 00063 public: 00064 00065 //--------------------------------------------------------------------- 00066 // CONSTRUCTOR & DESTRUCTOR: 00067 //--------------------------------------------------------------------- 00068 00070 cViewport(HWND a_winHandle, 00071 cCamera *a_camera, 00072 const bool a_stereoEnabled = false, 00073 PIXELFORMATDESCRIPTOR* a_pixelFormat = 0); 00074 00076 ~cViewport(); 00077 00078 00079 //--------------------------------------------------------------------- 00080 // GENERAL SEETINGS 00081 //--------------------------------------------------------------------- 00082 00084 unsigned int getHeight() const { return (m_activeRenderingArea.top - m_activeRenderingArea.bottom); } 00085 00087 unsigned int getWidth() const { return (m_activeRenderingArea.right - m_activeRenderingArea.left); } 00088 00090 void setCamera(cCamera *a_camera); 00091 00093 cCamera* getCamera() const { return (m_camera); } 00094 00096 void setEnabled( const bool& a_enabled ) { m_enabled = a_enabled; } 00097 00099 bool getEnabled() const { return (m_enabled); } 00100 00101 00102 //--------------------------------------------------------------------- 00103 // STEREO DISPLAY SUPPORT 00104 //--------------------------------------------------------------------- 00105 00107 void setStereoOn(bool a_stereoEnabled); 00108 00110 bool getStereoOn() const { return (m_stereoEnabled); } 00111 00112 00113 //--------------------------------------------------------------------- 00114 // MOUSE SELECTION 00115 //--------------------------------------------------------------------- 00116 00118 bool select(const unsigned int a_windowPosX, 00119 const unsigned int a_windowPosY, 00120 cCollisionSettings* a_collisionSettings = NULL); 00121 00123 cGenericObject* getLastSelectedObject() { return (m_collisionRecorder.m_nearestCollision.m_object); } 00124 00126 cTriangle* getLastSelectedTriangle() { return (m_collisionRecorder.m_nearestCollision.m_triangle); } 00127 00129 cVector3d getLastSelectedPoint(void) { return(m_collisionRecorder.m_nearestCollision.m_globalPos); } 00130 00132 cVector3d getLastSelectedPointNormal(void) { return(m_collisionRecorder.m_nearestCollision.m_globalNormal);} 00133 00135 double getLastSelectedDistance(void) { return (sqrt(m_collisionRecorder.m_nearestCollision.m_squareDistance)); } 00136 00138 cCollisionRecorder m_collisionRecorder; 00139 00140 00141 //--------------------------------------------------------------------- 00142 // RENDERING 00143 //--------------------------------------------------------------------- 00144 00146 bool render(const int imageIndex = CHAI_STEREO_DEFAULT); 00147 00152 virtual void onDisplayReset(); 00153 00155 HDC getGLDC() { return m_glDC; } 00156 00158 const PIXELFORMATDESCRIPTOR* getPixelFormat() { return (&m_pixelFormat); } 00159 00161 bool update(bool resizeOnly=false); 00162 00164 int m_glViewport[4]; 00165 00167 void setPostRenderCallback( cGenericObject* a_postRenderCallback ) 00168 { m_postRenderCallback = a_postRenderCallback; } 00169 00171 cGenericObject* getPostRenderCallback() const { return (m_postRenderCallback); } 00172 00173 00174 //--------------------------------------------------------------------- 00175 // SUB AREA RENDERING 00176 //--------------------------------------------------------------------- 00177 00184 void setRenderArea(RECT& r); 00185 00187 void getRenderArea(RECT& r) { r = this->m_forceRenderArea; } 00188 00190 static cViewport* getLastActiveViewport() { return lastActiveViewport; } 00191 00196 cVector3d projectPoint(cVector3d& a_point); 00197 00198 00199 protected: 00200 00201 //--------------------------------------------------------------------- 00202 // GENERAL PROPERTIES: 00203 //--------------------------------------------------------------------- 00204 00206 cCamera* m_camera; 00207 00209 bool m_enabled; 00210 00212 bool m_stereoEnabled; 00213 00215 HWND m_winHandle; 00216 00218 HGLRC m_glContext; 00219 00221 HDC m_glDC; 00222 00224 bool m_glReady; 00225 00230 RECT m_activeRenderingArea; 00231 00238 RECT m_forceRenderArea; 00239 00241 PIXELFORMATDESCRIPTOR m_pixelFormat; 00242 00247 cGenericObject* m_postRenderCallback; 00248 00253 static cViewport* lastActiveViewport; 00254 00255 00256 //--------------------------------------------------------------------- 00257 // PROTECTED METHODS: 00258 //--------------------------------------------------------------------- 00259 00261 bool cleanup(); 00262 00264 virtual bool renderView(const int a_imageIndex); 00265 00266 }; 00267 00268 //--------------------------------------------------------------------------- 00269 #endif // _WIN32 00270 //--------------------------------------------------------------------------- 00271 #endif 00272 //--------------------------------------------------------------------------- 00273