예제 #1
0
void Character::updatePosition(Ogre::Real timeSinceLastFrame)
{
    if(!isLoaded())
        return;

    if (mAgentControlled) {
        if(getAgent()->active) {
            Ogre::Vector3 agentPos;
            OgreRecast::FloatAToOgreVect3(getAgent()->npos, agentPos);

            getNode()->setPosition(agentPos);
        }
    } else {
        // Move character manually to new position
        if(getVelocity().isZeroLength())
            return;

        // Make other agents avoid first character by placing a temporary obstacle in its position
        mDetourTileCache->removeTempObstacle(mTempObstacle);   // Remove old obstacle
        getNode()->setPosition(getPosition() + timeSinceLastFrame * getVelocity());
        // TODO check whether this position is within navmesh
        mTempObstacle = mDetourTileCache->addTempObstacle(getPosition());   // Add new obstacle
    }

    // Clip position to terrain height
    if (mClipTo)
        clipToTerrainHeight();
}
예제 #2
0
bool ShootingWeapon::canFire(QPointF pt)
{
	if(distanceBetweenPoints(getAgent()->pos(), pt) <= range){
		return true;
	}
	return false;
}
예제 #3
0
void PheromoneDepositor::placePheromoneItem(PheromoneItem *pi)
{
	Agent *ag = getAgent();
	PheromoneItem *tmpPI;
	QList<QGraphicsItem*> items;
	int numItems;
//    QGraphicsObject *obj;
	int tmpX = math::roundedMultiplo(ag->x(), gridSpace),
			tmpY = math::roundedMultiplo(ag->y(), gridSpace);
	bool putNewPheromone = true;

	items = ag->scene()->items(QPointF(tmpX, tmpY));
	numItems = items.count();
	for(int i = 0; i < numItems; i++){
		if((tmpPI = dynamic_cast<PheromoneItem*>(items[i]))){
			tmpPI->incrementPheromoneValue(pheromoneIntensity);
			if(lastPheromoneItem){
				tmpPI->addLastPheromone(lastPheromoneItem.data());
			}
			lastPheromoneItem = tmpPI;
			putNewPheromone = false;
			delete pi;
			break;
		}else{
			putNewPheromone = true;
		}
	}
	if(putNewPheromone){
		pi->setPos(tmpX, tmpY);
//        if(!lastPheromoneItem.isNull()){
			pi->addLastPheromone(lastPheromoneItem.data());
//        }
		ag->scene()->addItem(pi);
	}
}
예제 #4
0
Ogre::Real Character::getMaxAcceleration()
{
    if(isLoaded())
        return getAgent()->params.maxAcceleration;
    else
        return 0.0f;
}
예제 #5
0
Ogre::Real Character::getMaxSpeed()
{
    if(isLoaded())
        return getAgent()->params.maxSpeed;
    else
        return 0.0f;
}
예제 #6
0
    void LocationModel::insertNetworkModels(std::set<LocationModel *> &network)
    {
        std::set<LocationModel *> fringe;
        fringe.insert(this);

        auto agentMan = mLocationModelMan->level()->agentMan();
        auto insertLocationModelsInFringeIfNotInNetwork = [&network, &fringe, agentMan](std::set<AgentId> const & nodes)->void
        {
            for(auto const & aid : nodes)
            {
                Agent *agent = agentMan->getAgent(aid);

                if(nullptr == agent || INVALID_ID == agent->locationModelId() || network.end() != network.find(agent->locationModel()))
                    continue;

                fringe.insert(agent->locationModel());
            }
        };

        while(fringe.size())
        {
            LocationModel *model = *fringe.begin();
            fringe.erase(fringe.begin());

            if(nullptr == model)
                continue;

            network.insert(model);
            insertLocationModelsInFringeIfNotInNetwork(model->sources());
            insertLocationModelsInFringeIfNotInNetwork(model->destinations());
        }
    }
예제 #7
0
bool ShootingWeapon::canFire(Unit *un)
{
//    Agent *agent = getAgent();
	if(distanceBetweenUnits(getAgent(), un) <= range){
		return true;
	}
	return false;
}
예제 #8
0
파일: AgentManager.cpp 프로젝트: onze/Steel
    bool AgentManager::assignBTPath(AgentId movableAid, AgentId pathAid)
    {
        Agent *movableAgent;

        if(nullptr == (movableAgent = getAgent(movableAid)))
            return false;

        return movableAgent->followNewPath(pathAid);
    }
예제 #9
0
파일: AgentManager.cpp 프로젝트: onze/Steel
    bool AgentManager::unassignBTPath(AgentId movableAid, AgentId pathAid)
    {
        Agent *movableAgent;

        if(nullptr == (movableAgent = getAgent(movableAid)))
            return true;

        return movableAgent->stopFollowingPath(pathAid);
    }
예제 #10
0
dtOffMeshConnection* dtCrowdQuery::getOffMeshConnection(unsigned id, float dist) const
{
	// Check validity of the ID
	if (id >= m_maxAgents || dist < 0.f)
		return 0;

	const dtCrowdAgent ag = *getAgent(id);
	dtPolyRef agentPolyRef;
	float nearest[3];

	// Get the polygon reference the agent is on
	m_navMeshQuery->findNearestPoly(ag.position, m_ext, &m_filter, &agentPolyRef, nearest);

	if (!agentPolyRef)
		return 0;

	dtPoly poly;
	dtMeshTile tile;
	const dtPoly* ptrPoly = &poly;
	const dtMeshTile* ptrTile = &tile;

	// Get the tile the agent is on
	if (dtStatusFailed(m_navMeshQuery->getAttachedNavMesh()->getTileAndPolyByRef(agentPolyRef, 
																				(const dtMeshTile**)(&ptrTile), 
																				(const dtPoly**)(&ptrPoly))))
		return 0;

	if (ptrTile->header->offMeshConCount <= 0)
		return 0;

	unsigned nbOffMeshConnections = ptrTile->header->offMeshConCount;
	dtOffMeshConnection* offMeshConnections = ptrTile->offMeshCons;

	// For every offMesh connections located in this tile
	for (unsigned i = 0; i < nbOffMeshConnections; ++i)
	{
		dtPolyRef polysIDs[256];
		int nbPolys = 0;
		dtOffMeshConnection& offMeshCo = offMeshConnections[i];

		// Find every polygons reached by the offMesh connection and its radius
		if (dtStatusFailed(m_navMeshQuery->findPolysAroundCircle(agentPolyRef, offMeshCo.pos, offMeshCo.rad, &m_filter, polysIDs, 0, 0, &nbPolys, 256)))
			continue;

		if (nbPolys <= 0)
			continue;

		// For every polygons touched by the offMesh connection, we check if one of them is the one the agent is on.
		// If so, we check the distance from the agent to the center of the offMesh connection (taking into account the extra distance)
		for (int j = 0; j < nbPolys; ++j)
			if (polysIDs[j] == agentPolyRef)
				if (dtVdist(ag.position, offMeshCo.pos) < offMeshCo.rad + dist)
					return &offMeshCo;
	}

	return 0;
}
bool OgreDetourCrowd::requestVelocity(int agentId, Ogre::Vector3 velocity)
{
    if (!getAgent(agentId)->active)
        return false;

    float vel[3];
    OgreRecast::OgreVect3ToFloatA(velocity, vel);

    return m_crowd->requestMoveVelocity(agentId, vel);
}
예제 #12
0
bool Character::destinationReached()
{
    if(!isLoaded())
        return false;

    if(getPosition().squaredDistance(getDestination()) <= Character::DESTINATION_RADIUS)
        return true;


    return mDetourCrowd->destinationReached(getAgent(), Character::DESTINATION_RADIUS);
}
예제 #13
0
void ShootingWeapon::timerEvent(QTimerEvent *event)
{
	static int proyDistAnt = 999999;

	int eventID = event->timerId();
	if(eventID == timerID){
		QPainterPath path;
		ShootingUnit *su = static_cast<ShootingUnit*>(getAgent());
		if(unitToShoot != NULL && su){
			Vector2D line(su->pos(), unitToShoot->pos());
			line.setModulo(10);

			incProyectile += int(proyectileVelocity * double(timerInterval)/1000);
			QPointF startPoint = Vector2D(float(su->getRadius() + incProyectile), float(line.getAngle())).toPointF();

			double dist = distanceBetweenPoints(su->mapToScene(startPoint + line.toPointF()), unitToShoot->pos());

//            if(dist - proyDistAnt < 0){
			if((dist > unitToShoot->getRadius()) && (dist - proyDistAnt < 0)){
				path.moveTo(startPoint);
				path.lineTo(startPoint + line.toPointF());
				proyDistAnt = dist;
			}else{
				proyDistAnt = 999999;
				incProyectile = 0;
				secureKillTimer(timerID);

				//Decrementa la vitalidad
				unitToShoot->decrementHealth(getPower());

//                emit enemyHitted(su, unitToShoot);

			}
//            }else{
//                incProyectile = 0;
//                killTimer(timerID);
//                timerID = 0;
//                emit unitHitted(unitToShoot);
//            }
		}else{
			secureKillTimer(timerID);
		}
		setShape(path);
		su->update();
	}
//    else if(eventID == timerGarbageCollectorID){
//        foreach(void* item, gcItems){
//            delete item;
//        }
////        delete gcItems;
//        killTimer(timerGarbageCollectorID);
//        timerGarbageCollectorID = 0;
//    }
}
예제 #14
0
  QList<AgentInfo> ServerManager::getAgents() {
    QList<AgentInfo> agents;

    QSqlQuery query("SELECT ID FROM Agents");
    query.exec();

    while (query.next()) {
      agents.append(getAgent(query.value(0).toString()));
    }
    
    return agents;
  }
