rotate and translate opengl difficulties
I am currently writing an openGL 3D terrain viewer which will hopefully be turned into a game. Currently I have a large square filled with tiles of random height.
I have it set up so that with keyboard control you can rotate the camera on the x and y axis and translate on the y axis. No problems here. I then added in a feature to let you scroll along the map by moving the cursor to the screen edge (as seen in most RTS games).
My problem is that I have to rotate on the y and then translate to make the camera rotate and not the map, but that means the axis have changed and when I translate the map, it veers off in the wrong direction if the camera has been rotated away from the zero position.
I would appreciate any help, furballphat.
I have it set up so that with keyboard control you can rotate the camera on the x and y axis and translate on the y axis. No problems here. I then added in a feature to let you scroll along the map by moving the cursor to the screen edge (as seen in most RTS games).
My problem is that I have to rotate on the y and then translate to make the camera rotate and not the map, but that means the axis have changed and when I translate the map, it veers off in the wrong direction if the camera has been rotated away from the zero position.
I would appreciate any help, furballphat.
The key to understanding this is to think that you're really moving the terrain, not the camera. Anyway, rotating and then translating is the right way to do this.
What you're probably doing is moving the camera as if it weren't rotated at all. You probably want to change the direction of camera movement so it lines up with the rotation:
What you're probably doing is moving the camera as if it weren't rotated at all. You probably want to change the direction of camera movement so it lines up with the rotation:
Code:
//To change to the location
locationX -= sin(rotation) * kSpeed;
locationZ -= cos(rotation) * kSpeed;
//When drawing
glPushMatrix();
glTranslatef(0., 0., -20.);
glRotatef(80., 1., 0., 0.);
glRotatef(-m_rotation, 0., 1., 0.);
glTranslatef(locationX, 0., locationZ);
DrawSomething();
glPopMatrix();
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Cube auto-rotate | sakrist | 2 | 2,629 |
May 5, 2009 03:31 AM Last Post: Ingemar |
|
| rotate to focus on objects | szgezu | 1 | 1,756 |
Mar 4, 2006 03:59 AM Last Post: SOUCHAN |
|
| How does one rotate a scanned image in openGL? | WhatMeWorry | 16 | 7,618 |
Feb 2, 2005 09:25 PM Last Post: arekkusu |
|
| Best way to rotate an object | Jake | 12 | 3,954 |
Jul 30, 2003 01:09 PM Last Post: Jake |
|
| blending difficulties | ghettotek | 6 | 3,316 |
Feb 10, 2003 04:03 AM Last Post: ghettotek |
|

