We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
how old is that tutorial?
PVector is a built-in class now, probably best not to have your own class with the same name
http://processing.org/reference/PVector.html
im just interested in seeing how the methods and constructor for this class are built you see if anyone point out how the method add(PVector v) is built that would be great
You can see the source code for PVector here
thanks dude!