Wednesday, July 15, 2015

Amy Mercury
( or Amy Iodyne )

well yesterday i didnt finish the mcjAimAnim

but i found out information which will help me in the future

notably: the getXAxis() function in DS4 ( maybe DS3 too ) returns non-normalized vectors

the getAngleTo() function returns absolute value of the rotation angle

this function here seems to work

let vn = Q.getXAxis()

v1 and v2 have been projected on the XAxis (normal) plane

we want to rotate v1 around the X axis until it's oriented like v2

this seems to work

function getAngleTo( v1, v2, vn )
{
 v1.normalize();
 v2.normalize();
 var ca = v1.dot( v2 );
 var angle = Math.acos( ca );
 cp = v1.cross( v2 );
 cp.normalize();
 if( vn.dot( cp ) < 0 ) 
 {
  angle = -angle;
 }
 return( angle );
}

then we add this angle to the joint's XRotation ( Euler ) angle 
function rotateX( t, limbRoot, currnt, wanted  )


{

 var axis = limbRoot.getWSRot( t ).getXAxis();

 var a = degrees * rotate( axis, t, limbRoot, currnt, wanted  );

 var ctl = limbRoot.getXRotControl();

 ctl.setValue( t, ctl.getValue( t ) + a );

}

function rotate( axis, t, limbRoot, currnt, wanted  )

{

 //todo it's a vector we project on the plane, 

 //make sure we do this properly

 currnt = projectPointOnPlane( currnt, axis );

 wanted = projectPointOnPlane( wanted, axis );

 var a = getAngleTo( currnt, wanted, axis );

 return( a );

}

function projectPointOnPlane( p, n )



{

 n = n.normalized();

 var t = p.dot( n );

 var v = new DzVec3( p.x - t * n.x,  p.y - t * n.y, p.z - t * n.z );

 return( v );

}


No comments:

Post a Comment