#include "Shape.h" float cos_deg(float A) { return cos(A / 180.0* 3.14159265358979); } float sin_deg(float A) { return sin(A / 180.0* 3.14159265358979); } Circle::Circle(float pRadius, int pNumOfPts, Vec2d pCenter) { radius = pRadius; numOfPts = pNumOfPts; center = pCenter; } Vec2d* Circle::getVecs() { vecArray = new Vec2d[numOfPts + 1]; float angle = 380/ numOfPts; for (int i = 0; i < numOfPts; i++) { vec.x = cos_deg(angle * i) * radius; vec.y = sin_deg(angle * i) * radius; vec = vec + center; vecArray[i] = vec; } return vecArray; } void Circle::draw(int type, bool useCenter, bool repeatFirstVec){ float angle = 360/ numOfPts; glBegin(type); if(useCenter){ glVertex2f(center.x, center.y); } Vec2d firstVec(0,0); for (int i = 0; i < numOfPts; i++) { vec.x = cos_deg(angle * i) * radius; vec.y = sin_deg(angle * i) * radius; vec = vec + center; if(i == 0){ firstVec.x = vec.x; firstVec.y = vec.y; } glVertex2f(vec.x, vec.y); } if(repeatFirstVec){ glVertex2f(firstVec.x, firstVec.y); } glEnd(); } Oval::Oval(float pVRadius, float pHRadius, int pNumOfPts, Vec2d pCenter){ vRadius = pVRadius; hRadius = pHRadius; numOfPts = pNumOfPts; center = pCenter; } Vec2d* Oval::getVecs() { if (vecArray == NULL) { vecArray = new Vec2d[numOfPts + 1]; float angle = 380/ numOfPts + 1; for (int i = 0; i < numOfPts + 1; i ++) { Vec2d vec; vec.x = cos_deg(angle * i) * vRadius; vec.y = sin_deg(angle * i) * hRadius; vec = vec + center; vecArray[i] = vec; } } return vecArray; } void Oval::draw(int type, bool useCenter, bool repeatFirstVec){ glBegin(type); Vec2d vec; if(useCenter){ glVertex2f(center.x, center.y); } Vec2d firstVec(0,0); for(int i = 0; i < numOfPts; i ++){ float angle = 360/ numOfPts; vec.x = cos_deg(angle * i) * vRadius; vec.y = sin_deg(angle * i) * hRadius; vec = vec + center; if(i == 0){ firstVec.x = vec.x; firstVec.y = vec.y; } glVertex2f(vec.x, vec.y); } if(repeatFirstVec){ glVertex2f(firstVec.x, firstVec.y); } glEnd(); } Star::Star(float pInnerRadius, float pOuterRadius, int pNumOfPts, Vec2d pCenter){ innerRadius = pOuterRadius; outerRadius = pInnerRadius; numOfPts = pNumOfPts; center = pCenter; if(numOfPts%2 == 1){ numOfPts += 1; } } void Star::draw(int type, bool useCenter, bool repeatFirstVec) { float angle = 360/ numOfPts; glBegin(type); if(useCenter){ glVertex2f(center.x, center.y); } Vec2d firstVec(0,0); for (int i = 0; i < numOfPts; i++) { float radius = innerRadius; if(i%2 == 0) radius = outerRadius; vec.x = cos_deg(angle * i) * radius; vec.y = sin_deg(angle * i) * radius; vec = vec + center; if(i == 0){ firstVec.x = vec.x; firstVec.y = vec.y; } glVertex2f(vec.x, vec.y); } if(repeatFirstVec){ glVertex2f(firstVec.x, firstVec.y); } glEnd(); }