Esempio n. 1
0
void GLRenderer::blitTexture(const GPUTexture *tex, bool flipVertically,
		bool centerHoriz, bool centerVert, const Vector2i &offset) {
	tex->bind();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);
	Vector2i scrSize = Vector2i(viewport[2], viewport[3]);
	Vector2i texSize = Vector2i(tex->getSize().x, tex->getSize().y);
	if (scrSize.x == 0 || scrSize.y == 0) {
		tex->unbind();
		return;
	}

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, scrSize.x, scrSize.y, 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0.375f, 0.375f, 0.0f);
	glBegin(GL_QUADS);

	Vector2i upperLeft(0), lowerRight(0);
	if (centerHoriz)
		upperLeft.x = (scrSize.x - texSize.x)/2;
	if (centerVert)
		upperLeft.y = (scrSize.y - texSize.y)/2;
	upperLeft += offset;
	lowerRight = upperLeft + texSize;

	if (flipVertically)
		std::swap(upperLeft.y, lowerRight.y);

	const float zDepth = -1.0f; // just before the far plane
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f((float) upperLeft.x, (float) upperLeft.y, zDepth);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f((float) lowerRight.x, (float) upperLeft.y, zDepth);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f((float) lowerRight.x, (float) lowerRight.y, zDepth);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f((float) upperLeft.x, (float) lowerRight.y, zDepth);
	glEnd();

	tex->unbind();
}
Esempio n. 2
0
CExtent TextStruct::getTextBox(double spaceRatio, double penWidth) const
{
   const double characterSpacing = .1; 
   const double textLeading = 1.25;

   double boxWidth = getMaxLineLength(spaceRatio,penWidth);

   int numLines = getNumLines();

   double boxHeight = m_height + ((numLines - 1) * textLeading * m_height);

   CPoint2d upperLeft(0.,0.);

   switch (getVerticalPosition())
   {
   case verticalPositionBaseline:  upperLeft.y = m_height;      break;
   case verticalPositionCenter:    upperLeft.y = boxHeight/2.;  break;
   case verticalPositionBottom:    upperLeft.y = boxHeight;     break;
   case verticalPositionTop:       upperLeft.y = 0.;            break;
   }

   switch (getHorizontalPosition())
   {
   case horizontalPositionLeft:    upperLeft.x = 0.;           break;
   case horizontalPositionCenter:  upperLeft.x = -boxWidth/2.; break;
   case horizontalPositionRight:   upperLeft.x = -boxWidth;    break;
   }

   CPoint2d lowerRight = upperLeft + CPoint2d(boxWidth,-boxHeight);

   if (m_oblique != 0)
   {
      double offset = m_height * cos(degreesToRadians(m_oblique));

      if (offset < 0.) upperLeft.x  -= offset;
      else             lowerRight.x += offset;
   }

   CExtent textBox;

   textBox.update(upperLeft);
   textBox.update(lowerRight);

   return textBox;
}
Esempio n. 3
0
//Modified from original
bool Engine::collisionBR(Sprite *sprite1, Sprite *sprite2)
{
    bool ret = false;

    /*			Rect *ra = new Rect(
    				sprite1->getX(),
    				sprite1->getY(),
    				sprite1->getX() + sprite1->getWidth() * sprite1->getScale(),
    				sprite1->getY() + sprite1->getHeight() * sprite1->getScale() );
    			Rect *rb = new Rect(
    				sprite2->getX(),
    				sprite2->getY(),
    				sprite2->getX() + sprite2->getWidth() * sprite2->getScale(),
    				sprite2->getY() + sprite2->getHeight() * sprite2->getScale() );

    			//are any of sprite b's corners intersecting sprite a?
    			if (ra->isInside( rb->getLeft(), rb->getTop() ) ||
    				ra->isInside( rb->getRight(), rb->getTop() ) ||
    				ra->isInside( rb->getLeft(), rb->getBottom() ) ||
    				ra->isInside( rb->getRight(), rb->getBottom() ))
                        ret = true;*/


    Rect ra = sprite1->getBounds();
    Rect rb = sprite2->getBounds();

    /*   Vector3 upperLeft( ra.left, rb.top, 0.0 );
       Vector3 lowerLeft( rb.left, rb.bottom, 0.0 );
       Vector3 upperRight( rb.right, rb.top, 0.0 );
       Vector3 lowerRight( rb.right, rb.bottom, 0.0 );

    if (ra.isInside( upperLeft ) || ra.isInside( lowerLeft ) ||
    	ra.isInside( upperRight ) || ra.isInside( lowerRight ))
    	ret = true;*/

    Vector3 upperLeft(ra.left,ra.top,0.0f);

    if(rb.isInside(upperLeft))
        ret = true;

    //delete ra;
    //delete rb;
    return ret;
}
Esempio n. 4
0
bool LineIntersectsRect( const DVec2 &v1, const DVec2 &v2, float x, float y, float width, float height )
{
        FVec2 lowerLeft( x, y+height );
        FVec2 upperRight( x+width, y );
        FVec2 upperLeft( x, y );
        FVec2 lowerRight( x+width, y+height);
        // check if it is inside
        if (v1.x > lowerLeft.x && v1.x < upperRight.x && v1.y < lowerLeft.y && v1.y > upperRight.y &&
            v2.x > lowerLeft.x && v2.x < upperRight.x && v2.y < lowerLeft.y && v2.y > upperRight.y )
        {   
            return true;
        }
        // check each line for intersection
        if (LineIntersectLine(v1,v2, upperLeft, lowerLeft ) ) return true;
        if (LineIntersectLine(v1,v2, lowerLeft, lowerRight) ) return true;
        if (LineIntersectLine(v1,v2, upperLeft, upperRight) ) return true;
        if (LineIntersectLine(v1,v2, upperRight, lowerRight) ) return true;
        return false;
}
Esempio n. 5
0
/**
 * Main program
 * @param  argc Number of command line arguments, inlucing the program itself.
 * @param  argv Vector of command line arguments.
 * @return      EXIT_SUCCESS if program exits normally, EXIT_ERROR otherwise.
 */
