Japanese | English | Korean

Samples


The following primitives can be rendered:

Primitive Explanation
Point A single point rendered with 1 pixel
Color can be specified, one primitive at a time
Blending method (no blending, semi-transparency, additive blending, or subtractive blending) can be selected using the attribute
Line A 1-pixel wide straight line connecting two points
Color can be specified, one primitive at a time
Blending method can be selected using the attribute
Triangular polygon A triangle polygon rendered when 3 points are specified
Polygon attributes including the following can be selected:
  • Color polygons, or texture polygons
  • Normals per vertex, or normals per primitive
  • Blending method
  • Enabling/Disabling the lighting
  • Enabling/Disabling the sphere mapping
Quadrilateral polygon A quadrangle polygon rendered when 4 points are specified
Selectable polygon attributes are same as the triangular polygon
Point sprite Specify the displaying coordinates, and it renders a quadrilateral polygon with the front side always facing the viewpoint
Blending method can be specified

Sample screenshot


1. Primitives

Let's take a look at each primitive that can be rendered in MascotCapsule V3.

1.1. Point

This primitive renders a point specified by the three-dimensional coordinates. The point to be rendered is represented by 1 pixel, regardless of the display screen setting.
The following parameters are required for rendering a point:

  • Three-dimensional coordinates that render the point (model coordinate system)
  • Color of the point
  • Attributes and data type of the point

1.2. Line

This primitive renders a line connecting the two points specified by the three-dimensional coordinates. The line width to be rendered is represented by 1 pixel, regardless of the display screen setting.
The following parameters are required for rendering a line:

  • Three-dimensional coordinates at both ends of the line (model coordinate system)
  • Color of the line
  • Attributes and data type of the line

1.3. Triangular polygon

This primitive renders a triangular polygon comprised of the three points specified by the three-dimensional coordinates. Two kinds of triangular polygons are available: a texture polygon to be applied, and a color polygon to be rendered in a specified one color.
The following parameters are required for rendering the triangular polygon:

  • Three-dimensional coordinates of the three points that comprise a triangular polygon (model coordinate system)
  • Normals of the triangular polygon
  • Texture coordinates to be applied to the triangular polygon (for a texture polygon)
  • Color of the triangular polygon (for a color polygon)
  • Attributes and data type of the triangular polygon

1.4. Quadrilateral polygon

This primitive renders a quadrilateral polygon comprised of the four points specified by the three-dimensional coordinates. Similar to triangular polygons, there are two kinds of quadrilateral polygons: a texture polygon, and a color polygon.
The following parameters are required for rendering the quadrilateral polygon:

  • Three-dimensional coordinates of the four points that comprise a quadrilateral polygon (model coordinate system)
  • Normals of the quadrilateral polygon
  • Texture coordinates to be applied to the quadrilateral polygon (for a texture polygon)
  • Color of the quadrilateral polygon (for a color polygon)
  • Attributes and data type of the quadrilateral polygon

1.5. Point sprite

This primitive renders a quadrilateral polygon, which is centered at a point represented by the three-dimensional coordinate, and always faces its front side to the viewpoint.
The following parameters are required for rendering the point sprite:

  • A three-dimensional coordinate that represents the position for displaying the point sprite (model coordinate system)
  • Texture coordinates to be applied to the point sprite
  • Size and angle of the point sprite
  • Display flag of the point sprite
  • Attributes and data type of the point sprite

Specify the following flags to determine the displaying method for the point sprite of MascotCapsule V3:

Flag Explanation
POINT_SPRITE_LOCAL_SIZE Specifies the size in model coordinate system
POINT_SPRITE_PIXEL_SIZE Specifies the size in screen coordinate system
POINT_SPRITE_PERSPECTIVE Enables the perspective in perspective projection
POINT_SPRITE_NO_PERS Disables the perspective in perspective projection

Specify the logical sum of these flags as a displaying method.
However, POINT_SPRITE_LOCAL_SIZE and POINT_SPRITE_PIXEL_SIZE, as well as POINT_SPRITE_PERSPECTIVE and POINT_SPRITE_NO_PERS are exclusive to each other.




