NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 11384|回复: 9
打印 上一主题 下一主题

[在线求助] 新手Processing代码求教

[复制链接]
跳转到指定楼层
1m
发表于 2014-6-11 02:51:43 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
有几年没碰语言了,重拾起来倍感吃力,跟着教材模拟小球收重力和风力两个力影响的情况,写出来不知道问题出在哪里。。有很多基本的概念也半懂不懂。。向论坛里求解,什么是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();
}


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2m
 楼主| 发表于 2014-6-13 09:41:15 | 显示全部楼层

嗯,我只是对交互设计感兴趣所以在开始看些散的知识~
3m
 楼主| 发表于 2014-6-13 09:42:48 | 显示全部楼层
月之眼 发表于 2014-6-11 12:44
请加40391970这个群。processing的版主会给你解答的

好的,谢谢已加

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-5-4 02:19 , Processed in 0.061085 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表