//----------------------------------------------------------------------------- // Returns a random player spawnpoint. //----------------------------------------------------------------------------- SceneObject *SceneManager::GetRandomPlayerSpawnPoint() { // Get a random spawn point. SceneObject *point = m_playerSpawnPoints->GetRandom(); // If the spawner's collision stamp equals the current frame stamp, then // something has collided with the spawner. Alternatively this spawner may // not be enabled. In either case, return NULL to indicate that a vacent // spawn point was not found. The caller will have to try again later. if( point->GetCollisionStamp() != m_frameStamp && point->GetEnabled() == true ) return point; else return NULL; }
//----------------------------------------------------------------------------- // Returns the result of a ray intersection with the scene and all its objects. //----------------------------------------------------------------------------- bool SceneManager::RayIntersectScene( RayIntersectionResult *result, D3DXVECTOR3 rayPosition, D3DXVECTOR3 rayDirection, bool checkScene, SceneObject *thisObject, bool checkObjects ) { float hitDistance = 0.0f; // Check if the ray needs to check for intersection with the scene. if( checkScene == true ) { // Go through all the faces in the scene, check for intersection. for( unsigned long f = 0; f < m_totalFaces; f++ ) { // Skip this face if its material is set to ignore rays. if( m_faces[f].renderCache->GetMaterial()->GetIgnoreRay() == true ) continue; // Check the ray against this face. if( D3DXIntersectTri( (D3DXVECTOR3*)&m_vertices[m_faces[f].vertex0], (D3DXVECTOR3*)&m_vertices[m_faces[f].vertex1], (D3DXVECTOR3*)&m_vertices[m_faces[f].vertex2], &rayPosition, &rayDirection, NULL, NULL, &hitDistance ) == TRUE ) { if( hitDistance < result->distance || result->material == NULL ) { ( *result ).distance = hitDistance; ( *result ).material = m_faces[f].renderCache->GetMaterial(); } } } } // Check if the ray needs to check for intersection with the objects. if( checkObjects == true ) { // Stores the ray in model space. D3DXVECTOR3 rp, rd; // Iterate all the objects in the scene, check for intersection. SceneObject *object = m_dynamicObjects->GetFirst(); while( object != NULL ) { // Only check this object if it is enabled, has a mesh and is not // the calling object. if( object->GetEnabled() == true && object->GetMesh() != NULL && object != thisObject ) { // Transform the ray into model space. D3DXMATRIX inverse; D3DXMatrixInverse( &inverse, NULL, object->GetWorldMatrix() ); D3DXVec3TransformCoord( &rp, &rayPosition, &inverse ); D3DXVec3TransformNormal( &rd, &rayDirection, &inverse ); // Go through the list of frames in the object's mesh. LinkedList< Frame > *frames = object->GetMesh()->GetFrameList(); frames->Iterate( true ); while( frames->Iterate() != NULL ) { // Ignore this frame if it has no mesh. if( frames->GetCurrent()->pMeshContainer == NULL ) continue; // Check the ray against this frame's mesh. BOOL hit; D3DXIntersect( frames->GetCurrent()->pMeshContainer->MeshData.pMesh, &rp, &rd, &hit, NULL, NULL, NULL, &hitDistance, NULL, NULL ); if( hit == TRUE && ( hitDistance < result->distance || result->material == NULL ) ) { ( *result ).distance = hitDistance; ( *result ).material = object->GetMesh()->GetStaticMesh()->materials[0]; ( *result ).hitObject = object; } } } // Go to the next object. object = m_dynamicObjects->GetNext( object ); } } // Return false if no intersection occured. if( result->material == NULL ) return false; // Calculate the point of intersection. ( *result ).point = rayPosition + rayDirection * result->distance; return true; }