home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / egg / egg.c next >
C/C++ Source or Header  |  1997-07-14  |  3KB  |  106 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File: egg.c
  6.  *
  7.  ***************************************************************************/
  8.  
  9. #include "rmdemo.h"
  10.  
  11. BOOL
  12. BuildScene(LPDIRECT3DRMDEVICE dev, LPDIRECT3DRMVIEWPORT view,
  13.        LPDIRECT3DRMFRAME scene, LPDIRECT3DRMFRAME camera)
  14. {
  15.     LPDIRECT3DRMFRAME lights = NULL;
  16.     LPDIRECT3DRMMESHBUILDER egg_builder = NULL;
  17.     LPDIRECT3DRMFRAME egg = NULL;
  18.     LPDIRECT3DRMLIGHT light1 = NULL;
  19.     LPDIRECT3DRMLIGHT light2 = NULL;
  20.     HRESULT rval;
  21.  
  22.     view = view;        /* not used */
  23.  
  24.     /*
  25.      * initialize the lights in the scene
  26.      */
  27.     if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &lights)))
  28.     goto generic_error;
  29.     if (FAILED(lights->lpVtbl->SetPosition(lights, scene, D3DVAL(5), D3DVAL(5),
  30.                                 -D3DVAL(1))))
  31.                 goto generic_error;
  32.     if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_DIRECTIONAL, D3DVAL(0.9),
  33.                                   D3DVAL(0.8), D3DVAL(0.7), &light1)))
  34.                   goto generic_error;
  35.     if (FAILED(lights->lpVtbl->AddLight(lights, light1)))
  36.         goto generic_error;
  37.     if (FAILED(lights->lpVtbl->SetRotation(lights, scene, D3DVAL(0), D3DVAL(1), D3DVAL(1),
  38.                                 D3DVAL(-0.02))))
  39.                 goto generic_error;
  40.     if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_AMBIENT, D3DVAL(0.1),
  41.                                   D3DVAL(0.1), D3DVAL(0.1), &light2)))
  42.                   goto generic_error;
  43.     if (FAILED(scene->lpVtbl->AddLight(scene, light2)))
  44.     goto generic_error;
  45.  
  46.     /*
  47.      * load mesh file
  48.      */
  49.     if (FAILED(lpD3DRM->lpVtbl->CreateMeshBuilder(lpD3DRM, &egg_builder)))
  50.     goto generic_error;
  51.     rval = egg_builder->lpVtbl->Load(egg_builder, "egg.x", NULL,
  52.                     D3DRMLOAD_FROMFILE, NULL, NULL);
  53.     if (rval != D3DRM_OK) {
  54.         Msg("Failed to load egg.x\n%s", D3DRMErrorToString(rval));
  55.     goto ret_with_error;
  56.     }
  57.  
  58.     /*
  59.      * create an egg frame within the scene
  60.      */
  61.     if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &egg)))
  62.     goto generic_error;
  63.  
  64.     /*
  65.      * add the loaded mesh into the frame
  66.      */
  67.     if (FAILED(egg->lpVtbl->AddVisual(egg, (LPDIRECT3DRMVISUAL)egg_builder)))
  68.     goto generic_error;
  69.  
  70.     /*
  71.      * set up the frames position, orientation and rotation
  72.      */
  73.     if (FAILED(camera->lpVtbl->SetPosition(camera, scene, D3DVAL(0), D3DVAL(0), -D3DVAL(10))))
  74.     goto generic_error;
  75.     if (FAILED(camera->lpVtbl->SetOrientation(camera, scene, D3DVAL(0), D3DVAL(0), D3DVAL(1), D3DVAL(0),
  76.                                    D3DVAL(1), D3DVAL(0))))
  77.                    goto generic_error;
  78.     if (FAILED(egg->lpVtbl->SetRotation(egg, scene, D3DVAL(0), D3DVAL(1), D3DVAL(1),
  79.                              D3DVAL(0.02))))
  80.                  goto generic_error;
  81.  
  82.     RELEASE(egg);
  83.     RELEASE(lights);
  84.     RELEASE(egg_builder);
  85.     RELEASE(light1);
  86.     RELEASE(light2);
  87.     return TRUE;
  88.  
  89. generic_error:
  90.     Msg("A failure occured while building the scene.\n");
  91. ret_with_error:
  92.     RELEASE(egg);
  93.     RELEASE(lights);
  94.     RELEASE(egg_builder);
  95.     RELEASE(light1);
  96.     RELEASE(light2);
  97.     return FALSE;
  98. }
  99.  
  100. void
  101. OverrideDefaults(Defaults *defaults)
  102. {
  103.     defaults->bNoTextures = TRUE;
  104.     lstrcpy(defaults->Name, "Egg Direct3DRM Example");
  105. }
  106.