Beispiel #1
0
void GUIPanel::packFreeLayout()
{
  if(!update || !parent)
    return;

  Tuple4i newBounds = getWindowBounds();
  size_t  t         = 0;
  int     temp1     = 0,
          temp2     = 0;

  for(t = 0; t < elements.size(); t++)
  {
    elements[t]->forceUpdate(update);
    const Tuple4i &childBounds = elements[t]->getWindowBounds();

    newBounds.x = (childBounds.x - clipSize) < newBounds.x ?
                   childBounds.x - clipSize : newBounds.x;
    newBounds.y = (childBounds.y - clipSize) < newBounds.y ?
                   childBounds.y - clipSize : newBounds.y;
    newBounds.z = (childBounds.z + clipSize) > newBounds.z ?
                   childBounds.z + clipSize: newBounds.z;
    newBounds.w = (childBounds.w + clipSize) > newBounds.w ?
                   childBounds.w + clipSize : newBounds.w;
  }

  windowBounds = newBounds;
  update       = false;

  correctPosition();
  computeClippedBounds(windowBounds);

  for(t = 0; t < elements.size(); t++)
    elements[t]->computeWindowBounds();
}
void PhysicsComponent::correctPositionAfterCollision(Scene& scene, Axis axis)
{
	if (owner_.getType() != GameObject::Type::TILE)
	{
		int startC = std::max(0, (int) (collider_->getLeft() / Constants::TILE_SIZE));
		int startR = std::max(0, (int) (collider_->getTop() / Constants::TILE_SIZE));
		int endC = std::min(scene.gameObjects.getTiles().cols - 1, (int)((collider_->getRight()) / Constants::TILE_SIZE));
		int endR = std::min(scene.gameObjects.getTiles().rows - 1, (int)((collider_->getBottom()) / Constants::TILE_SIZE));


		for (int c = startC; c <= endC; ++c)
		{
			for(int r = startR; r <= endR; ++r)
			{
				GameObject& tile = scene.gameObjects.getTiles().tiles[r][c];

				if (collider_->checkCollision(tile))
				{
					correctPosition(tile, scene, axis);
					callOnCollision(tile, scene);
				}
			}
		}
	}
}
Beispiel #3
0
void HeroNode::updateCurrent(sf::Time dt)
{
	correctDiagonalVelocity();
	accelerate(trmb::Entity::getVelocity() * getMaxSpeed());
	trmb::Entity::updateCurrent(dt);
	correctPosition();
}
Beispiel #4
0
void GUIPanel::pack()
{
  if(!update)
    return;

  size_t t = 0;

  for(t = 0; t < elements.size(); t++)
    elements[t]->forceUpdate(update);

  if(!t)
  {
    correctPosition();
    return;
  }

  switch(layout)
  {
    case PL_YAXIS_LAYOUT:
    case PL_YAXIS_CEN_LAYOUT:
      packYAxisLayout();
    break;
    case PL_XAXIS_LAYOUT: 
      packXAxisLayout(); 
    break;
    default: packFreeLayout();
  }

  for(t = 0; t < elements.size(); t++)
    elements[t]->forceUpdate(update);
}
Beispiel #5
0
double ProbBool(extmanager MyManager, DdNode *node, int bits, int nBit,int posBVar,variable v, int comp)
/* explores a group of binary variables making up the multivalued variable v */
{
  DdNode *T,*F;
  double p,res;
  double * probs;
  int index;
  probs=v.probabilities;
  if (nBit==0)
  {
    if (bits>=v.nVal)
	{
	return 0.0;
	}
    else
    {
      p=probs[bits];
      res=p*Prob(MyManager,node,comp);
      return res;
    }
  }
  else
  {
    index=Cudd_NodeReadIndex(node);
     if (correctPosition(index,v,posBVar))
    {
      T = Cudd_T(node);
      F = Cudd_E(node);
      bits=bits<<1;
      res=ProbBool(MyManager,T,bits+1,nBit-1,posBVar+1,v,comp);
      comp=(!comp && Cudd_IsComplement(F)) || (comp && !Cudd_IsComplement(F));
res=res+ 
        ProbBool(MyManager,F,bits,nBit-1,posBVar+1,v,comp);
      return res;
    }
    else
    {
      bits=bits<<1;
      res=ProbBool(MyManager,node,bits+1,nBit-1,posBVar+1,v,comp);
      res=res+ 
        ProbBool(MyManager,node,bits,nBit-1,posBVar+1,v,comp);
return res;
    }
  }
}
Beispiel #6
0
//----------------------------------------------------------------------
// function that handles HUD items alignment on screen to get rid
// of screen dimensions dependancy. Gets alignment from LUA and
// sets offsets for eac HUD item
//----------------------------------------------------------------------
sf::Vector2f BaseHud::fixAlignment(int alignment, int xOffset, int yOffset, int width, int height) {
    sf::Vector2f correctPosition(0,0);
    wSize = _window->getSize();

    switch ( alignment ) {                    //X Alignment                    //Y Alignment
        case 1:  correctPosition = sf::Vector2f(Align_X_Left(xOffset)          , Align_Y_Top(yOffset));            break; // LEFT_TOP
        case 2:  correctPosition = sf::Vector2f(Align_X_Left(xOffset)          , Align_Y_Center(height, yOffset)); break; // LEFT_CENTER
        case 3:  correctPosition = sf::Vector2f(Align_X_Left(xOffset)          , Align_Y_Bottom(height, yOffset)); break; // LEFT_BOTTOM
        case 4:  correctPosition = sf::Vector2f(Align_X_Center(width, xOffset) , Align_Y_Top(yOffset));            break; // CENTER_TOP
        case 5:  correctPosition = sf::Vector2f(Align_X_Center(width, xOffset) , Align_Y_Center(height, yOffset)); break; // CENTER_CENTER
        case 6:  correctPosition = sf::Vector2f(Align_X_Center(width, xOffset) , Align_Y_Bottom(height, yOffset)); break; // CENTER_BOTTOM
        case 7:  correctPosition = sf::Vector2f(Align_X_Right(width, xOffset)  , (yOffset));                       break; // RIGHT_TOP
        case 8:  correctPosition = sf::Vector2f(Align_X_Right(width, xOffset)  , Align_Y_Center(height, yOffset)); break; // RIGHT_CENTER
        case 9:  correctPosition = sf::Vector2f(Align_X_Right(width, xOffset)  , Align_Y_Bottom(height, yOffset)); break; // RIGHT_BOTTOM
        default: std::cout << "WARNING: Alignment '" << alignment << "' doesn't exist!" << std::endl;              break; // WARNING
    }
    return correctPosition;
}
Beispiel #7
0
void GUIPanel::packXAxisLayout()
{
  computeWindowBounds();

  std::vector<int> childrenWidths,
              childrenHeights;
  float       offset      = 0;
  size_t      t           = 0;
  int         height      = 0,
              width       = 0,
              panelHeight = windowBounds.w - windowBounds.y;

  for(t = 0; t < elements.size(); t++)
  {
    const Tuple4i &childBounds = elements[t]->getWindowBounds();
    childrenHeights.push_back(childBounds.w - childBounds.y);
    childrenWidths.push_back (childBounds.z - childBounds.x + interval.x);

    width       += childrenWidths[t];
    height       = childBounds.w - childBounds.y;
    panelHeight  = height > panelHeight ? height : panelHeight;
  }

  dimensions.set(float(width), float(panelHeight));
  GUIRectangle::computeWindowBounds();

  windowBounds.z += interval.x;
  windowBounds.w += interval.y*2;

  update = false;
  width  = interval.x;

  correctPosition();
  computeClippedBounds(windowBounds);

  for(t = 0; t < elements.size(); t++)
  {
    offset = clamp(float(panelHeight - childrenHeights[t])/2.0f + interval.y, 0.0f, 1000.0f);
    elements[t]->setAnchorPoint(AT_CORNERLU);
    elements[t]->setPosition(float(width), offset);
    elements[t]->computeWindowBounds();
    width += childrenWidths[t];
  }
}
Beispiel #8
0
void GUIPanel::packYAxisLayout()
{
  computeWindowBounds();

  std::vector<int> childrenHeights,
              childrenWidths;

  size_t      t          = 0;
  int         height     = 0,
              xOffset    = 0,
              panelWidth = getWidth();

  for(t = 0; t < elements.size(); t++)
  {
    const Tuple4i &childBounds = elements[t]->getWindowBounds();
    childrenHeights.push_back(childBounds.w - childBounds.y + interval.y);
    childrenWidths.push_back(childBounds.z - childBounds.x);
    height       += childrenHeights[t];
    panelWidth    = childrenWidths[t] > panelWidth ? childrenWidths[t] : panelWidth;
  }

  dimensions.set(float(panelWidth), float(height));
  GUIRectangle::computeWindowBounds();

  windowBounds.z += interval.x*2;
  windowBounds.w += interval.y;

  update = false;
  height = interval.y;

  correctPosition();
  computeClippedBounds(windowBounds);

  for(t = 0; t < elements.size(); t++)
  {
    xOffset = (layout == PL_YAXIS_CEN_LAYOUT) * (panelWidth - childrenWidths[t])/2;

    elements[t]->setAnchorPoint(AT_CORNERLU);
    elements[t]->setPosition(float(interval.x + xOffset), float(height));
    elements[t]->computeWindowBounds();
    height += childrenHeights[t];
  }
}
float CExporter::calcWeightError(grp::SkinnedMeshExporter& skinnedMesh, grp::SkinVertex& skinVertex, grp::Vector3& position)
{
	grp::Vector3 correctPosition(grp::Vector3::ZERO);
	grp::Vector3 lodPosition;
	for (int i = 0; i < grp::MAX_VERTEX_INFLUENCE; ++i)
	{
		grp::VertexInfluence& influence = skinVertex.influences[i];
		if (influence.weight <= 0)
		{
			break;
		}
		assert(influence.boneIndex < skinnedMesh.m_offsetMatrices.size());
		grp::Vector3 influencePos = skinnedMesh.m_offsetMatrices[influence.boneIndex].transformVector3(position);
		if (i == 0)
		{
			lodPosition = influencePos;
		}
		correctPosition += (influence.weight * influencePos);
	}
	return correctPosition.distance(lodPosition);
}
Beispiel #10
0
void DriverData::addFPQLap(const EventData &ed)
{
    //during practice and quali we only save timed laps
    if ((lastLap.lapTime.toString() != "") && (lapData.empty() ||
            (/*(lastLap.numLap > lapData.last().numLap) &&*/ lastLap.getSectorTime(1).toString() != "" && lastLap.getSectorTime(2).toString() != "" && lastLap.getSectorTime(3).toString() != "")))
    {
        bool correction = false;
        //sometimes servers messes up with lap numbers, we catch this if the numlap is <= than the last one
        if (!lapData.isEmpty() && lastLap.lapNum+1 <= lapData.last().lapNum)
        {
            correction = true;
            bool approx = lapData.last().qualiLapExtraData.approxLap || lapData.last().practiceLapExtraData.approxLap;
            int numlap = lapData.last().lapNum-1;
            lapData.last() = LapData(lastLap);
            lapData.last().qualiLapExtraData.approxLap = approx;
            lapData.last().practiceLapExtraData.approxLap = approx;

            if (lapData.size() > 1)
                lapData.last().lapNum = numlap;


            if (sessionRecords.bestLap.lapNum == numlap)
                sessionRecords.bestLap.lapNum = lapData.last().lapNum;
        }
        else
        {

            //if decryption fails, replace the garbage we obtained with the best lap time
            if (lastLap.lapTime.toString() != "" && !lastLap.lapTime.isValid())
                lastLap.lapTime = sessionRecords.bestLap.lapTime;

            lastLap.qualiLapExtraData.sessionTime = ed.getRemainingTime();
            lastLap.practiceLapExtraData.sessionTime = ed.getRemainingTime();
            lapData.append(lastLap);
            lapData.last().lapNum--;

            if (ed.getEventType() == LTPackets::QUALI_EVENT)
            {
                int qPeriod = ed.getQualiPeriod() > 0 ? ed.getQualiPeriod() : 1;
                lastLap.qualiLapExtraData.qualiPeriod = qPeriod;
                lapData.last().qualiLapExtraData.qualiPeriod = qPeriod;

            }

            updateSectorRecords();
        }

        if (!correction)
        {
            if (ed.getEventType() == LTPackets::PRACTICE_EVENT)
            {
                if (lastLap < sessionRecords.bestLap)
                    sessionRecords.bestLap = lapData.last();

                else if (lastLap.lapTime == sessionRecords.bestLap.lapTime)
                {
                    lapData.last().lapTime = LapData::sumSectors(lapData.last().getSectorTime(1).toString(), lapData.last().getSectorTime(2).toString(), lapData.last().getSectorTime(3).toString());
                    lapData.last().practiceLapExtraData.approxLap = true;
                }
                else
                    lapData.last().practiceLapExtraData.approxLap = false;

            }
            else if (ed.getEventType() == LTPackets::QUALI_EVENT)
            {
                if (lastLap < sessionRecords.bestLap)
                    sessionRecords.bestLap = lapData.last();

                if (lastLap < sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1] ||
                        !sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1].getTime().isValid())
                {
                    sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1] = lapData.last();

                    if (sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1] < sessionRecords.bestLap)
                        sessionRecords.bestLap = sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1];
                }
                //if the current lap time is the same as the best lap, probably the driver hasn't improved so we have to calculate the real lap time from the sectors time
                else if (lastLap.lapTime == sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1].lapTime)
                {
                    lapData.last().lapTime = LapData::sumSectors(lapData.last().getSectorTime(1).toString(), lapData.last().getSectorTime(2).toString(), lapData.last().getSectorTime(3).toString());
                    lapData.last().qualiLapExtraData.approxLap = true;
                }
                else
                    lapData.last().qualiLapExtraData.approxLap = false;

                correctPosition(ed);
            }

        }
        lapData.last().gap = QString::number((lapData.last().lapTime - ed.getSessionRecords().getFastestLap().getTime()).toDouble());

        posHistory.append(lastLap.pos);
        outLap = false;
    }

    //saving in and out laps
    else if (lastLap.lapNum > 1)
    {
        if (lapData.isEmpty() || (!lapData.isEmpty() && lapData.last().lapNum < lastLap.lapNum-1))
        {
            if (outLap == true || inPits == false)
            {
                lapData.append(lastLap);
                lapData.last().lapTime = LapTime("OUT LAP");

                if (inPits == true)
                    lapData.last().lapTime = LapTime("INST. LAP");

                lapData.last().lapNum--;
                outLap = false;
            }
            else
            {
                lapData.append(lastLap);
                lapData.last().lapTime = LapTime("IN LAP");
                lapData.last().lapNum--;
            }
            lapData.last().qualiLapExtraData.sessionTime = ed.getRemainingTime();
            lapData.last().practiceLapExtraData.sessionTime = ed.getRemainingTime();

            if (ed.getEventType() == LTPackets::QUALI_EVENT)
            {
                int qPeriod = ed.getQualiPeriod() > 0 ? ed.getQualiPeriod() : 1;
                lastLap.qualiLapExtraData.qualiPeriod = qPeriod;
                lapData.last().qualiLapExtraData.qualiPeriod = qPeriod;
            }

            updateSectorRecords();
        }
    }
}