void CrowdAgent::SetMoveVelocity(const Vector3& velocity) { const dtCrowdAgent* agent = GetDetourCrowdAgent(); if (agent && agent->active) { crowdManager_->GetCrowd()->requestMoveVelocity(agentCrowdId_, velocity.Data()); MarkNetworkUpdate(); } }
void CrowdAgent::SetTargetVelocity(const Vector3& velocity) { if (velocity != targetVelocity_ || CA_REQUESTEDTARGET_VELOCITY != requestedTargetType_) { targetVelocity_ = velocity; requestedTargetType_ = CA_REQUESTEDTARGET_VELOCITY; MarkNetworkUpdate(); if (IsInCrowd()) crowdManager_->GetCrowd()->requestMoveVelocity(agentCrowdId_, velocity.Data()); } }
int CrowdManager::AddAgent(CrowdAgent* agent, const Vector3& pos) { if (!crowd_ || !navigationMesh_ || !agent) return -1; dtCrowdAgentParams params; params.userData = agent; if (agent->radius_ == 0.f) agent->radius_ = navigationMesh_->GetAgentRadius(); if (agent->height_ == 0.f) agent->height_ = navigationMesh_->GetAgentHeight(); return crowd_->addAgent(pos.Data(), ¶ms); }
bool CrowdAgent::SetMoveVelocity(const Vector3& velocity) { if (crowdManager_ && inCrowd_) { const dtCrowdAgent* agent = crowdManager_->GetCrowdAgent(agentCrowdId_); if (agent && agent->active) { crowdManager_->GetCrowd()->requestMoveVelocity(agentCrowdId_, velocity.Data()); MarkNetworkUpdate(); } } return false; }
int CrowdManager::AddAgent(CrowdAgent* agent, const Vector3& pos) { if (!crowd_ || !navigationMesh_ || !agent) return -1; dtCrowdAgentParams params; params.userData = agent; if (agent->radius_ == 0.f) agent->radius_ = navigationMesh_->GetAgentRadius(); if (agent->height_ == 0.f) agent->height_ = navigationMesh_->GetAgentHeight(); // dtCrowd::addAgent() requires the query filter type to find the nearest position on navmesh as the initial agent's position params.queryFilterType = (unsigned char)agent->GetQueryFilterType(); return crowd_->addAgent(pos.Data(), ¶ms); }
bool DetourCrowdManager::SetAgentTarget(CrowdAgent* agent, Vector3 target) { if (!crowd_) return false; dtPolyRef polyRef; float nearestPos[3]; dtStatus status = navigationMesh_->navMeshQuery_->findNearestPoly( target.Data(), crowd_->getQueryExtents(), crowd_->getFilter(agent->filterType_), &polyRef, nearestPos); return !dtStatusFailed(status) && crowd_->requestMoveTarget(agent->GetAgentCrowdId(), polyRef, nearestPos); }
Vector3 DetourCrowdManager::GetClosestWalkablePosition(Vector3 pos) const { if (!crowd_) return Vector3::ZERO; float closest[3]; const static float extents[] = { 1.0f, 20.0f, 1.0f }; dtPolyRef closestPoly; dtQueryFilter filter; dtStatus status = navigationMesh_->navMeshQuery_->findNearestPoly( pos.Data(), crowd_->getQueryExtents(), &filter, &closestPoly, closest); return Vector3(closest); }
bool DetourCrowdManager::SetAgentTarget(CrowdAgent* agent, Vector3 target, unsigned& targetRef) { if (crowd_ == 0) return false; float nearestPos[3]; dtStatus status = navigationMesh_->navMeshQuery_->findNearestPoly( target.Data(), crowd_->getQueryExtents(), crowd_->getFilter(agent->filterType_), &targetRef, nearestPos); // Return true if detour has determined it can do something with our move target return !dtStatusFailed(status) && crowd_->requestMoveTarget(agent->GetAgentCrowdId(), targetRef, nearestPos) && crowd_->getAgent(agent->GetAgentCrowdId())->targetState != DT_CROWDAGENT_TARGET_FAILED; }
void updateListenerPostion(Node *n) { if(n) { Vector3 pos = n->GetWorldPosition(); Vector3 upv = n->GetWorldUp(); Vector3 forwardv = n->GetWorldDirection(); float ori[6]; ori[0] = forwardv.x_; ori[1] = forwardv.y_; ori[2] = forwardv.z_; ori[3] = upv.x_; ori[4] = upv.y_; ori[5] = upv.z_; alListenerfv(AL_POSITION, pos.Data()); alListenerfv(AL_ORIENTATION, ori); } }
void CrowdAgent::SetTargetPosition(const Vector3& position) { if (position != targetPosition_ || CA_REQUESTEDTARGET_POSITION != requestedTargetType_) { targetPosition_ = position; requestedTargetType_ = CA_REQUESTEDTARGET_POSITION; MarkNetworkUpdate(); if (!IsInCrowd()) AddAgentToCrowd(); if (IsInCrowd()) // Make sure the previous method call is successful { dtPolyRef nearestRef; Vector3 nearestPos = crowdManager_->FindNearestPoint(position, queryFilterType_, &nearestRef); crowdManager_->GetCrowd()->requestMoveTarget(agentCrowdId_, nearestRef, nearestPos.Data()); } } }
int DetourCrowdManager::AddAgent(CrowdAgent* agent, const Vector3& pos) { if (!crowd_ || navigationMesh_.Expired()) return -1; dtCrowdAgentParams params; params.userData = agent; if (agent->radius_ <= 0.0f) agent->radius_ = navigationMesh_->GetAgentRadius(); params.radius = agent->radius_; if (agent->height_ <= 0.0f) agent->height_ = navigationMesh_->GetAgentHeight(); params.height = agent->height_; params.queryFilterType = (unsigned char)agent->filterType_; params.maxAcceleration = agent->maxAccel_; params.maxSpeed = agent->maxSpeed_; params.collisionQueryRange = params.radius * 8.0f; params.pathOptimizationRange = params.radius * 30.0f; params.updateFlags = DT_CROWD_ANTICIPATE_TURNS | DT_CROWD_OPTIMIZE_VIS | DT_CROWD_OPTIMIZE_TOPO | DT_CROWD_OBSTACLE_AVOIDANCE; params.obstacleAvoidanceType = 3; params.separationWeight = 2.0f; params.queryFilterType = 0; dtPolyRef polyRef; float nearestPos[3]; rcVcopy(nearestPos, &pos.x_); dtStatus status = navigationMesh_->navMeshQuery_->findNearestPoly( pos.Data(), crowd_->getQueryExtents(), crowd_->getFilter(agent->filterType_), &polyRef, nearestPos); const int agentID = crowd_->addAgent(nearestPos, ¶ms); if (agentID != -1) agents_.Push(agent); return agentID; }
Vector3 Deserializer::ReadVector3() { Vector3 ret; Read((void*)ret.Data(), sizeof ret); return ret; }