Hi,

On Sonntag 17 Juli 2005 10:16, Vivian Meazza wrote:
> Before we do any rework of the MP code, it works as is in 0.9.8 (with some
> bugs), but it is fundamentally broken in CVS. In cvs the received aircraft
> are displayed close to the observer, rather than in their proper locations.
> It works OK in 0.9.8. Melchior suggested this was something to do with one
> of your recent updates, but I haven't rolled back to establish if this is
> the case.

The jitter removal patch was the cause for that.
But to be honest, that current multiplayer protocol cannot really work.
It transmits only offsets to the tile center without the information on which 
tile it is.
This was more or less sufficient for the case we had the scenery center at the 
tile center. But flying across tile bondaries was still broken ...

I have now included a patch to the multiplyer protocoll which does:

1. place the 3d model into the scenery using a placement transform which can 
dynamically change its scenry center.
2. Transmits unique position and orientation data for the 3d model.
3. Thus breaks protocol compatibility.
 :-/

Since the fg_server only forwards the network packets without looking into 
them, this will still work with that code.
But the position data sent by a flightgear release version cannot be 
understood by the current version. The same holds for the other way.

Opinions?

Given that it will make that usable in some way I will vote for applying.

Anyway, this protocol is very error prone since it neither cares for alignment 
nor for endianess. I don't know of it still works for x86_64, don't talk 
about the sgi's in Erik's zoo ...
:)

    Greetings

            Mathias

-- 
Mathias Fröhlich, email: [EMAIL PROTECTED]
Index: src/MultiPlayer/mpmessages.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/MultiPlayer/mpmessages.hxx,v
retrieving revision 1.2
diff -u -r1.2 mpmessages.hxx
--- src/MultiPlayer/mpmessages.hxx	26 Mar 2003 14:06:51 -0000	1.2
+++ src/MultiPlayer/mpmessages.hxx	24 Jul 2005 17:07:25 -0000
@@ -39,7 +39,8 @@
 
 // Message identifiers
 #define CHAT_MSG_ID 1
-#define POS_DATA_ID 2
+#define UNUSABLE_POS_DATA_ID 2
+#define POS_DATA_ID 3
 
 #define MAX_CALLSIGN_LEN 10
 /** Header for use with all messages sent */
@@ -80,7 +81,8 @@
     char sModel[MAX_MODEL_NAME_LEN];
 
     /** Position data for the aircraft */
-    sgMat4 PlayerPos;
+    sgdVec3 PlayerPosition;
+    sgQuat PlayerOrientation;
 
 } T_PositionMsg;
 
Index: src/MultiPlayer/mpplayer.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/MultiPlayer/mpplayer.cxx,v
retrieving revision 1.9
diff -u -r1.9 mpplayer.cxx
--- src/MultiPlayer/mpplayer.cxx	15 Jul 2005 09:45:57 -0000	1.9
+++ src/MultiPlayer/mpplayer.cxx	24 Jul 2005 17:07:25 -0000
@@ -53,6 +53,7 @@
 #include <plib/sg.h>
 
 #include <simgear/scene/model/modellib.hxx>
+#include <simgear/scene/model/placementtrans.hxx>
 
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
@@ -140,6 +141,7 @@
 
         // Disconnect the model from the transform, then the transform from the scene.
         m_ModelTrans->removeKid(m_Model);
+        globals->get_scenery()->unregister_placement_transform(m_ModelTrans);
         globals->get_scenery()->get_aircraft_branch()->removeKid( m_ModelTrans);
 
         // Flush the model loader so that it erases the model from its list of
@@ -164,12 +166,14 @@
 * Description: Updates position data held for this player and resets
 * the last update time.
 ******************************************************************/
