Пример #1
0
 RobotPosition PledgeAlgorithm::getNextPosition(const RobotPosition p_pos)
 {
     int x = (int) meterToCm(p_pos.point.x);
     int y = (int) meterToCm(p_pos.point.y);
     float theta = p_pos.theta;
     bool obstacle = false;
     bool leftSideObstacle = false;
     RobotPosition newPosition;
     
     
     if(turn == 0)
     {
         if(!obstacle)
         {
             newPosition = calculateNewPosition(x, y, theta);
             return newPosition;
         }
         else
         {
             obstacleFound = true;
             while(obstacle) // evtl sackgasse
             {
                 theta -= M_PI/2;
                 turn--;
                 
                 obstacle = checkObstacle(x, y, theta);
             }
             newPosition = calculateNewPosition(x, y, theta);
             return newPosition;
         }
     }
     
     if(turn != 0)
     {
         leftSideObstacle = checkLeftSideObstacle(x, y, theta);
         
         if(leftSideObstacle)
         {
             newPosition = calculateNewPosition(x, y, theta);
             return newPosition;
         }
         else
         {
             theta += M_PI/2; //drehung nach links?
             turn++;
             newPosition = calculateNewPosition(x, y, theta);
             return newPosition;
         }
     }
 }
Пример #2
0
 RobotPosition BugZeroAlgorithm::getNextPosition(const RobotPosition p_pos)
 {
     
     float x = meterToCm(p_pos.point.x);
     float y = meterToCm(p_pos.point.y);
     float theta = p_pos.theta;
     bool frontObstacle = false;
     
     // mutex lock
     
     RobotPosition newPosition;
     
     frontObstacle = checkFrontObstacle();
     
     if(!frontObstacle)
     {
         newPosition = calculateNewPosition(x, y, theta);
     }
     else
     {
         newPosition.point.x = p_pos.point.x;
         newPosition.point.y = p_pos.point.y;
         newPosition.theta = theta + M_PI/2;
     }
     
     // mutex unlock
     return newPosition;
 }
