View Full Version : A question about geometric-transformation function...
04-17-2004, 10:37 AM
Recently,I need to write a simple program which produces a screw line.Of course,I can implement this in a fairly brute force way such as write a for loop,based on simple math,in the block which is constructed with glBegin(GL_LINE_STRIP) and glEnd(). I wonder if there is a simpler way to do this? In my case, if I can use rotation function such as rotatef to control vertex position in glBegin-glEnd block, then I can solve this case simply enough with a for loop containing a call to rotation and a call to glVertex*. I wonder is that possible in OpenGL? I try to find the answer in my reference book...but I failed. Thanks!
04-17-2004, 04:02 PM
Anytime that you have alot of geometry, it is almost always better to precompute that geometry and then transform it on the fly. Take your screw, for example; you could precompute the (x,y,z) for the winding around the x axis. Then, in the pipe, you could transform that axis along any direction you saw fit, and translate and scale it to boot.
04-19-2004, 08:02 AM
You could use either approach. You could either generate a Line Strip as you said (this would require multiple calls to glVertex*) or you could simply use a GL_LINE inside a for loop while you translate and rotate about the winding path that you want to create (this would require multiple calls to glPush and glPop Matrix).
A better solution might be to instead store each vertex in a vertex array (just take your glVertex* calls from the line strip and instead store those vertices in an array) and then use vertex arrays to batch render the whole thing. Why not cut down on function calls if possible.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.