Changeset 2796 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
- Timestamp:
- 06/22/08 09:23:45 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2787 r2796 7 7 { 8 8 9 using namespace std; 10 9 11 10 12 Camera::Camera() … … 12 14 mWidth = 100; 13 15 mHeight = 100; 14 mFovy = 90.0f * M_PI / 180.0f; 16 mFovy = 60.0f * M_PI / 180.0f; 17 mIsOrtho = false; 18 19 SetPosition(Vector3(0, 0, 0)); 20 21 mPitch = mYaw = 0; 22 Precompute(Vector3(0, 1, 0)); 15 23 } 16 24 … … 22 30 23 31 mFovy = fieldOfView * M_PI / 180.0f; 24 } 25 26 27 void Camera::Precompute() 28 { 29 mDirection.Normalize(); 30 31 /*Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection); 32 mUp = -Normalize(CrossProd(side, mDirection)); 33 mRight = -Normalize(CrossProd(mDirection, mUp));*/ 34 35 mUp = Vector3(0, 0, 1); 36 mRight = -CrossProd(mDirection, mUp); 37 mUp = -Normalize(CrossProd(mRight, mDirection)); 38 } 32 33 mIsOrtho = false; 34 35 SetPosition(Vector3(0, 0, 0)); 36 37 mPitch = mYaw = 0; 38 Precompute(Vector3(0, 1, 0)); 39 } 40 41 42 void Camera::Precompute(const Vector3 &direction) 43 { 44 /* 45 Vector3 side = CrossProd(Vector3(1, 0, 0), direction); 46 Vector3 up = -Normalize(CrossProd(side, direction)); 47 Vector3 right = -Normalize(CrossProd(direction, up)); 48 */ 49 Vector3 up = Vector3(0, 0, 1); 50 Vector3 right = -Normalize(-CrossProd(direction, up)); 51 up = -Normalize(CrossProd(right, direction)); 52 53 mBaseOrientation = Matrix4x4(right, up, direction); 54 mViewOrientation = mBaseOrientation; 55 } 56 39 57 40 58 … … 42 60 { 43 61 mPosition = pos; 44 Precompute();45 }46 47 48 void Camera::SetDirection(const Vector3 &dir)49 {50 mDirection = dir;51 Precompute();52 62 } 53 63 … … 56 66 { 57 67 mNear = nearDist; 58 }59 60 61 void Camera::LookInBox(const AxisAlignedBox3 &box)62 {63 //mDirection = Vector3(0, 0, 1);64 mDirection = Vector3(0, 1, 0);65 mPosition = box.Center();66 mPosition.z = box.Min(2) + 0.9f * box.Size(2);67 68 Precompute();69 }70 71 72 void Camera::LookAtBox(const AxisAlignedBox3 &box)73 {74 mDirection = Vector3(0, box.Min().y - box.Max().y, 0);75 mPosition = Vector3(0);//box.Max() - mDirection;76 77 Precompute();78 68 } 79 69 … … 156 146 void Camera::SetupCameraView() 157 147 { 158 glLoadIdentity(); 159 gluLookAt(mPosition.x, mPosition.y, mPosition.z, 160 mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z, 161 mUp.x, mUp.y, mUp.z); 162 163 //std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl; 148 Matrix4x4 tview = mViewOrientation; 149 150 Vector3 pos = -mPosition; 151 pos = tview * pos; 152 153 Matrix4x4 viewOrientation = mViewOrientation; 154 155 viewOrientation.x[3][0] = pos.x; 156 viewOrientation.x[3][1] = pos.y; 157 viewOrientation.x[3][2] = pos.z; 158 159 glLoadMatrixf((float *)viewOrientation.x); 164 160 } 165 161 … … 177 173 const float w_far = h_far * GetAspect(); 178 174 179 //const Vector3 view = mDirection; 180 const Vector3 view = mDirection; 175 const Vector3 view = GetDirection(); 181 176 const Vector3 fc = mPosition + view * z_far; 182 177 183 const Vector3 up = mUp; 184 const Vector3 right = mRight; 178 const Vector3 up = GetUpVector(); 179 180 const Vector3 right = GetRightVector(); 185 181 186 182 Vector3 t1, t2; … … 194 190 fbr = fc - t1 + t2; 195 191 196 const Vector3 nc = mPosition + mDirection* z_near;192 const Vector3 nc = mPosition + view * z_near; 197 193 198 194 t1 = h_near * 0.5f * up; … … 206 202 207 203 208 } 209 204 void Camera::SetOrtho(bool ortho) 205 { 206 mIsOrtho = true; 207 } 208 209 210 void Camera::Yaw(float angle) 211 { 212 mYaw += angle; 213 CalculateFromPitchAndYaw(); 214 /* 215 Matrix4x4 viewOrientation(mRight, mUp, mDirection); 216 Matrix4x4 rot = RotationYMatrix(angle); 217 218 viewOrientation = viewOrientation * rot; 219 220 mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]); 221 mRight = Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]); 222 mUp = Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/ 223 } 224 225 226 void Camera::Pitch(float angle) 227 { 228 mPitch += angle; 229 CalculateFromPitchAndYaw(); 230 } 231 232 233 void Camera::CalculateFromPitchAndYaw() 234 { 235 mViewOrientation = mBaseOrientation; 236 237 Matrix4x4 roty = RotationYMatrix(mPitch); 238 Matrix4x4 rotx = RotationXMatrix(mYaw); 239 240 mViewOrientation *= roty; 241 mViewOrientation *= rotx; 242 } 243 244 245 Vector3 Camera::GetDirection() const 246 { 247 return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 248 } 249 250 251 Vector3 Camera::GetUpVector() const 252 { 253 return Vector3(mViewOrientation.x[0][1], mViewOrientation.x[1][1], mViewOrientation.x[2][1]); 254 } 255 256 257 Vector3 Camera::GetRightVector() const 258 { 259 return Vector3(mViewOrientation.x[0][0], mViewOrientation.x[1][0], mViewOrientation.x[2][0]); 260 261 } 262 263 264 } 265
Note: See TracChangeset
for help on using the changeset viewer.