Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

help: GL translation vs DirectX

Started by mercior Jan 3, 2010 at 9:22 PM 2 replies 800+ views
Original Post
mercior
mercior
I'm trying to mimick this directx transform code in OpenGL:
Quote:
D3DXMATRIX tmp; D3DXMatrixTranslation(&matView, -x, -y, 0.0f); D3DXMatrixScaling(&tmp, hscale, vscale, 1.0f); D3DXMatrixMultiply(&matView, &matView, &tmp); D3DXMatrixRotationZ(&tmp, -rot); D3DXMatrixMultiply(&matView, &matView, &tmp); D3DXMatrixTranslation(&tmp, x+dx, y+dy, 0.0f); D3DXMatrixMultiply(&matView, &matView, &tmp);
using:
Quote:
glTranslatef(-x, -y, 0.0f); glScalef(hscale, vscale, 1.0f); glRotatef(-rot, 0, 0, 1); glTranslatef(x+dx, y+dy, 0.0f);
I've read up on the functions and this seems correct to me, but I'm new to GL and probably missing something! The GL code does not produce the same result. Can anybody help?
idinev
idinev
Try reversing the order of ops.
mercior
mercior
yup that worked :) not sure I get why though?
Yann L
Yann L
Quote:
Original post by mercior
yup that worked :) not sure I get why though?

Because OpenGL uses column-major matrices, while D3D uses row-major ones. Multiplication order needs to be flipped in order to get the same result.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.