0001: // ----------------------------------------------------------------------------
0002: //
0003: // load.cpp - 読み込み部分
0004: // 
0005: // Copyright (c) 2001 IF (if@kun-desu.ne.jp)
0006: // All Rights Reserved.
0007: //
0008: // ----------------------------------------------------------------------------
0009: #define STRICT
0010: 
0011: #include <d3d8.h>
0012: #include <d3dx8.h>
0013: #include "main.h"
0014: 
0015: LPDIRECT3DVERTEXBUFFER8 pLightVB  = NULL;           // 光源点表示用、バッファ
0016: 
0017: 
0018: //-----------------------------------------------------------------------------
0019: // 光源の位置を描く
0020: //-----------------------------------------------------------------------------
0021: typedef struct{
0022:     FLOAT x, y, z;  // 位置
0023:     DWORD color;    // 色
0024: }POINT_VERTEX;
0025: #define D3DFVF_POINT_VERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)
0026: //-----------------------------------------------------------------------------
0027: // 初期化
0028: void InitLightEff(LPDIRECT3DDEVICE8 lpD3DDEV, D3DXVECTOR4 pos)
0029: {
0030:     POINT_VERTEX vertices[] = {
0031:         //     x,            y,         z,  color
0032:         {     pos.x,     pos.y,     pos.z, D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), },
0033:         {15.0f*pos.x,15.0f*pos.y,15.0f*pos.z, D3DCOLOR_RGBA(0xff, 0xff, 0xff, 0xff), },
0034:     };
0035:     RELEASE(pLightVB);
0036:     if(FAILED(lpD3DDEV->CreateVertexBuffer( sizeof(vertices),0,
0037:                           D3DFVF_POINT_VERTEX, D3DPOOL_DEFAULT, &pLightVB))) return;
0038:     VOID* pVertices;
0039:     if(FAILED(pLightVB->Lock( 0, sizeof(vertices), (BYTE**)&pVertices, 0))) return;
0040:     memcpy( pVertices, vertices, sizeof(vertices) );
0041:     pLightVB->Unlock();
0042: }
0043: //-----------------------------------------------------------------------------
0044: void DrawLightEff(LPDIRECT3DDEVICE8 lpD3DDEV, D3DXMATRIX mView, D3DXMATRIX mProj)
0045: {
0046:     D3DXMATRIX mWorld;
0047:     D3DXMatrixIdentity(&mWorld);
0048:     lpD3DDEV->SetTransform(D3DTS_WORLD, &mWorld);
0049:     lpD3DDEV->SetTransform(D3DTS_VIEW,  &mView);
0050:     lpD3DDEV->SetTransform(D3DTS_PROJECTION, &mProj);
0051:     lpD3DDEV->SetStreamSource( 0, pLightVB, sizeof(POINT_VERTEX) );
0052:     lpD3DDEV->SetVertexShader( D3DFVF_POINT_VERTEX );
0053:     lpD3DDEV->DrawPrimitive( D3DPT_LINELIST , 0, 1 );
0054: }
0055: //-----------------------------------------------------------------------------
0056: void CleanLightEff()
0057: {
0058:     RELEASE(pLightVB);
0059: }
0060: