From 060dfb791b823bb3c465ff5ab885cd0776496bf3 Mon Sep 17 00:00:00 2001 From: SilverIce Date: Fri, 24 Jun 2011 14:28:08 +0300 Subject: [PATCH] [11667] Implement transport path rotation Transport rotation transforms transport path - this makes possible to have few transports with same entry but with modified paths. This also solvers problems with some transports (like deeprun tram). TODO: some transports has non standart rotations, that must be stored in db Signed-off-by: SilverIce --- src/game/GameObject.cpp | 44 +++++++++++++++++++++++++--------------- src/game/GameObject.h | 6 ++++-- src/game/Level2.cpp | 2 +- src/shared/revision_nr.h | 2 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index f3bde11d63c..3d494e98cf1 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -129,7 +129,10 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMa SetObjectScale(goinfo->size); - SetRotationQuat(rotation0,rotation1,rotation2,rotation3); + SetWorldRotation(rotation0,rotation1,rotation2,rotation3); + // For most of gameobjects is (0, 0, 0, 1) quaternion, only transports has not standart rotation + // TODO: store these values in DB + SetTransportPathRotation(0, 0, 0, 1.f); SetUInt32Value(GAMEOBJECT_FACTION, goinfo->faction); SetUInt32Value(GAMEOBJECT_FLAGS, goinfo->flags); @@ -514,10 +517,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask) data.posY = GetPositionY(); data.posZ = GetPositionZ(); data.orientation = GetOrientation(); - data.rotation0 = GetFloatValue(GAMEOBJECT_PARENTROTATION+0); - data.rotation1 = GetFloatValue(GAMEOBJECT_PARENTROTATION+1); - data.rotation2 = GetFloatValue(GAMEOBJECT_PARENTROTATION+2); - data.rotation3 = GetFloatValue(GAMEOBJECT_PARENTROTATION+3); + data.rotation0 = m_quatX; + data.rotation1 = m_quatY; + data.rotation2 = m_quatZ; + data.rotation3 = m_quatW; data.spawntimesecs = m_spawnedByDefault ? (int32)m_respawnDelayTime : -(int32)m_respawnDelayTime; data.animprogress = GetGoAnimProgress(); data.go_state = GetGoState(); @@ -535,10 +538,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask) << GetPositionY() << ", " << GetPositionZ() << ", " << GetOrientation() << ", " - << GetFloatValue(GAMEOBJECT_PARENTROTATION) << ", " - << GetFloatValue(GAMEOBJECT_PARENTROTATION+1) << ", " - << GetFloatValue(GAMEOBJECT_PARENTROTATION+2) << ", " - << GetFloatValue(GAMEOBJECT_PARENTROTATION+3) << ", " + << m_quatX << ", " + << m_quatY << ", " + << m_quatZ << ", " + << m_quatW << ", " << m_respawnDelayTime << ", " << uint32(GetGoAnimProgress()) << ", " << uint32(GetGoState()) << ")"; @@ -1669,7 +1672,7 @@ struct QuaternionCompressed int64 m_raw; }; -void GameObject::SetRotationQuat(float qx, float qy, float qz, float qw) +void GameObject::SetWorldRotation(float qx, float qy, float qz, float qw) { Quat quat(qx, qy, qz, qw); // Temporary solution for gameobjects that has no rotation data in DB: @@ -1678,16 +1681,25 @@ void GameObject::SetRotationQuat(float qx, float qy, float qz, float qw) quat.unitize(); m_rotation = QuaternionCompressed(quat).m_raw; - SetFloatValue(GAMEOBJECT_PARENTROTATION+0, quat.x); - SetFloatValue(GAMEOBJECT_PARENTROTATION+1, quat.y); - SetFloatValue(GAMEOBJECT_PARENTROTATION+2, quat.z); - SetFloatValue(GAMEOBJECT_PARENTROTATION+3, quat.w); + m_rotation = QuaternionCompressed(quat).m_raw; + m_quatX = quat.x; + m_quatY = quat.y; + m_quatZ = quat.z; + m_quatW = quat.w; +} + +void GameObject::SetTransportPathRotation(float qx, float qy, float qz, float qw) +{ + SetFloatValue(GAMEOBJECT_PARENTROTATION+0, qx); + SetFloatValue(GAMEOBJECT_PARENTROTATION+1, qy); + SetFloatValue(GAMEOBJECT_PARENTROTATION+2, qz); + SetFloatValue(GAMEOBJECT_PARENTROTATION+3, qw); } -void GameObject::SetRotationAngles(float z_rot, float y_rot, float x_rot) +void GameObject::SetWorldRotationAngles(float z_rot, float y_rot, float x_rot) { Quat quat( G3D::Matrix3::fromEulerAnglesZYX(z_rot, y_rot, x_rot) ); - SetRotationQuat(quat.x, quat.y, quat.z, quat.w); + SetWorldRotation(quat.x, quat.y, quat.z, quat.w); } bool GameObject::IsHostileTo(Unit const* unit) const diff --git a/src/game/GameObject.h b/src/game/GameObject.h index 1b59595e1e0..2cca1643ba8 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -607,7 +607,9 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject bool HasStaticDBSpawnData() const; // listed in `gameobject` table and have fixed in DB guid // z_rot, y_rot, x_rot - rotation angles around z, y and x axes - void SetRotationAngles(float z_rot, float y_rot, float x_rot); + void SetWorldRotationAngles(float z_rot, float y_rot, float x_rot); + void SetWorldRotation(float qx, float qy, float qz, float qw); + void SetTransportPathRotation(float qx, float qy, float qz, float qw); // transforms(rotates) transport's path int64 GetRotation() const { return m_rotation; } // overwrite WorldObject function for proper name localization @@ -745,9 +747,9 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject GameObjectInfo const* m_goInfo; GameObjectDisplayInfoEntry const* m_displayInfo; int64 m_rotation; + float m_quatX, m_quatY, m_quatZ, m_quatW; private: void SwitchDoorOrButton(bool activate, bool alternative = false); - void SetRotationQuat(float qx, float qy, float qz, float qw); GridReference m_gridRef; }; diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index e11045cf0c2..f3a2b84e922 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -962,7 +962,7 @@ bool ChatHandler::HandleGameObjectTurnCommand(char* args) if (!ExtractFloat(&args, z_rot) || !ExtractOptFloat(&args, y_rot, 0) || !ExtractOptFloat(&args, x_rot, 0)) return false; - obj->SetRotationAngles(z_rot, y_rot, x_rot); + obj->SetWorldRotationAngles(z_rot, y_rot, x_rot); obj->SaveToDB(); PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, obj->GetGUIDLow(), obj->GetGOInfo()->name, obj->GetGUIDLow()); return true; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 5256f4e2303..ebcd7e8a148 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11666" + #define REVISION_NR "11667" #endif // __REVISION_NR_H__