Changeset 2780 for GTP/trunk


Ignore:
Timestamp:
06/19/08 18:43:17 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
4 edited

Legend:

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

    r2779 r2780  
    77{ 
    88 
    9 using namespace std; 
    10  
    119 
    1210Camera::Camera()  
     
    1513        mHeight = 100; 
    1614        mFovy = 90.0f * M_PI / 180.0f; 
    17         mIsOrtho = false; 
    18          
    19         SetPosition(Vector3(0, 0, 0)); 
    20  
    21         mPitch = mYaw = 0; 
    22         Precompute(); 
    2315} 
    2416 
     
    3022         
    3123        mFovy = fieldOfView * M_PI / 180.0f; 
    32  
    33         mIsOrtho = false; 
    34  
    35         SetPosition(Vector3(0, 0, 0)); 
    36  
    37         SetPosition(Vector3(0, 0, 0)); 
    38  
    39         mPitch = mYaw = 0; 
    40         Precompute(); 
    4124} 
    4225 
     
    4427void Camera::Precompute()  
    4528{ 
    46         Vector3 direction = Vector3(0, 1, 0); 
    47  
    48         Vector3 side = CrossProd(Vector3(1, 0, 0), direction); 
    49          
    50         Vector3 up = -Normalize(CrossProd(side, direction)); 
    51         Vector3 right = -Normalize(CrossProd(direction, up)); 
    52  
    53         mBaseOrientation = Matrix4x4(right, up, direction); 
    54         mViewOrientation = mBaseOrientation; 
    55         cout<<"view: " << direction << " right: " << right << " up " << up << endl; 
    56 } 
    57  
     29        mDirection.Normalize(); 
     30 
     31        //Vector3 side = CrossProd(Vector3(0, 1, 0), mDirection); 
     32        Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection); 
     33         
     34        mUp = -Normalize(CrossProd(side, mDirection)); 
     35        mRight = -Normalize(CrossProd(mDirection, mUp)); 
     36 
     37 
     38        float k = tan(mFovy/2); 
     39        mUp *= k; 
     40        mRight *= k*mWidth/mHeight; 
     41} 
    5842 
    5943 
     
    6145{ 
    6246        mPosition = pos; 
     47        Precompute(); 
     48} 
     49 
     50 
     51void Camera::SetDirection(const Vector3 &dir)  
     52{ 
     53        mDirection = dir; 
     54        Precompute(); 
    6355} 
    6456 
     
    6759{ 
    6860        mNear = nearDist; 
     61} 
     62 
     63 
     64void Camera::LookInBox(const AxisAlignedBox3 &box) 
     65{ 
     66        //mDirection = Vector3(0, 0, 1); 
     67        mDirection = Vector3(0, 1, 0); 
     68        mPosition = box.Center(); 
     69        mPosition.z = box.Min(2) + 0.9f * box.Size(2); 
     70 
     71        Precompute(); 
     72} 
     73 
     74 
     75void Camera::LookAtBox(const AxisAlignedBox3 &box) 
     76{ 
     77        mDirection = Vector3(0, box.Min().y - box.Max().y, 0); 
     78        mPosition = Vector3(0);//box.Max() - mDirection; 
     79 
     80        Precompute(); 
    6981} 
    7082 
     
    147159void Camera::SetupCameraView() 
    148160{ 
    149         Matrix4x4 viewOrientation = mViewOrientation; 
    150         Vector3 pos = -mPosition; 
    151         pos = mViewOrientation * pos; 
    152  
    153         viewOrientation.x[3][0] = pos.x; 
    154         viewOrientation.x[3][1] = pos.y; 
    155         viewOrientation.x[3][2] = pos.z; 
    156  
    157161        glLoadIdentity(); 
    158         glMultMatrixf((float *)viewOrientation.x); 
     162        gluLookAt(mPosition.x, mPosition.y, mPosition.z, 
     163                  mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z,  
     164                          mUp.x, mUp.y, mUp.z); 
     165 
     166        //std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl; 
    159167} 
    160168 
     
    172180        const float w_far = h_far * GetAspect(); 
    173181 
    174         const Vector3 view = GetDirection(); 
     182        const Vector3 view = mDirection; 
    175183        const Vector3 fc = mPosition + view * z_far;  
    176184         
    177         const Vector3 up = GetUpVector(); 
    178  
    179         const Vector3 right = GetRightVector(); 
     185        const Vector3 up = mUp; 
     186 
     187        const Vector3 right = mRight; 
    180188 
    181189        Vector3 t1, t2; 
     
    189197        fbr = fc - t1 + t2; 
    190198 
    191         const Vector3 nc = mPosition + view * z_near; 
     199        const Vector3 nc = mPosition + mDirection * z_near; 
    192200         
    193201        t1 = h_near * 0.5f * up; 
     
    201209 
    202210 
    203 void Camera::SetOrtho(bool ortho) 
    204 { 
    205         mIsOrtho = true; 
    206 } 
    207  
    208  
    209 void Camera::Yaw(float angle) 
    210 { 
    211         mYaw += angle; 
    212         CalculateFromPitchAndYaw(); 
    213         /* 
    214         Matrix4x4 viewOrientation(mRight, mUp, mDirection); 
    215         Matrix4x4 rot = RotationYMatrix(angle); 
    216  
    217         viewOrientation = viewOrientation * rot; 
    218  
    219         mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]); 
    220         mRight =     Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]); 
    221         mUp =        Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/ 
    222 } 
    223  
    224  
    225 void Camera::Pitch(float angle) 
    226 { 
    227         mPitch += angle; 
    228         CalculateFromPitchAndYaw(); 
    229 } 
    230  
    231  
    232 void Camera::CalculateFromPitchAndYaw() 
    233 { 
    234         mViewOrientation = mBaseOrientation; 
    235  
    236         Matrix4x4 roty = RotationYMatrix(mPitch); 
    237         Matrix4x4 rotx = RotationXMatrix(mYaw); 
    238  
    239         mViewOrientation *= roty; 
    240         mViewOrientation *= rotx; 
    241 } 
    242  
    243  
    244 Vector3 Camera::GetDirection() const 
    245 {  
    246         return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 
    247 } 
    248  
    249  
    250 Vector3 Camera::GetUpVector() const  
    251 {  
    252         return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 
    253 } 
    254  
    255  
    256 Vector3 Camera::GetRightVector() const  
    257 {  
    258         return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 
    259                  
    260 } 
    261  
    262  
    263 } 
    264  
     211} 
     212 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h

    r2778 r2780  
    2020        { 
    2121                /// the 6 clip planes 
     22                //float mClipPlane[6][4]; 
    2223                Plane3 mClipPlanes[6]; 
    2324 
     
    2930        Camera(int width, int height, float fieldOfView = 90.f); 
    3031 
     32        void Precompute(); 
     33 
     34        void LookInBox(const AxisAlignedBox3 &box); 
     35 
     36        void LookAtBox(const AxisAlignedBox3 &box); 
    3137 
    3238        void SetPosition(const Vector3 &pos); 
    3339 
     40        void SetDirection(const Vector3 &dir); 
     41 
    3442        inline Vector3 GetPosition() const { return mPosition; } 
    35         Vector3 GetDirection() const; 
    36         Vector3 GetUpVector() const; 
    37         Vector3 GetRightVector() const; 
     43        inline Vector3 GetDirection() const { return mDirection; } 
     44        inline Vector3 GetUpVector() const { return mUp; } 
     45        inline Vector3 GetRightVector() const { return mRight; } 
    3846 
    3947        inline float GetFov() const { return mFovy; } 
     
    5260        inline float GetNear() const { return mNear; } 
    5361        void SetNear(float nearDist); 
    54          
    55         inline float GetFar() const { return mFar; } 
    56  
    57         void SetFar(float farDist) { mFar = farDist; } 
    58  
    59         void SetOrtho(bool ortho); 
    60  
    61         void Yaw(float angle); 
    62         void Pitch(float angle); 
    63         /** Sets up viewing in gl 
    64         */ 
    65         void Render(); 
    6662 
    6763 
    6864protected: 
    6965 
    70         void Precompute(); 
    71  
    72         void CalculateFromPitchAndYaw(); 
    73  
    7466        //////////////// 
    7567 
     68        Vector3 mPosition; 
     69        Vector3 mDirection; 
     70 
     71        /// up vector takes into account the FOV at a unit distance from the origin 
     72        Vector3 mUp; 
     73        /// right vector takes into account the FOV at a unit distance from the origin 
     74        Vector3 mRight; 
    7675 
    7776        float mFovy; 
     
    8079 
    8180        float mNear; 
    82  
    83         float mFar; 
    84  
    85         bool mIsOrtho; 
    86  
    87         Matrix4x4 mBaseOrientation; 
    88         Matrix4x4 mViewOrientation; 
    89  
    90         float mPitch; 
    91         float mYaw; 
    92  
    93         Vector3 mPosition; 
    9481}; 
    9582 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/SceneQuery.cpp

    r2778 r2780  
    6363 
    6464        Camera *orthoCam = new Camera(len.x, len.y); 
    65         orthoCam->SetOrtho(true); 
     65        //orthoCam->SetOrtho(true); 
    6666 
    6767        orthoCam->SetNear(0.0f); 
    68         orthoCam->SetFar(len.z); 
     68        //orthoCam->SetFar(len.z); 
    6969 
    7070        orthoCam->SetPosition(pos); 
     
    7272        cout << "fov: " << orthoCam->GetFov() << endl; 
    7373        cout << "near: " << orthoCam->GetNear() << endl; 
    74         cout << "far: " << orthoCam->GetFar() << endl; 
     74        //cout << "far: " << orthoCam->GetFar() << endl; 
    7575        cout << "aspect: " << orthoCam->GetAspect() << endl; 
    7676 
     
    8080 
    8181        //orthoCam->SetDirection(Vector3(0, 1, 0)); 
    82         orthoCam->Yaw(M_PI * 0.5f); 
     82        //orthoCam->Yaw(M_PI * 0.5f); 
    8383         
    8484        renderer->SetCamera(orthoCam); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp

    r2779 r2780  
    163163        //camera->LookInBox(bvh->GetBox()); 
    164164 
    165         //camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 
    166         //camera->SetDirection(Vector3(0.0f, 1.0f, 0.0f)); 
     165        camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 
    167166        camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 
    168167 
     
    295294                break; 
    296295        case RenderTraverser::CHC: 
    297                 cout << "using chc" << endl; 
    298296                traverser = new CHCTraverser(); 
    299297                break; 
     
    490488        case 'A': 
    491489                { 
    492                         camera->Pitch(keyRotation); 
     490                        Vector3 viewDir = camera->GetDirection(); 
     491                        // rotate view vector 
     492                        Matrix4x4 rot = RotationZMatrix(keyRotation); 
     493                        viewDir = rot * viewDir; 
     494                        camera->SetDirection(viewDir); 
    493495                } 
    494496                break; 
     
    496498        case 'D': 
    497499        { 
    498                         camera->Pitch(-keyRotation); 
     500                        Vector3 viewDir = camera->GetDirection(); 
     501                        // rotate view vector 
     502                        Matrix4x4 rot = RotationZMatrix(-keyRotation); 
     503                        viewDir = rot * viewDir; 
     504                        camera->SetDirection(viewDir); 
    499505                } 
    500506                break; 
    501507        case 'w': 
    502508        case 'W': 
     509                { 
     510                        Vector3 pos = camera->GetPosition(); 
     511                        pos += hvec * keyForwardMotion; 
     512                        camera->SetPosition(pos); 
     513                } 
     514                break; 
     515        case 'x': 
     516        case 'X': 
    503517                { 
    504518                        Vector3 pos = camera->GetPosition(); 
     
    507521                } 
    508522                break; 
    509         case 'x': 
    510         case 'X': 
    511                 { 
    512                         Vector3 pos = camera->GetPosition(); 
    513                         pos += hvec * keyForwardMotion; 
    514                         camera->SetPosition(pos); 
    515                 } 
    516                 break; 
    517523        case 'r': 
    518524        case 'R': 
     
    541547        case GLUT_KEY_LEFT: 
    542548                { 
    543                         camera->Pitch(keyRotation); 
     549                        Vector3 viewDir = camera->GetDirection(); 
     550                        // rotate view vector 
     551                        Matrix4x4 rot = RotationZMatrix(keyRotation); 
     552                        viewDir = rot * viewDir; 
     553                        camera->SetDirection(viewDir); 
    544554                } 
    545555                break; 
    546556        case GLUT_KEY_RIGHT: 
    547557                { 
    548                         camera->Pitch(-keyRotation); 
     558                        Vector3 viewDir = camera->GetDirection(); 
     559                        // rotate view vector 
     560                        Matrix4x4 rot = RotationZMatrix(-keyRotation); 
     561                        viewDir = rot * viewDir; 
     562                        camera->SetDirection(viewDir); 
    549563                } 
    550564                break; 
    551565        case GLUT_KEY_UP: 
     566                { 
     567                        Vector3 pos = camera->GetPosition(); 
     568                        pos += hvec * 0.6f; 
     569                        camera->SetPosition(pos); 
     570                } 
     571                break; 
     572        case GLUT_KEY_DOWN: 
    552573                { 
    553574                        Vector3 pos = camera->GetPosition(); 
    554575                        pos -= hvec * 0.6f; 
    555                         camera->SetPosition(pos); 
    556                 } 
    557                 break; 
    558         case GLUT_KEY_DOWN: 
    559                 { 
    560                         Vector3 pos = camera->GetPosition(); 
    561                         pos += hvec * 0.6f; 
    562576                        camera->SetPosition(pos); 
    563577                } 
     
    627641void leftMotion(int x, int y)  
    628642{ 
     643        static float eyeXAngle = 0.0f; 
     644 
    629645        Vector3 viewDir = camera->GetDirection(); 
    630646        Vector3 pos = camera->GetPosition(); 
     
    633649        Vector3 horView(viewDir[0], viewDir[1], 0); 
    634650         
    635         float eyeXAngle = 0.2f *  M_PI * (xEyeBegin - x) / 180.0; 
    636  
    637         camera->Pitch(eyeXAngle); 
    638  
    639         pos -= horView * (yMotionBegin - y) * 0.2f; 
    640          
     651        eyeXAngle = 0.2f *  M_PI * (xEyeBegin - x) / 180.0; 
     652 
     653        // rotate view vector 
     654        Matrix4x4 rot = RotationZMatrix(eyeXAngle); 
     655        viewDir = rot * viewDir; 
     656 
     657        pos += horView * (yMotionBegin - y) * 0.2f; 
     658 
     659        camera->SetDirection(viewDir); 
    641660        camera->SetPosition(pos); 
    642661         
     
    653672void rightMotion(int x, int y)  
    654673{ 
    655         float eyeYAngle = -0.2f *  M_PI * (yEyeBegin - y) / 180.0; 
    656  
    657         camera->Yaw(eyeYAngle); 
    658          
     674        static float eyeYAngle = 0.0f; 
     675 
     676        Vector3 viewDir = camera->GetDirection(); 
     677        Vector3 right = camera->GetRightVector(); 
     678 
     679        eyeYAngle = -0.2f *  M_PI * (yEyeBegin - y) / 180.0; 
     680 
     681        // rotate view vector 
     682        Matrix4x4 rot = RotationAxisMatrix(right, eyeYAngle); 
     683        viewDir = rot * viewDir; 
     684 
     685        camera->SetDirection(viewDir); 
     686                 
    659687        yEyeBegin = y; 
    660688         
     
    678706        rVec = rot * rVec; 
    679707         
    680         pos += rVec * (x - horizontalMotionBegin) * 0.1f; 
     708        pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 
    681709        //pos[1] += (verticalMotionBegin - y) * 0.1f; 
    682710        pos[2] += (verticalMotionBegin - y) * 0.1f; 
     
    771799        //////////// 
    772800        // --- visualization of the occlusion culling 
    773  
    774801        visualization->Render(); 
    775802         
Note: See TracChangeset for help on using the changeset viewer.