Thursday, August 09, 2007

Problems Rotating Models in XNA

After finding Blender I've created some simple cubes and exported them into an XNA project. I want to rotate these after receiving input from the GamePad (although currently I'm testing with the Keyboard).

The idea that I have calls for the cubes to be rotated 90 degrees after a button press. The camera isn't moving, so having a cube rotate in this way means that the cube will always be displaying a full face.

I've figured out how to rotate, but as soon as I rotate around more than 1 axis I have to consider which direction the cube is facing to determine which direction I should rotate based on the next button press.

The cube needs to rotate up and down, and left and right, and the buttons to do this should be the same regardless of the cube's current orientation. My initial simple hamfisted attempt at rotating didn't take this into account. So if I rotated left and then pressed the button to rotate up, the model twists clockwise.

I rather stupidly failed to realise that the rotations are being done in relation to the model. Hindsight tells me how stupid I am for not realising this--how difficult would model movement and rotation be if everything was done in relation to the camera or an absolute point?

But now I know this it's got me wondering how I can achieve what I need. I suspect I need to store the current orientation of the cube, and then based on this determine which way is up so I can rotate accordingly.

Anyone have any experience of rotating models in this way?


Luna said...

I have exactly the same problem, haven't found a solution yet though...

Ian Dykes said...

Yeah, I still haven't figured that one out yet. Haven't been able to look at it much in the past couple of months though.

I guess I could search to see if anyone has released a 3D framework I could use.

I doubt I'll have much time to spend investigating this though

Anonymous said...

Yes, me too! yabba dabba doo!