2. Primitive rendering

Use the Graphics3D.renderPrimitives() method to perform rendering registration of multiple primitives all at once. After rendering registration, call the Graphics3D.flush() method to execute the actual rendering process. Only the same type of primitives with the same attributes can be simultaneously registered. Different types of primitives, or the same type of primitives with different attributes must be separately registered for rendering.

Example of the same primitive type, and different attributes:
       Triangular polygons that have normals per primitives, and triangular polygons that have normals per vertex, etc.

The following parameters must be specified for the Graphics3D.renderPrimitives() method:

  • Coordinates of the rendering position
  • Primitive type, attribute, and data type
  • The number of primitives
  • Vertex array for primitive rendering
  • Normal array for primitive rendering
  • Texture position array for primitive rendering
  • Color information array for primitive rendering

Even if any of these vertex array, normal array, texture position array, or color information array is not used, an arbitrary array must be specified. Also, in order to use a texture, a Texture object must be specified.

Let's take a look at each parameter.

2.1. Primitive types, attributes, and data type

In order to specify these parameters, use a bitwise OR operator and specify the logical sum of each item as follows:

Primitive type | Primitive attribute | Primitive data type

private int triangles; // Triangular polygon information

/* Triangular polygon */
triangles = Graphics3D.PRIMITVE_TRIANGLES |
   Graphics3D.PDATA_NORMAL_PER_FACE |
   Graphics3D.PDATA_COLOR_PER_FACE | Graphics3D.PATTR_LIGHTING;

If necessary, multiple attributes and data types can be defined in succession.



Use the following definition for specifying the primitive type:

Primitive Definition
Point PRIMITVE_POINTS
Line PRIMITVE_LINES
Triangular polygon PRIMITVE_TRIANGLES
Quadrilateral polygon PRIMITVE_QUADS
Point sprite PRIMITVE_POINT_SPRITES

Only one type of primitive must be defined per one rendering registration.



Use the following definition for specifying attributes:

Definition Explanation
PATTR_LIGHTING Lighting effect is enabled for the primitive
Not valid for the point, line, and point sprite
PATTR_SPHERE_MAP Sphere mapping process is enabled for the primitive
Not valid for the point, line, and point sprite
PATTR_COLORKEY Transparent process using the color key is enabled for the primitive
Not valid for the point and line
PATTR_BLEND_NORM Blending process is disabled
PATTR_BLEND_HALF Semi-transparency blending process is enabled
PATTR_BLEND_ADD Additive blending process is enabled
PATTR_BLEND_SUB Subtractive blending process is enabled

Specify the logical sum of the necessary attributes. However, some attributes are not valid for certain primitive types. For the details of lighting, sphere mapping, color key, blending effects, etc., please refer to the following MIDP + MascotCapsule V3 API samples:



Use the following definition for specifying the data type:

Definition Explanation
PDATA_NORAML_PER_FACE Contains the normal per primitive
Not valid for the point, line and point sprite
PDATA_NORMAL_PER_VERTEX Contains the normal per vertex
Not valid for the point, line and point sprite
PDATA_COLOR_PER_COMMAND Each command has the same color information
Not valid for the point sprite
For the point and line, this definition or PDATA_COLOR_PER_FACE must always be specified
PDATA_COLOR_PER_FACE Contains the color information per primitive
Not valid for the point sprite
For the point and line, this definition or PDATA_COLOR_PER_COMMAND must always be specified
PDATA_TEXURE_COORD Contains the texture position information
Not valid for the point and line
PDATA_POINT_SPRITE_PARAMS_PER_CMD All the point sprites share a common texture position information
Only valid for the point sprite
For the point sprite, this definition, or PDATA_POINT_SPRITE_PARAMS_PER_FACE, or PDATA_POINT_SPRITE_PARAMS_PER_VERTEX must always be specified
PDATA_POINT_SPRITE_PARAMS_PER_FACE Contains the point sprite's texture position information per primitive (*)
Only valid for the point sprite
For the point sprite, this definition, or PDATA_POINT_SPRITE_PARAMS_PER_CMD, or PDATA_POINT_SPRITE_PARAMS_PER_VERTEX must always be specified
PDATA_POINT_SPRITE_PARAMS_PER_VERTEX Contains the point sprite's texture position information per vertex (*)
Only valid for the point sprite
For the point sprite, this definition, or PDATA_POINT_SPRITE_PARAMS_PER_CMD, or PDATA_POINT_SPRITE_PARAMS_PER_FACE must always be specified
PDATA_NORMAL_NONE No normal information
PDATA_COLOR_NONE No color information
PDATA_TEXURE_COORD_NONE No texture position information

