示例#1
0
CCSceneCollideable* CCBasicLineCollisionCheck(const CCVector3 &start, 
                                              const CCVector3 &end,
                                              const float width,
                                              CCSceneCollideable *source)
{	
    static CCVector3 hitLocation;
    CCSceneCollideable *hitObject = CCBasicLineCollisionCheck( gEngine->collisionManager.collideables.list,
                                                               gEngine->collisionManager.collideables.length,
                                                               source,
                                                               start, end,
                                                               &hitLocation,
                                                               true,
                                                               collision_static,
                                                               true );
    if( hitObject == NULL )
    {
        static CCVector3 minStart, minEnd, maxStart, maxEnd;
        minStart.set( start.x - width, start.y, start.z - width );
        minEnd.set( end.x - width, start.y, end.z - width );
        maxStart.set( start.x + width, start.y, start.z + width );
        maxEnd.set( end.x - width, start.y, end.z - width );

        hitObject = CCBasicLineCollisionCheck( gEngine->collisionManager.collideables.list,
                                               gEngine->collisionManager.collideables.length,
                                               NULL,
                                               minStart, maxEnd,
                                               &hitLocation,
                                               true,
                                               collision_static,
                                               true );

        if( hitObject == NULL )
        {
            hitObject = CCBasicLineCollisionCheck( gEngine->collisionManager.collideables.list,
                                                   gEngine->collisionManager.collideables.length,
                                                   NULL,
                                                   maxStart, minEnd,
                                                   &hitLocation,
                                                   true,
                                                   collision_static,
                                                   true );
        }
    }

    return hitObject;
}
示例#2
0
void CCPathFinderNetwork::view()
{
    if( nodes.length > 0 && connectingNodes == false )
    {
		gEngine->textureManager->setTextureIndex( 1 );

        const CCColour nodeColour = CCColour( 1.0f, 0.0f, 0.0f, 1.0f );
        const CCColour pathColour = CCColour( 1.0f, 1.0f, 1.0f, 1.0f );

        CCSetColour( nodeColour );

        for( int i=0; i<nodes.length; ++i )
        {
            const PathNode *node = nodes.list[i];
            GLPushMatrix();
            GLTranslatef( node->point.x, node->point.y, node->point.z );
            CCRenderCube( true );
            GLPopMatrix();
        }

        static CCVector3 start, end;
		{
            GLVertexPointer( 3, GL_FLOAT, sizeof( PathNode ), &nodes.list[0]->point, nodes.length );
#ifndef DXRENDERER
            GLDrawArrays( GL_POINTS, 0, nodes.length );
#endif

            for( int i=0; i<nodes.length; ++i )
            {
                const PathNode *node = nodes.list[i];
                const CCList<PathNode::PathConnection> &connections = node->connections;
                for( int j=0; j<connections.length; ++j )
                {
                    const PathNode::PathConnection *connection = connections.list[j];
                    start.set( node->point.x, 2.0f, node->point.z );
                    end.set( connection->node->point.x, 2.0f, connection->node->point.z );
                    CCRenderLine( start, end );
                }
            }
        }

        if( pathingFrom != NULL )
        {
            CCRenderer::CCSetDepthRead( false );

            CCSetColour( pathColour );

            const PathNode *currentNode = pathingFrom;
            for( int i=0; i<path.endDirection; ++i )
            {
                const int connectionIndex = path.directions[i];
                const CCList<PathNode::PathConnection> &connections = currentNode->connections;
                if( connectionIndex < connections.length )
                {
                    const PathNode::PathConnection *connection = connections.list[connectionIndex];
                    const PathNode *toNode = connection->node;
                    ASSERT( toNode != NULL );
                    start.set( currentNode->point.x, 5.0f, currentNode->point.z );
                    end.set( toNode->point.x, 5.0f, toNode->point.z );
                    CCRenderLine( start, end );
                    currentNode = toNode;
                }
            }

            CCRenderer::CCSetDepthRead( true );
        }
    }
}