[ Prev | Index | Next ]
Japanese English

Moving 3D Objects

This section covers how to move models and polygons.

Moving Models

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 -

void moveModel (
  int modelID,
  float dx, float dy, float dz
)

Arguments:

  • modelID: Specifies the ID of the model to move.
  • dx, dy, dz: Specify the distance to move in the X, Y, and Z directions respectively.

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.

Moving Individual Polygons

To move a single polygon (rather than a model), use the movePolygon function.

- Function Format -

void movePolygon (
  int polygonID,
  float dx, float dy, float dz
)

Arguments:

  • Specifies the ID of the polygon to move.
  • Specify the distance to move in the X, Y, and Z directions respectively.

Example Program

Basic Example: Moving an Object Once

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.

球を移動した例の図
Execution Result
The sphere model has been moved and is visible.

Animation Example: Moving Gradually

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
[an error occurred while processing this directive]/en-us/code/archive/0002/0300-doc-3d-move-model-animation/download/MoveModel.zip[an error occurred while processing this directive] [an error occurred while processing this directive]/en-us/code/archive/0002/0300-doc-3d-move-model-animation/[an error occurred while processing this directive]

When you run this program, the white sphere will slowly move along the X-axis in an animated manner.

Execution Result
Execution Result
The sphere model gradually moves across the screen.



Sponsored Link



Japanese English
Index
[ Prev | Index | Next ]
News From RINEARN
* VCSSL is developed by RINEARN.

English Documentation for Our Software and VCSSL Is Now Nearly Complete
2025-06-30 - We're happy to announce that the large-scale expansion of our English documentation with the support of AI — a project that began two years ago — has now reached its initial target milestone.

VCSSL 3.4.52 Released: Enhanced Integration with External Programs and More
2025-05-25 - This update introduces enhancements to the external program integration features (e.g., for running C-language executables). Several other improvements and fixes are also included. Details inside.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!