(*) The same effect is achieved by PDATA_POINT_SPRITE_PARAMS_PER_FACE and PDATA_POINT_SPRITE_PARAMS_PER_VERTEX processes; the only difference is how these definitions are used in the program.

Similar to attributes, specify the logical sum of necessary data types. Some data types are requirement. However, some data types are not valid for certain primitive types.

If you have specified PDATA_POINT_SPRITE_PARAMS_PER_CMD for the point sprite, you can use the same texture position information, i.e., point sprite parameters.
Similarly, if you have specified PDATA_COLOR_PER_COMMAND, you can use the same color information in this case as well.

2.2. Vertex array

In order to specify the vertex array, use the int array.
Necessary number of vertices varies depending on the primitive type; therefore, specify the necessary number as follows:

private int[] trVertex = new int[ 18 ]; // Triangular polygon vertex array

/* Vertex information */
/* Set 1 */
trVertex [ 0 ] = 0;
trVertex [ 1 ] = 256;
trVertex [ 2 ] = 0;
trVertex [ 3 ] = -128;
trVertex [ 4 ] = 0;
trVertex [ 5 ] = 0;
trVertex [ 6 ] = 128;
trVertex [ 7 ] = 0;
trVertex [ 8 ] = 0;
/* Set 2 */
trVertex [ 9 ] = 0;
trVertex [ 10 ] = -256;
trVertex [ 11 ] = 0;
trVertex [ 12 ] = -128;
trVertex [ 13 ] = 0;
trVertex [ 14 ] = 0;
trVertex [ 15 ] = 128;
trVertex [ 16 ] = 0;
trVertex [ 17 ] = 0;
Primitive Necessary number of vertices
Point Number of primitives ×1
Line Number of primitives ×2
Triangular polygon Number of primitives ×3
Quadrilateral polygon Number of primitives ×4
Point sprite Number of primitives ×1

Each vertex is comprised of the three elements ( x, y, z ); therefore, the actual size of the array is the number of vertices x3 (multiplied by 3). The three elements of vertex are stored in the order of x, y, and z.

2.3. Normal array

In order to specify the normal array, use the int array. Necessary number of normals varies depending on the primitive type and data type; therefore, specify the necessary number as follows:

private int [] trNormal = new int [ 6 ] ; // Triangular polygon normal array

/* Normal information */
/* Set 1 */
trNormal [ 0 ] = 0;
trNormal [ 1 ] = 0;
trNormal [ 2 ] = 4096;
/* Set 2 */
trNormal [ 3 ] = 0;
trNormal [ 4 ] = 0;
trNormal [ 5 ] = 4096;
Primitive Data type Necessary number of normals
Point - - - 0
Line - - - 0
Triangular polygon PDATA_NORMAL_NONE 0
PDATA_NORMAL_PER_FACE Number of primitives ×1
PDATA_NORMAL_PER_VERTEX Number of primitives ×3
Quadrilateral polygon PDATA_NORMAL_NONE 0
PDATA_NORMAL_PER_FACE Number of primitives ×1
PDATA_NORMAL_PER_VERTEX Number of primitives ×4
Point sprite - - - 0

Each normal is comprised of the three elements ( x, y, z ); therefore, the actual size of the array is the number of normals x3 (multiplied by 3). The three elements of normal are stored in the order of x, y, and z.
Normals must be normalized. Normalization in MascotCapsule means that the length is 4096.

