mirror of https://github.com/bjornbytes/lovr.git
lovr.graphics.box; Better non-uniform scale;
This commit is contained in:
parent
a13c793769
commit
dd1db4c86f
|
@ -463,7 +463,7 @@ int l_lovrGraphicsScale(lua_State* L) {
|
||||||
|
|
||||||
int l_lovrGraphicsTransform(lua_State* L) {
|
int l_lovrGraphicsTransform(lua_State* L) {
|
||||||
float transform[16];
|
float transform[16];
|
||||||
luax_readtransform(L, 1, transform);
|
luax_readtransform(L, 1, transform, 0);
|
||||||
lovrGraphicsMatrixTransform(transform);
|
lovrGraphicsMatrixTransform(transform);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ int l_lovrGraphicsPlane(lua_State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int l_lovrGraphicsCube(lua_State* L) {
|
static int luax_rectangularprism(lua_State* L, int uniformScale) {
|
||||||
Texture* texture = NULL;
|
Texture* texture = NULL;
|
||||||
DrawMode drawMode;
|
DrawMode drawMode;
|
||||||
if (lua_isstring(L, 1)) {
|
if (lua_isstring(L, 1)) {
|
||||||
|
@ -536,15 +536,23 @@ int l_lovrGraphicsCube(lua_State* L) {
|
||||||
texture = luax_checktype(L, 1, Texture);
|
texture = luax_checktype(L, 1, Texture);
|
||||||
}
|
}
|
||||||
float transform[16];
|
float transform[16];
|
||||||
luax_readtransform(L, 2, transform);
|
luax_readtransform(L, 2, transform, uniformScale);
|
||||||
lovrGraphicsCube(drawMode, texture, transform);
|
lovrGraphicsBox(drawMode, texture, transform);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrGraphicsCube(lua_State* L) {
|
||||||
|
return luax_rectangularprism(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrGraphicsBox(lua_State* L) {
|
||||||
|
return luax_rectangularprism(L, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int l_lovrGraphicsPrint(lua_State* L) {
|
int l_lovrGraphicsPrint(lua_State* L) {
|
||||||
const char* str = luaL_checkstring(L, 1);
|
const char* str = luaL_checkstring(L, 1);
|
||||||
float transform[16];
|
float transform[16];
|
||||||
int index = luax_readtransform(L, 2, transform);
|
int index = luax_readtransform(L, 2, transform, 1);
|
||||||
float wrap = luaL_optnumber(L, index++, 0);
|
float wrap = luaL_optnumber(L, index++, 0);
|
||||||
HorizontalAlign halign = *(HorizontalAlign*) luax_optenum(L, index++, "center", &HorizontalAligns, "alignment");
|
HorizontalAlign halign = *(HorizontalAlign*) luax_optenum(L, index++, "center", &HorizontalAligns, "alignment");
|
||||||
VerticalAlign valign = *(VerticalAlign*) luax_optenum(L, index++, "middle", &VerticalAligns, "alignment");
|
VerticalAlign valign = *(VerticalAlign*) luax_optenum(L, index++, "middle", &VerticalAligns, "alignment");
|
||||||
|
@ -809,6 +817,7 @@ const luaL_Reg lovrGraphics[] = {
|
||||||
{ "triangle", l_lovrGraphicsTriangle },
|
{ "triangle", l_lovrGraphicsTriangle },
|
||||||
{ "plane", l_lovrGraphicsPlane },
|
{ "plane", l_lovrGraphicsPlane },
|
||||||
{ "cube", l_lovrGraphicsCube },
|
{ "cube", l_lovrGraphicsCube },
|
||||||
|
{ "box", l_lovrGraphicsBox },
|
||||||
{ "print", l_lovrGraphicsPrint },
|
{ "print", l_lovrGraphicsPrint },
|
||||||
{ "cylinder", l_lovrGraphicsCylinder },
|
{ "cylinder", l_lovrGraphicsCylinder },
|
||||||
{ "getWidth", l_lovrGraphicsGetWidth },
|
{ "getWidth", l_lovrGraphicsGetWidth },
|
||||||
|
|
|
@ -67,7 +67,7 @@ extern map_int_t VerticalAligns;
|
||||||
extern map_int_t WrapModes;
|
extern map_int_t WrapModes;
|
||||||
|
|
||||||
void luax_checkmeshformat(lua_State* L, int index, MeshFormat* format);
|
void luax_checkmeshformat(lua_State* L, int index, MeshFormat* format);
|
||||||
int luax_readtransform(lua_State* L, int index, mat4 transform);
|
int luax_readtransform(lua_State* L, int index, mat4 transform, int uniformScale);
|
||||||
Blob* luax_readblob(lua_State* L, int index, const char* debug);
|
Blob* luax_readblob(lua_State* L, int index, const char* debug);
|
||||||
int luax_pushshape(lua_State* L, Shape* shape);
|
int luax_pushshape(lua_State* L, Shape* shape);
|
||||||
int luax_pushjoint(lua_State* L, Joint* joint);
|
int luax_pushjoint(lua_State* L, Joint* joint);
|
||||||
|
|
|
@ -11,7 +11,7 @@ int l_lovrMathInit(lua_State* L) {
|
||||||
|
|
||||||
int l_lovrMathNewTransform(lua_State* L) {
|
int l_lovrMathNewTransform(lua_State* L) {
|
||||||
float matrix[16];
|
float matrix[16];
|
||||||
luax_readtransform(L, 1, matrix);
|
luax_readtransform(L, 1, matrix, 0);
|
||||||
Transform* transform = lovrTransformCreate(matrix);
|
Transform* transform = lovrTransformCreate(matrix);
|
||||||
luax_pushtype(L, Transform, transform);
|
luax_pushtype(L, Transform, transform);
|
||||||
lovrRelease(&transform->ref);
|
lovrRelease(&transform->ref);
|
||||||
|
|
|
@ -30,7 +30,7 @@ void luax_checkmeshformat(lua_State* L, int index, MeshFormat* format) {
|
||||||
int l_lovrMeshDraw(lua_State* L) {
|
int l_lovrMeshDraw(lua_State* L) {
|
||||||
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
Mesh* mesh = luax_checktype(L, 1, Mesh);
|
||||||
float transform[16];
|
float transform[16];
|
||||||
luax_readtransform(L, 2, transform);
|
luax_readtransform(L, 2, transform, 1);
|
||||||
lovrMeshDraw(mesh, transform);
|
lovrMeshDraw(mesh, transform);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
int l_lovrModelDraw(lua_State* L) {
|
int l_lovrModelDraw(lua_State* L) {
|
||||||
Model* model = luax_checktype(L, 1, Model);
|
Model* model = luax_checktype(L, 1, Model);
|
||||||
float transform[16];
|
float transform[16];
|
||||||
luax_readtransform(L, 2, transform);
|
luax_readtransform(L, 2, transform, 1);
|
||||||
lovrModelDraw(model, transform);
|
lovrModelDraw(model, transform);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,24 @@
|
||||||
#include "math/mat4.h"
|
#include "math/mat4.h"
|
||||||
#include "math/transform.h"
|
#include "math/transform.h"
|
||||||
|
|
||||||
int luax_readtransform(lua_State* L, int index, mat4 m) {
|
int luax_readtransform(lua_State* L, int index, mat4 m, int uniformScale) {
|
||||||
if (lua_isnumber(L, index)) {
|
if (lua_isnumber(L, index)) {
|
||||||
float x = luaL_optnumber(L, index++, 0);
|
float x = luaL_optnumber(L, index++, 0);
|
||||||
float y = luaL_optnumber(L, index++, 0);
|
float y = luaL_optnumber(L, index++, 0);
|
||||||
float z = luaL_optnumber(L, index++, 0);
|
float z = luaL_optnumber(L, index++, 0);
|
||||||
float s = luaL_optnumber(L, index++, 1);
|
float sx, sy, sz;
|
||||||
|
if (uniformScale) {
|
||||||
|
sx = sy = sz = luaL_optnumber(L, index++, 1);
|
||||||
|
} else {
|
||||||
|
sx = luaL_optnumber(L, index++, 1);
|
||||||
|
sy = luaL_optnumber(L, index++, 1);
|
||||||
|
sz = luaL_optnumber(L, index++, 1);
|
||||||
|
}
|
||||||
float angle = luaL_optnumber(L, index++, 0);
|
float angle = luaL_optnumber(L, index++, 0);
|
||||||
float ax = luaL_optnumber(L, index++, 0);
|
float ax = luaL_optnumber(L, index++, 0);
|
||||||
float ay = luaL_optnumber(L, index++, 1);
|
float ay = luaL_optnumber(L, index++, 1);
|
||||||
float az = luaL_optnumber(L, index++, 0);
|
float az = luaL_optnumber(L, index++, 0);
|
||||||
mat4_setTransform(m, x, y, z, s, angle, ax, ay, az);
|
mat4_setTransform(m, x, y, z, sx, sy, sz, angle, ax, ay, az);
|
||||||
return index;
|
return index;
|
||||||
} else if (lua_isnoneornil(L, index)) {
|
} else if (lua_isnoneornil(L, index)) {
|
||||||
mat4_identity(m);
|
mat4_identity(m);
|
||||||
|
@ -88,7 +95,7 @@ int l_lovrTransformScale(lua_State* L) {
|
||||||
int l_lovrTransformSetTransformation(lua_State* L) {
|
int l_lovrTransformSetTransformation(lua_State* L) {
|
||||||
Transform* transform = luax_checktype(L, 1, Transform);
|
Transform* transform = luax_checktype(L, 1, Transform);
|
||||||
lovrTransformOrigin(transform); // Dirty the Transform
|
lovrTransformOrigin(transform); // Dirty the Transform
|
||||||
luax_readtransform(L, 2, transform->matrix);
|
luax_readtransform(L, 2, transform->matrix, 0);
|
||||||
lua_pushvalue(L, 1);
|
lua_pushvalue(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -620,7 +620,7 @@ void lovrGraphicsPlane(DrawMode mode, Texture* texture, float x, float y, float
|
||||||
float theta = acos(nz);
|
float theta = acos(nz);
|
||||||
|
|
||||||
float transform[16];
|
float transform[16];
|
||||||
mat4_setTransform(transform, x, y, z, size, theta, cx, cy, cz);
|
mat4_setTransform(transform, x, y, z, size, size, size, theta, cx, cy, cz);
|
||||||
|
|
||||||
lovrGraphicsPush();
|
lovrGraphicsPush();
|
||||||
lovrGraphicsMatrixTransform(transform);
|
lovrGraphicsMatrixTransform(transform);
|
||||||
|
@ -677,7 +677,7 @@ void lovrGraphicsPlaneFullscreen(Texture* texture) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrGraphicsCube(DrawMode mode, Texture* texture, mat4 transform) {
|
void lovrGraphicsBox(DrawMode mode, Texture* texture, mat4 transform) {
|
||||||
lovrGraphicsPush();
|
lovrGraphicsPush();
|
||||||
lovrGraphicsMatrixTransform(transform);
|
lovrGraphicsMatrixTransform(transform);
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ void lovrGraphicsLine(float* points, int count);
|
||||||
void lovrGraphicsTriangle(DrawMode mode, float* points);
|
void lovrGraphicsTriangle(DrawMode mode, float* points);
|
||||||
void lovrGraphicsPlane(DrawMode mode, Texture* texture, float x, float y, float z, float size, float nx, float ny, float nz);
|
void lovrGraphicsPlane(DrawMode mode, Texture* texture, float x, float y, float z, float size, float nx, float ny, float nz);
|
||||||
void lovrGraphicsPlaneFullscreen(Texture* texture);
|
void lovrGraphicsPlaneFullscreen(Texture* texture);
|
||||||
void lovrGraphicsCube(DrawMode mode, Texture* texture, mat4 transform);
|
void lovrGraphicsBox(DrawMode mode, Texture* texture, mat4 transform);
|
||||||
void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, int capped, int segments);
|
void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, int capped, int segments);
|
||||||
void lovrGraphicsSkybox(Skybox* skybox, float angle, float ax, float ay, float az);
|
void lovrGraphicsSkybox(Skybox* skybox, float angle, float ax, float ay, float az);
|
||||||
void lovrGraphicsPrint(const char* str, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
void lovrGraphicsPrint(const char* str, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
||||||
|
|
|
@ -208,10 +208,10 @@ mat4 mat4_scale(mat4 m, float x, float y, float z) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 mat4_setTransform(mat4 m, float x, float y, float z, float s, float angle, float ax, float ay, float az) {
|
mat4 mat4_setTransform(mat4 m, float x, float y, float z, float sx, float sy, float sz, float angle, float ax, float ay, float az) {
|
||||||
mat4_identity(m);
|
mat4_identity(m);
|
||||||
mat4_translate(m, x, y, z);
|
mat4_translate(m, x, y, z);
|
||||||
mat4_scale(m, s, s, s);
|
mat4_scale(m, sx, sy, sz);
|
||||||
return mat4_rotate(m, angle, ax, ay, az);
|
return mat4_rotate(m, angle, ax, ay, az);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ mat4 mat4_translate(mat4 m, float x, float y, float z);
|
||||||
mat4 mat4_rotate(mat4 m, float angle, float x, float y, float z);
|
mat4 mat4_rotate(mat4 m, float angle, float x, float y, float z);
|
||||||
mat4 mat4_rotateQuat(mat4 m, quat q);
|
mat4 mat4_rotateQuat(mat4 m, quat q);
|
||||||
mat4 mat4_scale(mat4 m, float x, float y, float z);
|
mat4 mat4_scale(mat4 m, float x, float y, float z);
|
||||||
mat4 mat4_setTransform(mat4 m, float x, float y, float z, float s, float angle, float ax, float ay, float az);
|
mat4 mat4_setTransform(mat4 m, float x, float y, float z, float sx, float sy, float sz, float angle, float ax, float ay, float az);
|
||||||
mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float near, float far);
|
mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float near, float far);
|
||||||
mat4 mat4_perspective(mat4 m, float near, float far, float fov, float aspect);
|
mat4 mat4_perspective(mat4 m, float near, float far, float fov, float aspect);
|
||||||
void mat4_transform(mat4 m, vec3 v);
|
void mat4_transform(mat4 m, vec3 v);
|
||||||
|
|
Loading…
Reference in New Issue