Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "speedboid.h"
- #include "ofAuDApp.h"
- /**
- * Standartkonstruktor
- *
- * @brief SpeedBoid::SpeedBoid
- */
- SpeedBoid::SpeedBoid() {
- posX = 0;
- posY = 0;
- vx = 0;
- vy = 0;
- size = 20;
- }
- /**
- * Zeichnet den Boid
- * @brief SpeedBoid::draw
- */
- void SpeedBoid::draw() {
- ofSetColor(255,255,255);
- if ( (vx == 0) && (vy == 0 ) ) {
- ofDrawCircle(posX,posY,size/4);
- } else {
- float dist = sqrt(vx*vx + vy*vy);
- float dirX = vx/dist;
- float dirY = vy/dist;
- float aX = posX + size*dirX;
- float aY = posY + size*dirY;
- float bX = posX - size/4*dirY;
- float bY = posY + size/4*dirX;
- float cX = posX + size/4*dirY;
- float cY = posY - size/4*dirX;
- ofDrawTriangle(aX,aY,bX,bY,cX,cY);
- }
- }
- /**
- * Bewegt den Boid entsprechend seiner Geschwindigkeit
- * @brief SpeedBoid::move
- */
- void SpeedBoid::move() {
- posX = posX + vx;
- posY = posY + vy;
- }
- //========================================================================
- //===================== Getter und Setter ============================
- //========================================================================
- /**
- * Setzt den Boid auf eine bestimmte Position
- * @brief SpeedBoid::setPosition
- * @param x x-Koordinate
- * @param y y-Koordinate
- */
- void SpeedBoid::setPosition(int x, int y) {
- posX = x;
- posY = y;
- }
- /**
- * Setzt die Geschwindigkeit des Boids
- * @brief SpeedBoid::setSpeed
- * @param x x-Anteil der Geschwindigkeit
- * @param y y-Anteil der Geschwindigkeit
- */
- void SpeedBoid::setSpeed(int x, int y) {
- vx = x;
- vy = y;
- }
- int SpeedBoid::getX() {
- return posX;
- }
- int SpeedBoid::getY() {
- return posY;
- }
- int SpeedBoid::getSpeedX() {
- return vx;
- }
- int SpeedBoid::getSpeedY() {
- return vy;
- }
- ofVec2f SpeedBoid::getVelocityVec() const
- {
- ofVec2f hVelocityVec;
- hVelocityVec.set(vx,vy);
- return hVelocityVec;
- }
- void SpeedBoid::setVelocityVec(const ofVec2f &velocity)
- {
- velocityVec = velocity;
- }
- ofVec2f SpeedBoid::getPositionVec() const
- {
- ofVec2f hPositionVec;
- hPositionVec.set(posX,posY);
- return hPositionVec;
- }
- void SpeedBoid::setPositionVec(const ofVec2f &position)
- {
- positionVec = position;
- }
- int SpeedBoid::getId() const
- {
- return id;
- }
- void SpeedBoid::setId(int pId)
- {
- id = pId;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement