Esempio n. 1
0
void DesignWidget::drawFloor(LBFloor *drawnFloor)
{
  if(drawnFloor == NULL)
    return;

    if( !(drawnFloor -> isItDrawn) )
        return;

    LField *helpField;
    if(drawnFloor -> hasChild())
        helpField = (LField*)drawnFloor -> child;
    else
        return;



    //break this while, when last field of actual floor is drawn
    while(1)
    {
      //Okay, little mess. We have new state: connectingFields
      //this complicates following code (before drawing floors other than actual one)
      //if another state will appear, rebuild of following "if" will be needed


      //for now: check if field is pointed only if ...

      //TODO: VERY BAD WAY ... CHANGE IT!
      //following 'if' is for checking what state we actualy have
      //maybe there's a better way than making OR with desired states
      
      if(*(GC -> appState) == none || *(GC -> appState) == editingField ||
	 *(GC->appState) == definingStairs)
	if(drawnFloor == GC -> actualFloor)
	  {
            //check if field is pointed with mouse
            if(helpField->isPointIn(LVector(mouseV.x, 0.0f, mouseV.z)))
            {
                isFieldPointed = true;
                GC -> cameraKid -> position = helpField->centerPoint;
                GC -> cameraKid -> position.y = GC -> actualFloor -> height;

                //if new field is not being defined right now
                if(!cornerIndex)
                {
                    //pointedFieldID = helpField->ID;
                    pointedField = helpField;
		    setDrawStyle(stylePointedField);
                }
	    }
            else
	      {
		if(*(GC -> appState) == editingField)
		  setDrawStyle(inactive);
		else
		setDrawStyle(drawStyleField);
	      }

            if(helpField == GC->chosenField)
	      setDrawStyle(styleChosenField);
	    
            QPolygon drawField;

	    LField *drawnField = new LField(*helpField);

	    for(int a = 0; a < 4; a++)
	      {
		//for scaling with mouse wheel
		//		drawnField->corners[a].mulMatrix(globalMatrix);
	      }


	    drawField << QPoint(drawnField->corners[0].x, drawnField->corners[0].z)
		      << QPoint(drawnField->corners[1].x,drawnField->corners[1].z)
		      << QPoint(drawnField->corners[2].x,drawnField->corners[2].z)
		      << QPoint(drawnField->corners[3].x,drawnField->corners[3].z);

	    painter->drawPolygon(drawField);

	  }//(if drawnFloor == GC -> actualFloor)

      //draw parts of "connectingFields" state
      if(*(GC -> appState) == connectingFields)
	{
	  
	}


        /////////////////////////////////////////////
        //PART FOR EVERY FLOOR (not only actual) :
        /////////////////////////////////////////////

        //draw Normals
        setDrawStyle(normal);
        for(int cntN = 0; cntN < 4; cntN++)
        {
            int x1 = helpField->corners[cntN].x + helpField->vectors[cntN].x/2;
            int z1 = helpField->corners[cntN].z + helpField->vectors[cntN].z/2;
            int x2 = x1 + helpField->cornersN[cntN].x*10.0f;
            int z2 = z1 + helpField->cornersN[cntN].z*10.0f;

	    painter -> drawLine(x1, z1, x2, z2);
        }


        /////////////////////////////////////////
        //draw walls with defined passages
	if(drawnFloor == GC -> actualFloor)
	  setDrawStyle(drawStyleWall);
	else
	  setDrawStyle(wallInactive);

        for(int cnt = 0; cnt < 4; cnt++)
        {
            int a, b;
            a = cnt;
            if(cnt == 3)
                b = 0;
            else
                b = a + 1;

	    LVector wallVector = helpField -> corners[b] - helpField -> corners[a];
	    float wallLength = wallVector.Length();

	    //points for drawing lines defining wall parts
	    LVector pointA, pointB;

	    pointA = helpField -> corners[a];

	    if(helpField -> passageTree[a] -> hasChild())
	      {
		lbpassage *helpPassage = (lbpassage*)(helpField -> passageTree[a] -> child);
		while(1)
		  {
		    //multiply wall's vector by ratio of passage's point distance and Wall's length
		    pointB = helpField -> corners[a] + wallVector * (helpPassage -> d1 / wallLength);
		    painter -> drawLine(pointA.x, pointA.z, pointB.x, pointB.z);
		    pointA = helpField -> corners[a] + wallVector * (helpPassage -> d2 / wallLength);

		    if( ! helpPassage -> isLast())
		      {
			helpPassage = (lbpassage*)(helpPassage -> next);
		      }
		    //last passage
		    else
		      {
			break;
		      }
		  }
	      }

	    //draw last wall part (draw whole wall if we don't have passages yet)
	    pointB = helpField -> corners[b];
	    painter -> drawLine(pointA.x, pointA.z, pointB.x, pointB.z);

	}

        /////////////////////////////
        if(helpField -> isLast())
            break;
        else
            helpField = (LField*)helpField -> next;
        /////////////////////////////
    }

}
Esempio n. 2
0
void
DesignWidget::drawBreakingHole()
{
  //TODO: check what things can be calculated only once (once after choosing wall part)
  /*
    As in drawWallParts:
     "drawWallParts() is invoked for many appStates, but works for them almost is the
     same way. So first prepare variables needed to make prope things depending on
     appState. Inheritance from one class (lbhelpersbase) is helpful - lbStairsHelper
     and lbwallhelper have the same variables."
   */

  
  /*  if(HB == SH)
    {
      field1 = GC->stairsBottom;
      field2 = GC->stairsTop;
    }
  else
    if(HB == &WH)
      {
	field1 = chosenField;
	field2 = chosenField2;
	}*/
  
  if(GC -> isPassWithDoors)
    {
      setDrawStyle(drawStyleHighlightPartsD);
    }
  else
    {
      setDrawStyle(drawStyleHighlightParts);
    }

  painter -> drawLine(HB->passageA.x, HB->passageA.z,
	    HB->passageB.x, HB->passageB.z);

  LVector temp = HB->passageB - HB->passageA;
  LVector multiplied = LVector(0.0f, 1.0f, 0.0f);
  LVector normal1 = temp^multiplied;
  normal1.normalize();

  //reportWidget -> setText (QString::number(normal1.x)+QString::number(normal1.z));
  //  reportWidget -> setText(QString::number(MH.pointLineDistance
  //					  (1,1,2,2,2,1)));

  float pointDistance = MH.pointLineDistance(HB->passageA.x, HB->passageA.z, HB->passageA.x + normal1.x, HB->passageA.z + normal1.z, mouseV.x, mouseV.z);

  //  reportWidget -> setText(QString::number(MH.pointLineDistance(WH.passageA.x, WH.passageA.z, WH.passageA.x + normal1.x, WH.passageA.z + normal1.z, mouseV.x, mouseV.z)));

  float passLength = temp.Length();
  
  LVector mouseVec;
  mouseVec.x = mouseV.x - HB->passageA.x;
  mouseVec.z = mouseV.z - HB->passageA.z;

  //setting distPointer for the first time
  if(HB->distPointer == NULL)
    {
      HB->distPointer = &(HB->dist1);
      HB->pointPointer = &(HB->point1);
    }
  
  //check 2 conditions: mouse is pointing farther than passageA or passageB
  //(problem was, that equations is showing distance from both sides of wall part)

  //is mouse pointing outside passageA?
  if((-temp) % mouseVec >= 0)
    {
      *(HB->pointPointer) = HB->passageA;
      //      printSuccess(QString::number(0));
      *(HB->distPointer) = 0;
      //      printInfo("vec!");
    }
  else
    //is mouse poining outside passageB?
    if(pointDistance > passLength)
      {
	*(HB->pointPointer) = HB->passageB;
	//	printSuccess(QString::number(temp.Length()));
	*(HB->distPointer) = temp.Length();
	//	printError("distance!");
      }
  //mouse is geometrically betweeen passageA and passageB
    else
      {
	HB->pointPointer->x = HB->passageA.x + temp.x*pointDistance/passLength;
	HB->pointPointer->z = HB->passageA.z + temp.z*pointDistance/passLength;
	//	printSuccess(QString::number(pointDistance));
	*(HB->distPointer) = pointDistance;
	//	printSuccess("middle!");
      }
  
    setDrawStyle(drawStyleBigPoint);
    HB->drawPassagePoints(painter);

    /////////// DRAW DISTANCES ///////////////
    drawDistPoints(HB->passageA, HB->point1,0.0f, 0.0f, 15.0f);

    if(HB -> distPointer == &(HB -> dist2))
      {
	drawDistPoints(HB->passageB, HB->point2, 0.0f, 0.0f, -15.0f);
	drawDistPoints(HB->point1,HB->point2,0.0f, -15.0f, 0.0f);
      }
    /////////// DRAW DISTANCES ///////////////
}