| nimoNew.Internet.Master.Operator | Salut a tous
 j'ai fais une simulation 3D d'un person qui se promaine ds un park mais depui que j'ai essayer de mettre un menu pour avoir une selection pou voir:
 
 -comment jouer
 -lancer une perti
 -quiter
 
 ma simulation ne marche plus
 
 voici le code:
 
 
 | Code : 
 // Include the directx 8 utility library:
#include <dxu.h>#include <dxu3d.h>#include "D3dx8math.h"#include "Object3D.h"#include "SimpleObject3D.h"#include "GroundGrid.h"#include "OverlayGrid.h"#include "olliderClass.h"#include "Explosion.h"#include "Bullet.h"#include "resource.h"extern unsigned char OverlayMap[ARRAYSIZE][ARRAYSIZE];#define TITLE "SIMULATION: WALK THROUGH THE PARK"// some defines to use when changing camera view
#define SHOULDER 0#define SIDE 1#define TOP 2#define INTRO 3#define HOW 4#define GAMEOVER 5#define SINGLE 6/*******************************************************************************************/#define ABOUT_BOX_INFORMATION "CMT 3311: COURSEWORK1 COPYRIGHT ALEXANDRE NALIN"#define ABOUT_BOX_INFORMATION1 "Main menu: S to start, Q to exit\nUse Key left to move left\nUse key right to move right"// Generated to handle Menu Actions:
LRESULT WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){	// grap the message parameters stored in wParam:
	int loWord = LOWORD(wParam); // first 16 bits
	int hiWord = HIWORD(wParam); // last  16 bits
    switch(msg)    {	    case WM_COMMAND:  // This is a menu or button message
     if ( loWord == ID_FILE_EXIT ) // exit menu item was selected
     {  	   // Send a quit message which will destroy the application
  	   DXUDestroyWindow();  	   return 0; // This declares that a message was processed
     }     else if ( loWord == ID_MUSIC_SOUNDOFF )     {    DXUDeleteAllMusic();    return 0;     }        else if ( loWord == ID_MUSIC_SFXOFF )     {    DXUDeleteAllSFX();    return 0;     }        else if ( loWord == ID_HELP_ABOUT ) // about menu item was selected
     {  	   // Display a Message Box identifiying the application    	   MessageBox(hWnd,ABOUT_BOX_INFORMATION,"About",MB_ICONINFORMATION|MB_OK);  	   return 0; // This declares that a message was processed
     }     else if ( loWord == ID_HOWTOPLAY )     {  	   // Display a Message Box identifiying the application    	   MessageBox(hWnd,ABOUT_BOX_INFORMATION1,"About1",MB_ICONINFORMATION|MB_OK);  	   return 0; // This declares that a message was processed
     }    }   // process any messages that we didn't take care of     return (DefWindowProc(hWnd, msg, wParam, lParam));}/*****************************************************************************************/// Global Variables
D3DXMATRIX   matWorld,matCamera,matProj,matCamera1;DXULIGHT     directLight,spotLight;// create an Object3D called car  Object3D car;// Create a grid for the ground
GroundGrid groundgrid;// create a grid of overlay objects
OverlayGrid overlayGrid;// create and instance of the collider class
ColliderClass collider;// create an Object3D for an explosion
Explosion explosion;// create an Object3D for a bullet
Bullet bullet;DXUIMAGE	imgLife; // Image to represent a life
DXUSPRITE	sprLife; // sprite datatype to show a life image on screen
DXUIMAGE	imgHow;DXUSPRITE	sprHow;DXUIMAGE	imgIntro;DXUSPRITE	sprIntro;typedef struct{	int x;}AMUSIC;AMUSIC m[9];DXUMIDIID m0,m1,m2,m3,m4,m5,m6,m7,m8,m9;DXUSFXID  SN1,SN2,SN3,SN4,SN5,SN6,SN7,SN8,SN9,SN10,SN11,SN12,SN13,SN14;int mode=INTRO;// a font for writing text on the screen
DXUFONT dxuFont;//Function prototypes
VOID LoadWorld();VOID UpdateWorld();VOID ReleaseWorld();// Initialise lighting
VOID InitialiseLights(){	// Turn lighting calculation on
	DXUEnableLighting(TRUE);	// Create a directional light source
	DXUCreateDirectionalLight(&directLight,                      &D3DXVECTOR3(-1,-1,0.5),  // Direction Up Left
                      &D3DXVECTOR3(1.0f,1.0f,1.0f));	// White Color Normalised
	// Associate light with D3D device
	DXUSetDeviceLight(&directLight);	// Turn on this light source
	DXUEnableDeviceLight(&directLight,TRUE);	// Set ambient light intensity for the world
	DXUSetWorldAmbientLight(RGB(64,64,64));//ambientIntensity
}// the following are the vectors describing look at point
// and the camera or eye position in space
// they are defined globally so that they can be used by
// individual classes for billboarding
DXUVECTOR3D  vLookatPt,vEyePt;/***************************************** CAMERA SETTINGS *******************************//******************************************* SHOULDER CAM ********************************/// This function sets the camera to be above and behind the car
void SetShoulderCamera(){	// distz specifies how far behind the camera should be
	// disty specifies how far above the camera should be
	float distz=50,disty=20;	DXUMatrixLookAtRH(&matCamera1, &DXUVECTOR3D  	(  	// cameras world position is defined below as being
  	// distz and disty along the cars local z and y axes respectively
  	car.x-(car.matrix(2,0)*distz)+(car.matrix(1,0)*disty),  	car.y-(car.matrix(2,1)*distz)+(car.matrix(1,1)*disty),  	car.z-(car.matrix(2,2)*distz)+(car.matrix(1,2)*disty)  	),            &DXUVECTOR3D(car.x, car.y,car.z ), // look at point set to the car
  	// the direction up is set to the cars y axis direction    	&DXUVECTOR3D( car.matrix(1,0), car.matrix(1,1),car.matrix(1,2) ));	// make matCamera camera the device camera:
	DXUSetDeviceCameraMatrix(&matCamera1);	// global variable storing the look at point which set to the car
	vLookatPt.x=car.x;	vLookatPt.y=car.y;	vLookatPt.z=car.z;	// global variable storing the position of the camera
	vEyePt.x= car.x-(car.matrix(2,0)*distz)+(car.matrix(1,0)*disty);	vEyePt.y= car.y-(car.matrix(2,1)*distz)+(car.matrix(1,1)*disty);	vEyePt.z= car.z-(car.matrix(2,2)*distz)+(car.matrix(1,2)*disty);}/******************************************* TOP CAM ************************************/// This function sets the camera to be very far above the car
void SetTopCamera(){	float disty=990,distx=100;	DXUMatrixLookAtRH(&matCamera1, &DXUVECTOR3D  	( // cameras world position
  	car.x+(car.matrix(1,0)*disty),  	car.y+(car.matrix(1,1)*disty),  	car.z+(car.matrix(1,2)*disty)  	),            &DXUVECTOR3D(car.x, car.y,car.z ), // look at the car
  	// the direction up   
  	&DXUVECTOR3D( car.matrix(2,0), car.matrix(2,1),car.matrix(2,2) ));	// make matCamera camera the device camera:
	DXUSetDeviceCameraMatrix(&matCamera1);	vLookatPt.x=car.x;	vLookatPt.y=car.y;	vLookatPt.z=car.z;	vEyePt.x= car.x-(car.matrix(2,0)*disty)+(car.matrix(1,0)*distx);	vEyePt.y= car.y-(car.matrix(2,1)*disty)+(car.matrix(1,1)*distx);	vEyePt.z= car.z-(car.matrix(2,2)*disty)+(car.matrix(1,2)*distx);}/******************************************* SIDE CAM ************************************/// this sets the camera to look at the car from above and to the side of the car
void SetSideCamera(){	float disty=50,distx=100;	DXUMatrixLookAtRH(&matCamera1,&DXUVECTOR3D  	( // cameras world position
  	car.x+(car.matrix(0,0)*distx)+(car.matrix(1,0)*disty),  	car.y+(car.matrix(0,1)*distx)+(car.matrix(1,1)*disty),  	car.z+(car.matrix(0,2)*distx)+(car.matrix(1,2)*disty)  	),            &DXUVECTOR3D(car.x, car.y,car.z ), // look at the car
  	// the direction up   
  	&DXUVECTOR3D( car.matrix(1,0), car.matrix(1,1),car.matrix(1,2) ));	// make matCamera camera the device camera:
	DXUSetDeviceCameraMatrix(&matCamera1);	vLookatPt.x=car.x;	vLookatPt.y=car.y;	vLookatPt.z=car.z;	vEyePt.x= car.x-(car.matrix(2,0)*disty)+(car.matrix(1,0)*distx);	vEyePt.y= car.y-(car.matrix(2,1)*disty)+(car.matrix(1,1)*distx);	vEyePt.z= car.z-(car.matrix(2,2)*disty)+(car.matrix(1,2)*distx);}/************************************ INITIALISE WORLD ************************************/// Initialise rendering states, and camera, projection and world matrices
VOID Initialise3DWorld(){    // Enable Z-Buffering:
	DXUEnableZBuffering(TRUE);	// Enable Writing to the Z-Buffer instead of the back buffer:
	DXUEnableZBufferWrite(TRUE);	// set solid fill mode
	DXUSetFillMode(DXUFILL_SOLID);	// set no culling modes
	DXUSetCullMode(DXUCULL_NONE);	// We would normally set the camera up here but it is set in the
	// updateworld function in this program
	// initialise a perspective projection matrix:
	// at Field of view: 3.14/4 ( what a human can see )
	// aspect ratio same as screen ratio  	// nearest visibility at 1.0
	// furthest  visibility at 1000.0*/
	DXUMatrixPerspectiveFovRH(&matProj,D3DX_PI/4,640.0f/480.f,1.0f,1000.0f);	// set this projection matrix to be the worlds projection matrix
	DXUSetDeviceProjectionMatrix(&matProj);	// initialise the world matrix to the identity matrix - no transformation
	DXUMatrixIdentity( &matWorld);	// set the world matrix
	DXUSetDeviceWorldMatrix(&matWorld);}/**************************************** UPDATE WORLD ***********************************/// UpdateWorld reads keyboard input and transforms the car accordingly
VOID UpdateWorld(){//	int t = rand()%9;
//	DXUPlayMusic(m[t].x);
	D3DXMATRIX rot;	// amount to increment rotation by
	float inc=3.0;	static int r=1;	int i,j;	// camera is a staic variable which traks which of three possible
	// camera views the user has selected, default is the shoulder view
	static camera =SHOULDER;// FIRST OF ALL DEAL WITH KEYBOARD INPUT
	if( dxuKeyState[DIK_LEFT] )	{// left arrow pressed
  car.RotateY(inc);  // positive rotate around y axis
	}	if( dxuKeyState[DIK_RIGHT])	{// right arrow pressed
  car.RotateY(-inc );  // negative rotate around y axis
	}	if( dxuKeyState[DIK_UP] )	{// up arrow pressed
  car.RotateX(inc);	// positive rotate around x axis
	}	if( dxuKeyState[DIK_DOWN])	{// down arrow pressed
  car.RotateX(-inc);  // negative rotate around x axis
	}	if( dxuKeyState[DIK_Z] )	{// Z  pressed
  car.RotateZ(inc);  // positive rotate around z axis
	}	if( dxuKeyState[DIK_X])	{// X  pressed
  car.RotateZ(-inc);  // negative rotate around r axis
	}	if( dxuKeyState[DIK_R])	{// R  pressed
  car.Reset();  // reset the car to the start position
  car.LocalTranslation(0,5.9,20);	}	if( dxuKeyState[DIK_A])	{// A  pressed,    // move car forward
  car.Advance();  // check for collision with overlay objects
  for( i=0;i<ARRAYSIZE;i++)  {  	for( j=0;j<ARRAYSIZE;j++)  	{    // if the overlay map !=0 we need to check for collision
    if (OverlayMap[i][j]!=0)    {    	// call collision detection with threshold of 20
    	// ie: objects collide if dist between their
    	// centers is les than 20
    	if(collider.SimpleCollision(20,car.x,car.y,car.z,i*45,0,j*45))    	{      // if the above test is true there is a collision
      // in which case we reverse the car by one increment
      // as we advanced the car by one increment before the collision test
      // this has the net effect of making the car halt when
      // it collides with a overlay object
      car.Reverse();    	}    }  	}  }	}	if( dxuKeyState[DIK_S])	{// S  pressed
  car.Reverse();  // reverse the car
  for( i=0;i<ARRAYSIZE;i++)  {  	for( j=0;j<ARRAYSIZE;j++)  	{    // if the overlay map !=0 we need to check for collision
    if (OverlayMap[i][j]!=0)    {    	// call collision detection with threshold of 20
    	// ie: objects collide if dist between their
    	// centers is les than 20
    	if(collider.SimpleCollision(20,car.x,car.y,car.z,i*45,0,j*45))    	{      // if the above test is true there is a collision
      // in which case we reverse the car by one increment
      // as we advanced the car by one increment before the collision test
      // this has the net effect of making the car halt when
      // it collides with a overlay object
      car.Advance();    	}    }  	}  }	}	if( dxuKeyState[DIK_SPACE])	{// Space  pressed so we need to fire a bullet if we can
  // first check that the bullet is not currently alive
  // if it is currently alive the bullet cannot be fired    if(!bullet.alive)  	// fire the bullet from the car position
  	// and using the cars direction which is encoded in the cars rotmatrix
  	bullet.fire(car.rotMatrix,car.x,car.y,car.z);	}	// if f1 is pressed we will set camera to view from the side
	if(dxuKeyState[DIK_F1])	{  camera=SIDE;	}	// if f2 is pressed we will set camera to view from the top
	if(dxuKeyState[DIK_F2])	{  camera=TOP;	}	// if f3 is pressed we will set camera to view from the shoulder
	if(dxuKeyState[DIK_F3])	{  camera=SHOULDER;	}// NEXT DEAL WITH UPDATING GAME OBJECTS
	// If the bullet is currently alive it needs to be dealt with
	// ie: move it on a bit, and check whether it collides with anything
	// in the world overlay layer
	if(bullet.alive)	{  // update moves the bullet on and kills it if it has gone too far
  bullet.Update();  // transform applies the movement
  bullet.Transform();  // do collision detection with all overlay world objects
  for( i=0;i<ARRAYSIZE;i++)  {  	for( j=0;j<ARRAYSIZE;j++)  	{    // only need to do collision detect if there is an object
    // at this position
    if ((OverlayMap[i][j]!=0)&&(OverlayMap[i][j]!=6))    {    	// collision detction treshold is set to 40
    	if(collider.SimpleCollision(40,bullet.x,bullet.y,bullet.z,i*45,6,j*45))    	{      // if their is a collision we set the overlay map entry to 0
      // this means the object wont be drawn anymore
      OverlayMap[i][j]=0;      // we se bullet alive to false so the bullet wont be drawn
      bullet.alive=false;      // set distanceTravelled to 0 ready for the next firing
      bullet.distanceTravelled=0;      // start an explosion at the position of the bullet on        // collision detection
      explosion.StartExplosion(bullet.x,bullet.y,bullet.z);    	}    }  	}  }	}	// If the explosion is currently alive we need to update it
	if(explosion.alive)  explosion.Update();	// We need to call tranform for the car to apply and transformation
	// that resulted from pushing keyboard buttons
	car.Transform();// FINALLY	DEAL WITH THE CAMERA AND SET IT TO THE CHOSEN VIEW
	switch (camera)	{  case 0:{  	SetShoulderCamera();  	break;  }  case 1:{  	SetSideCamera();  	break;  }  case 2:{  	SetTopCamera();  	break;  }	}}/******************************************************************************************/int introScreen(){//	DXURunMedia();
	int t = rand()%9;	DXUPlayMusic(m[t].x);	while (DXUProcessMessages()) // Process system Messages
	{	// read key board    DXUReadKeyboard();  // if Q is pressed return game over
  if (dxuKeyState[DIK_Q] )  	DXUDestroyWindow() ;  //	if S is pressed return SINGLE player game
  if (dxuKeyState[DIK_S])  	return SINGLE;  if (dxuKeyState[DIK_H])  	return HOW;  // Other wise draw the background    DXURenderPrepare();  DXUDrawSpriteFast(&sprIntro);  DXURenderFinish();	}	// if there was error processing system messages return MESSAGEERROR
	return GAMEOVER;}/****** HOW TO ********** Display the instruction menu *****************************/int how(){double renderTime = 0;	while (DXUProcessMessages()) // Process system Messages
	{  DXUReadKeyboard();  // if its time to render i.e. a 30th of a second  since last time
  if (DXUIsTimeToRender() )  	{    if ( dxuKeyState[DIK_ESCAPE] )    {    	return INTRO;    }  renderTime += DXUGetSecsPerFrame();  DXURenderPrepare();  DXUDrawSpriteFast(&sprHow);  DXURenderFinish();  	}	}	// if there was error processing system messages return MESSAGEERROR
	return GAMEOVER;}/******************************************* LOAD WORLD **********************************/// Load and initialise the 3D world
VOID LoadWorld(){	DXULoadImage(&imgLife,"life.bmp",DXUCKRGB(0,0,0));	// initialise life sprite
	DXUSetSprite(&imgLife,&sprLife,32,45);	DXULoadImage(&imgHow,"how.bmp",DXUCK_NOCOLOURKEY);	DXUSetSprite(&imgHow,&sprHow,0,0);	DXULoadImage(&imgIntro,"war1.bmp",DXUCK_NOCOLOURKEY);	DXUSetSprite(&imgIntro,&sprIntro,0,0);	car.LoadMesh("gun.x" ); // load the car mesh
	car.LocalTranslation(0,5.9,20); // move car onto ground plane
	explosion.LoadMesh("explode.x" ); // load the explosion mesh
	explosion.LocalTranslation(0,6,0); // move bullet onto ground plane
	bullet.LoadMesh("bullet2.x" );// load the bullet mesh
	bullet.LocalTranslation(0,6,0); // move bullet onto ground plane
	groundgrid.Initialise();	overlayGrid.Initialise();	DXULoadFont(&dxuFont,"Times new Roman",10,10); // load the font
	Initialise3DWorld();  // Initialise the world
	InitialiseLights();	  // initialise lighting  }/************************************** RELEASE *************************************/// Release resources
VOID ReleaseWorld(){  DXUReleaseFont(&dxuFont);	car.Release();	explosion.Release();	bullet.Release();	groundgrid.Release();	overlayGrid.Release();}/************************************** RENDER ***************************************/// Render the world
VOID RenderWorld(){	TCHAR str[100];	DXURenderPrepare();    // get ready to render    // render al objects thats needs to be drawn
//  int t = rand()%9;
//  DXUPlayMusic(m[t].x);
  if(bullet.alive)bullet.Render();  car.Render();  groundgrid.Render();  overlayGrid.Render();  if(explosion.alive)explosion.Render();  // get string ready to print frame rate on the screen
  wsprintf(str,"Rendering %d fps",DXUGetFramesPerSecondpp());  // draw the string to the screen
  DXUDrawTextFast(&dxuFont,str,0,0,DXURGB(0,255,0));  // Draw the only sprite used on the screen
  DXUDrawSprite(&sprLife);	DXURenderFinish();  // finish rendering
}/************************************* MAIN LOOP ***************************************/// Main:
int APIENTRY WinMain(HINSTANCE hinstance,                     HINSTANCE hPreInstance,                     LPSTR lpCmdLine,int nCmdShow){   	// Load the Direct3D COM and Build the current system device list:
	if ( !DXULoadDirectXGraphics() )	{  DXUDisplayLastError();  return -1;	}	// Set Window Title Name and window name
	DXUSetWindowInfo(TITLE,"trans",NULL,NULL);	// Create a WIN32 window:
	if(!DXUCreateWindow(hinstance,0,0,640+6,480+26))	{	   DXUDisplayLastError();	   return -1;	}    // Initialise Windowed Graphics:
	if (!DXUInitGraphics())	{	    DXUDisplayLastError();  return -1;	}	DXUInitSoundSystem();	DXUInitMusicSystem();//	int t = rand()%9;
//	DXUPlayMusic(m[t].x);
	m[0].x = DXULoadMusic("mid0.mid" );	m[1].x = DXULoadMusic("mid1.mid" );	m[2].x = DXULoadMusic("mid2.mid" );	m[3].x = DXULoadMusic("mid3.mid" );	m[4].x = DXULoadMusic("mid4.mid" );	m[5].x = DXULoadMusic("mid5.mid" );	m[6].x = DXULoadMusic("mid6.mid" );	m[7].x = DXULoadMusic("mid7.mid" );	m[8].x = DXULoadMusic("mid8.mid" );//	LoadWorld();  // load and initialise 3D world
	DXUInitInput();  // initialise DirectInput
	DXUInitKeyboard();	// initialise keyboard input
	DXUEnableAlphaBlending(true);	// Main game loop:
/*	while (DXUProcessMessages()) // Process The system Messages
	{
  DXUReadKeyboard();  // read the keyboard
  if (DXUIsTimeToRender() ) // if its time to render
  {
  	LoadWorld();  // load and initialise 3D world
  	UpdateWorld();  	// update the world objects
      RenderWorld();  	// render the world
  }
	}
*//************************************* GAME LOOP *****************************************/	while(mode!=GAMEOVER)	{  // introduction
  if(mode==INTRO){mode=introScreen();}  if(mode==HOW){mode=how();}  // start the single player game from first level
  if(mode==SINGLE)  {  	LoadWorld();  // load and initialise 3D world
  	UpdateWorld();  // update the world objects
      RenderWorld();  // render the world
  }	}/********************************************************************************************/	// Do not forget to release everything:
	DXUReleaseSprite(&sprLife);	DXUReleaseImage(&imgLife);	DXUDeleteAllSFX();	DXUDeleteAllMusic();	DXUCloseSoundSystem();	DXUCloseMusicSystem();	ReleaseWorld();	DXUReleaseKeyboard();    DXUCloseInput();	DXUReleaseGraphics();    DXUUnloadDirectXGraphics();	return DXUGetLastMessage()->wParam;}/**************************************** END OF GAME *************************************/
 | 
   ---------------Message édité par nimo le 02-01-2005 à 19:37:21
 NEC 3500 | YAMADA 6600 | NIMO_CORP
 
   |