Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
In my OpenGL view (which was switched from a normal NSView), I have had to adjust from using NSView's bounds rectangle to using Modelview matrix transformations so that the user can move around, zoom in/zoom out.

I have a system set up with three variables: translateX, translateY, and zoom. Every time I draw, I load the identity matrix, then use these variables to transform the view. I have also thought about using glFrustrum, along with these variables to transform the view in just one operation.

I just wanted to know how you do transformations in OpenGL, and if my way can be improved on. (It is pretty inefficient).
:)

EDIT:
I have another idea. I know that re-drawing a scene that is animating is very time consuming if I redraw every time (In this case, the planets in Gravita are being redrawn each time). Is it possible to remember what has to move, and by how much, then push a matrix, move the origin to whatever needs to move, move it, then pop the matrix and repeat? Would that work?

-- woah, just realized why that wouldn't work! --

But is there another way to translate only one part of a drawing in OpenGL, instead of clearing the screen with black and redrawing? That seems a bit inefficient. :/
 
Just redraw the entire scene every frame. OpenGL is very fast, and polygons offscreen get clipped anyway.

Remember what Knuth said: premature optimization is the root of all evil.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.