CCSceneCollideable* CCOctreeCollisionCheck(const CCVector3 &min, const CCVector3 &max, const CCSceneCollideable *sourceObject, const uint flags) { setCollideablesList( min, max ); CCSceneCollideable *closestCollision = NULL; for( int i=0; i<numberOfCollideables; ++i ) { CCSceneCollideable *checkingObject = collideables[i]; if( checkingObject != sourceObject ) { const CCVector3 &targetMin = checkingObject->min; const CCVector3 &targetMax = checkingObject->max; if( CCHasFlag( checkingObject->collideableType, collision_box ) ) { if( flags == collision_box || CCHasFlag( checkingObject->collideableType, flags ) ) { CCUpdateCollisions( checkingObject ); if( CCBasicBoxCollisionCheck( min, max, targetMin, targetMax ) ) { closestCollision = checkingObject; break; } } } } } return closestCollision; }
void CCTile3DButton::construct(CCSceneBase *scene) { AddFlag( collideableType, collision_ui ); if( scene != NULL ) { setScene( scene ); } renderDepth = false; setTransparent(); model = new CCModelBase(); baseModel = new CCModelBase(); model->addModel( baseModel ); setBaseColour( CCColour() ); colourInterpolator.setDuration( 0.5f ); baseSquare = NULL; textModel = new CCModelText( this ); if( scale == NULL ) { CCVector3FillPtr( &scale, 0.0f, 0.0f, 1.0f ); } scaleInterpolator.setup( scale, 1.0f ); CCUpdateCollisions( this ); }
void CCPathFinderNetwork::addFillerNodes(CCCollideable *collideable) { CCUpdateCollisions( collideable ); const float maxIncrement = 50.0f; const float minIncrement = 5.0f; const float startX = collideable->aabbMin.x + minIncrement; const float endX = collideable->aabbMax.x - minIncrement; const float width = endX - startX; float numberOfIncrements = roundf( ( width / maxIncrement ) + 0.5f ); if( numberOfIncrements < 1.0f ) { numberOfIncrements = 1.0f; } const float spacingX = width / numberOfIncrements; const float startZ = collideable->aabbMin.z + minIncrement; const float endZ = collideable->aabbMax.z - minIncrement; const float depth = endZ - startZ; numberOfIncrements = roundf( ( depth / maxIncrement ) + 0.5f ); if( numberOfIncrements < 1.0f ) { numberOfIncrements = 1.0f; } const float spacingZ = depth / numberOfIncrements; for( float x=startX; x<endX+1.0f; x+=spacingX ) { for( float z=startZ; z<endZ+1.0f; z+=spacingZ ) { addNode( CCVector3( x, 0.0f, z ) ); } } }
CCSceneCollideable* CCBasicOctreeCollisionCheck(CCSceneCollideable *sourceObject, const CCVector3 *targetLocation, const bool requestCollisionReport, const CCCollisionFlags flags) { if( CCHasFlag( sourceObject->collideableType, collision_box ) && sourceObject->octrees.length > 0 ) { CCVector3 sourceMin = CCVector3( targetLocation->x - sourceObject->collisionBounds.x, targetLocation->y - sourceObject->collisionBounds.y, targetLocation->z - sourceObject->collisionBounds.z ); CCVector3 sourceMax = CCVector3( targetLocation->x + sourceObject->collisionBounds.x, targetLocation->y + sourceObject->collisionBounds.y, targetLocation->z + sourceObject->collisionBounds.z ); setCollideablesList( sourceMin, sourceMax ); CCSceneCollideable *closestCollision = NULL; for( int i=0; i<numberOfCollideables; ++i ) { CCSceneCollideable *checkingObject = collideables[i]; if( checkingObject != sourceObject ) { if( CCHasFlag( checkingObject->collideableType, flags ) ) { if( sourceObject->shouldCollide( checkingObject, true ) ) { const CCVector3 &targetMin = checkingObject->min; const CCVector3 &targetMax = checkingObject->max; if( CCHasFlag( checkingObject->collideableType, collision_box ) ) { CCUpdateCollisions( checkingObject ); if( CCBasicBoxCollisionCheck( sourceMin, sourceMax, targetMin, targetMax ) ) { closestCollision = checkingObject; if( requestCollisionReport && closestCollision != NULL ) { closestCollision = sourceObject->requestCollisionReport( closestCollision ); } if( closestCollision != NULL ) { break; } } } } } } } return closestCollision; } return NULL; }
void CCTile3DButton::setupBase(const float width, const float height) { if( baseSquare == NULL ) { baseSquare = new CCPrimitiveSquare(); baseModel->addPrimitive( baseSquare ); } const float hWidth = width * 0.5f; const float hHeight = height * 0.5f; setHCollisionBounds( hWidth, hHeight, CC_SMALLFLOAT ); baseSquare->setupZFacing( collisionBounds.x, collisionBounds.y ); CCUpdateCollisions( this ); }
const bool CCBasicLineCollisionCheck(CCSceneCollideable *checkingObject, CCSceneCollideable *sourceObject, const CCVector3 &start, const CCVector3 &end) { CCUpdateCollisions( checkingObject ); const CCVector3 &targetMin = checkingObject->min; const CCVector3 &targetMax = checkingObject->max; static CCVector3 currentHitLocation; static float currentHitDistance; if( lineCheckBox( start, end, targetMin, targetMax, currentHitLocation, currentHitDistance ) ) { return true; } return false; }
void CCTile3DButton::construct(CCSceneBase *scene) { AddFlag( collideableType, collision_ui ); if( scene != NULL ) { setScene( scene ); } renderDepth = false; setTransparent(); model = new CCModelBase(); baseModel = new CCModelBase(); model->addModel( baseModel ); setBaseColour( CCColour() ); colourInterpolator.setDuration( 0.5f ); baseSquare = NULL; textModel = new CCModelText( this ); allowTouchRotation( false ); touchRotationMagnitude = 0.0f; touchRotationSpeed = 1.0f; if( scale == NULL ) { CCVector3FillPtr( &scale, 0.0f, 0.0f, 1.0f ); } scaleInterpolator.setup( scale, 1.0f ); allowTouchMovement( false ); touchDepressInterpolator.setDuration( 0.125f ); setTouchDepressRange( 1.0f ); touchDepressDepth = 3.0f; CCUpdateCollisions( this ); }
CCSceneCollideable* CCBasicCollisionCheck(CCSceneCollideable *sourceObject, const CCVector3 *targetLocation) { CCList<CCSceneCollideable> &collideables = gEngine->collisionManager.collideables; if( CCHasFlag( sourceObject->collideableType, collision_box ) ) { CCVector3 sourceMin = CCVector3( targetLocation->x - sourceObject->collisionBounds.x, targetLocation->y - sourceObject->collisionBounds.y, targetLocation->z - sourceObject->collisionBounds.z ); CCVector3 sourceMax = CCVector3( targetLocation->x + sourceObject->collisionBounds.x, targetLocation->y + sourceObject->collisionBounds.y, targetLocation->z + sourceObject->collisionBounds.z ); for( int i=0; i<collideables.length; ++i ) { CCSceneCollideable *checkingObject = collideables.list[i]; if( checkingObject != sourceObject ) { if( CCHasFlag( checkingObject->collideableType, collision_box ) ) { CCUpdateCollisions( checkingObject ); const CCVector3 &targetMin = checkingObject->min; const CCVector3 &targetMax = checkingObject->max; if( CCBasicBoxCollisionCheck( sourceMin, sourceMax, targetMin, targetMax ) ) { return checkingObject; } } } } } return NULL; }
CCSceneCollideable* CCBasicLineCollisionCheck(CCSceneCollideable **list, const int length, CCSceneCollideable *sourceObject, const CCVector3 &start, const CCVector3 &end, CCVector3 *hitLocation, const bool collideInsideObjects, const CCCollisionFlags flags, const bool stopAtAnyCollision) { float hitDistance = MAXFLOAT; CCSceneCollideable *hitObject = NULL; static CCVector3 currentHitLocation; static float currentHitDistance; for( int i=0; i<length; ++i ) { CCSceneCollideable *checkingObject = list[i]; if( checkingObject != sourceObject ) { if( checkingObject->enabled && checkingObject->isActive() && CCHasFlag( checkingObject->collideableType, flags ) ) { CCUpdateCollisions( checkingObject ); const CCVector3 &targetMin = checkingObject->min; const CCVector3 &targetMax = checkingObject->max; if( lineCheckBox( start, end, targetMin, targetMax, currentHitLocation, currentHitDistance ) ) { if( currentHitDistance < hitDistance && ( collideInsideObjects || currentHitDistance > 0.0f ) ) { hitDistance = currentHitDistance; hitObject = checkingObject; if( hitLocation != NULL ) { *hitLocation = currentHitLocation; } if( stopAtAnyCollision ) { return hitObject; } } } } } } // Finally test our source object if we have nothing else if( hitObject == NULL && sourceObject != NULL ) { CCSceneCollideable *checkingObject = sourceObject; CCUpdateCollisions( checkingObject ); const CCVector3 &targetMin = checkingObject->min; const CCVector3 &targetMax = checkingObject->max; if( lineCheckBox( start, end, targetMin, targetMax, currentHitLocation, currentHitDistance ) ) { if( currentHitDistance < hitDistance && ( collideInsideObjects || currentHitDistance > 0.0f ) ) { hitDistance = currentHitDistance; hitObject = checkingObject; *hitLocation = currentHitLocation; } } } return hitObject; }