RotateBy

MGraphic3D::RotateBy rotates the graphic counterclockwise around an axis or a ray by the specified angle.

Axis rotation

This argument list takes an angle in degrees and an axis. The graphic rotates counterclockwise around the axis at the specified angle. Figure 146 shows a 30 degree rotation around the x axis.

    virtual void MGraphic3D::RotateBy( GDegrees angle, TGrafMatrix3D::EAxis axis );
angle: The amount of the rotation in degrees. When you look from the positive axis towards the 3D origin, a 90 degree counterclockwise rotation transforms one positive axis into the other.

axis: The x, y, or z axis around which the rotation occurs. TGrafMatrix3D has the following enumeration values that you supply for this parameter: kAboutXAxis, kAboutYAxis, kAboutZAxis.


The following code fragment draws a rounded box sweep (shown on the left in Figure 146), and then translates it 250 world-coordinate units in the x direction and rotates it 30 degrees (shown on the right in Figure 146). The rounded box sweep is 200 world-coordinate units deep and high, with a round radius of 20. The round radius is used to calculate the rounded corners of the box sweep. The origin is in the center of the rounded box sweep, and the camera position is TGPoint3D(1440, 0, 1440).

      TRoundedBox3D box( 200, 200, 20 );
      box.Draw( thePort );
      
      box.TranslateBy( TGPoint3D( 250, 0, 0 ) );
      box.RotateBy( 30, TGrafMatrix3D = kAboutXAxis );
      box.Draw( port );

Ray rotation

This argument list takes an angle and a vector to generate the rotational components for the matrix. Figure 147
shows a 30 degree rotation around a ray.

    virtual void MGraphic3D::RotateBy( GDegrees angle, const TGLine3D& ray );
angle: The amount of the rotation in degrees. When you look from the positive axis towards the 3D origin, a 90 degree counterclockwise rotation transforms one positive axis into the other.

ray: An arbitrary vector around which the rotation occurs. The direction of the vector determines the orientation of the rotation, which is counter-clockwise around the vector. The endpoint of TGLine3D determines the direction of the ray.


The following code fragment translates the rounded box sweep by 250 worldcoordinate units in the x direction, and rotates it 30 degrees around a ray.

      box.TranslateBy( TGPoint3D( 250, 0, 0 ) );
      TGLine3D ray( TGPoint3D( 1, 0, 0 ), TGPoint3D( 150, 150, 0 ) );
      box.RotateBy( 30, ray );
      box.Draw( port );

ScaleBy

MGraphic3D::ScaleBy changes the size of a graphic by multiplying the graphics's coordinates by a constant value. It scales the graphic about the centerOfScale by factor.

      virtual void MGraphic3D::ScaleBy(   const TGPoint3D& factor, 
                                          const TGPoint3D& centerOfScale );
factor: Factor determines the amount of scaling in the x, y, and z directions for uniform and non-uniform scaling. Uniform scaling is when the x, y, and z values are the same. Non-uniform scaling is when the x, y, and z values are different.

centerOfScale: The center of scale determines the point around which the graphic is scaled. A center of scale other than the center of the graphic can scale the graphic beyond the visible area of the view.

Figure 148 shows uses three different centers of scale on the rounded box sweep. From left to right, the centers of scale are the center of the graphic, the origin, and a point.


Center of graphic

      box.ScaleBy( TGPoint3D( .5, .5, .5 ), box.GetGeometricBounds().GetCenter() );
      box.Draw( port );

Origin of View

      box.ScaleBy( TGPoint3D( .5, .5, .5 ), TGPoint3D::kOrigin );
      box.Draw( port );

TGPoint3D( )

      box.ScaleBy( TGPoint3D( .5, .5, .5 ), TGPoint3D( 0, 200, 0 ) );
      box.Draw( port );

Negative scale factor

The effect of negative scale factors is the same as
mirroring. Scaling by 1.0 in the x direction is like mirroring about the yz plane. A negative scale factor in the y direction is like mirroring about the xz plane. A negative scale factor in the z direction is like mirroring about the xy plane.

Figure 149 shows the original rounded box sweep on the left and the same rounded box sweep translated by 350 world-coordinate units in the x direction, and scaled by the factor (1.0, 1.0, 1.0) with the origin as the a center of scale.


      box.ScaleBy( TGPoint3D( -1, -1, -1 ), TGPoint3D::kOrigin );
      box.Draw( port );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker