diff --git a/src/api/graphics.c b/src/api/graphics.c index 1fe0fe6a..62cc64d5 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -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; } diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index dbf56b0f..922ebd38 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -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); diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 385ef071..39714796 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -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);