Пример #3
0
void MoveNodeInteraction::snapMouseReleaseEvent(QMouseEvent * event, Feature* Closer)
{
    if (event->button() != Qt::LeftButton)
        return;

    if (Moving.size() && !panning() && HasMoved)
    {
        Coord Diff(calculateNewPosition(event,Closer, theList)-StartDragPosition);
        if (Moving.size() > 1) {
            theList->setDescription(MainWindow::tr("Move Nodes"));
            theList->setFeature(Moving[0]);
        } else {
            if (!Virtual) {
                theList->setDescription(MainWindow::tr("Move Node %1").arg(Moving[0]->id().numId));
                theList->setFeature(Moving[0]);
            }
        }
        QSet<Way*> WaysToUpdate;
        for (int i=0; i<Moving.size(); ++i)
        {
            Moving[i]->setPosition(OriginalPosition[i]);
            if (Moving[i]->layer()->isTrack())
                theList->add(new MoveNodeCommand(Moving[i],OriginalPosition[i]+Diff, Moving[i]->layer()));
            else
                theList->add(new MoveNodeCommand(Moving[i],OriginalPosition[i]+Diff, document()->getDirtyOrOriginLayer(Moving[i]->layer())));
            for (int j=0; j<Moving[i]->sizeParents(); ++j) {
                if (Way* aRoad = CAST_WAY(Moving[i]->getParent(j)))
                    WaysToUpdate << aRoad;
                else {
                    Feature* f = CAST_FEATURE(Moving[i]->getParent(j));
                    if (f)
                        g_backend.sync(f);
                }
            }
        }
        foreach (Way* w, WaysToUpdate) {
            g_backend.sync(w);
        }
Пример #4
0
void gkCameraNode::update(gkScalar tick)
{
	gkQuaternion rollNode = m_rollNode * gkQuaternion(Ogre::Angle(-GET_SOCKET_VALUE(REL_X)), gkVector3::UNIT_Z);

	gkScalar rollDegrees = rollNode.getRoll().valueDegrees();

	if (rollDegrees >= GET_SOCKET_VALUE(MIN_ROLL) && rollDegrees <= GET_SOCKET_VALUE(MAX_ROLL))
	{
		m_rollNode = rollNode;
	}

	gkQuaternion pitchNode = m_pitchNode * gkQuaternion(Ogre::Angle(-GET_SOCKET_VALUE(REL_Y)), gkVector3::UNIT_X);

	gkScalar pitchDegrees = pitchNode.getPitch().valueDegrees();

	if (pitchDegrees >= GET_SOCKET_VALUE(MIN_PITCH) && pitchDegrees <= GET_SOCKET_VALUE(MAX_PITCH))
	{
		m_pitchNode = pitchNode;
	}

	m_target->setOrientation(m_rollNode * m_pitchNode);

	if (m_center != GET_SOCKET_VALUE(CENTER_POSITION))
	{
		m_oldCenter = m_center;

		m_center = GET_SOCKET_VALUE(CENTER_POSITION);
	}

	gkVector3 currentPosition = m_target->getPosition();

	Ogre::Vector3 dir;

	{
		gkVector3 newZPosition = currentPosition;

		if (GET_SOCKET_VALUE(REL_Z))
		{
			newZPosition.z += newZPosition.z * GET_SOCKET_VALUE(REL_Z) * 0.5;

			m_radiusIdealIsSet = false;
		}

		if (GET_SOCKET_VALUE(KEEP_DISTANCE))
		{
			dir = m_oldCenter - newZPosition;

			m_oldCenter = m_center;
		}
		else
		{
			dir = m_center - newZPosition;
		}
	}

	gkScalar radius = dir.length();

	if (!m_radiusIdealIsSet)
	{
		m_idealRadius = radius;

		m_radiusIdealIsSet = true;
	}

	if (!m_oldRadiusIsSet)
	{
		m_oldRadius = radius;

		m_oldRadiusIsSet = true;
	}

	gkScalar stretch = (radius - m_idealRadius) * GET_SOCKET_VALUE(STIFNESS);
	gkScalar damp = (radius - m_oldRadius) * GET_SOCKET_VALUE(DAMPING);

	radius += -stretch * tick - damp;

	gkScalar minZ = GET_SOCKET_VALUE(MIN_Z);
	gkScalar maxZ = GET_SOCKET_VALUE(MAX_Z);

	if (radius < minZ)
	{
		radius = minZ;
	}
	else if (radius > maxZ)
	{
		radius = maxZ;
	}

	m_oldRadius = radius;

	calculateNewPosition(currentPosition, radius, tick);

	SET_SOCKET_VALUE(CURRENT_ROLL, m_rollNode);
	SET_SOCKET_VALUE(CURRENT_PITCH, m_pitchNode);
}
Пример #5
0
/*!
* \fn void ShootStatus::shoot(double sourcePosX,double sourcePosY,double posx,double posy,int reboundNumber)
* \brief Realise un tir laser entre les coordonnees sourcePosx,sourcePosY et posx,posy, en accord avec le nombre de rebonds restants
* \param double sourcePosx, sourcePosy les coordonnees de depart du tir
* \param double posx, posy les coordonnees d'arrivee du tir
* \param int reboundNumber le nombre de rebonds restants
* \return
*/
void ShootStatus::shoot(double sourcePosX,double sourcePosY,double posx,double posy,int reboundNumber) {

    double angleDroite = getAngle(sourcePosX,sourcePosY,posx,posy);

    std::map<double,Position> casesTraversees;
    std::map<double,Position>::iterator it;

    //Calcul des cases traversees par le tir selon l'angle du tir
    if ((angleDroite >= 0) && (angleDroite <90)) {
        casesTraversees = shootUpRight(posx,posy,sourcePosX,sourcePosY);
    }
    if ((angleDroite >= 270) && (angleDroite <360)) {
        casesTraversees = shootDownRight(posx,posy,sourcePosX,sourcePosY);
    }
    if ((angleDroite >= 90) && (angleDroite <180)) {
        casesTraversees = shootUpLeft(posx,posy,sourcePosX,sourcePosY);
    }
    if ((angleDroite >= 180) && (angleDroite <270)) {
        casesTraversees = shootDownLeft(posx,posy,sourcePosX,sourcePosY);
    }

    std::vector<Position> playersPos = game->getPlayersPosition();
    std::vector<Position> asteroidPos = game->getAsteroidsPosition();

    int reboundAsteroid = -1;

    //Iteration sur les cases traversees pour arreter le tir au bon endroit
    for (it = casesTraversees.begin(); (it != casesTraversees.end()) && (reboundAsteroid==-1); it++ ) {
        //case joueur : tue eventuellement le joueur
        for (int i=0; (i<playersPos.size()) ; i++) {
            if (playersPos[i].equals((*it).second)) {
                std::cout << "case joueur traversee" << std::endl;
                Position rebondPos = calculateAsteroidRebound(sourcePosX,sourcePosY,posx,posy,playersPos[i]);
                lastShootTrace.push_back(rebondPos);
                int currentPlayer = game->getCurrentPlayer();
                Player* player = game->getPlayer(currentPlayer);
                int reboundPlayer = player->getSpaceship()->getReboundNumber();
                //on ne tue pas avant le premier rebond
                if (reboundNumber != reboundPlayer) game->shootPlayer(i);
                return;
            }
        }
        //case asteroide
        for (int i=0; (i<asteroidPos.size()) && (reboundAsteroid==-1); i++) {
            if (asteroidPos[i].equals((*it).second)) {
                std::cout << "case asteroid traversee: "<<(*it).second.x<<"-"<<(*it).second.y << std::endl;
                //game->shootAsteroid(asteroidPos[i].x,asteroidPos[i].y)
                reboundAsteroid = i;
            }
        }

    }
    //rebond sur asteroide
    if (reboundAsteroid!=-1) {
        Position rebondPos = calculateAsteroidRebound(sourcePosX,sourcePosY,posx,posy,asteroidPos[reboundAsteroid]);
        std::cout << "rebond coordonnee "<<rebondPos.x<<"-"<<rebondPos.y<<std::endl;
        lastShootTrace.push_back(rebondPos);
        reboundNumber--;
        Position newPos = calculateNewPosition(angleDroite,rebondPos.x,rebondPos.y);
        if (reboundNumber>=0) shoot(rebondPos.x,rebondPos.y,newPos.x,newPos.y,reboundNumber);
    }

    //sinon rebond sur le bord
    else {
        std::map<double,Position>::reverse_iterator rit;
        rit = casesTraversees.rbegin();
        if (rit==casesTraversees.rend()) return;
        std::cout << "rebond case bord:" <<(rit->second).x<<" - "<<(rit->second).y<<std::endl;
        Position rebondPos = calculateEdgeRebound(sourcePosX,sourcePosY,posx,posy,rit->second);
        std::cout << "rebond bord coordonnee "<<rebondPos.x<<"-"<<rebondPos.y<<std::endl;
        lastShootTrace.push_back(rebondPos);
        reboundNumber--;
        Position newPos = calculateNewPosition(angleDroite,rebondPos.x,rebondPos.y);
        if (reboundNumber>=0) shoot(rebondPos.x,rebondPos.y,newPos.x,newPos.y,reboundNumber);
    }
}
Пример #6
0
/* ******************************************************************************
*  Function Name : instanceCurve()
*
*  Description :
*
*  Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp
*
*  Return Value : int
*
***************************************************************************** */
int VRAY_clusterThis::instanceCurve(GU_Detail * inst_gdp, GU_Detail * mb_gdp, fpreal theta, long int point_num)
{
#ifdef DEBUG
   std::cout << "VRAY_clusterThis::instanceCurve()" << std::endl;
#endif

   GEO_Point * ppt;
   GU_PrimNURBCurve * myCurve, * myMBCurve;
   uint32 num_vtx;
   int myCurvePointNum = 0;
   UT_Vector4 pt_pos;
   GU_Detail * curve_gdp, * curve_mb_gdp;

   curve_gdp = allocateGeometry();

   GA_RWAttributeRef prim_Cd = curve_gdp->addDiffuseAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_Alpha = curve_gdp->addAlphaAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_v = curve_gdp->addVelocityAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_N = curve_gdp->addNormalAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_material = curve_gdp->addStringTuple(GEO_PRIMITIVE_DICT, "shop_materialpath", 1);

   GA_RWAttributeRef pt_Cd = curve_gdp->addDiffuseAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_Alpha = curve_gdp->addAlphaAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_v = curve_gdp->addVelocityAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_N = curve_gdp->addNormalAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_pscale = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "pscale", 1);
   GA_RWAttributeRef pt_width = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "width", 1);
   GA_RWAttributeRef pt_id = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "id", 1);
   GA_RWAttributeRef pt_instId = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "inst_id", 1);
   GA_RWAttributeRef pt_material = curve_gdp->addStringTuple(GA_ATTRIB_POINT, "shop_materialpath", 1);

   GA_RWAttributeRef pt_mb_Cd;
   GA_RWAttributeRef pt_mb_Alpha;
   GA_RWAttributeRef pt_mb_v;
   GA_RWAttributeRef pt_mb_N;
   GA_RWAttributeRef pt_mb_pscale;
   GA_RWAttributeRef pt_mb_width;
   GA_RWAttributeRef pt_mb_id;
   GA_RWAttributeRef pt_mb_instId;
   GA_RWAttributeRef pt_mb_material;

   num_vtx = ((myNumCopies * myRecursion) > 4)?(myNumCopies * myRecursion):4;
   myCurve = (GU_PrimNURBCurve *)GU_PrimNURBCurve::build((GU_Detail *)curve_gdp, num_vtx, 4, 0, 1, 1);

   myCurve->setValue<UT_Vector3>(prim_Cd, (const UT_Vector3)myPointAttributes.Cd);
   myCurve->setValue<fpreal>(prim_Alpha, (const fpreal)myPointAttributes.Alpha);
   myCurve->setString(prim_material, myPointAttributes.material);

