Skip to main content
GameDev.net gamedev.net
🔒 Locked

Beginner transformation question

Started by MelonTime Sep 24, 2010 at 9:21 AM 0 replies 400+ views
Original Post
MelonTime
MelonTime
Hey folks. I've been coding in OpenGL for a few days using python (and a library, pygame, to handle input and drawing), and I'm struggling to wrap my head around it.

1. My first question is about glLoadIdentity(). My current understanding is this: There is an origin, (0,0,0), that the program starts at. If you use glTranslate or glRotate then you move the current location; say, if you translate (0,1,0), then the new current location is 1 tile above the origin. Now, if you draw a vertex at location (0,0,0), it will draw relative to this new coordinate. Then if you use glLoadIdentity(), the current coordinate moves back to the origin again; so if you draw another vertex, it will be relative to (0,0,0). Is this correct?

2. I'm a bit confused as to when I should use it. Should I use it at the start of the frame, and have every object draw relative to it? Should every single object's render function use it to translate to the center and then draw?

3. My program rotates the camera vertically, which causes an object the camera moves with to move up and down on the screen. If I make the camera rotate then the object draw it screws up everything else. How can I fix this?
i.e. (. is the object the camera follows, < is the camera, - and / are the view of the camera)
<
/
. /
rotates to
--<

.
when I want it to be


. --<
It rotates in a circular arc around the object.
Sorry if that's confusing =/

4. Also, if anybody is feeling generous, could you write me some really quick pseudocode for a program that draws a plane in a fixed location, allows the camera to move about and draws a cube in front of the camera.
My current code looks like this:

rotate and move camera based on input
glLoadIdentity()
rotate the camera on the x plane
prot.render(camera.position) # prot is the cube in front of the camera
rotate the camera on the y plane
render object

[Edited by - MelonTime on September 24, 2010 10:28:04 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.