Ejemplo n.º 1
73
// Return orientation of the polygon by checking orientation of the left bottom corner of the polygon
// using exact arithmetics. The input polygon must not contain duplicate points
// (or at least the left bottom corner point must not have duplicates).
static inline bool is_ccw(const Polygon &poly)
{
    // The polygon shall be at least a triangle.
    assert(poly.points.size() >= 3);
    if (poly.points.size() < 3)
        return true;

    // 1) Find the lowest lexicographical point.
    unsigned int imin = 0;
    for (unsigned int i = 1; i < poly.points.size(); ++ i) {
        const Point &pmin = poly.points[imin];
        const Point &p    = poly.points[i];
        if (p(0) < pmin(0) || (p(0) == pmin(0) && p(1) < pmin(1)))
            imin = i;
    }

    // 2) Detect the orientation of the corner imin.
    size_t iPrev = ((imin == 0) ? poly.points.size() : imin) - 1;
    size_t iNext = ((imin + 1 == poly.points.size()) ? 0 : imin + 1);
    Orientation o = orient(poly.points[iPrev], poly.points[imin], poly.points[iNext]);
    // The lowest bottom point must not be collinear if the polygon does not contain duplicate points
    // or overlapping segments.
    assert(o != ORIENTATION_COLINEAR);
    return o == ORIENTATION_CCW;
}
  bool PointGrid::ptInPolygon(const geometry_msgs::Point32& pt, const vector<geometry_msgs::Point>& poly){
    if(poly.size() < 3)
      return false;

    //a point is in a polygon iff the orientation of the point
    //with respect to sides of the polygon is the same for every
    //side of the polygon
    bool all_left = false;
    bool all_right = false;
    for(unsigned int i = 0; i < poly.size() - 1; ++i){
      //if pt left of a->b
      if(orient(poly[i], poly[i + 1], pt) > 0){
        if(all_right)
          return false;
        all_left = true;
      }
      //if pt right of a->b
      else{
        if(all_left)
          return false;
        all_right = true;
      }
    }
    //also need to check the last point with the first point
    if(orient(poly[poly.size() - 1], poly[0], pt) > 0){
      if(all_right)
        return false;
    }
    else{
      if(all_left)
        return false;
    }

    return true;
  }
Ejemplo n.º 3
0
void tft_t::bmp(bool e)
{
	if (e)
		_setOrient(orient() + BMPLandscape);
	else
		_setOrient(orient());
}
Ejemplo n.º 4
0
LeaderNode::LeaderNode() {
   // Allocate space for data structures within this object.
   allocate();

   // TODO: Make this job to run specified later during runtime. For now this is
   // just a work around for testing.
   job_exec = "./job_layer";

   // Set tag counter to 0;
   next_job_num = 0;

   // Keep the system up until told otherwise.
   shutdown = false;

   // Update the stdin_delay time.
   get_timestamp(&stdin_delay); 

   // Set initial number of swing nodes to zero.
   num_swing_nodes = 0;

   // Determine where this node is in the system.
   orient();

   // TODO: REMOVE THIS (just for testing)
   create_test_job();

   // Handle all requests sent to this cache node.
   handle_requests();
}
Ejemplo n.º 5
0
LeaderNode::LeaderNode(const std::string& job_name) {
   // Job to run
   job_exec = job_name;

   // Set tag counter to 0;
   next_job_num = 0;

   // Keep the system up until told otherwise.
   shutdown = false;

   // Update the stdin_delay time.
   get_timestamp(&stdin_delay); 

   // Set initial number of swing nodes to zero.
   num_swing_nodes = 0;

   // Determine where this node is in the system.
   orient();

   // Allocate space for data structures within this object.
   allocate();

   // TODO: REMOVE THIS (just for testing)
   create_test_job();

   // Handle all requests sent to this cache node.
   handle_requests();
}
Ejemplo n.º 6
0
Archivo: draw.cpp Proyecto: RebUT/REBUT
/*
 * Functions to draw keypoints and matches.
 */
