lovr.graphics.plane takes regular transform;

This commit is contained in:
bjorn 2017-07-19 05:07:18 +09:00
parent d8500e456c
commit 41210b1bd0
3 changed files with 5 additions and 31 deletions

View File

@ -515,14 +515,9 @@ int l_lovrGraphicsPlane(lua_State* L) {
return 0;
}
}
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float s = luaL_optnumber(L, 5, 1.f);
float nx = luaL_optnumber(L, 6, 0.f);
float ny = luaL_optnumber(L, 7, 1.f);
float nz = luaL_optnumber(L, 8, 0.f);
lovrGraphicsPlane(drawMode, texture, x, y, z, s, nx, ny, nz);
float transform[16];
luax_readtransform(L, 2, transform, 1);
lovrGraphicsPlane(drawMode, texture, transform);
return 0;
}

View File

@ -603,28 +603,7 @@ 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) {
// Normalize the normal vector
float len = sqrt(nx * nx + ny * ny + nz + nz);
if (len != 0) {
len = 1 / len;
nx *= len;
ny *= len;
nz *= len;
}
// Vector perpendicular to the normal vector and the vector of the default geometry (cross product)
float cx = -ny;
float cy = nx;
float cz = 0.f;
// Angle between normal vector and the normal vector of the default geometry (dot product)
float theta = acos(nz);
float transform[16];
mat4_setTransform(transform, x, y, z, size, size, size, theta, cx, cy, cz);
void lovrGraphicsPlane(DrawMode mode, Texture* texture, mat4 transform) {
lovrGraphicsPush();
lovrGraphicsMatrixTransform(transform);

View File

@ -171,7 +171,7 @@ void lovrGraphicsDrawPrimitive(GLenum mode, int hasNormals, int hasTexCoords, in
void lovrGraphicsPoints(float* points, int count);
void lovrGraphicsLine(float* points, int count);
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, mat4 transform);
void lovrGraphicsPlaneFullscreen(Texture* texture);
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);