From f663b290c44f9e1b643a6fe01aeb735234267d33 Mon Sep 17 00:00:00 2001 From: Cazomino05 Date: Fri, 13 Jun 2014 00:00:26 +0000 Subject: [PATCH] Added Element.matrix and Element.getMatrix 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" --- .../shared_logic/luadefs/CLuaMatrixDefs.cpp | 7 +- .../mods/deathmatch/logic/lua/CLuaMain.cpp | 6 +- .../logic/lua/oopdefs/CLuaOOPDefs.h | 6 + .../oopdefs/CLuaOOPFunctionDefs.Camera.cpp | 108 +++++++++++++++++- .../oopdefs/CLuaOOPFunctionDefs.Element.cpp | 25 +++- .../logic/luadefs/CLuaMatrixDefs.cpp | 7 +- 6 files changed, 153 insertions(+), 6 deletions(-) diff --git a/MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp b/MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp index 33af7db287..223ecee165 100644 --- a/MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp +++ b/MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp @@ -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; } diff --git a/MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp b/MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp index 6ff4d8f697..b67586eed1 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -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" ); @@ -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 diff --git a/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h b/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h index 110d128603..fac1af6805 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h +++ b/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPDefs.h @@ -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 diff --git a/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Camera.cpp b/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Camera.cpp index ca113dfe5d..ae64baaffa 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Camera.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Camera.cpp @@ -13,6 +13,7 @@ int CLuaOOPDefs::GetCameraMatrix ( lua_State* luaVM ) { + // Needs further attention before adding CPlayer* pPlayer; CScriptArgReader argStream ( luaVM ); @@ -30,4 +31,109 @@ int CLuaOOPDefs::GetCameraMatrix ( lua_State* luaVM ) lua_pushboolean ( luaVM, false ); return 1; -} \ No newline at end of file +} + +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; +} diff --git a/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp b/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp index 2d764c1d6b..830f62f36f 100644 --- a/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp +++ b/MTA10_Server/mods/deathmatch/logic/lua/oopdefs/CLuaOOPFunctionDefs.Element.cpp @@ -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; @@ -52,4 +74,5 @@ int CLuaOOPDefs::GetElementRotation ( lua_State* luaVM ) lua_pushboolean ( luaVM, false ); return 1; -} \ No newline at end of file +} + diff --git a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaMatrixDefs.cpp b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaMatrixDefs.cpp index a2ce445c1a..9f643c907e 100644 --- a/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaMatrixDefs.cpp +++ b/MTA10_Server/mods/deathmatch/logic/luadefs/CLuaMatrixDefs.cpp @@ -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; }