PROGRAMMER'S GUIDEVDP1 library
BackForward
VDP1 library

3.VDP1 3D guide


3.1 Purpose

The purpose is to display 3D sprites using the VDP1 extension processing library.
The features are shown below.

3.2 3D coordinate system and display model

[Coordinate system]

The distance from the viewpoint to the screen is fixed at 1.0.

[Display model]
The display model is an object that is a collection of polygons connected to a hierarchical structure as a cluster as shown below. The clusters are in a parent-child relationship, and the position of the objects in the child cluster is placed in the body coordinate system of the parent cluster. Therefore, when the parent cluster moves, all child clusters connected below move.

┏━━━━━━━┓ ┏━━━━━━━┓ 
┃Object 0 ┃┃Object 1┃ 
┗━━━━━━━┛ ┗━━━━━━━┛ 
:: 
: ┌───────┐ 
: ┌─┤ Cluster 10│ 
: │ └───────┘ 
: │ 
┌───────┐ │ ┌───────┐ 
│ Cluster 00 ├─┼─┤ Cluster 11 │ 
└───────┘ │ └───────┘ ┌───────┐
Root cluster │ ┌─┤ cluster 20 │
│ ┌───────┐ │ └───────┘
└─┤ Cluster 12 ├─┤ 
└───────┘ │ ┌───────┐
└─┤ Cluster 21 │
└───────┘

3.3 Program description example

An example of an actual program in C language is shown below.

#include <machine.h>
#define _SPR3_ / * Using sprite 3D display library * /
#define SPR_3USE_DOUBLE_BUF / * Double buffer specification * /
#include "sega_spr.h"
#include "sega_scl.h"
#include "sega_int.h"

SprCluster model0;
SprCluster model1;

#define COMMAND_MAX 1000 / * Maximum number of commands * /
#define GOUR_TBL_MAX 1000 / * Maximum number of gouro tables * /
#define LOOKUP_TBL_MAX 1000 / * Maximum number of lookup tables * /
#define CHAR_MAX 100 / * Maximum number of characters * /
#define DRAW_PRTY_MAX 256 / * Maximum number of drawing priority blocks * /
SPR_2DefineWork (work2d, COMMAND_MAX, GOUR_TBL_MAX,
                                 LOOKUP_TBL_MAX, CHAR_MAX, DRAW_PRTY_MAX)
                                       / * 2D work area definition * /
#define OBJ_SURF_MAX 16 / * Maximum number of faces in object * /
#define OBJ_VERT_MAX 16 / * Maximum number of vertices in object * /
SPR_3DefineWork (work3d, OBJ_SURF_MAX, OBJ_VERT_MAX)
                                       / * 3D display work area definition * /

extern void vbStart (void); / * V-BLANK IN interrupt routine * /
extern void vbEnd (void); / * V-BLANK OUT interrupt routine * / 
main ()
{
     set_imask (0); / * Enable interrupts * /

     SCL_Vdp2Init (); / * Scroll and priority initialization * /
     SCL_SetPriority (SCL_SP0 | SCL_SP1 | SCL_SP2 | SCL_SP3 | SCL_SP4 |
                              SCL_SP5 | SCL_SP6 | SCL_SP7,7);
     SCL_SetSpriteMode (SCL_TYPE1, SCL_MIX, SCL_SP_WINDOW);

     SPR_2Initial (& work2d); / * Initialize 2D sprite display * /

     SPR_3Initial (& work3d); / * Initialize 3D sprite display * /

     INT_ChgMsk (INT_MSK_NULL, INT_MSK_VBL_IN | INT_MSK_VBL_OUT);
                                       / * Disable V-BLANK interrupts * /
     INT_SetFunc (INT_SCU_VBLK_IN, & vbStart);
                                       / * Registration of V-BLANK IN interrupt routine * /
     INT_SetFunc (INT_SCU_VBLK_OUT, & vbEnd);
                                       / * Registration of V-BLANK OUT interrupt routine * /
     INT_ChgMsk (INT_MSK_VBL_IN | INT_MSK_VBL_OUT, INT_MSK_NULL);
                                       / * Enable V-BLANK interrupt * /

     SPR_2FrameChgIntr (0xffff); / * Indefinite frame change interval * /
                                       / * Set to mode * /

     SPR_3SetTexture (texture); / * Set texture data for 3D * /

     for (;;) {
           --------------- / * Scroll dataset * /

          SPR_3SetLight (...); / * Set 3D light source * /
          SPR_3SetView (...); / * Set 3D viewpoint * /

          SPR_2OpenCommand (SPR_2DRAW_PRTY_ON); 
                                       / * Open sprite command write * /
          SPR_2SysClip (SPR_2MOST_FAR, & xy);
                                       / * System clip area command * /
          SPR_2LocalCoord (SPR_2MOST_FAR, & xy); 
                                       / * Local coordinate command * /

          SPR_3moveCluster (model0, ...); / * Move the root cluster of 3D model 0 * /
          SPR_3DrawModel (model0, ...); / * Register 3D model 0 * /

          SPR_3moveCluster (model1, ...); / * Move the root cluster of 3D model 1 * /
          SPR_3DrawModel (model1, ...); / * Registration of 3D model 1 * /
                            ..
                            ..
                            ..
          SPR_3Flush (); / * 3D sprite command set * /
          SPR_2CloseCommand (); / * Close sprite command write * /
          SCL_DisplayFrame (); / * Wait for V-BLANK interrupt, * /
                                       / * Sprite display and scrolling * /
      }
}

