rotate and translate opengl difficulties

furballphat
Unregistered
 
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
Unregistered
 
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:

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();
Quote this message in a reply
furballphat
Unregistered
 
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 3,108 May 5, 2009 03:31 AM
Last Post: Ingemar
  rotate to focus on objects szgezu 1 2,072 Mar 4, 2006 03:59 AM
Last Post: SOUCHAN
  How does one rotate a scanned image in openGL? WhatMeWorry 16 8,767 Feb 2, 2005 09:25 PM
Last Post: arekkusu
  Best way to rotate an object Jake 12 4,489 Jul 30, 2003 01:09 PM
Last Post: Jake
  blending difficulties ghettotek 6 3,773 Feb 10, 2003 04:03 AM
Last Post: ghettotek