absence_thelab
view src/hellpart.cpp @ 0:1cffe3409164
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 23 Oct 2014 01:46:07 +0300 |
parents | |
children |
line source
1 #include <cassert>
2 #include "hellpart.h"
4 HellPart::HellPart(GraphicsContext *gc) {
5 this->gc = gc;
7 SceneLoader::SetNormalFileSaving(true);
8 SceneLoader::SetDataPath("data/textures/");
9 SceneLoader::LoadScene("data/geometry/hell.3ds", &scene);
11 CamPath = scene->GetCurve("CamPath");
12 cam = const_cast<Camera*>(scene->GetActiveCamera());
13 cam->SetCameraPath(CamPath, 0, 0, 30000);
14 cam->SetClippingPlanes(1.0f, 100000.0f);
16 cam2 = scene->GetCamera("Camera02");
17 cam3 = scene->GetCamera("Camera03");
18 cam2->SetClippingPlanes(1.0f, 100000.0f);
19 cam3->SetClippingPlanes(1.0f, 100000.0f);
21 Thunder = scene->GetLight("Omni01");
22 Thunder->SetIntensity(0.0f);
24 ThundEnv[0] = scene->GetObject("b1");
25 ThundEnv[1] = scene->GetObject("b2");
26 ThundEnv[2] = scene->GetObject("b3");
27 ThundEnv[3] = scene->GetObject("b4");
28 ThundEnv[4] = scene->GetObject("b5");
29 for(int i=0; i<5; i++) {
30 scene->RemoveObject(ThundEnv[i]);
31 }
33 Stones[0] = scene->GetObject("Box01");
34 Stones[1] = scene->GetObject("Box02");
35 Stones[2] = scene->GetObject("Box03");
36 Stones[3] = scene->GetObject("Box04");
37 Stones[4] = scene->GetObject("Box05");
38 for(int i=0; i<5; i++) {
39 scene->RemoveObject(Stones[i]);
40 Stones[i]->SetShadingMode(FlatShading);
41 }
43 Rings[0] = scene->GetObject("Tube01");
44 Rings[1] = scene->GetObject("Tube02");
45 Rings[2] = scene->GetObject("Tube03");
46 Rings[3] = scene->GetObject("Tube04");
47 Rings[4] = scene->GetObject("Tube05");
48 for(int i=0; i<5; i++) {
49 scene->RemoveObject(Rings[i]);
50 }
52 // Load Credits
53 dbgtex = gc->texman->AddTexture("data/textures/psys02.jpg");
54 CredNuc[0] = gc->texman->AddTexture("data/textures/credits/nuc1.jpg");
55 CredNuc[1] = gc->texman->AddTexture("data/textures/credits/nuc2.jpg");
56 CredNuc[2] = gc->texman->AddTexture("data/textures/credits/nuc3.jpg");
57 CredNuc[3] = gc->texman->AddTexture("data/textures/credits/nuc4.jpg");
58 CredNuc[4] = gc->texman->AddTexture("data/textures/credits/nuc5.jpg");
59 CredNuc[5] = gc->texman->AddTexture("data/textures/credits/nuc6.jpg");
60 CredNuc[6] = gc->texman->AddTexture("data/textures/credits/nuc7.jpg");
62 CredRaw[0] = gc->texman->AddTexture("data/textures/credits/raw1.jpg");
63 CredRaw[1] = gc->texman->AddTexture("data/textures/credits/raw2.jpg");
64 CredRaw[2] = gc->texman->AddTexture("data/textures/credits/raw3.jpg");
65 CredRaw[3] = gc->texman->AddTexture("data/textures/credits/raw4.jpg");
66 CredRaw[4] = gc->texman->AddTexture("data/textures/credits/raw5.jpg");
67 CredRaw[5] = gc->texman->AddTexture("data/textures/credits/raw6.jpg");
68 CredRaw[6] = gc->texman->AddTexture("data/textures/credits/raw7.jpg");
70 CredAmi[0] = gc->texman->AddTexture("data/textures/credits/am1.jpg");
71 CredAmi[1] = gc->texman->AddTexture("data/textures/credits/am2.jpg");
72 CredAmi[2] = gc->texman->AddTexture("data/textures/credits/am3.jpg");
73 CredAmi[3] = gc->texman->AddTexture("data/textures/credits/am4.jpg");
74 CredAmi[4] = gc->texman->AddTexture("data/textures/credits/am5.jpg");
75 CredAmi[5] = gc->texman->AddTexture("data/textures/credits/am6.jpg");
76 CredAmi[6] = gc->texman->AddTexture("data/textures/credits/am7.jpg");
78 CredAmv[0] = gc->texman->AddTexture("data/textures/credits/amv1.jpg");
79 CredAmv[1] = gc->texman->AddTexture("data/textures/credits/amv2.jpg");
80 CredAmv[2] = gc->texman->AddTexture("data/textures/credits/amv3.jpg");
81 CredAmv[3] = gc->texman->AddTexture("data/textures/credits/amv4.jpg");
82 CredAmv[4] = gc->texman->AddTexture("data/textures/credits/amv5.jpg");
83 CredAmv[5] = gc->texman->AddTexture("data/textures/credits/amv6.jpg");
84 CredAmv[6] = gc->texman->AddTexture("data/textures/credits/amv7.jpg");
86 Credits = new Object(gc);
87 Credits->CreatePlane(1.7f, 0);
88 Credits->Scale(1.0f, 0.3f, 1.0f);
90 Blood = scene->GetObject("Blood");
91 scene->RemoveObject(Blood);
92 Grail = scene->GetObject("Object13");
93 //scene->RemoveObject(Grail);
94 }
96 HellPart::~HellPart() {
97 delete scene;
98 }
100 void HellPart::MainLoop() {
101 dword msec = timer.GetMilliSec();
102 float t = msec / 1000.0f;
104 // deform blood surface
105 Vertex *BloodVerts = Blood->GetTriMesh()->GetModVertexArray();
106 dword VertexCount = Blood->GetTriMesh()->GetVertexCount();
108 for(dword i=0; i<VertexCount; i++) {
109 Vector2 pos2d(BloodVerts[i].pos.x, BloodVerts[i].pos.z);
110 float dist = pos2d.Length();
111 BloodVerts[i].pos.y = (1.5f * sinf(dist - t*3.0f)) * (dist > 0.0f ? (1.0f / (dist*1.5f)) : 1.0f);
112 }
113 Blood->GetTriMesh()->CalculateNormals();
116 ////////////////////////
118 gc->Clear(0);
119 gc->ClearZBufferStencil(1.0f, 0);
121 scene->SetActiveCamera(cam);
123 if(t >= 18.0f && t < 22.0f) {
124 scene->SetActiveCamera(cam2);
125 Credits->material.SetTexture(CredNuc[(int)(t * 20.0f) % 7], TextureMap);
126 }
127 if(t >= 24.0f && t < 28.0f) {
128 scene->SetActiveCamera(cam3);
129 Credits->material.SetTexture(CredRaw[(int)(t * 20.0f) % 7], TextureMap);
130 }
131 if(t >= 30.0f && t < 34.0f) {
132 scene->SetActiveCamera(cam2);
133 Credits->material.SetTexture(CredAmi[(int)(t * 20.0f) % 7], TextureMap);
134 }
135 if(t >= 36.0f && t < 40.0f) {
136 scene->SetActiveCamera(cam3);
137 Credits->material.SetTexture(CredAmv[(int)(t * 20.0f) % 7], TextureMap);
138 }
140 cam->FollowPath(msec);
142 gc->SetAmbientLight(Color(0.5f));
144 scene->Render();
146 for(int i=0; i<5; i++) {
147 Matrix4x4 tmat = Stones[i]->TransMat, rmat = Stones[i]->GRotMat;
148 Stones[i]->Translate(0.0f, sinf(t) * 54.0f, 0.0f);
149 Stones[i]->GlobalRotate(0.0f, t/4.0f, 0.0f);
151 Stones[i]->Render();
153 Stones[i]->TransMat = tmat;
154 Stones[i]->GRotMat = rmat;
155 }
157 float Rot = t / 2.0f;
159 for(int i=0; i<5; i++) {
160 Rings[i]->ResetRotation();
161 }
163 Rings[0]->Rotate(Rot, 0.0f, 0.0f);
165 Rings[1]->Rotate(0.0f, 0.0f, Rot);
167 Vector3 axis(1.0f, 0.0f, 0.0f);
168 axis.Rotate(0.0f, 0.0f, QuarterPi);
169 Rings[2]->Rotate(0.0f, 0.0f, QuarterPi);
170 Rings[2]->Rotate(axis, Rot);
172 axis = Vector3(0.0f, 0.0f, 1.0f);
173 axis.Rotate(QuarterPi, 0.0f, 0.0f);
174 Rings[3]->Rotate(QuarterPi, 0.0f, 0.0f);
175 Rings[3]->Rotate(axis, Rot);
177 Rings[4]->Rotate(Rot, 0.0f, Rot);
179 gc->SetZWrite(false);
180 for(int i=0; i<5; i++) {
181 Rings[i]->Render();
182 }
183 gc->SetZWrite(true);
185 Light *light = scene->GetLight("Spot01");
186 light->SetRange(100000.0f);
187 light->SetIntensity(0.5f);
188 light->SetLight(0, gc);
189 Blood->Render();
190 light->SetRange(100.0f);
191 light->SetLight(0, gc);
193 gc->SetAmbientLight(Color(0.0f));
195 if((t >= 18.0f && t < 22.0f) || (t >= 24.0f && t < 28.0f) || (t >= 30.0f && t < 34.0f) || (t >= 36.0f && t < 40.0f)) {
196 gc->SetAlphaBlending(true);
197 gc->SetLighting(false);
198 gc->SetZBuffering(false);
199 gc->SetBlendFunc(BLEND_ONE, BLEND_ONE);
200 gc->SetMaterial(Material(1.0f, 1.0f, 1.0f));
201 gc->SetTexture(0, Credits->material.Maps[TextureMap]);
202 gc->SetTexture(1, 0);
203 gc->SetTextureCoordIndex(0, 0);
205 gc->SetTextureStageColor(0, TexBlendSelectArg1, TexArgTexture, TexArgCurrent);
206 gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgTexture, TexArgCurrent);
207 Matrix4x4 WorldMat;
208 WorldMat.Scale(1.0f, 0.3f, 1.0f);
209 gc->SetWorldMatrix(WorldMat);
210 Matrix4x4 ViewMat;
211 ViewMat.Translate(0.0f, 0.0f, 2.0f);
212 gc->SetViewMatrix(ViewMat);
213 Matrix4x4 ProjMat, OldProj;
214 OldProj = gc->GetProjectionMatrix();
215 CreateProjectionMatrix(&ProjMat, QuarterPi, 1.333333f, 1.0f, 10.0f);
216 gc->SetProjectionMatrix(ProjMat);
218 Credits->RenderBare();
220 gc->SetProjectionMatrix(OldProj);
221 gc->SetLighting(true);
222 gc->SetZBuffering(true);
223 gc->SetAlphaBlending(false);
224 }
225 }