−V Blank processing routine (source file different from the above main) −

#include <machine.h>
#include "sega_spr.h"
#include "sega_scl.h"

#pragma interrupt (VbStart)
#pragma interrupt (VbEnd)

void VbStart (void)
{
     SCL_VblankStart (); / * V blank start VDP interrupt processing * /
     -------- / * Other V blank start processing * /
 }

void VbEnd (void)
{
     SCL_VblankEnd (); / * V blank end VDP interrupt processing * /
      -------- / * Other V blank end processing * /
}

Since the Z sort of polygons in the viewpoint coordinate system of the sprite 3D display library is performed using the sprite command priority drawing function of the VDP1 extension processing library (2D library), the priority drawing is turned on in the SPR_2OpenCommand () routine to perform the Z sort of polygons. Must be (SPR_2DRAW_PRTY_ON).

3.4 Object-to-object connection Polygon object

If you want to transform Object2 according to the movement of Object1 and display it as shown in the figure below, you can automatically transform and draw by defining Object2, which is a polygon between Object0 and Object1, as an inter-object connection polygon object.

Cluster, object, connection between objects Each table of polygon information is connected as follows.

Child 
┌──────────────────┐ ┌──────────────────┐
│ Cruster0 │ → │ Cruster1 │
└──────────────────┘└──────────────────┘
::::: 
↓ ↓ ↓ ↓ 
┌─────────┐┌───────┐┌─────────┐┌───────┐
│ InbetInf0 │ │ Object0 │ │InbetInf1 │ │ Object1 │
└─────────┘└───────┘└─────────┘└───────┘
: 
↓ 
┌───────┐
│ Object2 │
└───────┘

[Processing polygon objects connected between objects]

  1. The drawing order of the objects is from the parent cluster to the child cluster, and if multiple objects are connected to the cluster, they are drawn in the connection order.
    In the above example, Object0, Object1, and Object2 are drawn in this order.

  2. When drawing, if the inter-object connection polygon information is connected to the cluster, the coordinate-converted vertex data to the viewpoint coordinate system is set in the vertex data table of the corresponding inter-object connection polygon object according to the specified table.
    With Gouraud shading, set the calculated vertex brightness in the vertex normal data table of the inter-object connection polygon object.
    In the above example, InbetInf0 sets the viewpoint coordinate system vertex data (0,1,2,3) of Object0 to the vertex data of Object2 (4,5,6,7), and InbetInf1 sets the viewpoint coordinate system vertex data of Object1 (4,5,6,7). Set 4,5,6,7) to the vertex data (0,1,2,3) of Object2.

  3. If the drawing object is an inter-object connection polygon object, the normal vector of each face is obtained from the converted vertices to the viewpoint coordinate system, and the drawing is performed according to the drawing mode.
    In the above example, Object2 is an inter-object connecting polygon object.

  4. Setting conditions for connecting polygon objects between objects

    • If you want to connect to the cluster as one of multiple objects, connect at the end of the object chain.

    • Set the calculation correction value of the surface normal vector in the object table as a negative value.


BackForward
PROGRAMMER'S GUIDEVDP1 library
Copyright SEGA ENTERPRISES, LTD., 1997