Esempio n. 1
0
void CrowdAgent::SetMoveVelocity(const Vector3& velocity)
{
    const dtCrowdAgent* agent = GetDetourCrowdAgent();
    if (agent && agent->active)
    {
        crowdManager_->GetCrowd()->requestMoveVelocity(agentCrowdId_, velocity.Data());
        MarkNetworkUpdate();
    }
}
Esempio n. 2
0
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());
    }
}
Esempio n. 3
0
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(), &params);
}
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;
}
Esempio n. 5
0
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(), &params);
}
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;
}
Esempio n. 9
0
 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);
     }
 }
Esempio n. 10
0
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, &params);
    if (agentID != -1)
        agents_.Push(agent);
    return agentID;
}
Esempio n. 12
0
Vector3 Deserializer::ReadVector3()
{
    Vector3 ret;
    Read((void*)ret.Data(), sizeof ret);
    return ret;
}