• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

This topic is now archived and is closed to further replies.

# scaling

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

## Recommended Posts

this is actually for my opengl app, but im going to ask a general question here because i find that the opengl forum is slow, and id be hard pressed to get more than 2 responses within a days time. problem is scaling. im drawing cubes at specific points on a 3D graph. since i know where those points are, i know when a cube is not drawn in the right place. when i scale a cube down (to make it smaller), some of the cubes are misplaced. i tried scaling before translation, and after translation. both gives me different yet incorrect results. anyone knows why? also, a link to a good tutorial will do me some good. and i already tried google.

##### Share on other sites
You scale, rotate x, rotate y, rotate z, then transform, in that order.You said you tried before transform and after, did you try before rotating?

##### Share on other sites
all i do is scale and translate, there is not rotations.

the best results i can get is to translate first and then scale.
if i scale and then translate then the cubes appear to translate with the scale in mind...meaning with a scale of 0.25f, a translation of 1.0f on the x axis will actually be 0.25f.

this is what it appears to be anyway.

##### Share on other sites
being a directx forum im not sure if posting code will help.
but here it is anyways.

again, im putting this here as a general question rather than an opengl question.

also, i believe that opengl and directx process rotations, scaling, and translations in different orders. right?

heres my snipp:

glPushMatrix();         //glLoadIdentity();         glTranslatef(x, y, z);         glScalef(0.25f,0.25f,0.25f);         glCallList(box);glPopMatrix();

##### Share on other sites
D3DXMATRIX World, Position, xRot, yRot, zRot, Scale;D3DXMatrixIdentity(&World);//Consider the others identities by same methodD3DXMatrixTranslation(&Position, xPos, yPos, zPos);D3DXMatrixRotationX(&xRot, xRotation);D3DXMatrixRotationY(&yRot, yRotation);D3DXMatrixRotationZ(&zRot, zRotation);D3DXMatrixScaling(&Scale, xScale, yScale, zScale);D3DXMatrixMultiply(&world, &world, &Scale);D3DXMatrixMultiply(&world, &world, &xRot);D3DXMatrixMultiply(&world, &world, &yRot);D3DXMatrixMultiply(&world, &world, &zRot);D3DXMatrixMultiply(&world, &world, &Position);AdapterDevice->SetTransform(D3DTS_WORLD, &World);

When D3D does it, it scales the vertices, then rotates the vertices, then moves the origin. If OpenGL does it differently...

Think about it: You have a box sitting at the origin. If you scale, you move the verticies closer or further away from the origin by a specific amount. When you rotate, you recalculate their position around the origin. When you translate, you move the verticies away from the origin. It seems odd to me that you say scaling FIRST causes the movement to seem scaled, because, in D3D and according to the very little I understand about matrix math, it should be the opposite.
In matrix math: A*B != B*A.

So when you rotate before scaling, it'll look squashed. If you Transform before scaling, it'll appear that the movement was scaled as well (and the vertices may appear... off, but I'm not entirely sure about that). If you transform before rotating it'll look like you rotated around a different origin point.

Maybe OpenGL does it differently (Since I don't understand the matrix math going on behind the scenes I don't know if you can or not. It says something about the California School System when I can ace Calculus 3 in college and still not know what's going on with matricies...), does it in the reverse order as you say it appears, then maybe that is what's happening.

[edited by - Erzengeldeslichtes on September 23, 2003 12:19:44 AM]

##### Share on other sites
I know!

I tried scaling and then translating again, the boxes are very close to the origin, even though they are not suppose to.

im gonna post this one on opengl - and consequently probably wait a day or two to get a response.

thanks anyway.