int main(int argc, char** argv) {
  if(argc < 2 || argc > 3) {
    std::cout << "Usage: warper input_image [ouput_image]" << std::endl;
    return EXIT_FAILURE;
  }

  readImage(argv[1]);

  Matrix3x3 M(1.0, 0.0, 0.0,
              0.0, 1.0, 0.0,
              0.0, 0.0, 1.0);
  process_input(M, originalWidth, originalHeight);

  Vector3d upperRight(originalWidth-1,originalHeight-1, 1);
  Vector3d lowerRight(originalWidth-1,0, 1);
  Vector3d upperLeft(0,originalHeight-1, 1);
  Vector3d lowerLeft(0,0, 1);

  upperRight = (M * upperRight)/upperRight[2];
  lowerRight = (M * lowerRight)/lowerRight[2];
  upperLeft = (M * upperLeft)/upperLeft[2];
  lowerLeft = (M * lowerLeft)/lowerLeft[2];

  newWidth = max(max(lowerLeft[0], lowerRight[0]), max(upperLeft[0], upperRight[0]));
  newHeight = max(max(lowerLeft[1], lowerRight[1]), max(upperLeft[1], upperRight[1]));

  int originX = min(min(lowerLeft[0], lowerRight[0]), min(upperLeft[0], upperRight[0]));
  int originY = min(min(lowerLeft[1], upperLeft[1]), min(lowerRight[1], upperRight[1]));

  newHeight = newHeight - originY;
  newWidth = newWidth - originX;

  Vector3d newOrigin(originX, originY, 0);

  // Initalize 2d array
  warppedPixels = new rgba_pixel*[newHeight];
  warppedPixels[0] = new rgba_pixel[newWidth*newHeight];

  for (int i=1; i < newHeight; i++) {
    warppedPixels[i] = warppedPixels[i-1] + newWidth;
  }

  Matrix3x3 invM = M.inv();

  for(int row = 0; row < newHeight; row++)
    for(int col = 0; col < newWidth; col++) {

      Vector3d pixel_out(col, row, 1);
      pixel_out = pixel_out + newOrigin;
      Vector3d pixel_in = invM * pixel_out;

      float u = pixel_in[0] / pixel_in[2];
      float v = pixel_in[1] / pixel_in[2];

      int roundedU = round(u);
      int roundedV = round(v);

      if((0 <= roundedU && roundedU < originalWidth) && (0 <= roundedV && roundedV < originalHeight)) {
          warppedPixels[row][col] = pixels[roundedV][roundedU];
        }
      else {
        rgba_pixel p;
        p.r = 0;
        p.g = 0;
        p.b = 0;
        p.a = 1;
        warppedPixels[row][col] = p;
      }
    }

    // Flip for openGL
    openGLFlip();

    // Init OpenGL
    glutInit(&argc, argv);
    openGLSetup(newWidth, newHeight);

    if(argc == 3) {
      outImage = argv[2];
      writeImage();
    }

    // Start running display window
    glutMainLoop();

  return EXIT_SUCCESS;
}
Esempio n. 6
0
void mitk::PaintbrushTool::UpdateContour(const InteractionPositionEvent* positionEvent)
{
  //MITK_INFO<<"Update...";
  // examine stateEvent and create a contour that matches the pixel mask that we are going to draw
  //mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>( interactionEvent );
  //const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return;

  // Get Spacing of current Slice
  //mitk::Vector3D vSpacing = m_WorkingSlice->GetSlicedGeometry()->GetPlaneGeometry(0)->GetSpacing();

  //
  // Draw a contour in Square according to selected brush size
  //
  int radius = (m_Size)/2;
  float fradius = static_cast<float>(m_Size) / 2.0f;

  ContourModel::Pointer contourInImageIndexCoordinates = ContourModel::New();


  // estimate center point of the brush ( relative to the pixel the mouse points on )
  // -- left upper corner for even sizes,
  // -- midpoint for uneven sizes
  mitk::Point2D centerCorrection;
  centerCorrection.Fill(0);

  // even --> correction of [+0.5, +0.5]
  bool evenSize = ((m_Size % 2) == 0);
  if( evenSize )
  {
    centerCorrection[0] += 0.5;
    centerCorrection[1] += 0.5;
  }

  // we will compute the control points for the upper left quarter part of a circle contour
  std::vector< mitk::Point2D > quarterCycleUpperRight;
  std::vector< mitk::Point2D > quarterCycleLowerRight;
  std::vector< mitk::Point2D > quarterCycleLowerLeft;
  std::vector< mitk::Point2D > quarterCycleUpperLeft;


  mitk::Point2D curPoint;
  bool curPointIsInside = true;
  curPoint[0] = 0;
  curPoint[1] = radius;
  quarterCycleUpperRight.push_back( upperLeft(curPoint) );

  // to estimate if a pixel is inside the circle, we need to compare against the 'outer radius'
  // i.e. the distance from the midpoint [0,0] to the border of the pixel [0,radius]
  //const float outer_radius = static_cast<float>(radius) + 0.5;

  while (curPoint[1] > 0)
  {
     // Move right until pixel is outside circle
     float curPointX_squared = 0.0f;
     float curPointY_squared = (curPoint[1] - centerCorrection[1] ) * (curPoint[1] - centerCorrection[1] );
     while( curPointIsInside )
     {
        // increment posX and chec
        curPoint[0]++;
        curPointX_squared = (curPoint[0] - centerCorrection[0] ) * (curPoint[0] - centerCorrection[0] );
        const float len = sqrt( curPointX_squared + curPointY_squared);
        if ( len > fradius )
        {
           // found first Pixel in this horizontal line, that is outside the circle
           curPointIsInside = false;
        }
     }
     quarterCycleUpperRight.push_back( upperLeft(curPoint) );

     // Move down until pixel is inside circle
     while( !curPointIsInside )
     {
        // increment posX and chec
        curPoint[1]--;
        curPointY_squared = (curPoint[1] - centerCorrection[1] ) * (curPoint[1] - centerCorrection[1] );
        const float len = sqrt( curPointX_squared + curPointY_squared);
        if ( len <= fradius )
        {
           // found first Pixel in this horizontal line, that is outside the circle
           curPointIsInside = true;
           quarterCycleUpperRight.push_back( upperLeft(curPoint) );
        }

        // Quarter cycle is full, when curPoint y position is 0
        if (curPoint[1] <= 0)
           break;
     }

   }

  // QuarterCycle is full! Now copy quarter cycle to other quarters.

  if( !evenSize )
  {
    std::vector< mitk::Point2D >::const_iterator it = quarterCycleUpperRight.begin();
    while( it != quarterCycleUpperRight.end() )
    {
      mitk::Point2D p;
      p = *it;

      // the contour points in the lower right corner have same position but with negative y values
      p[1] *= -1;
      quarterCycleLowerRight.push_back(p);

      // the contour points in the lower left corner have same position
      // but with both x,y negative
      p[0] *= -1;
      quarterCycleLowerLeft.push_back(p);

      // the contour points in the upper left corner have same position
      // but with x negative
      p[1] *= -1;
      quarterCycleUpperLeft.push_back(p);

      it++;
    }
  }
  else
  {
    std::vector< mitk::Point2D >::const_iterator it = quarterCycleUpperRight.begin();
    while( it != quarterCycleUpperRight.end() )
    {
      mitk::Point2D p,q;
      p = *it;

      q = p;
      // the contour points in the lower right corner have same position but with negative y values
      q[1] *= -1;
      // correct for moved offset if size even = the midpoint is not the midpoint of the current pixel
      // but its upper rigt corner
      q[1] += 1;
      quarterCycleLowerRight.push_back(q);

      q = p;
      // the contour points in the lower left corner have same position
      // but with both x,y negative
      q[1] = -1.0f * q[1] + 1;
      q[0] = -1.0f * q[0] + 1;
      quarterCycleLowerLeft.push_back(q);

      // the contour points in the upper left corner have same position
      // but with x negative
      q = p;
      q[0] *= -1;
      q[0] +=  1;
      quarterCycleUpperLeft.push_back(q);

      it++;
    }
  }

  // fill contour with poins in right ordering, starting with the upperRight block
  mitk::Point3D tempPoint;
  for (unsigned int i=0; i<quarterCycleUpperRight.size(); i++)
  {
     tempPoint[0] = quarterCycleUpperRight[i][0];
     tempPoint[1] = quarterCycleUpperRight[i][1];
     tempPoint[2] = 0;
     contourInImageIndexCoordinates->AddVertex( tempPoint );
  }
  // the lower right has to be parsed in reverse order
  for (int i=quarterCycleLowerRight.size()-1; i>=0; i--)
  {
     tempPoint[0] = quarterCycleLowerRight[i][0];
     tempPoint[1] = quarterCycleLowerRight[i][1];
     tempPoint[2] = 0;
     contourInImageIndexCoordinates->AddVertex( tempPoint );
  }
  for (unsigned int i=0; i<quarterCycleLowerLeft.size(); i++)
  {
     tempPoint[0] = quarterCycleLowerLeft[i][0];
     tempPoint[1] = quarterCycleLowerLeft[i][1];
     tempPoint[2] = 0;
     contourInImageIndexCoordinates->AddVertex( tempPoint );
  }
  // the upper left also has to be parsed in reverse order
  for (int i=quarterCycleUpperLeft.size()-1; i>=0; i--)
  {
     tempPoint[0] = quarterCycleUpperLeft[i][0];
     tempPoint[1] = quarterCycleUpperLeft[i][1];
     tempPoint[2] = 0;
     contourInImageIndexCoordinates->AddVertex( tempPoint );
  }

  m_MasterContour = contourInImageIndexCoordinates;

}
Esempio n. 7
0
//------------------------------------------------------------------------------
// void SaveChildPositionAndSize()
//------------------------------------------------------------------------------
void GmatMdiChildFrame::SaveChildPositionAndSize()
{
   if (mCanSaveLocation == false)
      return;

   if (IsIconized())
      return;
   
   // Get the position and size of the window first
   #ifdef __WXMAC__
      Integer screenWidth  = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
      Integer screenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);
   #else
      Integer screenWidth;
      Integer screenHeight;
      GmatAppData::Instance()->GetMainFrame()->GetActualClientSize(&screenWidth, &screenHeight, true);
      // Since GmatMainFrame::GetActualClientSize() subtracts one, add one here (LOJ: 2012.07.23)
      screenWidth++;
      screenHeight++;
   #endif

   bool isMinimized = IsIconized(), isMaximized = IsMaximized();
   if (isMinimized)	
	  Iconize(false);
   else if (isMaximized)
	  Maximize(false);

   int tmpX = -1, tmpY = -1;
   int tmpW = -1, tmpH = -1;
   GetPosition(&tmpX, &tmpY);
   GetSize(&tmpW, &tmpH);
   Rvector upperLeft(2, ((Real) tmpX /(Real)  screenWidth), ((Real) tmpY /(Real)  screenHeight));
   Rvector childSize(2,  ((Real) tmpW /(Real)  screenWidth), ((Real) tmpH /(Real)  screenHeight));

   if (isMinimized)	
	  Iconize();
   else if (isMaximized)
	  Maximize();


   #ifdef DEBUG_PERSISTENCE
   // ======================= begin temporary ==============================
   MessageInterface::ShowMessage("*** Size of SCREEN %s is: width = %d, height = %d\n",
                                 mChildName.WX_TO_C_STRING, screenWidth, screenHeight);
   MessageInterface::ShowMessage("Position of View plot %s is: x = %d, y = %d\n",
                                 mChildName.WX_TO_C_STRING, tmpX, tmpY);
   MessageInterface::ShowMessage("Size of View plot %s is: width = %d, height = %d\n",
                                 mChildName.WX_TO_C_STRING, tmpW, tmpH);
   // ======================= end temporary ==============================
   #endif

   if ((mItemType == GmatTree::OUTPUT_REPORT)  ||
       (mItemType == GmatTree::OUTPUT_CCSDS_OEM_FILE ) ||
       (mItemType == GmatTree::OUTPUT_ORBIT_VIEW) ||
       (mItemType == GmatTree::OUTPUT_XY_PLOT) ||
       (mItemType == GmatTree::OUTPUT_GROUND_TRACK_PLOT)
       // We'll want to add the event reports eventually, but they are not subscriber based
       //|| (mItemType == GmatTree::EVENT_REPORT)
       )
   {
      GmatBase *obj = theGuiInterpreter->GetConfiguredObject(mChildName.c_str());
      
      #ifdef DEBUG_FUNCTION
      // Check if child name is the configured object name
      MessageInterface::ShowMessage
         ("GmatMdiChildFrame::SaveChildPositionAndSize() the child '%s' %s a "
          "configured object, obj = <%p>[%s]'%s'\n", mChildName.WX_TO_C_STRING,
          obj ? "is" : "is not", obj, obj ? obj->GetTypeName().c_str() : "NULL",
          obj ? obj->GetName().c_str() : "NULL");
      #endif
      
      if (!obj)
      {
         // Just return if child is not a configured subscriber,ie,
         // plotting from GMAT function (LOJ: 2015.06.26)
         #ifdef DEBUG_FUNCTION
         MessageInterface::ShowMessage
            ("**** WARNING **** GmatMdiChildFrame::SaveChildPositionAndSize() "
             "will not save position and size for unconfigured subscriber '%s'\n",
             mChildName.WX_TO_C_STRING);
         #endif
         return;
      }
      else if (!obj->IsOfType("Subscriber"))
      {
         #ifdef DEBUG_PERSISTENCE
         MessageInterface::ShowMessage
            ("**** WARNING **** GmatMdiChildFrame::SaveChildPositionAndSize() "
             "cannot not save position and size for non-subscriber '%s'\n",
             mChildName.WX_TO_C_STRING);
         #endif
         SubscriberException se;
         se.SetDetails("Cannot set position and size for non-subscriber '%s'");
         throw se;
      }
      
      Subscriber *sub = (Subscriber*) obj;
      
      #ifdef DEBUG_PERSISTENCE
         MessageInterface::ShowMessage("...... Now saving plot data to %s:\n", (sub->GetName()).c_str());
         MessageInterface::ShowMessage("       Upper left             = %12.10f   %12.10f\n", upperLeft[0], upperLeft[1]);
         MessageInterface::ShowMessage("       Size                   = %12.10f   %12.10f\n", childSize[0], childSize[1]);
         MessageInterface::ShowMessage("       RelativeZOrder         = %d\n", relativeZOrder);
      #endif
      sub->SetRvectorParameter(sub->GetParameterID("UpperLeft"), upperLeft);
      sub->SetRvectorParameter(sub->GetParameterID("Size"), childSize);
      sub->SetIntegerParameter(sub->GetParameterID("RelativeZOrder"), relativeZOrder);
      sub->SetBooleanParameter(sub->GetParameterID("Maximized"), isMaximized);
   }
   else if (mItemType == GmatTree::MISSION_TREE_UNDOCKED)
   {
      // get the config object
      wxFileConfig *pConfig;
      pConfig = (wxFileConfig *) GmatAppData::Instance()->GetPersonalizationConfig();
      std::stringstream location("");
      location << upperLeft[0] << " " << upperLeft[1];
      std::stringstream size("");
      size << childSize[0] << " " << childSize[1];
      pConfig->Write("/MissionTree/UpperLeft", location.str().c_str());
      pConfig->Write("/MissionTree/Size", size.str().c_str());
      pConfig->Write("/MissionTree/IsMaximized", isMaximized);
      pConfig->Write("/MissionTree/IsMinimized", isMinimized);
   }
   else if (mItemType == GmatTree::SCRIPT_FILE)
   {
      // get the config object
      wxFileConfig *pConfig;
      pConfig = (wxFileConfig *) GmatAppData::Instance()->GetPersonalizationConfig();
      std::stringstream location("");
      location << upperLeft[0] << " " << upperLeft[1];
      std::stringstream size("");
      size << childSize[0] << " " << childSize[1];
      pConfig->Write("/ScriptEditor/UpperLeft", location.str().c_str());
      pConfig->Write("/ScriptEditor/Size", size.str().c_str());
      pConfig->Write("/ScriptEditor/IsMaximized", isMaximized);
      pConfig->Write("/ScriptEditor/IsMinimized", isMinimized);
   }
}
Esempio n. 8
0
//------------------------------------------------------------------------------
// void SaveChildPositionAndSize()
//------------------------------------------------------------------------------
void GmatMdiChildFrame::SaveChildPositionAndSize()
{
   if (mCanSaveLocation == false)
      return;

   // Get the position and size of the window first
   #ifdef __WXMAC__
      Integer screenWidth  = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
      Integer screenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);
   #else
      Integer screenWidth;
      Integer screenHeight;
      //theParent->GetClientSize(&screenWidth, &screenHeight);
      GmatAppData::Instance()->GetMainFrame()->GetActualClientSize(&screenWidth, &screenHeight, true);
   #endif

