PDA

View Full Version : how to custom implement gltranslate



brett01
09-29-2008, 11:33 AM
sir,
I want to implement opengl translate function


static void mytranslate(float x,float y,float z)
{
gmtl::Matrix44f M,T;
T.set(1,0,0,x,
0,1,0,y,
0,0,0,z,
0,0,0,1);
gmtl::postMult(M,T);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(M.getData());

}
Ive implemented this using gmtl and in visual studio.

Im getting the following errors

error C3861: 'mytranslate': identifier not found
error C2365: 'mytranslate' : redefinition; previous definition was 'formerly unknown identifier'
please help me why im getting these errors??
If you want any more details i will give it.

trinitrotoluene
09-29-2008, 11:51 AM
Do you use mytranslate function in another file. I am very not sure about this one, but using the qualifier static for a function tell the compiler that function will only be used in the file where it is declared.

If this information is false don't blame me, I am still learning.

Remove the static qualifier, verify if include file are correct, clear the project (this remove compiled object file) and recompile all your file.

brett01
09-29-2008, 11:55 AM
Hi,Thank you for the reply.Im not using any header files other than standard ones and inorder to use the function i simply used
translate(2,0,0);Does this work???I removed static qualifier but gettin the same error.

trinitrotoluene
09-29-2008, 12:06 PM
Ok, insert the prototype of your function just after all your include file and before the main function.

#include <stdio.h> ...
//prototype of the function
void mytranslate(float x,float y,float z);

void main(...)
{
...
mytranslate(...)
...
}

//definition of the function
mytranslate(...)
{

}

brett01
09-29-2008, 12:22 PM
ya its working but can any one tell me how to use glLoadMatrix and glMultmtrix???bcos previous transformations are not working???

trinitrotoluene
09-29-2008, 12:26 PM
Use glMultMatrixf(M.getData()) instead of glLoadMatrixf(M.getData()). The first multiply your matrix with the matrix at the top of the matrix stack, the second replace it.

brett01
09-29-2008, 12:37 PM
Do i need to do M.T or T.M to translate???

trinitrotoluene
09-29-2008, 12:44 PM
I don't see the need to do gmtl::postMult(M,T) because you don't define the M matrix (what is inside this matrix? identity?). Just use the T matrix. If you use glMultMatrix, OpenGL will multiply the matrix at the top of the stack(MTS) with the matrix T (MTS*T).

brett01
09-29-2008, 12:49 PM
The thing is shape of my cube is changing in vertical direction when i use this translate function.Im my code i implemented translate follows



glClear(GL_COLOR_BUFFER_BIT);
//glColor3f(1.0,1.0,1.0);
glPushMatrix();
glLoadIdentity();
gluLookAt (0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
mytranslate(1.0,0.0,0.0);
glRotatef(-60,1.0,.0,0.0);
glBegin();

trinitrotoluene
09-29-2008, 12:55 PM
Remember that in OpenGL you have to declare transformations in the inverse order. So your code that you post above will do the rotation first then the translation.

brett01
09-29-2008, 01:06 PM
Thank you but the thing is that when a use

glrotatef()
then
mytranslate() its undoing the rotation???

ok now i got it.Thank u very much dude for the help

trinitrotoluene
09-29-2008, 01:21 PM
Remember that OpenGL store is matrix in column major order. Transpose your matrix T to be in the right order or use glMultTransposeMatrixf (http://www.opengl.org/sdk/docs/man/xhtml/glMultTransposeMatrix.xml).