Tôi đang cố gắng tìm hiểu cách sử dụng jBullet trong một dự án mà tôi đang làm việc và tôi đã xem xét bản demo mà nguồn cung cấp nhưng tôi không thể tìm ra cách các bản demo này hiển thị đối tượng. Có ai có một nguồn lực tốt họ có thể chỉ cho tôi hoặc cung cấp một ví dụ cơ bản hiển thị một hoặc hai đối tượng trên màn hình?Ví dụ jBullet
Cảm ơn bạn trước, tôi xin lỗi tôi không có bất kỳ mã nào để hiển thị tôi có thể nhanh chóng viết lên một số nếu cần nhưng chỉ thực sự tìm kiếm hướng đi.
Cảm ơn bạn,
Mã cho Cube mà tôi đang sử dụng, vì vậy tôi đang cố gắng để thêm va chạm với nó, nhưng tôi không chắc chắn cách sử dụng jbullet:
public void Draw() {
// center point posX, posY, posZ
float radius = size/2;
//top
glPushMatrix();
glBegin(GL_QUADS);
{
glColor3f(1.0f,0.0f,0.0f); // red
glVertex3f(posX + radius, posY + radius, posZ - radius);
glVertex3f(posX - radius, posY + radius, posZ - radius);
glVertex3f(posX - radius, posY + radius, posZ + radius);
glVertex3f(posX + radius, posY + radius, posZ + radius);
}
glEnd();
glPopMatrix();
//bottom
glPushMatrix();
glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,0.0f); // ?? color
glVertex3f(posX + radius, posY - radius, posZ + radius);
glVertex3f(posX - radius, posY - radius, posZ + radius);
glVertex3f(posX - radius, posY - radius, posZ - radius);
glVertex3f(posX + radius, posY - radius, posZ - radius);
}
glEnd();
glPopMatrix();
//right side
glPushMatrix();
glBegin(GL_QUADS);
{
glColor3f(1.0f,0.0f,1.0f); // ?? color
glVertex3f(posX + radius, posY + radius, posZ + radius);
glVertex3f(posX + radius, posY - radius, posZ + radius);
glVertex3f(posX + radius, posY - radius, posZ - radius);
glVertex3f(posX + radius, posY + radius, posZ - radius);
}
glEnd();
glPopMatrix();
//left side
glPushMatrix();
glBegin(GL_QUADS);
{
glColor3f(0.0f,1.0f,1.0f); // ?? color
glVertex3f(posX - radius, posY + radius, posZ - radius);
glVertex3f(posX - radius, posY - radius, posZ - radius);
glVertex3f(posX - radius, posY - radius, posZ + radius);
glVertex3f(posX - radius, posY + radius, posZ + radius);
}
glEnd();
glPopMatrix();
//front side
glPushMatrix();
glBegin(GL_QUADS);
{
glColor3f(0.0f,0.0f,1.0f); //blue
glVertex3f(posX + radius, posY + radius, posZ + radius);
glVertex3f(posX - radius, posY + radius, posZ + radius);
glVertex3f(posX - radius, posY - radius, posZ + radius);
glVertex3f(posX + radius, posY - radius, posZ + radius);
}
glEnd();
glPopMatrix();
//back side
glPushMatrix();
glBegin(GL_QUADS);
{
glColor3f(0.0f,1.0f,0.0f); // green
glVertex3f(posX + radius, posY - radius, posZ - radius);
glVertex3f(posX - radius, posY - radius, posZ - radius);
glVertex3f(posX - radius, posY + radius, posZ - radius);
glVertex3f(posX + radius, posY + radius, posZ - radius);
}
glEnd();
glPopMatrix();
}
Đây là mã chuyển đổi của tôi từ mã kiểm tra hello world, điều này có đúng với mọi người không? :
public static void HelloWorld() {
BroadphaseInterface broadphase = new DbvtBroadphase();
DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);
SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();
DiscreteDynamicsWorld dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
// set the gravity of our world
dynamicsWorld.setGravity(new Vector3f(0, -10, 0));
// setup our collision shapes
CollisionShape groundShape = new StaticPlaneShape(new Vector3f(0, 1, 0), 1);
CollisionShape fallShape = new SphereShape(1);
// setup the motion state
DefaultMotionState groundMotionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, -1, 0), 1.0f)));
RigidBodyConstructionInfo groundRigidBodyCI = new RigidBodyConstructionInfo(0, groundMotionState, groundShape, new Vector3f(0,0,0));
RigidBody groundRigidBody = new RigidBody(groundRigidBodyCI);
dynamicsWorld.addRigidBody(groundRigidBody); // add our ground to the dynamic world..
// setup the motion state for the ball
DefaultMotionState fallMotionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, 50, 0), 1.0f)));
//This we're going to give mass so it responds to gravity
int mass = 1;
Vector3f fallInertia = new Vector3f(0,0,0);
fallShape.calculateLocalInertia(mass,fallInertia);
RigidBodyConstructionInfo fallRigidBodyCI = new RigidBodyConstructionInfo(mass,fallMotionState,fallShape,fallInertia);
RigidBody fallRigidBody = new RigidBody(fallRigidBodyCI);
//now we add it to our physics simulation
dynamicsWorld.addRigidBody(fallRigidBody);
for (int i=0 ; i<300 ; i++) {
dynamicsWorld.stepSimulation(1/60.f, 10);
Transform trans = new Transform();
fallRigidBody.getMotionState().getWorldTransform(trans);
System.out.println("sphere height: " + trans.origin.y);
}
}
lẽ bạn có thể liên kết đến các bản demo bạn đang tìm kiếm tại? – theJollySin
Tôi đang xem các bản trình diễn có trong thư viện, tôi xin lỗi nhưng họ không liên kết chúng với nhau. Tôi sẽ đăng mã nhưng nó được chia thành nhiều tập tin lớp, và sẽ là cồng kềnh để làm ở đây.Tôi đã xem qua các hướng dẫn viên đạn, nhưng chúng thực sự không áp dụng tốt cho jBullet vì tên hàm là khác nhau: http://bulletphysics.org/mediawiki-1.5.8/index.php/Hello_World – Kenneth
Nếu bạn đang nói về việc hiển thị thông tin gỡ lỗi vật lý trên màn hình, bạn sẽ cần phải triển khai lớp 'IDebugDraw' của riêng bạn. Nếu bạn đang nói về việc vẽ các đối tượng mà bạn muốn được kiểm soát bởi vật lý, bạn làm điều đó mà không có thư viện vật lý nào có liên quan gì cả. jBullet chỉ nên được sử dụng để kiểm soát vật lý của đối tượng của bạn, tức là di chuyển chúng xung quanh và va chạm với nhau. Vẽ các mô hình hoặc đối tượng của bạn phải được thực hiện bằng mã của riêng bạn. Nếu bạn xác định những gì bạn đang cố gắng làm tôi sẽ cung cấp một câu trả lời về cách làm điều đó. – MichaelHouse