本文整理汇总了Java中com.bulletphysics.collision.dispatch.PairCachingGhostObject类的典型用法代码示例。如果您正苦于以下问题:Java PairCachingGhostObject类的具体用法?Java PairCachingGhostObject怎么用?Java PairCachingGhostObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PairCachingGhostObject类属于com.bulletphysics.collision.dispatch包,在下文中一共展示了PairCachingGhostObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPhysics
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
@Override
public void initPhysics() {
Transform startTranform = new Transform();
startTranform.setIdentity();
startTranform.origin.set(5, -35, -4);
collisionShape = new CapsuleShape(0.5f, 1);
ghostObject = new PairCachingGhostObject();
ghostObject.setWorldTransform(startTranform);
// set getOverlappingPairCache & setInternalGhostPairCallback
ghostObject.setCollisionShape(collisionShape);
ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
characterController = new KinematicCharacterController(ghostObject, collisionShape, 0.5f);
characterController.setGravity(10);
characterController.setMaxJumpHeight(1.5f);
}
示例2: KinematicCharacterController
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
public KinematicCharacterController (PairCachingGhostObject ghostObject, ConvexShape convexShape, float stepHeight,
int upAxis) {
this.upAxis = upAxis;
this.addedMargin = 0.02f;
this.walkDirection.set(0, 0, 0);
this.useGhostObjectSweepTest = true;
this.ghostObject = ghostObject;
this.stepHeight = stepHeight;
this.turnAngle = 0.0f;
this.convexShape = convexShape;
this.useWalkDirection = true;
this.velocityTimeInterval = 0.0f;
this.verticalVelocity = 0.0f;
this.verticalOffset = 0.0f;
this.gravity = 9.8f; // 1G acceleration
this.fallSpeed = 55.0f; // Terminal velocity of a sky diver in m/s.
this.jumpSpeed = 10.0f; // ?
this.wasOnGround = false;
setMaxSlope((float)((50.0f / 180.0f) * Math.PI));
}
示例3: KinematicCharacterController
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
public KinematicCharacterController(PairCachingGhostObject ghostObject, ConvexShape convexShape, float stepHeight, int upAxis) {
this.upAxis = upAxis;
this.addedMargin = 0.02f;
this.walkDirection.set(0, 0, 0);
this.useGhostObjectSweepTest = true;
this.ghostObject = ghostObject;
this.stepHeight = stepHeight;
this.turnAngle = 0.0f;
this.convexShape = convexShape;
this.useWalkDirection = true;
this.velocityTimeInterval = 0.0f;
this.verticalVelocity = 0.0f;
this.verticalOffset = 0.0f;
this.gravity = 9.8f; // 1G acceleration
this.fallSpeed = 55.0f; // Terminal velocity of a sky diver in m/s.
this.jumpSpeed = 10.0f; // ?
this.wasOnGround = false;
setMaxSlope((float)((50.0f/180.0f) * Math.PI));
}
示例4: updateTrigger
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
@ReceiveEvent(components = {TriggerComponent.class, LocationComponent.class})
public void updateTrigger(ChangedComponentEvent event, EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
PairCachingGhostObject triggerObj = entityTriggers.get(entity);
if (triggerObj != null) {
float scale = location.getWorldScale();
if (Math.abs(triggerObj.getCollisionShape().getLocalScaling(new Vector3f()).x - scale) > BulletGlobals.SIMD_EPSILON) {
physics.removeCollider(triggerObj);
createTrigger(entity);
} else {
triggerObj.setWorldTransform(new Transform(new Matrix4f(location.getWorldRotation(), location.getWorldPosition(), 1.0f)));
}
}
// TODO: update if detectGroups changed
}
示例5: initPhysics
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
public void initPhysics() throws Exception {
CollisionShape groundShape = new BoxShape(new Vector3f(50, 3, 50));
collisionShapes.add(groundShape);
collisionConfiguration = new DefaultCollisionConfiguration();
dispatcher = new CollisionDispatcher(collisionConfiguration);
Vector3f worldMin = new Vector3f(-1000f,-1000f,-1000f);
Vector3f worldMax = new Vector3f(1000f,1000f,1000f);
AxisSweep3 sweepBP = new AxisSweep3(worldMin, worldMax);
overlappingPairCache = sweepBP;
constraintSolver = new SequentialImpulseConstraintSolver();
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher,overlappingPairCache,constraintSolver,collisionConfiguration);
Transform startTransform = new Transform();
startTransform.setIdentity();
startTransform.origin.set(0.0f, 4.0f, 0.0f);
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);
new BspToBulletConverter().convertBsp(getClass().getResourceAsStream("/com/bulletphysics/demos/bsp/exported.bsp.txt"));
dynamicsWorld.addCollisionObject(ghostObject, CollisionFilterGroups.CHARACTER_FILTER, (short)(CollisionFilterGroups.STATIC_FILTER | CollisionFilterGroups.DEFAULT_FILTER));
dynamicsWorld.addAction(character);
clientResetScene();
setCameraDistance(56f);
}
示例6: KinematicCharacterControllerComponent
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
public KinematicCharacterControllerComponent(boolean gravity, float radius, float height, float stepHeight, Vector3f position, int jumpKey, int forwardKey, int backKey, int leftKey, int rightKey) {
shape = new CapsuleShape(radius,height);
ghostObject = new PairCachingGhostObject();
ghostObject.setWorldTransform(PhysicsSystem.createTransform(position, null));
ghostObject.setCollisionShape(shape);
ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
// http://hub.jmonkeyengine.org/javadoc/com/jme3/bullet/control/BetterCharacterControl.html
character = new KinematicCharacterController(ghostObject,shape ,stepHeight);
if (gravity) {
character.setJumpSpeed(5.0f);
character.setFallSpeed(500.0f);
} else {
character.setJumpSpeed(0.0f);
character.setFallSpeed(0.0f);
character.setGravity(0);
}
this.gravity = gravity;
PhysicsSystem.getWorld().addCollisionObject(ghostObject,CollisionFilterGroups.CHARACTER_FILTER,(short)(CollisionFilterGroups.STATIC_FILTER | CollisionFilterGroups.DEFAULT_FILTER));
PhysicsSystem.getWorld().addAction(character);
this.jumpKey = jumpKey;
this.forwardKey = forwardKey;
this.backKey = backKey;
this.leftKey = leftKey;
this.rightKey = rightKey;
this.height = height;
initFeet();
lastWalkPosition.set(position);
wasOnGround = character.onGround();
}
示例7: createTrigger
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
private void createTrigger(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
TriggerComponent trigger = entity.getComponent(TriggerComponent.class);
ConvexShape shape = getShapeFor(entity);
if (shape != null) {
float scale = location.getWorldScale();
shape.setLocalScaling(new Vector3f(scale, scale, scale));
List<CollisionGroup> detectGroups = Lists.newArrayList(trigger.detectGroups);
PairCachingGhostObject triggerObj = physics.createCollider(location.getWorldPosition(), shape, Lists.<CollisionGroup>newArrayList(StandardCollisionGroup.SENSOR), detectGroups, CollisionFlags.NO_CONTACT_RESPONSE);
triggerObj.setUserPointer(entity);
entityTriggers.put(entity, triggerObj);
}
}
示例8: createCollider
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
private PairCachingGhostObject createCollider(Vector3f pos, ConvexShape shape, short groups, short filters, int collisionFlags) {
Transform startTransform = new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), pos, 1.0f));
PairCachingGhostObject result = new PairCachingGhostObject();
result.setWorldTransform(startTransform);
result.setCollisionShape(shape);
result.setCollisionFlags(collisionFlags);
_discreteDynamicsWorld.addCollisionObject(result, groups, filters);
return result;
}
示例9: move
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
private MoveResult move(Vector3f startPosition, Vector3f moveDelta, float stepHeight, float slopeFactor, PairCachingGhostObject collider) {
steppedUpDist = 0;
stepped = false;
MoveResult result = new MoveResult();
Vector3f position = new Vector3f(startPosition);
result.finalPosition = position;
// Actual upwards movement
if (moveDelta.y > 0) {
result.hitTop = moveDelta.y - moveUp(moveDelta.y, collider, position) > BulletGlobals.SIMD_EPSILON;
}
result.hitHoriz = moveHorizontal(new Vector3f(moveDelta.x, 0, moveDelta.z), collider, position, slopeFactor, stepHeight);
if (moveDelta.y < 0 || steppedUpDist > 0) {
float dist = (moveDelta.y < 0) ? moveDelta.y : 0;
dist -= steppedUpDist;
result.hitBottom = moveDown(dist, slopeFactor, collider, position);
}
if (!result.hitBottom && stepHeight > 0) {
Vector3f tempPos = new Vector3f(position);
result.hitBottom = moveDown(-stepHeight, slopeFactor, collider, tempPos);
// Don't apply step down if nothing to step onto
if (result.hitBottom) {
position.set(tempPos);
}
}
return result;
}
示例10: checkStep
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
private boolean checkStep(PairCachingGhostObject collider, Vector3f position, Vector3f direction, SweepCallback callback, float slopeFactor, float stepHeight) {
if (!stepped) {
stepped = true;
Vector3f lookAheadOffset = new Vector3f(direction);
lookAheadOffset.y = 0;
lookAheadOffset.normalize();
lookAheadOffset.scale(CHECK_FORWARD_DIST);
boolean hitStep = false;
float stepSlope = 1f;
Vector3f fromWorld = new Vector3f(callback.hitPointWorld);
fromWorld.y += stepHeight + 0.05f;
fromWorld.add(lookAheadOffset);
Vector3f toWorld = new Vector3f(callback.hitPointWorld);
toWorld.y -= 0.05f;
toWorld.add(lookAheadOffset);
CollisionWorld.ClosestRayResultCallback rayResult = new CollisionWorld.ClosestRayResultCallback(fromWorld, toWorld);
CollisionWorld.rayTestSingle(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), fromWorld, 1.0f)), new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), toWorld, 1.0f)), callback.hitCollisionObject, callback.hitCollisionObject.getCollisionShape(), callback.hitCollisionObject.getWorldTransform(new Transform()), rayResult);
if (rayResult.hasHit()) {
hitStep = true;
stepSlope = rayResult.hitNormalWorld.dot(new Vector3f(0, 1, 0));
}
fromWorld.add(lookAheadOffset);
toWorld.add(lookAheadOffset);
rayResult = new CollisionWorld.ClosestRayResultCallback(fromWorld, toWorld);
CollisionWorld.rayTestSingle(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), fromWorld, 1.0f)), new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), toWorld, 1.0f)), callback.hitCollisionObject, callback.hitCollisionObject.getCollisionShape(), callback.hitCollisionObject.getWorldTransform(new Transform()), rayResult);
if (rayResult.hasHit()) {
hitStep = true;
stepSlope = Math.min(stepSlope, rayResult.hitNormalWorld.dot(new Vector3f(0, 1, 0)));
}
if (hitStep && stepSlope >= slopeFactor) {
steppedUpDist = moveUp(stepHeight, collider, position);
return true;
}
}
return false;
}
示例11: getObjectId
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
/**
* used internally
*/
public PairCachingGhostObject getObjectId() {
return gObject;
}
示例12: getGhostObject
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
private PairCachingGhostObject getGhostObject () {
return ghostObject;
}
示例13: getGhostObject
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
private PairCachingGhostObject getGhostObject() {
return ghostObject;
}
示例14: setGhostObject
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
public void setGhostObject(PairCachingGhostObject ghostObject) {
this.ghostObject = ghostObject;
}
示例15: getGhostObject
import com.bulletphysics.collision.dispatch.PairCachingGhostObject; //导入依赖的package包/类
/**
*
* @return
*/
public PairCachingGhostObject getGhostObject() {
return this.ghostObject;
}