void Box3D::TranslateBox(Vector& mins, Vector& maxs)
{
	if ( m_TranslateMode == modeNone )
	{
		return;
	}

	if ( m_TranslateMode == modeMove )
	{
		mins += m_vTranslation;
		maxs += m_vTranslation;
	}

	else if ( m_TranslateMode == modeScale )
	{
		for ( int i=0; i<3; i++ )
		{
			float handle = m_TranslateHandle[i];

			if ( handle > 0 )
			{
				maxs[i] += m_vTranslation[i];
			}
			else if ( handle < 0 )
			{
				mins[i] += m_vTranslation[i];
			}
		}
	}

	else if ( m_TranslateMode == modeShear )
	{
		TranslatePoint( mins );
		TranslatePoint( maxs );
	}
	else if ( m_TranslateMode == modeRotate )
	{
		TranslatePoint( mins );
		TranslatePoint( maxs );
	}

	NormalizeBox( mins, maxs );
}
Exemple #2
0
// add a vector of data to the plot (will use a new color for each call)
const char* svgPlot::addData( std::vector<Point>& data )
{
   bool first = true ;
   std::vector<Point>::iterator itLast ;

   const char* strColor = colors[ _color ] ;
   _color++ ;
   if( _color >= NUMBER_COLORS )
   {
      _color = 0 ;
   }

   svgGroup* group = new svgGroup ;
   group->setViewport( 0 , 0 , _width , _height ) ;

   for( std::vector<Point>::iterator it = data.begin(); it != data.end(); ++it) 
   {
      Point point1 = TranslatePoint( *it ) ;

      svgEllipse* ellipse = new svgEllipse( point1.xVal , point1.yVal , MARKER_RADIUS , MARKER_RADIUS , strColor ) ;
      group->addElement( ellipse ) ;

      if( first )
      {
         first = false ;
         itLast = it ;
         continue ;
      }

      Point point2 = TranslatePoint( *itLast ) ;
      svgLine* line = new svgLine( point1 , point2 , strColor ) ;
      group->addElement( line ) ;

      itLast = it ;
   }

   addElement( group ) ;

   return strColor ;
}
//-----------------------------------------------------------------------------
// Purpose: Renders this region as a wireframe box.
// Input  : pRender - 3D Renderer.
//-----------------------------------------------------------------------------
void Box3D::RenderTool3D(CRender3D *pRender)
{
    if ( IsTranslating() )
	{
		VMatrix matrix = GetTransformMatrix();
		pRender->BeginLocalTransfrom( matrix );
	}
	else if (IsEmpty())
	{
		return;
	}

	pRender->PushRenderMode( RENDER_MODE_FLAT );
	pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) );
	pRender->DrawBox( bmins, bmaxs );
	pRender->PopRenderMode();

	if ( IsTranslating() )
	{
		pRender->EndLocalTransfrom();

		if ( m_TranslateMode == modeMove || m_TranslateMode == modeRotate )
		{
			Vector vec = m_vTranslationFixPoint;

			if ( m_TranslateMode == modeMove  )
			{
				TranslatePoint( vec );
			}

			// draw 'X'
			pRender->PushRenderMode( RENDER_MODE_FLAT_NOZ );
			pRender->SetHandleStyle( 7, CRender::HANDLE_CROSS );
			pRender->SetHandleColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) );
			pRender->DrawHandle( vec );
			pRender->PopRenderMode();

		}
	}
	else if ( m_bEnableHandles )
	{
		RenderHandles3D( pRender, bmins, bmaxs );
	};

	

	
}
VOID DrawHand (HPS hps, POINTL aptlIn[], INT iNum, INT iAngle,
               PWINDOWINFO pwi)
     {
     INT    iIndex ;
     POINTL aptl [5] ;

     for (iIndex = 0 ; iIndex < iNum ; iIndex++)
          aptl [iIndex] = aptlIn [iIndex] ;

     RotatePoint    (aptl, iNum, iAngle) ;
     ScalePoint     (aptl, iNum, pwi) ;
     TranslatePoint (aptl, iNum, pwi) ;

     GpiMove (hps, aptl) ;
     GpiPolyLine (hps, iNum - 1L, aptl + 1) ;
     }
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pDC - 
//			bounds - 
//-----------------------------------------------------------------------------
void Box3D::RenderTool2D(CRender2D *pRender)
{
	Vector mins = bmins;
	Vector maxs = bmaxs;
	CMapView2D *pView = (CMapView2D*)pRender->GetView();

	Assert( pRender );

	if ( IsTranslating() )
	{
		TranslateBox( mins, maxs );
	}
	else if ( IsEmpty() )
	{
		return;
	}


	if ( m_dwDrawFlags & boundstext)
	{
		DrawBoundsText(pRender, mins, maxs, DBT_TOP | DBT_LEFT);
	}

	if ( IsTranslating() )
	{
	    pRender->PushRenderMode( RENDER_MODE_DOTTED );
		pRender->SetDrawColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) );
	}
	else if (!(m_dwDrawFlags & thicklines))
	{
		pRender->PushRenderMode( RENDER_MODE_DOTTED );
		pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) );
	}
	else
	{
		pRender->PushRenderMode( RENDER_MODE_FLAT_NOZ );
		pRender->SetDrawColor( GetRValue(m_clrBox), GetGValue(m_clrBox), GetBValue(m_clrBox) );
	}

	// render bounds
	if ( !IsTranslating() || m_TranslateMode == modeScale || m_TranslateMode == modeMove )
	{
		// draw simple rectangle
		pRender->DrawRectangle( mins, maxs, false, 0 );
	}
	else
	{
		// during rotation or shearing, draw transformed bounding box

		Vector v[4];
		
		// init all points to center
		v[0] = v[1] = v[2] = v[3] = (bmins+bmaxs) / 2;

		int axis = pView->axHorz;

		v[0][axis] = v[1][axis] = bmins[axis];
		v[2][axis] = v[3][axis] = bmaxs[axis];

		axis = pView->axVert;

		v[1][axis] = v[2][axis] = bmins[axis];
		v[0][axis] = v[3][axis] = bmaxs[axis];

		for ( int i=0; i<4; i++)
		{
			TranslatePoint( v[i] );
		}
		
		pRender->DrawLine( v[0], v[1] );
		pRender->DrawLine( v[1], v[2] );
		pRender->DrawLine( v[2], v[3] );
		pRender->DrawLine( v[3], v[0] );
	}

	pRender->PopRenderMode();

	// draw a cross for translation origin in move or rotation mode
	if ( IsTranslating() )
	{
		if ( m_TranslateMode == modeMove || m_TranslateMode == modeRotate )
		{
			Vector vec = m_vTranslationFixPoint;

			if ( m_TranslateMode == modeMove  )
 			{
				TranslatePoint( vec );
			}

			// draw 'X'
			pRender->SetHandleStyle( 7, CRender::HANDLE_CROSS );
			pRender->SetHandleColor( GetRValue(Options.colors.clrToolDrag), GetGValue(Options.colors.clrToolDrag), GetBValue(Options.colors.clrToolDrag) );
			pRender->DrawHandle( vec );
			
		}
	}
	else if ( m_bEnableHandles )
	{
		RenderHandles2D( pRender, mins, maxs );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pszBuf - 
//-----------------------------------------------------------------------------
void Box3D::GetStatusString(char *pszBuf)
{
	*pszBuf = '\0';



	Vector mins(0,0,0);
	Vector maxs(0,0,0);

	if ( IsValidBox() )
	{
		mins = bmins;
		maxs = bmaxs;
	}

	if ( IsTranslating() )
	{
		TranslateBox( mins, maxs );
	}

	Vector size = maxs - mins;
	Vector center = ( maxs + mins ) * 0.5f;

	if ( !IsTranslating() || m_TranslateMode == modeScale || m_TranslateMode == modeMove )
	{
		if (!IsEmpty())
		{
			if ( IsTranslating() && m_TranslateMode == modeMove )
			{
				center = m_vTranslationFixPoint;
				TranslatePoint( center );
			}

			switch (m_eWorldUnits)
			{
				case Units_None:
				{
					sprintf(pszBuf, " %dw %dl %dh @(%.0f %.0f %.0f)", 
						(int)fabs(size.x), (int)fabs(size.y), (int)fabs(size.z),
						center.x,center.y,center.z );
					break;
				}

				case Units_Inches:
				{
					sprintf(pszBuf, " %d\"w %d\"l %d\"h", (int)fabs(size.x), (int)fabs(size.y), (int)fabs(size.z));
					break;
				}

				case Units_Feet_Inches:
				{
					int nFeetWide = (int)fabs(size.x) / 12;
					int nInchesWide = (int)fabs(size.x) % 12;

					int nFeetLong = (int)fabs(size.y) / 12;
					int nInchesLong = (int)fabs(size.y) % 12;

					int nFeetHigh = (int)fabs(size.z) / 12;
					int nInchesHigh = (int)fabs(size.z) % 12;

					sprintf(pszBuf, " %d' %d\"w %d' %d\"l %d' %d\"h", nFeetWide, nInchesWide, nFeetLong, nInchesLong, nFeetHigh, nInchesHigh);
					break;
				}
			}
		}
	}
	else if ( m_TranslateMode == modeShear )
	{
		sprintf(pszBuf, " shear: %d %d %d ", (int)m_vTranslation.x, (int)m_vTranslation.y, (int)m_vTranslation.z );
	}
	else if ( m_TranslateMode == modeRotate )
	{
		int rotAxis = GetTransformationAxis();

		if ( rotAxis != -1  )
		{
			sprintf(pszBuf, " %.2f%c", m_vTranslation[abs(rotAxis+2)%3], 0xF8);
		}
		else
		{
			sprintf(pszBuf, " %.2f %.2f %.2f%c", m_vTranslation.x, m_vTranslation.y, m_vTranslation.z, 0xF8);
		}
	}
	else
	{
		Assert( 0 );
	}
	
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static DATETIME   dtPrevious ;
     static HDC        hdc ;
     static LONG       xPixelsPerMeter, yPixelsPerMeter ;
     static POINTL     aptlHour   [5] = { 0,-15, 10,0, 0,60, -10,0, 0,-15 },
                       aptlMinute [5] = { 0,-20,  5,0, 0,80,  -5,0, 0,-20 },
                       aptlSecond [2] = { 0,  0,  0,80 } ;
     static WINDOWINFO wi ;
     DATETIME          dt ;
     HPS               hps ;
     INT               iDiamMM, iAngle ;
     POINTL            aptl [3] ;

     switch (msg)
          {
          case WM_CREATE:
               hdc = WinOpenWindowDC (hwnd) ;

               DevQueryCaps (hdc, CAPS_VERTICAL_RESOLUTION,
                                  1L, &yPixelsPerMeter) ;
               DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION,
                                  1L, &xPixelsPerMeter) ;

               DosGetDateTime (&dtPrevious) ;
               dtPrevious.hours = (dtPrevious.hours * 5) % 60 +
                                   dtPrevious.minutes / 12 ;
               return 0 ;

          case WM_SIZE:
               wi.cxClient = SHORT1FROMMP (mp2) ;
               wi.cyClient = SHORT2FROMMP (mp2) ;

               iDiamMM = min (wi.cxClient * 1000L / xPixelsPerMeter,
                              wi.cyClient * 1000L / yPixelsPerMeter) ;

               wi.cxPixelDiam = xPixelsPerMeter * iDiamMM / 1000 ;
               wi.cyPixelDiam = yPixelsPerMeter * iDiamMM / 1000 ;
               return 0 ;

          case WM_TIMER:
               DosGetDateTime (&dt) ;
               dt.hours = (dt.hours * 5) % 60 + dt.minutes / 12 ;

               hps = WinGetPS (hwnd) ;
               GpiSetColor (hps, CLR_BACKGROUND) ;

               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               if (dt.hours   != dtPrevious.hours ||
                   dt.minutes != dtPrevious.minutes)
                    {
                    DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
                    DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
                    }

               GpiSetColor (hps, CLR_NEUTRAL) ;

               DrawHand (hps, aptlHour,   5, dt.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dt.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dt.seconds, &wi) ;

               WinReleasePS (hps) ;
               dtPrevious = dt ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;
               GpiErase (hps) ;

               for (iAngle = 0 ; iAngle < 60 ; iAngle++)
                    {
                    aptl[0].x = 0 ;
                    aptl[0].y = 90 ;

                    RotatePoint    (aptl, 1, iAngle) ;
                    ScalePoint     (aptl, 1, &wi) ;
                    TranslatePoint (aptl, 1, &wi) ;

                    aptl[2].x = aptl[2].y = iAngle % 5 ? 2 : 10 ;

                    ScalePoint (aptl + 2, 1, &wi) ;

                    aptl[0].x -= aptl[2].x / 2 ;
                    aptl[0].y -= aptl[2].y / 2 ;

                    aptl[1].x = aptl[0].x + aptl[2].x ;
                    aptl[1].y = aptl[0].y + aptl[2].y ;

                    GpiMove (hps, aptl) ;
                    GpiBox (hps, DRO_OUTLINEFILL, aptl + 1,
                                 aptl[2].x, aptl[2].y) ;
                    }
               DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
Vector2 LandscapeEditorDrawSystem::LandscapePointToTexturePoint(Landscape::eTextureLevel level, const Vector2& point)
{
	return TranslatePoint(point, GetLandscapeRect(), GetTextureRect(level));
}
Vector2 LandscapeEditorDrawSystem::TexturePointToHeightmapPoint(Landscape::eTextureLevel level, const Vector2& point)
{
	return TranslatePoint(point, GetTextureRect(level), GetHeightmapRect());
}
Exemple #10
0
void SRObj::GetObjToWorldMatrix(Matrix4x4 outMatrix)
{
	TranslatePoint(m_pos.x, m_pos.y, m_pos.z, outMatrix);
}