3D View and orientation of other player's

Started by
20 comments, last by Dominik_78 21 years, 3 months ago
Hi, i got my networkcode working now - but I am stuck to what to transfer to the server. I got the Position in Space and my qauntion (Angle and 3 Values). but I got a wiered effect in the rotation. what i transfer: cameraQuat.GetAxisAngle(axis, angle); angle = (float) RADTODEG(angle); float ax, ay, az; axis.GetValues(ax, ay, az); I transfer angle, ax, ay, az. (this represents the functioning view rotation info of a clients view) this is what i do to render the client on the server: for (int ei = 0; ei < enemycount; ei++) { if (enemies[ei].isConnected() == TRUE && enemies[ei].isAlive() == TRUE) { glLoadIdentity(); glRotatef(angle, ax, ay, az); glTranslatef(x_tra,y_tra,z_tra); glTranslatef(enemies[ei].x_pos,enemies[ei].y_pos,enemies[ei].z_pos); glRotatef(enemies[ei].angle, enemies[ei].dx, enemies[ei].dy, enemies[ei].dz); res = res + enemies[ei].drawEnemy(); } } *_pos = position d* = direction (quantion) what have I done wrong? thank you Dominik
Advertisement
Hi again,

as i play around with this I notice it feels like gimbal lock. but how can this be? I use quantions? Is this because I have to multiply my 2 Rotations into one in a different way? and if this is so, how to do this? (link to a more in deep quantion tutorial would be best if this is the way to do it).

But this way of rotate translate camera view + translate rotate client position and direction is giving the right position but the orientation of the client is in some ways wrong (sometimes it is ok, if i only rotate on one axis). just like my old problem which was due to the gimbal lock.

did somebody else experiensed this?

thanks

Dominik

Nobody know''s about this?
First of all, it''s quaternion, not quantion (the term quantion actually exists, btw, but it is used in the field of particle physics... )

About your problem, well, I have to admit that I don''t really understand what you mean. There is something ''wrong'' with your rotations. OK. But what exactly ? We need more information to be able to help you.

Generally, if your camera computation are solely based on quaternions, and no Euler angles come into play at any moment (and that includes things like roll, pitch and yaw), then the gimbal lock should not occur. A conversion from quaternion to angle/axis should not be a problem either.

Now, you apply two different glRotate() commands on two different angle/axis pairs. This can lead to a gimbal lock. You can actually visualize the two distinct angle/axis pairs as two (from 3) vectors forming an Euler coordinate triple: your are rotating your coordinate frame twice, around different axes. Given the (in-)appropriate values for such an axis/angle pair, the last rotation can possibly lock.

The trick to avoid gimbal lock-like situations, is to do *all* the rotation in quaternion space. Only the final rotation can then be safely transfered to a rotation matrix (perhaps through an intermediate angle/axis conversion). Any subsequent coordsys rotation you apply to this system can produce a gimbal lock.

But your problem can very well be somewhere else. There is not enough information. For further help, you''ll need to describe your problem in greater detail, and provide some more insight in what you are trying to achieve with those rotations.

/ Yann
Thank's Yann L,

it is probably due to my lack of abitlity to express my problem in 3D in english that good.

I got my Camera Rotation's and I use quaternion to represent them.

EDIT: The view on the client is perfect but the representation of the client rotation on the server is the problem.

If I move and turn in space my quaternion is affected and just before I render to the screen I read out the euler angle out of the Camera - quaternion.
this:


          	CSSVector3D	axis;	cameraQuat.GetAxisAngle(axis, angle);	angle = (float) RADTODEG(angle);	float ax, ay, az;	axis.GetValues(ax, ay, az);        


Now this happens:

I transfer this extracted values to the server (problably wrong if I understand your post right).

Now to display the client on the server I first extract the euler angle from the quaternion like on the client (camera orientation of the server). and then I apply the translation of the client and the rotation of the client to OpenGL and render a client object. Position then is OK but the rotation not.

Now the effect is:

if i turn around only on one the x-ax on the client (pull the stick back to make a looping) everything is ok but as soon as a 2nd axis come into play the problem starts just like my gimbal lock problem I had the time before I started to changes all my rotations to quaternions.

now what can I do?

Am I right to think that I need 2 rotations because of the translate between them and sticking the 2 together will mess my client position up a lot. Because it is a difference to rotate and translate or translate and rotate right?



[edited by - Dominik_78 on December 28, 2002 11:19:45 AM]
An easier question would have been at all:

how to draw my own camera orientation and player position and draw my enemies with it''s orientation?

a tip or sourcecode would then be enough.

thank you

Dominik
So Yann L, is it now easier to understand my problem?

I need that 2 Rotations and between that I need a translate. to make 1. My Enemy rotate around me and second rotate about it own center to make the enemy point to the right direction.


thanks

Dominik
quote:
So Yann L, is it now easier to understand my problem?

Honestly, I''m still not quite sure what you want I guess you''re writing a multiplayer game, where each player has his local camera position. And you want the player character''s mesh objects to be oriented in the right direction, when viewed from another player. Is that right ? If not, kannst Du dein Problem auch kurz auf Deutsch erklären, um weiteren Mißverständnissen vorzubeugen

So let''s assume that this is what you want. The standard way of doing that is as follows: Player A moves around in a 3D scene. His camera matrix gets transfered to Player B. B''s system applies A''s transfered camera matrix as local transformation matrix onto A''s character mesh object. That''s pretty much it. The local camera view of B should, and will not interfere with the local object matrix of A''s character.

In pseudocode, that would look like this:


  glLoadIdentity();glLoadMatrixf( This_Players_Camera_Matrix );for( p = each connected enemy player ) {   m = Network.GetEnemyObjectMatrix(p);    // get the local character object matrix of enemy[p]   glPushMatrix();                         // push current view matrix onto the stack    glMultMatrixf(m);                       // multiply the local transform matrix of the current enemy with the view matrix   RenderObject(p);                        // draw it   glPopMatrix();                          // get back view matrix from the stack}  

There won''t be any gimbal lock problems. The local object transform matrix is just normally concatenated with the view matrix, pretty much standard. You should also directly extract the camera matrix from the quaternion you use for your camera model. Not using Euler angles at any point is the best way to avoid gimbal locks of any sort.

/ Yann
Puh, now that is what I want.

I thank you Yann L.

Danke

I did not mentioned the multiplayer aspect. That was my 1. fault.

I will test this in the evening - now I have to work a bit for the last days of the year.

thank you
Hmmm Yann L,

I am sorry but this did not solved the problem.

I post a bit source code this evening.

Or what else can I do now?

thanks

Dominik

[edited by - Dominik_78 on December 30, 2002 10:08:42 AM]

This topic is closed to new replies.

Advertisement