This section explains how to perform screen projection of vectors. Screen projection allows you to obtain the X and Y coordinates (i.e., window coordinates) on the graphics display that correspond to arbitrary positions in 3D space.
If you want to find out where a point in 3D space appears on the screen, you can use screen projection. By applying screen projection to a vector placed in 3D space, you can obtain the corresponding X and Y coordinates in the rendering area -- these are known as window coordinates.
One important point to note is the position of the origin in the rendering area.
In many fields outside of 3DCG, the top-left corner of the screen is treated as the origin. However, in certain 3DCG contexts that use right-handed coordinate systems, the bottom-left corner is often used instead, due to various technical conventions (though the top-left origin is still used in some cases).
VCSSL Graphics3D adopts a right-handed coordinate system, so the origin of the rendering area is considered to be at the bottom-left.
As a result:
Keep this difference in mind when combining these systems.
To perform screen projection and obtain the X and Y screen coordinates of a vector, use the projectVectorX(...) and projectVectorY(...) functions, respectively.
- Function Format -
Arguments:
Let's get the screen coordinates corresponding to the origin of the world coordinate system. Try writing and running the following code:
import graphics3d.Graphics3DFramework ;
import Graphics3D ;
// Function called at the start of the program
void onStart ( int rendererID ) {
// Create a vector at the origin
int vector = newVector( 0.0, 0.0, 0.0 ) ;
// Place the vector in the world coordinate system
mountVector( vector, rendererID ) ;
// Project the vector onto the screen
int x = projectVectorX( vector, rendererID );
int y = projectVectorY( vector, rendererID );
// Output the result
println( "X=" + x + ", " + "Y=" + y ) ;
}
Sample.vcssl
When you run this program, the VCSSL console will display something like:
This indicates the coordinates near the center of the rendering area.
(The exact values may vary depending on your environment or software version.)
Note: In the Graphics3DFramework, the component ID of the GUI element representing the rendering area can be obtained using the getImageLabel() function.