Fix stuttering of item rotation for big nitro switched by bubblegum

This commit is contained in:
Benau 2018-11-02 15:59:32 +08:00
parent 832c1abc9b
commit a7bbe54ea6
3 changed files with 23 additions and 15 deletions

View File

@ -159,7 +159,6 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
initItem(type, xyz); initItem(type, xyz);
m_graphical_type = type; m_graphical_type = type;
m_original_rotation = shortestArcQuat(Vec3(0, 1, 0), normal); m_original_rotation = shortestArcQuat(Vec3(0, 1, 0), normal);
m_rotation_angle = 0.0f;
m_listener = NULL; m_listener = NULL;
LODNode* lodnode = LODNode* lodnode =
@ -210,7 +209,6 @@ Item::Item(const Vec3& xyz, float distance, TriggerItemListener* trigger)
initItem(ITEM_TRIGGER, xyz); initItem(ITEM_TRIGGER, xyz);
m_graphical_type = ITEM_TRIGGER; m_graphical_type = ITEM_TRIGGER;
m_original_rotation = btQuaternion(0, 0, 0, 1); m_original_rotation = btQuaternion(0, 0, 0, 1);
m_rotation_angle = 0.0f;
m_node = NULL; m_node = NULL;
m_listener = trigger; m_listener = trigger;
m_was_available_previously = true; m_was_available_previously = true;
@ -332,7 +330,6 @@ void Item::handleNewMesh(ItemType type)
Vec3 hpr; Vec3 hpr;
hpr.setHPR(m_original_rotation); hpr.setHPR(m_original_rotation);
m_node->setRotation(hpr.toIrrHPR()); m_node->setRotation(hpr.toIrrHPR());
m_rotation_angle = 0.0f;
#endif #endif
} // handleNewMesh } // handleNewMesh
@ -369,18 +366,32 @@ void Item::updateGraphics(float dt)
if (!isAvailable() && time_till_return <= 1.0f) if (!isAvailable() && time_till_return <= 1.0f)
{ {
// Make it visible by scaling it from 0 to 1: // Make it visible by scaling it from 0 to 1:
if (rotating())
{
float angle =
fmodf((float)(World::getWorld()->getTicksSinceStart() +
getTicksTillReturn()) / 40.0f, M_PI * 2);
btMatrix3x3 m;
m.setRotation(m_original_rotation);
btQuaternion r = btQuaternion(m.getColumn(1), angle) *
m_original_rotation;
Vec3 hpr;
hpr.setHPR(r);
m_node->setRotation(hpr.toIrrHPR());
}
m_node->setVisible(true); m_node->setVisible(true);
m_node->setScale(core::vector3df(1, 1, 1)*(1 - time_till_return)); m_node->setScale(core::vector3df(1, 1, 1)*(1 - time_till_return));
} }
if (isAvailable() && rotating()) if (isAvailable() && rotating())
{ {
// have it rotate // have it rotate
m_rotation_angle += dt * M_PI; float angle =
if (m_rotation_angle > M_PI * 2) m_rotation_angle -= M_PI * 2; fmodf((float)World::getWorld()->getTicksSinceStart() / 40.0f,
M_PI * 2);
btMatrix3x3 m; btMatrix3x3 m;
m.setRotation(m_original_rotation); m.setRotation(m_original_rotation);
btQuaternion r = btQuaternion(m.getColumn(1), m_rotation_angle) * btQuaternion r = btQuaternion(m.getColumn(1), angle) *
m_original_rotation; m_original_rotation;
Vec3 hpr; Vec3 hpr;

View File

@ -323,9 +323,6 @@ private:
* rotation). */ * rotation). */
btQuaternion m_original_rotation; btQuaternion m_original_rotation;
/** Used when rotating the item */
float m_rotation_angle;
/** Scene node of this item. */ /** Scene node of this item. */
LODNode *m_node; LODNode *m_node;

View File

@ -56,12 +56,6 @@ protected:
/** The instance of ItemManager while a race is on. */ /** The instance of ItemManager while a race is on. */
static std::shared_ptr<ItemManager> m_item_manager; static std::shared_ptr<ItemManager> m_item_manager;
/** Stores all item models. */
static std::vector<scene::IMesh *> m_item_mesh;
/** Stores all low-resolution item models. */
static std::vector<scene::IMesh *> m_item_lowres_mesh;
public: public:
static void loadDefaultItemMeshes(); static void loadDefaultItemMeshes();
static void removeTextures(); static void removeTextures();
@ -116,6 +110,12 @@ private:
* field is undefined if no Graph exist, e.g. arena without navmesh. */ * field is undefined if no Graph exist, e.g. arena without navmesh. */
std::vector< AllItemTypes > *m_items_in_quads; std::vector< AllItemTypes > *m_items_in_quads;
/** Stores all item models. */
static std::vector<scene::IMesh *> m_item_mesh;
/** Stores all low-resolution item models. */
static std::vector<scene::IMesh *> m_item_lowres_mesh;
protected: protected:
/** Remaining time that items should remain switched. If the /** Remaining time that items should remain switched. If the
* value is <0, it indicates that the items are not switched atm. */ * value is <0, it indicates that the items are not switched atm. */