Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Client/game_sa/CEntitySA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,28 @@ bool CEntitySA::GetBoneRotation(eBone boneId, float& yaw, float& pitch, float& r
return false;
}

bool CEntitySA::GetBoneRotationQuat(eBone boneId, float& x, float& y, float& z, float& w)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
x = boneOrientation->imag.x;
y = boneOrientation->imag.y;
z = boneOrientation->imag.z;
w = boneOrientation->real;
return true;
}
}
return false;
}

bool CEntitySA::SetBoneRotation(eBone boneId, float yaw, float pitch, float roll)
{
RpClump* clump = GetRpClump();
Expand All @@ -628,6 +650,33 @@ bool CEntitySA::SetBoneRotation(eBone boneId, float yaw, float pitch, float roll
return false;
}

bool CEntitySA::SetBoneRotationQuat(eBone boneId, float x, float y, float z, float w)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
boneOrientation->imag.x = x;
boneOrientation->imag.y = y;
boneOrientation->imag.z = z;
boneOrientation->real = w;
CEntitySAInterface* theInterface = GetInterface();
if (theInterface)
{
theInterface->bDontUpdateHierarchy = false;
}
return true;
}
}
return false;
}

bool CEntitySA::GetBonePosition(eBone boneId, CVector& position)
{
RwMatrix* rwBoneMatrix = GetBoneRwMatrix(boneId);
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CEntitySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ class CEntitySA : public virtual CEntity
bool SetBoneMatrix(eBone boneId, const CMatrix& matrix);

bool GetBoneRotation(eBone boneId, float& yaw, float& pitch, float& roll);
bool GetBoneRotationQuat(eBone boneId, float& x, float& y, float& z, float& w);
bool SetBoneRotation(eBone boneId, float yaw, float pitch, float roll);
bool SetBoneRotationQuat(eBone boneId, float x, float y, float z, float w);
bool GetBonePosition(eBone boneId, CVector& position);
bool SetBonePosition(eBone boneId, const CVector& position);

Expand Down
41 changes: 35 additions & 6 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ void CLuaPedDefs::LoadFunctions()
{"getPedBonePosition", GetPedBonePosition},
{"setElementBonePosition", ArgumentParser<SetElementBonePosition>},
{"setElementBoneRotation", ArgumentParser<SetElementBoneRotation>},
{"setElementBoneQuaternion", ArgumentParser<SetElementBoneQuaternion>},
{"getElementBonePosition", ArgumentParser<GetElementBonePosition>},
{"getElementBoneRotation", ArgumentParser<GetElementBoneRotation>},
{"getElementBoneQuaternion", ArgumentParser<GetElementBoneQuaternion>},
{"setElementBoneMatrix", ArgumentParser<SetElementBoneMatrix>},
{"getElementBoneMatrix", ArgumentParser<GetElementBoneMatrix>},
{"updateElementRpHAnim", ArgumentParser<UpdateElementRpHAnim>},
Expand Down Expand Up @@ -998,19 +1000,31 @@ int CLuaPedDefs::CanPedBeKnockedOffBike(lua_State* luaVM)
return 1;
}

bool CLuaPedDefs::SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId, CVector position)
bool CLuaPedDefs::SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CVector position)
{
CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBonePosition(static_cast<eBone>(boneId), position) : false;
}

bool CLuaPedDefs::SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId, float yaw, float pitch, float roll)
bool CLuaPedDefs::SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float yaw, float pitch, float roll)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");

CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBoneRotation(static_cast<eBone>(boneId), yaw, pitch, roll) : false;
}

std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId)
bool CLuaPedDefs::SetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float x, float y, float z, float w)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");

CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBoneRotationQuat(static_cast<eBone>(boneId), x, y, z, w) : false;
}

std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
{
CEntity* theEntity = entity->GetGameEntity();
CVector position;
Expand All @@ -1019,22 +1033,37 @@ std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElement
return false;
}

std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId)
std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");

float yaw = 0.0f, pitch = 0.0f, roll = 0.0f;
CEntity* theEntity = entity->GetGameEntity();
if (theEntity && theEntity->GetBoneRotation(static_cast<eBone>(boneId), yaw, pitch, roll))
return std::make_tuple(yaw, pitch, roll);
return false;
}

bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId, CMatrix boneMatrix)
std::variant<bool, CLuaMultiReturn<float, float, float, float>> CLuaPedDefs::GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");

float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
CEntity* theEntity = entity->GetGameEntity();
if (theEntity && theEntity->GetBoneRotationQuat(static_cast<eBone>(boneId), x, y, z, w))
return std::make_tuple(x, y, z, w);
return false;
}

bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix)
{
CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBoneMatrix(static_cast<eBone>(boneId), boneMatrix) : false;
}

std::variant<bool, std::array<std::array<float, 4>, 4>> CLuaPedDefs::GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId)
std::variant<bool, std::array<std::array<float, 4>, 4>> CLuaPedDefs::GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
{
CEntity* theEntity = entity->GetGameEntity();
if (theEntity)
Expand Down
14 changes: 8 additions & 6 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ class CLuaPedDefs : public CLuaDefs
LUA_DECLARE(GetPedContactElement);
LUA_DECLARE(GetPedRotation);
LUA_DECLARE(CanPedBeKnockedOffBike);
static bool SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId, CVector position);
static bool SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId, float yaw, float pitch, float roll);
static std::variant<bool, CLuaMultiReturn<float, float, float>> GetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId);
static bool SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CVector position);
static bool SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float yaw, float pitch, float roll);
static bool SetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float x, float y, float z, float w);
static std::variant<bool, CLuaMultiReturn<float, float, float>> GetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId);

static std::variant<bool, CLuaMultiReturn<float, float, float>> GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId);
static std::variant<bool, CLuaMultiReturn<float, float, float>> GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId);
static std::variant<bool, CLuaMultiReturn<float, float, float, float>> GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId);

static bool SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId, CMatrix boneMatrix);
static bool SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix);

static std::variant<bool, std::array<std::array<float, 4>, 4>> GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::int32_t boneId);
static std::variant<bool, std::array<std::array<float, 4>, 4>> GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId);

static bool UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity);
LUA_DECLARE_OOP(GetPedBonePosition);
Expand Down
2 changes: 2 additions & 0 deletions Client/sdk/game/CEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ class CEntity
virtual bool SetBoneMatrix(eBone boneId, const CMatrix& matrix) = 0;

virtual bool GetBoneRotation(eBone boneId, float& yaw, float& pitch, float& roll) = 0;
virtual bool GetBoneRotationQuat(eBone boneId, float& x, float& y, float& z, float& w) = 0;
virtual bool SetBoneRotation(eBone boneId, float yaw, float pitch, float roll) = 0;
virtual bool SetBoneRotationQuat(eBone boneId, float x, float y, float z, float w) = 0;
virtual bool GetBonePosition(eBone boneId, CVector& position) = 0;
virtual bool SetBonePosition(eBone boneId, const CVector& position) = 0;
};