本文整理汇总了Java中com.bulletphysics.collision.shapes.StaticPlaneShape类的典型用法代码示例。如果您正苦于以下问题:Java StaticPlaneShape类的具体用法?Java StaticPlaneShape怎么用?Java StaticPlaneShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StaticPlaneShape类属于com.bulletphysics.collision.shapes包,在下文中一共展示了StaticPlaneShape类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get_plane_equation_transformed
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public static void get_plane_equation_transformed(StaticPlaneShape shape, Transform trans, Vector4f equation) {
get_plane_equation(shape, equation);
Vector3f tmp = Stack.alloc(Vector3f.class);
trans.basis.getRow(0, tmp);
float x = VectorUtil.dot3(tmp, equation);
trans.basis.getRow(1, tmp);
float y = VectorUtil.dot3(tmp, equation);
trans.basis.getRow(2, tmp);
float z = VectorUtil.dot3(tmp, equation);
float w = VectorUtil.dot3(trans.origin, equation) + equation.w;
equation.set(x, y, z, w);
}
示例2: getBulletShape
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
@Override
public CollisionShape getBulletShape() {
// Make sure the shape is configured
if(this.bulletShape == null) {
// Determine the size of the shape
Vector3f shapeSize = new Vector3f();
switch(this.orientation) {
case QuadMeshGenerator.ORIENTATION_X_POSITIVE:
case QuadMeshGenerator.ORIENTATION_X_NEGATIVE:
shapeSize.x = this.thickness / 2.0f;
shapeSize.y = this.size.x / 2.0f;
shapeSize.z = this.size.y / 2.0f;
break;
case QuadMeshGenerator.ORIENTATION_Y_POSITIVE:
case QuadMeshGenerator.ORIENTATION_Y_NEGATIVE:
shapeSize.x = this.size.x / 2.0f;
shapeSize.y = this.thickness / 2.0f;
shapeSize.z = this.size.y / 2.0f;
break;
case QuadMeshGenerator.ORIENTATION_Z_POSITIVE:
case QuadMeshGenerator.ORIENTATION_Z_NEGATIVE:
shapeSize.x = this.size.x / 2.0f;
shapeSize.y = this.size.y / 2.0f;
shapeSize.z = this.thickness / 2.0f;
break;
}
// Construct the shape
this.bulletShape = new BoxShape(shapeSize);
// FIXME: Temporarily using a static plane, for better results!
this.bulletShape = new StaticPlaneShape(new Vector3f(0, 1, 0), 0.1f);
}
// Return the shape
return this.bulletShape;
}
示例3: get_plane_equation
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public static void get_plane_equation (StaticPlaneShape shape, Quaternion equation) {
Stack stack = Stack.enter();
Vector3 tmp = stack.allocVector3();
equation.set(shape.getPlaneNormal(tmp), 0);
equation.w = shape.getPlaneConstant();
stack.leave();
}
示例4: get_plane_equation
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public static void get_plane_equation(StaticPlaneShape shape, Vector4f equation) {
Vector3f tmp = Stack.alloc(Vector3f.class);
equation.set(shape.getPlaneNormal(tmp));
equation.w = shape.getPlaneConstant();
}
示例5: createShape
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
protected void createShape() {
cShape = new StaticPlaneShape(Converter.convert(plane.getNormal()),plane.getConstant());
cShape.setLocalScaling(Converter.convert(getScale()));
cShape.setMargin(margin);
}
示例6: processCollision
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
@Override
public void processCollision (CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo,
ManifoldResult resultOut) {
if (manifoldPtr == null) {
return;
}
Stack stack = Stack.enter();
Transform tmpTrans = stack.allocTransform();
CollisionObject convexObj = isSwapped ? body1 : body0;
CollisionObject planeObj = isSwapped ? body0 : body1;
ConvexShape convexShape = (ConvexShape)convexObj.getCollisionShape();
StaticPlaneShape planeShape = (StaticPlaneShape)planeObj.getCollisionShape();
boolean hasCollision = false;
Vector3 planeNormal = planeShape.getPlaneNormal(stack.allocVector3());
float planeConstant = planeShape.getPlaneConstant();
Transform planeInConvex = stack.allocTransform();
convexObj.getWorldTransform(planeInConvex);
planeInConvex.inverse();
planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));
Transform convexInPlaneTrans = stack.allocTransform();
convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));
Vector3 tmp = stack.allocVector3();
tmp.set(planeNormal).scl(-1);
tmp.mul(planeInConvex.basis);
Vector3 vtx = convexShape.localGetSupportingVertex(tmp, stack.allocVector3());
Vector3 vtxInPlane = stack.alloc(vtx);
convexInPlaneTrans.transform(vtxInPlane);
float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
Vector3 vtxInPlaneProjected = stack.allocVector3();
tmp.set(planeNormal).scl(distance);
vtxInPlaneProjected.set(vtxInPlane).sub(tmp);
Vector3 vtxInPlaneWorld = stack.alloc(vtxInPlaneProjected);
planeObj.getWorldTransform(tmpTrans).transform(vtxInPlaneWorld);
hasCollision = distance < manifoldPtr.getContactBreakingThreshold();
resultOut.setPersistentManifold(manifoldPtr);
if (hasCollision) {
// report a contact. internally this will be kept persistent, and contact reduction is done
Vector3 normalOnSurfaceB = stack.alloc(planeNormal);
normalOnSurfaceB.mul(planeObj.getWorldTransform(tmpTrans).basis);
Vector3 pOnB = stack.alloc(vtxInPlaneWorld);
resultOut.addContactPoint(normalOnSurfaceB, pOnB, distance);
}
if (ownManifold) {
if (manifoldPtr.getNumContacts() != 0) {
resultOut.refreshContactPoints();
}
}
stack.leave();
}
示例7: gimpacttrimeshpart_vs_plane_collision
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
Stack stack = Stack.enter();
Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
StaticPlaneShape planeshape = shape1;
Quaternion plane = stack.allocQuaternion();
PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
// test box against plane
AABB tribox = stack.allocAABB();
shape0.getAabb(orgtrans0, tribox.min, tribox.max);
tribox.increment_margin(planeshape.getMargin());
if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
return;
}
shape0.lockChildShapes();
float margin = shape0.getMargin() + planeshape.getMargin();
Vector3 vertex = stack.allocVector3();
Vector3 tmp = stack.allocVector3();
int vi = shape0.getVertexCount();
while ((vi--) != 0) {
shape0.getVertex(vi, vertex);
orgtrans0.transform(vertex);
float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
if (distance < 0f)//add contact
{
if (swapped) {
tmp.set(-plane.x, -plane.y, -plane.z);
addContactPoint(body1, body0, vertex, tmp, distance);
}
else {
tmp.set(plane.x, plane.y, plane.z);
addContactPoint(body0, body1, vertex, tmp, distance);
}
}
}
shape0.unlockChildShapes();
stack.leave();
}
示例8: PlaneCollider
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public PlaneCollider(Vector4f normal, float buffer) {
setCollisionShape(new StaticPlaneShape(new Vector3f(normal.x, normal.y, normal.z), buffer));
}
示例9: processCollision
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
@Override
public void processCollision(CollisionObject body0, CollisionObject body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
if (manifoldPtr == null) {
return;
}
Transform tmpTrans = Stack.alloc(Transform.class);
CollisionObject convexObj = isSwapped ? body1 : body0;
CollisionObject planeObj = isSwapped ? body0 : body1;
ConvexShape convexShape = (ConvexShape) convexObj.getCollisionShape();
StaticPlaneShape planeShape = (StaticPlaneShape) planeObj.getCollisionShape();
boolean hasCollision = false;
Vector3f planeNormal = planeShape.getPlaneNormal(Stack.alloc(Vector3f.class));
float planeConstant = planeShape.getPlaneConstant();
Transform planeInConvex = Stack.alloc(Transform.class);
convexObj.getWorldTransform(planeInConvex);
planeInConvex.inverse();
planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));
Transform convexInPlaneTrans = Stack.alloc(Transform.class);
convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));
Vector3f tmp = Stack.alloc(Vector3f.class);
tmp.negate(planeNormal);
planeInConvex.basis.transform(tmp);
Vector3f vtx = convexShape.localGetSupportingVertex(tmp, Stack.alloc(Vector3f.class));
Vector3f vtxInPlane = Stack.alloc(vtx);
convexInPlaneTrans.transform(vtxInPlane);
float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
Vector3f vtxInPlaneProjected = Stack.alloc(Vector3f.class);
tmp.scale(distance, planeNormal);
vtxInPlaneProjected.sub(vtxInPlane, tmp);
Vector3f vtxInPlaneWorld = Stack.alloc(vtxInPlaneProjected);
planeObj.getWorldTransform(tmpTrans).transform(vtxInPlaneWorld);
hasCollision = distance < manifoldPtr.getContactBreakingThreshold();
resultOut.setPersistentManifold(manifoldPtr);
if (hasCollision) {
// report a contact. internally this will be kept persistent, and contact reduction is done
Vector3f normalOnSurfaceB = Stack.alloc(planeNormal);
planeObj.getWorldTransform(tmpTrans).basis.transform(normalOnSurfaceB);
Vector3f pOnB = Stack.alloc(vtxInPlaneWorld);
resultOut.addContactPoint(normalOnSurfaceB, pOnB, distance);
}
if (ownManifold) {
if (manifoldPtr.getNumContacts() != 0) {
resultOut.refreshContactPoints();
}
}
}
示例10: gimpacttrimeshpart_vs_plane_collision
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
Transform orgtrans0 = body0.getWorldTransform(Stack.alloc(Transform.class));
Transform orgtrans1 = body1.getWorldTransform(Stack.alloc(Transform.class));
StaticPlaneShape planeshape = shape1;
Vector4f plane = Stack.alloc(Vector4f.class);
PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
// test box against plane
AABB tribox = Stack.alloc(AABB.class);
shape0.getAabb(orgtrans0, tribox.min, tribox.max);
tribox.increment_margin(planeshape.getMargin());
if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
return;
}
shape0.lockChildShapes();
float margin = shape0.getMargin() + planeshape.getMargin();
Vector3f vertex = Stack.alloc(Vector3f.class);
Vector3f tmp = Stack.alloc(Vector3f.class);
int vi = shape0.getVertexCount();
while ((vi--) != 0) {
shape0.getVertex(vi, vertex);
orgtrans0.transform(vertex);
float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
if (distance < 0f)//add contact
{
if (swapped) {
tmp.set(-plane.x, -plane.y, -plane.z);
addContactPoint(body1, body0, vertex, tmp, distance);
}
else {
tmp.set(plane.x, plane.y, plane.z);
addContactPoint(body0, body1, vertex, tmp, distance);
}
}
}
shape0.unlockChildShapes();
}
示例11: Ground
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public Ground(Screen screen) {
float size = 100000;
ObjLoader loader = new ObjLoader();
//loader.load("res/snow/snow_terrain.obj");
Model groundModel = new Model();
groundModel.useShader(ShaderProgram.textureShader);
Mesh groundMesh = new Mesh();
groundMesh.setTexture(new Texture("res/snow/CanadianArctic.jpg",GL11.GL_REPEAT));
groundMesh.create(
new float[]{
-size, 0, -size, // down left
-size, 0, size, // up left
size, 0, -size, // down right
size, 0, -size, // down right
size, 0, size, // up right
-size, 0, size // up left
},
null, null,
new float[]{
0, 0,// down left
0, size/50,// up left
size/50, 0,// down right
size/50, 0,// down right
size/50, size/50,// up right
0, size/50,// up left
},
null
);
groundModel.addMesh(groundMesh);
MotionState state2 = new DefaultMotionState(new Transform(MatrixConverter.convert(groundModel.getModel())));
CollisionShape shape2 = new StaticPlaneShape(new Vector3f(0, 1, 0),1f);
RigidBodyConstructionInfo info2 = new RigidBodyConstructionInfo(0f, state2, shape2);
RigidBody body2 = new RigidBody(info2);
body2.setFriction(0.3f);
groundModel.body = body2;
screen.addEntity(groundModel);
}
示例12: initPhysics
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public void initPhysics() {
setCameraDistance(30f);
// collision configuration contains default setup for memory, collision setup
collisionConfiguration = new DefaultCollisionConfiguration();
// use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
dispatcher = new CollisionDispatcher(collisionConfiguration);
overlappingPairCache = new SimpleBroadphase();
// the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver();
solver = sol;
// TODO: needed for SimpleDynamicsWorld
//sol.setSolverMode(sol.getSolverMode() & ~SolverMode.SOLVER_CACHE_FRIENDLY.getMask());
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
//dynamicsWorld = new SimpleDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0f, -10f, 0f));
initGImpactCollision();
float mass = 0f;
Transform startTransform = new Transform();
startTransform.setIdentity();
CollisionShape staticboxShape1 = new BoxShape(new Vector3f(200f, 1f, 200f)); // floor
CollisionShape staticboxShape2 = new BoxShape(new Vector3f(1f, 50f, 200f)); // left wall
CollisionShape staticboxShape3 = new BoxShape(new Vector3f(1f, 50f, 200f)); // right wall
CollisionShape staticboxShape4 = new BoxShape(new Vector3f(200f, 50f, 1f)); // front wall
CollisionShape staticboxShape5 = new BoxShape(new Vector3f(200f, 50f, 1f)); // back wall
CompoundShape staticScenario = new CompoundShape(); // static scenario
startTransform.origin.set(0f, 0f, 0f);
staticScenario.addChildShape(startTransform, staticboxShape1);
startTransform.origin.set(-200f, 25f, 0f);
staticScenario.addChildShape(startTransform, staticboxShape2);
startTransform.origin.set(200f, 25f, 0f);
staticScenario.addChildShape(startTransform, staticboxShape3);
startTransform.origin.set(0f, 25f, 200f);
staticScenario.addChildShape(startTransform, staticboxShape4);
startTransform.origin.set(0f, 25f, -200f);
staticScenario.addChildShape(startTransform, staticboxShape5);
startTransform.origin.set(0f, 0f, 0f);
RigidBody staticBody = localCreateRigidBody(mass, startTransform, staticScenario);
staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
// enable custom material callback
//staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.CUSTOM_MATERIAL_CALLBACK);
// static plane
Vector3f normal = new Vector3f(0.4f, 1.5f, -0.4f);
normal.normalize();
CollisionShape staticplaneShape6 = new StaticPlaneShape(normal, 0f); // A plane
startTransform.origin.set(0f, 0f, 0f);
RigidBody staticBody2 = localCreateRigidBody(mass, startTransform, staticplaneShape6);
staticBody2.setCollisionFlags(staticBody2.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
for (int i=0; i<9; i++) {
CollisionShape boxShape = new BoxShape(new Vector3f(1f, 1f, 1f));
startTransform.origin.set(2f * i - 5f, 2f, -3f);
localCreateRigidBody(1, startTransform, boxShape);
}
}
示例13: initPhysics
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public void initPhysics() {
setCameraDistance(30f);
// collision configuration contains default setup for memory, collision setup
collisionConfiguration = new DefaultCollisionConfiguration();
// use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
dispatcher = new CollisionDispatcher(collisionConfiguration);
overlappingPairCache = new DbvtBroadphase();
// the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver();
solver = sol;
// TODO: needed for SimpleDynamicsWorld
//sol.setSolverMode(sol.getSolverMode() & ~SolverMode.SOLVER_CACHE_FRIENDLY.getMask());
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
//dynamicsWorld = new SimpleDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0f, -10f, 0f));
initGImpactCollision();
float mass = 0f;
Transform startTransform = new Transform();
startTransform.setIdentity();
CollisionShape staticboxShape1 = new BoxShape(new Vector3f(200f, 1f, 200f)); // floor
CollisionShape staticboxShape2 = new BoxShape(new Vector3f(1f, 50f, 200f)); // left wall
CollisionShape staticboxShape3 = new BoxShape(new Vector3f(1f, 50f, 200f)); // right wall
CollisionShape staticboxShape4 = new BoxShape(new Vector3f(200f, 50f, 1f)); // front wall
CollisionShape staticboxShape5 = new BoxShape(new Vector3f(200f, 50f, 1f)); // back wall
CompoundShape staticScenario = new CompoundShape(); // static scenario
startTransform.origin.set(0f, 0f, 0f);
staticScenario.addChildShape(startTransform, staticboxShape1);
startTransform.origin.set(-200f, 25f, 0f);
staticScenario.addChildShape(startTransform, staticboxShape2);
startTransform.origin.set(200f, 25f, 0f);
staticScenario.addChildShape(startTransform, staticboxShape3);
startTransform.origin.set(0f, 25f, 200f);
staticScenario.addChildShape(startTransform, staticboxShape4);
startTransform.origin.set(0f, 25f, -200f);
staticScenario.addChildShape(startTransform, staticboxShape5);
startTransform.origin.set(0f, 0f, 0f);
RigidBody staticBody = localCreateRigidBody(mass, startTransform, staticScenario);
staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
// enable custom material callback
//staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.CUSTOM_MATERIAL_CALLBACK);
// static plane
Vector3f normal = new Vector3f(0.4f, 1.5f, -0.4f);
normal.normalize();
CollisionShape staticplaneShape6 = new StaticPlaneShape(normal, 0f); // A plane
startTransform.origin.set(0f, 0f, 0f);
RigidBody staticBody2 = localCreateRigidBody(mass, startTransform, staticplaneShape6);
staticBody2.setCollisionFlags(staticBody2.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
for (int i=0; i<9; i++) {
CollisionShape boxShape = new BoxShape(new Vector3f(1f, 1f, 1f));
startTransform.origin.set(2f * i - 5f, 2f, -3f);
localCreateRigidBody(1, startTransform, boxShape);
}
}
示例14: createPlane
import com.bulletphysics.collision.shapes.StaticPlaneShape; //导入依赖的package包/类
public static RigidBody createPlane(float mass, Vector3f normal, float planeConstant, Vector3f position, Quaternion rotation) {
return createRigidBody(createDefaultRBCI(new StaticPlaneShape(normal.toVecmathVec3f(),planeConstant),mass,position,rotation));
}