Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualgbMike

Posted 28 April 2012 - 03:56 PM

I have a ray, that I am trying to convert the vertices in, from global space, to the local space of an object. Converting translations and scale were easy enough, but rotations are giving me trouble.

Specifically, when I apply a apply a rotation in only the x, y, or z coord, it will calculate correctly. But if I apply rotation in two directions, it does not calculate correct coords. I'm not sure why they would fail running with multiple rotations, since if they each work individually. Here is my code:


Any thoughts? Thanks in advance.


[source lang="cpp"]  /////////// Z /////////////  // atan2( 0, 0 ) will throw an error  if( !(point.x == 0 && point.y == 0) )  {   //get initial 'rotation' of the vert from (0,0,0)   rot = atan2( -point.x, -point.y );     //convert rotation to radians and add it to the existing rotation   rot += CMath::DegreesToRadians( rotations.z );     length =  Vector3( point.x, point.y, 0 ).Length();   point.x = -sin( rot ) * length;   point.y = cos( rot ) * length;  }    /////////// Y /////////////  if( !(point.x == 0 && point.z == 0) )  {   rot = atan2( -point.x, -point.z );   rot += CMath::DegreesToRadians( rotations.y );     length =  Vector3( point.x, point.z, 0 ).Length();     point.x = sin( rot ) * length;   point.z = -cos( rot ) * length;  }      /////////// X /////////////  if( !(point.z == 0 && point.y == 0) )  {   rot = atan2( -point.z, -point.y );   rot += CMath::DegreesToRadians( rotations.x );   length =  Vector3( point.z, point.y, 0 ).Length();   point.z = sin( rot ) * length; //adj   point.y = -cos( rot ) * length; //opp  }[/source]

#1gbMike

Posted 28 April 2012 - 03:00 PM

I have a ray, that I am trying to convert the vertices in, from global space, to the local space of an object. Converting translations and scale were easy enough, but rotations are giving me trouble.

Specifically, when I apply a apply a rotation in only the x, y, or z coord, it will calculate correctly. But if I apply rotation in two directions, it does not calculate correct coords. I'm not sure why they would fail running with multiple rotations, since if they each work individually. Here is my code:


Any thoughts? Thanks in advance.


[source lang="cpp"]  /////////// Z /////////////  // atan2( 0, 0 ) will throw an error  if( !(point.x == 0 && point.y == 0) )  {   //get initial 'rotation' of the vert from (0,0,0)   rot = atan2( -point.x, -point.y );     //convert rotation to radians and add it to the existing rotation   rot += CMath::DegreesToRadians( rotations.z );     length =  Vector3( point.x, point.y, 0 ).Length();   point.x = -sin( rot ) * length;   point.y = cos( rot ) * length;  }    /////////// Y /////////////  if( !(point.x == 0 && point.z == 0) )  {   rot = atan2( -point.x, -point.z );   rot += CMath::DegreesToRadians( rotations.y );     length =  Vector3( point.x, point.z, 0 ).Length();     point.x = sin( rot ) * length;   point.z = -cos( rot ) * length;  }      /////////// X /////////////  if( !(point.z == 0 && point.y == 0) )  {   rot = atan2( -point.z, -point.y );   rot += CMath::DegreesToRadians( rotations.x );   length =  Vector3( point.z, point.y, 0 ).Length();   point.z = sin( rot ) * length; //adj   point.y = -cos( rot ) * length; //opp  }[/source]

PARTNERS