spin.c 4.35 KB

/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1995, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., 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 Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/

/*
 * File:	spin.c
 *
 * Routines for creating display list for Spin application
 *   Create Matrices
 *   Set Attributes
 *   Select Model
 *
 */

#include <ultra64.h>
#include <gu.h>
#include <os.h>
#include <em.h>

#include "spin.h"
#include "texture.h"


extern Spin_mode;

/**************************************************************************
 *  List of model display lists, main loop cycles through these.
 **************************************************************************/
Gfx *modelList[] = {
    &(square_dl[0]),
    &(square2_dl[0]),
    &(box_dl[0]),
    &(rect_box_dl[0]),
    &(cone_dl[0]),
    &(cylinder_dl[0]),
    &(frustrum_dl[0]),
    &(bumble_dl[0]),
    &(icosa_dl[0]),
    &(torii_dl[0]),
    &(ground_dl[0]),
    &(u64_dl[0]),
    &(cross_dl[0]),
    &(sphere_dl[0]),
    &(pipe_dl[0]),
    &(twist_dl[0]),
    &(twist1_dl[0]),
    &(sector_dl[0]),
    &(frac_island_dl[0]),
    &(triangle_dl[0]),
    &(runway_dl[0]),
    &(hexagonOpaInter_dl[0]),
    &(big_tex_dl[0]),
    &(bigger_tex_dl[0]),
    &(gorge_dl[0]),
    &(airport_dl[0]),
    &(xluramp_q_dl[0]),
    &(tex_fill_rect_dl[0]),
    (Gfx *) NULL,	/* last one, to count them... */
};


/**************************************************************************
 *  Build display list
 **************************************************************************/
void BuildDisplayList(Dynamic *dynamicp, int caseno, int fov, float aspect, int near, int far)
{
    unsigned char red, grn, blu; /* mode icon color */
    u16			perspNorm;
    Mtx rot;
  
    /*
     *	  Build Matrices
     */
    guPerspective(&dynamicp->projection,&perspNorm,
		  (float)fov, aspect, (float)near, (float)far, 1.0);
    guLookAt(&dynamicp->viewing, 
	     0, 0, 3000,
	     0, 0, 0,
	     0, 1, 0);

    gSPMatrix(glistp++, osVirtualToPhysical(&(dynamicp->projection)),
	      G_MTX_PROJECTION|G_MTX_LOAD|G_MTX_NOPUSH);

/****************** special transform for immobile background **************/
/*****************************************************************************/

    gSPMatrix(glistp++, osVirtualToPhysical(&(dynamicp->viewing)),
	      G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);

    gSPMatrix(glistp++, osVirtualToPhysical(&(dynamicp->eye)),
	      G_MTX_MODELVIEW|G_MTX_MUL|G_MTX_NOPUSH);

    gSPMatrix(glistp++, osVirtualToPhysical(&(dynamicp->modeling)),
	      G_MTX_MODELVIEW|G_MTX_MUL|G_MTX_NOPUSH);
    
    gSPPerspNormalize(glistp++, perspNorm);


    /* 
     * select model
     */

    /* ### What is caseno 21??? */
    if (caseno == 21) 
    {
	/* 
	 * opaque non-inter polys
	 */
	gSPDisplayList(glistp++, box1Opa_dl);
	gSPDisplayList(glistp++, opaDecal_dl);

	/* set up static viewpoint to draw transparent parts of hexagon */
	guLookAt(&(dynamicp->view), 
		 0, 0, 3000,
		 0, 0, 0,
		 0, 1, 0);
	gSPMatrix(glistp++, osVirtualToPhysical(&(dynamicp->view)),
		  G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_PUSH);
	/*
	 * opaque inter polys
	 */
	gSPDisplayList(glistp++, hexagonOpaInter_dl);
	gSPDisplayList(glistp++, opaHexDecal_dl);
	gSPPopMatrix(glistp++, G_MTX_MODELVIEW);

	/*
	 * transparent non-inter polys
	 */
	gSPDisplayList(glistp++, box1Trans_dl);
	gSPDisplayList(glistp++, transDecal_dl);

	gSPMatrix(glistp++, osVirtualToPhysical(&(dynamicp->view)),
		  G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_PUSH);

	/*
	 * cloud surface
	 gSPDisplayList(glistp++, square1_dl);
	 */

	/*
	 * transparent inter polys
	 */
	gSPDisplayList(glistp++, hexagonTransInter_dl);
	gSPPopMatrix(glistp++, G_MTX_MODELVIEW);

    } 
    else 
    {
	gSPDisplayList(glistp++, modelList[caseno]);
    }
    
    gDPFullSync(glistp++);
}