// set owner
void CInvaderGame::setOwner(CObject *owner)
{
  CComponent::setOwner(owner);

  CObject *playerObject = nullptr;
  CObject *stageObject = nullptr;

  playerObject = new CObject(CVector2(0.0f, -150.0f));
  stageObject = new CObject(CVector2(0.0f, 0.0f));
  _player = new CPlayer(this);
  _stage = new CStage();

  playerObject->addComponent(_player);
  playerObject->addComponent(new CSprite(CSize2(32.0f, 22.0f),
                                  "Resources/player.png"));
  playerObject->addComponent(new CCollider(5.0f));

  stageObject->addComponent(_stage);

  getOwner()->addChild(playerObject);
  getOwner()->addChild(stageObject);

  _firstGenned = true;
  system("clear");
}
void CRecruitmentLoopFunctions::Init(TConfigurationNode& t_node) {
   try {
      /* Get a pointer to the floor entity */
	  m_pcFloor =  &(GetSpace().GetFloorEntity());
      //m_pcFloor = &m_cSpace.GetFloorEntity();
      /* Create a new RNG */
      m_pcRNG = CRandom::CreateRNG("argos");

      /* Get the number of food items we want to be scattered from XML */
      TConfigurationNode& tForaging = GetNode(t_node, "foraging");
      GetNodeAttribute(tForaging, "output", m_strOutput);
      UInt32 NbFoodItems;
      GetNodeAttribute(tForaging, "items", NbFoodItems);
      GetNodeAttribute(tForaging, "radius", m_fFoodSquareRadius);
      m_fFoodSquareRadius *= m_fFoodSquareRadius;

      /* Distribute uniformly the items in the environment */
      for(UInt32 i = 0; i < NbFoodItems; ++i) {
         m_cFoodPos.push_back(
            CVector2(m_pcRNG->Uniform(m_cForagingArenaSideX),
                     m_pcRNG->Uniform(m_cForagingArenaSideY)));
      }
      for(UInt32 i = 0; i < NbFoodItems; ++i) {
         m_cFoodPos.push_back(
            CVector2(m_pcRNG->Uniform(m_cForagingArena2SideX),
                     m_pcRNG->Uniform(m_cForagingArena2SideY)));
      }
   }
   catch(CARGoSException& ex) {
      THROW_ARGOSEXCEPTION_NESTED("Error parsing loop functions!", ex);
   }

   m_cOutput.open(m_strOutput.c_str(), std::ios_base::trunc | std::ios_base::out);
   m_cOutput << "# clock\tcollected_food\tavarage per 100 steps" << std::endl;
}
Esempio n. 3
0
void CTargetingComputer::render() 
{
   // Display surround
   renderQuad();

   char strFont[256];

   if (m_pTarget) {
      // Calculate position of targeting reticle
      CVector3 pos = m_pTarget->m_ppMasses[0]->m_vecPos;
      // Get viewport
      int viewport[4];
      double modelview[16];
      double projection[16];
      glGetIntegerv(GL_VIEWPORT,viewport);
      glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
      glGetDoublev(GL_PROJECTION_MATRIX,projection);
      // Project to 2d screen coords
      double dX, dY, dZ;
      gluProject(pos.X(),pos.Y(),pos.Z(),
                 modelview, projection,
                 viewport, &dX, &dY, &dZ);
      // If behind, invert and scale everything up lots to force it to the edge
      // This could perhaps work better... not too happy, but it's late
      if (dZ > 1.0f) {
         dX = -(dX - (viewport[2]/2)) * viewport[2] + viewport[2]/2;
         dY = -(dY - (viewport[3]/2)) * viewport[3] + viewport[3]/2;
      }
      // Clip
      if (dX < 0) dX = 0;
      else if (dX > viewport[2]) dX = viewport[2];
      if (dY < 0) dY = 0;
      else if (dY > viewport[3]) dY = viewport[3];         
      // Rescale to 0..1
      dX /= viewport[2];
      dY /= viewport[3];
		double dW = 32.0f / viewport[2];
		double dH = 32.0f / viewport[3];
      // Render reticle
      m_poTargetingReticle->setPosition(dX-dW, (1-dY)-dH, dW*2, dH*2);
		m_poTargetingReticle->setTexturePercentage(100.0f);
		m_poTargetingReticle->renderQuad();
		// Radar imagexs
		m_poHoloTarget->renderQuad();
         // Calculate range
		NSDMath::CVector3 vecTarget = m_pTarget->m_ppMasses[0]->m_vecPos - m_pPlayerShip->m_ppMasses[0]->m_vecPos;
      int iRange = static_cast<int>(vecTarget.length());           
      // Range
      sprintf(strFont,"%5d m", iRange);
      m_poFont->print("Range:", CVector2(0.03f, 0.25f), 0.0075f, CVector3(0,1,0));
      m_poFont->print(strFont, CVector2(0.03f, 0.28f), 0.0075f, CVector3(0,1,0));
      // Velocity
      sprintf(strFont,"%5d m/s", static_cast<int>(m_pTarget->m_fVel));
      g_oTextureManager.render(m_auiOffScreenTexture);
      m_poFont->print("Velocity:", CVector2(0.03f, 0.32f), 0.0075f, CVector3(0,1,0));
      m_poFont->print(strFont, CVector2(0.03f, 0.35f), 0.0075f, CVector3(0,1,0));
    }
}
void CFootBotUN::initOdometry() {
	position = CVector2(0, 0);
	angle = CRadians(0);
	velocity = CVector2(0, 0);
	axisLength = encoderSensor->GetReading().WheelAxisLength * 0.01;

	printf("INIT axis length %.3f", axisLength);

}
Esempio n. 5
0
void DSA_controller::ApproachTheTarget(CVector2 myTarget) {

	const CCI_FootBotProximitySensor::TReadings& tProxReads = proximitySensor->GetReadings();
	CVector2 cAccumulator;
	Real front(0.0);
	Real back(0.0);
	Real m = 1.0;

	for(size_t i = 0; i <= 1; ++i) {
		cAccumulator += CVector2(tProxReads[i].Value, tProxReads[i].Angle);
		front += tProxReads[i].Value;
	}

	for(size_t i = 22; i <= 23; ++i) {
		cAccumulator += CVector2(tProxReads[i].Value, tProxReads[i].Angle);
		front += tProxReads[i].Value;
	}

	for(size_t i = 2; i <= 21; ++i) {
		back += tProxReads[i].Value;
	}

 	cAccumulator /= tProxReads.size();
	CVector2 t = myTarget;

	if(front > 0.0) {
		t += cAccumulator;
		collisionCounter++;
	}

	if(front == 0 && collisionCounter > 0) collisionCounter--;

	if(collisionCounter > loopFunctions.TicksPerSecond * 2.0) {
		m *= -1.0;
	}

    /* angle of the robot's direction relative to the arena's origin */
    CRadians angle1  = GetHeading();
    /* angle from the target to the robot's position */
    CRadians angle2  = (t - GetPosition()).Angle();
    /* heading = angle1 - angle2 = 0.0 when the robot is facing its target */
    CRadians heading = (angle1 - angle2).SignedNormalize();

	if(AngleToleranceInRadians.WithinMinBoundIncludedMaxBoundIncluded(heading)) {
        /* Go straight */
        motorActuator->SetLinearVelocity(m * RobotForwardSpeed, m * RobotForwardSpeed);
        //SetStop(1);
    } else {
	    if(heading > AngleToleranceInRadians.GetMax()) {
	        motorActuator->SetLinearVelocity(RobotTurningSpeed, -RobotForwardSpeed);
	    } else if(heading < AngleToleranceInRadians.GetMin()) {
	        motorActuator->SetLinearVelocity(-RobotForwardSpeed, RobotTurningSpeed);
	    }
	}

}
Esempio n. 6
0
CLevelSelectionContext::CLevelSelectionContext(CPakFile* pakFile)
: CContextBase(pakFile)
, m_mousePosition(0, 0)
{
	CVector2 screenSize = Palleon::CGraphicDevice::GetInstance().GetScreenSize();

	m_viewport = Palleon::CViewport::Create();

	{
		Palleon::CameraPtr camera = Palleon::CCamera::Create();
		camera->SetupOrthoCamera(screenSize.x, screenSize.y);
		m_viewport->SetCamera(camera);
	}
	Palleon::CGraphicDevice::GetInstance().AddViewport(m_viewport.get());
	
	for(unsigned int i = 0; i < MAX_LEVELS; i++)
	{
		m_levelShotTextures[i] = LoadTexture(g_levelShotTexturePaths[i]);
	}

	{
		Palleon::SceneNodePtr sceneRoot = m_viewport->GetSceneRoot();

		{
			Palleon::LabelPtr label = Palleon::CLabel::Create();
			label->SetFont(Palleon::CResourceManager::GetInstance().GetResource<Palleon::CFontDescriptor>(FONTDESCRIPTOR_NAME_DEFAULT));
			label->SetPosition(CVector3(0, 0, 0));
			label->SetSize(screenSize);
			label->SetHorizontalAlignment(Palleon::CLabel::HORIZONTAL_ALIGNMENT_CENTER);
			label->SetText("Select your destiny");
			label->SetTextScale(CVector2(0.75, 0.75));
			sceneRoot->AppendChild(label);
		}

		float posX = (screenSize.x - (2 * SHOT_SIZE + MARGIN_SIZE)) / 2;
		float posY = 32;

		for(unsigned int i = 0; i < MAX_LEVELS; i++)
		{
			unsigned int x = i % 2;
			unsigned int y = i / 2;
			Palleon::SpriteButtonPtr button = Palleon::CSpriteButton::Create();
			button->SetPosition(CVector3(
				posX + (x * (SHOT_SIZE + MARGIN_SIZE)), 
				posY + (y * (SHOT_SIZE + MARGIN_SIZE)), 0));
			button->SetSize(CVector2(128, 128));
			button->SetReleasedTexture(m_levelShotTextures[i]);
			button->SetPressedTexture(m_levelShotTextures[i]);
			button->Press.connect(boost::bind(&CLevelSelectionContext::OnShotButtonPress, this, i));
			sceneRoot->AppendChild(button);
		}
	}
}
CVector2 CFootBotFlocking::FlockingVector() {
   /* Get the camera readings */
   const CCI_ColoredBlobOmnidirectionalCameraSensor::SReadings& sReadings = m_pcCamera->GetReadings();
   /* Go through the camera readings to calculate the flocking interaction vector */
   if(! sReadings.BlobList.empty()) {
      CVector2 cAccum;
      Real fLJ;
      size_t unBlobsSeen = 0;

      for(size_t i = 0; i < sReadings.BlobList.size(); ++i) {

         /*
          * The camera perceives the light as a yellow blob
          * The robots have their red beacon on
          * So, consider only red blobs
          * In addition: consider only the closest neighbors, to avoid
          * attraction to the farthest ones. Taking 180% of the target
          * distance is a good rule of thumb.
          */
         if(sReadings.BlobList[i]->Color == CColor::RED &&
            sReadings.BlobList[i]->Distance < m_sFlockingParams.TargetDistance * 1.80f) {
            /*
             * Take the blob distance and angle
             * With the distance, calculate the Lennard-Jones interaction force
             * Form a 2D vector with the interaction force and the angle
             * Sum such vector to the accumulator
             */
            /* Calculate LJ */
            fLJ = m_sFlockingParams.GeneralizedLennardJones(sReadings.BlobList[i]->Distance);
            /* Sum to accumulator */
            cAccum += CVector2(fLJ,
                               sReadings.BlobList[i]->Angle);
            /* Increment the blobs seen counter */
            ++unBlobsSeen;
         }
      }
      /* Divide the accumulator by the number of blobs seen */
      cAccum /= unBlobsSeen;
      /* Clamp the length of the vector to the max speed */
      if(cAccum.Length() > m_sWheelTurningParams.MaxSpeed) {
         cAccum.Normalize();
         cAccum *= m_sWheelTurningParams.MaxSpeed;
      }
      return cAccum;
   }
   else {
      return CVector2();
   }
}
Esempio n. 8
0
//Subtract vector from self and return
CVector2 CVector2::operator- (const CVector2& other) const
{
	return CVector2	(
						x - other.x,
						y - other.y
					);
}
Esempio n. 9
0
//Add vector to self and return
CVector2 CVector2::operator+(const CVector2& other) const
{
	return CVector2	(
						x + other.x,
						y + other.y
					);
}
Esempio n. 10
0
// Scalar division
CVector2 CVector2::operator/ (float scalar)
{
	return CVector2	(
						x / scalar,
						y / scalar
					);
}
Esempio n. 11
0
CVector2 operator* (float scalar, const CVector2& vector)
{
	return CVector2	(
						scalar * vector.x,
						scalar * vector.y
					);
}
Esempio n. 12
0
//Scalar multiplication
CVector2 CVector2::operator* (float scalar)
{
	return CVector2	(
						scalar * x,
						scalar * y
					);
}
Esempio n. 13
0
// Negate self and return
CVector2 CVector2::operator- () const
{
	return CVector2	(	
						-x,
						-y
					);
}
Esempio n. 14
0
void	CAsteroid::Init(EAsteroidType type)
{
	m_State = AS_NONE;
	m_Type = type;
	m_Pos.Zero();
	m_Vel.Zero();
	m_Rot	= RandFloat(0.0f, 360.0f);
	m_RotVel= RandFloat(-100.0f, 100.0f);
	m_Time	= 0.0f;

	if (type == AT_BIG)	m_Size	= RandFloat(25.0f, 35.0f);
	else				m_Size	= RandFloat(5.0f, 15.0f);

	// Create the asteroid by forming a circle that we randomize a bit
	f32			rot = 0.0f;
	CVector2	prev(0.0f, 0.0f);
	for (int lNr=0; lNr<ASTEROIDNUMLINES; lNr++)
	{
		CVector2 v = CVector2(0.0f, m_Size*RandFloat(0.7f, 1.0f)).Rotate((f32)(lNr+1)*(360.0f/(f32)ASTEROIDNUMLINES));
		m_Lines[lNr][0] = prev;
		m_Lines[lNr][1] = v;
		prev = v;
	}
	m_Lines[0][0] = m_Lines[ASTEROIDNUMLINES-1][1];
}
void CCombinedLoopFunctions::generateFoodPatches(){
	for(UInt32 i = 0; i < nbFoodPatches ; i++){
		foodPatches.push_back(std::vector<CVector2>());
		foodPatchCenters.push_back(GenerateFoodPatchPosition());
		foodPatchSizes.push_back(CVector2(foodPatchSize, foodPatchSize));
	}
}
bool CHomingToFoodBeaconBehavior::TakeControl()
{
    /* Get readings from RAB sensor */
    /* Set heading to beacon with smallest range */

    bool controltaken(false);

    Real closestBeaconRange = 1000000.0f;  CRadians closestBeaconBearing; /*Range of 1000000.0cm will never be exceeded */
    for(size_t i = 0; i <  m_sSensoryData.m_RABSensorData.size(); ++i)
    {
        //BEACON_ESTABLISHED = m_iBeaconData
        //std::cout << "Received - byte  0 " << m_sSensoryData.m_RABSensorData[i].Data[0] << std::endl;

        if(m_sSensoryData.m_RABSensorData[i].Data[0] == m_iBeaconData && m_sSensoryData.m_RABSensorData[i].Range < m_fBeaconSignalRange)
        {
            controltaken = true;

            if(m_sSensoryData.m_RABSensorData[i].Range < closestBeaconRange)
            {
                closestBeaconRange   = m_sSensoryData.m_RABSensorData[i].Range;
                closestBeaconBearing = m_sSensoryData.m_RABSensorData[i].HorizontalBearing;
            }
        }
    }

    if(controltaken)
    {
        m_cHomingVector = CVector2(closestBeaconRange, closestBeaconBearing); // range is in cm, but since we are going to normalise the vector it does not matter
        // std::cout << " HomingToFoodBeacon Behavior  - closestBeaconBearing" << ToDegrees(closestBeaconBearing).UnsignedNormalize().GetValue() << std::endl;
    }

    return controltaken;
}
CVector2 CFootBotForaging::CalculateVectorToLight() {
   /* Get readings from light sensor */
   const CCI_FootBotLightSensor::TReadings& tLightReads = m_pcLight->GetReadings();
   /* Sum them together */
   CVector2 cAccumulator;
   for(size_t i = 0; i < tLightReads.size(); ++i) {
      cAccumulator += CVector2(tLightReads[i].Value, tLightReads[i].Angle);
   }
   /* If the light was perceived, return the vector */
   if(cAccumulator.Length() > 0.0f) {
      return CVector2(1.0f, cAccumulator.Angle());
   }
   /* Otherwise, return zero */
   else {
      return CVector2();
   }
}
void iAnt_controller::SetTargetInBounds(CVector2 t) {
    /* Bound the X value based on the forage range. */
    if(t.GetX() > data->ForageRangeX.GetMax())
        t = CVector2(data->ForageRangeX.GetMax(), t.GetY());
    
    if(t.GetX() < data->ForageRangeX.GetMin())
        t = CVector2(data->ForageRangeX.GetMin(), t.GetY());
    
    /* Bound the Y value based on the forage range. */
    if(t.GetY() > data->ForageRangeY.GetMax())
        t = CVector2(t.GetX(), data->ForageRangeY.GetMax());
    
    if(t.GetY() < data->ForageRangeY.GetMin())
        t = CVector2(t.GetX(), data->ForageRangeY.GetMin());
    
    /* Set the robot's target to the bounded t position. */
    target = t;
}
void CBTFootbotRecruiterRootBehavior::Drop(){
	CVector2 vect = CVector2(0,0);
	m_pcMotionControl->ComputeSpeedFromForce(vect);
	m_pcMotionControl->Step(*c_robot_state);

	if(--timer == 0){
		pickedUp = false;
	}
}
Esempio n. 20
0
void		CAsteroid::Explode(const CVector2& vel)
{
	m_Time = ASTEROIDEXPTIME;
	m_State = AS_EXPLODING;

	for (int lNr=0; lNr<ASTEROIDNUMLINES; lNr++)
	{
		m_LineVel[lNr] = CVector2(RandSFloat()*100.0f, RandSFloat()*100.0f);
		m_LineRot[lNr] = RandSFloat()*300.0f;
	}
}
void CFootBotUN::updateNavigation() {
	printf("UPDATE Navigation with state %d\n", state);

	if (state == ARRIVED_AT_TARGET) {
		agent->desideredAngle = CRadians::ZERO;
		agent->desideredSpeed = 0;
		agent->desideredVelocity = CVector2(0, 0);
	} else {
		updateDesideredVelocity();
	}
	agent->updateVelocity();
	updateVelocity();
}
CVector2 CFootBotFlocking::VectorToLight() {
   /* Get light readings */
   const CCI_FootBotLightSensor::TReadings& tReadings = m_pcLight->GetReadings();
   /* Calculate a normalized vector that points to the closest light */
   CVector2 cAccum;
   for(size_t i = 0; i < tReadings.size(); ++i) {
      cAccum += CVector2(tReadings[i].Value, tReadings[i].Angle);
   }
   if(cAccum.Length() > 0.0f) {
      /* Make the vector long as 1/4 of the max speed */
      cAccum.Normalize();
      cAccum *= 0.25f * m_sWheelTurningParams.MaxSpeed;
   }
   return cAccum;
}
Esempio n. 23
0
SInt32 CLandmarks::AtTarget(CFootBotEntity& c_fb) {
   /*
    * Go through the targets
    * If the square distance between the foot-bot center and the target center
    * is less than the target radius squared, return the id of the current target
    * Otherwise, return -1
    */
   for(size_t i = 0; i < TARGETS; ++i) {
     if(SquareDistance(CVector2(c_fb.GetEmbodiedEntity().GetOriginAnchor().Position.GetX(),
				c_fb.GetEmbodiedEntity().GetOriginAnchor().Position.GetY()),
                        m_vecTargets[i]) < TARGET_RADIUS2) {
         return i;
      }
   }
   return -1;
}
Esempio n. 24
0
// gen bullets
void CPlayer::genBullets()
{
  if(_nextGen < _elapseTime)
  {
    _nextGen += 0.08f;

    CObject *bullet = new CObject(getOwner()->getLocation(), PLAYER_BULLET);
    bullet->addComponent(new CMoveInfo(CVector2(0.0f, 1.0f), 200.0f));
    bullet->addComponent(new CStraightMove());
    CSprite *sprite = new CSprite(CSize2(10.0f, 10.0f), "Resources/bullets.png");
    sprite->setDrawRange(CRect(0, 64, 30, 94));
    bullet->addComponent(sprite);
    bullet->addComponent(new CDeleteBullet());
    bullet->addComponent(new CBulletInfo(1));
    bullet->addComponent(new CCollider(5.0f));
    getOwner()->getParent()->addChild(bullet);
  }
}
CVector2 CFootBotForaging::DiffusionVector(bool& b_collision) {
   /* Get readings from proximity sensor */
   const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings();
   /* Sum them together */
   CVector2 cDiffusionVector;
   for(size_t i = 0; i < tProxReads.size(); ++i) {
      cDiffusionVector += CVector2(tProxReads[i].Value, tProxReads[i].Angle);
   }
   /* If the angle of the vector is small enough and the closest obstacle
      is far enough, ignore the vector and go straight, otherwise return
      it */
   if(m_sDiffusionParams.GoStraightAngleRange.WithinMinBoundIncludedMaxBoundIncluded(cDiffusionVector.Angle()) &&
      cDiffusionVector.Length() < m_sDiffusionParams.Delta ) {
      b_collision = false;
      return CVector2::X;
   }
   else {
      b_collision = true;
      cDiffusionVector.Normalize();
      return -cDiffusionVector;
   }
}
Esempio n. 26
0
//--------------------------------------------------------------------------------------------------------------------
void RDX11RenderHelper::RenderWorldGrid(XMMATRIX& mtWorld, int size, int lineCount)
{
	RenderPlane(mtWorld, CVector2(100,100));
	SetWorldTM(mtWorld);

	float halfWidth = size/2.f;
	float lineWidth = size/50.f;

	CVertexPC v1,v2;

	for(int i = 0 ; i < lineCount ;  i += 2)
	{

		v1.vPos.x = halfWidth - i/2 * lineWidth;
		v2.vPos.x = v1.vPos.x;

		v1.vPos.z = 0;
		v2.vPos.z = 0;

		if( i== 50 )
		{
			v1.vPos.y = 0;
			v2.vPos.y = -halfWidth;
		}
		else
		{
			v1.vPos.y = halfWidth;
			v2.vPos.y = -halfWidth;
		}

		v1.color = COLOR_GRAY;
		v2.color = COLOR_GRAY;

		m_LineVertices.Add(v1);
		m_LineVertices.Add(v2);
	}

	for(int i = lineCount ; i < lineCount *2 ; i += 2)
	{
		v1.vPos.y = halfWidth - ( i - lineCount )/2 * lineWidth;
		v2.vPos.y = v1.vPos.y;

		v1.vPos.z = 0;
		v2.vPos.z = 0;

		if( i== 150 )
		{
			v1.vPos.x = 0;
			v2.vPos.x = -halfWidth;
		}
		else
		{
			v1.vPos.x = halfWidth;
			v2.vPos.x = -halfWidth;
		}

		v1.color = COLOR_GRAY;
		v2.color = COLOR_GRAY;

		m_LineVertices.Add(v1);
		m_LineVertices.Add(v2);
	}
	
	v1.vPos = CVector3(0.0f, 0.0f, 0.0f);
	v1.color = COLOR_RED;
	m_LineVertices.Add(v1);

	v1.vPos = CVector3(halfWidth, 0.0f, 0.0f);
	v1.color = COLOR_RED;
	m_LineVertices.Add(v1);

	v1.vPos = CVector3(0.0f, 0.0f, 0.0f);
	v1.color = COLOR_BLUE;
	m_LineVertices.Add(v1);

	v1.vPos = CVector3(0.0f, 0.0f, halfWidth);
	v1.color = COLOR_BLUE;
	m_LineVertices.Add(v1);

	v1.vPos = CVector3(0.0f, 0, 0.0f);
	v1.color = COLOR_GREEN;
	m_LineVertices.Add(v1);

	v1.vPos = CVector3(0.0f, halfWidth, 0.0f);
	v1.color = COLOR_GREEN;
	m_LineVertices.Add(v1);

	GLOBAL::ShaderMgr()->Begin(SHADER_COLOR_VS, SHADER_COLOR_PS);
	DrawLine();
}
 CVector2 CTransformationMatrix2::GetTranslationVector() const {
    return CVector2(m_pfValues[2], m_pfValues[5]);
 }
