Sign in to follow this  
suliman

draw ellipse instead of circle?

Recommended Posts

suliman    1653
Hi How could i edit this so i can supply a width and height instead of a radius, making it draw a ellipse instead of a circle? Thanks Erik
void gameGFX::circle(float x, float y, float Radius, int Segments, DWORD color) 
{ 
  x+=offsetX;
  y+=offsetY;

  float EachAngle; 
  float a; 
  float x1; 
  float x2; 
  float y1; 
  float y2; 
  
  EachAngle = 2.0 * M_PI / (float)Segments; 
  
  x2 = Radius; 
  y2 = 0.0; 
  
  for(a=0.0; a<= (2.0*M_PI + EachAngle); a+=EachAngle) { 
    x1 = x2; 
    y1 = y2; 
    x2 = Radius * cos(a); 
    y2 = Radius * sin(a); 
    hge->Gfx_RenderLine(x1+x, y1+y, x2+x, y2+y, color); 
  } 
} 

Share this post


Link to post
Share on other sites
suliman    1653
works like a charm, thanks.
for anyone that wants it, here's the draw ellipse code. Just change the last line to your own drawLine function and your own color.



void gameGFX::ellipse(float x, float y, float w,float h, int Segments, DWORD color)
{
x+=offsetX;
y+=offsetY;

float EachAngle;
float a;
float x1;
float x2;
float y1;
float y2;

EachAngle = 2.0 * M_PI / (float)Segments;

x2 = w/2;
y2 = 0;

for(a=0.0; a<= (2.0*M_PI + EachAngle); a+=EachAngle){
x1 = x2;
y1 = y2;
x2 = w/2.0f * cos(a);
y2 = h/2.0f * sin(a);
hge->Gfx_RenderLine(x1+x, y1+y, x2+x, y2+y, color);
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this