Jump to content
  • Advertisement
Sign in to follow this  
ibr_ozdemir

OpenGL matrix which contain both camera and object's matrix

This topic is 3177 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i have to change my graphic engine from direct3d to opengl, as you know in direct3d also there is "FD3DDevice.SetTransform(D3DTS_VIEW,MatrixView);" matrix for camera viewing, but opengl has that "glMatrixMode(GL_MODELVIEW);" command for modeling and viewing matrix i used to set the d3ddevice's D3DTS_VIEW option with my camera first then i set the modeling matrix of next object which has to drawn while i was setting the scene, but now i have to set both matrix at the same time (camera and object) here is the method i use glMatrixMode(GL_MODELVIEW); glLoadIdentity; mtrx:=Camera.MatrixView; mtrx2:=Object.Matrix; UEMatrixMultiply(mtrx,mtrx2,mtrx); glLoadMatrixf(@mtrx); //draw the object so you see i'm multipling 2 matrixes (dont laugh if that stupid) please don't tell me "you have to prepare yor matixes with glRotatef, glTranslatef and such as that commands" i gotta use the same methods that i used in my direct3d engine, i have to work with matrixes only

Share this post


Link to post
Share on other sites
Advertisement
well the problem is when i multiply two (camera and object) matrixes, final matrix screws, it is not right, object turns in to a freak

i just want to learn the right method for creating the modelview matrix
i dont think multiplying is the right way

Share this post


Link to post
Share on other sites
thanks for quick reply Bob

here is my multiplying procedure

procedure UEMatrixMultiply(out Matrix: TMatrix; const m1, m2: TMatrix);
var
I, J: Integer;
begin
for I := 0 to 3 do
for J := 0 to 3 do
Matrix.m[I, J] :=
M1.m[I, 0] * M2.m[0, J] +
M1.m[I, 1] * M2.m[1, J] +
M1.m[I, 2] * M2.m[2, J] +
M1.m[I, 3] * M2.m[3, J];
end;



and i copy and paste it form Geometry.pas unit. and also i checked the result with directx's procedure which d3dx9 has. it's the same

Share this post


Link to post
Share on other sites
I don't know the parameter mechanisms in that language, but are you sure the matrices are not passed by reference semantics? If they are, you may be overwriting the second matrix, M2, with the result as you multiply them.

Checked the order of multiplication also?

Share this post


Link to post
Share on other sites
multiplying procedure is working fine and also i try pass the parameters otherway instead of UEMatrixMultiply(mtrx,mtrx2,mtrx); UEMatrixMultiply(mtrx,mtrx,mtrx2);

anyway and i search and couldn't find any tutorial shows handling camera and object matrix, i mean they always keeping the objects fixed and just moving camera, can you point me an example which moves objects and also camera

thanks

Share this post


Link to post
Share on other sites
There is no difference between moving the camera or moving the object. So an example using one way will be the same as one using the other way. You just have to realize that moving the camera is exactly the same as moving the object in the opposite direction.

But if you have verified that the multiplication is indeed correct, then there is nothing wrong with the code you have posted, and the error is somewhere else.

Share this post


Link to post
Share on other sites
you are right my problem isn't camera or object transformations, my problem is preparing the matrixes with glLoadMatrixf instead of glRotatef or glTranslatef.
you see i dont want to build all those structure again, i just have to pass the prepared matrixes to GL_MODELVIEW

Share this post


Link to post
Share on other sites
for example there is this code


void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f); //Rotate the camera
glTranslatef(0.0f, 0.0f, -5.0f); //Move forward 5 units

glPushMatrix(); //Save the transformations performed thus far
glTranslatef(0.0f, -1.0f, 0.0f); //Move to the center of the trapezoid
glRotatef(_angle, 0.0f, 0.0f, 1.0f); //Rotate about the z-axis

glBegin(GL_QUADS);

//Trapezoid
glVertex3f(-0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, -0.5f, 0.0f);
glVertex3f(0.4f, 0.5f, 0.0f);
glVertex3f(-0.4f, 0.5f, 0.0f);

glEnd();

glPopMatrix(); //Undo the move to the center of the trapezoid
glPushMatrix(); //Save the current state of transformations
glTranslatef(1.0f, 1.0f, 0.0f); //Move to the center of the pentagon
glRotatef(_angle, 0.0f, 1.0f, 0.0f); //Rotate about the y-axis
glScalef(0.7f, 0.7f, 0.7f); //Scale by 0.7 in the x, y, and z directions

glBegin(GL_TRIANGLES);

//Pentagon
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);

glEnd();

glPopMatrix(); //Undo the move to the center of the pentagon
glPushMatrix(); //Save the current state of transformations
glTranslatef(-1.0f, 1.0f, 0.0f); //Move to the center of the triangle
glRotatef(_angle, 1.0f, 2.0f, 3.0f); //Rotate about the the vector (1, 2, 3)

glBegin(GL_TRIANGLES);

//Triangle
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);

glEnd();

glPopMatrix(); //Undo the move to the center of the triangle

glutSwapBuffers();
}




i just dont want to use pop or push matrix or glTranslatef or glRotatef things

thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!