Changeset 3061 for GTP


Ignore:
Timestamp:
10/23/08 12:26:37 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
11 edited

Legend:

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

    r3053 r3061  
    11891189                // no split could be achieved => just halve number of objects 
    11901190                split = (leaf->mLast - leaf->mFirst) / 2; 
    1191                 cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << split << " " << leaf->mLast << endl; 
     1191                cerr << "no reduction " << leaf->CountPrimitives() << " " << leaf->mFirst << " " << leaf->mLast << endl; 
    11921192        } 
    11931193 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r2988 r3061  
    1818Camera::Camera()  
    1919{ 
    20         mWidth = 100; 
    21         mHeight = 100; 
    22         mFovy = 60.0f * M_PI / 180.0f; 
    23         mIsOrtho = false; 
     20        mFOVy = 60.0f * M_PI / 180.0f; 
     21        //mIsOrtho = false; 
    2422         
    2523        SetPosition(Vector3(0, 0, 0)); 
     
    3230 
    3331 
    34 Camera::Camera(int width, int height, float fieldOfView)  
    35 { 
    36         mWidth = width; 
    37         mHeight = height; 
    38          
    39         mFovy = fieldOfView * M_PI / 180.0f; 
    40  
    41         mIsOrtho = false; 
     32Camera::Camera(float aspect, float fieldOfView)  
     33{ 
     34        mFOVy = fieldOfView * M_PI / 180.0f; 
     35        mAspect = aspect; 
     36        //mIsOrtho = false; 
    4237 
    4338        SetPosition(Vector3::ZERO()); 
     
    5348{ 
    5449        Vector3 up = Vector3::UNIT_Z(); 
    55         //Vector3 right = Normalize(CrossProd(dir, up)); 
    56         //up = Normalize(CrossProd(right, dir)); 
    57  
    58         //mBaseOrientation = Matrix4x4(right, up, -dir); 
    59         mBaseOrientation = LookAt(Vector3::ZERO(), dir, up);//Matrix4x4(right, up, -dir); 
     50         
     51        mBaseOrientation = LookAt(Vector3::ZERO(), dir, up); 
    6052        mViewOrientation = mBaseOrientation; 
    6153} 
     
    128120                frustum.mClipPlanes[i].mNormal *= invLength; 
    129121        } 
     122} 
     123 
     124 
     125void 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 
     136void Camera::SetupProjection() 
     137{ 
     138        glLoadIdentity(); 
     139        gluPerspective(mFOVy * 180.0f / M_PI, mAspect, mNear, mFar); 
    130140} 
    131141 
     
    147157                                                                   float farthestVisibleDistance) const 
    148158{ 
    149         float z_near = mNear; 
    150         float z_far = min(mFar, farthestVisibleDistance); 
    151  
    152         float fov = mFovy; 
     159        const float z_near = mNear; 
     160        const float z_far = min(mFar, farthestVisibleDistance); 
     161 
     162        const float fov = mFOVy; 
    153163 
    154164        const float aspectRatio = GetAspect(); 
     
    162172        const Vector3 fc = pos + view * z_far;  
    163173         
     174 
    164175        Vector3 t1, t2; 
    165176 
     
    194205 
    195206 
    196 void Camera::SetOrtho(bool ortho) 
    197 { 
    198         mIsOrtho = true; 
    199 } 
     207/*void Camera::SetOrtho(bool ortho) 
     208{ 
     209        mIsOrtho = ortho; 
     210}*/ 
    200211 
    201212 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h

    r3045 r3061  
    3939 
    4040 
     41/** Classs representing a camera. 
     42*/ 
    4143class Camera 
    4244{ 
     
    4446 
    4547public: 
    46          
     48        /** Default constructor. 
     49        */ 
    4750        Camera(); 
    48  
    49         Camera(int width, int height, float fieldOfView = 90.f); 
    50  
     51        /** Camera taking the image width and height and the field of view. 
     52        */ 
     53        Camera(float aspect, float fieldOfView = 90.f); 
    5154        /** Sets the current camera position. 
    5255        */ 
    5356        void SetPosition(const Vector3 &pos); 
    54  
     57        /** See set. 
     58        */ 
    5559        inline Vector3 GetPosition() const { return mPosition; } 
    56          
     60        /** Returns view direction. 
     61        */ 
    5762        Vector3 GetDirection() const; 
     63        /** Returns up vector. 
     64        */ 
    5865        Vector3 GetUpVector() const; 
     66        /** Returns right vector. 
     67        */ 
    5968        Vector3 GetRightVector() const; 
    6069 
     
    6271        Vector3 GetBaseUpVector() const; 
    6372        Vector3 GetBaseRightVector() const; 
    64  
    65         inline float GetFov() const { return mFovy; } 
    66         inline float GetAspect() const { return (float) mWidth / mHeight; } 
    67         inline int GetWidth() const { return mWidth; } 
    68         inline int GetHeight() const { return mHeight; } 
    69  
    70         /** Sets up viewing in gl 
     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; } 
     79        /** Sets up viewing matrices in for opengl rendering 
    7180        */ 
    7281        void SetupCameraView(); 
     
    102111        */ 
    103112        void SetFar(float farDist); 
    104          
    105         void SetOrtho(bool ortho); 
    106  
     113        /** Sets this camera to orthographic projection. 
     114        */ 
     115        //void SetOrtho(bool ortho); 
     116        /** Set yaw (rotation around vertical axis. 
     117        */ 
    107118        void Yaw(float angle); 
     119        /** Set pitch. 
     120        */ 
    108121        void Pitch(float angle); 
    109          
     122        /** Returns pitch. 
     123        */ 
    110124        float GetPitch() const { return mPitch; } 
     125        /** Returns yaw. 
     126        */ 
    111127        float GetYaw() const { return mYaw; } 
     128        /** Resets pitch and yaw. 
     129        */ 
    112130        void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; } 
    113         /** Sets the camera direction. 
     131        /** Sets the view direction. 
    114132        */ 
    115133        void SetDirection(const Vector3 &direction); 
     
    117135        */ 
    118136        Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 
     137        /** Sets up projection matrix in OpenGl. 
     138        */ 
     139        void SetupProjection(); 
     140        /** Sets up view + projection matrix in OpenGl. 
     141        */ 
     142        void SetupViewProjection(); 
     143 
    119144 
    120145protected: 
     
    133158        //-- members 
    134159 
    135         float mFovy; 
    136         int mWidth; 
    137         int mHeight; 
    138  
     160        float mFOVy; 
    139161        float mNear; 
    140  
    141162        float mFar; 
    142  
    143         bool mIsOrtho; 
     163         
     164        /// if this camera is orthgraphic or perspective 
     165        //bool mIsOrtho; 
    144166 
    145167        Matrix4x4 mBaseOrientation; 
     
    150172 
    151173        Vector3 mPosition; 
     174 
     175        float mAspect; 
    152176}; 
    153177 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp

    r3060 r3061  
    1414{ 
    1515 
    16  
    17 /*inline static bool CompDist(RenderQueueBucket *b1, RenderQueueBucket *b2) 
    18 { 
    19         return (b1->mMinDistance < b2->mMinDistance); 
    20 }*/ 
    2116RenderQueue::RenderQueue():  
    2217mState(NULL),  
    23 mCamera(NULL), 
    2418mNumEntries(0) 
    2519{ 
     
    2721 
    2822 
    29 RenderQueue::RenderQueue(RenderState *state, Camera *cam): 
     23RenderQueue::RenderQueue(RenderState *state): 
    3024mState(state),  
    31 mCamera(cam), 
    3225mNumEntries(0) 
    3326{ 
     
    158151        if (bucket->IsEmpty()) 
    159152        { 
    160                 // add to currently active buckets that will be rendered 
     153                // add bucket to the list of currently active buckets that will be rendered 
    161154                // assume that the incoming nodes are ordered by distance  
    162155                // => active buckets are sorted by distance 
    163156                mActiveBuckets.push_back(bucket); 
    164          
    165                 // => set min dist on first incoming node 
    166                 //const Vector3 v = shape->GetCenter() - mCamera->GetPosition(); 
    167                 //const float dist = SqrMagnitude(v); 
    168                 //bucket->mMinDistance = dist; 
    169  
    170                 } 
     157        } 
    171158 
    172159        bucket->mShapes.push_back(shape); 
     
    178165        for (size_t i = 0; i < mActiveBuckets.size(); ++ i) 
    179166        { 
    180                 //mBuckets[i]->mMinDistance = -1; 
    181167                mActiveBuckets[i]->mShapes.clear(); 
    182168        } 
    183169 
    184170        mNumEntries = 0; 
    185  
    186171        mActiveBuckets.clear(); 
    187172} 
     
    196181void RenderQueue::Render() 
    197182{ 
    198         // sort the buckets 
    199         //Sort(); 
    200  
    201183        // render all buckets 
    202         for (size_t i = 0; i < mBuckets.size(); ++ i) 
    203         { 
    204                 ShapeContainer::const_iterator sit, sit_end = mBuckets[i]->mShapes.end(); 
    205  
    206                 for (sit = mBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit) 
     184        for (size_t i = 0; i < mActiveBuckets.size(); ++ i) 
     185        { 
     186                ShapeContainer::const_iterator sit, sit_end = mActiveBuckets[i]->mShapes.end(); 
     187 
     188                for (sit = mActiveBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit) 
    207189                { 
    208190                        Shape *shape = *sit; 
     
    210192                } 
    211193        } 
    212         //Print(); 
    213 } 
    214  
    215  
    216 void RenderQueue::Print() 
    217 { 
    218         for (size_t i = 0; i < mBuckets.size(); ++ i) 
    219         { 
    220                 Debug << "\n******\nbucket " << (int)i << endl; 
    221  
    222                 ShapeContainer::const_iterator sit, sit_end = mBuckets[i]->mShapes.end(); 
    223  
    224                 for (sit = mBuckets[i]->mShapes.begin(); sit != sit_end; ++ sit) 
    225                 { 
    226                         Shape *shape = *sit; 
    227                          
    228                         Technique *tech = shape->GetMaterial()->GetTechnique(mState->GetRenderTechnique()); 
    229                         int tsize = tech->GetTexture() ? tech->GetTexture()->GetByteSize() : 0; 
    230                          
    231                         float dist = SqrMagnitude(shape->GetBoundingBox().Center() - mCamera->GetPosition()); 
    232                          
    233                         Debug << "e: " << shape << " a: " << tech->IsAlphaTestEnabled() << " s: " << tsize << " d: " << dist << " " << endl; 
    234                 } 
    235         } 
    236 } 
    237  
    238  
    239 /*void RenderQueue::Sort() 
    240 { 
    241         // sort buckets itself by distance 
    242         sort(mBuckets.begin(), mBuckets.end(), CompDist); 
    243 }*/ 
     194        //cout << "active: " << (int)mActiveBuckets.size() << endl; 
     195} 
    244196 
    245197 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h

    r3060 r3061  
    6363        */ 
    6464        RenderQueue(); 
    65         /** Constructor taking a render queue 
     65        /** Constructor passing the current render state 
    6666        */ 
    67         RenderQueue(RenderState *state, Camera *cam); 
     67        RenderQueue(RenderState *state); 
    6868 
    6969        ~RenderQueue(); 
     
    7777        */ 
    7878        void SetRenderState(RenderState *state); 
    79         /** Sets the current render state 
    80         */ 
    81         void SetCamera(Camera *cam); 
    8279        /** Returns the number of entries currently in the queue. 
    8380        */ 
     
    9895        */ 
    9996        void Render(); 
    100         /** Prints the current state of the render queue. 
    101         */ 
    102         void Print(); 
    10397 
    10498 
     
    108102        // the current render state 
    109103        RenderState *mState; 
    110          
    111         Camera *mCamera; 
    112104        /// each bucket contains objects with similar materials that don't cause a hard state change 
    113105        std::vector<RenderQueueBucket *> mBuckets; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r3055 r3061  
    1313class Material; 
    1414 
    15 /** The current render state. 
     15/** Class representing the current render state. 
    1616*/ 
    1717class RenderState 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

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

    r3038 r3061  
    148148 
    149149 
    150         mShadowCam = new Camera(mSize, mSize); 
    151         mShadowCam->SetOrtho(true); 
     150        mShadowCam = new Camera(1); 
     151        //mShadowCam->SetOrtho(true); 
    152152} 
    153153 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h

    r3054 r3061  
    2222 
    2323 
    24 /** Class representing a shape. 
    25     A shape basically consists of geometry and a material 
     24/** Class representing a 3D shape consisting  
     25        of geometry (with texture coordinates, normals) and a material 
    2626*/ 
    2727class Shape 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h

    r3028 r3061  
    1515 
    1616 
    17 /** Class representing a wrapper class for a 3D transformation 
     17/** Wrapper class for a 3D transformation 
    1818*/ 
    1919class Transform3 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3059 r3061  
    369369        /////////////////////////// 
    370370 
    371         camera = new Camera(winWidth, winHeight, fov); 
     371        camera = new Camera(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 Camera(winWidth / winHeight, fov); 
    379379        visCamera->SetNear(0.0f); 
    380380        visCamera->Yaw(.5 * M_PI); 
     
    382382        // create a new light 
    383383        light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1)); 
    384  
    385  
    386         renderQueue = new RenderQueue(&state, camera); 
     384        // the render queue for material sorting 
     385        renderQueue = new RenderQueue(&state); 
    387386 
    388387        glutInitWindowSize(winWidth, winHeight); 
     
    761760        oldViewProjMat = viewProjMat; 
    762761 
    763         glMatrixMode(GL_PROJECTION); 
    764         glLoadIdentity(); 
    765         gluPerspective(fov, winAspectRatio, nearDist, farDist); 
    766  
    767         glMatrixMode(GL_MODELVIEW); 
    768          
    769         // set up the camera view 
    770         camera->SetupCameraView(); 
    771                  
     762        camera->SetupViewProjection(); 
     763 
     764 
    772765        ///////////////// 
    773766        //-- compute view projection matrix and store for later use 
     
    15811574 
    15821575        glLoadIdentity(); 
    1583          
    15841576        glOrtho(-offs, offs, -offs, offs, 0.0f, box.Size().z * 100.0f);  
    15851577 
Note: See TracChangeset for help on using the changeset viewer.