Esempio n. 28
0
void CActorViewer::NotifyMouseMove(int x, int y)
{
	m_mousePosition = CVector2(x, y);
}
Esempio n. 29
0
void CWorldEditor::NotifyMouseMove(int x, int y)
{
	m_mousePosition = CVector2(static_cast<float>(x), static_cast<float>(y));
	m_mainCamera->UpdateDrag(m_mousePosition);
}
Esempio n. 30
0
bool CGesturer::HandleInput(CInputEvent* _event)
{
	bool recognizedDrag = false;

#ifndef WALO_PLATFORM_WIN
	if(_event->InputType == CInputEvent::EIT_TOUCH)
	{
		CTouchEvent* tevent = (CTouchEvent*)_event;
        if(tevent->TouchCount > 1)
		{
			m_bDragging = false;
			CVector2 ptFirstFinger = CVector2(tevent->Touches[0].X, tevent->Touches[0].Y);
			CVector2 ptSecondFinger = CVector2(tevent->Touches[1].X, tevent->Touches[1].Y);
			f32 zoom = ptSecondFinger.Distance(ptFirstFinger);
			f32 roto = CMath::Atan2(ptSecondFinger.Y - ptFirstFinger.Y, ptSecondFinger.X - ptFirstFinger.X);

			if(tevent->Touches[0].TouchType == CTouchEvent::ETE_BEGIN || tevent->Touches[1].TouchType == CTouchEvent::ETE_BEGIN)
			{
				_BeginRotoZoom(roto, zoom);
                return true;
			}
			else 
			if(tevent->Touches[0].TouchType == CTouchEvent::ETE_MOVE || tevent->Touches[1].TouchType == CTouchEvent::ETE_MOVE)
			{
				_DoRotoZoom(roto, zoom);
                return true;
			}
			else
			{
                if(m_bZoomRot)
                {
                    m_bZoomRot = false;
                    return false;
                }
			}
		}
		else
		{
			m_bZoomRot = false;
            
			if(tevent->Touches[0].TouchType == CTouchEvent::ETE_BEGIN)
			{
				m_DragStart.X = tevent->Touches[0].X;
				m_DragStart.Y = tevent->Touches[0].Y;
                m_bDragging = false;
			}
			else
            if(tevent->Touches[0].TouchType == CTouchEvent::ETE_MOVE)
			{
                if(!m_bDragging)
                {
                    recognizedDrag = _RecognizeDrag(tevent->Touches[0].X, tevent->Touches[0].Y);

                    if(recognizedDrag)
                        _BeginDrag(tevent->Touches[0].X, tevent->Touches[0].Y);
                }
				else
					_DoDrag(tevent->Touches[0].X, tevent->Touches[0].Y);
			}
			else
            {
				if(!m_bDragging)
				{
					_HandleTap(tevent->Touches[0].X, tevent->Touches[0].Y);
					recognizedDrag = true;
				}

                m_bDragging = false;
            }
            
            return recognizedDrag;
		}
	}
	else
#endif
	if(_event->InputType == CInputEvent::EIT_MOUSE)
	{
		CMouseEvent* mevent = (CMouseEvent*)_event;

		if((mevent->Buttons & CMouseEvent::EMBM_LEFT) && !m_MLBPressed)
		{
			m_DragStart.X = mevent->X;
			m_DragStart.Y = mevent->Y;

			m_bDragging = false;
			m_MLBPressed = true;
		}
		else
        if((mevent->Buttons & CMouseEvent::EMBM_LEFT) && m_MLBPressed)
		{
			if(!m_bDragging)
			{
				recognizedDrag = _RecognizeDrag(mevent->X, mevent->Y);

				if(recognizedDrag)
					_BeginDrag(mevent->X, mevent->Y);
			}
			else
				_DoDrag(mevent->X, mevent->Y);
		}
		else
		{
			if((mevent->Buttons & CMouseEvent::EMBM_LEFT) == 0 && m_MLBPressed)
			{
				if(!m_bDragging)
				{
					_HandleTap(mevent->X, mevent->Y);
					recognizedDrag = true;
				}

				m_MLBPressed = false;
				m_bDragging = false;
			}
		}

		if((mevent->Buttons & CMouseEvent::EMBM_RIGHT) && !m_bZoomRot)
		{
			_BeginRotoZoom(mevent->X, mevent->Y);
            return true;
		}
		else
        if((mevent->Buttons & CMouseEvent::EMBM_RIGHT) && m_bZoomRot)
		{
			_DoRotoZoom(mevent->X, mevent->Y);
            return true;
		}
		else
        if(m_bZoomRot)
		{
			m_bZoomRot = false;
            return false;
		}
        
        return recognizedDrag;
	}
	return false;
}