|
Vectors and Matrices |
Thomas Fjellstrom
Member #476
June 2000
|
Ok. I've hacked together a little GL program (attached), my goal is to be able to "fly" around the "world" I've created, freely. Right now I'm stuck moving in tracks. I have only a basic understanding of the Matrix math included ("borrowed" it from a program of George Foot's). I "think" I can get the movement I want by including the "vel" vector into the matrix equations somehow, but I'm not exactly sure how. to build the program, It requires the latest AllegroGL CVS, and Allegro 4.2+. edit, hmm, I realize some here may be a little lazy, so I'll post some of the relavant code:
Keyboard/Movement:
Now, it could be just me, but theres got to be a way to include the "pos+vel" into the matrix calculations in Camera::setup. edit2, 5+ hours and nothing? Thanks guys. -- |
Archon
Member #4,195
January 2004
|
Is this camera rotation or camera movement? [edit] I have to go out now but perhaps drawing what you want to happen then connecting the patterns would help you form an idea of what you need to do. ^ Disregard that if it doesn't help you at all. |
Thomas Fjellstrom
Member #476
June 2000
|
Thanks Archon. Its both really. I want to properly move through a 3d environment with all 360 degrees of freedom. I've attempted to modify my camera update to the following, but it seems I've got something totally wrong about the gl matrices:
What exactly am I doing wrong? I want the camera to be able to fly around as if it were, say a space ship, or a plane, in and arround the cubes and whatnot. edit, KittyCat has given me one fix: GLfloat mat2[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, pos.x, pos.y, pos.z, 1 }; It helps a little, but now the arrow keys cause the camera's position to slowly rotate around its pos. edit2, I've commended the pos.Normalize(); and its going better. edit3, Now, the camera doesn't move in the direction of the direction vectors... -- |
Tobias Dammers
Member #2,604
August 2002
|
I usually store both rotation and position together in a struct (a class actually), and each as a vector, where the rotation vector indicates axis (the vector's direction) and angle (its length). This "position" struct can be used both for objects and for cameras. To activate it as a drawing offset (as an object position), do a glRotate() first, then a glTranslate(). To use as a camera, you do the translate first and with opposite signs, then the rotate, also with opposite signs. --- |
|