3D Game Builder SDK

SDK Functions

gameCloseModel( int id )

Description

Close a 3D model that was opened using the gameOpenModel( char * name ) function.

Specification

int gameCloseModel( int id )

int id

= the id number of the open model

return value

= 1 (success) or 0 (failed)

Notes

This function closes a 3D model that was created using 3D Model Builder and opened using the gameOpenModel( char * name ) function.

For Example

#include "3dgamebuilder.h"

// exported game function
DLL_EXPORT int gameLoop(void)
{
	int		cube;

	float	anglex = 0.0f;
	float	angley = 0.0f;
	float	zoom   = 1.0f;
	float	posx   = 0.0f;
	float	posy   = 0.0f;

	// open model
	cube = gameOpenModel( "cube.mod" );

	// validate
	if (cube == 0) return 1;

	// init
	anglex = 0.0f;
	angley = 0.0f;

	// game loop
	while(1)
	{
		// read the controller
		gamePadRead();

		// rotate
		if (gamePadButtonDown(1,PAD_BUTTON_RIGHT)) anglex += -4.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_LEFT))  anglex +=  4.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_UP))    angley +=  4.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_DOWN))  angley += -4.0f;

		// move
		if (gamePadButtonDown(1,PAD_BUTTON_A)) posy -= 1.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_B)) posx -= 1.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_C)) posy += 1.0f;
		if (gamePadButtonDown(1,PAD_BUTTON_D)) posx += 1.0f;

		// adjust zoom
		if (gamePadButtonDown(1,PAD_BUTTON_RIGHT_1)) zoom += 0.05f;
		if (gamePadButtonDown(1,PAD_BUTTON_RIGHT_2)) zoom -= 0.05f;
		if (gamePadButtonDown(1,PAD_BUTTON_LEFT_1))  zoom += 0.05f;
		if (gamePadButtonDown(1,PAD_BUTTON_LEFT_2))  zoom -= 0.05f;

		// limit zoom
		if (zoom < 0.1f) zoom = 0.1f;
		if (zoom > 2.0f) zoom = 2.0f;

		// start drawing
		gameStartRender();

		// init projection matrix
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity();
		// adjust for screen ratio (assuming square pixels)
		glScalef( (272.0f/480.0f), 1.0f, 1.0f );
		// create a volume that is 20 x 20 x 20 
		glScalef( (1.0f/20.0f * zoom), (1.0f/20.0f * zoom), 1.0f/20.0f );
		glTranslatef( posx, posy, 0.0f );
		
		// rotate model view matrix
		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();
		glRotatef( anglex, 0.0f, 1.0f, 0.0f );
		glRotatef( angley, 1.0f, 0.0f, 0.0f );

		// draw the cube
		gameDrawModel(cube);

		// end of drawing
		gameEndRender();
	}

	// clean up
	gameCloseModel(cube);

	return 0;
}

See Also

  gameOpenModel( char * name )
  gameCloseModel( int id )
  gameDrawModel( int id )
  gameFlushModels( void )
  gameSetModelLighting( int on )

Go Back

SDK Functions