From e81e91cc392914369f71430d1fcf94e8a9c6acdc Mon Sep 17 00:00:00 2001
From: "Sven (Sbte)" <svenb.linux@gmail.com>
Date: Sun, 10 Mar 2013 11:59:49 +0100
Subject: Improve detection of whether we have to interpolate
Fixes angle interpolation in a nicer way and also fixed case where a turn
started before anything was rendered
---
source/simulation2/components/CCmpPosition.cpp | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp
index c24ec8f..7306a00 100644
a
|
b
|
public:
|
72 | 72 | entity_pos_t m_YOffset; |
73 | 73 | bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height |
74 | 74 | |
75 | | entity_angle_t m_RotX, m_RotY, m_RotZ; |
| 75 | entity_angle_t m_RotX, m_RotY, m_LastRotY, m_PrevRotY, m_RotZ; |
76 | 76 | float m_InterpolatedRotY; // not serialized |
77 | 77 | |
78 | 78 | static std::string GetSchema() |
… |
… |
public:
|
121 | 121 | |
122 | 122 | m_RotYSpeed = paramNode.GetChild("TurnRate").ToFixed().ToFloat(); |
123 | 123 | |
124 | | m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); |
| 124 | m_RotX = m_RotY = m_RotZ = m_PrevRotY = m_LastRotY = entity_angle_t::FromInt(0); |
125 | 125 | m_InterpolatedRotY = 0; |
126 | 126 | |
127 | 127 | m_PositionChanged = false; |
| 128 | m_Interpolated = false; |
128 | 129 | } |
129 | 130 | |
130 | 131 | virtual void Deinit() |
… |
… |
public:
|
329 | 330 | virtual void SetYRotation(entity_angle_t y) |
330 | 331 | { |
331 | 332 | m_RotY = y; |
| 333 | m_PrevRotY = y; |
| 334 | m_LastRotY = y; |
332 | 335 | m_InterpolatedRotY = m_RotY.ToFloat(); |
333 | 336 | |
334 | 337 | AdvertisePositionChanges(); |
… |
… |
public:
|
420 | 423 | { |
421 | 424 | case MT_Interpolate: |
422 | 425 | { |
| 426 | m_Interpolated = true; |
| 427 | if (!m_PositionChanged) |
| 428 | return; |
| 429 | |
423 | 430 | const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); |
424 | 431 | |
425 | 432 | float rotY = m_RotY.ToFloat(); |
… |
… |
public:
|
433 | 440 | // Calculate new orientation, in a peculiar way in order to make sure the |
434 | 441 | // result gets close to m_orientation (rather than being n*2*M_PI out) |
435 | 442 | m_InterpolatedRotY = rotY + deltaClamped - delta; |
436 | | |
437 | | // Anything smaller than this will not be visible |
438 | | if (abs(delta) > 0.0001) |
439 | | m_PositionChanged = true; |
440 | 443 | |
441 | 444 | break; |
442 | 445 | } |
… |
… |
public:
|
445 | 448 | // Store the positions from the turn before |
446 | 449 | m_PrevX = m_LastX; |
447 | 450 | m_PrevZ = m_LastZ; |
448 | | |
| 451 | m_PrevRotY = m_LastRotY; |
| 452 | |
449 | 453 | m_LastX = m_X; |
450 | 454 | m_LastZ = m_Z; |
| 455 | m_LastRotY = m_RotY; |
451 | 456 | |
452 | | m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ; |
| 457 | m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated; |
| 458 | m_Interpolated = false; |
453 | 459 | |
454 | 460 | break; |
455 | 461 | } |
… |
… |
private:
|
478 | 484 | } |
479 | 485 | |
480 | 486 | bool m_PositionChanged; |
| 487 | bool m_Interpolated; |
481 | 488 | }; |
482 | 489 | |
483 | 490 | REGISTER_COMPONENT_TYPE(Position) |