mirror of https://github.com/bjornbytes/lovr.git
lovr.graphics.circle;
This commit is contained in:
parent
4881d2ebbe
commit
81c29176ab
|
@ -525,6 +525,15 @@ int l_lovrGraphicsBox(lua_State* L) {
|
|||
return luax_rectangularprism(L, false);
|
||||
}
|
||||
|
||||
int l_lovrGraphicsCircle(lua_State* L) {
|
||||
DrawMode drawMode = *(DrawMode*) luax_checkenum(L, 1, &DrawModes, "draw mode");
|
||||
float transform[16];
|
||||
int index = luax_readtransform(L, 2, transform, true);
|
||||
int segments = luaL_optnumber(L, index, 32);
|
||||
lovrGraphicsCircle(drawMode, transform, segments);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsCylinder(lua_State* L) {
|
||||
float x1 = luaL_checknumber(L, 1);
|
||||
float y1 = luaL_checknumber(L, 2);
|
||||
|
@ -815,6 +824,7 @@ const luaL_Reg lovrGraphics[] = {
|
|||
{ "plane", l_lovrGraphicsPlane },
|
||||
{ "cube", l_lovrGraphicsCube },
|
||||
{ "box", l_lovrGraphicsBox },
|
||||
{ "circle", l_lovrGraphicsCircle },
|
||||
{ "cylinder", l_lovrGraphicsCylinder },
|
||||
{ "sphere", l_lovrGraphicsSphere },
|
||||
{ "skybox", l_lovrGraphicsSkybox },
|
||||
|
|
|
@ -707,6 +707,48 @@ void lovrGraphicsBox(DrawMode mode, mat4 transform) {
|
|||
lovrGraphicsPop();
|
||||
}
|
||||
|
||||
void lovrGraphicsCircle(DrawMode mode, mat4 transform, int segments) {
|
||||
lovrGraphicsPush();
|
||||
lovrGraphicsMatrixTransform(MATRIX_MODEL, transform);
|
||||
|
||||
vec_clear(&state.streamData);
|
||||
|
||||
if (mode == DRAW_MODE_LINE) {
|
||||
} else if (mode == DRAW_MODE_FILL) {
|
||||
vec_push(&state.streamData, 0);
|
||||
vec_push(&state.streamData, 0);
|
||||
vec_push(&state.streamData, 0);
|
||||
|
||||
vec_push(&state.streamData, 0);
|
||||
vec_push(&state.streamData, 0);
|
||||
vec_push(&state.streamData, 1);
|
||||
|
||||
vec_push(&state.streamData, .5);
|
||||
vec_push(&state.streamData, .5);
|
||||
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
float theta = i / (float) segments * 2 * M_PI;
|
||||
float x = cos(theta) * .5;
|
||||
float y = sin(theta) * .5;
|
||||
vec_push(&state.streamData, x);
|
||||
vec_push(&state.streamData, y);
|
||||
vec_push(&state.streamData, 0);
|
||||
|
||||
vec_push(&state.streamData, 0);
|
||||
vec_push(&state.streamData, 0);
|
||||
vec_push(&state.streamData, 1);
|
||||
|
||||
vec_push(&state.streamData, x + .5);
|
||||
vec_push(&state.streamData, 1 - (y + .5));
|
||||
}
|
||||
|
||||
lovrGraphicsSetDefaultShader(SHADER_DEFAULT);
|
||||
lovrGraphicsDrawPrimitive(GL_TRIANGLE_FAN, true, true, false);
|
||||
}
|
||||
|
||||
lovrGraphicsPop();
|
||||
}
|
||||
|
||||
void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, bool capped, int segments) {
|
||||
float axis[3] = { x1 - x2, y1 - y2, z1 - z2 };
|
||||
float n[3] = { x1 - x2, y1 - y2, z1 - z2 };
|
||||
|
|
|
@ -163,6 +163,7 @@ void lovrGraphicsTriangle(DrawMode mode, float* points);
|
|||
void lovrGraphicsPlane(DrawMode mode, mat4 transform);
|
||||
void lovrGraphicsPlaneFullscreen(Texture* texture);
|
||||
void lovrGraphicsBox(DrawMode mode, mat4 transform);
|
||||
void lovrGraphicsCircle(DrawMode mode, mat4 transform, int segments);
|
||||
void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, bool capped, int segments);
|
||||
void lovrGraphicsSphere(mat4 transform, int segments);
|
||||
void lovrGraphicsSkybox(Texture* texture, float angle, float ax, float ay, float az);
|
||||
|
|
Loading…
Reference in New Issue