//   #ifdef DEBUG_PERSISTENCE
//   wxRect      wxR         = GetScreenRect();
//   wxPoint     wxP         = wxR.GetPosition();
//   wxSize      wxS         = wxR.GetSize();
//   Integer     x           = (Integer) wxP.x;
//   Integer     y           = (Integer) wxP.y;
//   Integer     w           = (Integer) wxS.GetWidth();
//   Integer     h           = (Integer) wxS.GetHeight();
//   MessageInterface::ShowMessage
//      (wxT("wxP.x = %d, wxP.y = %d, wxS.w = %d, wxS.h = %d\n"), x, y, w, h);
//   #endif

   int tmpX = -1, tmpY = -1;
   int tmpW = -1, tmpH = -1;
   GetPosition(&tmpX, &tmpY);
   GetSize(&tmpW, &tmpH);
   Rvector upperLeft(2, ((Real) tmpX /(Real)  screenWidth), ((Real) tmpY /(Real)  screenHeight));
   Rvector childSize(2,  ((Real) tmpW /(Real)  screenWidth), ((Real) tmpH /(Real)  screenHeight));

   #ifdef DEBUG_PERSISTENCE
   // ======================= begin temporary ==============================
   MessageInterface::ShowMessage(wxT("*** Size of SCREEN %s is: width = %d, height = %d\n"), mPlotName.c_str(), screenWidth, screenHeight);
   MessageInterface::ShowMessage(wxT("Position of View plot %s is: x = %d, y = %d\n"), mPlotName.c_str(), tmpX, tmpY);
   MessageInterface::ShowMessage(wxT("Size of View plot %s is: width = %d, height = %d\n"), mPlotName.c_str(), tmpW, tmpH);
