rotate and translate opengl difficulties

Post: #1
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.
Quote this message in a reply
Jeff Binder
Post: #2
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:

//To change to the location
locationX -= sin(rotation) * kSpeed;
locationZ -= cos(rotation) * kSpeed;

//When drawing
glTranslatef(0., 0., -20.);
glRotatef(80., 1., 0., 0.);
glRotatef(-m_rotation, 0., 1., 0.);
glTranslatef(locationX, 0., locationZ);


Quote this message in a reply
Post: #3
Thanks. I tried using trig functions before, but I now realize that the reason it wasn't working was because I was only translating on one axis at a time. I need to brush up on my trig.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cube auto-rotate sakrist 2 4,256 May 5, 2009 03:31 AM
Last Post: Ingemar
  rotate to focus on objects szgezu 1 2,756 Mar 4, 2006 03:59 AM
Last Post: SOUCHAN
  How does one rotate a scanned image in openGL? WhatMeWorry 16 11,987 Feb 2, 2005 09:25 PM
Last Post: arekkusu
  Best way to rotate an object Jake 12 6,540 Jul 30, 2003 01:09 PM
Last Post: Jake
  blending difficulties ghettotek 6 5,335 Feb 10, 2003 04:03 AM
Last Post: ghettotek