Jump to content
  • Advertisement
Sign in to follow this  
suliman

draw ellipse instead of circle?

This topic is 4153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Just change

x2 = Radius * cos(a);
y2 = Radius * sin(a);


to

x2 = Width/2.0f * cos(a);
y2 = Height/2.0f * sin(a);

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!