Mouse Control and Animation
Since 3D graphics involve working with solid objects, the image you see changes depending on the viewing angle (camera angle).
It's very useful to be able to adjust the viewpoint using mouse controls. This section explains how to implement such functionality.
Sponsored Link
Event Handlers
We won't go into full detail here, but when a user performs actions -- like mouse operations -- on a GUI component, a special function called an event handler is automatically called by the system. For more details, please refer to the GUI Library Guide.

For example, if you want to change the camera angle based on mouse input, you'll need to set up a mouse event handler.
There are two approaches:
- Use a built-in default event handler (simpler, one line of code)
- Write a custom event handler (more flexible and fully customizable)
In this guide, we'll use the first approach -- the built-in handler.
- Function Format -
int rendererID, int componentID
)
Arguments:
- rendererID: The ID of the 3D renderer.
- componentID: The ID of the GUI component that displays the graphics (e.g., a graphics label). When mouse actions are performed on this component, the camera angle will automatically update in response.
Animation
Infinite Loop
To perform animation, your program must keep redrawing the screen continuously from the moment it starts until it ends. In other words, you need a control flow that resembles an infinite loop.

bool mainLoopState = true; // Set to false when you want to exit the animation
while( mainLoopState ){
/* This is the main animation loop: write rendering logic here */
}
Loop.vcssl
Exiting the Loop When the Window Is Closed
If you use an infinite loop like the one above, you need to make sure the program can automatically exit when the window is closed. Otherwise, especially in cases where the VCSSL console is hidden or not available, there would be no way to stop the program -- it would keep animating forever.
To handle this, define an event handler named "onWindowClose", which will be called automatically when the window is closed:
- Function Format -
The "componentID" parameter receives the ID of the GUI component (the window) that was closed.
When you define this function, the system will call it automatically when the window is closed.
Example Program
Now let's write an actual animation program.
To make camera movement easier to understand, we'll add an axis model to the scene. We'll cover model generation and placement in detail in the next section, but for now, just copy and run the following:
import Graphics;
import Graphics3D;
import GUI;
// Create graphics resource and 3D renderer
int graphicsID = newGraphics( );
int rendererID = newGraphics3DRenderer( 800, 600, graphicsID );
// Create display window
int windowID = newWindow( 0, 0, 800, 600, " Hello 3DCG ! " );
int labelID = newImageLabel( 0, 0, 800, 600, graphicsID );
mountComponent( labelID, windowID );
// Enable mouse-based camera control
setGraphics3DDefaultEventHandler( rendererID, labelID );
// Set background color to black
setGraphics3DColor( rendererID, 0, 0, 0, 255 );
// Generate and place the axis model
int axis = newAxisModel( 3.0, 3.0, 3.0 );
mountModel( axis, rendererID );
// Animation loop
bool mainLoopState = true;
while( mainLoopState ) {
sleep( 30 ); // Wait for 30 milliseconds
paintGraphics3D( rendererID ); // Render 3DCG
paintComponent( labelID ); // Refresh GUI
paintComponent( windowID ); // Refresh GUI
}
exit(); // Exit program after breaking the loop
// Called when the window is closed
void onWindowClose( int id ) {
mainLoopState = false; // Exit the loop
}
Sample.vcssl
When you run this program, a window will appear showing a coordinate axis model against a black background.
- Left mouse drag rotates the viewpoint.
- Right mouse drag pans the view.
- Mouse wheel zooms in and out.

- 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