aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/scene/igeneric.cpp
blob: 03836190a0dd3ffef5998a7e2d04bfa6c3761870 (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
/*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;

extern IrrlichtDevice* device;

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;
}

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;
}

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;
}

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;
}

//iscenesetmaterial(ud_ISceneNode,ud_itexture)
int iscenesetmaterial(lua_State* L){
	printf("Calling generic iscenesetmaterial function\n");
	ITexture* txt = (ITexture*)lua_touserdata(L,-1);//ud_ISceneNode,ud_itexture
	lua_pop(L,1);//ud_ISceneNode
	ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//ud_ISceneNode
	lua_pop(L,2);//

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