![]() |
| | #1 |
| Registered User Join Date: Feb 2002
Posts: 93
| 1) When up or down is pressed on keyboard I want the camera & view to move up or down (like someone is wearing a jetpack and is flying) 2) When left or right is pressed on the keyboard i want the camera to rotate around a point vertically Can someone tell me the steps i need to accomplish this? 1) Check for keyboard input 2) Find the direction between camera & view 3) Find the cross product between direction & upvector 4) Normalize the cross vector 5) who knows ??? Am i even on the right track? I've looked at code that rotates the camera around a point horizontally and strafes the camera left and right but i can't understand the math.. anyone have a good site that explains the math involved with some diagrams or something? I can't picture the upvector or the cross product vector in my mind... its making it difficult to imagine what axises i need to rotate about... thnx for any help [EDIT] i've messed around a bit more and i got the camera to act like someone is wearing a jetpack.. though i doubt i did it correctly... Code: 1) Camera view - camera position = camera direction 2) Camera position = Camera position + camera direction * constant speed 3) Camera view = Camera view + camera direction * constant speed Last edited by tegwin; 01-23-2003 at 01:33 PM. |
| tegwin is offline | |
| | #2 |
| Registered User Join Date: Apr 2002
Posts: 1,571
| Okay, lets assume you have a camera class that stores information about your camera. Lets say you have the following things defined. Point3D pPosition; // Location Vector3D vRight; // Right of camera Vector3D vUp; // Up from camera Vector3D vBack; // Back of camera So, when you say move up or down I assume you mean move the camera along the Y-Axis. If you actually mean Look up and Look down, then you can get that effect by using matrices. Moving your camera around can be accomplished by use of matrices. You'll need matrices for X, Y and Z rotations. Then, Y Rotations will be looking left and looking right, X rotation will be looking up and down. If you need the specific matrices let me know but they are fairly easy to find and derive from scratch. Use your vRight vUp and vBack vectors in these calculations for the axis's though. For camera movement simply increment the pPosition by some scalar multiple of the back vector. I can go into more detail if you want. I'm not sure how much you know of Linear Algebra but it certainly helps. Let me know if you need more steps or something and I can write out some more. |
| MrWizard is offline | |
| | #3 | ||
| Banned Join Date: Jan 2003
Posts: 1,708
| Quote:
EDIT: Quote:
EDIT1: I'd really appreciate it if you could send those matricies or send me to them or something. I'm not looking for them myself right now because I'm going to bed and I'm lazy and I don't want to do the work if someone already has them Last edited by Silvercord; 01-23-2003 at 10:58 PM. | ||
| Silvercord is offline | |
| | #4 |
| Registered User Join Date: Apr 2002
Posts: 1,571
| Rotation with respect to the X axis of the camera will be equivalent to looking up/down. Think about the X axis. Then imagine something rotating with respect to that axis. It should be clear to see this is how you can make the camera look up / down. Here are the rotation matrices with respect to each axis. I had them typed out but they looked real ugly cause I couldn't get the formatting quite right. Instead I'll give you a link to a site. http://216.239.57.100/search?q=cache...hl=en&ie=UTF-8 |
| MrWizard is offline | |
| | #5 |
| Programming Sex-God Join Date: Nov 2002
Posts: 1,078
| You really only need 1 single matrix to represent any rotation about an axis which goes through the origin -- you don't need one for each axis. |
| Polymorphic OOP is offline | |
| | #6 |
| Registered User Join Date: Apr 2002
Posts: 1,571
| Yup, I know. That matrix is a little hairy though and for people just starting out its easier to tell them the standard ones. They are easy to derive etc. The arbitrary vector one isn't hard to derive though. I learned them in order ( i.e. the 3 std. rots , then the arb. rot ) so thats generally the order in which I tell people. |
| MrWizard is offline | |
| | #7 | |
| Banned Join Date: Jan 2003
Posts: 1,708
| I guess I'm confused and I would like someone to clear some things up for me. In first person shooters, you are constantly moving and therefore the vector you rotate up/down about is also constantly changing, hence the reason you must find the cross product between the view vector and the up vector, correct? Quote:
EDIT: Do either of you have a book on just this type of stuff that describes matrices of different rotations/translations/scalings etc etc? Any suggestions on this? http://www.amazon.com/exec/obidos/se...674404-5770368 Last edited by Silvercord; 01-24-2003 at 10:19 AM. | |
| Silvercord is offline | |
| | #8 |
| Registered User Join Date: Feb 2002
Posts: 93
| Hello Hello... from reading your post in which you wrote Vector3D vRight; // Right of camera Vector3D vUp; // Up from camera Vector3D vBack; // Back of camera i found myself completely lost already ... so i decided to do some searching and I think I've come across a good tutorial that talks about Rotation/Translate/Transform matrices in the realm of 3D programming.. I haven't finished it yet but it has "DIAGRAMS" to show what they are talking about.. HOORAY... from what I've read so far it seems like a pretty good tutorial...Rotation Matrices Tutorial For 3D Programming I'm sure when I'm done reading it i'll have more questions and i'll post 'em here.. |
| tegwin is offline | |
| | #9 | |
| Programming Sex-God Join Date: Nov 2002
Posts: 1,078
| Quote:
You can derive that matrix on paper by writing up the rotation matrices for x rotation, y rotation, and z rotation (actually, you can represent any rotation with rotations around 2 standard axes as well) and then multiplying them all together. Once you get that matrix, you can just plug in any vector axis and angle and you'll get a valid rotation matrix about an arbitrary axis. Last edited by Polymorphic OOP; 01-24-2003 at 10:47 AM. | |
| Polymorphic OOP is offline | |
| | #10 |
| Banned Join Date: Jan 2003
Posts: 1,708
| So does that mean that you must always translate to the origin to ensure the vector will cross through it? |
| Silvercord is offline | |
| | #11 | |
| Registered User Join Date: Apr 2002
Posts: 1,571
| Quote:
1. Translate so that rotation axis passes through origin 2. Rotate so that the rotation axis is aligned with one of the principle coordinate axes 3. Perform rotation of object about coordinate axis 4. Perform inverse rotation of step 2 5. Perform iInverse translation of step 1 You will then compose all of these together to get one final matrix. So to answer your question yes you do need to translate so that is crosses through the origin but when using the std. matrix it is done "behind the scenes" for you. Near the end of this page you will find the matrix you desire. http://216.239.57.100/search?q=cache...n&ie=UTF-8</a> As far as a book goes, I read through a lot of this book one day and it was pretty good imo. You should probably just flip through it one day at a store before you buy it ( like any other book ). http://search.barnesandnoble.com/boo...84500379&itm=1 This book covers a wide variety of things such as vectors and matrices, BSP Trees, quaternions, intersections ( i.e. line/plane , ray/sphere ). Last edited by MrWizard; 01-24-2003 at 01:48 PM. | |
| MrWizard is offline | |
| | #12 |
| Banned Join Date: Jan 2003
Posts: 1,708
| Just from reading the description offered at that link, that books seems incredibly good and I am going to go to barnes and noble to check it out. Thanks. |
| Silvercord is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| camera rotation matrix | Vick jr | Game Programming | 5 | 05-26-2009 08:16 AM |
| 3D starfields regardless of ship position | Bubba | Game Programming | 7 | 10-17-2006 11:49 PM |
| opengl: moving the light with level | bluehead | Game Programming | 24 | 04-13-2005 02:25 PM |
| Obfuscated Code Contest: The Results | Stack Overflow | Contests Board | 29 | 02-18-2005 05:39 PM |
| Getting right sprite direction in 3D world - like FFT or Xenogears | rmullen3 | Game Programming | 3 | 05-12-2003 05:49 PM |