1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
tbResult Render(float fNumSecsPassed)
{
HRESULT hResult;
tbMatrix mWorld;
tbMatrix mCamera;
if(FAILED(hResult = g_pD3DDevice->Clear(0,NULL,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(63, 0, 63),1.0f,0)))
{
TB_ERROR_DIRECTX("g_pD3DDevice->Clear", hResult, TB_STOP);
}
g_pD3DDevice->BeginScene();
//Kameramatrix
mCamera=tbMatrixCamera(g_vCamPos,
g_vCamPos+tbVector3(sinf(g_fCamAngle),0.0f,cosf(g_fCamAngle)),
tbVector3(0.0f,1.0f,0.0f));
g_pD3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)(&mCamera));
// Sky-Box zeichnen //////////////////////////////////////////////////////////////////////
// States setzen
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
g_pD3DDevice->SetTexture(0,g_pEnvMap);
//g_pD3DDevice->SetTexture(1,NULL);
mWorld=tbMatrixTranslation(g_vCamPos);
g_pD3DDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)(&mWorld));
if(FAILED(hResult = g_pD3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,8,12,
g_ausSkyBoxIndex,D3DFMT_INDEX16,g_aSkyBoxVertex,sizeof(SVertex))))
{
// Fehler beim Zeichnen!
TB_ERROR_DIRECTX("g_pD3DDevice->DrawIndexedPrimitiveUP", hResult, TB_ERROR);
}
// Die Meshes ///////////////////////////////////////////////////////////////////////////
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING,TRUE);
g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
// Material und Licht
D3DMATERIAL9 Material;
D3DLIGHT9 PointLight;
Material.Ambient=tbColor(0.0f,1.0f,1.0f);
Material.Diffuse=tbColor(0.0f,0.0f,1.0f);
Material.Emissive=tbColor(1.0f,1.0f,1.0f);
Material.Power=30.0f;
Material.Specular=tbColor(0.0f,1.0f,1.0f);
g_pD3DDevice->SetMaterial(&Material);
ZeroMemory(&PointLight,sizeof(D3DLIGHT9));
PointLight.Ambient=tbColor(1.0f,1.0f,1.0f);
PointLight.Attenuation0=0.0f;
PointLight.Attenuation1=0.025f;
PointLight.Attenuation2=0.0f;
PointLight.Type=D3DLIGHT_POINT;
PointLight.Position=tbVector3(0.0f,0.0f,0.0f);
PointLight.Specular=tbColor(0.0f,0.0f,1.0f);
PointLight.Diffuse=tbColor(0.0f,1.0f,1.0f);
PointLight.Range=1000.0f;
g_pD3DDevice->SetLight(0,&PointLight);
g_pD3DDevice->LightEnable(0,TRUE);
g_pD3DDevice->SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
g_pD3DDevice->SetTextureStageState(0,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT3);
// Boden zeichnen ////////////////////////////////////////////////////////////////////////
mWorld=tbMatrixScaling(tbVector3(10.0f))*tbMatrixTranslation(tbVector3(0.0f,-4.0f,0.0f));
g_pD3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)(&mWorld));
g_pD3DDevice->SetTexture(0,g_pTexture2);
//g_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
g_pGroundModel->DrawSubset(0);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
return TB_OK;
}
|