the PVector class

edited February 2014 in Programming Questions

Hi guys im trying to understand how the PVector class works interms of adding vectors

so far I saw this in shifams book

class PVector {
  float x;
  float y;
  PVector(float x_, float y_) {
    x = x_;
    y = y_;
  }

  void add(PVector v) {
    y = y + v.y;
    x = x + v.x;
  }
} 

ive written this just to see if this actually does work but get errors im trying figure out how the methods work in draw. im aslo trying to understand OOB as well so perhaps im missing something here

PVector vector ;

void setup(){  
  size(200,200);
 vector = new PVector(1,2);
}

void draw(){
  vector.add(0,1);// referencing x , y
}

class PVector(){

 float x;
 float y;

PVector(float x_,float y_){
   x = x_;
   y = y_;
   }

  void add(PVector v){
    x = x + v.x;
    y = y + v.y;
    print(x,y);
  }
}

Answers

Sign In or Register to comment.