【问题标题】:Adding physics to a obj in processing在处理中将物理添加到 obj
【发布时间】:2014-06-05 08:10:29
【问题描述】:

所以我试图给一个 obj 一些物理特性,并处理处理附带的弹跳球的例子,我已经让它而不是一个球成为一个圆柱体,但我找不到使 obj 具有物理特性的方法。 我正在使用库 saito.objloader 导入 o​​bj。我有这段代码,是obj的调用

import processing.opengl.*;
import saito.objloader.*;

OBJModel modelCan;

PVector location;  // Location of shape
PVector velocity;  // Velocity of shape
PVector gravity;   // Gravity acts at the shape's acceleration

float rotX, rotY;

void setup() {
  size(1028, 768, OPENGL);
  frameRate(30);

  modelCan = new OBJModel(this, "can.obj", "absolute", TRIANGLES);
  modelCan.scale(50);
  modelCan.translateToCenter();
  modelCan.enableTexture();

  location = new PVector(100,100,100);
  velocity = new PVector(1.5,2.1,3);
  gravity = new PVector(0,0.2,0);
}

void draw() {
  background(129);
  lights();

  // Add velocity to the location.
  location.add(velocity);
  // Add gravity to velocity
  velocity.add(gravity);

  // Bounce off edges
  if ((location.x > width) || (location.x < 0)) {
    velocity.x = velocity.x * -1;
  }
  if (location.y > height) {
    // We're reducing velocity ever so slightly 
    // when it hits the bottom of the window
    velocity.y = velocity.y * -0.95; 
    location.y = height;
  }
  if (location.z < -height || location.z > 0) {  //note that Zaxis goes 'into' the screen
    velocity.z = velocity.z * -0.95; 
    //location.z = height;
  }

  println("location x: "+location.x);
  println("location y: "+location.y);
  println("location z: "+location.z);

  println("velocidad x: "+velocity.x);
  println("velocidad y: "+velocity.y);
  println("velocidad z: "+velocity.z);

  pushMatrix();
  translate(width/2, height/2, 0);
  modelCan.draw();
  popMatrix();
}

我希望你们能帮助我!谢谢!

【问题讨论】:

    标签: processing physics


    【解决方案1】:

    弹跳球的例子是一个非常简单的例子,我猜你不能以简单的方式将它应用到圆柱体上。

    您可能想看看这些网站:

    碰撞检测是在计算机时间内进行的:这意味着它与您的程序执行频率相关。例如,一个对象的速度可能非常大,以至于在两个渲染周期之间,您的第一个对象正在穿过您的第二个对象:不会发生碰撞检测。它们在上一个周期中没有碰撞,在当前周期中也没有碰撞。

    这就是为什么像Box2D 这样的物理“引擎”会尝试预测碰撞,计算每个对象的边界框。

    如果您想在 3D 中进行准确的碰撞检测,您可以查看在许多游戏和电影中使用的 Bullet 库:http://bulletphysics.org/wordpress/,但学习曲线可能会很大。

    在您的程序中,您可以尝试为碰撞检测设置阈值(并将对象的尺寸添加到其位置,如果您希望整个身体发生碰撞,而不仅仅是它的中心!):如果您的对象的位置介于您的限制和(您的限制 +/- 一个阈值)之间,认为它正在发生冲突,但您不会完全避免 tunnelling。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      相关资源
      最近更新 更多