【发布时间】:2017-11-25 00:53:59
【问题描述】:
以下代码有问题:
//Make life easier by assigning the last two relevant messages to variables
Update pos0 = m_Network->positionUpdates[m_Network->positionUpdates.size() - 1];
Update pos1 = m_Network->positionUpdates[m_Network->positionUpdates.size() - 2];
//Calculate velocities for X and Z from last two messages
velX = (pos0.posX - pos1.posX) / (pos0.timeStamp - pos1.timeStamp);
velZ = (pos0.posZ - pos1.posZ) / (pos0.timeStamp - pos1.timeStamp);
//Calculate the time for when we are trying to predict
predictionTime = totalTime - pos0.timeStamp;
//Linear prediction model to calculate where we want the car to be
D3DXVECTOR3 newPos = D3DXVECTOR3((pos0.posX + velX * predictionTime), 2.0f, (pos0.posZ + velZ * predictionTime));
//Interpolate to the new position
D3DXVec3Lerp(&position, &position, &newPos, timeSinceLastFrame);
//Set the model to where the car is
m_Model->SetPosition(position.x, position.y, position.z);
如您所见,这个想法是获取从另一个客户端收到的消息,并找到对象的速度以计算其位置。
我知道那部分是有效的,因为当我简单地将汽车的位置更新为方程的输出时,汽车会去它应该去的地方(以一种非常紧张的方式)。
当我尝试从当前位置移动到新位置时,汽车甚至没有出现在屏幕上。查看 Ve3Lerp 函数实际返回的内容,我得到的只是“-1 INDEF”。
有什么想法吗?
【问题讨论】:
-
timeSinceLastFrame 是 int 还是 float?是否以毫秒为单位?可能就是这样。
-
它是一个浮点数,时间以秒为单位(即0.016)
-
您可以尝试将不同的向量作为第一个参数传递。由于第二个被标记为 const 它可能会做一些奇怪的事情,如果它碰巧正在修改第一个而期望第二个不会改变。
-
刚刚试了一下,但没有任何作用,尽管欢呼,但还是不错的建议。
-
请记住,D3DXmath 是旧版,需要在您的目标系统上部署已弃用的
D3DX9、D3DX10或D3DX11DLL。请参阅 MSDN 和 Living without D3DX。此外,没有理由使用 Direct3D 10。请改用 DirectX 11。
标签: c++ directx-10 lerp