Jump to content
  • Advertisement
Sign in to follow this  
barakus

OpenGL Matrices with OpenGL

This topic is 4969 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

Hey guys ive started to learn OpenGL after using DirectX for some time. Ive had many problems with the API, but the one thats bugging me the most has to do with matrices. To setup my matrices in Direct3D i would use the following code:
	        D3DXVECTOR3 cameraPos(cameraX,cameraY,cameraZ);
		D3DXVECTOR3 cameraTarget(cameraX,cameraY,0.0f);
		D3DXVECTOR3 cameraUp(0,1.0f,0.0f);

		D3DXMatrixLookAtLH( &viewMatrix, &cameraPos, &cameraTarget, &cameraUp);
		p_D3DDevice->SetTransform(D3DTS_VIEW, &viewMatrix);
	
		D3DXMatrixPerspectiveLH(&projMatrix,-256,-224,1.0f,100.0f);
		p_D3DDevice->SetTransform(D3DTS_PROJECTION, &projMatrix);

But there doesnt seem to be an OpenGL equivalent to PerspectiveLH, so im forced to use the Fov variation. However, this makes the view to close in, as in that u need to space things out by decimal places rather than whole integers. And the origin changes depending on the size of the window. if its at its default size of 640 x 480 its 1/4 from the top of the screen to the right but if I maximise the window the origin is almost reversed. Could anyone shed any light on the subject? All i really need is for the origin to begin in the top left corner BTW here is my OpenGL Matrix code:
	glViewport(0,0,width,height);
		
	
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(45,(GLfloat)persWidth/(GLfloat)persHeight,0.1f,100.0f);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(cameraX,cameraY,cameraZ,cameraX,cameraY,cameraZ,0,1,0);

Share this post


Link to post
Share on other sites
Advertisement
Well, i tried that, but that didnt go to well either...
I think i might just start my GL rendering class from scratch again.

Share this post


Link to post
Share on other sites
I Did it!
i just reversed the parametres i had for GL Fulstrum and i got it working perfectly! Before i had it
glFrustum(0,640,0,480,1, 150.0f);
but then my y axis was going the other way.
so i just switched the top and bottom properties and now its working well

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!