Skip to content

Commit 6767b2d

Browse files
committed
Matrix4, Matrix3 and Matrix2 defs
1 parent 25b1cb7 commit 6767b2d

25 files changed

+976
-78
lines changed

roc_app/roc_app.vcxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
<Link>
8181
<SubSystem>Console</SubSystem>
8282
<GenerateDebugInformation>true</GenerateDebugInformation>
83-
<AdditionalDependencies>glew32.lib;opengl32.lib;sfml-2-d.lib;BulletDynamics_Debug.lib;BulletCollision_Debug.lib;LinearMath_Debug.lib;freetype.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
84-
<AdditionalLibraryDirectories>../vendor/SFML/lib/win64;../vendor/bullet/lib/win64;../vendor/freetype2/lib/win64;../vendor/glew/lib/win64;../vendor/zlib/lib/win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
83+
<AdditionalDependencies>glew32.lib;opengl32.lib;sfml-main-d.lib;sfml-system-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;BulletDynamics_Debug.lib;BulletCollision_Debug.lib;LinearMath_Debug.lib;freetype.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
84+
<AdditionalLibraryDirectories>../vendor/SFML/lib;../vendor/bullet/lib/win64;../vendor/freetype2/lib/win64;../vendor/glew/lib/win64;../vendor/zlib/lib/win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
8585
<EnableUAC>false</EnableUAC>
8686
<Profile>false</Profile>
8787
</Link>
@@ -115,8 +115,8 @@
115115
<GenerateDebugInformation>false</GenerateDebugInformation>
116116
<EnableCOMDATFolding>true</EnableCOMDATFolding>
117117
<OptimizeReferences>true</OptimizeReferences>
118-
<AdditionalLibraryDirectories>../vendor/SFML/lib/win64;../vendor/bullet/lib/win64;../vendor/freetype2/lib/win64;../vendor/glew/lib/win64;../vendor/zlib/lib/win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
119-
<AdditionalDependencies>glew32.lib;opengl32.lib;BulletDynamics.lib;BulletCollision.lib;LinearMath.lib;freetype.lib;sfml-2.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
118+
<AdditionalLibraryDirectories>../vendor/SFML/lib;../vendor/bullet/lib/win64;../vendor/freetype2/lib/win64;../vendor/glew/lib/win64;../vendor/zlib/lib/win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
119+
<AdditionalDependencies>glew32.lib;opengl32.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;sfml-audio.lib;BulletDynamics.lib;BulletCollision.lib;LinearMath.lib;freetype.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
120120
<EnableUAC>false</EnableUAC>
121121
<Profile>false</Profile>
122122
</Link>

roc_app/stdafx.h

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#pragma warning (disable : 4250)
32

43
#define WIN32_LEAN_AND_MEAN
54
#include <Windows.h>
@@ -39,7 +38,3 @@
3938
#include "MaxRectsBinPack.h"
4039
#include "pugixml.hpp"
4140
#include "zlib.h"
42-
43-
#ifdef _DEBUG
44-
#define DEBUG_PRINT(T) std::cout << T << std::endl
45-
#endif

roc_module_lua/Lua/LuaDefs/CameraDefs.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
extern const std::string g_vec2Name;
1212
extern const std::string g_vec3Name;
1313
extern const std::string g_vec4Name;
14-
extern const std::string g_matrixName;
14+
extern const std::string g_matrix4Name;
1515
extern const std::string g_cameraName("Camera");
1616
const std::string g_cameraInvalid("Invalid object/Camera");
1717

