aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/scene/igeneric.cpp
blob: 63bf4bcdfe31cf5ea7649cbb0b9a9184cdcb8240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*This file defines some things that all igui stuff can do*/
extern "C" {
  #include <lua.h>
  #include <lauxlib.h>
  #include <lualib.h>
}
#include <irrlicht.h>
#include "igeneric.hpp"
#include "../gameparts.hpp"
#include <shared/lua_api/common.hpp>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

/***
@classmod iscenenode 
*/

extern IrrlichtDevice* device;



/***
Get the position of a scene element.
@function iscenenode:getpos()
@treturn vector3d position The position this element is at
*/
int iscenegetpos(lua_State* L){//{node=ud_IMeshSceneNode}
	lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
	ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
	vector3df pos = i->getAbsolutePosition();
	lua_pop(L,2);
	pushvector3d(L,pos.X,pos.Y,pos.Z);
	
	return 1;
}

/***
Set the position of a scene element.
@function iscenenode:setpos(vector3d)
@tparam vector3d position The position to set this element to
*/
int iscenesetpos(lua_State* L){//{node=ISceneNode},{x,y,z}
	double x,y,z;
	popvector3d(L,&x,&y,&z);//{node=ud_ISceneNode}
	lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode
	ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	i->setPosition(vector3df(x,y,z));
	i->updateAbsolutePosition();
	lua_pop(L,2);//
	return 0;
}

/***
Set the rotation of a scene element.
@function iscenenode:getang()
@treturn angle3d The angle of this element
*/
int iscenegetangle(lua_State* L){//{node=ud-IMeshSceneNode}
	lua_getfield(L,-1,"node");
	ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);
	irr::core::vector3df ang = i->getRotation();
	pushvector3d(L,ang.X, ang.Y, ang.Z);
	return 1;
}

/***
Set the rotation of a scene element.
@function iscenenode:getang()
@tparam angle3d angle The angle to set this element to
*/
int iscenesetangle(lua_State* L){//{node=ud_ISceneNode},{x,y,z}
	double x,y,z;
	popvector3d(L,&x,&y,&z);
	lua_getfield(L,-1,"node");
	ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);
	irr::core::vector3df ang = irr::core::vector3df(x,y,z);
	i->setRotation(ang);
	return 0;
}

/***
Set the mateiral of a scene element.
@function iscenenode:setmaterial()
@tparam texture texture The texture to apply to this material
*/
//iscenesetmaterialtexture({node=ud_ISceneNode},{texture=ud_itexture},texture_number=0)
int iscenesetmaterial(lua_State *L){
	printf("Calling generic iscenesetmaterial function\n");
	int args = lua_gettop(L);
	u32 layer = 0;
	if(args == 3){
		layer = lua_tonumber(L,-1);
		lua_pop(L,1);
	}
	lua_getfield(L,-1,"texture");
	ITexture *txt = (ITexture*)lua_touserdata(L,-1);//{node=ud_ISceneNode},{texture=ud_itexture},ud_itexture
	lua_pop(L,2);//{node=ud_ISceneNode}
	lua_getfield(L,-1,"node");
	ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	lua_pop(L,2);//

	i->setMaterialTexture(layer,txt);
    
	return 0;
}

/***
Set the name of a scene element.
@function iscenenode:setname()
@tparam string name The name to give this scene element.
*/
//iscenesetname({node=ud_ISceneNode},str_name)
int iscenesetname(lua_State *L){
	const char *name = lua_tostring(L,-1);
	lua_pop(L,1);//{node=ud_ISceneNode}

	lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode
	ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	lua_pop(L,2);

	i->setName((c8*)name);
	return 0;
}

/***
Get the name of this scene element.
@function iscenenode:getname()
@tparam string name The name to give this scene element.
*/
//iscenesetname({node=ud_ISceneNode})
int iscenegetname(lua_State *L){
	lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode
	ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	lua_pop(L,2);

	const char *name = i->getName();

	lua_pushstring(L,name);
	return 1;
}

/***
Set the scale of this scene element.
@function iscenenode:setscale({x,y,z})
@tparam vector3d scale The scale to give this scene element.
*/
//iscenesetscale({x,y,z})
int iscenesetscale(lua_State *L){
	double x,y,z;
	popvector3d(L,&x,&y,&z);

	lua_getfield(L,-1,"node");
	ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	lua_pop(L,2);

	i->setScale(vector3df(x,y,z));
	return 1;
}

/***
Get the scale of this scene element.
@function iscenenode:getscale()
@treturn vector3d The scale scale of this element.
*/
//iscenegetscale()
int iscenegetscale(lua_State *L){
	lua_getfield(L,-1,"node");
	ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	lua_pop(L,2);

	vector3df scale = i->getScale();
	double x,y,z;
	x = scale.X;
	y = scale.Y;
	z = scale.Z;

	pushvector3d(L,x,y,z);
	return 1;
}

/***
Get the scale of this scene element.
@function iscenenode:getscale()
@treturn vector3d The scale scale of this element.
*/
//iscenenode:remove()
int isceneremove(lua_State *L){
	lua_getfield(L,-1,"node");
	ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode
	lua_pop(L,2);
	
	i->remove();

	return 1;
}

extern const luaL_reg igeneric_m[] = {
	{"getpos",        iscenegetpos},
	{"setpos",        iscenesetpos},
	{"getang",        iscenegetangle},
	{"setang",        iscenesetangle},
	{"setmaterialtexture",   iscenesetmaterial},
	{"getname",       iscenegetname},
	{"setname",       iscenesetname},
	{"setscale",      iscenesetscale},
	{"getscale",      iscenegetscale},
	{"remove",        isceneremove},
	{0, 0},
};