EGG.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

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