Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


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.

  • You cannot reply to this topic
2 replies to this topic

#1 t_man700   Members   -  Reputation: 100

Like
0Likes
Like

Posted 05 April 2011 - 06:02 AM

Hey guys, new here and first post. Awesome site :P

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.

Sponsor:

#2 haegarr   Crossbones+   -  Reputation: 4602

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.

#3 hentailoli   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);
glLoadIdentity();
gluLookAt(xf, yf, zf, xf + lx, yt, zf + lz, 0, 1, 0);

if keyboard_check(vk_left){
	dir -= 1
	lx = sin(degtorad(dir))
	lz = -cos(degtorad(dir));
}
if keyboard_check(vk_right){
	dir += 1
	lx = sin(degtorad(dir))
	lz = -cos(degtorad(dir));
}
//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