Modifying the texture matrix
Hey, I have a strange problem at least for me it is...
I tried to use that code:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(Scroll.x, Scroll.y, 0);
glRotatef(Rotate, 0,0,-1);
glMatrixMode(GL_MODELVIEW);
It should firstly rotate the texture around the 0,0 corner and then translate it in the world coordinate system with Scroll. Although it doesn''t do that; it translates the texture in the new local coordinate system (after rotating)! How could I achieve to use the world system?
Please help, it is really important!
Thanks in advance
ps. and I need to firstly rotate it, so changing the order doesn''t help...
-- tSG --
-- tSG --
Scroll and rotate ? hmmm..
what kind of effect do you look for ? the way you''re doing is a bit weird (I mean, hard to master)
what kind of effect do you look for ? the way you''re doing is a bit weird (I mean, hard to master)
Ok, here''s my ideas on what I grasp so far from your post (I''m by no means an expert, so I''m open to corrections)..
Looks like you''re rotating and translating ALL textures at once (generally, the only reason you''d attempt to use the texture matrix, IMHO). Scrolling is generally done by modifying the texture coordinates for each polygon, not the texture itself.
As for the rotation, I''d assume that you could just rotate the texture coordinates as though they were points on a plane, and MAYBE that would come out correct. I''ve never tried that, so that is just a guess.
And if you want the rotation to come out first, you have to rotate first. Order does matter when multiplying matrices (which both translation and rotation are, in this case).
Looks like you''re rotating and translating ALL textures at once (generally, the only reason you''d attempt to use the texture matrix, IMHO). Scrolling is generally done by modifying the texture coordinates for each polygon, not the texture itself.
As for the rotation, I''d assume that you could just rotate the texture coordinates as though they were points on a plane, and MAYBE that would come out correct. I''ve never tried that, so that is just a guess.
And if you want the rotation to come out first, you have to rotate first. Order does matter when multiplying matrices (which both translation and rotation are, in this case).
This effect is useful if you don't want to change all of the texture coordinates... for example if you have a nice always sliding and rotating cloud on the top of your room, on the ceiling (for instance quake used that technique I think or at least it should use that because it is free on hw)
I wanted to be able to rotate AND translate the texture with the desired amounts... Now I am only able to translate OR rotate the texture...
Oh yeah, and I don't have a specific effect. I would like to make my engine as flexible as possible.
Thanks for the replies
-- tSG --
[edited by - tSG on March 25, 2002 6:23:17 PM]
I wanted to be able to rotate AND translate the texture with the desired amounts... Now I am only able to translate OR rotate the texture...
Oh yeah, and I don't have a specific effect. I would like to make my engine as flexible as possible.
Thanks for the replies
-- tSG --
[edited by - tSG on March 25, 2002 6:23:17 PM]
-- tSG --
if I understand u right, u want the coord-system of ur texture be the same as the one of our object? then don''t load the identity or rotate and translate the Matrix the same amount.
with the translate and rotate thing, i try first rotating and then translating or switch the order.
with the translate and rotate thing, i try first rotating and then translating or switch the order.
You may do the rotation thanks to the texture transformation matrix and do the "translation" just by modifyng your texture coordinate. Something like :
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(Rotate, 0,0,-1);
glMatrixMode(GL_MODELVIEW);
glTranslatef(, Scroll.y, 0);
glVertex2f( x, y)
glTexCoord2f( normalXValue - Scroll.x, normalYValue - Scroll.y);
Hope it helps !
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(Rotate, 0,0,-1);
glMatrixMode(GL_MODELVIEW);
glTranslatef(, Scroll.y, 0);
glVertex2f( x, y)
glTexCoord2f( normalXValue - Scroll.x, normalYValue - Scroll.y);
Hope it helps !
First of all thanks for the replies!
glnefugio: no, I would like to transform my texturematrix as I want... So if I say I wanna rotate it with 90 degrees per second and translate it by (1,0) - so rotate it around the origo and translate it along the x axis by 1 unit per minute then it should do that
Now I almost reached that but the translation happens on the local x axis - after the rotation - which is not suitable for me as I would like it to happen along the global x axis.
Prosper/LOADED: thanks, that would really work but as I want to make a flexible engine I can''t do that. This is a case in which I can only manipulate the texturematrix...
-- tSG --
glnefugio: no, I would like to transform my texturematrix as I want... So if I say I wanna rotate it with 90 degrees per second and translate it by (1,0) - so rotate it around the origo and translate it along the x axis by 1 unit per minute then it should do that

Now I almost reached that but the translation happens on the local x axis - after the rotation - which is not suitable for me as I would like it to happen along the global x axis.
Prosper/LOADED: thanks, that would really work but as I want to make a flexible engine I can''t do that. This is a case in which I can only manipulate the texturematrix...
-- tSG --
-- tSG --
quote:
Prosper/LOADED: thanks, that would really work but as I want to make a flexible engine I can''t do that. This is a case in which I can only manipulate the texturematrix...
Ok, it will require a bit more work but there is a quite simple way to do it I think.
Multiply your translation vector by the rotation matrix inverse. It''s quite easy to compute a rotation inverse : the inverse of a rotation of Phi is a rotation of -Phi.
Then, translate by this vector, after the rotation. Here''s a quick and dirty example (may be buggy as hell) :
void doIt( float tx, float ty, float phi){ float tx2 = tx*cos(-phi) - ty*sin(-phi); float ty2 = tx*sin(-phi) + ty*cos(-phi); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef(Rotate, 0,0,-1); glTranslatef( tx2, ty2, 0.0f); glMatrixMode(GL_MODELVIEW);}
Thanks Prosper! That is what I haven''t thought about! That has to work. Thx again

-- tSG --
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement