Elements used in the Balls and Things games for the RETRO.
Dependents: RETRO_BallsAndPaddle RETRO_BallAndHoles
Vector.cpp
- Committer:
- maxint
- Date:
- 2015-02-06
- Revision:
- 0:3d0db4e183ee
- Child:
- 2:74bc9b16fb88
File content as of revision 0:3d0db4e183ee:
#include "Vector.h" Vector::Vector() { // constructor this->set((float)0,(float)0); } Vector::Vector(float fX, float fY) { this->set(fX, fY); } void Vector::set(float fX, float fY) { x=fX; y=fY; } void Vector::set(int nX, int nY) { this->set((float)nX, (float)nY); } float Vector::getSize() { // get the size of the vector return(sqrt(x*x+y*y)); } bool Vector::isLeft() { return(x<0); } bool Vector::isRight() { return(x>0); } bool Vector::isUp() { return(y<0); } bool Vector::isDown() { return(y>0); } void Vector::add(float fAdd) { // add the size of the vector by adding to its size float fSize=getSize(); float fSizeNew=fSize+fAdd; if(fSize!=0) { x=x * (fSizeNew/fSize); y=y * (fSizeNew/fSize); } else { // in case of zero lenght, default to addition in first quadrant. x=sqrt(0.5 * fAdd * fAdd); y=x; } } void Vector::add(Vector vAdd) { x+=vAdd.x; y+=vAdd.y; } void Vector::multiply(Vector vMult) { // multiply the vector by means of the other vector x*=vMult.x; y*=vMult.y; }