This section introduces a simplified framework that automates the basic setup required for 3DCG programs.
As we saw in the previous sections, 3DCG programs in VCSSL usually require a number of fundamental tasks: creating a window and a 3D renderer (drawing engine), setting up animation loops, handling mouse interaction, and so on.
To avoid writing these routines every time, VCSSL provides a built-in framework called Graphics3DFramework that automates all of these setup processes.
The framework itself is a fully functional program, and you can run it as-is. However, by default, it doesn't place any models, so you'll just see a blank (white) screen.
Typically, you'll import the framework into your own program and define only the parts you want to customize -- like placing models or applying transformations.
To do this, simply define specific functions with predefined names and argument formats. The framework will automatically call those functions at the appropriate time.
Here are the five functions the framework can call automatically:
The "rendererID" parameter passed to each function is the ID of a pre-created 3DCG renderer, provided automatically by the framework.
You'll use this ID when placing or manipulating models.
The onUpdate() function is typically called around 30 times per second, depending on processing load. While onPaint() is commonly used in 2DCG applications, it is rarely needed for 3DCG.
Let's use the framework to create a 3DCG animation where an axis model slowly rotates.
// Import the framework
import graphics3d.Graphics3DFramework;
import Graphics3D;
// Variable to store the axis model ID
int axis;
// 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 the axis model
axis = newAxisModel( 3.0, 3.0, 3.0, );
mountModel( axis, rendererID );
}
// Called multiple times per second (around 30 FPS)
void onUpdate( int rendererID ) {
// Slightly rotate the axis model around the Z-axis
rotModelZ( axis, 0.03 );
}
Sample.vcssl
When you run this program, a window will open displaying a coordinate axis model that continuously rotates slowly.