Scaling 3D Objects
This section covers how to scale (enlarge or shrink) models and polygons.
Scaling a Model
To scale a model, use the scaleModel(...) function.
- Function Format -
int modelID,
float sx, float sy, float sz
)
Arguments:
- modelID: Specifies the ID of the model to be scaled.
- sx, sy, sz: Specify the scale factors for the X, Y, and Z directions respectively. A value greater than 1.0 enlarges the model, while a value less than 1.0 shrinks it. To keep the original size in a direction, use 1.0.
Scaling a Polygon
To scale a polygon, use the scalePolygon(...) function.
- Function Format -
int polygonID,
float sx, float sy, float sz
)
Arguments:
- polygonID: Specifies the ID of the polygon to be scaled.
- sx, sy, sz: Specify the scale factors for the X, Y, and Z directions respectively. A value greater than 1.0 enlarges the polygon, while a value less than 1.0 shrinks it. To keep the original size in a direction, use 1.0.
Example Program
Let's place a sphere model and stretch it by a factor of 2 along the Z-axis. Write and run the following code:
import graphics3d.Graphics3DFramework;
import Graphics3D;
// Function called at the start of the program
void onStart ( int rendererID ) {
// Optional: Set window size and background color
setWindowSize( 800, 600 );
setBackgroundColor( 0, 0, 0, 255 );
// Create and place an axis model
int axis = newAxisModel( 3.0, 3.0, 3.0 );
mountModel( axis, rendererID );
// Create and place a sphere model
int sphere = newSphereModel( 1.0, 1.0, 1.0, 10, 7 );
mountModel( sphere, rendererID );
// Stretch the sphere 2x in the Z direction
scaleModel( sphere, 1.0, 1.0, 2.0 );
}
Sample.vcssl
When you run this program, a white sphere will appear on a black background. The sphere is stretched 2x in the Z direction.

- 3D Computer Graphics
- Setting Up the Foundation
- Mouse Control and Animation
- Using the Framework
- Creating and Placing Light Sources (and Adjusting Their Properties)
- Creating and Placing Models / Standard Models
- Creating and Placing Polygons, and Various Types of Polygons
- Moving 3D Objects
- Rotating 3D Objects
- Scaling 3D Objects
- Flipping 3D Objects
- Setting Colors for 3D Objects
- Configuring the Shape of 3D Objects
- Fill Settings for 3D Objects
- Material Settings for 3D Objects
- Understanding Coordinate Systems: Concepts, Creation, and Placement
- Moving Coordinate Systems
- Walking Coordinate Systems
- Controlling the Origin Position of a Coordinate System
- Rotating Coordinate Systems
- Spinning a Coordinate System
- Euler Angle-Based Attitude Control of Coordinate Systems
- Camera Work
- Creating, Placing, and Performing Basic Operations on Vectors
- Coordinate Transformations
- Screen Projection
- Collision Detection