static inline void _drawKeypoint( Mat& img, const KeyPoint& p, const Scalar& color, int flags )
{
    Point center( cvRound(p.pt.x * draw_multiplier), cvRound(p.pt.y * draw_multiplier) );

    if( flags & DrawMatchesFlags::DRAW_RICH_KEYPOINTS )
    {
        int radius = cvRound(p.size/2 * draw_multiplier); // KeyPoint::size is a diameter

        // draw the circles around keypoints with the keypoints size
        circle( img, center, radius, color, 1, CV_AA, draw_shift_bits );

        // draw orientation of the keypoint, if it is applicable
        if( p.angle != -1 )
        {
            float srcAngleRad = p.angle*(float)CV_PI/180.f;
            Point orient(cvRound(cos(srcAngleRad)*radius), 
						 cvRound(sin(srcAngleRad)*radius));
            line( img, center, center+orient, color, 1, CV_AA, draw_shift_bits );
        }
#if 0
        else
        {
            // draw center with R=1
            int radius = 1 * draw_multiplier;
            circle( img, center, radius, color, 1, CV_AA, draw_shift_bits );
        }
#endif
    }
    else
    {
        // draw center with R=3
        int radius = 3 * draw_multiplier;
        circle( img, center, radius, color, 1, CV_AA, draw_shift_bits );
    }
}
TiXmlElement* TransformComponent::GenerateXml()
{
	TiXmlElement* pBaseElement = CB_NEW TiXmlElement(GetName());

	// initial transform -> position
	TiXmlElement* pPosition = CB_NEW TiXmlElement("Position");
	Vec3 pos(m_Transform.GetPosition());
	pPosition->SetAttribute("x", ToStr(pos.x).c_str());
	pPosition->SetAttribute("y", ToStr(pos.y).c_str());
	pPosition->SetAttribute("z", ToStr(pos.z).c_str());
	pBaseElement->LinkEndChild(pPosition);

	// initial transform -> LookAt
	TiXmlElement* pDirection = CB_NEW TiXmlElement("YawPitchRoll");
	Vec3 orient(m_Transform.GetYawPitchRoll());
	orient.x = RADIANS_TO_DEGREES(orient.x);
	orient.y = RADIANS_TO_DEGREES(orient.y);
	orient.z = RADIANS_TO_DEGREES(orient.z);
	pDirection->SetAttribute("x", ToStr(orient.x).c_str());
	pDirection->SetAttribute("y", ToStr(orient.y).c_str());
	pDirection->SetAttribute("z", ToStr(orient.z).c_str());
	pBaseElement->LinkEndChild(pDirection);

	return pBaseElement;
}
Ejemplo n.º 8
0
Cache::Cache(int *argc_ptr, char ***argv_ptr) {
   MPI_ASSERT(argc_ptr != NULL);
   MPI_ASSERT(argv_ptr != NULL);

   allocate();
   orient(argc_ptr, argv_ptr); 
}
Ejemplo n.º 9
0
void moveCar(orientation direction, int distance){
  orient(distance); 
  switch(direction){
  	case Straight:
  	  driveStraight(distance);
  	break;
  	case Right:
  	  turnRight(distance);
	driveStraight(distance);
  	break;
  	case Left:
  	  turnLeft(distance);
	driveStraight(distance);
  	break;
	case Back:
		turnRight(distance);
		sleep(1);
		turnRight(distance);
		driveStraight(distance);
		break;
  	default:
  	  motorright.duty = 7.25;
  	  motorleft.duty = 7.25;
  	  break; 
  }
  //bcm2835_close();
  return ;
}
Ejemplo n.º 10
0
TiXmlElement* TransformComponent::VGenerateXml(void)
{
    TiXmlElement* pBaseElement = AC_NEW TiXmlElement(VGetName());

    // initial transform -> position
    TiXmlElement* pPosition = AC_NEW TiXmlElement("Position");
    Vec3 pos(m_transform.GetPosition());
    pPosition->SetAttribute("x", ToStr(pos.x).c_str());
    pPosition->SetAttribute("y", ToStr(pos.y).c_str());
    pPosition->SetAttribute("z", ToStr(pos.z).c_str());
    pBaseElement->LinkEndChild(pPosition);

    // initial transform -> LookAt
    TiXmlElement* pDirection = AC_NEW TiXmlElement("YawPitchRoll");
	Vec3 orient(m_transform.GetYawPitchRoll());
	orient.x = RADIANS_TO_DEGREES(orient.x);
	orient.y = RADIANS_TO_DEGREES(orient.y);
	orient.z = RADIANS_TO_DEGREES(orient.z);
    pDirection->SetAttribute("x", ToStr(orient.x).c_str());
    pDirection->SetAttribute("y", ToStr(orient.y).c_str());
    pDirection->SetAttribute("z", ToStr(orient.z).c_str());
    pBaseElement->LinkEndChild(pDirection);

	/***
	// This is not supported yet
    // initial transform -> position
    TiXmlElement* pScale = AC_NEW TiXmlElement("Scale");
    pPosition->SetAttribute("x", ToStr(m_scale.x).c_str());
    pPosition->SetAttribute("y", ToStr(m_scale.y).c_str());
    pPosition->SetAttribute("z", ToStr(m_scale.z).c_str());
    pBaseElement->LinkEndChild(pScale);
	**/

    return pBaseElement;
}
Ejemplo n.º 11
0
void Drive::calculateOrientation(float dtime, Vector3<float> accel,
		Vector3<float> gyro) {

	Vector3<float> orient(mRoll, mPitch, mYaw);
	// -gyro.y because Gyro has opposite direction to Accelerometer in y axis
	orient += Vector3<float>(gyro.x * dtime, -gyro.y * dtime, gyro.z * dtime);

	if (orient.x > 180.0f)  orient.x -= 360.0f;
	if (orient.x < -180.0f) orient.x += 360.0f;
	if (orient.y > 180.0f)  orient.y -= 360.0f;
	if (orient.y < -180.0f) orient.y += 360.0f;
	if (orient.z > 180.0f)  orient.z -= 360.0f;
	if (orient.z < -180.0f) orient.z += 360.0f;

	float accelroll = atan2(accel.x, -accel.z) * 180.0 / PI;
	float accelpitch = atan2(accel.y, -sign(accel.z)
			* sqrt(accel.x * accel.x + accel.z * accel.z)) * 180.0 / PI;

	float accelmag = magnitude(accel);
	float factor = 1.0f - sign(1.0f - accelmag) * (1.0f - accelmag);
	if (factor < 0.0f)
		factor = 0.0f;

	mRoll  = orient.x * (1.0f - factor) + accelroll * factor;
	mPitch = orient.y * (1.0f - factor) + accelpitch * factor;
	mYaw   = orient.z;
}
Ejemplo n.º 12
0
//Towards player, shoot if close, run if low hp
void Enemy::classicAI()
{
	Shape* player = getPlayer_();
	if (player)
	{
		b2Vec2 playerPos = player->getPosition();
		b2Vec2 ePos = getPosition();
		b2Vec2 between = playerPos - ePos;

		//In long distance, look
		if (between.Length() < 40 || between.Length() < 4.f)
		{
			orient(between);
		}

		//In med distance, move towards, shoot at
		if (between.Length() < 25 && (getHP() >= verticesMIN_ * hpScale_))
		{
			if (getArmed())
			{
				move(between);
				orient(between);
				if (getWeaponReady())
				{
					float rotation = atan2f(between.y, between.x);
					float adjust = randFloat(-0.4, 0.4);
					b2Vec2 newDir(cosf(rotation + adjust), sinf(rotation + adjust));
					trigger(between);
				}
				else release();
			}
		}

		else if (getArmed() && between.Length() < verticesMIN_ * hpScale_)
		{
			orient(-between);
			move(-between);
		}

		else if (!getArmed() && between.Length() < size_ * 1.5f)
		{
			orient(-between);
		}

		else move(b2Vec2_zero);
	}
}
Ejemplo n.º 13
0
void Bond::updateOrientation() 
{
   Vec a(m_begin->displacedPosition());
   Vec b(m_end  ->displacedPosition());
   Quaternion orient(s_zAxis, b-a); 
   setPosition(a);
   setOrientation(orient); 
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
    bool  recalculate = FALSE;
    int   len;
    err_t err = NULL;
    char *infile;
    char *conn_name;
    int  lineno=0;
    struct connection *c1 = NULL;

#ifdef HAVE_EFENCE
    EF_PROTECT_FREE=1;
#endif

    progname = argv[0];
    leak_detective = 1;

    if(argc != 3 && argc!=4) {
	fprintf(stderr, "Usage: %s [-r] <whackrecord> <conn-name>\n", progname);
	exit(10);
    }
    /* skip argv0 */
    argc--; argv++;

    if(strcmp(argv[0], "-r")==0) {
        recalculate = 1;    /* do all crypto */
        argc--; argv++;
    }

    tool_init_log();
    load_oswcrypto();
    init_fake_vendorid();
    init_fake_secrets();
    init_local_interface();

    infile = argv[0];
    conn_name = argv[1];

    cur_debugging = DBG_CONTROL|DBG_CONTROLMORE;
    if(readwhackmsg(infile) == 0) exit(11);

    send_packet_setup_pcap("OUTPUT/" TESTNAME ".pcap");

    c1 = con_by_name(conn_name, TRUE);
    assert(c1 != NULL);

    //list_public_keys(FALSE, FALSE);
    assert(orient(c1, 500));
    show_one_connection(c1, whack_log);

    kick_adns_connection_lookup(c1, &c1->spd.that, TRUE);

    report_leaks();

    tool_close_log();
    exit(0);
}
Ejemplo n.º 15
0
//-----------------------------------------------------------------------
void LLListener::set(LLVector3 pos, LLVector3 vel, LLVector3 up, LLVector3 at)
{
	mPosition = pos;
	mVelocity = vel;

	setPosition(pos);
	setVelocity(vel);
	orient(up,at);
}
Ejemplo n.º 16
0
void PoseArrayDisplay::processMessage( const geometry_msgs::PoseArray::ConstPtr& msg )
{
  if( !validateFloats( *msg ))
  {
    setStatus( StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)" );
    return;
  }

  manual_object_->clear();

  Ogre::Vector3 position;
  Ogre::Quaternion orientation;
  if( !context_->getFrameManager()->getTransform( msg->header, position, orientation ))
  {
    ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
  }

  scene_node_->setPosition( position );
  scene_node_->setOrientation( orientation );

  manual_object_->clear();

  Ogre::ColourValue color = color_property_->getOgreColor();
  float length = length_property_->getFloat();
  size_t num_poses = msg->poses.size();
  manual_object_->estimateVertexCount( num_poses * 6 );
  manual_object_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST );
  for( size_t i=0; i < num_poses; ++i )
  {
    Ogre::Vector3 pos( msg->poses[i].position.x,
                       msg->poses[i].position.y,
                       msg->poses[i].position.z );
    Ogre::Quaternion orient( msg->poses[i].orientation.w,
                             msg->poses[i].orientation.x,
                             msg->poses[i].orientation.y,
                             msg->poses[i].orientation.z );
    // orient here is not normalized, so the scale of the quaternion
    // will affect the scale of the arrow.

    Ogre::Vector3 vertices[6];
    vertices[0] = pos; // back of arrow
    vertices[1] = pos + orient * Ogre::Vector3( length, 0, 0 ); // tip of arrow
    vertices[2] = vertices[ 1 ];
    vertices[3] = pos + orient * Ogre::Vector3( 0.75*length, 0.2*length, 0 );
    vertices[4] = vertices[ 1 ];
    vertices[5] = pos + orient * Ogre::Vector3( 0.75*length, -0.2*length, 0 );

    for( int i = 0; i < 6; ++i )
    {
      manual_object_->position( vertices[i] );
      manual_object_->colour( color );
    }
  }
  manual_object_->end();

  context_->queueRender();
}
Ejemplo n.º 17
0
//Execute reaction
void Enemy::execute(const Reaction& reaction)
{
	move(reaction.move);

	if (reaction.fire)
		fireAt(reaction.look, accuracy_[brainStem_.weapon_training]); //*// Weapon training

	else orient(reaction.look);
}
Ejemplo n.º 18
0
Archivo: wob.cpp Proyecto: jlcox5/Frost
void WOB::draw() const{
  glEnable(GL_NORMALIZE);
  glEnable(GL_TEXTURE_2D);
  glPushMatrix();
  orient(); 
  model->drawModel();
  glDisable(GL_TEXTURE_2D);
  glPopMatrix();
}
puzzle act(const puzzle& cube, Action a ) {
    puzzle ret = cube;
    switch (a) {
        case Action::U :
            ret = permutation(ret, 0, 1, 3, 2);
            return permutation(ret, 8, 9, 10, 11);
        case Action::D :
            ret = permutation(ret, 7, 6, 4, 5);
            return permutation(ret, 18, 17, 16, 19);
        case Action::L :
            ret = orient(ret, a);
            ret = flip_edges(ret, {11, 15, 19, 12});
            ret = permutation(ret, 11, 15, 19, 12);
            return permutation(ret, 0, 2, 6, 4);
        case Action::R :
            ret = orient(ret, a);
            ret = flip_edges(ret, {14, 9, 13, 17});
            ret = permutation(ret, 14, 9, 13, 17);
            return permutation(ret, 3, 1, 5, 7);
        case Action::F :
            ret = orient(ret, a);
            ret = flip_edges(ret, {10, 14, 18, 15});
            ret = permutation(ret, 10, 14, 18, 15);
            return permutation(ret, 3, 7, 6, 2);
        case Action::B :
            ret = orient(ret, a);
            ret = flip_edges(ret, {13, 8, 12, 16});
            ret = permutation(ret, 13, 8, 12, 16);
            return permutation(ret, 1, 0, 4, 5);
        case Action::Ur :
            return act(act(act(ret, Action::U), Action::U), Action::U);
        case Action::Dr :
            return act(act(act(ret, Action::D), Action::D), Action::D);
        case Action::Lr :
            return act(act(act(ret, Action::L), Action::L), Action::L);
        case Action::Rr :
            return act(act(act(ret, Action::R), Action::R), Action::R);
        case Action::Fr :
            return act(act(act(ret, Action::F), Action::F), Action::F);
        case Action::Br :
            return act(act(act(ret, Action::B), Action::B), Action::B);
    }
}
Ejemplo n.º 20
0
 static inline Sign point_is_in_half_plane(
     const vec2& p, const vec2& q1, const vec2& q2,
     bool invert
 ) {
     Sign result = orient(q1, q2, p) ;
     if(invert) {
         result = opposite(result) ;
     }
     return result ;
 }
