Changeset 3062 for GTP


Ignore:
Timestamp:
10/23/08 14:53:23 (16 years ago)
Author:
mattausch
Message:

updating camera system: debug version

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r3061 r3062  
    1616 
    1717 
    18 Camera::Camera()  
    19 { 
    20         mFOVy = 60.0f * M_PI / 180.0f; 
    21         //mIsOrtho = false; 
    22          
    23         SetPosition(Vector3(0, 0, 0)); 
    24  
    25         mPitch = mYaw = 0; 
    26         Precompute(baseDir); 
    27  
    28         CalculateFromPitchAndYaw(); 
    29 } 
    30  
    31  
    32 Camera::Camera(float aspect, float fieldOfView)  
    33 { 
    34         mFOVy = fieldOfView * M_PI / 180.0f; 
    35         mAspect = aspect; 
    36         //mIsOrtho = false; 
    37  
    38         SetPosition(Vector3::ZERO()); 
    39  
    40         mPitch = mYaw = 0; 
    41         Precompute(baseDir); 
    42  
    43         CalculateFromPitchAndYaw(); 
    44 } 
    45  
    46  
    47 void Camera::Precompute(const Vector3 &dir)  
    48 { 
    49         Vector3 up = Vector3::UNIT_Z(); 
    50          
    51         mBaseOrientation = LookAt(Vector3::ZERO(), dir, up); 
    52         mViewOrientation = mBaseOrientation; 
    53 } 
    54  
    55  
    56 void Camera::SetPosition(const Vector3 &pos)  
    57 { 
    58         mPosition = pos; 
    59 } 
    60  
    61  
    62 void Camera::SetNear(float nearDist)  
    63 { 
    64         mNear = nearDist; 
    65 } 
    66  
    67  
    68 void Camera::SetFar(float farDist)  
    69 {  
    70         mFar = farDist;  
    71 } 
    72  
    73  
    74 void Camera::GetProjectionMatrix(Matrix4x4 &mat) const 
    75 { 
    76         glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat.x); 
    77 } 
    78  
    79  
    80 void Camera::GetModelViewMatrix(Matrix4x4 &mat) const 
    81 { 
    82         mat = mViewOrientation; 
    83  
    84         // note: left handed system => we go into positive z 
    85         mat.x[3][0] = -DotProd(GetRightVector(), mPosition); 
    86         mat.x[3][1] = -DotProd(GetUpVector(), mPosition); 
    87         mat.x[3][2] = DotProd(GetDirection(), mPosition); 
    88 } 
    89  
    90  
    91 void Camera::GetViewOrientationMatrix(Matrix4x4 &mat) const 
    92 { 
    93         mat = mViewOrientation; 
    94 } 
    95  
    96  
    97 void Camera::CalcFrustum(Frustum &frustum) 
    98 { 
    99         // we grab the plane equations of the six clipplanes of the viewfrustum 
    100         Matrix4x4 matViewing, matProjectionView; 
    101  
    102         GetModelViewMatrix(matViewing); 
    103         GetProjectionMatrix(matProjectionView); 
    104  
    105         matProjectionView = matViewing * matProjectionView; 
    106  
    107         frustum = Frustum(matProjectionView); 
    108  
    109  
    110         //////////// 
    111         //-- normalize the coefficients 
    112  
    113         for (int i = 0; i < 6; ++ i) 
    114         { 
    115                 // the clipping planes look outward the frustum, 
    116                 // so distances > 0 mean that a point is outside 
    117                 const float invLength = -1.0f / Magnitude(frustum.mClipPlanes[i].mNormal); 
    118          
    119                 frustum.mClipPlanes[i].mD *= invLength; 
    120                 frustum.mClipPlanes[i].mNormal *= invLength; 
    121         } 
    122 } 
    123  
    124  
    125 void Camera::SetupViewProjection() 
    126 { 
    127         glMatrixMode(GL_PROJECTION); 
    128         SetupProjection(); 
    129  
    130         glMatrixMode(GL_MODELVIEW); 
    131         // set up the view matrix 
    132         SetupCameraView(); 
    133 } 
    134  
    135  
    136 void Camera::SetupProjection() 
    137 { 
    138         glLoadIdentity(); 
    139         gluPerspective(mFOVy * 180.0f / M_PI, mAspect, mNear, mFar); 
    140 } 
    141  
    142  
    143 void Camera::SetupCameraView() 
    144 { 
    145         Matrix4x4 m; 
    146         GetModelViewMatrix(m); 
    147  
    148         glLoadMatrixf((float *)m.x); 
    149 } 
    150  
    151  
    152  
    153 void Camera::ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
    154                                                                    Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
    155                                                                    const Vector3 &view, const Vector3 &right, const Vector3 &up, 
    156                                                                    const Vector3 &pos, 
    157                                                                    float farthestVisibleDistance) const 
    158 { 
    159         const float z_near = mNear; 
    160         const float z_far = min(mFar, farthestVisibleDistance); 
    161  
    162         const float fov = mFOVy; 
    163  
    164         const float aspectRatio = GetAspect(); 
    165  
    166         const float h_near = tan(fov * 0.5f) * z_near; 
    167         const float w_near = h_near * aspectRatio; 
    168  
    169         const float h_far = tan(fov * 0.5f) * z_far; 
    170         const float w_far = h_far * aspectRatio; 
    171  
    172         const Vector3 fc = pos + view * z_far;  
    173          
    174  
    175         Vector3 t1, t2; 
    176  
    177         t1 = h_far * up; 
    178         t2 = w_far * right; 
    179  
    180         ftl = fc + t1 - t2; 
    181         ftr = fc + t1 + t2; 
    182         fbl = fc - t1 - t2; 
    183         fbr = fc - t1 + t2; 
    184  
    185         const Vector3 nc = pos + view * z_near; 
    186          
    187         t1 = h_near * up; 
    188         t2 = w_near * right; 
    189  
    190         ntl = nc + t1 - t2; 
    191         ntr = nc + t1 + t2; 
    192         nbl = nc - t1 - t2; 
    193         nbr = nc - t1 + t2; 
    194 } 
    195  
    196  
    197 void Camera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
    198                                                    Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
    199                                                    float farthestVisibleDistance) const 
    200 { 
    201         ComputePointsInternal(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr,  
    202                                                   GetDirection(), GetRightVector(), GetUpVector(), GetPosition(), 
    203                                                   farthestVisibleDistance); 
    204 } 
    205  
    206  
    207 /*void Camera::SetOrtho(bool ortho) 
    208 { 
    209         mIsOrtho = ortho; 
    210 }*/ 
    211  
    212  
    213 void Camera::Yaw(float angle) 
    214 { 
    215         mYaw += angle; 
    216         CalculateFromPitchAndYaw(); 
    217 } 
    218  
    219  
    220 void Camera::Pitch(float angle) 
    221 { 
    222         mPitch += angle; 
    223         CalculateFromPitchAndYaw(); 
    224 } 
    225  
    226  
    227 void Camera::SetDirection(const Vector3 &dir) 
    228 { 
    229         Vector3 ndir = -Normalize(dir); 
    230  
    231         mPitch = -atan2(ndir.x, ndir.y); 
    232         mYaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 
    233  
    234         CalculateFromPitchAndYaw(); 
    235 } 
    236  
    237  
    238 void Camera::CalculateFromPitchAndYaw() 
    239 { 
    240         mViewOrientation = mBaseOrientation; 
    241  
    242         Matrix4x4 roty = RotationYMatrix(mPitch); 
    243         Matrix4x4 rotx = RotationXMatrix(mYaw); 
    244  
    245         mViewOrientation *= roty; 
    246         mViewOrientation *= rotx; 
    247 } 
    248  
    249  
    250 Vector3 Camera::GetDirection() const 
    251 {  
    252         return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 
    253 } 
    254  
    255  
    256 Vector3 Camera::GetUpVector() const  
    257 {  
    258         return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 
    259 } 
    260  
    261  
    262 Vector3 Camera::GetRightVector() const  
    263 {  
    264         return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]);            
    265 } 
    266  
    267  
    268 Vector3 Camera::GetBaseDirection() const 
    269 {  
    270         return -Vector3(mBaseOrientation.x[0][2], mBaseOrientation.x[1][2], mBaseOrientation.x[2][2]); 
    271 } 
    272  
    273  
    274 Vector3 Camera::GetBaseUpVector() const  
    275 {  
    276         return Vector3(mBaseOrientation.x[0][1], mBaseOrientation.x[1][1], mBaseOrientation.x[2][1]); 
    277 } 
    278  
    279  
    280 Vector3 Camera::GetBaseRightVector() const  
    281 {  
    282         return Vector3(mBaseOrientation.x[0][0], mBaseOrientation.x[1][0], mBaseOrientation.x[2][0]); 
    283 } 
     18 
     19/**********************************************************/ 
     20/*            class Frustum implementation                */ 
     21/**********************************************************/ 
    28422 
    28523 
     
    31250                Plane3 &plane = mClipPlanes[i]; 
    31351 
    314                 //cout << "p" << i << " " << plane.mD  << endl; 
    315  
    31652                VertexArray::const_iterator it, it_end = vertices.end(); 
    317  
    31853                float minDist = 1e20; 
    31954 
     
    34681 
    34782 
    348 Polyhedron *Camera::ComputeFrustum(float farthestVisibleDistance) const 
     83 
     84/*********************************************************/ 
     85/*            class Camera implementation                */ 
     86/*********************************************************/ 
     87 
     88 
     89Camera::Camera()  
     90{ 
     91        SetPosition(Vector3(0, 0, 0)); 
     92 
     93        mPitch = mYaw = 0; 
     94        Precompute(baseDir); 
     95 
     96        CalculateFromPitchAndYaw(); 
     97} 
     98 
     99 
     100void Camera::Precompute(const Vector3 &dir)  
     101{ 
     102        Vector3 up = Vector3::UNIT_Z(); 
     103         
     104        mBaseOrientation = LookAt(Vector3::ZERO(), dir, up); 
     105        mViewOrientation = mBaseOrientation; 
     106} 
     107 
     108 
     109void Camera::SetPosition(const Vector3 &pos)  
     110{ 
     111        mPosition = pos; 
     112} 
     113 
     114 
     115void Camera::SetNear(float nearDist)  
     116{ 
     117        mNear = nearDist; 
     118} 
     119 
     120 
     121void Camera::SetFar(float farDist)  
     122{  
     123        mFar = farDist;  
     124} 
     125 
     126 
     127void Camera::GetModelViewMatrix(Matrix4x4 &mat) const 
     128{ 
     129        mat = mViewOrientation; 
     130 
     131        // note: left handed system => we go into positive z 
     132        mat.x[3][0] = -DotProd(GetRightVector(), mPosition); 
     133        mat.x[3][1] = -DotProd(GetUpVector(), mPosition); 
     134        mat.x[3][2] = DotProd(GetDirection(), mPosition); 
     135} 
     136 
     137 
     138void Camera::GetViewOrientationMatrix(Matrix4x4 &mat) const 
     139{ 
     140        mat = mViewOrientation; 
     141} 
     142 
     143 
     144void Camera::SetupViewProjection() 
     145{ 
     146        glMatrixMode(GL_PROJECTION); 
     147        SetupProjection(); 
     148 
     149        glMatrixMode(GL_MODELVIEW); 
     150        // set up the view matrix 
     151        SetupCameraView(); 
     152} 
     153 
     154 
     155void Camera::SetupProjection() 
     156{ 
     157        Matrix4x4 m; 
     158 
     159        GetProjectionMatrix(m); 
     160        glLoadMatrixf((float *)m.x); 
     161} 
     162 
     163 
     164void Camera::SetupCameraView() 
     165{ 
     166        Matrix4x4 m; 
     167        GetModelViewMatrix(m); 
     168 
     169        glLoadMatrixf((float *)m.x); 
     170} 
     171 
     172 
     173void Camera::Yaw(float angle) 
     174{ 
     175        mYaw += angle; 
     176        CalculateFromPitchAndYaw(); 
     177} 
     178 
     179 
     180void Camera::Pitch(float angle) 
     181{ 
     182        mPitch += angle; 
     183        CalculateFromPitchAndYaw(); 
     184} 
     185 
     186 
     187void Camera::SetDirection(const Vector3 &dir) 
     188{ 
     189        Vector3 ndir = -Normalize(dir); 
     190 
     191        mPitch = -atan2(ndir.x, ndir.y); 
     192        mYaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 
     193 
     194        CalculateFromPitchAndYaw(); 
     195} 
     196 
     197 
     198void Camera::CalculateFromPitchAndYaw() 
     199{ 
     200        mViewOrientation = mBaseOrientation; 
     201 
     202        Matrix4x4 roty = RotationYMatrix(mPitch); 
     203        Matrix4x4 rotx = RotationXMatrix(mYaw); 
     204 
     205        mViewOrientation *= roty; 
     206        mViewOrientation *= rotx; 
     207} 
     208 
     209 
     210Vector3 Camera::GetDirection() const 
     211{  
     212        return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 
     213} 
     214 
     215 
     216Vector3 Camera::GetUpVector() const  
     217{  
     218        return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 
     219} 
     220 
     221 
     222Vector3 Camera::GetRightVector() const  
     223{  
     224        return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]);            
     225} 
     226 
     227 
     228Vector3 Camera::GetBaseDirection() const 
     229{  
     230        return -Vector3(mBaseOrientation.x[0][2], mBaseOrientation.x[1][2], mBaseOrientation.x[2][2]); 
     231} 
     232 
     233 
     234Vector3 Camera::GetBaseUpVector() const  
     235{  
     236        return Vector3(mBaseOrientation.x[0][1], mBaseOrientation.x[1][1], mBaseOrientation.x[2][1]); 
     237} 
     238 
     239 
     240Vector3 Camera::GetBaseRightVector() const  
     241{  
     242        return Vector3(mBaseOrientation.x[0][0], mBaseOrientation.x[1][0], mBaseOrientation.x[2][0]); 
     243} 
     244 
     245 
     246void Camera::CalcFrustum(Frustum &frustum) 
     247{ 
     248        // we grab the plane equations of the six clipplanes of the viewfrustum 
     249        Matrix4x4 matViewing, matProjectionView; 
     250 
     251        GetModelViewMatrix(matViewing); 
     252        GetProjectionMatrix(matProjectionView); 
     253 
     254        matProjectionView = matViewing * matProjectionView; 
     255 
     256        frustum = Frustum(matProjectionView); 
     257 
     258 
     259        //////////// 
     260        //-- normalize the coefficients 
     261 
     262        for (int i = 0; i < 6; ++ i) 
     263        { 
     264                // the clipping planes look outward the frustum, 
     265                // so distances > 0 mean that a point is outside 
     266                const float invLength = -1.0f / Magnitude(frustum.mClipPlanes[i].mNormal); 
     267         
     268                frustum.mClipPlanes[i].mD *= invLength; 
     269                frustum.mClipPlanes[i].mNormal *= invLength; 
     270        } 
     271} 
     272 
     273 
     274/*********************************************************/ 
     275/*       Class PerspectiveCamera implementation           */ 
     276/*********************************************************/ 
     277 
     278 
     279PerspectiveCamera::PerspectiveCamera()  
     280{ 
     281        mFOVy = 60.0f * M_PI / 180.0f; 
     282} 
     283 
     284 
     285PerspectiveCamera::PerspectiveCamera(float aspect, float fieldOfView)  
     286{ 
     287        mFOVy = fieldOfView * M_PI / 180.0f; 
     288        mAspect = aspect; 
     289} 
     290 
     291 
     292Polyhedron *PerspectiveCamera::ComputeFrustum(float farthestVisibleDistance) const 
    349293{ 
    350294        Vector3 ftl, ftr, fbl, fbr; 
     
    384328 
    385329 
    386 } 
     330void PerspectiveCamera::ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
     331                                                                                          Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
     332                                                                                          const Vector3 &view, const Vector3 &right, const Vector3 &up, 
     333                                                                                          const Vector3 &pos, 
     334                                                                                          float farthestVisibleDistance) const 
     335{ 
     336        const float z_near = mNear; 
     337        const float z_far = min(mFar, farthestVisibleDistance); 
     338 
     339        const float fov = mFOVy; 
     340 
     341        const float aspectRatio = GetAspect(); 
     342 
     343        const float h_near = tan(fov * 0.5f) * z_near; 
     344        const float w_near = h_near * aspectRatio; 
     345 
     346        const float h_far = tan(fov * 0.5f) * z_far; 
     347        const float w_far = h_far * aspectRatio; 
     348 
     349        const Vector3 fc = pos + view * z_far;  
     350         
     351 
     352        Vector3 t1, t2; 
     353 
     354        t1 = h_far * up; 
     355        t2 = w_far * right; 
     356 
     357        ftl = fc + t1 - t2; 
     358        ftr = fc + t1 + t2; 
     359        fbl = fc - t1 - t2; 
     360        fbr = fc - t1 + t2; 
     361 
     362        const Vector3 nc = pos + view * z_near; 
     363         
     364        t1 = h_near * up; 
     365        t2 = w_near * right; 
     366 
     367        ntl = nc + t1 - t2; 
     368        ntr = nc + t1 + t2; 
     369        nbl = nc - t1 - t2; 
     370        nbr = nc - t1 + t2; 
     371} 
     372 
     373 
     374void PerspectiveCamera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
     375                                                                          Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
     376                                                                          float farthestVisibleDistance) const 
     377{ 
     378        ComputePointsInternal(ftl, ftr, fbl, fbr,  
     379                                  ntl, ntr, nbl, nbr,  
     380                                                  GetDirection(), GetRightVector(), GetUpVector(),  
     381                                                  GetPosition(), 
     382                                                  farthestVisibleDistance); 
     383} 
     384 
     385 
     386void PerspectiveCamera::GetProjectionMatrix(Matrix4x4 &mat) const 
     387{ 
     388        mat = GetPerspective(mFOVy, 1.0f / mAspect, mNear, mFar); 
     389 
     390        Matrix4x4 mat2; 
     391        glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat2.x); 
     392 
     393        cout << "my projview:\n" << mat  << endl; 
     394        cout << "gl projview:\n" << mat2 << endl; 
     395} 
     396 
     397 
     398} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h

    r3061 r3062  
    1212class Matrix4x4; 
    1313class Polyhedron; 
     14 
    1415 
    1516/** Class representing a frustum. 
     
    4344class Camera 
    4445{ 
    45         friend class ShadowMap; 
    46  
    4746public: 
    4847        /** Default constructor. 
    4948        */ 
    5049        Camera(); 
    51         /** Camera taking the image width and height and the field of view. 
    52         */ 
    53         Camera(float aspect, float fieldOfView = 90.f); 
    5450        /** Sets the current camera position. 
    5551        */ 
     
    7167        Vector3 GetBaseUpVector() const; 
    7268        Vector3 GetBaseRightVector() const; 
    73         /** Returns the field of view. 
    74         */ 
    75         inline float GetFov() const { return mFOVy; } 
    76         /** Returns the aspect ratio. 
    77         */ 
    78         inline float GetAspect() const { return mAspect; } 
    7969        /** Sets up viewing matrices in for opengl rendering 
    8070        */ 
     
    8272        /** Returns the current projection matrix. 
    8373        */ 
    84         void GetProjectionMatrix(Matrix4x4 &mat) const; 
     74        virtual void GetProjectionMatrix(Matrix4x4 &mat) const = 0; 
    8575        /** Returns the current model view matrix. 
    8676        */ 
     
    8979        */ 
    9080        void GetViewOrientationMatrix(Matrix4x4 &mat) const; 
    91         /** Calculates a frustum from the projection and the modelview matrix. 
    92         */ 
    93         void CalcFrustum(Frustum &frustum); 
    94         /** Computes the extremal points of this frustum. 
    95                 If farthestVisibleDistance is nearer than the far plane,  
    96                 it is used to define the far plane instead. 
    97         */ 
    98         void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
    99                                Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
    100                                            float farthestVisibleDistance = 1e25f) const; 
    10181        /** Returns the near plane. 
    10282        */ 
     
    11191        */ 
    11292        void SetFar(float farDist); 
    113         /** Sets this camera to orthographic projection. 
    114         */ 
    115         //void SetOrtho(bool ortho); 
    11693        /** Set yaw (rotation around vertical axis. 
    11794        */ 
     
    132109        */ 
    133110        void SetDirection(const Vector3 &direction); 
    134         /** Returns frustum as polyhedron.  
    135         */ 
    136         Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 
    137111        /** Sets up projection matrix in OpenGl. 
    138112        */ 
     
    141115        */ 
    142116        void SetupViewProjection(); 
    143  
     117        /** Calculates a frustum from the projection and the modelview matrix. 
     118        */ 
     119        void CalcFrustum(Frustum &frustum); 
    144120 
    145121protected: 
     
    148124 
    149125        void CalculateFromPitchAndYaw(); 
     126 
     127 
     128        //////////////// 
     129        //-- members 
     130 
     131        float mNear; 
     132        float mFar; 
     133         
     134        Matrix4x4 mBaseOrientation; 
     135        Matrix4x4 mViewOrientation; 
     136 
     137        float mPitch; 
     138        float mYaw; 
     139 
     140        Vector3 mPosition; 
     141}; 
     142 
     143 
     144/** Classs representing a perspective camera. 
     145*/ 
     146class PerspectiveCamera: public Camera 
     147{ 
     148        friend class ShadowMap; 
     149 
     150public: 
     151        /** Default constructor. 
     152        */ 
     153        PerspectiveCamera(); 
     154        /** Camera taking the image width and height and the field of view. 
     155        */ 
     156        PerspectiveCamera(float aspect, float fieldOfView = 90.f); 
     157        /** Returns the field of view. 
     158        */ 
     159        inline float GetFov() const { return mFOVy; } 
     160        /** Returns the aspect ratio. 
     161        */ 
     162        inline float GetAspect() const { return mAspect; } 
     163        /** Returns the current projection matrix. 
     164        */ 
     165        virtual void GetProjectionMatrix(Matrix4x4 &mat) const; 
     166        /** Computes the extremal points of this frustum. 
     167                If farthestVisibleDistance is nearer than the far plane,  
     168                it is used to define the far plane instead. 
     169        */ 
     170        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
     171                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
     172                                           float farthestVisibleDistance = 1e25f) const; 
     173        /** Returns frustum as polyhedron.  
     174        */ 
     175        Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 
     176 
     177 
     178protected: 
    150179 
    151180        void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
     
    159188 
    160189        float mFOVy; 
    161         float mNear; 
    162         float mFar; 
    163          
    164         /// if this camera is orthgraphic or perspective 
    165         //bool mIsOrtho; 
    166  
    167         Matrix4x4 mBaseOrientation; 
    168         Matrix4x4 mViewOrientation; 
    169  
    170         float mPitch; 
    171         float mYaw; 
    172  
    173         Vector3 mPosition; 
    174  
    175190        float mAspect; 
    176191}; 
    177192 
     193 
    178194} 
    179195#endif 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3057 r3062  
    231231 
    232232 
    233 DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor): 
     233DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam, float scaleFactor): 
    234234mWidth(w), mHeight(h),  
    235235mCamera(cam), 
     
    298298 
    299299        i = 0; 
    300  
    301300        sCgSsaoProgram->AddParameter("colors", i ++); 
    302301        sCgSsaoProgram->AddParameter("normals", i ++); 
     
    314313 
    315314        i = 0; 
    316  
    317315        sCgGiProgram->AddParameter("colors", i ++); 
    318316        sCgGiProgram->AddParameter("normals", i ++); 
     
    529527        sCgSsaoProgram->SetValue3f(10, tr.x, tr.y, tr.z); 
    530528 
     529        cout << "new projview:\n" << projViewMatrix << endl; 
     530        cout << "old projview:\n" << oldProjViewMatrix << endl; 
     531 
    531532        sCgSsaoProgram->SetMatrix(11, projViewMatrix); 
    532533        sCgSsaoProgram->SetMatrix(12, oldProjViewMatrix); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3038 r3062  
    1515class FrameBufferObject; 
    1616class Vector3; 
    17 class Camera; 
     17class PerspectiveCamera; 
    1818class Matrix4x4; 
    1919class ShadowMap; 
     
    3636                exact scene size that was scaled in order to improve floating point precision. 
    3737        */ 
    38         DeferredRenderer(int w, int h, Camera *cam, float scaleFactor); 
     38        DeferredRenderer(int w, int h, PerspectiveCamera *cam, float scaleFactor); 
    3939        /** The algorithm renders the scene given an fbo consists of 1 color buffer,  
    4040                1 position buffer, and 1 normal buffer. 
     
    122122        int mHeight; 
    123123 
    124         Camera *mCamera; 
     124        PerspectiveCamera *mCamera; 
    125125 
    126126        bool mUseTemporalCoherence; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp

    r2953 r3062  
    649649} 
    650650 
    651 Matrix4x4  
    652 NormalTransformMatrix(const Matrix4x4 &tform) 
     651 
     652Matrix4x4  NormalTransformMatrix(const Matrix4x4 &tform) 
    653653{ 
    654654        Matrix4x4 m = tform; 
     
    692692        return m; 
    693693} 
    694 /* 
    695  
    696 template<class REAL> 
    697 Matrix4<REAL>& scaleTranslateToFit(Matrix4<REAL>& output, const Vector3<REAL>& vMin, const Vector3<REAL>& vMax) { 
    698         const REAL diffX = vMax.x()-vMin.x(); 
    699         output[ 0] = 2/diffX; 
    700         output[ 4] = 0; 
    701         output[ 8] = 0; 
    702         output[12] = -(vMax.x()+vMin.x())/diffX; 
    703  
    704         const REAL diffY = vMax.y()-vMin.y(); 
    705         output[ 1] = 0; 
    706         output[ 5] = 2/diffY; 
    707         output[ 9] = 0; 
    708         output[13] = -(vMax.y()+vMin.y())/diffY; 
    709  
    710         const REAL diffZ = vMax.z()-vMin.z(); 
    711         output[ 2] = 0; 
    712         output[ 6] = 0; 
    713         output[10] = 2/diffZ; 
    714         output[14] = -(vMax.z()+vMin.z())/diffZ; 
    715  
    716         output[ 3] = 0; 
    717         output[ 7] = 0; 
    718         output[11] = 0; 
    719         output[15] = 1; 
    720         return output; 
    721 } 
     694 
     695 
     696/** The resultig matrix that is equal to the result of glFrustum 
    722697*/ 
    723  
    724  
    725  
    726 //output is initialized with the same result as glFrustum 
    727698Matrix4x4 GetFrustum(float left, float right,  
    728699                                         float bottom, float top,  
     
    781752 
    782753 
    783 } 
     754/** The resultig matrix that is equal to the result of glOrtho 
     755*/ 
     756Matrix4x4 GetOrtho(float left, float right, float bottom, float top, float far, float near) 
     757{ 
     758        Matrix4x4 m; 
     759 
     760        const float xDif = 1.0f / (right - left); 
     761        const float yDif = 1.0f / (top - bottom); 
     762        const float zDif = 1.0f / (far - near); 
     763 
     764        m.x[0][0] = 2.0f * xDif; 
     765        m.x[0][1] = .0f; 
     766        m.x[0][2] = .0f; 
     767        m.x[0][3] = .0f; 
     768 
     769        m.x[1][0] = .0f; 
     770        m.x[1][1] = 2.0f * yDif; 
     771        m.x[1][2] = .0f; 
     772        m.x[1][3] = .0f; 
     773 
     774        m.x[2][0] = .0f; 
     775        m.x[2][1] = .0f; 
     776        m.x[2][2] = -2.0f * zDif; 
     777        m.x[2][3] = .0f; 
     778         
     779        m.x[3][0] = (right + left) * xDif; 
     780        m.x[3][1] = (top + bottom) * yDif; 
     781        m.x[3][2] = (far + near) * zDif; 
     782        m.x[3][3] = 1.0f; 
     783 
     784        return m; 
     785} 
     786 
     787/** The resultig matrix that is equal to the result of gluPerspective 
     788*/ 
     789Matrix4x4 GetPerspective(float fov, float aspect, float near, float far) 
     790{ 
     791        Matrix4x4 m; 
     792 
     793        const float x = 1.0f / tan(fov * 0.5f); 
     794        const float zDif = 1.0f / (near - far); 
     795 
     796        m.x[0][0] = x / aspect; 
     797        m.x[0][1] = .0f; 
     798        m.x[0][2] = .0f; 
     799        m.x[0][3] = .0f; 
     800 
     801        m.x[1][0] = .0f; 
     802        m.x[1][1] = x; 
     803        m.x[1][2] = .0f; 
     804        m.x[1][3] = .0f; 
     805 
     806        m.x[2][0] = .0f; 
     807        m.x[2][1] = .0f; 
     808        m.x[2][2] = (far + near) * zDif; 
     809        m.x[2][3] = -1.0f; 
     810         
     811        m.x[3][0] = .0f; 
     812        m.x[3][1] = .0f; 
     813        m.x[3][2] = 2.0f *(far * near) * zDif; 
     814        m.x[3][3] = 0.0f; 
     815 
     816        return m; 
     817} 
     818 
     819 
     820} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h

    r2944 r3062  
    165165Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far); 
    166166Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
    167  
     167Matrix4x4 GetOrtho(float fov, float aspect, float near, float far); 
     168Matrix4x4 GetPerspective(float fov, float aspect, float near, float far); 
    168169 
    169170} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r3061 r3062  
    139139        const float ylen = mSceneBox.Size().y * 0.5f; 
    140140         
    141         Camera *orthoCam = new Camera(xlen / ylen); 
     141        PerspectiveCamera *orthoCam = new PerspectiveCamera(xlen / ylen); 
    142142        //orthoCam->SetOrtho(true); 
    143143 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r3061 r3062  
    134134 
    135135 
    136 ShadowMap::ShadowMap(DirectionalLight *light 
    137                                          , int size,  
     136ShadowMap::ShadowMap(DirectionalLight *light,  
     137                                         int size,  
    138138                                         const AxisAlignedBox3 &sceneBox, 
    139                                          Camera *cam): 
     139                                         PerspectiveCamera *cam): 
    140140mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) 
    141141{ 
     
    148148 
    149149 
    150         mShadowCam = new Camera(1); 
     150        mShadowCam = new PerspectiveCamera(1); 
    151151        //mShadowCam->SetOrtho(true); 
    152152} 
     
    713713        glDisable(GL_POLYGON_OFFSET_FILL); 
    714714} 
     715 
     716 
    715717} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r3034 r3062  
    1414class RenderTraverser; 
    1515class Vector3; 
    16 class Camera; 
     16class PerspectiveCamera; 
    1717class DirectionalLight; 
     18 
    1819 
    1920/** This class implements a the computation of single shadow map using  
     
    2728                The shadow map has resolution size squared. 
    2829        */ 
    29         ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 
     30        ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, PerspectiveCamera *cam); 
    3031 
    3132        ~ShadowMap(); 
     
    5253        /** Returns the camera used for light view rendering. 
    5354        */ 
    54         Camera *GetShadowCamera() const { return mShadowCam; } 
     55        PerspectiveCamera *GetShadowCamera() const { return mShadowCam; } 
    5556        /** Renders the scene from shadow view using conventional shading. 
    5657        */ 
     
    111112        int mSize; 
    112113        /// the shadow view 
    113         Camera *mShadowCam; 
     114        PerspectiveCamera *mShadowCam; 
    114115        /// the texture matrix 
    115116        Matrix4x4 mTextureMatrix; 
     
    117118        DirectionalLight *mLight; 
    118119        /// the scene camera 
    119         Camera *mCamera; 
     120        PerspectiveCamera *mCamera; 
    120121 
    121122        Matrix4x4 mLightProjView; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp

    r2963 r3062  
    66#include "RenderState.h" 
    77#include "ShadowMapping.h" 
    8  
    98#include <stack> 
    109 
     
    7069 
    7170Visualization::Visualization(Bvh *bvh,  
    72                                                          Camera *camera,  
     71                                                         PerspectiveCamera *camera,  
    7372                                                         Camera *vizCamera,  
    7473                                                         RenderState *renderState):  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h

    r2889 r3062  
    99 
    1010class Bvh; 
     11class PerspectiveCamera; 
    1112class Camera; 
    1213class RenderState; 
     
    2324            as parameters 
    2425        */ 
    25         Visualization(Bvh *bvh, Camera *camera, Camera *vizCamera, RenderState *state); 
     26        Visualization(Bvh *bvh, PerspectiveCamera *camera, Camera *vizCamera, RenderState *state); 
    2627 
    2728        ~Visualization(); 
     
    3839        /** Sets the currently used scene camera. 
    3940        */ 
    40         void SetCamera(Camera *cam)  {mCamera = cam;} 
     41        void SetCamera(PerspectiveCamera *cam)  {mCamera = cam;} 
    4142        /** Sets the current render state 
    4243        */ 
     
    4546        */ 
    4647        void SetFrameId(int frameId); 
    47  
    48                 /** Renders a camera frustum. 
     48        /** Renders a camera frustum. 
    4949        */ 
    5050        void RenderFrustum(); 
     
    5656 
    5757        /// the current camera 
    58         Camera *mCamera; 
     58        PerspectiveCamera *mCamera; 
    5959        /// the visualization camera 
    6060        Camera *mVizCamera; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3061 r3062  
    7979ShaderManager *shaderManager = NULL; 
    8080/// the scene camera 
    81 Camera *camera = NULL; 
     81PerspectiveCamera *camera = NULL; 
    8282/// the scene camera 
    83 Camera *visCamera = NULL; 
     83PerspectiveCamera *visCamera = NULL; 
    8484/// the visualization 
    8585Visualization *visualization = NULL; 
     
    257257void CalcDecimalPoint(string &str, int d); 
    258258/// Creates the traversal method (vfc, stopandwait, chc, chc++) 
    259 RenderTraverser *CreateTraverser(Camera *cam); 
     259RenderTraverser *CreateTraverser(PerspectiveCamera *cam); 
    260260 
    261261/// place the viewer on the floor plane 
     
    369369        /////////////////////////// 
    370370 
    371         camera = new Camera(winWidth / winHeight, fov); 
     371        camera = new PerspectiveCamera(winWidth / winHeight, fov); 
    372372        camera->SetNear(nearDist); 
    373373        camera->SetFar(1000); 
     
    376376        camera->SetPosition(camPos); 
    377377 
    378         visCamera = new Camera(winWidth / winHeight, fov); 
     378        visCamera = new PerspectiveCamera(winWidth / winHeight, fov); 
    379379        visCamera->SetNear(0.0f); 
    380380        visCamera->Yaw(.5 * M_PI); 
     
    661661 
    662662 
    663 RenderTraverser *CreateTraverser(Camera *cam) 
     663RenderTraverser *CreateTraverser(PerspectiveCamera *cam) 
    664664{ 
    665665        RenderTraverser *tr; 
Note: See TracChangeset for help on using the changeset viewer.