//   MessageInterface::ShowMessage(wxT("Position of View plot %s in pixels rel. to parent window is: x = %d, y = %d\n"),
//                                 mPlotName.c_str(), (Integer) tmpX, (Integer) tmpY);
//   MessageInterface::ShowMessage(wxT("Size of View plot %s in pixels rel. to parent window is: x = %d, y = %d\n"),
//                                 mPlotName.c_str(), (Integer) tmpW, (Integer) tmpH);
//   wxPoint tmpPt = ScreenToClient(wxP);
//   MessageInterface::ShowMessage(wxT("--- Position of View plot %s in client coords is: x = %d, y = %d\n"),
//                                 mPlotName.c_str(), (Integer) tmpPt.x, (Integer) tmpPt.y);
   // ======================= end temporary ==============================
   #endif

   if ((mItemType == GmatTree::OUTPUT_REPORT)  || (mItemType == GmatTree::OUTPUT_ORBIT_VIEW) ||
       (mItemType == GmatTree::OUTPUT_XY_PLOT) || (mItemType == GmatTree::OUTPUT_GROUND_TRACK_PLOT)
       // We'll want to add the event reports eventually, but they are not subscriber based
       //|| (mItemType == GmatTree::EVENT_REPORT)
       )
   {
      GmatBase *obj =
         (Subscriber*)theGuiInterpreter->GetConfiguredObject(mPlotName.c_str());
         
      if (!obj || !obj->IsOfType(wxT("Subscriber")))
      {
         wxString errmsg = wxT("Cannot find subscriber ");
         errmsg += mPlotName + wxT("\n");
         throw SubscriberException(errmsg);
      }
      Subscriber *sub = (Subscriber*) obj;

      #ifdef DEBUG_PERSISTENCE
         MessageInterface::ShowMessage("...... Now saving plot data to %s:\n", (sub->GetName()).c_str());
         MessageInterface::ShowMessage("       Upper left             = %12.10f   %12.10f\n", upperLeft[0], upperLeft[1]);
         MessageInterface::ShowMessage("       Size                   = %12.10f   %12.10f\n", childSize[0], childSize[1]);
         MessageInterface::ShowMessage("       RelativeZOrder         = %d\n", relativeZOrder);
      #endif
      sub->SetRvectorParameter(sub->GetParameterID(wxT("UpperLeft")), upperLeft);
      sub->SetRvectorParameter(sub->GetParameterID(wxT("Size")), childSize);
      sub->SetIntegerParameter(sub->GetParameterID(wxT("RelativeZOrder")), relativeZOrder);
   }
   else if (mItemType == GmatTree::MISSION_TREE_UNDOCKED)
   {
      // get the config object
      wxFileConfig *pConfig;
      pConfig = (wxFileConfig *) GmatAppData::Instance()->GetPersonalizationConfig();
      wxString location;
      location << upperLeft[0] << wxT(" ") << upperLeft[1];
      wxString size;
      size << childSize[0] << wxT(" ") << childSize[1];
      pConfig->Write(wxT("/MissionTree/UpperLeft"), location.c_str());
      pConfig->Write(wxT("/MissionTree/Size"), size.c_str());
   }
}
Esempio n. 9
0
wxPoint MutIconShapeClass<T>::GetPerimeterPoint(const wxPoint &i,const wxPoint &o, wxWindow * paintingWindow) const {
//	wxPoint inner = ScreenToClient(i); unused
	wxPoint myoffset = GetPositionInWindow(paintingWindow);
	wxPoint outer = o - myoffset;
	DEBUGLOG(routinggui,_T("outer (%d,%d) is in device (%d,%d)"),o.x,o.y,outer.x,outer.y);
	wxRect iconRect = this->GetIconRect();
	DEBUGLOG(routinggui,_T("Icon rect: x=%d, y=%d, w=%d, h=%d"),iconRect.x,iconRect.y,iconRect.width,iconRect.height);
	wxPoint iconCenter(iconRect.x+iconRect.width/2,
			   iconRect.y+iconRect.height/2);
	DEBUGLOG(routinggui,_T("center = (%d,%d)"), iconCenter.x, iconCenter.y);
/*
	wxRect screenRect = this->GetScreenRect();
	// transform Screen rect to upper left and 
	wxPoint upperLeft(this->ScreenToClient(wxPoint(screenRect.x,screenRect.y)));
	wxPoint lowerRight(this->ScreenToClient(wxPoint(screenRect.x+screenRect.width,screenRect.y+screenRect.height)));
*/
	wxRect screenRect = this->GetClientRect();
	wxPoint upperLeft(screenRect.x,screenRect.y);
	wxPoint lowerRight(screenRect.x+screenRect.width,screenRect.y+screenRect.height);
	DEBUGLOG(routinggui,_T("Rectangle: (%d,%d) -- (%d,%d)"),upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y);

	wxPoint perimeterpoint(0,0);
	if (lowerRight.x <= outer.x) {
		perimeterpoint.x = lowerRight.x;
		perimeterpoint.y = iconCenter.y;
	} else if (outer.x <= upperLeft.x) {
		perimeterpoint.x = upperLeft.x;
		perimeterpoint.y = iconCenter.y;
	} else if (outer.y <= upperLeft.y) {
		perimeterpoint.x = iconCenter.x;
		perimeterpoint.y = upperLeft.y;
	} else if (lowerRight.y <= outer.y) {
		perimeterpoint.x = iconCenter.x;
		perimeterpoint.y = lowerRight.y;
	} else {
		perimeterpoint = iconCenter;
	}

	mutpointlist::iterator pos = std::find(usedperimeterpoints.begin(),
					       usedperimeterpoints.end(),
					       perimeterpoint);
	if (pos == usedperimeterpoints.end())
		usedperimeterpoints.push_back(perimeterpoint);

	wxPoint retval = perimeterpoint + myoffset;

	DEBUGLOG(routinggui,_T("perimeter point (%d,%d), returning (%d,%d)"), 
		 perimeterpoint.x,perimeterpoint.y,retval.x,retval.y);

	return retval;


#if 0
	wxRect r = this->GetRect();
	DEBUGLOG (other, _T("Rect: (%d,%d) -- (%d,%d)"),r.x,r.y,r.x+r.width,r.y+r.height);
	DEBUGLOG (other, _T("Points: i = (%d,%d), o = (%d, %d)"),i.x,i.y,o.x,o.y);
	wxRect ir = this->GetIconRect();
#ifdef DEBUG
	std::cerr.flush();
	mutASSERT(r.Contains(i));
#endif

	wxPoint p;
	int xoffset = 0;
#if __WXMAC__ && 0
	xoffset = this->GetWindowBorderSize().x/2;
#endif

	r.y += borderOffset.y;
#if __WXMAC__
	r.y += maxBorderSize.y - borderOffset.y;
#endif
	if (r.x+r.width <= o.x) {
		p.x = r.x + r.width + xoffset;
		p.y = ir.y + ir.height/2;
	} else if (r.x >= o.x) {
		p.x = r.x - xoffset;
		p.y = ir.y + ir.height/2;
	} else if (r.y <= o.y) {
		p.x = r.x + r.width/2;
		p.y = r.y;
	} else if (r.y + r.height >= o.y) {
		p.x = r.x + r.width/2;
		p.y = r.y + r.height;
	} else p = o;


	mutpointlist::iterator pos = std::find(usedperimeterpoints.begin(),
					       usedperimeterpoints.end(),
					       p);
	if (pos == usedperimeterpoints.end())
		usedperimeterpoints.push_back(p);

#if __WXGTK__ && 0
	p.y += maxBorderSize.y - this->GetWindowBorderSize().y / 2;
#endif
	return p;
#endif
}
Esempio n. 10
0
bool Ball::FlipperCollision(Vector4& otherCenter, Game_Object& other, float& angle)
{
	bool hasCollided;

	Vector4 axis, C, A, B;
	float projC, projA, projB, gap;

	// Calculate the center
	Vector2 thisCenter(this->translationMatrix[0][3], this->translationMatrix[1][3]);

	// Corners of flipper
	Vector4 upperRight(other.sprite->GetRadius().x, other.sprite->GetRadius().y, 0.0f, 0.0f);
	Vector4 upperLeft(-other.sprite->GetRadius().x, other.sprite->GetRadius().y, 0.0f, 0.0f);
	Vector4 bottomRight(other.sprite->GetRadius().x, -other.sprite->GetRadius().y, 0.0f, 0.0f);
	Vector4 bottomLeft(-other.sprite->GetRadius().x, -other.sprite->GetRadius().y, 0.0f, 0.0f);
	// Properly rotate all corners
	upperRight = other.rotationMatrix * upperRight;
	upperLeft = other.rotationMatrix * upperLeft;
	bottomRight = other.rotationMatrix * bottomRight;
	bottomLeft = other.rotationMatrix * bottomLeft;

	// Corners of circle
	Vector4 circleUpperRight( (float)sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), (float)sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), 0.0f, 0.0f ); 
	Vector4 circleUpperLeft( (float)-sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), (float)sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), 0.0f, 0.0f );
	Vector4 circleBottomRight( (float)sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), (float)-sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), 0.0f, 0.0f );
	Vector4 circleBottomLeft( (float)-sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), (float)-sqrt( pow( this->sprite->GetRadius().x, 2.0f ) / 2.0f ), 0.0f, 0.0f );
	// Properly rotate all corners
	circleUpperRight = other.rotationMatrix * circleUpperRight;
	circleUpperLeft = other.rotationMatrix * circleUpperLeft;
	circleBottomRight = other.rotationMatrix * circleBottomRight;
	circleBottomLeft = other.rotationMatrix * circleBottomLeft;

	// Axis 1 (top)
	// Calculate axis, 3 vectors, the dot, and then the gap
	axis = Vector4( (upperRight - upperLeft).normalize(upperRight - upperLeft) );
	C = Vector4(otherCenter.x - thisCenter.x, otherCenter.y - thisCenter.y, 0.0f, 0.0f);
	A = Vector4(circleUpperRight);
	B = Vector4(upperRight);

	projC = C.dot(axis);
	projA = A.dot(axis);
	projB = B.dot(axis);
	gap = abs(projC) - abs(projA) - abs(projB);	

	// Check value of gap
	if(gap > 0)
		return false;

	// Axis 2 (bottom)
	// Calculate axis, 3 vectors, the dot, and then the gap
	axis = Vector4( (bottomRight - bottomLeft).normalize(bottomRight - bottomLeft) );
	C = Vector4(otherCenter.x - thisCenter.x, otherCenter.y - thisCenter.y, 0.0f, 0.0f);
	A = Vector4(circleBottomRight);
	B = Vector4(bottomRight);

	projC = C.dot(axis);
	projA = A.dot(axis);
	projB = B.dot(axis);
	gap = abs(projC) - abs(projA) - abs(projB);	

	// Check value of gap
	if(gap > 0)
		return false;

	// Axis 3 (right)
	// Calculate axis, 3 vectors, the dot, and then the gap
	axis = Vector4( (upperRight - bottomRight).normalize(upperRight - bottomRight) );
	C = Vector4(otherCenter.x - thisCenter.x, otherCenter.y - thisCenter.y, 0.0f, 0.0f);
	A = Vector4(circleBottomRight);
	B = Vector4(bottomRight);

	projC = C.dot(axis);
	projA = A.dot(axis);
	projB = B.dot(axis);
	gap = abs(projC) - abs(projA) - abs(projB);	

	// Check value of gap
	if(gap > 0)
		return false;

	// Axis 4 (left)
	// Calculate axis, 3 vectors, the dot, and then the gap
	axis = Vector4( (upperLeft - bottomLeft).normalize(upperLeft - bottomLeft) );
	C = Vector4(otherCenter.x - thisCenter.x, otherCenter.y - thisCenter.y, 0.0f, 0.0f);
	A = Vector4(circleBottomLeft);
	B = Vector4(bottomLeft);

	projC = C.dot(axis);
	projA = A.dot(axis);
	projB = B.dot(axis);
	gap = abs(projC) - abs(projA) - abs(projB);	

	// Check value of gap
	if(gap > 0)
		return false;

	float currentAngle = acos(other.rotationMatrix[0][0]);

	// Collides with long side
	if(projC > 0 && projA < 0 )
	{
		// compare against leftUpper && leftLower
			// use distance formula - from circle_center to each point
			// which is shortest? leftUpper => "above", leftLower => "below"
		float distanceUpper = ( (upperLeft + otherCenter) - Vector4(thisCenter.x, thisCenter.y, 0.0f, 0.0f )).length();
		float distanceLower = ( (bottomLeft + otherCenter) - Vector4(thisCenter.x, thisCenter.y, 0.0f, 0.0f )).length();
		if(distanceUpper < distanceLower)
		{
			// Hit "top" side
			angle = currentAngle;

			if(angle <= PI)
				angle = PI - angle;
			else
				angle = 2*PI - angle;
		}
		else
		{
			// Hit "bottom" side
			angle = currentAngle + PI;

			if(angle <= PI)
				angle = PI - angle;
			else
				angle = 2*PI - angle;
		}
	}
	// Collides with short side
	else
	{
		// compare against leftUpper && rightUpper
			// use distance formula - from circle_center to each point
			// which is shortest? leftUpper => "left", rightUpper => "right"
		float distanceLeft = ( (upperLeft + otherCenter) - Vector4(thisCenter.x, thisCenter.y, 0.0f, 0.0f )).length();
		float distanceRight = ( (upperRight + otherCenter) - Vector4(thisCenter.x, thisCenter.y, 0.0f, 0.0f )).length();
		if(distanceLeft < distanceRight)
		{
			// Hit "left" side
			angle = currentAngle + PI / 2;

			if(angle <= PI)
				angle = PI - angle;
			else
				angle = 2*PI - angle;
		}
		else
		{
			// Hit "right" side
			angle = currentAngle + 3 * PI / 2;

			if(angle <= PI)
				angle = PI - angle;
			else
				angle = 2*PI - angle;
		}
	}


	return true;
}