2.4. Texture position array

In order to specify the texture position array, use the int array. Necessary number of texture position information varies depending on the primitive type and data type; therefore, specify the necessary number as follows:

private int [] qdTexCoord = new int [ 8 ] ; // Quadrilateral polygon texture position array

/* Texture position information */
qdTexCoord [ 0 ] = 255;
qdTexCoord [ 1 ] = 255;
qdTexCoord [ 2 ] = 0;
qdTexCoord [ 3 ] = 255;
qdTexCoord [ 4 ] = 0;
qdTexCoord [ 5 ] = 0;
qdTexCoord [ 6 ] = 255;
qdTexCoord [ 7 ] = 0;
Primitive Data type Necessary number of texture position information
Point - - - 0
Line - - - 0
Triangular polygon PDATA_COLOR_PER_FACE or PDATA_COLOR_PER_COMMAND 0
PDATA_TEXURE_COORD Number of primitives ×3
Quadrilateral polygon PDATA_COLOR_PER_FACE or PDATA_COLOR_PER_COMMAND 0
PDATA_TEXURE_COORD Number of primitives ×4
Point sprite PDATA_POINT_SPRITE_PARAMS_PER_CMD 1 (*)
PDATA_POINT_SPRITE_PARAMS_PER_FACE Number of primitives ×1 (*)
PDATA_POINT_SPRITE_PARAMS_PER_VERTEX Number of vertices ×1 (*)

Vertex information of the triangular polygon and quadrilateral polygon is represented by the two-dimensional coordinates ( x, y ) on the texture; therefore, the actual array size is the number of texture position information x2 (multiplied by 2). Also, the triangular polygon and quadrilateral polygon's coordinates specified by the vertex information, and the coordinates specified by the texture position information are associated according to these coordinates' specified order.


(*) If you are using a point sprite, parameters for point sprite are also contained here. Necessary parameters for the point sprite are as follows:

  • Width of the point sprite
  • Height of the point sprite
  • Angle of the point sprite (360 degrees = 4096)
  • Texture position information ( x, y ) that is equivalent to the upper-left of the point sprite
  • Texture position information ( x, y ) that is equivalent to the lower-right of the point sprite
  • Display flag of the point sprite

The size of this parameter array is the number of primitives x8 (multiplied by 8).

2.5. Color information array

In order to specify the color information array, use the int array. Necessary number of color information varies depending on the primitive type and data type; therefore, specify the necessary number as follows:

private int [] trColor = new int [ 2 ] ; // Triangular polygon color information array

/* Color information */
/* Set 1 */
trColor[ 0 ] = ( ( 255 << 16 ) | ( 0 << 8 ) | ( 0 ) );
/* Set 2 */
trColor[ 1 ] = ( ( 0 << 16 ) | ( 255 << 8 ) | ( 0 ) );
Primitive Data type Necessary number of color information
Point PDATA_COLOR_PER_COMMAND 1
PDATA_COLOR_PER_FACE Number of primitives ×1
Line PDATA_COLOR_PER_COMMAND 1
PDATA_COLOR_PER_FACE Number of primitives ×1
Triangular polygon PDATA_COLOR_NONE 0
PDATA_COLOR_PER_COMMAND 1
PDATA_COLOR_PER_FACE Number of primitives ×1
Quadrilateral polygon PDATA_COLOR_NONE 0
PDATA_COLOR_PER_COMMAND 2
PDATA_COLOR_PER_FACE Number of primitives ×1
Point sprite - - - 0

The color information is RGB, and must be specified in 24-bit format, where each element is 8 bit. Always use this format regardless of the pixel information in the actual environment.

( R element << 16 ) | ( G << 8 ) | ( B )

As a result, the actual array size is the number of necessary color information x1.




3. Primitive rendering sample code

Let's take a look at the portion of the sample code that renders primitives. As an example, let's look at how to render triangular polygons as described in “1. Primitives” and “2. Primitive rendering”.

