PDA

View Full Version : Problems with transformations



07-23-2002, 08:19 AM
Hey, I am trying to use OpenGL to implement graphics for another program.
That program creates objects on a coordinate system in which each
coordinate ranges from -100 to 100. Thus, I have had to scale the objects
by 1/100 to get them to fit in the default OpenGL window. My problem is
this: I am now trying to implement transformations for these objects (so
that they will appear at their correct locations and orientations in
space), but the scaling factor is giving me trouble since I have to scale
translations by 1/100 while keeping rotations and scale factors the same
(which gets a little annoying since I'm working from the object
transformation matrices).

I think the easiest way to solve this problem would be to move the camera
way back and render the objects on their original scale. However, I tried
doing this and it didn't seem to work - the objects vanish into the background at a distance of about 3 from the camera. Is there some way to prevent this from happening?

If not, the other approach that I've been trying to use involves separating the object transformation into translation, scaling, and rotation components. The translation and scaling work just fine, but I'm having trouble converting the 3x3 rotation matrix I have into the 4x4 one required by OpenGL. Based on what I've read about the w coordinate, I've been trying to copy the 3x3 matrix into the upper left corner of the 4x4 matrix and then fill out the rest of the 4x4 matrix with zeroes and ones in the pattern of an identity matrix (I then feed this matrix into glMultMatrixd), but this doesn't seem to be working. Am I doing this wrong? Any other good suggestions on how to take a 3x3 matrix and implement that rotation in OpenGL? Would I, for example, be better off trying to calculate the axis and angle of rotation from the 3x3 matrix and using glRotate?

Thanks, Shannon

mikael_aronsson
07-23-2002, 10:27 AM
Hi !

Check the near/far clipping planes, anything beyond thoose planes will be clipped, you specify the clipping planes with the perspective/ortho functions.

Mikael

JML
07-23-2002, 08:53 PM
Check out the documentation about projection matrices and the GL_PROJECTION and GL_MODELVIEW matrix modes of OpenGL.

OpenGL allows you to use any projection matrix you want, and you are in no way restricted to the default [-1 -1 -1] to [1 1 1] world cube.

As Mikael points out, the near and far clipping planes that are specified when setting up the projection matrix determine what portions of your scene will be shown.

Good luck,

Jean-Marc.

bensch128
07-23-2002, 10:51 PM
Hi,

If you set glScalef(1.0f/100.0f, 1.0f/100.0f, 1.0f/100.0f); at the top of your display function (actually you should first glMatrixMode(GL_MODELVIEW); glPushMatrix() http://www.opengl.org/discussion_boards/ubb/wink.gif

all of the translations and rotations will be scaled properly.

Ben Schleimer