@@ -370,7 +370,7 @@ int CameraDefs::GetViewMatrix(lua_State *p_state)
370370
{
371371
ROC::ICamera *l_camera;
372372
if(Utils::IsValid(l_obj) && (l_camera = Utils::Cast<ROC::ICamera*>(l_obj)))
373-
l_argReader.PushObject(new glm::mat4(l_camera->GetViewMatrix()), g_matrixName, false);
373+
l_argReader.PushObject(new glm::mat4(l_camera->GetViewMatrix()), g_matrix4Name, false);
374374
else
375375
{
376376
l_argReader.SetError(g_cameraInvalid);
@@ -393,7 +393,7 @@ int CameraDefs::GetProjectionMatrix(lua_State *p_state)
393393
{
394394
ROC::ICamera *l_camera;
395395
if(Utils::IsValid(l_obj) && (l_camera = Utils::Cast<ROC::ICamera*>(l_obj)))
396-
l_argReader.PushObject(new glm::mat4(l_camera->GetProjectionMatrix()), g_matrixName, false);
396+
l_argReader.PushObject(new glm::mat4(l_camera->GetProjectionMatrix()), g_matrix4Name, false);
397397
else
398398
{
399399
l_argReader.SetError(g_cameraInvalid);
@@ -416,7 +416,7 @@ int CameraDefs::GetViewProjectionMatrix(lua_State *p_state)
416416
{
417417
ROC::ICamera *l_camera;
418418
if(Utils::IsValid(l_obj) && (l_camera = Utils::Cast<ROC::ICamera*>(l_obj)))
419-
l_argReader.PushObject(new glm::mat4(l_camera->GetViewProjectionMatrix()), g_matrixName, false);
419+
l_argReader.PushObject(new glm::mat4(l_camera->GetViewProjectionMatrix()), g_matrix4Name, false);
420420
else
421421
{
422422
l_argReader.SetError(g_cameraInvalid);
+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#include "stdafx.h"
2+
#include "Lua/LuaDefs/Matrix2Defs.h"
3+
#include "Lua/LuaDefs.h"
4+
#include "Lua/LuaVM.h"
5+
#include "Lua/LuaArgReader.h"
6+
#include "Utils.h"
7+
8+
extern const std::string g_matrix2Name("Matrix2");
9+
10+
std::vector<LuaPropDef> Matrix2Defs::ms_staticProps;
11+
std::vector<LuaMethodDef> Matrix2Defs::ms_staticMethods;
12+
std::vector<LuaMethodDef> Matrix2Defs::ms_metaMethods;
13+
std::vector<LuaPropDef> Matrix2Defs::ms_instanceProps;
14+
std::vector<LuaMethodDef> Matrix2Defs::ms_instanceMethods;
15+
16+
void Matrix2Defs::Init()
17+
{
18+
ms_staticProps.emplace_back("identity", GetIdentity, nullptr);
19+
ms_staticProps.emplace_back("zero", GetZero, nullptr);
20+
21+
ms_metaMethods.emplace_back("__add", Add);
22+
ms_metaMethods.emplace_back("__sub", Subtract);
23+
ms_metaMethods.emplace_back("__div", Divide);
24+
ms_metaMethods.emplace_back("__mul", Multiply);
25+
ms_metaMethods.emplace_back("__len", GetDeterminant);
26+
27+
ms_instanceProps.emplace_back("inverse", GetInverse, nullptr);
28+
}
29+
30+
void Matrix2Defs::RegisterInVM(LuaVM *p_vm)
31+
{
32+
p_vm->RegisterLuaClass(g_matrix2Name, Create, &ms_staticProps, &ms_staticMethods, &ms_metaMethods, &ms_instanceProps, &ms_instanceMethods);
33+
p_vm->RegisterFunction("isMatrix2", IsMatrix2);
34+
}
35+
36+
int Matrix2Defs::Create(lua_State *p_state)
37+
{
38+
LuaArgReader l_argReader(p_state);
39+
float l_val[4] = { 0.f };
40+
l_argReader.Skip();
41+
for(size_t i = 0U; i < 9U; i++)
42+
l_argReader.ReadNextNumber(l_val[i]);
43+
l_argReader.PushObject(
44+
new glm::mat2(
45+
l_val[0], l_val[1],
46+
l_val[2], l_val[3]
47+
), g_matrix2Name, false
48+
);
49+
return l_argReader.GetReturnValue();
50+
}
51+
52+
int Matrix2Defs::GetIdentity(lua_State *p_state)
53+
{
54+
LuaArgReader l_argReader(p_state);
55+
l_argReader.PushObject(new glm::mat2(1.f), g_matrix2Name, false);
56+
return 1;
57+
}
58+
int Matrix2Defs::GetZero(lua_State *p_state)
59+
{
60+
LuaArgReader l_argReader(p_state);
61+
l_argReader.PushObject(new glm::mat2(0.f), g_matrix2Name, false);
62+
return 1;
63+
}
64+
65+
int Matrix2Defs::Add(lua_State *p_state)
66+
{
67+
LuaArgReader l_argReader(p_state);
68+
glm::mat2 *l_matA = nullptr;
69+
glm::mat2 *l_matB = nullptr;
70+
l_argReader.ReadObject(l_matA, g_matrix2Name);
71+
l_argReader.ReadObject(l_matB, g_matrix2Name);
72+
if(!l_argReader.HasError())
73+
l_argReader.PushObject(new glm::mat2(*l_matA + *l_matB), g_matrix2Name, false);
74+
else
75+
l_argReader.PushBoolean(false);
76+
77+
l_argReader.LogError();
78+
return 1;
79+
}
80+
int Matrix2Defs::Subtract(lua_State *p_state)
81+
{
82+
LuaArgReader l_argReader(p_state);
83+
glm::mat2 *l_matA = nullptr;
84+
glm::mat2 *l_matB = nullptr;
85+
l_argReader.ReadObject(l_matA, g_matrix2Name);
86+
l_argReader.ReadObject(l_matB, g_matrix2Name);
87+
if(!l_argReader.HasError())
88+
l_argReader.PushObject(new glm::mat2(*l_matA - *l_matB), g_matrix2Name, false);
89+
else
90+
l_argReader.PushBoolean(false);
91+
92+
l_argReader.LogError();
93+
return 1;
94+
}
95+
int Matrix2Defs::Divide(lua_State *p_state)
96+
{
97+
LuaArgReader l_argReader(p_state);
98+
glm::mat2 *l_matA = nullptr;
99+
float l_val;
100+
l_argReader.ReadObject(l_matA, g_matrix2Name);
101+
l_argReader.ReadNumber(l_val);
102+
if(!l_argReader.HasError())
103+
l_argReader.PushObject(new glm::mat2(*l_matA / l_val), g_matrix2Name, false);
104+
else
105+
l_argReader.PushBoolean(false);
106+
107+
l_argReader.LogError();
108+
return 1;
109+
}
110+
int Matrix2Defs::Multiply(lua_State *p_state)
111+
{
112+
LuaArgReader l_argReader(p_state);
113+
114+
if(l_argReader.IsNextNumber()) // Number * Matrix
115+
{
116+
float l_val;
117+
glm::mat2 *l_mat;
118+
l_argReader.ReadNumber(l_val);
119+
l_argReader.ReadObject(l_mat, g_matrix2Name);
120+
if(!l_argReader.HasError())
121+
l_argReader.PushObject(new glm::mat2(*l_mat * l_val), g_matrix2Name, false);
122+
else
123+
l_argReader.PushBoolean(false);
124+
}
125+
else
126+
{
127+
// Matrix * <something>
128+
glm::mat2 *l_mat;
129+
l_argReader.ReadObject(l_mat, g_matrix2Name);
130+
if(l_argReader.IsNextNumber()) // Matrix * number
131+
{
132+
float l_val;
133+
l_argReader.ReadNumber(l_val);
134+
if(!l_argReader.HasError())
135+
l_argReader.PushObject(new glm::mat2(*l_mat * l_val), g_matrix2Name, false);
136+
else
137+
l_argReader.PushBoolean(false);
138+
}
139+
else
140+
{
141+
// Matrix * Matrix
142+
glm::mat2 *l_matB = nullptr;
143+
l_argReader.ReadObject(l_matB, g_matrix2Name);
144+
if(!l_argReader.HasError())
145+
l_argReader.PushObject(new glm::mat2(*l_mat * *l_matB), g_matrix2Name, false);
146+
else
147+
l_argReader.PushBoolean(false);
148+
}
149+
}
150+
151+
l_argReader.LogError();
152+
return 1;
153+
}
154+
155+
int Matrix2Defs::GetDeterminant(lua_State *p_state)
156+
{
157+
LuaArgReader l_argReader(p_state);
158+
glm::mat2 *l_mat = nullptr;
159+
l_argReader.ReadObject(l_mat, g_matrix2Name);
160+
if(!l_argReader.HasError())
161+
l_argReader.PushNumber(glm::determinant(*l_mat));
162+
else
163+
l_argReader.PushBoolean(false);
164+
165+
l_argReader.LogError();
166+
return 1;
167+
}
168+
169+
int Matrix2Defs::GetInverse(lua_State *p_state)
170+
{
171+
LuaArgReader l_argReader(p_state);
172+
glm::mat2 *l_mat = nullptr;
173+
l_argReader.ReadObject(l_mat, g_matrix2Name);
174+
if(!l_argReader.HasError())
175+
l_argReader.PushObject(new glm::mat2(glm::inverse(*l_mat)), g_matrix2Name, false);
176+
else
177+
l_argReader.PushBoolean(false);
178+
179+
l_argReader.LogError();
180+
return 1;
181+
}
182+
183+
int Matrix2Defs::IsMatrix2(lua_State *p_state)
184+
{
185+
LuaArgReader l_argReader(p_state);
186+
glm::mat2 *l_mat = nullptr;
187+
l_argReader.ReadNextObject(l_mat, g_matrix2Name);
188+
l_argReader.PushBoolean(l_mat != nullptr);
189+
return l_argReader.GetReturnValue();
190+
}

roc_module_lua/Lua/LuaDefs/MatrixDefs.h renamed to roc_module_lua/Lua/LuaDefs/Matrix2Defs.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ struct LuaPropDef;
44
struct LuaMethodDef;
55
class LuaVM;
66

7-
class MatrixDefs final
7+
class Matrix2Defs final
88
{
99
static std::vector<LuaPropDef> ms_staticProps;
1010
static std::vector<LuaMethodDef> ms_staticMethods;
1111
static std::vector<LuaMethodDef> ms_metaMethods;
1212
static std::vector<LuaPropDef> ms_instanceProps;
1313
static std::vector<LuaMethodDef> ms_instanceMethods;
1414

15-
MatrixDefs() = delete;
16-
~MatrixDefs() = delete;
15+
Matrix2Defs() = delete;
16+
~Matrix2Defs() = delete;
1717

1818
static int Create(lua_State *p_state);
1919
static int GetZero(lua_State *p_state);
@@ -24,7 +24,7 @@ class MatrixDefs final
2424
static int Multiply(lua_State *p_state);
2525
static int GetDeterminant(lua_State *p_state);
2626
static int GetInverse(lua_State *p_state);
27-
static int IsMatrix(lua_State *p_state);
27+
static int IsMatrix2(lua_State *p_state);
2828
public:
2929
static void Init();
3030
static void RegisterInVM(LuaVM *p_vm);

0 commit comments

Comments
 (0)