Skip to content

Commit

Permalink
[11667] Implement transport path rotation
Browse files Browse the repository at this point in the history
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 <slifeleaf@gmail.com>
  • Loading branch information
SilverIce committed Jun 24, 2011
1 parent 1928b4f commit 060dfb7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
44 changes: 28 additions & 16 deletions src/game/GameObject.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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()) << ")";
Expand Down Expand Up @@ -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:
Expand All @@ -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;

This comment has been minimized.

Copy link
@NeatElves

NeatElves Jun 24, 2011

1683 m_rotation = QuaternionCompressed(quat).m_raw;
1684 + m_rotation = QuaternionCompressed(quat).m_raw;
?)

This comment has been minimized.

Copy link
@SilverIce

SilverIce Jun 24, 2011

Author

my typo, thanks :)

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
Expand Down
6 changes: 4 additions & 2 deletions src/game/GameObject.h
Expand Up @@ -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
Expand Down Expand Up @@ -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<GameObject> m_gridRef;
};
Expand Down
2 changes: 1 addition & 1 deletion src/game/Level2.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion 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__

1 comment on commit 060dfb7

@PSZ
Copy link
Contributor

@PSZ PSZ commented on 060dfb7 Jun 24, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ай, спасибо :)

Please sign in to comment.