Ejemplo n.º 1
0
void Container::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    QGraphicsItem::mousePressEvent(event);
    if(this->isSelected())
    {
        QRectF r = this->rect();
        QRectF corner1(r.width()/2 -8,0,16,5);
        QRectF corner2(0,r.bottom()/2-8,5,16);
        QRectF corner3(r.right()-5,r.bottom()/2-8,5,16);
        QRectF corner4(r.width()/2 -8,r.bottom()-5,16,5);
        if(corner1.contains(event->pos()))
        {
            _onResize = true;
            _resizeType = 0;
        }
        else if(corner2.contains(event->pos()))
        {
            _onResize = true;
            _resizeType = 1;
        }
        else if(corner3.contains(event->pos()))
        {
            _onResize = true;
            _resizeType = 2;
        }
        else if(corner4.contains(event->pos()))
        {
            _onResize = true;
            _resizeType = 3;
        }
    }
}
Ejemplo n.º 2
0
void CBoundingBoxAligned::Transform(const CMatrix3D& transform, CBoundingBoxOriented& result) const
{
	// The idea is this: compute the corners of this bounding box, transform them according to the specified matrix,
	// then derive the box center, orientation vectors, and half-sizes.
	// TODO: this implementation can be further optimized; see Philip's comments on http://trac.wildfiregames.com/ticket/914
	const CVector3D& pMin = m_Data[0];
	const CVector3D& pMax = m_Data[1];

	// Find the corners of these bounds. We only need some of the corners to derive the information we need, so let's 
	// not actually compute all of them. The corners are numbered starting from the minimum position (m_Data[0]), going
	// counter-clockwise in the bottom plane, and then in the same order for the top plane (starting from the corner
	// that's directly above the minimum position). Hence, corner0 is pMin and corner6 is pMax, so we don't need to
	// custom-create those.
	
	CVector3D corner0; // corner0 is pMin, no need to copy it
	CVector3D corner1(pMax.X, pMin.Y, pMin.Z);
	CVector3D corner3(pMin.X, pMin.Y, pMax.Z);
	CVector3D corner4(pMin.X, pMax.Y, pMin.Z);
	CVector3D corner6; // corner6 is pMax, no need to copy it

	// transform corners to world space
	corner0 = transform.Transform(pMin); // = corner0
	corner1 = transform.Transform(corner1);
	corner3 = transform.Transform(corner3);
	corner4 = transform.Transform(corner4);
	corner6 = transform.Transform(pMax); // = corner6

	// Compute orientation vectors, half-size vector, and box center. We can get the orientation vectors by just taking
	// the directional vectors from a specific corner point (corner0) to the other corners, once in each direction. The
	// half-sizes are similarly computed by taking the distances of those sides and dividing them by 2. Finally, the 
	// center is simply the middle between the transformed pMin and pMax corners.

	const CVector3D sideU(corner1 - corner0);
	const CVector3D sideV(corner4 - corner0);
	const CVector3D sideW(corner3 - corner0);

	result.m_Basis[0] = sideU.Normalized();
	result.m_Basis[1] = sideV.Normalized();
	result.m_Basis[2] = sideW.Normalized();

	result.m_HalfSizes = CVector3D(
		sideU.Length()/2.f,
		sideV.Length()/2.f,
		sideW.Length()/2.f
	);

	result.m_Center = (corner0 + corner6) * 0.5f;
}
Ejemplo n.º 3
0
void CBC_DefaultPlacement::place() {
  int32_t pos = 0;
  int32_t row = 4;
  int32_t col = 0;
  do {
    if ((row == m_numrows) && (col == 0)) {
      corner1(pos++);
    }
    if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) {
      corner2(pos++);
    }
    if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) {
      corner3(pos++);
    }
    if ((row == m_numrows + 4) && (col == 2) && ((m_numcols % 8) == 0)) {
      corner4(pos++);
    }
    do {
      if ((row < m_numrows) && (col >= 0) && !hasBit(col, row)) {
        utah(row, col, pos++);
      }
      row -= 2;
      col += 2;
    } while (row >= 0 && (col < m_numcols));
    row++;
    col += 3;
    do {
      if ((row >= 0) && (col < m_numcols) && !hasBit(col, row)) {
        utah(row, col, pos++);
      }
      row += 2;
      col -= 2;
    } while ((row < m_numrows) && (col >= 0));
    row += 3;
    col++;
  } while ((row < m_numrows) || (col < m_numcols));
  if (!hasBit(m_numcols - 1, m_numrows - 1)) {
    setBit(m_numcols - 1, m_numrows - 1, true);
    setBit(m_numcols - 2, m_numrows - 2, true);
  }
}