/****************************************************************** * Definition of a coil * * A coil is defined by its radius, dz for a round and the number * * of rounds. We also define an angle, this is the angle by which * * we rotate round the Y axis * * All three variables can be get and set by calling the * * appropiate member functions and the coil can be drawn by * * calling the draw() member function * ******************************************************************/ #include #include using namespace std; const double NUM_LINES_A_LOOP = 40; class Coil{ public: Coil(); Coil(double radius, double dz, int rounds,double angle); double getRadius() const; double getdZ() const; int getRounds() const; double getAngle() const; void setRadius(double radius); void setdZ(double dz); void setRounds(int rounds); void setAngle(double angle); void draw() const; private: double radius, dz; int rounds; double angle; }; Coil::Coil(void){ radius = 1.0; dz = 0.5; rounds = 10; angle = 90; } Coil::Coil(double radius, double dz, int rounds,double angle){ this->radius = radius; this->dz = dz; this->rounds = rounds; setAngle(angle); } double Coil::getRadius() const{ return radius; } double Coil::getdZ() const{ return dz; } int Coil::getRounds() const{ return rounds; } double Coil::getAngle() const{ return angle; } void Coil::setRadius(double radius){ this->radius = radius; } void Coil::setdZ(double dz){ this->dz = dz; } void Coil::setRounds(int rounds){ this->rounds = rounds; } void Coil::setAngle(double angle){ this->angle = angle; while(this->angle>=360){ this->angle-=360; } while(this->angle<0){ this->angle+=360; } } void Coil::draw(void) const{ double angle; // create zstart to make it symmetrical around the origin double zstart = -(rounds*dz)/2.0; double z; glRotatef(this->angle,0.0,1.0,0.0); glBegin(GL_LINE_STRIP); for(int i = 0; i