• Create Account

# OpenGl Camera Setup

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1t_man700  Members   -  Reputation: 100

Like
0Likes
Like

Posted 05 April 2011 - 06:02 AM

Hey guys, new here and first post. Awesome site

Anyways, I have a quick question about how to setup a camera that moves forward at all times and when you hit left or right on the keyboard for example, the camera will start turning left or right so that you could go in a full 360 if you so choose (like driving a car for example). It can (to be simple) stay on the same plane on the Y-axis at all times (doesn't have to move up or down).

I'm using GLUT, and I am setting the camera at each frame using gluLookAt(); If anyone can give me some tips on how to do this I would greatly appreciate it.

Thanks.

### #2haegarr  Crossbones+   -  Reputation: 7163

Like
1Likes
Like

Posted 05 April 2011 - 08:23 AM

Hi, be welcome.

I suggest you to drop the usage of GLUT. Instead, define a transformation matrix. Increment the rotational part of the matrix using its up vector as rotation axis and an incrementation angle (positive for turning to the one side, negative for the other side), perhaps scaled by the latest time delta. Pick the new forward vector, scale it by the speed and time delta, and add that to the positional part of the matrix. Use the inverse of that matrix as next VIEW matrix portion.

### #3hentailoli  Members   -  Reputation: 185

Like
0Likes
Like

Posted 06 April 2011 - 08:40 AM

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
gluLookAt(xf, yf, zf, xf + lx, yt, zf + lz, 0, 1, 0);

if keyboard_check(vk_left){
dir -= 1
}
if keyboard_check(vk_right){
dir += 1
}
//primitive drawing functions here

xf yf zf represents where you are looking for
yf is the upvector so if youre used to x y z now it will be x z y get it ?
yt is the height of the point you are looking at.
hope that helps

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS