PDA

View Full Version : GLFrame's getMatrix problem in superBible4ed



ashi08104
05-22-2011, 08:59 PM
Hi,All.I want to draw 4 rectangles in a line and then rotate them(as fig.a,b,c in result.jpg show,this image is manually edited by Gimp,I haven't got the result yet).However,my result is as fig.d in result.jpg.I follow the examples in SuperBible 4ed,and I step in GLFrame::ApplyActorTransform() when debugging,found that the GetMatrix() function in line1Frame.ApplyActorTransform() didn't return the identity matrix,it return a matrix like this:
-1 0 0 0
0 1 0 0
0 0-1 0
0 0 0 1
I think this matrix rotate my rectangle incorrectly.How can I fix it? Thanks for any reply!

here is part of my source code,GLFrame.h is also attached.


GLFrame line1Frame;
GLFrame line2Frame;
GLFrame line3Frame;
GLFrame line4Frame;

void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();

line1Frame.ApplyActorTransform();
//line1Frame.ApplyCameraTransform();

glColor3f(0.30f,0.00f,0.00f);
drawMyRectangle();

//line2Frame.ApplyCameraTransform();
line2Frame.ApplyActorTransform();

glColor3f(0.60f,0.00f,0.00f);
drawMyRectangle();

//line3Frame.ApplyCameraTransform();
line3Frame.ApplyActorTransform();

glColor3f(0.90f,0.00f,0.00f);
drawMyRectangle();

//line4Frame.ApplyCameraTransform();
line4Frame.ApplyActorTransform();

glColor3f(1.00f,0.00f,0.80f);
drawMyRectangle();

glPopMatrix();
// Flush drawing commands
glutSwapBuffers();
}
// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
line2Frame.MoveUp(10);
line3Frame.MoveUp(10);
line4Frame.MoveUp(10);
glLineWidth(1);

}

ashi08104
05-23-2011, 01:47 AM
and another question:is there a "standard" way to do rotation and translation in OpenGL3.3 or later?I google the "GLFrame",there are little related article with it.however,the Superbible suggested using GLFrame.

Alfonse Reinheart
05-23-2011, 02:12 AM
and another question:is there a "standard" way to do rotation and translation in OpenGL3.3 or later?

The "standard" way is to download and use a math library. I suggest GLM myself, but there are others available that can be useful.


however,the Superbible suggested using GLFrame.

In what way does it suggest using GLFrame? They wrote GLFrame, as part of their source code for running OpenGL applications. That doesn't mean you have to or even ought to use it. They use it because they needed something to do that stuff.

ashi08104
05-23-2011, 02:39 AM
and another question:is there a "standard" way to do rotation and translation in OpenGL3.3 or later?

The "standard" way is to download and use a math library. I suggest GLM myself, but there are others available that can be useful.


however,the Superbible suggested using GLFrame.

In what way does it suggest using GLFrame? They wrote GLFrame, as part of their source code for running OpenGL applications. That doesn't mean you have to or even ought to use it. They use it because they needed something to do that stuff.
Alfonse Reinheart,thanks!you are right.Actually,the SuperBible 5ed just uses GLFrame,and mentioned it is a powerful mechanism.

I think SuperBible trys to simplify transformation operation in OpenGL by GLFrame,but I was confused by its some function.

I've replaced GLFrame by glRotatf() and glTranslatef() in preceding problem,and it works.I'll try GLM:)