/*---------------------------------------------------------------------------* Project: Dolphin/Revolution gx demo File: tf-pn-mtx.c Copyright 1998-2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #include #include /*---------------------------------------------------------------------------* Forward references *---------------------------------------------------------------------------*/ void main ( void ); static void CameraInit ( void ); static void DrawInit ( void ); static void VertexLightInit ( void ); static void DrawTick ( void ); static void AnimTick ( void ); /*---------------------------------------------------------------------------* Global variables *---------------------------------------------------------------------------*/ Mtx v; u32 rot; /*---------------------------------------------------------------------------* Application main loop *---------------------------------------------------------------------------*/ void main ( void ) { DEMOInit(NULL); OSReport("\n\n"); OSReport("**********************************************\n"); OSReport("tf-pn-mtx: Position/normal matrix demo\n"); OSReport("**********************************************\n"); OSReport("To quit hit the start button.\n"); OSReport("\n"); OSReport("Each cube is drawn with a different HW matrix.\n"); OSReport("**********************************************\n"); OSReport("\n\n"); DrawInit(); // Define my vertex formats and set array pointers. DEMOPadRead(); // Read the joystick for this frame // While the quit button is not pressed while(!(DEMOPadGetButton(0) & PAD_BUTTON_MENU)) { DEMOPadRead(); // Read the joystick for this frame // Do animation based on input AnimTick(); DEMOBeforeRender(); DrawTick(); // Draw the model. DEMODoneRender(); } OSHalt("End of test"); } /*---------------------------------------------------------------------------* Functions *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* Name: CameraInit Description: Initialize the projection matrix and load into hardware. Arguments: v view matrix to be passed to ViewInit cameraLocScale scale for the camera's distance from the object - to be passed to ViewInit Returns: none *---------------------------------------------------------------------------*/ static void CameraInit ( void ) { Mtx44 p; Vec camPt = {0.0F, 0.0F, 650.0F}; Vec up = {0.0F, 1.0F, 0.0F}; Vec origin = {0.0F, 0.0F, 0.0F}; MTXFrustum(p, 240, -240, -320, 320, 500, 2000); GXSetProjection(p, GX_PERSPECTIVE); MTXLookAt(v, &camPt, &up, &origin); } /*---------------------------------------------------------------------------* Name: DrawInit Description: Calls the correct initialization function for the current model. Arguments: none Returns: none *---------------------------------------------------------------------------*/ static void DrawInit( void ) { CameraInit(); // Initialize the camera. VertexLightInit(); } /*---------------------------------------------------------------------------*/ static void VertexLightInit ( void ) { GXLightObj MyLight; GXColor color = {255, 255, 255, 255}; GXInitLightPos(&MyLight, 0.0F, 0.0F, 0.0F); GXInitLightColor(&MyLight, color); GXLoadLightObjImm(&MyLight, GX_LIGHT0); GXSetChanMatColor(GX_COLOR0, color); GXSetChanCtrl( GX_COLOR0, GX_TRUE, // enable channel GX_SRC_REG, // amb source GX_SRC_REG, // mat source GX_LIGHT0, // light mask GX_DF_CLAMP,// diffuse function GX_AF_NONE); GXSetNumChans(1); GXSetNumTexGens( 0 ); GXSetTevOp( GX_TEVSTAGE0, GX_PASSCLR ); GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); } /*---------------------------------------------------------------------------* Name: DrawTick Description: Draw the current model once. Arguments: v view matrix m model matrix Returns: none *---------------------------------------------------------------------------*/ static void DrawTick( void ) { Mtx rx, ry, rz, s, mv, t; MTXScale(s, 70, 70, 70); MTXRotDeg(rx, 'X', (float)rot); MTXRotDeg(ry, 'Y', (float)rot); MTXRotDeg(rz, 'Z', (float)rot); MTXTrans(t, -240, 150, 0); MTXConcat(rx, s, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX0); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX0); MTXTrans(t, -80, 150, 0); MTXConcat(ry, s, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX1); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX1); MTXTrans(t, 80, 150, 0); MTXConcat(rz, s, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX2); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX2); MTXTrans(t, 240, 150, 0); MTXConcat(rx, s, mv); MTXConcat(ry, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX3); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX3); MTXTrans(t, -240, -150, 0); MTXConcat(rx, s, mv); MTXConcat(rz, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX4); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX4); MTXTrans(t, -80, -150, 0); MTXConcat(ry, s, mv); MTXConcat(rz, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX5); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX5); MTXTrans(t, 80, -150, 0); MTXConcat(rz, s, mv); MTXConcat(ry, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX6); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX6); MTXTrans(t, 240, -150, 0); MTXConcat(rz, s, mv); MTXConcat(rx, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX7); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX7); MTXTrans(t, -80, 0, 0); MTXConcat(rz, s, mv); MTXConcat(rx, mv, mv); MTXConcat(ry, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX8); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX8); MTXTrans(t, 80, 0, 0); MTXConcat(rx, s, mv); MTXConcat(ry, mv, mv); MTXConcat(rz, mv, mv); MTXConcat(t, mv, mv); MTXConcat(v, mv, mv); GXLoadPosMtxImm(mv, GX_PNMTX9); MTXInverse(mv, mv); MTXTranspose(mv, mv); GXLoadNrmMtxImm(mv, GX_PNMTX9); GXSetCurrentMtx(GX_PNMTX0); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX1); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX2); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX3); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX4); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX5); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX6); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX7); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX8); GXDrawCube(); GXSetCurrentMtx(GX_PNMTX9); GXDrawCube(); } /*---------------------------------------------------------------------------* Name: AnimTick Description: Animates the camera and object based on the joystick's state. Arguments: none Returns: none *---------------------------------------------------------------------------*/ static void AnimTick ( void ) { rot ++; if(rot > 719) rot = 0; } /*---------------------------------------------------------------------------*/