Commits

Bill Meltsner  committed 395ac35

added love.graphics.arc

  • Participants
  • Parent commits 6df14a8
  • Branches minor

Comments (0)

Files changed (4)

File src/modules/graphics/opengl/Graphics.cpp

 		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;
 		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 )
 	{

File src/modules/graphics/opengl/Graphics.h

 // SDL
 #include <SDL.h>
 #include "GLee.h"
-#include <SDL_opengl.h>
 
 // LOVE
 #include <graphics/Graphics.h>
 		* @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.

File src/modules/graphics/opengl/wrap_Graphics.cpp

 		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)
 	{
 		{ "rectangle", w_rectangle },
 		{ "quad", w_quad },
 		{ "circle", w_circle },
+		{ "arc", w_arc },
 
 		{ "polygon", w_polygon },
 

File src/modules/graphics/opengl/wrap_Graphics.h

 	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);