/* Triangular polygon */
private int triangles;                               // Triangular polygon information
private int [] trVertex = new int [ 18 ] ;     // Triangular polygon vertex array
private int [] trNormal = new int [ 6 ] ;      // Triangular polygon normal array
private int [] trColor = new int [ 2 ] ;        // Triangular polygon color information array
private int [] trTexCoord = new int [ 1 ] ;  // Triangular polygon texture position array
/* Triangular polygon */
triangles = Graphics3D.PRIMITVE_TRIANGLES |
Graphics3D.PDATA_NORMAL_PER_FACE |
Graphics3D.PDATA_COLOR_PER_FACE | Graphics3D.PATTR_LIGHTING;

/* Vertex information */
/* Set 1 */
trVertex [ 0 ] = 0;
trVertex [ 1 ] = 256;
trVertex [ 2 ] = 0;
trVertex [ 3 ] = -128;
trVertex [ 4 ] = 0;
trVertex [ 5 ] = 0;
trVertex [ 6 ] = 128;
trVertex [ 7 ] = 0;
trVertex [ 8 ] = 0;
/* Set 2 */
trVertex [ 9 ] = 0;
trVertex [ 10 ] = -256;
trVertex [ 11 ] = 0;
trVertex [ 12 ] = -128;
trVertex [ 13 ] = 0;
trVertex [ 14 ] = 0;
trVertex [ 15 ] = 128;
trVertex [ 16 ] = 0;
trVertex [ 17 ] = 0;

/* Normal information */
/* Set 1 */
trNormal [ 0 ] = 0;
trNormal [ 1 ] = 0;
trNormal [ 2 ] = 4096;
/* Set 2 */
trNormal [ 3 ] = 0;
trNormal [ 4 ] = 0;
trNormal [ 5 ] = 4096;

/* Color information */
/* Set 1 */
trColor [ 0 ] = ( ( 255 << 16 ) | ( 0 << 8 ) | ( 0 ) );
/* Set 2 */
trColor [ 1 ] = ( ( 0 << 16 ) | ( 255 << 8 ) | ( 0 ) );

/* Texture position information
  * The following is equivalent to null
  */
trTexCoord [ 0 ] = 0;

Perform the rendering registration to the Graphics class, and execute rendering.

/* Transformation matrix */
trans.multiply( xTrans, yTrans );
trans.multiply( vTrans, trans );

/* Coordinate transformation-related setting */
layout.setAffineTrans( trans );

/* Rendering */
g3d.renderPrimitives( null, 0, 0, layout, effect,
triangles, 2, trVertex, trNormal, trTexCoord, trColor );
g3d.flush();

Similarly, specify the setting for other primitives.

Line

/* Line */
private int lines;                                        // Line information
private int [] lnVertex = new int [ 6 ] ;          // Line vertex array
private int [] lnNormal = new int [ 1 ] ;          // Line normal array
private int [] lnColor = new int [ 1 ] ;            // Line color information array
private int [] lnTexCoord = new int [ 1 ] ;      // Line texture position array

/* Line */
lines = Graphics3D.PRIMITVE_LINES |
Graphics3D.PDATA_COLOR_PER_FACE |
Graphics3D.PATTR_LIGHTING;
/* Vertex information */
lnVertex [ 0 ] = 428;
lnVertex [ 1 ] = 256;
lnVertex [ 2 ] = 0;
lnVertex [ 3 ] = 428;
lnVertex [ 4 ] = -256;
lnVertex [ 5 ] = 0;

/* Normal information
  * The following is equivalent to null
  */
lnNormal [ 0 ] = 0;

/* Color information */
lnColor [ 0 ] = ( ( 255 << 16 ) | ( 0 << 8 ) | ( 0 ) );

/* Texture position information
  * The following is equivalent to null
  */
lnTexCoord [ 0 ] = 0;

g3d.renderPrimitives( null, 0, 0, layout, effect,
lines, 1, lnVertex, lnNormal, lnTexCoord, lnColor );
g3d.flush();

Point sprite

private Texture texture; // Image data for the primitive

