c++ - Opengl Why premultiply matrices when rotating in global space? -


ok know when call glrotatef() this,

c = c * m 

where "c" current matrix on stack, , "m" matrix computed glrotatef(). causes object rotate around local-axis. if want rotate object around global axis i'd have do

 c = m * c 

so example if wanted rotate around global x, global y, global z. it'd be

c = mz * my* mx * c

i have tested , works. wanna know reason why have premultiply global rotation , vice versa.

the "c" in case modelview matrix. note not talking pre multiplying matrices vectors. know column major - row major stuff. wanna know consequences of pre/post multiplying transformation matrix4x4.

at core, transformation matrix function converts positions/directions space i space o: input output. , therefore, transformations behave lot function composition. there difference between f(g(x)) , g(f(x)).

so start matrix c that, given vertex vi in space i, true: vo = c * vi, vo vertex in space o.

so, let's go original example: c = c * m. cut down on confusion (i need talk original c , output), i'm going give new matrix particular name: d = c * m.

the space i, input space c particular model space. you're adding new transformation this, had own input , output spaces. , multiplying them form single transformation, declaring something:

that mo, output space of m, same space ci, c's input space. therefore, dealing 3 spaces: mi, mo/ci, , co.

however, d composition of transforms. goes space mi space co; never see mo/ci. difference between c , d input spaces.

here's thing: space co, c's output space? has particular name: world space.

therefore, d goes exact same world space c did. should no surprise right-multiplying won't cause rotation around world space.

so let's @ this: e = m * c. here, have different situation. e has same input space (model space) c, has different output space. is, world space e transforms different world space c transformed into.

and that's want if want rotate relative world space. changing world space object.

if change model space transform, transforming relative model space. if change world space transform, transforming relative world space.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -