//
// Behavior moveArcBehavior(target)
// Last modified: 07Nov2009
//
// Moves the robot using the parameterized movement vector,
// returning the appropriate robot behavior.
//
// Returns:     the appropriate robot behavior
// Parameters:
//      target  in/out  the target move of the behavior
//
Behavior Robot::moveArcBehavior(const Vector &target)
{
    GLfloat theta    = target.angle();
	  GLfloat phi      = this->heading.angle();
	  GLfloat delta    = degreesToRadians(theta);
    GLfloat cosDelta = cos(delta);
    GLfloat sinDelta = sin(delta);
	  GLfloat t        = cosDelta * cosDelta * sign(cosDelta);
	  GLfloat r        = sinDelta * sinDelta * sign(sinDelta);
	  behavior         = Behavior(ACTIVE, t, r, maxSpeed());
    if (abs(theta) < 90.0f)
	      behavior.setDiffVel(maxSpeed() * (t + r), maxSpeed() * (t - r));
    else
        behavior.setDiffVel(maxSpeed() * (t - r), maxSpeed() * (t + r));
	  return behavior;
/*
    GLfloat r     = target.magnitude();
    if (r <= threshold()) return moveStop();
    GLfloat theta = degreesToRadians(target.angle());
    if (theta == 0.0f)    return moveForwardBehavior(r);
    else return moveArcBehavior((abs(theta) >
                                degreesToRadians(angThreshold())) ?
                                0.0f :
                                r * theta / sin(theta), getDiameter() * theta);
*/
}   // moveArcBehavior(const Vector &)
Ejemplo n.º 2
0
// reset state
void LowSpeedTurn::reset(){
  // reset vehicle state
  SimpleVehicle::reset();
  // speed along Forward direction.
  speed(startSpeed);
  // initial position along X axis
  position(startX, 0, 0);
  // steering force clip magnitude
  maxForce(0.3f);
  // velocity  clip magnitude
  maxSpeed(1.5f);
  // for next instance: step starting location
  startX += 2;
  // for next instance: step speed
  startSpeed += 0.15f;
  // 15 seconds and 150 points along the trail
  setTrailParameters(15, 150);

  clearTrailHistory();    // prevent long streaks due to teleportation
  // load the mesh
  Mesh = getMesh_VehicleDisk();
  Box = Mesh.getBoundingbox();
  setScale(irr::core::vector3df(2.0, 1.0, 2.0));
  // disable lighting
  Material.Lighting = false;
}
Ejemplo n.º 3
0
//
// bool init(dx, dy, dz, theta, colorIndex)
// Last modified: 06Nov2009
//
// Initializes the object to the parameterized values,
// returning true if successful, false otherwise.
//
// Returns:     true if successful, false otherwise
// Parameters:
//      dx          in      the initial x-coordinate of the object (default 0)
//      dy          in      the initial y-coordinate of the object (default 0)
//      dz          in      the initial z-coordinate of the object (default 0)
//      colorIndex  in      the initial array index of the color of the object
//
bool Object::init(const GLfloat dx,    const GLfloat dy, const GLfloat dz,
                 const GLfloat theta, const Color   colorIndex)
{
    Circle::init(dx, dy, dz, DEFAULT_OBJECT_RADIUS, colorIndex);
    setHeading(theta);
    behavior         = DEFAULT_OBJECT_BEHAVIOR;
    behavior.setMaxSpeed(maxSpeed());
    showFilled       = DEFAULT_OBJECT_SHOW_FILLED;
    setEnvironment(NULL);
    return true;
}   // init(const GLfloat..<4>, const Color)
Ejemplo n.º 4
0
void 
OpenSteer::SimpleVehicle::annotationVelocityAcceleration (float maxLengthA, 
                                                          float maxLengthV)
{
    const float desat = 0.4f;
    const float aScale = maxLengthA / maxForce ();
    const float vScale = maxLengthV / maxSpeed ();
    const Vec3& p = position();
    const Vec3 aColor (desat, desat, 1); // bluish
    const Vec3 vColor (    1, desat, 1); // pinkish

    annotationLine (p, p + (velocity ()           * vScale), vColor);
    annotationLine (p, p + (_smoothedAcceleration * aScale), aColor);
}
//
// bool init(dx, dy, dz, theta, colorIndex)
// Last modified: 06Nov2009
//
// Initializes the robot to the parameterized values,
// returning true if successful, false otherwise.
//
// Returns:     true if successful, false otherwise
// Parameters:
//      dx          in      the initial x-coordinate of the robot (default 0)
//      dy          in      the initial y-coordinate of the robot (default 0)
//      dz          in      the initial z-coordinate of the robot (default 0)
//      theta       in      the initial heading of the robot (default 0)
//      colorIndex  in      the initial array index of the color of the robot
//
bool Robot::init(const GLfloat dx,    const GLfloat dy, const GLfloat dz,
                 const GLfloat theta, const Color   colorIndex)
{
    Circle::init(dx, dy, dz, DEFAULT_ROBOT_RADIUS, colorIndex);
    setHeading(theta);
    behavior         = DEFAULT_ROBOT_BEHAVIOR;
    behavior.setMaxSpeed(maxSpeed());
    showHeading      = DEFAULT_ROBOT_SHOW_HEADING;
    heading.showLine = DEFAULT_ROBOT_SHOW_LINE;
    heading.showHead = DEFAULT_ROBOT_SHOW_HEAD;
    showFilled       = DEFAULT_ROBOT_SHOW_FILLED;
    setEnvironment(NULL);
    return true;
}   // init(const GLfloat..<4>, const Color)
Ejemplo n.º 6
0
void 
OpenSteer::SimpleVehicle::applySteeringForce (const Vec3& force,
                                              const float elapsedTime)
{

    const Vec3 adjustedForce = adjustRawSteeringForce (force, elapsedTime);

    // enforce limit on magnitude of steering force
    const Vec3 clippedForce = adjustedForce.truncateLength (maxForce ());

    // compute acceleration and velocity
    Vec3 newAcceleration = (clippedForce / mass());
    Vec3 newVelocity = velocity();

    // damp out abrupt changes and oscillations in steering acceleration
    // (rate is proportional to time step, then clipped into useful range)
    if (elapsedTime > 0)
    {
        const float smoothRate = clip (9 * elapsedTime, 0.15f, 0.4f);
        blendIntoAccumulator (smoothRate,
                              newAcceleration,
                              _smoothedAcceleration);
    }

    // Euler integrate (per frame) acceleration into velocity
    newVelocity += _smoothedAcceleration * elapsedTime;

    // enforce speed limit
    newVelocity = newVelocity.truncateLength (maxSpeed ());

    // update Speed
    setSpeed (newVelocity.length());

    // Euler integrate (per frame) velocity into position
    setPosition (position() + (newVelocity * elapsedTime));

    // regenerate local space (by default: align vehicle's forward axis with
    // new velocity, but this behavior may be overridden by derived classes.)
    regenerateLocalSpace (newVelocity, elapsedTime);

    // maintain path curvature information
    measurePathCurvature (elapsedTime);

    // running average of recent positions
    blendIntoAccumulator (elapsedTime * 0.06f, // QQQ
                          position (),
                          _smoothedPosition);
}
Ejemplo n.º 7
0
OpenSteer::Vec3 
OpenSteer::SimpleVehicle::adjustRawSteeringForce (const Vec3& force,
                                                  const float /* deltaTime */)
{
    const float maxAdjustedSpeed = 0.2f * maxSpeed ();

    if ((speed () > maxAdjustedSpeed) || (force == Vec3::zero))
    {
        return force;
    }
    else
    {
        const float range = speed() / maxAdjustedSpeed;
        // const float cosine = interpolate (pow (range, 6), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 10), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 20), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 100), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 50), 1.0f, -1.0f);
        const float cosine = interpolate (pow (range, 20), 1.0f, -1.0f);
        return limitMaxDeviationAngle (force, cosine, forward());
    }
}
//
// Behavior orbitBehavior(target, dist)
// Last modified: 03Sep2006
//
// Guides the robot around the parameterized target
// in a circular path maintaining the parameterized distance,
// returning the appropriate robot behavior.
//
// Returns:     the appropriate robot behavior
// Parameters:
//      target  in/out  the target to orbit
//      dist    in      the distance to maintain from the target
//
Behavior Robot::orbitBehavior(const Vector &target, const GLfloat dist)
{
    return sumBehaviors(orientForOrbitBehavior(target, dist),
                        moveForwardBehavior(maxSpeed()));
}   // orbit(const Vector &, const GLfloat)
Ejemplo n.º 9
0
float CAListView::maxSpeedCache(float dt)
{
    return (maxSpeed(dt) * 3.0f);
}
//
// GLfloat maxAngSpeed() const
// Last modified: 03Sep2006
//
// Returns the max angular speed of this robot.
//
// Returns:     the max angular speed of this robot
// Parameters:  <none>
//
GLfloat Robot::maxAngSpeed() const
{
    return radiansToDegrees(maxSpeed() / radius);
}   // maxAngSpeed() const
Ejemplo n.º 11
0
float CATableView::maxSpeedCache(float dt)
{
    return (maxSpeed(dt) * 3.0f);
}
	//-----------------------------------------------------------------------------
	// compute combined steering force: move forward, avoid obstacles
	// or neighbors if needed, otherwise follow the path and wander
	osVector3 Pedestrian::determineCombinedSteering (const float elapsedTime)
	{
		// note: to enable a better view on a remote vehicle we just
		//       skip computing a steering force for these guys
		//       it is the model to use anyways
		//       AI code has nothing todo on the remote side
		if( isRemoteObject() )	{
			return osVector3::zero;
		}

		// move forward
		osVector3 steeringForce = forward();

		// probability that a lower priority behavior will be given a
		// chance to "drive" even if a higher priority behavior might
		// otherwise be triggered.
		//	const float leakThrough = 0.1f;

		// no random behaviour for network samples
		const float leakThrough = -1.0f;

		// determine if obstacle avoidance is required
		osVector3 obstacleAvoidance;
		if (leakThrough < frandom01())	{
			const float oTime = 6; // minTimeToCollision = 6 seconds
			// ------------------------------------ xxxcwr11-1-04 fixing steerToAvoid
			// just for testing
			//             obstacleAvoidance = steerToAvoidObstacles (oTime, gObstacles);
			//             obstacleAvoidance = steerToAvoidObstacle (oTime, gObstacle1);
			//             obstacleAvoidance = steerToAvoidObstacle (oTime, gObstacle3);
			obstacleAvoidance = steerToAvoidObstacles (oTime, gObstacles);
			// ------------------------------------ xxxcwr11-1-04 fixing steerToAvoid
		}

		// if obstacle avoidance is needed, do it
		if (obstacleAvoidance != osVector3::zero)	{
			steeringForce += obstacleAvoidance;
		}
		else	{
			// otherwise consider avoiding collisions with others
			osVector3 collisionAvoidance;
			const float caLeadTime = 3;

			// find all neighbors within maxRadius using proximity database
			// (radius is largest distance between vehicles traveling head-on
			// where a collision is possible within caLeadTime seconds.)
			const float maxRadius = caLeadTime * maxSpeed() * 2;
			if( _proximityToken != nullptr)	{
				_neighbors.clear();
				_proximityToken->findNeighbors (position(), maxRadius, _neighbors);
			}

			// allways avoid neighbors
			//		if (leakThrough < frandom01())	
			{
				collisionAvoidance = steerToAvoidNeighbors (caLeadTime, _neighbors) * 10;
			}
			// if collision avoidance is needed, do it
			if (collisionAvoidance != osVector3::zero)	{
				steeringForce += collisionAvoidance;
			}
			else	{
#if 0
				NetPedestrianPlugin* netPedestrianPlugin = dynamic_cast<NetPedestrianPlugin*>(getParentEntity());
				// add in wander component (according to user switch)
				if (netPedestrianPlugin->m_bWanderSwitch)
					steeringForce += steerForWander (elapsedTime);
#endif
				// do (interactively) selected type of path following
				const float pfLeadTime = 3;
				const bool useDirectPathFollowing(true);
				const osVector3 pathFollow =
					(useDirectPathFollowing ? //(netPedestrianPlugin->m_bUseDirectedPathFollowing ?
					steerToFollowPath (pathDirection, pfLeadTime, *path) :
				steerToStayOnPath (pfLeadTime, *path));

				// add in to steeringForce
				steeringForce += pathFollow * 0.5;
			}
		}
#if OPENSTEER_Z_ISUP
		// return steering constrained to global XY "ground" plane
		return steeringForce.setZtoZero();
#else
		// return steering constrained to global XZ "ground" plane
		return steeringForce.setYtoZero();
#endif
	}
Ejemplo n.º 13
0
float CAAutoCollectionView::maxSpeedCache(float dt)
{
    return (maxSpeed(dt) * 2.0f);
}
Ejemplo n.º 14
0
float CATableView::maxSpeedCache(float delay)
{
    return (maxSpeed(delay) * 3.0f);
}
Ejemplo n.º 15
0
int Solid::Processor::maxSpeed() const
{
    Q_D(const Processor);
    return_SOLID_CALL(Ifaces::Processor *, d->backendObject(), 0, maxSpeed());
}
Ejemplo n.º 16
0
void CAScrollView::deaccelerateScrolling(float dt)
{
    dt = MIN(dt, 1/30.0f);
    dt = MAX(dt, 1/100.0f);

    if (m_tInertia.getLength() > maxSpeedCache(dt))
    {
        m_tInertia = ccpMult(m_tInertia, maxSpeedCache(dt) / m_tInertia.getLength());
    }
    
    DPoint speed = DPointZero;
    if (m_tInertia.getLength() > maxSpeed(dt))
    {
        speed = ccpMult(m_tInertia, maxSpeed(dt) / m_tInertia.getLength());
    }
    else
    {
        speed = m_tInertia;
    }
    
    DPoint point = m_pContainer->getFrameOrigin();

    if (m_bBounces)
    {
        DPoint resilience = DPointZero;
        DSize size = this->getBounds().size;
        DPoint curr_point = m_pContainer->getFrameOrigin();
        DPoint relust_point = curr_point;
        this->getScrollWindowNotOutPoint(relust_point);
        float off_x = relust_point.x - curr_point.x;
        float off_y = relust_point.y - curr_point.y;
        
        if (fabsf(off_x) > FLT_EPSILON)
        {
            resilience.x = off_x / size.width;
        }
        
        if (fabsf(off_y) > FLT_EPSILON)
        {
            resilience.y = off_y / size.height;
        }
        
        resilience = ccpMult(resilience, maxSpeed(dt));
        
        if (speed.getLength() < resilience.getLength())
        {
            speed = resilience;
            m_tInertia = DPointZero;
        }
    }
    
    if (speed.getLength() < 0.25f)
    {
        m_tInertia = DPointZero;
        this->getScrollWindowNotOutPoint(point);
        this->setContainerFrame(point);
        this->update(0);
        this->hideIndicator();
        this->stopDeaccelerateScroll();
        
        if (m_pScrollViewDelegate)
        {
            m_pScrollViewDelegate->scrollViewStopMoved(this);
        }
        
    }
    else
    {
        point = ccpAdd(point, speed);

        if (this->isScrollWindowNotMaxOutSide(point))
        {
            m_tInertia = DPointZero;
        }
        
        if (m_bBounces == false)
        {
            this->getScrollWindowNotOutPoint(point);
        }
        else
        {
            if (m_bBounceHorizontal == false)
            {
                point.x = this->getScrollWindowNotOutHorizontal(point.x);
            }
            
            if (m_bBounceVertical == false)
            {
                point.y = this->getScrollWindowNotOutVertical(point.y);
            }
        }

        if (point.equals(m_pContainer->getFrameOrigin()))
        {
            m_tInertia = DPointZero;
        }
        else
        {
            this->showIndicator();
            this->setContainerFrame(point);
        }
        
        if (fabsf(m_tInertia.x) > 16)
        {
            m_tInertia.x = m_tInertia.x * (1 - decelerationRatio(dt));
        }
        else if (fabsf(m_tInertia.x) > FLT_EPSILON)
        {
            m_tInertia.x = MAX((fabsf(m_tInertia.x) - 0.5f), 0) * fabsf(m_tInertia.x) / m_tInertia.x;
        }
        
        if (fabsf(m_tInertia.y) > 16)
        {
            m_tInertia.y = m_tInertia.y * (1 - decelerationRatio(dt));
        }
        else if (fabsf(m_tInertia.y) > FLT_EPSILON)
        {
            m_tInertia.y = MAX((fabsf(m_tInertia.y) - 0.5f), 0) * fabsf(m_tInertia.y) / m_tInertia.y;
        }
        
        if (m_pScrollViewDelegate)
        {
            m_pScrollViewDelegate->scrollViewDidMoved(this);
        }
    }
}
//
// bool setRadius(s)
// Last modified: 03Sep2006
//
// Attempts to set the radius to the parameterized radius,
// returning true if successful, false otherwise.
//
// Returns:     true if successful, false otherwise
// Parameters:
//      r       in      the radius to be set to
//
bool Robot::setRadius(const GLfloat r)
{
    if (!Circle::setRadius(r)) return false;
    return behavior.setMaxSpeed(maxSpeed());
}   // setRadius(const GLfloat)
Ejemplo n.º 18
0
void CAScrollView::deaccelerateScrolling(float delay)
{
    if (m_tInertia.getLength() > maxSpeedCache(delay))
    {
        m_tInertia = ccpMult(m_tInertia, maxSpeedCache(delay) / m_tInertia.getLength());
    }
    
    CCPoint speed;
    if (m_tInertia.getLength() > maxSpeed(delay))
    {
        speed = ccpMult(m_tInertia, maxSpeed(delay) / m_tInertia.getLength());
    }
    else
    {
        speed = m_tInertia;
    }
    
    m_tInertia = ccpMult(m_tInertia, 1 - decelerationRatio(delay));
    
    CCPoint point = m_pContainer->getCenterOrigin();

    if (m_bBounces)
    {
        CCSize size = this->getContentSize();
        CCSize cSize = m_pContainer->getFrame().size;
        cSize.width = MAX(cSize.width, size.width);
        cSize.height = MAX(cSize.height, size.height);
        
        CCPoint resilience = CCPointZero;
        
        if (point.x - cSize.width / 2 > 0)
        {
            resilience.x = (point.x - cSize.width / 2) / size.width;
        }
        
        if (point.y - cSize.height / 2 > 0)
        {
            resilience.y = (point.y - cSize.height / 2) / size.height;
        }
        
        if ((point.x + cSize.width / 2 - size.width) < 0)
        {
            resilience.x = (point.x + cSize.width / 2 - size.width) / size.width;
        }
        
        if ((point.y + cSize.height / 2 - size.height) < 0)
        {
            resilience.y = (point.y + cSize.height / 2 - size.height) / size.height;
        }
        
        resilience = ccpMult(resilience, maxBouncesSpeed(delay));

        if (speed.getLength() < resilience.getLength())
        {
            speed = ccpSub(speed, resilience);
            m_tInertia = CCPointZero;
        }
    }
    
    point = ccpAdd(point, speed);
    
    if (this->isScrollWindowNotMaxOutSide())
    {
        m_tInertia = CCPointZero;
    }
    
    if (m_bBounces == false)
    {
        point = this->getScrollWindowNotOutPoint(point);
    }
    else
    {
        if (m_bBounceHorizontal == false)
        {
            point.x = this->getScrollWindowNotOutHorizontal(point.x);
        }
        
        if (m_bBounceVertical == false)
        {
            point.y = this->getScrollWindowNotOutVertical(point.y);
        }
    }
    
    if (m_pScrollViewDelegate && point.equals(m_pContainer->getCenter().origin) == false)
    {
        m_pScrollViewDelegate->scrollViewDidScroll(this);
    }
    
    
    m_bDecelerating = true;
    
    if (speed.getLength() <= 0.5f)
    {
        point = this->getScrollWindowNotOutPoint(point);
        m_bDecelerating = false;
        CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(CAScrollView::deaccelerateScrolling), this);
    }
    
    m_pContainer->setCenterOrigin(point);
    
}
//
// GLfloat threshold() const
// Last modified: 03Sep2006
//
// Returns the minimum movement threshold of this robot.
//
// Returns:     the minimum movement threshold of this robot
// Parameters:  <none>
//
GLfloat Robot::threshold() const
{
    return FACTOR_THRESHOLD * maxSpeed();
}   // threshold() const
Ejemplo n.º 20
0
float CAScrollView::maxSpeedCache(float delay)
{
    return (maxSpeed(delay) * 1.5f);
}
//
// Behavior moveArcBehavior(t, r, s)
// Last modified: 03Sep2006
//
// Moves the robot using the parameterized translational
// and rotational velocities, returning the appropriate robot behavior.
//
// Returns:     the appropriate robot behavior
// Parameters:
//      t       in      the translational velocity of the behavior
//      r       in      the rotational velocity of the behavior
//      s       in      the status of the behavior (default ACTIVE)
//
Behavior Robot::moveArcBehavior(const GLfloat t,
                                const GLfloat r,
                                const Status  s)
{
    return Behavior(s, t, r, maxSpeed());
}   // moveArcBehavior(const GLfloat, const GLfloat, const Status)
Ejemplo n.º 22
0
void CAScrollView::deaccelerateScrolling(float dt)
{
    dt = MIN(dt, 1/30.0f);
    dt = MAX(dt, 1/100.0f);

    if (m_tInertia.getLength() > maxSpeedCache(dt))
    {
        m_tInertia = ccpMult(m_tInertia, maxSpeedCache(dt) / m_tInertia.getLength());
    }
    
    CCPoint speed = CCPointZero;
    if (m_tInertia.getLength() > maxSpeed(dt))
    {
        speed = ccpMult(m_tInertia, maxSpeed(dt) / m_tInertia.getLength());
    }
    else
    {
        speed = m_tInertia;
    }
    
    if (!m_tInertia.equals(CCPointZero))
    {
        m_tInertia = ccpMult(m_tInertia, 1 - decelerationRatio(dt));
    }

    CCPoint point = m_pContainer->getFrameOrigin();

    if (m_bBounces)
    {
        CCSize size = this->getBounds().size;
        CCSize cSize = m_pContainer->getFrame().size;
        cSize.width = MAX(cSize.width, size.width);
        cSize.height = MAX(cSize.height, size.height);
        
        float y_max = this->isHeaderRefreshing() ? _px(128) : 0.0f;
        float y_min = this->isFooterRefreshing() ? size.height - cSize.height - _px(128) : size.height - cSize.height;
        
        CCPoint resilience = CCPointZero;
        
        if (point.x > 0)
        {
            resilience.x = (point.x) / size.width;
        }
        
        if (point.y - y_max > 0)
        {
            resilience.y = (point.y - y_max) / size.height;
        }
        
        if ((point.x + cSize.width - size.width) < 0)
        {
            resilience.x = (point.x + cSize.width - size.width) / size.width;
        }
        
        if ((point.y - y_min) < 0)
        {
            resilience.y = (point.y - y_min) / size.height;
        }
        
        resilience = ccpMult(resilience, maxBouncesSpeed(dt));
        
        if (speed.getLength() < resilience.getLength())
        {
            speed = ccpMult(resilience, -1.0f);
            m_tInertia = CCPointZero;
        }
    }

    if (speed.getLength() <= minSpeed(dt) / 2)
    {
        point = this->getScrollWindowNotOutPoint(point);
        this->setContainerFrame(point);
        this->hideIndicator();
        //this->detectionFromPullToRefreshView();
        this->stopDeaccelerateScroll();
    }
    else
    {
        point = ccpAdd(point, speed);
        
        if (this->isScrollWindowNotMaxOutSide(m_pContainer->getFrameOrigin()))
        {
            m_tInertia = CCPointZero;
        }
        
        if (m_bBounces == false)
        {
            point = this->getScrollWindowNotOutPoint(point);
        }
        else
        {
            if (m_bBounceHorizontal == false)
            {
                point.x = this->getScrollWindowNotOutHorizontal(point.x);
            }
            
            if (m_bBounceVertical == false)
            {
                point.y = this->getScrollWindowNotOutVertical(point.y);
            }
        }
        
        //this->changedFromPullToRefreshView();
        this->showIndicator();
        this->setContainerFrame(point);
    }
    
    if (m_pScrollViewDelegate)
    {
        m_pScrollViewDelegate->scrollViewDidMoved(this);
    }
}