当前位置: 首页>>代码示例>>Java>>正文


Java SphereShape类代码示例

本文整理汇总了Java中com.bulletphysics.collision.shapes.SphereShape的典型用法代码示例。如果您正苦于以下问题:Java SphereShape类的具体用法?Java SphereShape怎么用?Java SphereShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SphereShape类属于com.bulletphysics.collision.shapes包,在下文中一共展示了SphereShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: EntityCrazyCube

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
public EntityCrazyCube(World world, Vec3f pos){
		super(world, getModel0(), pos);
		float s=Rand.f()+1;
		scale.set(s, s, s);
		
//		model.getMaterial(2).getDiffuse().set(177/256F, 0, 177/256F, 1);
//		model.getMaterial(1).getDiffuse().set(0x00C7E7);
//		model.getMaterial(1).getAmbient().set(0x00C7E7).a(1);
//		model.getMaterial(0).getDiffuse().set(0x0000FF);
		
		float massKg=0.5F*scale.x*scale.y*scale.z;
		
		if(CAM==null) CAM=this;
		
		getPhysicsObj().init(massKg, new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(pos.x, pos.y, pos.z), 0.5F)), new SphereShape(scale.x/2), Vec3f.single(0.9F));
//		getPhysicsObj().init(massKg, new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(pos.x, pos.y, pos.z), 0.5F)), new BoxShape(new Vector3f(scale.x/2, scale.y/2, scale.z/2)), Vec3f.single(0.9F));
		getPhysicsObj().body.setDamping(0.15F, 0.15F);
		getPhysicsObj().hookPos(this.pos);
		getPhysicsObj().hookRot(rot);
	}
 
开发者ID:LapisSea,项目名称:OpenGL-Bullet-engine,代码行数:21,代码来源:EntityCrazyCube.java

示例2: processTriangle

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
public void processTriangle (Vector3[] triangle, int partId, int triangleIndex) {
	// do a swept sphere for now

	// btTransform ident;
	// ident.setIdentity();

	CastResult castResult = new CastResult();
	castResult.fraction = hitFraction;
	SphereShape pointShape = new SphereShape(ccdSphereRadius);
	TriangleShape triShape = new TriangleShape(triangle[0], triangle[1], triangle[2]);
	VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
	SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(pointShape, triShape, simplexSolver);
	// GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
	// ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
	// local space?

	if (convexCaster.calcTimeOfImpact(ccdSphereFromTrans, ccdSphereToTrans, ident, ident, castResult)) {
		if (hitFraction > castResult.fraction) {
			hitFraction = castResult.fraction;
		}
	}
}
 
开发者ID:vbousquet,项目名称:libgdx-jbullet,代码行数:23,代码来源:ConvexConcaveCollisionAlgorithm.java

示例3: processTriangle

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) {
	// do a swept sphere for now
	
	//btTransform ident;
	//ident.setIdentity();
	
	CastResult castResult = new CastResult();
	castResult.fraction = hitFraction;
	SphereShape pointShape = new SphereShape(ccdSphereRadius);
	TriangleShape triShape = new TriangleShape(triangle[0], triangle[1], triangle[2]);
	VoronoiSimplexSolver simplexSolver = new VoronoiSimplexSolver();
	SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(pointShape, triShape, simplexSolver);
	//GjkConvexCast	convexCaster(&pointShape,convexShape,&simplexSolver);
	//ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
	//local space?

	if (convexCaster.calcTimeOfImpact(ccdSphereFromTrans, ccdSphereToTrans, ident, ident, castResult)) {
		if (hitFraction > castResult.fraction) {
			hitFraction = castResult.fraction;
		}
	}
}
 
开发者ID:warlockcodes,项目名称:Null-Engine,代码行数:23,代码来源:ConvexConcaveCollisionAlgorithm.java