예제 #15
0
Ogre::Vector3 Character::getVelocity()
{
    if(!isLoaded())
        return Ogre::Vector3::ZERO;

    if(mAgentControlled) {
        Ogre::Vector3 velocity;
        OgreRecast::FloatAToOgreVect3(getAgent()->nvel, velocity);
        return velocity;
    } else {
        return mManualVelocity;
    }
}
예제 #16
0
void PheromoneDepositor::timerCheckDistanceEvent()
{
	MovilAgent *ag = dynamic_cast<MovilAgent*>(getAgent());
//    PheromoneItem *pi;
	if(ag->isMoving()){
		if(lastPheromoneItem){
			if(distanceToLastPheromone() >= pheromoneDistance){
				placePheromoneItem(pheromoneIntensity);
			}
		}else{
			placePheromoneItem(pheromoneIntensity);
		}
	}
}
void OgreDetourCrowd::setMoveTarget(int agentId, Ogre::Vector3 position, bool adjust)
{
    // TODO extract common method
    // Find nearest point on navmesh and set move request to that location.
    dtNavMeshQuery* navquery = m_recast->m_navQuery;
    dtCrowd* crowd = m_crowd;
    const dtQueryFilter* filter = crowd->getFilter();
    const float* ext = crowd->getQueryExtents();
    float p[3];
    OgreRecast::OgreVect3ToFloatA(position, p);

    navquery->findNearestPoly(p, ext, filter, &m_targetRef, m_targetPos);
    // ----

    if (adjust) {
        const dtCrowdAgent *ag = getAgent(agentId);
        float vel[3];
        calcVel(vel, ag->npos, p, ag->params.maxSpeed);
        crowd->requestMoveVelocity(agentId, vel);
    } else {
        m_crowd->requestMoveTarget(agentId, m_targetRef, m_targetPos);
    }
}
예제 #18
0
void Processor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& /*midiMessages*/)
{ 
  const int numInputChannels = getTotalNumInputChannels();
  const int numOutputChannels = getTotalNumOutputChannels();
  const size_t samplesToProcess = buffer.getNumSamples();

  // Determine channel data
  const float* channelData0 = nullptr;
  const float* channelData1 = nullptr;
  if (numInputChannels == 1)
  {    
    channelData0 = buffer.getReadPointer(0);
    channelData1 = buffer.getReadPointer(0);
  }
  else if (numInputChannels == 2)
  {
    channelData0 = buffer.getReadPointer(0);
    channelData1 = buffer.getReadPointer(1);
  }

  // Convolution
  _wetBuffer.clear();
  if (numInputChannels > 0 && numOutputChannels > 0)
  {
    float autoGain = 1.0f;
    if (getParameter(Parameters::AutoGainOn))
    {
      autoGain = DecibelScaling::Db2Gain(getParameter(Parameters::AutoGainDecibels));
    }

    // Convolve
    IRAgent* irAgent00 = getAgent(0, 0);
    if (irAgent00 && irAgent00->getConvolver() && numInputChannels >= 1 && numOutputChannels >= 1)
    {
      irAgent00->process(channelData0, &_convolutionBuffer[0], samplesToProcess);
      _wetBuffer.addFrom(0, 0, &_convolutionBuffer[0], samplesToProcess, autoGain);
    }

    IRAgent* irAgent01 = getAgent(0, 1);
    if (irAgent01 && irAgent01->getConvolver() && numInputChannels >= 1 && numOutputChannels >= 2)
    {
      irAgent01->process(channelData0, &_convolutionBuffer[0], samplesToProcess);
      _wetBuffer.addFrom(1, 0, &_convolutionBuffer[0], samplesToProcess, autoGain);
    }

    IRAgent* irAgent10 = getAgent(1, 0);
    if (irAgent10 && irAgent10->getConvolver() && numInputChannels >= 2 && numOutputChannels >= 1)
    {      
      irAgent10->process(channelData1, &_convolutionBuffer[0], samplesToProcess);
      _wetBuffer.addFrom(0, 0, &_convolutionBuffer[0], samplesToProcess, autoGain);
    }

    IRAgent* irAgent11 = getAgent(1, 1);
    if (irAgent11 && irAgent11->getConvolver() && numInputChannels >= 2 && numOutputChannels >= 2)
    {
      irAgent11->process(channelData1, &_convolutionBuffer[0], samplesToProcess);
      _wetBuffer.addFrom(1, 0, &_convolutionBuffer[0], samplesToProcess, autoGain);
    }
  }

  // Stereo width
  if (numOutputChannels >= 2)
  {
    _stereoWidth.updateWidth(getParameter(Parameters::StereoWidth));
    _stereoWidth.process(_wetBuffer.getWritePointer(0), _wetBuffer.getWritePointer(1), samplesToProcess);
  }

  // Dry/wet gain
  {
    float dryGain0, dryGain1;
    _dryGain.updateValue(DecibelScaling::Db2Gain(getParameter(Parameters::DryDecibels)));
    _dryGain.getSmoothValues(samplesToProcess, dryGain0, dryGain1);
    buffer.applyGainRamp(0, samplesToProcess, dryGain0, dryGain1);
  }
  {
    float wetGain0, wetGain1;
    _wetGain.updateValue(DecibelScaling::Db2Gain(getParameter(Parameters::WetDecibels)));
    _wetGain.getSmoothValues(samplesToProcess, wetGain0, wetGain1);
    _wetBuffer.applyGainRamp(0, samplesToProcess, wetGain0, wetGain1);
  }

  // Level measurement (dry)
  if (numInputChannels == 1)
  {    
    _levelMeasurementsDry[0].process(samplesToProcess, buffer.getReadPointer(0));
    _levelMeasurementsDry[1].reset();
  }
  else if (numInputChannels == 2)
  {
    _levelMeasurementsDry[0].process(samplesToProcess, buffer.getReadPointer(0));
    _levelMeasurementsDry[1].process(samplesToProcess, buffer.getReadPointer(1));
  }

  // Sum wet to dry signal
  {
    float dryOnGain0, dryOnGain1;
    _dryOn.updateValue(getParameter(Parameters::DryOn) ? 1.0f : 0.0f);
    _dryOn.getSmoothValues(samplesToProcess, dryOnGain0, dryOnGain1);
    buffer.applyGainRamp(0, samplesToProcess, dryOnGain0, dryOnGain1);
  }
  {
    float wetOnGain0, wetOnGain1;
    _wetOn.updateValue(getParameter(Parameters::WetOn) ? 1.0f : 0.0f);
    _wetOn.getSmoothValues(samplesToProcess, wetOnGain0, wetOnGain1);
    if (numOutputChannels > 0)
    {
      buffer.addFromWithRamp(0, 0, _wetBuffer.getReadPointer(0), samplesToProcess, wetOnGain0, wetOnGain1);
    }
    if (numOutputChannels > 1)
    {
      buffer.addFromWithRamp(1, 0, _wetBuffer.getReadPointer(1), samplesToProcess, wetOnGain0, wetOnGain1);
    }
  }

  // Level measurement (wet/out)
  if (numOutputChannels == 1)
  {
    _levelMeasurementsWet[0].process(samplesToProcess, _wetBuffer.getReadPointer(0));
    _levelMeasurementsWet[1].reset();
    _levelMeasurementsOut[0].process(samplesToProcess, buffer.getReadPointer(0));
    _levelMeasurementsOut[1].reset();
  }
  else if (numOutputChannels == 2)
  {
    _levelMeasurementsWet[0].process(samplesToProcess, _wetBuffer.getReadPointer(0));
    _levelMeasurementsWet[1].process(samplesToProcess, _wetBuffer.getReadPointer(1));
    _levelMeasurementsOut[0].process(samplesToProcess, buffer.getReadPointer(0));
    _levelMeasurementsOut[1].process(samplesToProcess, buffer.getReadPointer(1));
  }

  // In case we have more outputs than inputs, we'll clear any output
  // channels that didn't contain input data, (because these aren't
  // guaranteed to be empty - they may contain garbage).
  for (int i=numInputChannels; i<numOutputChannels; ++i)
  {
    buffer.clear(i, 0, buffer.getNumSamples());
  }

  // Update beats per minute info
  float beatsPerMinute = 0.0f;
  juce::AudioPlayHead* playHead = getPlayHead();
  if (playHead)
  {
    juce::AudioPlayHead::CurrentPositionInfo currentPositionInfo;
    if (playHead->getCurrentPosition(currentPositionInfo))
    {
      beatsPerMinute = static_cast<float>(currentPositionInfo.bpm);
    }
  }
  if (::fabs(_beatsPerMinute.exchange(beatsPerMinute)-beatsPerMinute) > 0.001f)
  {
    notifyAboutChange();
  }
}
예제 #19
0
bool TMailAgent::startFetchAgentAndContact()
{
    getAgent();
    getMailContact();

}
예제 #20
0
파일: AgentManager.cpp 프로젝트: onze/Steel
 bool AgentManager::agentHasLocationPath(AgentId aid)
 {
     Agent *agent = getAgent(aid);
     return nullptr == agent ? false : agent->hasLocationPath();
 }
예제 #21
0
파일: AgentManager.cpp 프로젝트: onze/Steel
 bool AgentManager::agentCanBePathDestination(AgentId const aid) const
 {
     Agent *agent = getAgent(aid);
     return nullptr == agent ? false : true;
 }
예제 #22
0
double PheromoneDepositor::distanceToLastPheromone()
{
	return lastPheromoneItem ? math::distance(lastPheromoneItem->pos(), getAgent()->pos()) : NAN;
}