-void MPPlayer::SetPosition(const sgMat4 PlayerPosMat4) {
+void MPPlayer::SetPosition(const sgQuat PlayerOrientation,
+                           const sgdVec3 PlayerPosition) {
 
 
     // Save the position matrix and update time
     if (m_bInitialised) {
-        sgCopyMat4(m_ModelPos, PlayerPosMat4);
+        sgdCopyVec3(m_ModelPosition, PlayerPosition);
+        sgCopyVec4(m_ModelOrientation, PlayerOrientation);
         time(&m_LastUpdate);
         m_bUpdated = true;
     }
@@ -187,16 +191,16 @@
 
     MPPlayer::TPlayerDataState eResult = PLAYER_DATA_NOT_AVAILABLE;
 
-    sgCoord sgPlayerCoord;
-
     if (m_bInitialised && !m_bLocalPlayer) {
         if ((time(NULL) - m_LastUpdate < TIME_TO_LIVE)) {
             // Peform an update if it has changed since the last update
             if (m_bUpdated) {
 
                 // Transform and update player model
-                sgSetCoord( &sgPlayerCoord, m_ModelPos);
-                m_ModelTrans->setTransform( &sgPlayerCoord );
+                sgMat4 orMat;
+                sgMakeIdentMat4(orMat);
+                sgQuatToMatrix(orMat, m_ModelOrientation);
+                m_ModelTrans->setTransform(m_ModelPosition, orMat);
 
                 eResult = PLAYER_DATA_AVAILABLE;
 
@@ -247,7 +251,7 @@
 void MPPlayer::LoadModel(void) {
 
 
-    m_ModelTrans = new ssgTransform;
+    m_ModelTrans = new ssgPlacementTransform;
 
     // Load the model
     m_Model = globals->get_model_lib()->load_model( globals->get_fg_root(),
@@ -265,6 +269,7 @@
 
     // Place on scene under aircraft branch
     globals->get_scenery()->get_aircraft_branch()->addKid( m_ModelTrans );
+    globals->get_scenery()->register_placement_transform( m_ModelTrans);
 
 
 }
@@ -280,7 +285,8 @@
 
     strncpy(PosMsg->sModel, m_sModelName.c_str(), MAX_MODEL_NAME_LEN);
     PosMsg->sModel[MAX_MODEL_NAME_LEN - 1] = '\0';
-    sgCopyMat4(PosMsg->PlayerPos, m_ModelPos);
+    sgdCopyVec3(PosMsg->PlayerPosition, m_ModelPosition);
+    sgCopyQuat(PosMsg->PlayerOrientation, m_ModelOrientation);
 
 
 }
Index: src/MultiPlayer/mpplayer.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/MultiPlayer/mpplayer.hxx,v
retrieving revision 1.5
diff -u -r1.5 mpplayer.hxx
--- src/MultiPlayer/mpplayer.hxx	20 Sep 2004 13:21:52 -0000	1.5
+++ src/MultiPlayer/mpplayer.hxx	24 Jul 2005 17:07:25 -0000
@@ -54,7 +54,7 @@
 
 
 class ssgEntity;
-class ssgTransform;
+class ssgPlacementTransform;
 
 
 class MPPlayer {
@@ -89,7 +89,8 @@
     /** Sets the positioning matrix held for this player
     * @param PlayerPosMat4 Matrix for positioning player's aircraft
     */
-    void SetPosition(const sgMat4 PlayerPosMat4);
+    void SetPosition(const sgQuat PlayerOrientation,
+                     const sgdVec3 PlayerPosition);
 
     /** Transform and place model for player
     */
@@ -127,8 +128,11 @@
     /** True if object is initialised */
     bool m_bInitialised;
 
-    /** Position matrix for the player's aircraft */
-    sgMat4 m_ModelPos;
+    /** Position of the player's aircraft wrt the earth fixed global system */
+    sgdVec3 m_ModelPosition;
+
+    /** Orientation the player's aircraft wrt the earth fixed global system */
+    sgQuat m_ModelOrientation;
 
     /** Used to remove player if no activity */
     time_t m_LastUpdate;
@@ -146,7 +150,7 @@
     ssgEntity *m_Model;
 
     /** Model transform */
-    ssgTransform *m_ModelTrans;
+    ssgPlacementTransform *m_ModelTrans;
 
     /** True if this player is the local player */
     bool m_bLocalPlayer;
Index: src/MultiPlayer/multiplayrxmgr.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/MultiPlayer/multiplayrxmgr.cxx,v
retrieving revision 1.11
diff -u -r1.11 multiplayrxmgr.cxx
--- src/MultiPlayer/multiplayrxmgr.cxx	1 Apr 2004 15:28:03 -0000	1.11
+++ src/MultiPlayer/multiplayrxmgr.cxx	24 Jul 2005 17:07:25 -0000
@@ -269,7 +269,7 @@
                                             if (m_Player[iPlayerCnt]->CompareCallsign(MsgHdr->sCallsign)) {
 
                                                 // Player found. Update the data for the player.
-                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos);
+                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
                                                 bActivePlayer = true;
 
                                             }
@@ -284,7 +284,7 @@
                                                 SG_LOG( SG_NETWORK, SG_INFO, "FGMultiplayRxMgr::ProcessRxData - Add new player. IP: " << sIpAddress << ", Call: " <<  sCallsign << ", model: " << sModelName );
                                                 m_Player[iPlayerCnt] = new MPPlayer;
                                                 m_Player[iPlayerCnt]->Open(sIpAddress, iPort, sCallsign, sModelName, false);
-                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos);
+                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
                                                 bActivePlayer = true;
                                             }
                                             iPlayerCnt++;
Index: src/MultiPlayer/multiplaytxmgr.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/MultiPlayer/multiplaytxmgr.cxx,v
retrieving revision 1.9
diff -u -r1.9 multiplaytxmgr.cxx
--- src/MultiPlayer/multiplaytxmgr.cxx	1 Apr 2004 15:28:03 -0000	1.9
+++ src/MultiPlayer/multiplaytxmgr.cxx	24 Jul 2005 17:07:25 -0000
@@ -189,14 +189,15 @@
 * Name: SendMyPosition
 * Description: Sends the position data for the local position.
 ******************************************************************/
-void FGMultiplayTxMgr::SendMyPosition(const sgMat4 PlayerPosMat4) {
+void FGMultiplayTxMgr::SendMyPosition(const sgQuat PlayerOrientation,
+                                      const sgdVec3 PlayerPosition) {
 
     T_MsgHdr MsgHdr;
     T_PositionMsg PosMsg;
     char sMsg[sizeof(T_MsgHdr) + sizeof(T_PositionMsg)];
 
     if (m_bInitialised) {
-        mLocalPlayer->SetPosition(PlayerPosMat4);
+        mLocalPlayer->SetPosition(PlayerOrientation, PlayerPosition);
         mLocalPlayer->FillPosMsg(&MsgHdr, &PosMsg);
         memcpy(sMsg, &MsgHdr, sizeof(T_MsgHdr));
         memcpy(sMsg + sizeof(T_MsgHdr), &PosMsg, sizeof(T_PositionMsg));
Index: src/MultiPlayer/multiplaytxmgr.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/MultiPlayer/multiplaytxmgr.hxx,v
retrieving revision 1.4
diff -u -r1.4 multiplaytxmgr.hxx
--- src/MultiPlayer/multiplaytxmgr.hxx	20 Sep 2004 13:21:52 -0000	1.4
+++ src/MultiPlayer/multiplaytxmgr.hxx	24 Jul 2005 17:07:25 -0000
@@ -70,7 +70,7 @@
     /** Sends the position data for the local player
     * @param PlayerPosMat4 Transformation matrix for the player's position
     */
-    void SendMyPosition(const sgMat4 PlayerPosMat4);
+    void SendMyPosition(const sgQuat PlayerOrientation, const sgdVec3 PlayerPosition);
     
     /** Sends a tex chat message.
     * @param sMsgText Message text to send
Index: src/Network/multiplay.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Network/multiplay.cxx,v
retrieving revision 1.4
diff -u -r1.4 multiplay.cxx
--- src/Network/multiplay.cxx	9 May 2003 19:39:52 -0000	1.4
+++ src/Network/multiplay.cxx	24 Jul 2005 17:07:25 -0000
@@ -30,6 +30,8 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/scene/model/placement.hxx>
 
+#include <Scenery/scenery.hxx>
+
 #include "multiplay.hxx"
 
 SG_USING_STD(string);
@@ -105,8 +107,16 @@
 
   } else if (get_direction() == SG_IO_OUT) {
 
-    globals->get_multiplayer_tx_mgr()->
-    SendMyPosition(globals->get_aircraft_model()->get3DModel()->get_POS());
+    sgMat4 posTrans;
+    sgCopyMat4(posTrans, globals->get_aircraft_model()->get3DModel()->get_POS());
+    Point3D center = globals->get_scenery()->get_center();
+    sgdVec3 PlayerPosition;
+    sgdSetVec3(PlayerPosition, posTrans[3][0] + center[0],
+               posTrans[3][1] + center[1], posTrans[3][2] + center[2]);
+    sgQuat PlayerOrientation;
+    sgMatrixToQuat(PlayerOrientation, posTrans);
+
+    globals->get_multiplayer_tx_mgr()->SendMyPosition(PlayerOrientation, PlayerPosition);
 
   }
 
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to