示例4: init

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public void init() {
	Engine.scene.sun.direction = vec3(0.0f, -1.0f, 0.0f);
	Engine.scene.sun.color = vec3(1.2f, 1.2f, 1.2f);
	
	loadTexture("stone_tile.png", false, true);
	loadTexture("stone_tile_normal.png");
	loadTexture("stone_tile_specular.png");
	loadTexture("planks.jpg", false, true);
	loadTexture("planks_specular.jpg");
	
	planeMesh = Mesh.raw(Primitives.plane(16.0f), true);
	boxMesh = Mesh.raw(Primitives.cube(16.0f), true);
	sphereMesh = ObjLoader.loadFile("sphere.obj");

	Engine.scene.skybox = new Cubemap("sunset");
	Engine.scene.irradiance = new Cubemap("sunset-irradiance");
	
	Engine.scene.add(new PointLight(vec3(0.0f, 0.0f, 0.0f), vec3(1.0f, 1.0f, 1.0f), 0.42f, 0.2f));
	
	Engine.scene.add(new MeshSphere(vec3(), new Quat4f(), new SphereShape(1.0f), 1f, sphereMesh, 1f, sphereMaterial));
	Engine.scene.add(new MeshObject(vec3(0.0f, 5.0f, 0.0f), new Quat4f(), new BoxShape(new Vector3f(0.0f, 0.0f, 0.0f)), 0f, boxMesh, 1f, boxMaterial));
	Engine.scene.add(new MeshObject(vec3(0.0f, -10f, 0.0f), new Quat4f(1.0f, 0.0f, 0.0f, 60.0f), new BoxShape(new Vector3f(50f, 0f, 50f)), 0f, planeMesh, 100f,  groundMaterial));

}
 
开发者ID:pianoman373,项目名称:Point-Engine,代码行数:26,代码来源:KDemo.java

示例5: getBulletShape

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public CollisionShape getBulletShape() {
    // Make sure the shape has been configured
    if(this.bulletShape == null)
        this.bulletShape = new SphereShape(this.radius);

    // Return the shape
    return this.bulletShape;
}
 
开发者ID:timvisee,项目名称:key-barricade,代码行数:10,代码来源:SphereColliderComponent.java

示例6: processSphereShape

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
private ColliderInfo processSphereShape(JsonDeserializationContext context, JsonObject colliderDef, Rotation rot) {
    Vector3f offset = context.deserialize(colliderDef.get("position"), Vector3f.class);
    float radius = colliderDef.get("radius").getAsFloat();
    if (offset == null) throw new JsonParseException("Sphere Collider missing position");

    return new ColliderInfo(QuaternionUtil.quatRotate(rot.getQuat4f(), offset, offset), new SphereShape(radius));
}
 
开发者ID:zoneXcoding,项目名称:Mineworld,代码行数:8,代码来源:JsonBlockShapeLoader.java

示例7: getShapeFor

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
private ConvexShape getShapeFor(EntityRef entity) {
    BoxShapeComponent box = entity.getComponent(BoxShapeComponent.class);
    if (box != null) {
        Vector3f halfExtents = new Vector3f(box.extents);
        halfExtents.scale(0.5f);
        return new BoxShape(halfExtents);
    }
    SphereShapeComponent sphere = entity.getComponent(SphereShapeComponent.class);
    if (sphere != null) {
        return new SphereShape(sphere.radius);
    }
    CapsuleShapeComponent capsule = entity.getComponent(CapsuleShapeComponent.class);
    if (capsule != null) {
        return new CapsuleShape(capsule.radius, capsule.height);
    }
    CylinderShapeComponent cylinder = entity.getComponent(CylinderShapeComponent.class);
    if (cylinder != null) {
        return new CylinderShape(new Vector3f(cylinder.radius, 0.5f * cylinder.height, cylinder.radius));
    }
    HullShapeComponent hull = entity.getComponent(HullShapeComponent.class);
    if (hull != null) {
        ObjectArrayList<Vector3f> verts = new ObjectArrayList<Vector3f>();
        TFloatIterator iterator = hull.sourceMesh.getVertices().iterator();
        while (iterator.hasNext()) {
            Vector3f newVert = new Vector3f();
            newVert.x = iterator.next();
            newVert.y = iterator.next();
            newVert.z = iterator.next();
            verts.add(newVert);
        }
        return new ConvexHullShape(verts);
    }
    CharacterMovementComponent characterMovementComponent = entity.getComponent(CharacterMovementComponent.class);
    if (characterMovementComponent != null) {
        return new CapsuleShape(characterMovementComponent.radius, characterMovementComponent.height);
    }
    return null;
}
 