//   cout << "VRAY_clusterThis::instanceCurve() - num vertices: " << myCurve->getVertexCount() << endl;;
//   cout << "id: "  << myCurve->getPrimitiveId() << endl;
//   cout << "breakCount: "  << myCurve->breakCount() << endl;

   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
         curve_mb_gdp = allocateGeometry();
         myMBCurve = (GU_PrimNURBCurve *)GU_PrimNURBCurve::build((GU_Detail *)curve_mb_gdp, num_vtx, 4, 0, 1, 1);
         pt_mb_Cd = curve_gdp->addDiffuseAttribute(GEO_POINT_DICT);
         pt_mb_Alpha = curve_gdp->addAlphaAttribute(GEO_POINT_DICT);
         pt_mb_v = curve_gdp->addVelocityAttribute(GEO_POINT_DICT);
         pt_mb_N = curve_gdp->addNormalAttribute(GEO_POINT_DICT);
         pt_mb_pscale = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "pscale", 1);
         pt_mb_width = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "width", 1);
         pt_mb_id = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "id", 1);
         pt_mb_instId = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "inst_id", 1);
         pt_mb_material = curve_gdp->addStringTuple(GA_ATTRIB_POINT, "shop_materialpath", 1);
      }


   for(int copyNum = 0; copyNum < myNumCopies; copyNum++)
      for(int recursionNum = 0; recursionNum < myRecursion; recursionNum++) {

            calculateNewPosition(theta, copyNum, recursionNum);
            ppt = myCurve->getVertexElement(myCurvePointNum).getPt();
            ppt->setPos((float)myPointAttributes.myNewPos[0],
                        (float)myPointAttributes.myNewPos[1],
                        (float)myPointAttributes.myNewPos[2], 1.0);

            // Assign attributes to each point
            ppt->setValue<UT_Vector3>(pt_Cd, (const UT_Vector3)myPointAttributes.Cd);
            ppt->setValue<fpreal>(pt_Alpha, (const fpreal)myPointAttributes.Alpha);
            ppt->setValue<UT_Vector3>(pt_v, (const UT_Vector3)myPointAttributes.v);
            ppt->setValue<UT_Vector3>(pt_N, (const UT_Vector3)myPointAttributes.N);
            ppt->setValue<fpreal>(pt_pscale, (const fpreal)myPointAttributes.pscale);
            ppt->setValue<fpreal>(pt_width, (const fpreal)myPointAttributes.width);
            ppt->setValue<int>(pt_id, (const int)myPointAttributes.id);
            ppt->setValue<int>(pt_instId, (const int)myCurvePointNum);
            ppt->setString(pt_material, myPointAttributes.material);

            if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
                  ppt = myMBCurve->getVertexElement(myCurvePointNum).getPt();
                  ppt->setPos((float)myPointAttributes.myNewPos[0],
                              (float)myPointAttributes.myMBPos[1],
                              (float)myPointAttributes.myMBPos[2], 1.0);

                  // Assign attributes to each point
                  ppt->setValue<UT_Vector3>(pt_mb_Cd, (const UT_Vector3)myPointAttributes.Cd);
                  ppt->setValue<fpreal>(pt_mb_Alpha, (const fpreal)myPointAttributes.Alpha);
                  ppt->setValue<UT_Vector3>(pt_mb_v, (const UT_Vector3)myPointAttributes.v);
                  ppt->setValue<UT_Vector3>(pt_mb_N, (const UT_Vector3)myPointAttributes.N);
                  ppt->setValue<fpreal>(pt_mb_pscale, (const fpreal)myPointAttributes.pscale);
                  ppt->setValue<fpreal>(pt_mb_width, (const fpreal)myPointAttributes.width);
                  ppt->setValue<int>(pt_mb_id, (const int)myPointAttributes.id);
                  ppt->setValue<int>(pt_mb_instId, (const int)myInstanceNum);
                  ppt->setString(pt_mb_material, myPointAttributes.material);
               }
//            std::cout << "VRAY_clusterThis::instanceCurve() myCurvePointNum: " << myCurvePointNum << std::endl;
            myCurvePointNum++;
         }

//   myCurve->close();
//   myMBCurve->close ();

   if(myCVEX_Exec)
      VRAY_clusterThis::runCVEX(curve_gdp, curve_mb_gdp, myCVEXFname, CLUSTER_CVEX_POINT);

   if(myCVEX_Exec_prim)
      VRAY_clusterThis::runCVEX(curve_gdp, curve_mb_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

   inst_gdp->merge(*curve_gdp);
   VRAY_Procedural::freeGeometry(curve_gdp);
   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
         mb_gdp->merge(*curve_mb_gdp);
         VRAY_Procedural::freeGeometry(curve_mb_gdp);
      }

   return 0;
}
Пример #7
0
void MagnetSensor::update() {
	currentAngle = sensor.readAngle();

	calculateNewPosition(currentAngle);
}