Ejemplo n.º 21
0
int
gams::platforms::BasePlatform::pose(const pose::Pose & target,
    const pose::PoseBounds &bounds)
{
  int move_status = move(pose::Position(target), bounds);
  int orient_status = orient(pose::Orientation(target), bounds);
  if (move_status == 0 || orient_status == 0)
    return 0;
  if (move_status == 2 && orient_status == 2)
    return 2;
  return 1;
}
Ejemplo n.º 22
0
//Flocking together
void Enemy::flockTest()
{
	b2Vec2 sum(0, 0);
	b2Vec2 fire(0, 0);

	int count = 0;
	for (Enemy* v : swarm_)
	{
		if (v != this && v->getVertices() == vertices_)
		{
			b2Vec2 between = v->getPosition() - getPosition();
			float dist = between.Length();
			if (dist <= 5.f) {
				sum += LenardJonesPotential(v, count);
			}
		}
	}

	Shape* player = getPlayer_();
	if (player)
	{
		if ((player->getPosition() - getPosition()).Length() < visRange_[3])
		{
			//swarmTarget_ = player;
			//sum += LenardJonesPotential(player, count);
			//fire = FiringPotential(player);
		}
	}

	//get average
	if (count > 0)
	{
		sum.x /= static_cast<float>(count);
		sum.y /= static_cast<float>(count);
		orient(sum);
		move(sum);

		if (getArmed())
		{
			if (getWeaponReady())
			{
				trigger(fire);
			}

			else release();

			if ((weapon_->getBar() / weapon_->getBarMAX()) <= 0.1f)
			{
				reup();
			}
		}
	}
}
Coordinate Formation::hullCentroidCalc(Coordinate points[], int numPoints){//centroid calculator
  int hullNum = 0;
  if(numPoints==3){
	  centroid.x = (points[0].x + points[1].x + points[2].x)/3;
	  centroid.y = (points[0].y + points[1].y + points[2].y)/3;
  }
  else
  {
	int tempRes[4];
	for (int i = 0; i<4; i++) {
    tempRes[i] = -1;
  }
  int leftPoint = 0;
  for (int i = 1; i<4; i++) {
    if (points[i].x<points[leftPoint].x)
      leftPoint = i;
  }

  int a = leftPoint;
  int b = 0;
  int ct = 1;
  while (b != leftPoint || ct == 1)//changed to the ct method instead of the do-while loop
  {
    b = (a + 1) % 4;
    for (int w = 0; w<4; w++) {
      if (orient(points[a], points[w], points[b]) == 1) {
        b = w;
      }
    }
    tempRes[a] = b;
    a = b;
    ct++;
  }
  memset(centArr,0,4);
  for (int z = 0; z<4; z++) {
    if (tempRes[z] != -1) {
      Serial.println(points[z].x);
      Serial.println(points[z].y);
      centArr[z].x = points[z].x;
      centArr[z].y = points[z].y;
      hullNum++;
    }
  }
    centroid.x = (centArr[0].x + centArr[1].x + centArr[2].x + centArr[3].x) / 4;
    centroid.y = (centArr[0].y + centArr[1].y + centArr[2].y + centArr[3].y) / 4;
  }
  Serial.println(hullNum);
  Serial.println("Centroid:");
  Serial.println(centroid.x);
  Serial.println(centroid.y);
  return centroid; 
}
Ejemplo n.º 24
0
void NavViewPanel::processParticleCloud()
{
  cloud_.lock();
  new_cloud_ = false;

  if ( !cloud_object_ )
  {
    static int count = 0;
    std::stringstream ss;
    ss << "NavViewCloud" << count++;
    cloud_object_ = scene_manager_->createManualObject( ss.str() );
    Ogre::SceneNode* node = root_node_->createChildSceneNode();
    node->attachObject( cloud_object_ );
  }

  cloud_object_->clear();

  Ogre::ColourValue color( 1.0f, 0.0f, 0.0f, 1.0f );
  int num_particles = cloud_.get_particles_size();
  cloud_object_->estimateVertexCount( num_particles * 8 );
  cloud_object_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST );
  for( int i=0; i < num_particles; ++i)
  {
    Ogre::Vector3 pos( cloud_.particles[i].x, cloud_.particles[i].y, 0.0f );
    Ogre::Quaternion orient( Ogre::Quaternion( Ogre::Radian( cloud_.particles[i].th ), Ogre::Vector3::UNIT_Z ) );

    Ogre::Vector3 vertices[8];
    vertices[0] = pos;
    vertices[1] = pos + orient * Ogre::Vector3(ROBOT_RADIUS, 0.0f, 0.0f);
    vertices[2] = vertices[1];
    vertices[3] = pos + orient * Ogre::Vector3(0.75*ROBOT_RADIUS, -0.25*ROBOT_RADIUS, 0.0f);
    vertices[4] = vertices[3];
    vertices[5] = pos + orient * Ogre::Vector3(0.75*ROBOT_RADIUS, 0.25*ROBOT_RADIUS, 0.0f);
    vertices[6] = vertices[5];
    vertices[7] = pos + orient * Ogre::Vector3(ROBOT_RADIUS, 0.0f, 0.0f);

    for ( int i = 0; i < 8; ++i )
    {
      cloud_object_->position( vertices[i] );
      cloud_object_->colour( color );
    }
  }
  cloud_object_->end();


  cloud_object_->getParentSceneNode()->setPosition( Ogre::Vector3( 0.0f, 0.0f, CLOUD_DEPTH ) );

  cloud_.unlock();

  queueRender();
}
Ejemplo n.º 25
0
Archivo: plot.c Proyecto: aahud/harvey
int (*
heavens(double zlatdeg, double zlondeg, double clatdeg, double clondeg))(Loc*, double*, double*)
{
	struct place center;
	struct place zenith;

	center.nlat = mkcoord(clatdeg);
	center.wlon = mkcoord(clondeg);
	zenith.nlat = mkcoord(zlatdeg);
	zenith.wlon = mkcoord(zlondeg);
	projection = stereographic();
	orient(clatdeg, clondeg, rot(center, zenith)*180/PI);
	return projection;
}
Ejemplo n.º 26
0
void Projectile::update(int milliseconds)
{
	lifeTime_ -= milliseconds;

	if (alive_)
	{
		//Turn off penetration
		if (penetration_ < 0)
		{
			body_->GetFixtureList()->SetSensor(false);
		}

		if (lastPen_.z != 0)
		{
			forceCallback_(b2Vec2(lastPen_.x, lastPen_.y), force_.force, force_.radius, force_.lifeTime, faction_);
			lastPen_.z = 0;
		}

		if (tracking_.radius != 0 && tracking_.speed != 0)
		{
			track();
		}

		if (target_.z != 0)
		{
			b2Vec2 dir = b2Vec2(body_->GetPosition().x - target_.x, body_->GetPosition().y - target_.y);
			orient(dir);
		}

		b2Vec2 vel = body_->GetLinearVelocity();
		body_->SetTransform(body_->GetPosition(), atan2f(-vel.x, vel.y));

		//std::cout << vel.Length() << std::endl;

		if ((bounce_ <= 0 && vel.Length() <= 0) || hp_ <= 0 || lifeTime_ <= 0)
		{
			alive_ = false;
		}
	}

	//Do our force once before we deactivate
	else if (alive_ == false && active_ == true)
	{
		forceCallback_(body_->GetPosition(), force_.force, force_.radius, force_.lifeTime, faction_);
		active_ = false;
	}

	else active_ = false;
}
void NavViewPanel::incomingPoseArray(const geometry_msgs::PoseArray::ConstPtr& msg)
{
  if ( !cloud_object_ )
  {
    static int count = 0;
    std::stringstream ss;
    ss << "NavViewCloud" << count++;
    cloud_object_ = scene_manager_->createManualObject( ss.str() );
    Ogre::SceneNode* node = root_node_->createChildSceneNode();
    node->attachObject( cloud_object_ );
  }

  cloud_object_->clear();

  Ogre::ColourValue color( 1.0f, 0.0f, 0.0f, 1.0f );
  int num_particles = msg->poses.size();
  cloud_object_->estimateVertexCount( num_particles * 8 );
  cloud_object_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST );
  for( int i=0; i < num_particles; ++i)
  {
    Ogre::Vector3 pos( msg->poses[i].position.x, msg->poses[i].position.y, msg->poses[i].position.z );
    tf::Quaternion orientation;
    tf::quaternionMsgToTF(msg->poses[i].orientation, orientation);
    double yaw, pitch, roll;
    btMatrix3x3(orientation).getEulerYPR(yaw, pitch, roll);
    Ogre::Quaternion orient( Ogre::Quaternion( Ogre::Radian( yaw ), Ogre::Vector3::UNIT_Z ) );

    Ogre::Vector3 vertices[8];
    vertices[0] = pos;
    vertices[1] = pos + orient * Ogre::Vector3(ROBOT_RADIUS, 0.0f, 0.0f);
    vertices[2] = vertices[1];
    vertices[3] = pos + orient * Ogre::Vector3(0.75*ROBOT_RADIUS, -0.25*ROBOT_RADIUS, 0.0f);
    vertices[4] = vertices[3];
    vertices[5] = pos + orient * Ogre::Vector3(0.75*ROBOT_RADIUS, 0.25*ROBOT_RADIUS, 0.0f);
    vertices[6] = vertices[5];
    vertices[7] = pos + orient * Ogre::Vector3(ROBOT_RADIUS, 0.0f, 0.0f);

    for ( int i = 0; i < 8; ++i )
    {
      cloud_object_->position( vertices[i] );
      cloud_object_->colour( color );
    }
  }
  cloud_object_->end();

  cloud_object_->getParentSceneNode()->setPosition( Ogre::Vector3( 0.0f, 0.0f, CLOUD_DEPTH ) );

  queueRender();
}
Ejemplo n.º 28
0
//Behaviour based AI
void Enemy::behavTest()
{
	Shape* player = getPlayer_();
	if (player)
	{
		b2Vec2 pos = player->getPosition();
		b2Vec2 toward = getPosition() - pos;
		float dist = (player->getSize() + size_) * 1.5f;
		b2Vec2 vel = player->getBody()->GetLinearVelocity();

		b2Vec2 steer = pursue(pos, vel, dist);
		move(steer);
		orient(-toward);
	}
}
Ejemplo n.º 29
0
void camera_t::apply(float dt) {
  // pivot around a particular position i.e. "target"
  if (showreel) {
    static float radius = 16.72f, height = 5.0f, t = 0;
    t += dt / 2;
    this->pos = glm::vec3(radius * cos(float(M_PI * 2.0f) + t), height,
                          radius * sin(float(M_PI * 2.0f) + t));
    this->matrix = glm::lookAt(pos, target, glm::vec3(0.0f, 1.0f, 0.0f));
  } else // move around freely and unrestricted ...
  {
    calc_velocity(dt);
    if (!gui_enabled)
      orient(dt);
  }
}
Ejemplo n.º 30
0
 bool polygon_is_convex(const Polygon2d& P) {
     Sign s = ZERO ;
     for(unsigned int i=0; i<P.size(); i++) {
         unsigned int j = ((i+1) % P.size()) ;
         unsigned int k = ((j+1) % P.size()) ;
         Sign cur_s = orient(P[i],P[j],P[k]) ;
         if(s != ZERO && cur_s != ZERO && cur_s != s) {
             return false ;
         }
         if(cur_s != ZERO) {
             s = cur_s ;
         }
     }
     return true ;
 }