Esempio n. 1
0
void GLC_Octree::setDepth(int depth)
{
	m_OctreeDepth= depth;
	if (NULL != m_pRootNode)
	{
		updateSpacePartitioning();
	}
}
Esempio n. 2
0
void GLC_Octree::updateViewableInstances(const GLC_Frustum& frustum)
{
	if (NULL == m_pRootNode)
	{
		updateSpacePartitioning();
	}
	m_pRootNode->updateViewableInstances(frustum);
}
Esempio n. 3
0
QList<GLC_3DViewInstance*> GLC_Octree::listOfIntersectedInstances(const GLC_BoundingBox& bBox)
{
	if (NULL == m_pRootNode)
	{
		updateSpacePartitioning();
	}
	return m_pRootNode->setOfIntersectedInstances(bBox).toList();
}
Esempio n. 4
0
void GLC_Octree::createBox(GLC_Material* pMat, GLC_3DViewCollection* pCol)
{
	if (NULL == m_pRootNode)
	{
		updateSpacePartitioning();
	}

	if (NULL == pCol) pCol= m_pCollection;
	if (!m_pRootNode->isEmpty())
	{
		createBoxWithMaterial(pCol, m_pRootNode, pMat);
	}
}
//--------------------------------------------------------------
void ofApp::updateLinesMesh()
{
	float currTime = ofGetElapsedTimef();
	
	updateSpacePartitioning();
	
	// Now we update the line mesh, to do this we check each particle against every other particle, if they are
	// within a certain distance we draw a line between them. As this quickly becoems a pretty insane amount
	// of checks, we use our space partitioning scheme to optimize it all a little bit.
	
	linesMesh.clear();
	linesMesh.setMode( OF_PRIMITIVE_LINES );
	
	ofFloatColor scratchColor;
	scratchColor.set( 1.0f, 1.0f, 1.0f );
	
	lineConnectionMaxDistance =  ofMap( cosf( currTime / 7.0f ) , -1.0f, 1.0f, lineConnectionMaxDistanceMin, lineConnectionMaxDistanceMax); //   ofGetMouseY() / 10.0f;
	
	// how many slots do we need to check on each side?
	int spacePartitioningIndexDistanceX = ceil(lineConnectionMaxDistance / spacePartitioningGridWidth);
	int spacePartitioningIndexDistanceY = ceil(lineConnectionMaxDistance / spacePartitioningGridHeight);
	
	for( unsigned int particleIndex = 0; particleIndex < demos.size(); particleIndex++ )
	{
		DemoSphere* tmpParticle = &demos.at(particleIndex);
		
		/*
		if( tmpParticle->isMouseOvered )
		{
			continue; // skip to the next particle in the loop
		}*/
		
		// the particle knows where it is in the space partitioning grid, figure out which indices to loop between based
		// on how many slots the maximum line distance  can cover, then do a bounds check.
		int startIndexX = tmpParticle->spacePartitioningIndexX - spacePartitioningIndexDistanceX;
		if( startIndexX < 0 ) { startIndexX = 0; } if( startIndexX >= spacePartitioningResX ) { startIndexX = spacePartitioningResX-1;}
		
		int endIndexX   = tmpParticle->spacePartitioningIndexX + spacePartitioningIndexDistanceX;
		if( endIndexX < 0 ) { endIndexX = 0; } if( endIndexX >= spacePartitioningResX ) { endIndexX = spacePartitioningResX-1;}
		
		int startIndexY = tmpParticle->spacePartitioningIndexY - spacePartitioningIndexDistanceY;
		if( startIndexY < 0 ) { startIndexY = 0; } if( startIndexY >= spacePartitioningResY ) { startIndexY = spacePartitioningResY-1;}
		
		int endIndexY   = tmpParticle->spacePartitioningIndexY + spacePartitioningIndexDistanceY;
		if( endIndexY < 0 ) { endIndexY = 0; } if( endIndexY >= spacePartitioningResY ) { endIndexY = spacePartitioningResY-1;}
		
		for( int y = startIndexY; y < endIndexY; y++ )
		{
			for( int x = startIndexX; x < endIndexX; x++ )
			{
				for( unsigned int i = 0; i < spacePartitioningGrid.at(y).at(x).size(); i++ )
				{
					DemoSphere* tmpOtherParticle = spacePartitioningGrid.at(y).at(x).at(i);
									
					if( tmpOtherParticle->isMouseOvered )
					{
						continue; // skip to the next particle in the loop
					}
					
					if( tmpParticle->myID != tmpOtherParticle->myID )
					{
						ofVec3f diff = tmpParticle->pos - tmpOtherParticle->pos;
						float diffLength = diff.length();
						
						float tmpLineConnectionMaxDistance = lineConnectionMaxDistance;
						
						// lets make the allowed maximum distance smaller the closer we are to the mouse
						
//						tmpLineConnectionMaxDistance *= ofMap( demos[i].mouseDist, mouseAffectionRadius, 0.0f, 0.0f, 1.0f, true ); // the mouse reveals the mesh
						tmpLineConnectionMaxDistance *= ofMap( demos[i].mouseDist, mouseAffectionRadius, 0.0f, 1.0f, 0.0f, true ); // mouse takes away the mesh
						
						if( diffLength < tmpLineConnectionMaxDistance )
						{
							scratchColor.a =  1.0f - (diffLength / tmpLineConnectionMaxDistance);
							
							linesMesh.addVertex( tmpParticle->pos );
							//linesMesh.addColor( scratchColor );
							linesMesh.addColor( ofColor( tmpParticle->color, (int)(scratchColor.a * 255)) );
							
							linesMesh.addVertex( tmpOtherParticle->pos );
							//linesMesh.addColor( scratchColor );
							linesMesh.addColor( ofColor( tmpOtherParticle->color, (int)(scratchColor.a * 255)) );
							
							linesMesh.addIndex( linesMesh.getNumVertices() - 2 );
							linesMesh.addIndex( linesMesh.getNumVertices() - 1 );
						}
					}
				}
			}
		}
	}
	
}