java - gdx-bullet hello world 首次使用
问题描述
我正在尝试单独使用 gdx-bullet 并像在 cpp 中一样运行 hello world ,并且我得到的值从 0 到 2 甚至更高。
为什么在 jbullet 和 cpp 项目符号中工作正常,知道为什么它可能是setToTranslation
或字符串输出
图像。这是代码:
public static void main(String[] args) {
Bullet.init();
btCollisionConfiguration collisionConfig;
btCollisionDispatcher dispatcher;
btBroadphaseInterface overlappingPairCache;
btSequentialImpulseConstraintSolver solver;
btDiscreteDynamicsWorld dynamicWorld;
ArrayList<btCollisionShape> collisionShapes;
collisionShapes = new ArrayList<btCollisionShape>();
collisionConfig = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfig);
overlappingPairCache = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
dynamicWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfig);
dynamicWorld.setGravity(new Vector3(0, -10f, 0));
{
btCollisionShape groundShape = new btBoxShape(new Vector3(50.f, 50.f, 50.f));
collisionShapes.add(groundShape);
Matrix4 groundTransform = new Matrix4();
groundTransform.setToTranslation(new Vector3(0, -56, 0));
float mass = 0f;
boolean isDynamic = (mass != 0f);
Vector3 localInertia = new Vector3(0, 0, 0);
if (isDynamic)
groundShape.calculateLocalInertia(mass, localInertia);
btDefaultMotionState myMotionState = new btDefaultMotionState(groundTransform);
btRigidBodyConstructionInfo rbInfo = new btRigidBodyConstructionInfo(mass, myMotionState, groundShape,
localInertia);
btRigidBody body = new btRigidBody(rbInfo);
dynamicWorld.addRigidBody(body);
}
{
btCollisionShape colShape = new btSphereShape(1.f);
collisionShapes.add(colShape);
Matrix4 startTransform = new Matrix4();
startTransform.setToTranslation(new Vector3(2, 10, 0));
float mass = 1;
boolean isDynamic = (mass != 0f);
Vector3 localInertia = new Vector3(0, 0, 0);
if (isDynamic)
colShape.calculateLocalInertia(mass, localInertia);
btDefaultMotionState myMotionState = new btDefaultMotionState(startTransform);
btRigidBodyConstructionInfo rbInfo = new btRigidBodyConstructionInfo(mass, myMotionState, colShape,
localInertia);
btRigidBody body = new btRigidBody(rbInfo);
dynamicWorld.addRigidBody(body);
}
for (int i = 0; i < 150; i++) {
dynamicWorld.stepSimulation(1.f / 60.f, 10);
for (int j = dynamicWorld.getNumCollisionObjects() - 1; j >= 0; j--) {
btCollisionObject obj = dynamicWorld.getCollisionObjectArray().atConst(j);
btRigidBody body = (btRigidBody) obj;
if (body != null && body.getMotionState() != null) {
Matrix4 trans = new Matrix4();
body.getMotionState().getWorldTransform(trans);
System.out.println(
"world pos " + j + " = " + trans.val[12] + " , " + trans.val[13] + ", " + trans.val[14]);
}
}
}
collisionShapes.clear();
dynamicWorld.dispose();
overlappingPairCache.dispose();
dispatcher.dispose();
collisionConfig.dispose();
}
第二个角色对主角的感觉如何?
主角想对第二个角色说的话
解决方案
推荐阅读
- c++ - 使用 OpenGL ES glDrawElements 绘制正方形不起作用
- scala - 从 Uber Jar 中的资源加载 CSV 文件作为数据框
- generics - 在Java中是否可以调用兄弟类的受保护方法,其中兄弟具有不同的类型参数?
- google-apps-script - 即使脚本被授权,安装的触发器也会导致 Browser.inputBox 的权限错误
- javascript - 如何构建一个点击计数但仅显示带有反应组件的奇数的点击器?
- reactjs - React - Chrome 检查器显示正在添加/删除的元素,但更改在浏览器本身中不可见
- javascript - 在每个对象下方创建一个带有弹出窗口的动态列表(在 vue 中)
- unreal-engine4 - 如何在 UE4 中向特定方向发射光线?
- javascript - Appmaker:如何创建和访问全局变量?
- node.js - 使用 JWT Passport 的 NestJS 身份验证不起作用