Add function: engine_position_2d_to_tex
This commit is contained in:
parent
161bf5366c
commit
fcdc55f3b2
@ -73,3 +73,16 @@ void engine_rendertarget_draw_file(char * fpath) {
|
||||
y += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void engine_position_2d_to_tex(struct ENGINE_VECTOR_TEX * pos, float x, float y, int width, int height, char clamp) {
|
||||
width = width - 1;
|
||||
height = height - 1;
|
||||
pos->x = round(((float)width*0.5) + (((float)width*x) * 0.5));
|
||||
pos->y = round(((float)height*0.5) + (((float)height*y) * 0.5));
|
||||
if (clamp == 1) {
|
||||
if (pos->x < 0) { pos->x = 0; }
|
||||
if (pos->x > width) { pos->x = width; }
|
||||
if (pos->y < 0) { pos->y = 0; }
|
||||
if (pos->y > height) { pos->y = height; }
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,19 @@ int engine_luaf_3d_project(lua_State *L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
int engine_luaf_position_2d_to_tex(lua_State *L) {
|
||||
float x = luaL_checknumber(L,1);
|
||||
float y = luaL_checknumber(L,2);
|
||||
int width = luaL_checknumber(L,3);
|
||||
int height = luaL_checknumber(L,4);
|
||||
int clamp = luaL_checknumber(L,5);
|
||||
struct ENGINE_VECTOR_TEX pos;
|
||||
engine_position_2d_to_tex(&pos,x,y,width,height,clamp);
|
||||
lua_pushnumber(L,pos.x);
|
||||
lua_pushnumber(L,pos.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void engine_lua_init_manual() {
|
||||
lua_pushcfunction(engine_lua_state,engine_luaf_lua_event_get_data);
|
||||
lua_setglobal (engine_lua_state,"engine_lua_event_get_data");
|
||||
@ -93,4 +106,6 @@ void engine_lua_init_manual() {
|
||||
lua_setglobal (engine_lua_state,"engine_3d_rotate_position");
|
||||
lua_pushcfunction(engine_lua_state,engine_luaf_3d_project);
|
||||
lua_setglobal (engine_lua_state,"engine_3d_project");
|
||||
lua_pushcfunction(engine_lua_state,engine_luaf_position_2d_to_tex);
|
||||
lua_setglobal (engine_lua_state,"engine_position_2d_to_tex");
|
||||
}
|
||||
|
@ -89,6 +89,14 @@ arguments = ["char *"]
|
||||
argNames = ["fpath"]
|
||||
description = "Draw a file into the target."
|
||||
|
||||
# POSITION
|
||||
[engine_position_2d_to_tex]
|
||||
type = "void"
|
||||
arguments = ["struct ENGINE_VECTOR_TEXTURE *","float","float","int", "int", "char"]
|
||||
argNames = ["pos", "x", "y", "width","height","clamp"]
|
||||
description = "Convert 2D coordinates (range -1 = top/left, 1 = bottom/right) to ENGINE_VECTOR_TEXTURE. If clamp is set to 1, coordinates may not be less than 0, or more than width-1/height-1. Output is put into pos pointer. Pointer not required in Lua."
|
||||
lua = "manual"
|
||||
|
||||
# TIME
|
||||
[engine_time_sleep]
|
||||
type = "void"
|
||||
|
Loading…
Reference in New Issue
Block a user