Processing 在处理过程中将物理添加到obj中
所以我试着给一个物体一些物理知识,并以处理过程中的弹跳球为例,我把它变成一个圆柱体,而不是一个球,但我找不到让物体有物理知识的方法。 我正在使用库saito.objloader导入obj。我有这个代码,它是对obj的调用Processing 在处理过程中将物理添加到obj中,processing,physics,Processing,Physics,所以我试着给一个物体一些物理知识,并以处理过程中的弹跳球为例,我把它变成一个圆柱体,而不是一个球,但我找不到让物体有物理知识的方法。 我正在使用库saito.objloader导入obj。我有这个代码,它是对obj的调用 import processing.opengl.*; import saito.objloader.*; OBJModel modelCan; PVector location; // Location of shape PVector velocity; // Ve
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();
}
import processing.opengl.*;
导入saito.objloader.*;
OBJModel-modelCan;
PVector位置;//形状的位置
PVector速度;//形状速度
PVector重力;//重力作用于形状的加速度
浮子rotX,rotY;
无效设置(){
大小(1028768,OPENGL);
帧率(30);
modelCan=新的OBJModel(这是“can.obj”、“绝对”三角形);
模型罐比例(50);
modelCan.translateToCenter();
modelCan.enableTexture();
位置=新的PVector(100100);
速度=新PVector(1.5,2.1,3);
重力=新PVector(0,0.2,0);
}
作废提款(){
背景(129);
灯光();
//将速度添加到位置。
位置。添加(速度);
//给速度加上重力
速度加(重力);
//从边缘反弹
if((location.x>width)| |(location.x<0)){
速度x=速度x*-1;
}
如果(位置y>高度){
//我们稍微降低了速度
//当它碰到窗户底部时
速度y=速度y*-0.95;
位置y=高度;
}
如果(location.z<-height | | | location.z>0){//请注意,Zaxis进入屏幕
速度z=速度z*-0.95;
//位置z=高度;
}
println(“位置x:+location.x”);
println(“位置y:+location.y”);
println(“位置z:+location.z”);
println(“velocidad x:+velocity.x”);
println(“velocidad y:+velocity.y”);
println(“velocidad z:+velocity.z”);
pushMatrix();
平移(宽度/2,高度/2,0);
modelCan.draw();
popMatrix();
}
我希望你们能帮助我!谢谢 弹跳球的例子是一个非常简单的例子,我想你不能简单地把它应用到圆柱体上 您可能需要查看以下网站:
- (他的书很重要)
- (再次:丹尼尔·希夫曼)
在你的程序中,你可以尝试给你的碰撞检测出一个阈值(如果你想让整个物体碰撞,而不仅仅是它的中心!):如果你的物体的位置在你的极限和(你的极限+/-阈值)之间,它会发生碰撞,但是你不会完全避免。p>