Introduction
Graphics Library Structure
mgk |
|||
mgi |
|||
mhc |
|||
mif |
mrn |
||
mis |
|||
mso |
mvm |
nusys |
Objects in the mgk Library
Primary functions and macros
Usage Examples
mainproc should be executed as follows.
Since the default allocator is used when allocating memory, it must be initialized first before anything else.
static MsoHeapAllocator heap_allocator; void *heap_ptr; heap_ptr = _codeSegmentEnd; msoHeapAllocatorInit( &heap_allocator, heap_ptr, 0x80380000 - ( u32 )heap_ptr ); msoSetDefaultAllocator( _msoUpCast( MsoAllocator, &heap_allocator ) ); |
The heap area is managed by MsoHeapAllocator.
MsoHeapAllocator is initialized by msoHeamAllocatorInit and set in the default allocator by msoSetDefaultAllocator.
In the above example, the memory area from immediately after codeSegment to 0x80380000 is reserved as the heap area.
#define MAX_OBJS (4) MgkObj gObjArray[ MAX_OBJS ]; mgkAppInit( 2, 32768, 65536, 256, 16384, MAX_OBJS, gObjArray, NULL ); mgkAppInitGroups( ); |
The application is initialized by mgkAppInit.
The subsequent mgkAppInitGroups initializes MrnGroup.
Initialization of MrnGroup has historically been rather complicated, but this is the simplest initialization method.
In this example, the following settings are made.
mgkObjLoad( &gObjArray[ 0 ], ( u32 )_stageSegmentRomStart, ( u32 )_stageSegmentRomEnd ); mgkObjLoad( &gObjArray[ 1 ], ( u32 )_animalSegmentRomStart, ( u32 )_animalSegmentRomEnd ); |
Use mgkObjLoad to load the NVF to the object.
In the above example, the NVF in _stageSegment is loaded to gObjArray[0], and the NVF in
_animalSegment is loaded to gObjArray[1].
mgkObjCreateCamera( &gObjArray[ 2 ], 45.0f, 1.333333333f, 5.0f, 2000.0 ); |
The camera itself takes up one object.
mgkObjCreateCamera turns an object into a camera object.
Camera control is possible by using mgjObjLookAt, etc. on a camera object.
The following settings are made in this example.
The method for independently constructing the main loop is introduced here.
while ( 1 ) { ++gMgiApp.frame_count; nuContDataGetExAll( gMgiApp.cont_data ); _mgkAppBeginFrame( ); /* Object movement */ mgkObjMove( &gObjArray[ 1 ], x, y, z ); /* Face camera in direction of object */ mgkObjLookAt( &gObjArray[ 2 ], 0.0f, 0.0f, 1000.0f, /* Camera coordinates */ x, y, z, /* POV coordinates */ 0.0f, 1.0f, 0.0f ); /* Upward vector */ mgkAppEvalAll( ); mgkAppDraw( ); _mgkAppEndFrame( ); } |
The main loop must be processed in the following order.
There are no retrace stand-by's anywhere in this code, but since _mgkAppEndFrame is called in synchronization with the scheduler, processing proceeds as a whole in 1/60 units (as long as a frame is not dropped).