opengl - How to rotate object using the 3D graphics pipeline ( Direct3D/GL )? -


i have problems trying animate rotation of mesh objects.

if make rotation process once fine. meshes rotated , final image webgl buffer looks pretty fine.

http://s22.postimg.org/nmzvt9zzl/311.png

but if use rotation in loop (with each new frame record) meshes starting weird, next screenshot:

http://s22.postimg.org/j2dpecga9/312.png

i won't provide here programming code, because issue depend on incorrect 3d graphics handling.

i think opengl/direct3d developers may give advice how fix it, because question relates 3d-programming subject , specific gl or d3d function/method. think way of work rotation same both in opengl , direct3d because of linear algebra , affine affine transformations.

if interested i'm using, answer webgl.

let me describe how use rotation of object.

the simple rotation made using quaternions. mesh object define has quaternion property.

if rotate object method rotate() doing next:

// kind of pseudo-code function rotatemesh( vector, angle ) {     var tempquatenion = math.convertrotationtoquaternion( vector, angle );     this.quaternion = math.multiplyquaternions( this.quaternion, tempquatenion ); } 

i use next piece of code in renderer class handle mesh translation , rotation:

// kind of pseudo-code // each mesh, added scene modelviewmatrix = new identitymatrix() translatematrixbyvector( modelviewmatrix, mesh.position ) modelviewmatrix.multiplybymatrix( mesh.quaternion.tomatrix() ) 

so... want ask if logic above correct provide sources of math functions used quaternions, rotations, etc...

if logic above incorrect think makes no sense provide else. because it's required fix main logic.

quaternion multiplication not commutative, i.e., if a , b quaternions a * b != b * a. if want rotate quaternion quaternion b, need a = b * a, this:

    this.quaternion = math.multiplyquaternions( this.quaternion, tempquatenion ); 

should have arguments reversed.

in addition, mentioned @ratchet-freak in comments, should make sure quaternions normalized, otherwise transformations other rotation may happen.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -