Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Ammo.btCompoundShape(子弹物理的JavaScript端口)?_Javascript_Bullet_Ammo.js - Fatal编程技术网

如何使用Ammo.btCompoundShape(子弹物理的JavaScript端口)?

如何使用Ammo.btCompoundShape(子弹物理的JavaScript端口)?,javascript,bullet,ammo.js,Javascript,Bullet,Ammo.js,我使用的是AMMO.JS,C++的子弹物理的JavaScript端口。不幸的是,如果你的语言是Python和JavaScript,文档是C++,而不是伟大的阅读。 我有这个想法,但我搞不懂 我这里有一个工作代码,骨骼实例正好从地板上掉下来,如您所见。不要担心“Bone”的命名,在开发的这个阶段,它只是用来测试两个块的复合形状 类渲染引擎{ 构造器(游戏引擎){ this.gameEngine=gameEngine this.gameEngine.clock=新的三个.clock(); this

我使用的是AMMO.JS,C++的子弹物理的JavaScript端口。不幸的是,如果你的语言是Python和JavaScript,文档是C++,而不是伟大的阅读。 我有这个想法,但我搞不懂

我这里有一个工作代码,
骨骼
实例正好从地板上掉下来,如您所见。不要担心“Bone”的命名,在开发的这个阶段,它只是用来测试两个块的复合形状

类渲染引擎{
构造器(游戏引擎){
this.gameEngine=gameEngine
this.gameEngine.clock=新的三个.clock();
this.scene=新的三个.scene();
this.scene.background=新的三种颜色(0xbfd1e5);
this.camera=新的三视角摄像机(60,window.innerWidth/window.innerHeight,0.25000);
此.摄像机.位置.设置(0,30,70);
这个.camera.lookAt(新的3.Vector3(0,0,0));
恒半球光=新的三个半球光(0xffffff,0xffffff,0.1);
半光.彩色.setHSL(0.6,0.6,0.6);
半光底色setHSL(0.1,1,0.4);
半光。位置。设置(0,50,0);
此.scene.add(半光);
常数dirLight=新的三个方向光(0xffffff,1);
dirLight.color.setHSL(0.1,1,0.95);
dirLight.position.set(-1,1.75,1);
多刻度直射位置(100);
this.scene.add(dirLight);
dirLight.castShadow=true;
dirLight.shadow.mapSize.width=2048;
dirLight.shadow.mapSize.height=2048;
常数d=50;
dirLight.shadow.camera.left=-d;
dirLight.shadow.camera.right=d;
dirLight.shadow.camera.top=d;
dirLight.shadow.camera.bottom=-d;
dirLight.shadow.camera.far=13500;
this.renderer=new THREE.WebGLRenderer({
反别名:对
});
this.renderer.setClearColor(0xbfd1e5);
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.setSize(window.innerWidth、window.innerHeight);
document.body.appendChild(this.renderer.doElement);
this.renderer.shadowMap.enabled=true;
}
renderFrame(){
this.renderer.render(this.scene,this.camera)
}
}
类物理引擎{
构造器(游戏引擎、物理引擎){
this.gameEngine=gameEngine
让collisionConfiguration=新弹药。btDefaultCollisionConfiguration(),
dispatcher=新弹药.btCollisionDispatcher(碰撞配置),
overlappingPairCache=新弹药。btDbvtBroadphase(),
解算器=新弹药。b顺序脉冲应变解算器();
this.tmpTrans=新弹药.btTransform();
this.physicsWorld=new Ammo.btDiscretedDynamicsworld(调度器、重叠pairCache、解算器、碰撞配置);
这个.physicsWorld.setGravity(新弹药.btVector3(0,-10,0));
}
UpdateName(){
this.physicsWorld.stepSimulation(this.gameEngine.clock.getDelta(),10);
this.gameEngine.objects.forEach(object=>{
常量ms=object.ammo.getMotionState()
如果(毫秒){
ms.getWorldTransform(this.tmpTrans)
const p=this.tmpTrans.getOrigin()
const q=this.tmpTrans.getRotation()
object.mesh.position.set(p.x(),p.y(),p.z())
object.mesh.quaternion.set(q.x(),q.y(),q.z(),q.w())
}
})
}
}
类游戏引擎{
构造函数(渲染引擎、物理引擎){
this.objects=[]
this.renderEngine=新renderEngine(this,renderEngine)
this.physicsEngine=新physicsEngine(this,physicsEngine)
}
运行(){
this.physicsEngine.updateName()
this.renderEngine.renderFrame()
requestAnimationFrame(()=>{
this.run()
});
}
添加(对象){
this.objects.push(对象)
返回this.objects.length-1
}
删除(objectIndex){
this.objects[objectIndex]=false
}
}
类框{
构造函数(游戏引擎、属性){
this.gameEngine=gameEngine
这是物理(属性)
此._initRendering_(属性)
this.id=gameEngine.add(此)
}
_初始物理(属性){
const pos=properties.pos
常量quat=properties.quat
const scale=properties.scale
常量质量=properties.mass
const group=properties.group
const interactionGroup=properties.interactionGroup
const physicsWorld=this.gameEngine.physicengine.physicsWorld
常量转换=新弹药。btTransform()
transform.setIdentity()
变换设置原点(新弹药btVector3(位置x、位置y、位置z))
变换.setRotation(新弹药.bt四元数(quat.x,quat.y,quat.z,quat.w))
常量运动状态=新弹药。btDefaultMotionState(转换)
const colShape=新弹药.btBoxShape(新弹药.btVector3(比例x*0.5,比例y*0.5,比例z*0.5))
colShape.setMargin(0.05)
const localInertia=新弹药。btVector3(0,0,0)
colShape.计算校准(质量、局部校准)
const rbInfo=新弹药。b刚体构型信息(质量、运动状态、形状、位置)
const body=新弹药。b刚体(rbInfo)
physicsWorld.addRigidBody(body、group、interactionGroup)
这个。弹药=尸体
}
_初始化(属性){
const pos=properties.pos
const scale=properties.scale
const color=properties.color
this.mesh=new THREE.mesh(new THREE.BoxBufferGeometry(),new THREE.MeshPhongMaterial({
颜色
}))
此网格位置设置(位置x、位置y、位置z)
this.mesh.scale.set(scale.x、scale.y、scale.z)
this.mesh.castShadow=true
this.mesh.receiveShadow=true
this.gameEngine.renderEngine.scene.add(this.mesh)
}
}
类骨{
构造函数(游戏引擎、属性){
this.gameEngine=gameEngine
这是物理(属性)
此._initRendering_(属性)
this.id=gameEngine.add(此)
}
_初始物理(属性){
const pos=properties.pos
常量quat=properties.quat
const scale=properties.scale
常量质量=properties.mass
const group=properties.group
const interactionGroup=properties.interactionGroup
常量物理世界=
transform.setOrigin(new Ammo.btVector3(0, 0, 2.0))
_addSection_(compoundShape, properties) {
    const transform = new Ammo.btTransform()
    transform.setIdentity()
    // -- disable second transform: --
    // transform.setOrigin(new Ammo.btVector3( ... ))
    // transform.setRotation(new Ammo.btQuaternion( ... ))

    const colShape = new Ammo.btBoxShape(new Ammo.btVector3(scale.x * 0.5, scale.y * 0.5, scale.z * 0.5))
    compoundShape.addChildShape(transform, colShape)
}