view.c 2.09 KB
/*============================================================================
  NuSYSTEM サンプルプログラム「SNAKE TAIL HACK」
  
  view.c
  
  Copyright (C) 1997, NINTENDO Co,Ltd.
  ============================================================================*/

#include <assert.h>
#include <nusys.h>

#include "main.h"
#include "graphic.h"
#include "para.h"

void SetViewMtx( Dynamic* );
void SetViewMtxGameOver( Dynamic* );
extern float View;

/*--------------------------------------*/
/*  視点マトリックスの設定(通常時)	*/
/*  IN:	dp ダイナミックポインタ		*/
/*  RET:なし				*/
/*--------------------------------------*/
void
SetViewMtx( Dynamic* dp )
{
    u16   perspNorm;
    static LookAt lookat;
    /* 投影マトリックスの計算と設定 */
    guPerspective(&dp->projection, &perspNorm,
		  33, (float)SCREEN_WD/(float)SCREEN_HT, 10, 10000, 1.0);

    guLookAtReflect(&dp->viewing, &lookat,
		    0,
		    cosf(2.0*M_PI/(360/(View+90.0)))*CAM_DISTANCE,
		    sinf(2.0*M_PI/(360/(View+90.0)))*CAM_DISTANCE,
		    0, 0, 0,
		    0, 1, 0);

    gSPPerspNormalize(glistp++, perspNorm);
    gSPLookAt(glistp++, &lookat);

    gSPMatrix(glistp++, &(dp->projection), 
	      G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
    gSPMatrix(glistp++, &(dp->viewing), 
	      G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH);
}

/*----------------------------------------------*/
/*  視点マトリックスの設定(ゲームオーバー時)	*/
/*  IN:	dp ダイナミックポインタ			*/
/*  RET:なし					*/
/*----------------------------------------------*/
void
SetViewMtxGameOver( Dynamic* dp )
{
    u16   perspNorm;
    static LookAt lookat;
    /* 投影マトリックスの計算と設定 */
    guPerspective(&dp->projection, &perspNorm,
		  33, (float)SCREEN_WD/(float)SCREEN_HT, 10, 10000, 1.0);

    guLookAtReflect(&dp->viewing, &lookat,
		    0,
		    0,
		    1500,
		    0, 0, 0,
		    0, 1, 0);

    gSPPerspNormalize(glistp++, perspNorm);
    gSPLookAt(glistp++, &lookat);

    gSPMatrix(glistp++, &(dp->projection), 
	      G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
    gSPMatrix(glistp++, &(dp->viewing), 
	      G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH);
}