Skip to content

Commit

Permalink
Added Element.matrix and Element.getMatrix
Browse files Browse the repository at this point in the history
Started Camera Matrix/Position functions but it appears data is missing from the server.

Matrix.ToString now returns a string representing the matrix rather than just "Matrix"
  • Loading branch information
Cazomino05 committed Jun 13, 2014
1 parent 2f8f823 commit f663b29
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 6 deletions.
7 changes: 6 additions & 1 deletion MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp
Expand Up @@ -51,7 +51,12 @@ int CLuaMatrixDefs::ToString ( lua_State* luaVM )

if ( !argStream.HasErrors () )
{
SString string = "matrix";
SString string = SString ( "Matrix: { %.3f, %.3f, %.3f } { %.3f, %.3f, %.3f } { %.3f, %.3f, %.3f } { %.3f, %.3f, %.3f }",
pMatrix->vRight.fX, pMatrix->vRight.fY, pMatrix->vRight.fZ,
pMatrix->vFront.fX, pMatrix->vFront.fY, pMatrix->vFront.fZ,
pMatrix->vUp.fX, pMatrix->vUp.fY, pMatrix->vUp.fZ,
pMatrix->vPos.fX, pMatrix->vPos.fY, pMatrix->vPos.fZ );

lua_pushstring ( luaVM, string.c_str () );
return 1;
}
Expand Down
6 changes: 4 additions & 2 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp
Expand Up @@ -381,7 +381,8 @@ void CLuaMain::AddElementClass ( lua_State* luaVM )
lua_classfunction ( luaVM, "getColShape", "getElementColShape" );
lua_classfunction ( luaVM, "getData", "getElementData" );
lua_classfunction ( luaVM, "getPosition", "getElementPosition", CLuaOOPDefs::GetElementPosition );
lua_classfunction ( luaVM, "getRotation", "getElementRotation", CLuaOOPDefs::GetElementRotation );
lua_classfunction ( luaVM, "getRotation", "getElementRotation", CLuaOOPDefs::GetElementRotation );
lua_classfunction ( luaVM, "getMatrix", "getElementMatrix", CLuaOOPDefs::GetElementMatrix );
lua_classfunction ( luaVM, "getPosition", "getElementPosition" );
lua_classfunction ( luaVM, "getRotation", "getElementRotation" );
lua_classfunction ( luaVM, "getType", "getElementType" );
Expand Down Expand Up @@ -420,7 +421,8 @@ void CLuaMain::AddElementClass ( lua_State* luaVM )
lua_classvariable ( luaVM, "colShape", NULL, "getElementColShape" );
lua_classvariable ( luaVM, "collisions", "setElementCollisionsEnabled", "getElementCollisionsEnabled" );
lua_classvariable ( luaVM, "position", "setElementPosition", "getElementPosition", CLuaElementDefs::setElementPosition, CLuaOOPDefs::GetElementPosition );
lua_classvariable ( luaVM, "rotation", "setElementRotation", "getElementRotation", CLuaElementDefs::setElementRotation, CLuaOOPDefs::GetElementRotation );
lua_classvariable ( luaVM, "rotation", "setElementRotation", "getElementRotation", CLuaElementDefs::setElementRotation, CLuaOOPDefs::GetElementRotation );
lua_classvariable ( luaVM, "matrix", "", "getElementMatrix", NULL, CLuaOOPDefs::GetElementMatrix );
lua_classvariable ( luaVM, "velocity", "setElementVelocity", "getElementVelocity" ); // TODO return Vector3
//lua_classvariable ( luaVM, "data", "setElementData", "getElementData", CLuaOOPDefs::SetElementData, CLuaOOPDefs::GetElementData );
//lua_classvariable ( luaVM, "visibility", "setElementVisibleTo", "isElementVisibleTo", CLuaOOPDefs::SetElementVisibleTo, CLuaOOPDefs::IsElementVisibleTo ); // .visibility[john]=false
Expand Down
6 changes: 6 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h
Expand Up @@ -26,10 +26,16 @@ class CLuaOOPDefs : public CLuaDefs
public:
LUA_DECLARE ( SetPedOccupiedVehicle );

LUA_DECLARE ( GetElementMatrix );
LUA_DECLARE ( GetElementPosition );
LUA_DECLARE ( GetElementRotation );

LUA_DECLARE ( GetCameraMatrix );

LUA_DECLARE ( GetCameraPosition );
LUA_DECLARE ( SetCameraPosition );
LUA_DECLARE ( GetCameraRotation );
LUA_DECLARE ( SetCameraRotation );
};

#endif
Expand Up @@ -13,6 +13,7 @@

