【问题标题】:Processing Trigonometry Code Not Working处理三角函数代码不起作用
【发布时间】:2017-01-09 13:24:27
【问题描述】:

我的处理代码基于 Daniel Shiffman 的 Nature Of Code 的振荡章节,主要是他根据前进方向(鼠标)旋转移动器的示例。 它不起作用,尽管我很确定这是某个地方的一个小错误。矩形只是飞出屏幕。 书中的例子(不完整):

void display() {
    float angle = velocity.heading2D;
    stroke(0); fill(175); pushMatrix(); rectMode(CENTER);              
    translate(location.x,location.y);
    rotate (angle); 
    rect(0,0,30,10);
    popMatrix();
}

我的代码:

void show() {
    angle = velocity.heading2D();
    rectMode(CENTER);
    pushMatrix();
    translate(location.x,location.y);
    rotate(angle);

    fill(255,20,20,150);
    rect(location.x,location.y,carSize,carSize);
    popMatrix();
}

设置和绘制:

Car car ;
void setup() {
    car = new Car();
}

void draw() {
    mouse = new PVector(mouseX,mouseY);
    background(255);
    car.show();
    car.move();
    car.update();
}

【问题讨论】:

  • 你能发一个minimal reproducible example吗?不要只发布没有任何 setup()draw() 函数的整个课程(这意味着我们无法运行您的代码),而是将您的问题缩小到几行示例代码。
  • 对不起,我改一下。
  • 另外,我不知道 translate(location.x,location.y) 是做什么的

标签: java animation rotation processing trigonometry


【解决方案1】:

我终于明白了。而不是

 translate(location.x,location.y);  
 rect(location.x,location.y,40,40);  

必须是:

 translate(location.x,location.y);  
 rect(0,0,40,40);    

因为翻译已经将原点指向对象的位置,这就是我要绘制它的位置 (0,0)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多