#include "circle.h" #include #include #include #include #define PI 3.141592653589793238 using namespace wgd; float Circle::draw_x[CIRCLE_POINTS]; float Circle::draw_y[CIRCLE_POINTS]; Circle::Circle(const wgd::InstanceID &inst) : Body(inst) { if (property("radius") == Null) { setRadius(25); } for (int i = 0; i < CIRCLE_POINTS; i++) { float theta = 2 * i * PI / CIRCLE_POINTS; draw_x[i] = cos(theta); draw_y[i] = sin(theta); } } float Circle::getMinX () { return getX() - getRadius(); } float Circle::getMaxX () { return getX() + getRadius(); } float Circle::getMinY () { return getY() - getRadius(); } float Circle::getMaxY () { return getY() + getRadius(); } bool Circle::contains (const Vector2D& p) { return (p.distanceSquared(position()) <= getRadiusSq()); } void Circle::update() { Body::update(); } void Circle::draw() { glPushMatrix(); glTranslatef(getX(), getY(), property(ix::z)); float radius = getRadius(); Colour c = getColour(); glColor3f(c.r(), c.g(), c.b()); glBegin(GL_POLYGON); for (int i = 0; i < CIRCLE_POINTS; i++) { glVertex3f(draw_x[i] * radius, draw_y[i] * radius, 0); } glEnd(); glColor3f(0, 0, 0); float rot = getRotation(); glBegin(GL_LINES); glVertex3f(cos(rot) * radius, sin(rot) * radius, 0); glVertex3f(-cos(rot) * radius, -sin(rot) * radius, 0); glVertex3f(-sin(rot) * radius, cos(rot) * radius, 0); glVertex3f(sin(rot) * radius, -cos(rot) * radius, 0); glEnd(); glBegin(GL_LINE_LOOP); for (int i = 0; i < CIRCLE_POINTS; i++) { glVertex3f(draw_x[i] * radius, draw_y[i] * radius, 0); } glEnd(); glPopMatrix(); }