This section covers how to move models and polygons.
When continuously moving a model (e.g. for animation), it is generally best to use coordinate systems, which will be discussed later.
However, if you simply want to move a model once or only a few times, you can use the moveModel function for a simpler approach.
- Function Format -
Arguments:
This function moves the model by modifying the coordinate values of all polygons that make up the model.
As a result, this method is slightly more computationally expensive than coordinate system-based movement (discussed later). It also only allows additive movement, which can be inconvenient if you need to reset the model to its original position. That said, it's convenient for one-time or infrequent movements where these limitations are not an issue.
To move a single polygon (rather than a model), use the movePolygon function.
- Function Format -
Arguments:
Let's try placing a sphere model and moving it along the Z-axis. Write and run the following code:
When you run this program, a white sphere will appear on a black background. The sphere will have been moved 2 units in the Z direction.
import graphics3d.Graphics3DFramework;
import Graphics3D;
// This function is called at the start of the program
void onStart ( int rendererID ) {
// Set window size and background color (optional)
setWindowSize( 800, 600 );
setBackgroundColor( 0, 0, 0, 255 );
// Generate and mount axis model
int axis = newAxisModel( 3.0, 3.0, 3.0 );
mountModel( axis, rendererID );
// Generate and mount sphere model
int sphere = newSphereModel( 1.0, 1.0, 1.0, 10, 7 );
mountModel( sphere, rendererID );
// Move along the Z-axis
moveModel( sphere, 0.0, 0.0, 2.0 );
}
Move.vcssl
When you run this program, a white sphere will appear on a black background. The sphere will have been moved 2 units in the Z direction.
To move a model in an animation-like fashion, incrementally move it in the onUpdate function. This function is automatically called several dozen times per second by the framework.
import graphics3d.Graphics3DFramework;
import Graphics3D;
// Variables to store model IDs
int axis, sphere;
// Called at the start of the program
void onStart ( int rendererID ) {
// Set window size and background color (optional)
setWindowSize( 800, 600 );
setBackgroundColor( 0, 0, 0, 255 );
// Generate and mount axis model
axis = newAxisModel( 3.0, 3.0, 3.0 );
mountModel( axis, rendererID );
// Generate and mount sphere model
sphere = newSphereModel( 1.0, 1.0, 1.0, 10, 7 );
mountModel( sphere, rendererID );
}
// Called several dozen times per second
void onUpdate (int renderer) {
// Move gradually along the X-axis
moveModel( sphere, 0.02, 0.0, 0.0 );
}
MoveAnimation.vcssl
When you run this program, the white sphere will slowly move along the X-axis in an animated manner.