3

I want to be able to tell the server my model's orientation so it can in turn send it back to all other players. However getting values through shared memory(which at worst take byte values, at best integer).

Is there a mathematical way I can check my model's rotation, convert it to a degree value off of a default and then send that 1-360 degree value to the server rather than trying to send 16 float values of the entire matrix structure?

Sending the 16 floats racks me up to 120 somethin' extra shared memory files with all players involved. Not really the best practice. Any insight?

Remm
  • 677
  • 8
  • 24

2 Answers2

2

Would it be feasible convert the rotation matrix to a quaternion? This would cut down from sending the whole matrix to sending a single vector and rotation around that vector.

XNA has a quaternion structure ( http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.quaternion.aspx ) which contains the method: Quaternion.CreateFromRotationMatrix which takes a rotational matrix.

This will generate the ijk quaternion with the W component as the rotation theta around this axis.

Sojha
  • 38
  • 1
  • 6
  • It seems that the Y and the W of the quaternion account for the rotation, while X and Z stay at zero. Going to multiply the Y and W by 10 thousand each and send as integers, then divide them back when they come full circle to other clients. Accepted answer is yours if all goes according to plan – Remm Apr 15 '11 at 20:30
  • Bam. You win. I got it to work after a bit of jury rigging. My shared memory library does not work too well with decimal values, so I multiply it all by 10 thousand, then when it comes back around as peer data I divide it back. – Remm Apr 15 '11 at 21:59
  • @Remm Note that this is essentially the same approach as Euler angles. I'm curious as to why you keep saying decimal rather than float. You can't really be using decimal or are you? Why would you opt for that for something other than currency? – David Heffernan Apr 16 '11 at 14:25
  • when I say decimal I mean float, but I'm just generalizing between it and double. I'm not ignorant, just use poor wording, that's all. Everything is floating, we're all on a boat, no worries. :] – Remm Apr 16 '11 at 22:14
1

The 3 by 3 rotation part could be represented as 3 Euler angles. But then you've got to do quite a bit of trig to convert back and forth. Maybe your problem is easier since you hint that you only have 1 degree of freedom.

In any case why not send the 16 floats?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Mainly because that is 96 extra fields being sent from the server to the client, 20(hopefully 30 soon) times a second. Secondly, basically anything with a decimal value goes into convulsions when you try to put it into shared memory (in my experience, at least). If I have no other choice I will do this but getting something cleaner and more efficient to go back and forth between client, clientNetwork and Server programs would be beyond appreciated. I will look into trying to make it work with Euler angles, though that subject is new to me. – Remm Apr 15 '11 at 03:43