int CLuaOOPDefs::GetCameraMatrix ( lua_State* luaVM )
{
// Needs further attention before adding
CPlayer* pPlayer;

CScriptArgReader argStream ( luaVM );
Expand All @@ -30,4 +31,109 @@ int CLuaOOPDefs::GetCameraMatrix ( lua_State* luaVM )

lua_pushboolean ( luaVM, false );
return 1;
}
}

int CLuaOOPDefs::GetCameraPosition(lua_State* luaVM)
{
CPlayer* pPlayer;

CScriptArgReader argStream ( luaVM );

argStream.ReadUserData ( pPlayer );

if ( !argStream.HasErrors ( ) )
{
CVector vecPosition;
CPlayerCamera * pCamera = pPlayer->GetCamera ( );
if ( pCamera )
{
pCamera->GetPosition ( vecPosition );
lua_pushvector ( luaVM, vecPosition );
return 1;
}
}

lua_pushboolean ( luaVM, false );
return 1;
}

int CLuaOOPDefs::SetCameraPosition ( lua_State* luaVM )
{
// Needs further attention before adding
CPlayer* pPlayer;
CVector vecPosition;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pPlayer );
argStream.ReadVector3D ( vecPosition );

if ( !argStream.HasErrors ( ) )
{
CPlayerCamera * pCamera = pPlayer->GetCamera ( );
if ( pCamera )
{
/*if (!pCamera->IsInFixedMode())
{
pCamera->ToggleCameraFixedMode(true);
}*/

pCamera->SetPosition ( vecPosition );

lua_pushboolean ( luaVM, true );
return 1;
}
}
lua_pushboolean ( luaVM, false );
return 1;
}

int CLuaOOPDefs::GetCameraRotation(lua_State* luaVM)
{
// Needs further attention before adding
CPlayer* pPlayer;
CVector vecRotation;
CScriptArgReader argStream ( luaVM );

argStream.ReadUserData ( pPlayer );

if ( !argStream.HasErrors ( ) )
{

CPlayerCamera * pCamera = pPlayer->GetCamera ( );
if ( pCamera )
{
// TODO
}
lua_pushvector ( luaVM, vecRotation );
return 1;
}
}

int CLuaOOPDefs::SetCameraRotation(lua_State* luaVM)
{
// Needs further attention before adding
CPlayer* pPlayer;
CVector vecRotation;
CScriptArgReader argStream ( luaVM );

argStream.ReadUserData ( pPlayer );

argStream.ReadVector3D ( vecRotation );

if (!argStream.HasErrors())
{

CPlayerCamera * pCamera = pPlayer->GetCamera ( );
/*if (!pCamera->IsInFixedMode())
{
pCamera->ToggleCameraFixedMode(true);
}*/

// Needs to be in degrees
pCamera->SetRotation(vecRotation);

lua_pushboolean(luaVM, true);
return 1;
}
lua_pushboolean(luaVM, false);
return 1;
}
Expand Up @@ -11,6 +11,28 @@

#include "StdInc.h"

int CLuaOOPDefs::GetElementMatrix(lua_State* luaVM)
{
CElement* pEntity = NULL;

CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pEntity );

if ( !argStream.HasErrors ( ) )
{
CMatrix matrix;
pEntity->GetMatrix ( matrix );

lua_pushmatrix ( luaVM, matrix );
return 1;
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage ( ) );

lua_pushboolean ( luaVM, false );
return 1;
}

int CLuaOOPDefs::GetElementPosition ( lua_State* luaVM )
{
CElement* pElement = NULL;
Expand Down Expand Up @@ -52,4 +74,5 @@ int CLuaOOPDefs::GetElementRotation ( lua_State* luaVM )

lua_pushboolean ( luaVM, false );
return 1;
}
}

Expand Up @@ -51,7 +51,12 @@ int CLuaMatrixDefs::ToString ( lua_State* luaVM )

if ( !argStream.HasErrors () )
{
SString string = "matrix";
SString string = SString ( "Matrix: { %.3f, %.3f, %.3f } { %.3f, %.3f, %.3f } { %.3f, %.3f, %.3f } { %.3f, %.3f, %.3f }",
pMatrix->vRight.fX, pMatrix->vRight.fY, pMatrix->vRight.fZ,
pMatrix->vFront.fX, pMatrix->vFront.fY, pMatrix->vFront.fZ,
pMatrix->vUp.fX, pMatrix->vUp.fY, pMatrix->vUp.fZ,
pMatrix->vPos.fX, pMatrix->vPos.fY, pMatrix->vPos.fZ );

lua_pushstring ( luaVM, string.c_str () );
return 1;
}
Expand Down

0 comments on commit f663b29

Please sign in to comment.