opengl - Orders of Modifying the Shape -
i started learning transformations in opengl, , confused steps of modifying shape different position, angles or sizes.
for example, have house in 2d scene follow:
let's want transforms scene in (a) scene in part (b) of house, how should decide whether should scale it, translate or rotate first ? outcome going different ?
thank you.
the outcome going different based on order of transforms.
here pseudocode answers question directly (assuming each function takes x,y,z
parameters):
translate(-6, 0, 0) rotate(0, 0, 135) scale(2, 1, 1)
now let's @ why order matters!
first, have without transforms:
next, let's see happens when rotate counter-clockwise 45° , translate along positive x axis:
notice how translation caused square move toward top-right corner? because rotation transform modifies local axes. positive x points top-right. if rotated 180° +x point towards left instead of right.
now let's @ happens when perform same transforms in reverse order:
this time translation moved square right expected. after square rotated.
check out open.gl page on transformations more detail, around math behind of this.
Comments
Post a Comment