// ----------------------------------------------------------------------- // // Initialize a CDRGNURBSSurface object. This will normally only be called // once for a particular object but it's safe to call it more than once. // // ----------------------------------------------------------------------- bool CDRGNURBSSurface::Init(int uDegree, int vDegree, int uControlPoints, int vControlPoints, Point4D *pControlPoints, float *pUKnots, float *pVKnots, int iDefaultUTessellations, int iDefaultVTessellations) { // In case we've already been initialized. Cleanup(); // Copy the stuff we're given // m_iUDegree = uDegree; m_iVDegree = vDegree; m_iUControlPoints = uControlPoints; m_iVControlPoints = vControlPoints; // // Compute some other useful quantities // m_iUOrder = m_iUDegree + 1; m_iVOrder = m_iVDegree + 1; m_iUKnots = m_iUOrder + m_iUControlPoints; m_iVKnots = m_iVOrder + m_iVControlPoints; // Calculate how many valid spans exist in the Knot vectors m_iUBasisSpans = m_iUKnots - 2 * m_iUDegree; m_iVBasisSpans = m_iVKnots - 2 * m_iVDegree; // // Allocate some memory for the control points, knots, and basis stuff // m_pControlPoints = ALIGNED_NEW(m_iUControlPoints * m_iVControlPoints, Point4D); m_UKnots = ALIGNED_NEW(m_iUKnots, float); m_VKnots = ALIGNED_NEW(m_iVKnots, float); // For each span in the knot vector, there will be m_iUOrder (and m_iVOrder) // Basis polynomials that are non-zero. Each of those polynomials will // have m_iUOrder coefficients, hence m_iUBasisSpans * m_iUOrder * m_iUOrder m_UBasisCoefficients = ALIGNED_NEW(m_iUOrder * m_iUOrder * m_iUBasisSpans, float); m_VBasisCoefficients = ALIGNED_NEW(m_iVOrder * m_iVOrder * m_iVBasisSpans, float); m_UTemp = ALIGNED_NEW(m_iVOrder, Point4D); m_dUTemp = ALIGNED_NEW(m_iVOrder, Point4D); // // Copy the incoming data to the internal structures. If the incoming control // points are NOT stored as pre-weighted points, then you'll need to loop over // the points and multiply x, y, and z by the w value (so that the actual, // stored control point is {x*w, y*w, z*w, w}) // memcpy(m_pControlPoints, pControlPoints, m_iUControlPoints * m_iVControlPoints * sizeof(Point4D)); memcpy(m_UKnots, pUKnots, m_iUKnots * sizeof(float)); memcpy(m_VKnots, pVKnots, m_iVKnots * sizeof(float)); ComputeBasisCoefficients(); SetTessellations(iDefaultUTessellations, iDefaultVTessellations); return true; }
CylinderShapeX::CylinderShapeX(btScalar halfExtents) : CylinderShape((btCylinderShape*)0) { btVector3* halfExtentsTemp = ALIGNED_NEW(btVector3) (halfExtents, halfExtents, halfExtents); UnmanagedPointer = new btCylinderShapeX(*halfExtentsTemp); ALIGNED_FREE(halfExtentsTemp); }
Vector3 CylinderShape::HalfExtentsWithMargin::get() { btVector3* extentsTemp = ALIGNED_NEW(btVector3) (Native->getHalfExtentsWithMargin()); Vector3 extents = Math::BtVector3ToVector3(extentsTemp); ALIGNED_FREE(extentsTemp); return extents; }
CylinderShape::CylinderShape(btScalar halfExtents) : ConvexInternalShape(0) { btVector3* halfExtentsTemp = ALIGNED_NEW(btVector3) (halfExtents, halfExtents, halfExtents); UnmanagedPointer = new btCylinderShape(*halfExtentsTemp); ALIGNED_FREE(halfExtentsTemp); }
CylinderShapeZ::CylinderShapeZ(btScalar halfExtentsX, btScalar halfExtentsY, btScalar halfExtentsZ) : CylinderShape((btCylinderShape*)0) { btVector3* halfExtentsTemp = ALIGNED_NEW(btVector3) (halfExtentsX, halfExtentsY, halfExtentsZ); UnmanagedPointer = new btCylinderShapeZ(*halfExtentsTemp); ALIGNED_FREE(halfExtentsTemp); }
Vector3 TriangleMeshShape::LocalGetSupportingVertexWithoutMargin(Vector3 vec) { VECTOR3_DEF(vec); btVector3* vecOut = ALIGNED_NEW(btVector3); TriangleMeshShape_LocalGetSupportingVertexWithoutMargin(Native, VECTOR3_PTR(vec), vecOut); Vector3 vertex = Math::BtVector3ToVector3(vecOut); VECTOR3_DEL(vec); ALIGNED_FREE(vecOut); return vertex; }
// ----------------------------------------------------------------------- // // Change the number of tessellations used to render the object // // ----------------------------------------------------------------------- void CDRGNURBSSurface::SetTessellations(int iUTessellations, int iVTessellations) { if ((iUTessellations != m_iUTessellations) || (iVTessellations != m_iVTessellations)) { m_iUTessellations = iUTessellations; m_iVTessellations = iVTessellations; // // Free anything we've already allocated // ALIGNED_DELETE(m_UBasis); ALIGNED_DELETE(m_VBasis); ALIGNED_DELETE(m_dUBasis); ALIGNED_DELETE(m_dVBasis); SAFE_DELETE(m_TessUKnotSpan); SAFE_DELETE(m_TessVKnotSpan); // // Allocate memory for the basis functions, etc // m_UBasis = ALIGNED_NEW(m_iUOrder * SIMD_SIZE * (m_iUTessellations+1), float) ; m_VBasis = ALIGNED_NEW(m_iVOrder * SIMD_SIZE * (m_iVTessellations+1), float) ; m_dUBasis = ALIGNED_NEW(m_iUOrder * SIMD_SIZE * (m_iUTessellations+1), float) ; m_dVBasis = ALIGNED_NEW(m_iVOrder * SIMD_SIZE * (m_iVTessellations+1), float) ; m_TessUKnotSpan = new int[m_iUTessellations + 1]; m_TessVKnotSpan = new int[m_iVTessellations + 1]; ALIGNED_DELETE(m_pVertices); int iVertices = ((iUTessellations + 1) * (iVTessellations + 1)); //2 * (iVTessellations + 1); m_pVertices = ALIGNED_NEW(iVertices, splinePoint) ; // // Re-evaluate the basis functions // EvaluateBasisFunctions(); }
#ifndef DISABLE_UNCOMMON #include "SphereShape.h" #include "SphereTriangleDetector.h" #include "TriangleShape.h" #define Native static_cast<::SphereTriangleDetector*>(_native) BulletSharp::SphereTriangleDetector::SphereTriangleDetector(::SphereTriangleDetector* native) : DiscreteCollisionDetectorInterface(native) { } BulletSharp::SphereTriangleDetector::SphereTriangleDetector(SphereShape^ sphere, TriangleShape^ triangle, btScalar contactBreakingThreshold) : DiscreteCollisionDetectorInterface(ALIGNED_NEW(::SphereTriangleDetector)((btSphereShape*)sphere->_native, (btTriangleShape*)triangle->_native, contactBreakingThreshold)) { } bool BulletSharp::SphereTriangleDetector::Collide(Vector3 sphereCenter, Vector3% point, Vector3% resultNormal, btScalar% depth, btScalar% timeOfImpact, btScalar contactBreakingThreshold) { VECTOR3_CONV(sphereCenter); btVector3* pointTemp = ALIGNED_NEW(btVector3); btVector3* resultNormalTemp = ALIGNED_NEW(btVector3); btScalar depthTemp; btScalar timeOfImpactTemp; return Native->collide(VECTOR3_USE(sphereCenter), *pointTemp, *resultNormalTemp, depthTemp, timeOfImpactTemp, contactBreakingThreshold); depth = depthTemp; timeOfImpact = timeOfImpactTemp;
btDefaultMotionState* btDefaultMotionState_new3(const btScalar* startTrans, const btScalar* centerOfMassOffset) { TRANSFORM_CONV(startTrans); TRANSFORM_CONV(centerOfMassOffset); return ALIGNED_NEW(btDefaultMotionState)(TRANSFORM_USE(startTrans), TRANSFORM_USE(centerOfMassOffset)); }
btDefaultMotionState* btDefaultMotionState_new() { return ALIGNED_NEW(btDefaultMotionState)(); }
DiscreteCollisionDetectorInterface::ClosestPointInput::ClosestPointInput() { _native = ALIGNED_NEW(btDiscreteCollisionDetectorInterface::ClosestPointInput) (); }
btDefaultMotionState* btDefaultMotionState_new2(const btScalar* startTrans) { TRANSFORM_CONV(startTrans); return ALIGNED_NEW(btDefaultMotionState)(TRANSFORM_USE(startTrans)); }
btShapeHull* btShapeHull_new(const btConvexShape* shape) { return ALIGNED_NEW(btShapeHull)(shape); }
SphereBoxCollisionAlgorithm::SphereBoxCollisionAlgorithm(PersistentManifold^ mf, CollisionAlgorithmConstructionInfo^ ci, CollisionObjectWrapper^ body0Wrap, CollisionObjectWrapper^ body1Wrap, bool isSwapped) : ActivatingCollisionAlgorithm(new btSphereBoxCollisionAlgorithm((btPersistentManifold*)GetUnmanagedNullable(mf), *ci->_native, body0Wrap->_native, body1Wrap->_native, isSwapped)) { } #define Native static_cast<btSphereBoxCollisionAlgorithm*>(_native) bool SphereBoxCollisionAlgorithm::GetSphereDistance(CollisionObjectWrapper^ boxObjWrap, Vector3% v3PointOnBox, Vector3% normal, btScalar% penetrationDepth, Vector3 v3SphereCenter, btScalar fRadius, btScalar maxContactDistance) { btVector3* v3PointOnBoxTemp = ALIGNED_NEW(btVector3); btVector3* normalTemp = ALIGNED_NEW(btVector3); VECTOR3_DEF(v3SphereCenter); btScalar penetrationDepthTemp; bool ret = Native->getSphereDistance(boxObjWrap->_native, *v3PointOnBoxTemp, *normalTemp, penetrationDepthTemp, VECTOR3_USE(v3SphereCenter), fRadius, maxContactDistance); Math::BtVector3ToVector3(v3PointOnBoxTemp, v3PointOnBox); Math::BtVector3ToVector3(normalTemp, normal); penetrationDepth = penetrationDepthTemp; ALIGNED_FREE(v3PointOnBoxTemp); ALIGNED_FREE(normalTemp); VECTOR3_DEL(v3SphereCenter); return ret; }
#include "GjkPairDetector.h" #include "SimplexSolverInterface.h" #ifndef DISABLE_DEBUGDRAW #include "DebugDraw.h" #endif #define Native static_cast<btGjkPairDetector*>(_native) GjkPairDetector::GjkPairDetector(btGjkPairDetector* native) : DiscreteCollisionDetectorInterface(native) { } GjkPairDetector::GjkPairDetector(ConvexShape^ objectA, ConvexShape^ objectB, SimplexSolverInterface^ simplexSolver, ConvexPenetrationDepthSolver^ penetrationDepthSolver) : DiscreteCollisionDetectorInterface(ALIGNED_NEW(btGjkPairDetector) ((btConvexShape*)objectA->_native, (btConvexShape*)objectB->_native, simplexSolver->_native, GetUnmanagedNullable(penetrationDepthSolver))) { } GjkPairDetector::GjkPairDetector(ConvexShape^ objectA, ConvexShape^ objectB, BroadphaseNativeType shapeTypeA, BroadphaseNativeType shapeTypeB, btScalar marginA, btScalar marginB, SimplexSolverInterface^ simplexSolver, ConvexPenetrationDepthSolver^ penetrationDepthSolver) : DiscreteCollisionDetectorInterface(ALIGNED_NEW(btGjkPairDetector) ((btConvexShape*)objectA->_native, (btConvexShape*)objectB->_native, (int)shapeTypeA, (int)shapeTypeB, marginA, marginB, simplexSolver->_native, GetUnmanagedNullable(penetrationDepthSolver))) { } #ifndef DISABLE_DEBUGDRAW void GjkPairDetector::GetClosestPointsNonVirtual(ClosestPointInput^ input, Result^ output, IDebugDraw^ debugDraw)
#include "StdAfx.h" #include "TransformUtil.h" void TransformUtil::CalculateDiffAxisAngle(Matrix transform0, Matrix transform1, [Out] Vector3% axis, [Out] btScalar% angle) { TRANSFORM_CONV(transform0); TRANSFORM_CONV(transform1); btVector3* axisTemp = ALIGNED_NEW(btVector3); btScalar angleTemp; btTransformUtil::calculateDiffAxisAngle(TRANSFORM_USE(transform0), TRANSFORM_USE(transform1), *axisTemp, angleTemp); TRANSFORM_DEL(transform0); TRANSFORM_DEL(transform1); Math::BtVector3ToVector3(axisTemp, axis); ALIGNED_FREE(axisTemp); angle = angleTemp; } void TransformUtil::CalculateDiffAxisAngleQuaternion(Quaternion orn0, Quaternion orn1a, [Out] Vector3% axis, [Out] btScalar% angle) { QUATERNION_CONV(orn0); QUATERNION_CONV(orn1a); btVector3* axisTemp = ALIGNED_NEW(btVector3); btScalar angleTemp; btTransformUtil::calculateDiffAxisAngleQuaternion(QUATERNION_USE(orn0), QUATERNION_USE(orn1a), *axisTemp, angleTemp); QUATERNION_DEL(orn0); QUATERNION_DEL(orn1a);
VehicleRaycasterResult::VehicleRaycasterResult() { _native = ALIGNED_NEW(btVehicleRaycaster::btVehicleRaycasterResult) (); }