mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
added love.graphics.arc
--HG-- branch : minor
This commit is contained in:
@@ -950,7 +950,7 @@ namespace opengl
|
|||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::circle(DrawMode mode, float x, float y, float radius, int points )
|
void Graphics::circle(DrawMode mode, float x, float y, float radius, int points)
|
||||||
{
|
{
|
||||||
float two_pi = static_cast<float>(LOVE_M_PI * 2);
|
float two_pi = static_cast<float>(LOVE_M_PI * 2);
|
||||||
if(points <= 0) points = 1;
|
if(points <= 0) points = 1;
|
||||||
@@ -986,6 +986,48 @@ namespace opengl
|
|||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points)
|
||||||
|
{
|
||||||
|
float angle = angle2 - angle1;
|
||||||
|
while (angle < 0) angle += LOVE_M_PI * 2;
|
||||||
|
if(points <= 0) points = 1;
|
||||||
|
float angle_shift = (angle / points);
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
glTranslatef(x, y, 0.0f);
|
||||||
|
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
case DRAW_LINE:
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
|
||||||
|
glVertex2f(0, 0);
|
||||||
|
|
||||||
|
for(float i = 0; i <= angle+angle_shift/2; i+= angle_shift)
|
||||||
|
glVertex2f(radius * cos(i+angle1),radius * sin(i+angle1));
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case DRAW_FILL:
|
||||||
|
glBegin(GL_TRIANGLE_FAN);
|
||||||
|
|
||||||
|
glVertex2f(0, 0);
|
||||||
|
|
||||||
|
for(float i = 0; i <= angle+angle_shift/2; i+= angle_shift)
|
||||||
|
glVertex2f(radius * cos(i+angle1),radius * sin(i+angle1));
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
int Graphics::polygon( lua_State * L )
|
int Graphics::polygon( lua_State * L )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
// SDL
|
// SDL
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "GLee.h"
|
#include "GLee.h"
|
||||||
#include <SDL_opengl.h>
|
|
||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include <graphics/Graphics.h>
|
#include <graphics/Graphics.h>
|
||||||
@@ -483,6 +482,8 @@ namespace opengl
|
|||||||
* @param points Amount of points to use to draw the circle.
|
* @param points Amount of points to use to draw the circle.
|
||||||
**/
|
**/
|
||||||
void circle(DrawMode mode, float x, float y, float radius, int points = 10);
|
void circle(DrawMode mode, float x, float y, float radius, int points = 10);
|
||||||
|
|
||||||
|
void arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points = 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a polygon with an arbitrary number of vertices.
|
* Draws a polygon with an arbitrary number of vertices.
|
||||||
|
|||||||
@@ -853,6 +853,23 @@ namespace opengl
|
|||||||
instance->circle(mode, x, y, radius, points);
|
instance->circle(mode, x, y, radius, points);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_arc(lua_State * L)
|
||||||
|
{
|
||||||
|
Graphics::DrawMode mode;
|
||||||
|
const char * str = luaL_checkstring(L, 1);
|
||||||
|
if(!Graphics::getConstant(str, mode))
|
||||||
|
return luaL_error(L, "Incorrect draw mode %s", str);
|
||||||
|
|
||||||
|
float x = (float)luaL_checknumber(L, 2);
|
||||||
|
float y = (float)luaL_checknumber(L, 3);
|
||||||
|
float radius = (float)luaL_checknumber(L, 4);
|
||||||
|
float angle1 = (float)luaL_checknumber(L, 5);
|
||||||
|
float angle2 = (float)luaL_checknumber(L, 6);
|
||||||
|
int points = luaL_optint(L, 7, 10);
|
||||||
|
instance->arc(mode, x, y, radius, angle1, angle2, points);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int w_polygon(lua_State * L)
|
int w_polygon(lua_State * L)
|
||||||
{
|
{
|
||||||
@@ -974,6 +991,7 @@ namespace opengl
|
|||||||
{ "rectangle", w_rectangle },
|
{ "rectangle", w_rectangle },
|
||||||
{ "quad", w_quad },
|
{ "quad", w_quad },
|
||||||
{ "circle", w_circle },
|
{ "circle", w_circle },
|
||||||
|
{ "arc", w_arc },
|
||||||
|
|
||||||
{ "polygon", w_polygon },
|
{ "polygon", w_polygon },
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ namespace opengl
|
|||||||
int w_rectangle(lua_State * L);
|
int w_rectangle(lua_State * L);
|
||||||
int w_quad(lua_State * L);
|
int w_quad(lua_State * L);
|
||||||
int w_circle(lua_State * L);
|
int w_circle(lua_State * L);
|
||||||
|
int w_arc(lua_State * L);
|
||||||
int w_push(lua_State * L);
|
int w_push(lua_State * L);
|
||||||
int w_pop(lua_State * L);
|
int w_pop(lua_State * L);
|
||||||
int w_rotate(lua_State * L);
|
int w_rotate(lua_State * L);
|
||||||
|
|||||||
Reference in New Issue
Block a user