XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Rotating a single 3D object by multiple points (Also: quaternions)

Last post 25/06/2009 20:51 by Matt Richard. 2 replies.
  • 21/06/2009 3:04

    Rotating a single 3D object by multiple points (Also: quaternions)

    Okay,

    I have a very simple project set up specifically for this question. It's just a 3D shape centered in the origin. I've been looking everywhere for a way to rotate that object by any two points.
    So let's say the object was a gun and there was a character behind it with the gun mesh in its hand. I'd want to have the character and the gun to rotate around the same point so that the character and the gun it was carrying could rotate as a whole. But I'd also like to be able to tilt the gun around its own origin so that I could maybe make it point a little up in the character's hand. So I'd need to rotate it around the character's center and the gun's center.
    I'm sure this problem's come up a lot. I'm fine with just links to tutorials or other threads where this was explained in this forum.

    I have a pretty good understanding of matrices and their transformations, but I am completely lost with quaternions so links for those would be great too.

    Thanks
  • 21/06/2009 8:11 In reply to

    Re: Rotating a single 3D object by multiple points (Also: quaternions)

    First create the rotation matrix for the gun.
    second, place the gun at the hand
    third, make the rotation & translation matrix for the player
    fourth, mulitiply the gun matrix by the player matrix.

    something like this..

    gun_matrix = Matrix.Identity * Matrix.CreateRotationXXX( rotations )

    gun_matrix.Translation = position_of_players_hand

    player_matrix = Matrix.identity * Matrix.createrotationsxxxx(player rotations)

    player_matrix.Translation = position_of_player

    //now rotate the gun by the player matrix, which will also move it relative to the player

    gun_matrix *= player_matrix


    best,
    Byron








    ..shaders make you feel... powerful, or very very stupid.
    http://drjbn.spaces.live.com/
  • 25/06/2009 20:51 In reply to

    Re: Rotating a single 3D object by multiple points (Also: quaternions)

    Thanks that works great.
Page 1 of 1 (3 items) Previous Next