게임 엔진을 만들려고하는데 플레이어가 제어하는 카메라를 원하고 Java에 다른 jBullet 엔티티가 영향을 주길 원합니다. 나는 키네틱 스틱 오브젝트을 사용할 것을 제안 받았다. 그래서 그들에 대해 살펴 보았다. 내가 이해할 수있는 문서를 찾을 수 없었다.jBullet에서 Kinematic Objects를 만들려면 어떻게해야합니까?
운동 물체를 설치하고 사용하는 방법을 설명하거나 내가 시작할 수있는 곳을 보여줄 수 있습니까?
게임 엔진을 만들려고하는데 플레이어가 제어하는 카메라를 원하고 Java에 다른 jBullet 엔티티가 영향을 주길 원합니다. 나는 키네틱 스틱 오브젝트을 사용할 것을 제안 받았다. 그래서 그들에 대해 살펴 보았다. 내가 이해할 수있는 문서를 찾을 수 없었다.jBullet에서 Kinematic Objects를 만들려면 어떻게해야합니까?
운동 물체를 설치하고 사용하는 방법을 설명하거나 내가 시작할 수있는 곳을 보여줄 수 있습니까?
KinematicCharacterController에 대한 설명서는 here이지만 전체적으로 도움이되지는 않지만 CharacterDemo의 소스가 될 수 있습니다. 데모에서 두 가지 주요 속성이 정의됩니다.
public KinematicCharacterController character;
public PairCachingGhostObject ghostObject;
고스트는 동적 충돌 감지에 사용할 수 있습니다. 자동 감지는 해당 이벤트에 자동으로 반응하지 않기 때문입니다. 문자는 변형을 변경하여 이동할 수 있습니다.
//from the source src\com\bulletphysics\demos\character\CharacterDemo.java
Transform startTransform = new Transform();
startTransform.setIdentity();
startTransform.origin.set(0.0f, 4.0f, 0.0f);
Vector3f worldMin = new Vector3f(-1000f,-1000f,-1000f);
Vector3f worldMax = new Vector3f(1000f,1000f,1000f);
AxisSweep3 sweepBP = new AxisSweep3(worldMin, worldMax);
ghostObject = new PairCachingGhostObject();
ghostObject.setWorldTransform(startTransform);
sweepBP.getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback());
float characterHeight = 1.75f * characterScale;
float characterWidth = 1.75f * characterScale;
ConvexShape capsule = new CapsuleShape(characterWidth, characterHeight);
ghostObject.setCollisionShape(capsule);
ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
float stepHeight = 0.35f * characterScale;
character = new KinematicCharacterController(ghostObject, capsule, stepHeight);
dynamicsWorld.addCollisionObject(ghostObject, CollisionFilterGroups.CHARACTER_FILTER, (short)(CollisionFilterGroups.STATIC_FILTER | CollisionFilterGroups.DEFAULT_FILTER));
dynamicsWorld.addAction(character);
또한이
public class MyMotionState extends MotionState {
private Transform worldTransform;
public MyMotionState()
{
worldTransform = new Transform();
worldTransform.setIdentity();
}
@Override
public Transform getWorldTransform(Transform worldTrans)
{
worldTrans.set(worldTransform);
return worldTrans;
}
@Override
public void setWorldTransform(Transform worldTrans)
{
worldTransform.set(worldTrans);
}
}
변환 유지하기 위해 MotionState 클래스를 확장하는 것이 현명하고 문자로 물리학을 적용하고, 렌더링에 대한 정보를 얻기 위해 강체로 동점을 연결하는 것입니다.
rigidBody.setCollisionFlags(rigidBody.getCollisionFlags() | CollisionFlags.KINEMATIC_OBJECT);
rigidBody.setActivationState(CollisionObject.DISABLE_DEACTIVATION);
게임 루프를 반복 할 때마다 물리 엔진을 한 번 업데이트해야합니다. 원하는 경우
Transform transform = new Transform();
transform.setIdentity();
transform.origin.set(input.getX(), input.getY(), input.getZ());
myMotionState.setWorldTransform(transform);
rigidBody.setCenterOfMassTransform(myMotionState.getWorldTransform());
, 당신은 내가 도움이 희망
public class MainCharacter implements KeyListener, MouseListener
{
private DynamicsWorld world;
private MyMotionState myMotionState;
private RigidBody rigidBody;
private KinematicCharacterController character;
private ConvexShape shape;
private Texture texture;
private GhostObject ghost;
private Vector3f pos;
public MainCharacter(DynamicsWorld world, Vector3f initialPosition, ConvexShape shape, Texture texture)
{
this.world = world;
RigidBodyConstructionInfo constructInfo = new RigidBodyConstructionInfo(...);
this.myMotionState = myMotionState;
rigidBody = new RigidBody(constructInfo);
ghost = new GhostObject();
character = new KinematicCharacterController(ghost,shape,1);
}
public void render()
{
glBegin(GL_QUADS);
glVertex3f(...
...
glEnd();
}
public void mouseMoved(MouseEvent e)
{
//pseudocode
this.yaw = e.getDX();
this.pitch = e.getDY();
}
public void keyPressed(KeyEvent e)
{
Vector3f dPos = null;
if(e.getKeyChar() == 'W')
{
dPos.x = 10;
}
else if(e.getKeyChar() == 'S')
{
dPos.x = -10;
}
etc...
move(dPos.x,dPos.y,dPos.z);
}
public void move(float dx, float dy, float dz) {
pos.z += dx * (float) Math.cos(Math.toRadians(yaw - 90)) + dz * Math.cos(Math.toRadians(yaw));
pos.x -= dx * (float) Math.sin(Math.toRadians(yaw - 90)) + dz * Math.sin(Math.toRadians(yaw));
pos.y += dy * (float) Math.sin(Math.toRadians(pitch - 90)) + dz * Math.sin(Math.toRadians(pitch));
//pseudocode
rigidBody.update(pos);
world.update(pos);
}
}
또는 당신이 그것을 호출 어떤 (필자는 객체 지향 느낌을 위해 그것을 좋아하고 이해하기 쉽게) 귀하의 MainCharacter 클래스에 다음을 넣어 수 당신.
"변환을 유지하기 위해 MotionState 클래스를 확장하는 것이 좋습니다" 어떻게해야합니까? – Sierox
전체 MyMotionState 클래스를 표시하도록 편집되었습니다. 또한 MotionState는 루프 반복마다 데이터를 세계로 보냅니다. 따라서 자신 만의 데이터가있는 경우 해당 데이터 (즉, 위치)를 변경할 수 있습니다. – user2727804
왜이 것이 다운 되었습니까? – Prior99