-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionsluadraw.cpp
More file actions
168 lines (144 loc) · 5.27 KB
/
Copy pathfunctionsluadraw.cpp
File metadata and controls
168 lines (144 loc) · 5.27 KB
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
#include "functionsluadraw.h"
#include <string>
#include "raylib.h"
#include "raymath.h"
#include "rlgl.h"
#include <unordered_map>
#ifdef _WIN32
#include <lua.hpp>
#else
#include <luajit-2.1/lua.hpp>
#endif
#include "entitymanager.h"
#include "assetmanager.h"
#include "modelsdrawcalls.h"
extern lua_State* L;
extern Camera camera;
extern std::unordered_map<Model*,RenderBatch> batches;
void DrawBillboardNum(Camera cam, Texture2D texture, int index, int total_frames, Vector3 position,Vector2 _size,Vector2 origin,float rotation, Color tint){
float frame_width = (float)texture.width / total_frames;
index = index % total_frames;
Rectangle rect;
rect.x = frame_width * index;
rect.y = 0;
rect.width = frame_width;
rect.height = texture.height;
DrawBillboardPro(cam,texture,rect,position,{0,1,0},_size,origin,rotation,tint);
}
void DrawTextBetter(const char *text,Font font, Vector2 position, float fontsize,float spacing,Color color,float valign,float halign){
Vector2 t_size = MeasureTextEx(font,text,fontsize,spacing);
Vector2 t_origin = {0, 0};
if(valign == 0.0f) t_origin.y = -t_size.y;
else if(valign == 0.5f) t_origin.y = -t_size.y / 2;
else if(valign == 1.0f) t_origin.y = 0;
else t_origin.y = t_size.y / 2;
if(halign == 0.0f) t_origin.x = 0;
else if(halign == 0.5f) t_origin.x = -t_size.x / 2;
else if(halign == 1.0f) t_origin.x = -t_size.x;
else t_origin.x = t_size.x / 2;
Vector2 newpos = Vector2Add(position,t_origin);
DrawTextEx(font,text,newpos,fontsize,spacing,color);
}
int l_drawGrid(lua_State* L){
int a = lua_tointeger(L,1);
float b = lua_tonumber(L,2);
DrawGrid(a,b);
return 0;
}
int l_drawModel(lua_State* L){
std::string mdl = std::string(lua_tostring(L,1));
float x = lua_tonumber(L,2);
float y = lua_tonumber(L,3);
float z = lua_tonumber(L,4);
float rx = lua_tonumber(L,5);
float ry = lua_tonumber(L,6);
float rz = lua_tonumber(L,7);
float sx = lua_tonumber(L,8);
float sy = lua_tonumber(L,9);
float sz = lua_tonumber(L,10);
Model* model = &get_model(mdl);
Matrix matScale = MatrixScale(sx,sy,sz);
Matrix matRotX = MatrixRotateX(DEG2RAD * rx);
Matrix matRotY = MatrixRotateY(DEG2RAD * ry);
Matrix matRotZ = MatrixRotateZ(DEG2RAD * rz);
Matrix matTrans = MatrixTranslate(x,y,z);
Matrix _transform = MatrixMultiply(MatrixMultiply(MatrixMultiply(matScale, matRotX),MatrixMultiply(matRotY, matRotZ)),matTrans);
batches[model].model = model;
batches[model].transforms.push_back(_transform);
return 0;
}
int l_drawBillboard(lua_State* L){
std::string tex = std::string(lua_tostring(L,1));
float x = lua_tonumber(L,2);
float y = lua_tonumber(L,3);
float z = lua_tonumber(L,4);
float s = lua_tonumber(L,5);
Texture t_tex = get_texture(tex);
DrawBillboard(camera,t_tex,{x,y,z},s,WHITE);
return 0;
}
int l_drawBillboardAnimated(lua_State* L){
std::string tex = std::string(lua_tostring(L,1));
float x = lua_tonumber(L,2);
float y = lua_tonumber(L,3);
float z = lua_tonumber(L,4);
float xs = lua_tonumber(L,5);
float ys = lua_tonumber(L,6);
float xp = lua_tonumber(L,7);
float yp = lua_tonumber(L,8);
int tf = lua_tointeger(L,9);
int af = lua_tointeger(L,10);
Texture t_tex = get_texture(tex);
//DrawBillboardPro(camera,t_tex,rect,{x,y,z},{0,1,0},{1,1},{0.5,0.5},0,WHITE);
DrawBillboardNum(camera,t_tex,af,tf,{x,y,z},{xs,ys},{xs*xp,ys*yp},0,WHITE);
return 0;
}
int l_drawText(lua_State* L){
std::string txt = std::string(lua_tostring(L,1));
std::string fnt = std::string(lua_tostring(L,2));
float x = lua_tonumber(L,3);
float y = lua_tonumber(L,4);
float s = lua_tonumber(L,5);
float spacing = lua_tonumber(L,6);
Color color = GetColor((unsigned int)lua_tointeger(L,7));
float val = lua_tonumber(L,8);
float hal = lua_tonumber(L,9);
DrawTextBetter(txt.c_str(),get_font(fnt),{x,y},s,spacing,color,val,hal);
return 0;
}
int l_drawSprite(lua_State* L){
std::string tex = std::string(lua_tostring(L,1));
float x = lua_tonumber(L,2);
float y = lua_tonumber(L,3);
float r = lua_tonumber(L,4);
float s = lua_tonumber(L,5);
DrawTextureEx(get_texture(tex),{x,y},r,s,WHITE);
return 0;
}
int l_drawSpriteAnimated(lua_State* L){
std::string tex = std::string(lua_tostring(L,1));
float x = lua_tonumber(L,2);
float y = lua_tonumber(L,3);
float r = lua_tonumber(L,4);
float s = lua_tonumber(L,5);
float tf = lua_tointeger(L,6);
float af = lua_tointeger(L,7);
Texture t_tex = get_texture(tex);
float frame_width = (float)t_tex.width / tf;
Rectangle rect;
rect.x = frame_width * af;
rect.y = 0;
rect.width = frame_width;
rect.height = t_tex.height;
DrawTextureRec(t_tex,rect,(Vector2){x,y},WHITE);
return 0;
}
void ExposeDrawFunctions(){
lua_register(L,"draw_grid",l_drawGrid);
lua_register(L,"draw_model",l_drawModel);
lua_register(L,"draw_billboard",l_drawBillboard);
lua_register(L,"draw_billboard_animated",l_drawBillboardAnimated);
lua_register(L,"draw_text",l_drawText);
lua_register(L,"draw_sprite",l_drawSprite);
lua_register(L,"draw_sprite_animated",l_drawSpriteAnimated);
}