void SearchingState::StartNewHidingSpotSearch( idAI *owner ) { Memory &memory = owner->GetMemory(); // grayman #3438 - exit if there's no focus for the search if( memory.alertPos.x == idMath::INFINITY ) { return; } // Clear flags memory.restartSearchForHidingSpots = false; memory.noMoreHidingSpots = false; memory.mandatory = false; // grayman #3331 // Clear all the ongoing tasks owner->senseSubsystem->ClearTasks(); owner->actionSubsystem->ClearTasks(); owner->movementSubsystem->ClearTasks(); // Stop moving owner->StopMove( MOVE_STATUS_DONE ); memory.StopReacting(); // grayman #3559 owner->MarkEventAsSearched( memory.currentSearchEventID ); // grayman #3424 memory.lastAlertPosSearched = memory.alertPos; // grayman #3492 // If we are supposed to search the stimulus location do that instead // of just standing around while the search completes if( memory.stimulusLocationItselfShouldBeSearched ) { // The InvestigateSpotTask will take this point as first hiding spot memory.currentSearchSpot = memory.alertPos; // Delegate the spot investigation to a new task, this will take the correct action. owner->actionSubsystem->PushTask( TaskPtr( new InvestigateSpotTask( memory.investigateStimulusLocationClosely ) ) ); //gameRenderWorld->DebugArrow(colorPink, owner->GetEyePosition(), memory.currentSearchSpot, 1, 2000); // Prevent overwriting this hiding spot in the upcoming Think() call memory.hidingSpotInvestigationInProgress = true; // Reset the flags //memory.stimulusLocationItselfShouldBeSearched = false; // grayman #3756 - reset in InvestigateSpotTask() memory.investigateStimulusLocationClosely = false; } else { // AI is not moving, wait for spot search to complete memory.hidingSpotInvestigationInProgress = false; memory.currentSearchSpot = idVec3( idMath::INFINITY, idMath::INFINITY, idMath::INFINITY ); } idVec3 minBounds( memory.alertPos - memory.alertSearchVolume ); idVec3 maxBounds( memory.alertPos + memory.alertSearchVolume ); idVec3 minExclusionBounds( memory.alertPos - memory.alertSearchExclusionVolume ); idVec3 maxExclusionBounds( memory.alertPos + memory.alertSearchExclusionVolume ); // Close any previous search owner->Event_CloseHidingSpotSearch(); // Hiding spot test now started memory.hidingSpotSearchDone = false; memory.hidingSpotTestStarted = true; // Invalidate the vector, clear the indices memory.firstChosenHidingSpotIndex = -1; memory.currentChosenHidingSpotIndex = -1; // Start search int res = owner->StartSearchForHidingSpotsWithExclusionArea( owner->GetEyePosition(), minBounds, maxBounds, minExclusionBounds, maxExclusionBounds, 255, owner ); if( res == 0 ) { // Search completed on first round memory.hidingSpotSearchDone = true; } }
Ogre::MeshPtr LodOutsideMarker::createConvexHullMesh(const String& meshName, const String& resourceGroupName) { // Based on the wiki sample: http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Generating+A+Mesh // Resource with given name should not exist! assert(MeshManager::getSingleton().getByName(meshName).isNull()); generateHull(); // calculate mHull triangles. // Convex hull can't be empty! assert(!mHull.empty()); MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, resourceGroupName, NULL); SubMesh* subMesh = mesh->createSubMesh(); vector<Real>::type vertexBuffer; vector<unsigned short>::type indexBuffer; // 3 position/triangle * 3 Real/position vertexBuffer.reserve(mHull.size() * 9); // 3 index / triangle indexBuffer.reserve(mHull.size() * 3); int id=0; // min & max position Vector3 minBounds(std::numeric_limits<Real>::max(), std::numeric_limits<Real>::max(), std::numeric_limits<Real>::max()); Vector3 maxBounds(std::numeric_limits<Real>::min(), std::numeric_limits<Real>::min(), std::numeric_limits<Real>::min()); for (size_t i = 0; i < mHull.size(); i++) { assert(!mHull[i].removed); for(size_t n = 0; n < 3; n++){ indexBuffer.push_back(id++); vertexBuffer.push_back(mHull[i].vertex[n]->position.x); vertexBuffer.push_back(mHull[i].vertex[n]->position.y); vertexBuffer.push_back(mHull[i].vertex[n]->position.z); minBounds.x = std::min<Real>(minBounds.x, mHull[i].vertex[n]->position.x); minBounds.y = std::min<Real>(minBounds.y, mHull[i].vertex[n]->position.y); minBounds.z = std::min<Real>(minBounds.z, mHull[i].vertex[n]->position.z); maxBounds.x = std::max<Real>(maxBounds.x, mHull[i].vertex[n]->position.x); maxBounds.y = std::max<Real>(maxBounds.y, mHull[i].vertex[n]->position.y); maxBounds.z = std::max<Real>(maxBounds.z, mHull[i].vertex[n]->position.z); } } /// Create vertex data structure for 8 vertices shared between submeshes mesh->sharedVertexData = new VertexData(); mesh->sharedVertexData->vertexCount = mHull.size() * 3; /// Create declaration (memory format) of vertex data VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration; size_t offset = 0; // 1st buffer decl->addElement(0, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); /// Allocate vertex buffer of the requested number of vertices (vertexCount) /// and bytes per vertex (offset) HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( offset, mesh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); /// Upload the vertex data to the card vbuf->writeData(0, vbuf->getSizeInBytes(), &vertexBuffer[0], true); /// Set vertex buffer binding so buffer 0 is bound to our vertex buffer VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding; bind->setBinding(0, vbuf); /// Allocate index buffer of the requested number of vertices (ibufCount) HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). createIndexBuffer( HardwareIndexBuffer::IT_16BIT, indexBuffer.size(), HardwareBuffer::HBU_STATIC_WRITE_ONLY); /// Upload the index data to the card ibuf->writeData(0, ibuf->getSizeInBytes(), &indexBuffer[0], true); /// Set parameters of the submesh subMesh->useSharedVertices = true; subMesh->indexData->indexBuffer = ibuf; subMesh->indexData->indexCount = indexBuffer.size(); subMesh->indexData->indexStart = 0; /// Set bounding information (for culling) mesh->_setBounds(AxisAlignedBox(minBounds, maxBounds)); mesh->_setBoundingSphereRadius(maxBounds.distance(minBounds) / 2.0f); /// Set material to transparent blue subMesh->setMaterialName("Examples/TransparentBlue50"); /// Notify -Mesh object that it has been loaded mesh->load(); return mesh; }