void UpdateAgentsFromCrowdData(GSceneManager* crowdEngine, map<UID, IModel*>& agentModels, map<string, float> meshScales, map<string, IMesh*> meshList, map<UID, IModel*>& DestinationVectors, map<UID, IModel*>& MovementVectors) { //TODO: Find correct value for thisScale gen::CMatrix3x3 tempAgentMat; float tempModelMat[16]; for (auto agent : agentModels) { if (crowdEngine->GetAgentMatrix(agent.first, tempAgentMat)) { float thisScale = meshScales[FindStringFromMesh(agent.second->GetMesh(), meshList)]; agent.second->GetMatrix(tempModelMat); tempModelMat[0] = tempAgentMat.e00 * thisScale; tempModelMat[2] = tempAgentMat.e01 * thisScale; tempModelMat[8] = tempAgentMat.e10 * thisScale; tempModelMat[10] = tempAgentMat.e11 * thisScale; tempModelMat[12] = tempAgentMat.e20; tempModelMat[14] = tempAgentMat.e21; agent.second->SetMatrix(tempModelMat); } } #ifdef DirectionVisualiserEnabled gen::CVector2 tempDestination; for (auto destinationVector : DestinationVectors) { if (crowdEngine->GetAgentDestination(destinationVector.first, tempDestination)) { IModel* thisAgentModel = agentModels.at(destinationVector.first); //Set the vector model to the id model's position destinationVector.second->SetPosition(thisAgentModel->GetX(), thisAgentModel->GetY() + 10.0f, //+10 to have to vector model rest atop the id model thisAgentModel->GetZ()); destinationVector.second->LookAt(tempDestination.x, 10.0f, tempDestination.y); CVector2 vectorToEnd = tempDestination - CVector2(thisAgentModel->GetX(), thisAgentModel->GetZ()); destinationVector.second->ScaleZ(vectorToEnd.Length()); } } for (auto movementVector : MovementVectors) { //Will only fetch the results of global collision avoidance if (crowdEngine->GetAgentDesiredVector(movementVector.first, tempDestination)) { IModel* thisAgentModel = agentModels.at(movementVector.first); //Set the vector model to the id model's position movementVector.second->SetPosition(thisAgentModel->GetX(), thisAgentModel->GetY() + 11.0f, //+11 to have to vector model rest atop the id model thisAgentModel->GetZ()); movementVector.second->LookAt(tempDestination.x + thisAgentModel->GetX(), 10.0f, tempDestination.y + thisAgentModel->GetZ()); movementVector.second->ScaleZ(tempDestination.Length()); } } #endif }
void UpdateAgentFromCrowdData(UID agentID, GSceneManager* crowdEngine, map<UID, IModel*>& agentModels, map<string, float> meshScales, map<string, IMesh*> meshList, map<UID, IModel*>& DestinationVectors, map<UID, IModel*>& MovementVectors) { gen::CMatrix3x3 tempAgentMat; if (crowdEngine->GetAgentMatrix(agentID, tempAgentMat)) { try //Find the id 'holding' and set the holding skin { float tempModelMat[16]; IModel* thisAgentModel; thisAgentModel = agentModels.at(agentID); float thisScale = meshScales[FindStringFromMesh(thisAgentModel->GetMesh(), meshList)]; thisAgentModel->GetMatrix(tempModelMat); tempModelMat[0] = tempAgentMat.e00 * thisScale; tempModelMat[2] = tempAgentMat.e01 * thisScale; tempModelMat[8] = tempAgentMat.e10 * thisScale; tempModelMat[10] = tempAgentMat.e11 * thisScale; tempModelMat[12] = tempAgentMat.e20; tempModelMat[14] = tempAgentMat.e21; thisAgentModel->SetMatrix(tempModelMat); } catch (std::out_of_range err) { cout << err.what(); } } #ifdef DirectionVisualiserEnabled gen::CVector2 tempDestination; if (crowdEngine->GetAgentDestination(agentID, tempDestination)) { IModel* thisVectorModel; IModel* thisAgentModel; thisAgentModel = agentModels.at(agentID); thisVectorModel = DestinationVectors.at(agentID); //Set the vector model to the id model's position thisVectorModel->SetPosition(thisAgentModel->GetX(), thisAgentModel->GetY() + 10.0f, thisAgentModel->GetZ()); thisVectorModel->LookAt(tempDestination.x, 10.0f, tempDestination.y); CVector2 vectorToEnd = tempDestination - CVector2(thisAgentModel->GetX(), thisAgentModel->GetZ()); thisVectorModel->ScaleZ(vectorToEnd.Length()); } if (crowdEngine->GetAgentDesiredVector(agentID, tempDestination)) { IModel* thisVectorModel; IModel* thisAgentModel; thisAgentModel = agentModels.at(agentID); thisVectorModel = MovementVectors.at(agentID); //Set the vector model to the id model's position thisVectorModel->SetPosition(thisAgentModel->GetX(), thisAgentModel->GetY() + 10.0f, thisAgentModel->GetZ()); thisVectorModel->LookAt(tempDestination.x + thisAgentModel->GetX(), 10.0f, tempDestination.y + thisAgentModel->GetZ()); thisVectorModel->ScaleZ(tempDestination.Length()); } #endif }