/* Point sprite */
private int pointSprites;                             // Point sprite information
private int [] psVertex = new int [ 3 ];          // Point sprite vertex array
private int [] psNormal = new int [ 1 ];         // Point sprite normal array
private int [] psColor = new int [ 1 ];           // Point sprite color information array
private int [] psTexCoord = new int [ 8 ];     // Point sprite texture position array

try{
texture = new Texture( "/texture.bmp", true );
} catch( IOException e ) {
e.printStackTrace();
}

/* Point sprite */
pointSprites = Graphics3D.PRIMITVE_POINT_SPRITES |
Graphics3D.PDATA_POINT_SPRITE_PARAMS_PER_FACE |
Graphics3D.PDATA_TEXURE_COORD | Graphics3D.PATTR_LIGHTING;

/* Vertex information */
psVertex [ 0 ] = -428;
psVertex [ 1 ] = 128;
psVertex [ 2 ] = 0;

/* Normal information
  * The following is equivalent to null
  */
psNormal [ 0 ] = 0;

/* Color information
  * The following is equivalent to null
  */
psColor [ 0 ] = 0;

/* Texture position information */
psTexCoord [ 0 ] = 256;
psTexCoord [ 1 ] = 256;
psTexCoord [ 2 ] = 0;
psTexCoord [ 3 ] = 0;
psTexCoord [ 4 ] = 0;
psTexCoord [ 5 ] = 255;
psTexCoord [ 6 ] = 255;
psTexCoord [ 7 ] = Graphics3D.POINT_SPRITE_LOCAL_SIZE | Graphics3D.POINT_SPRITE_PERSPECTIVE;

g3d.renderPrimitives( texture, 0, 0, layout, effect,
pointSprites, 1, psVertex, psNormal, psTexCoord, psColor );

g3d.flush();

Quadrilateral polygon (* Texture data is shared with the point sprite)

/* Quadrilateral polygon */
private int quads;                                     // Quadrilateral polygon information
private int [] qdVertex = new int [ 12 ];       // Quadrilateral polygon vertex array
private int [] qdNormal = new int [ 3 ];        // Quadrilateral polygon normal array
private int [] qdColor = new int [ 1 ];          // Quadrilateral polygon color information array
private int [] qdTexCoord = new int [ 8 ];    // Quadrilateral polygon texture position array

/* Quadrilateral polygon */
quads = Graphics3D.PRIMITVE_QUADS |
Graphics3D.PDATA_COLOR_NONE | Graphics3D.PDATA_NORMAL_PER_FACE |
Graphics3D.PDATA_TEXURE_COORD | Graphics3D.PATTR_LIGHTING;

/* Vertex information */
qdVertex [ 0 ] = -300;
qdVertex [ 1 ] = 0;
qdVertex [ 2 ] = 0;
qdVertex [ 3 ] = -556;
qdVertex [ 4 ] = 0;
qdVertex [ 5 ] = 0;
qdVertex [ 6 ] = -556;
qdVertex [ 7 ] = -256;
qdVertex [ 8 ] = 0;
qdVertex [ 9 ] = -300;
qdVertex [ 10 ] = -256;
qdVertex [ 11 ] = 0;

/* Normal information */
qdNormal [ 0 ] = 0;
qdNormal [ 1 ] = 0;
qdNormal [ 2 ] = 4096;

/* Color information array
  * The following is equivalent to null
  */
qdColor [ 0 ] = 0;

/* Texture position array */
qdTexCoord [ 0 ] = 255;
qdTexCoord [ 1 ] = 255;
qdTexCoord [ 2 ] = 0;
qdTexCoord [ 3 ] = 255;
qdTexCoord [ 4 ] = 0;
qdTexCoord [ 5 ] = 0;
qdTexCoord [ 6 ] = 255;
qdTexCoord [ 7 ] = 0;

g3d.renderPrimitives( texture, 0, 0, layout, effect,
quads, 1, qdVertex, qdNormal, qdTexCoord, qdColor );

g3d.flush();

Sample screenshots (Settings for normals and the back side display)


Enabled normals: front side (left), back side (right)


Disabled normals: front side (left), back side (right)