Browse Source

added love.graphics.arc

--HG--
branch : minor
Bill Meltsner 14 years ago
parent
commit
33a2110b00

+ 43 - 1
src/modules/graphics/opengl/Graphics.cpp

@@ -950,7 +950,7 @@ namespace opengl
 		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);
 		if(points <= 0) points = 1;
@@ -986,6 +986,48 @@ namespace opengl
 		glPopMatrix();
 		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 )
 	{

+ 2 - 1
src/modules/graphics/opengl/Graphics.h

@@ -28,7 +28,6 @@
 // SDL
 #include <SDL.h>
 #include "GLee.h"
-#include <SDL_opengl.h>
 
 // LOVE
 #include <graphics/Graphics.h>
@@ -483,6 +482,8 @@ namespace opengl
 		* @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 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.

+ 18 - 0
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -853,6 +853,23 @@ namespace opengl
 		instance->circle(mode, x, y, radius, points);
 		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)
 	{
@@ -974,6 +991,7 @@ namespace opengl
 		{ "rectangle", w_rectangle },
 		{ "quad", w_quad },
 		{ "circle", w_circle },
+		{ "arc", w_arc },
 
 		{ "polygon", w_polygon },
 

+ 1 - 0
src/modules/graphics/opengl/wrap_Graphics.h

@@ -94,6 +94,7 @@ namespace opengl
 	int w_rectangle(lua_State * L);
 	int w_quad(lua_State * L);
 	int w_circle(lua_State * L);
+	int w_arc(lua_State * L);
 	int w_push(lua_State * L);
 	int w_pop(lua_State * L);
 	int w_rotate(lua_State * L);