游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4251|回复: 7

如何采用导航推测法实现网络同步?

[复制链接]

3

主题

14

帖子

18

积分

新手上路

Rank: 1

积分
18
发表于 2008-7-8 19:54:00 | 显示全部楼层 |阅读模式
我想实现对客户端预测以实现游戏画面的流畅性,不会产生人物位置跳来跳去的结果!
我分别参考了
//英文参考:"Defeating Lag With Cubic Splines" by Nick Caldwell        http://www.gamedev.net/reference/articles/article914.asp
//中文参考:《小谈网络游戏同步》http://dev.gameres.com/Program/Abstract/DeadReckoning.htm

可是感觉实现上还是很有难度。

3

主题

14

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2008-7-18 16:32:00 | 显示全部楼层

Re:如何采用导航推测法实现网络同步?

               Coord3 = xpacket + vpacket*t + .5*apacket*t2
                Coord4 = Coord3 -  (Vpacket + apacket*t)

          x= At3 + Bt2 + Ct + D
          y = Et3 + Ft3 + Gt + H


我不知道这两个t 是否相同,并且这个t又是从何处获取的呢?
并且感觉,这个坐标的算法和上面的
Coordinate 1 = Starting position
Coordinate 2 = Position after 1 second using starting velocity
= Coordinate1 + StartVelocity
Coordinate 3 = Position after 1 second using reversed ending velocity
= Coordinate4 - EndVelocity
Coordinate 4 = Ending position


这个第3个和第4个坐标是不是写错了



3

主题

14

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2008-7-18 16:33:00 | 显示全部楼层

Re:如何采用导航推测法实现网络同步?

希望有谁做过这方面的来指点一下

3

主题

14

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2008-7-18 16:34:00 | 显示全部楼层

Re:如何采用导航推测法实现网络同步?

贴上自己的代码

  1. //Update every frame  
  2. void MoveEventProcess::ExecuteEvent(float fElapsedTime;Mx_ICharacter* pCharacter)
  3. {
  4. //The Prediction position
  5. MxPoint3 ptPredictionPos(0,0,0);

  6. m_bMovingPrediction = false;

  7. //Receive new package
  8. if(!m_queMovePath.empty() && !m_bStartSmooth)
  9. {

  10.   m_bStartSmooth = true;

  11.   //pop the package from the queue
  12.   MovePath* path = m_queMovePath.front();
  13.   m_queMovePath.pop_front();

  14.   //get the velocity and position from package
  15.   ptVelocityNew = path->m_ptVelocity;
  16.   ptPosNew = path->oCurve.m_ptDest;

  17.   //get current position and  velocity
  18.   ptPosOld = pCharacter->GetTranslate();
  19.   ptVelocityOld = m_ptLastVelocity;

  20.   //get  the orientation
  21.   fDestAngle = path->oCurve.m_fDestAngle;

  22.   //Safe Realse the path
  23.   Mx_Safe_Delete(path);
  24. }

  25. else if (m_bStartSmooth)
  26. {
  27.   //predict for 1 second
  28.   if (m_fPredictionTime < 1)
  29.   {


  30.    ptPredictionPos = CubicSplines(ptPosOld,ptVelocityOld,ptPosNew,ptVelocityNew,m_fPredictionTime);


  31.    //Change the Character
  32.    pCharacter->SetTranslate(ptPredictionPos);
  33.    pCharacter->SetAnimationEvent(m_eLastTrigger);
  34.    pCharacter->SetOrient(fDestAngle);

  35.    //add the fElapsedTime
  36.    m_fPredictionTime  = m_fPredictionTime + fElapsedTime;

  37.   }
  38.   else
  39.   {
  40.    m_bStartSmooth = false;
  41.    m_fPredictionTime = 0.0f;

  42.    //save the new velocity to be a last veloctity
  43.    m_ptLastVelocity = ptVelocityNew;
  44.   }
  45. }


  46. //Make the character physical movement
  47. else if (m_queMovePath.empty() && !m_bStartSmooth)
  48. {

  49.   //If current state isn't stop
  50.   if (!m_ptLastVelocity.AlmostEqual(MxPoint3::ZERO))
  51.   {
  52.    m_bMovingPrediction = true;

  53.    //Calculated the position by velocity
  54.    MxPoint3 ptDisplace = m_ptLastVelocity * fElapsedTime;
  55.    MxPoint3 ptDest = pCharacter->GetTranslate() + ptDisplace;

  56.    //Update the Character
  57.    pCharacter->SetTranslate(ptDest);
  58.    pCharacter->SetAnimationEvent(m_eLastTrigger);
  59.   }

  60. }
  61. }


  62. //Cubic Splines Processing
  63. //
  64. MxPoint3 MoveEventProcess::CubicSplines(MxPoint3 ptPosOld,MxPoint3 ptVelocityOld,MxPoint3 ptPosNew,MxPoint3 ptVelocityNew,float fTime)
  65. {
  66. float t = fTime;

  67. //新的加速度
  68. //float fAccelerationNew = 0.f;

  69. MxPoint3 pos0 = ptPosOld;
  70. MxPoint3 pos1 = ptPosOld + ptVelocityOld;
  71. MxPoint3 pos2 = ptPosNew - ptVelocityNew ;
  72. MxPoint3 pos3 = ptPosNew;


  73. float A = pos3.x - 3 * pos2.x + 3 * pos1.x - pos0.x;
  74. float B = 3 * pos2.x - 6 * pos1.x + 3 * pos0.x;
  75. float C = 3 * pos1.x - 3 * pos0.x;
  76. float D = pos0.x;

  77. float E = pos3.y - 3 * pos2.y + 3 * pos1.y - pos0.y;
  78. float F = 3 * pos2.y - 6 * pos1.y + 3 * pos0.y;
  79. float G = 3 * pos1.y - 3 * pos0.y;
  80. float H = pos0.y;

  81. float I = pos3.z - 3 * pos2.z + 3 * pos1.z - pos0.z;
  82. float J = 3 * pos2.z - 6 * pos1.z + 3 * pos0.z;
  83. float K = 3 * pos1.z - 3 * pos0.z;
  84. float L = pos0.z;

  85. float t1 = t;
  86. float t2 = t * t;
  87. float t3 = t * t * t;

  88. float x = A * t3  + B * t2 + C * t1 + D;
  89. float y = E * t3  + F * t2 + G * t1 + H;
  90. float z = I * t3  + J * t2 + K * t1 + L;

  91. MxPoint3 pt(x,y,z);
  92. return pt;
  93. }
复制代码

0

主题

37

帖子

41

积分

注册会员

Rank: 2

积分
41
发表于 2008-7-18 17:11:00 | 显示全部楼层

Re:如何采用导航推测法实现网络同步?

偶是新手,进来学习学习

3

主题

14

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2008-7-18 18:50:00 | 显示全部楼层

Re:如何采用导航推测法实现网络同步?

神啊,来个能回答我问题的人吧…………

0

主题

2

帖子

16

积分

新手上路

Rank: 1

积分
16
发表于 2013-3-7 11:43:44 | 显示全部楼层
我现在也遇到了,看这个那个文档都不知道怎么实现,最后写出来的一顿一顿的

23

主题

515

帖子

552

积分

高级会员

Rank: 4

积分
552
发表于 2013-4-8 23:02:51 | 显示全部楼层
有什么可神秘的啊?就是按照你最后收到的速度和方向移动。。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-2-26 23:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表