开发者ID:zoneXcoding,项目名称:Mineworld,代码行数:39,代码来源:PhysicsSystem.java

示例8: createShape

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
protected void createShape() {
    cShape = new SphereShape(radius);
    cShape.setLocalScaling(Converter.convert(getScale()));
    cShape.setMargin(margin);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:6,代码来源:SphereCollisionShape.java

示例9: processCollision

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public void processCollision (CollisionObject col0, CollisionObject col1, DispatcherInfo dispatchInfo,
	ManifoldResult resultOut) {
	if (manifoldPtr == null) {
		return;
	}

	Stack stack = Stack.enter();
	Transform tmpTrans1 = stack.allocTransform();
	Transform tmpTrans2 = stack.allocTransform();

	resultOut.setPersistentManifold(manifoldPtr);

	SphereShape sphere0 = (SphereShape)col0.getCollisionShape();
	SphereShape sphere1 = (SphereShape)col1.getCollisionShape();

	Vector3 diff = stack.allocVector3();
	diff.set(col0.getWorldTransform(tmpTrans1).origin).sub(col1.getWorldTransform(tmpTrans2).origin);

	float len = diff.len();
	float radius0 = sphere0.getRadius();
	float radius1 = sphere1.getRadius();

	// #ifdef CLEAR_MANIFOLD
	// manifoldPtr.clearManifold(); // don't do this, it disables warmstarting
	// #endif

	// if distance positive, don't generate a new contact
	if (len > (radius0 + radius1)) {
		// #ifndef CLEAR_MANIFOLD
		resultOut.refreshContactPoints();
		// #endif //CLEAR_MANIFOLD
		return;
	}
	// distance (negative means penetration)
	float dist = len - (radius0 + radius1);

	Vector3 normalOnSurfaceB = stack.allocVector3();
	normalOnSurfaceB.set(1f, 0f, 0f);
	if (len > BulletGlobals.FLT_EPSILON) {
		normalOnSurfaceB.set(diff).scl(1f / len);
	}

	Vector3 tmp = stack.allocVector3();

	// point on A (worldspace)
	Vector3 pos0 = stack.allocVector3();
	tmp.set(normalOnSurfaceB).scl(radius0);
	pos0.set(col0.getWorldTransform(tmpTrans1).origin).sub(tmp);

	// point on B (worldspace)
	Vector3 pos1 = stack.allocVector3();
	tmp.set(normalOnSurfaceB).scl(radius1);
	pos1.set(col1.getWorldTransform(tmpTrans2).origin).add(tmp);

	// report a contact. internally this will be kept persistent, and contact reduction is done
	resultOut.addContactPoint(normalOnSurfaceB, pos1, dist);

	// #ifndef CLEAR_MANIFOLD
	resultOut.refreshContactPoints();
	// #endif //CLEAR_MANIFOLD
	stack.leave();
}
 
开发者ID:vbousquet,项目名称:libgdx-jbullet,代码行数:64,代码来源:SphereSphereCollisionAlgorithm.java

示例10: integrateTransforms

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
protected void integrateTransforms (float timeStep) {
	BulletStats.pushProfile("integrateTransforms");
	Stack stack = Stack.enter();
	int sp = stack.getSp();
	try {
		Vector3 tmp = stack.allocVector3();
		Transform tmpTrans = stack.allocTransform();

		Transform predictedTrans = stack.allocTransform();
		for (int i = 0; i < collisionObjects.size(); i++) {
			CollisionObject colObj = collisionObjects.getQuick(i);
			RigidBody body = RigidBody.upcast(colObj);
			if (body != null) {
				body.setHitFraction(1f);

				if (body.isActive() && (!body.isStaticOrKinematicObject())) {
					body.predictIntegratedTransform(timeStep, predictedTrans);

					tmp.set(predictedTrans.origin).sub(body.getWorldTransform(tmpTrans).origin);
					float squareMotion = tmp.len2();

					if (body.getCcdSquareMotionThreshold() != 0f && body.getCcdSquareMotionThreshold() < squareMotion) {
						BulletStats.pushProfile("CCD motion clamping");
						try {
							if (body.getCollisionShape().isConvex()) {
								BulletStats.gNumClampedCcdMotions++;

								ClosestNotMeConvexResultCallback sweepResults = new ClosestNotMeConvexResultCallback(body,
									body.getWorldTransform(tmpTrans).origin, predictedTrans.origin, getBroadphase()
										.getOverlappingPairCache(), getDispatcher());
								// ConvexShape convexShape = (ConvexShape)body.getCollisionShape();
								SphereShape tmpSphere = new SphereShape(body.getCcdSweptSphereRadius()); // btConvexShape* convexShape
																																	// =
																																	// static_cast<btConvexShape*>(body->getCollisionShape());

								sweepResults.collisionFilterGroup = body.getBroadphaseProxy().collisionFilterGroup;
								sweepResults.collisionFilterMask = body.getBroadphaseProxy().collisionFilterMask;

								convexSweepTest(tmpSphere, body.getWorldTransform(tmpTrans), predictedTrans, sweepResults);
								// JAVA NOTE: added closestHitFraction test to prevent objects being stuck
								if (sweepResults.hasHit() && (sweepResults.closestHitFraction > 0.0001f)) {
									body.setHitFraction(sweepResults.closestHitFraction);
									body.predictIntegratedTransform(timeStep * body.getHitFraction(), predictedTrans);
									body.setHitFraction(0f);
									// System.out.printf("clamped integration to hit fraction = %f\n", sweepResults.closestHitFraction);
								}
							}
						} finally {
							BulletStats.popProfile();
						}
					}

					body.proceedToTransform(predictedTrans);
				}
			}
		}
	} finally {
		stack.leave(sp);
		BulletStats.popProfile();
	}
}
 
开发者ID:vbousquet,项目名称:libgdx-jbullet,代码行数:62,代码来源:DiscreteDynamicsWorld.java

示例11: processCollision

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public void processCollision(CollisionObject col0, CollisionObject col1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
	if (manifoldPtr == null) {
		return;
	}
	
	Transform tmpTrans1 = Stack.alloc(Transform.class);
	Transform tmpTrans2 = Stack.alloc(Transform.class);

	resultOut.setPersistentManifold(manifoldPtr);

	SphereShape sphere0 = (SphereShape) col0.getCollisionShape();
	SphereShape sphere1 = (SphereShape) col1.getCollisionShape();

	Vector3f diff = Stack.alloc(Vector3f.class);
	diff.sub(col0.getWorldTransform(tmpTrans1).origin, col1.getWorldTransform(tmpTrans2).origin);

	float len = diff.length();
	float radius0 = sphere0.getRadius();
	float radius1 = sphere1.getRadius();

	//#ifdef CLEAR_MANIFOLD
	//manifoldPtr.clearManifold(); // don't do this, it disables warmstarting
	//#endif

	// if distance positive, don't generate a new contact
	if (len > (radius0 + radius1)) {
		//#ifndef CLEAR_MANIFOLD
		resultOut.refreshContactPoints();
		//#endif //CLEAR_MANIFOLD
		return;
	}
	// distance (negative means penetration)
	float dist = len - (radius0 + radius1);

	Vector3f normalOnSurfaceB = Stack.alloc(Vector3f.class);
	normalOnSurfaceB.set(1f, 0f, 0f);
	if (len > BulletGlobals.FLT_EPSILON) {
		normalOnSurfaceB.scale(1f / len, diff);
	}

	Vector3f tmp = Stack.alloc(Vector3f.class);

	// point on A (worldspace)
	Vector3f pos0 = Stack.alloc(Vector3f.class);
	tmp.scale(radius0, normalOnSurfaceB);
	pos0.sub(col0.getWorldTransform(tmpTrans1).origin, tmp);

	// point on B (worldspace)
	Vector3f pos1 = Stack.alloc(Vector3f.class);
	tmp.scale(radius1, normalOnSurfaceB);
	pos1.add(col1.getWorldTransform(tmpTrans2).origin, tmp);

	// report a contact. internally this will be kept persistent, and contact reduction is done
	resultOut.addContactPoint(normalOnSurfaceB, pos1, dist);

	//#ifndef CLEAR_MANIFOLD
	resultOut.refreshContactPoints();
	//#endif //CLEAR_MANIFOLD
}
 
开发者ID:warlockcodes,项目名称:Null-Engine,代码行数:61,代码来源:SphereSphereCollisionAlgorithm.java

示例12: integrateTransforms

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
protected void integrateTransforms(float timeStep) {
	BulletStats.pushProfile("integrateTransforms");
	try {
		Vector3f tmp = Stack.alloc(Vector3f.class);
		Transform tmpTrans = Stack.alloc(Transform.class);

		Transform predictedTrans = Stack.alloc(Transform.class);
		for (int i=0; i<collisionObjects.size(); i++) {
			CollisionObject colObj = collisionObjects.getQuick(i);
			RigidBody body = RigidBody.upcast(colObj);
			if (body != null) {
				body.setHitFraction(1f);

				if (body.isActive() && (!body.isStaticOrKinematicObject())) {
					body.predictIntegratedTransform(timeStep, predictedTrans);

					tmp.sub(predictedTrans.origin, body.getWorldTransform(tmpTrans).origin);
					float squareMotion = tmp.lengthSquared();

					if (body.getCcdSquareMotionThreshold() != 0f && body.getCcdSquareMotionThreshold() < squareMotion) {
						BulletStats.pushProfile("CCD motion clamping");
						try {
							if (body.getCollisionShape().isConvex()) {
								BulletStats.gNumClampedCcdMotions++;

								ClosestNotMeConvexResultCallback sweepResults = new ClosestNotMeConvexResultCallback(body, body.getWorldTransform(tmpTrans).origin, predictedTrans.origin, getBroadphase().getOverlappingPairCache(), getDispatcher());
								//ConvexShape convexShape = (ConvexShape)body.getCollisionShape();
								SphereShape tmpSphere = new SphereShape(body.getCcdSweptSphereRadius()); //btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());

								sweepResults.collisionFilterGroup = body.getBroadphaseProxy().collisionFilterGroup;
								sweepResults.collisionFilterMask = body.getBroadphaseProxy().collisionFilterMask;

								convexSweepTest(tmpSphere, body.getWorldTransform(tmpTrans), predictedTrans, sweepResults);
								// JAVA NOTE: added closestHitFraction test to prevent objects being stuck
								if (sweepResults.hasHit() && (sweepResults.closestHitFraction > 0.0001f)) {
									body.setHitFraction(sweepResults.closestHitFraction);
									body.predictIntegratedTransform(timeStep * body.getHitFraction(), predictedTrans);
									body.setHitFraction(0f);
									//System.out.printf("clamped integration to hit fraction = %f\n", sweepResults.closestHitFraction);
								}
							}
						}
						finally {
							BulletStats.popProfile();
						}
					}

					body.proceedToTransform(predictedTrans);
				}
			}
		}
	}
	finally {
		BulletStats.popProfile();
	}
}
 
开发者ID:warlockcodes,项目名称:Null-Engine,代码行数:57,代码来源:DiscreteDynamicsWorld.java

示例13: init

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public void init() {
	//lotta textures to load
	loadTexture("container2.png", false, true);
	loadTexture("container2_specular.png");
	loadTexture("brickwall.jpg", false, true);
	loadTexture("brickwall_normal.jpg");
	
	loadTexture("metal/albedo.png", false, true);
	loadTexture("metal/normal.png");
	loadTexture("metal/metallic.png");
	loadTexture("metal/roughness.png");
	
	loadTexture("plastic/albedo.png", false, true);
	loadTexture("plastic/normal.png");
	loadTexture("plastic/metallic.png");
	loadTexture("plastic/roughness.png");
	
	loadTexture("stone_tile.png", false, true);
	loadTexture("stone_tile_normal.png");
	loadTexture("stone_tile_specular.png");
	
	//all our meshes, some created in-engine and others imported via obj
	cubeMesh = Mesh.raw(Primitives.cube(1.0f), false);
	groundMesh = Mesh.raw(Primitives.cube(16.0f), true);
	sphere = ObjLoader.loadFile("sphere.obj");
	blender1 = ObjLoader.loadFile("matmodel-1.obj");
	blender2 = ObjLoader.loadFile("matmodel-2.obj");		
	
	//sets the skybox, renders as an actual skybox, and also used for reflections
	Engine.scene.skybox = new Cubemap("sunset");
	//think of this as an ambient map
	Engine.scene.irradiance = new Cubemap("sunset-irradiance");
	
	Engine.camera.setPosition(vec3(0, 0, 5));
	
	Engine.scene.sun.color = vec3(5, 5, 5);
	Engine.scene.sun.direction = vec3(-1, -0.8, -0.7f);
	
	Engine.scene.add(new MeshObject(vec3(-10, -10, -12), new Quat4f(), new BoxShape(new Vector3f(2f, 5f, 2f)), 0f, blender1,0.5f,  insideMaterial));
	Engine.scene.add(new MeshObject(vec3(-10, -10, -12), new Quat4f(), new SphereShape(0.5f), 0f, blender2,0.5f,  outsideMaterial));
	Engine.scene.add(new MeshObject(vec3(0, -60f, 0), new Quat4f(), new BoxShape(new Vector3f(50f, 50f, 50f)), 0f, groundMesh, 100f, groundMaterial));
	
	for (int x = 0; x < 7; x++) {
		for (int y = 0; y < 7; y++) {
			Material mat = new Material("stone_tile.png", y / 7f, "stone_tile_normal.png", x / 7f);
			Engine.scene.add(new MeshObject(vec3(x * 3, y * 3, 0).add(vec3(0, -9, -15)), new Quat4f(), new SphereShape(1f), 1f, sphere, 1f, mat));
		}
	}
	
	player = new ThirdPersonController(vec3(10, 0, 0));
	
	Engine.scene.add(player);
}
 
开发者ID:pianoman373,项目名称:Point-Engine,代码行数:55,代码来源:GLDemo.java

示例14: getCollisionShape

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public CollisionShape getCollisionShape() {
	return new SphereShape(radius);
}
 
开发者ID:tinrab,项目名称:zamtrax,代码行数:5,代码来源:SphereCollider.java

示例15: processCollision

import com.bulletphysics.collision.shapes.SphereShape; //导入依赖的package包/类
@Override
public void processCollision(CollisionObject col0, CollisionObject col1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
	if (manifoldPtr == null) {
		return;
	}
	
	Transform tmpTrans1 = Stack.alloc(Transform.class);
	Transform tmpTrans2 = Stack.alloc(Transform.class);

	resultOut.setPersistentManifold(manifoldPtr);

	SphereShape sphere0 = (SphereShape) col0.getCollisionShape();
	SphereShape sphere1 = (SphereShape) col1.getCollisionShape();

	Vector3f diff = Stack.alloc(Vector3f.class);
	diff.sub(col0.getWorldTransform(tmpTrans1).origin, col1.getWorldTransform(tmpTrans2).origin);

	float len = diff.length();
	float radius0 = sphere0.getRadius();
	float radius1 = sphere1.getRadius();

	//manifoldPtr.clearManifold(); // don't do this, it disables warmstarting

	// if distance positive, don't generate a new contact
	if (len > (radius0 + radius1)) {
		return;
	}
	// distance (negative means penetration)
	float dist = len - (radius0 + radius1);

	Vector3f normalOnSurfaceB = Stack.alloc(Vector3f.class);
	normalOnSurfaceB.set(1f, 0f, 0f);
	if (len > BulletGlobals.FLT_EPSILON) {
		normalOnSurfaceB.scale(1f / len, diff);
	}

	Vector3f tmp = Stack.alloc(Vector3f.class);

	// point on A (worldspace)
	Vector3f pos0 = Stack.alloc(Vector3f.class);
	tmp.scale(radius0, normalOnSurfaceB);
	pos0.sub(col0.getWorldTransform(tmpTrans1).origin, tmp);

	// point on B (worldspace)
	Vector3f pos1 = Stack.alloc(Vector3f.class);
	tmp.scale(radius1, normalOnSurfaceB);
	pos1.add(col1.getWorldTransform(tmpTrans2).origin, tmp);

	// report a contact. internally this will be kept persistent, and contact reduction is done
	resultOut.addContactPoint(normalOnSurfaceB, pos1, dist);

	//no resultOut->refreshContactPoints(); needed, because of clearManifold (all points are new)
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:54,代码来源:SphereSphereCollisionAlgorithm.java


注:本文中的com.bulletphysics.collision.shapes.SphereShape类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。