|
有几年没碰语言了,重拾起来倍感吃力,跟着教材模拟小球收重力和风力两个力影响的情况,写出来不知道问题出在哪里。。有很多基本的概念也半懂不懂。。向论坛里求解,什么是cannot make a static reference to the non-static method applyForce
class Mover{
PVector location;
PVector velocity;
PVector acceleration;
float mass;
Mover(){
mass=1;
location=new PVector( 30,30);
velocity=new PVector (0,0);
acceleration= new PVector(0,0);
}
void applyForce(PVector force){
PVector f = PVector.div(force,mass);
acceleration.add(f);
}
void update(){
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
}
void display(){
stroke(0);
fill(175);
ellipse(location.x,location.y,mass*16,mass*16);
}
void checkedge(){
if (location.x>width){
location.x=width;
velocity.x*=-1;
}else if (location.x < 0) {
velocity.x *= -1;
location.x = 0;
}if (location.y > height) {
velocity.y *= -1;
location.y = height;
}
}
}
void setup(){
size(200,500);
background(255);
}
void draw(){
PVector wind= new PVector (0.01,0);
PVector gravity= new PVector (0,0.1);
Mover.applyForce(wind);
Mover.applyForce(gravity);
Mover.update();
Mover.display();
Mover.checkedge();
}
|
|