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


Java SphereShape.getRadius方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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.getRadius方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。