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


Java StaticPlaneShape.getPlaneNormal方法代码示例

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


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

示例1: 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();
}
 
开发者ID:vbousquet,项目名称:libgdx-jbullet,代码行数:64,代码来源:ConvexPlaneCollisionAlgorithm.java

示例2: 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();
		}
	}
}
 
开发者ID:warlockcodes,项目名称:Null-Engine,代码行数:61,代码来源:ConvexPlaneCollisionAlgorithm.java


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