Screen Projection
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.
Screen Projection
Screen Projection of a Vector
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.
Origin Is at the Bottom-Left
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:
- In VCSSL GUI and VCSSL Graphics2D, the origin is at the top-left.
- In VCSSL Graphics3D, the origin is at the bottom-left.
Keep this difference in mind when combining these systems.
Projecting a Vector onto the Screen
To perform screen projection and obtain the X and Y screen coordinates of a vector, use the projectVectorX(...) and projectVectorY(...) functions, respectively.
- Function Format -
int projectVectorY ( int vectorID, int rendererID )
Arguments:
- vectorID: The ID of the vector to project.
- rendererID: The ID of the renderer.
Example Program
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.
- 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