absence_thelab
diff src/dungeonpart.cpp @ 0:1cffe3409164
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 23 Oct 2014 01:46:07 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/dungeonpart.cpp Thu Oct 23 01:46:07 2014 +0300 1.3 @@ -0,0 +1,321 @@ 1.4 +#include "dungeonpart.h" 1.5 +#include "d3dx8.h" 1.6 + 1.7 +DungeonPart::DungeonPart(GraphicsContext *gc) { 1.8 + 1.9 + this->gc = gc; 1.10 + 1.11 + SceneLoader::SetNormalFileSaving(true); 1.12 + SceneLoader::SetDataPath("data/textures/"); 1.13 + SceneLoader::LoadScene("data/geometry/scene2.3ds", &scene); 1.14 + 1.15 + // setup camera paths 1.16 + CamPath[0] = scene->GetCurve("cpath01"); 1.17 + CamPath[1] = scene->GetCurve("cpath02"); 1.18 + CamPath[2] = scene->GetCurve("cpath03"); 1.19 + TargPath[0] = scene->GetCurve("ctarget01"); 1.20 + TargPath[1] = scene->GetCurve("ctarget03"); 1.21 + 1.22 + CamPath[0]->SetArcParametrization(true); 1.23 + CamPath[1]->SetArcParametrization(true); 1.24 + CamPath[2]->SetArcParametrization(true); 1.25 + TargPath[0]->SetArcParametrization(true); 1.26 + TargPath[1]->SetArcParametrization(true); 1.27 + 1.28 + 1.29 + cam[0] = scene->GetCamera("Camera01"); 1.30 + cam[1] = scene->GetCamera("Camera02"); 1.31 + cam[2] = scene->GetCamera("Camera03"); 1.32 + cam[3] = scene->GetCamera("FreeCam"); 1.33 + 1.34 + cam[0]->SetCameraPath(CamPath[0], TargPath[0], 0, 40000); 1.35 + cam[1]->SetCameraPath(CamPath[1], 0, 40000, 45000); 1.36 + cam[2]->SetCameraPath(CamPath[2], TargPath[1], 45000, 75000); 1.37 + 1.38 + // get the lava crust under control 1.39 + LavaCrust = scene->GetObject("Plane02"); 1.40 + scene->RemoveObject(LavaCrust); 1.41 + 1.42 + // get the shadow-map walls under control 1.43 + ShadowObj[0] = scene->GetObject("TunnelLigh"); 1.44 + scene->RemoveObject(ShadowObj[0]); 1.45 + ShadowObj[1] = scene->GetObject("TunnelLig0"); 1.46 + scene->RemoveObject(ShadowObj[1]); 1.47 + 1.48 + // load the flame textures 1.49 + for(int i=0; i<FLAME_TEXTURES; i++) { 1.50 + char num[3]; 1.51 + itoa(i, num, 10); 1.52 + string fname = string("data/textures/flame/flame") + (i < 10 ? string("0") : string("")) + string(num) + string(".jpg"); 1.53 + FlameTex[i] = gc->texman->AddTexture(fname.c_str()); 1.54 + } 1.55 + 1.56 + // get the flame objects and remove them from the scene (to take over the rendering) 1.57 + for(int i=0; i<16; i++) { 1.58 + char num[3]; 1.59 + itoa(i, num, 10); 1.60 + string name = string("Fire") + (i < 10 ? string("0") : string("")) + string(num); 1.61 + 1.62 + Flame[i] = scene->GetObject(name.c_str()); 1.63 + scene->RemoveObject(Flame[i]); 1.64 + } 1.65 + 1.66 + LightRays = scene->GetObject("LightRays"); 1.67 + scene->RemoveObject(LightRays); 1.68 + 1.69 + Floor[0] = scene->GetObject("floor1"); 1.70 + Floor[1] = scene->GetObject("floor2"); 1.71 + Floor[2] = scene->GetObject("floor3"); 1.72 + for(int i=0; i<3; i++) scene->RemoveObject(Floor[i]); 1.73 + 1.74 + Obj = scene->GetObject("DefSphere"); 1.75 + scene->RemoveObject(Obj); 1.76 + 1.77 + mobj = new Object(gc); 1.78 + mobj->GetTriMesh()->SetData(Obj->GetTriMesh()->GetVertexArray(), Obj->GetTriMesh()->GetTriangleArray(), Obj->GetTriMesh()->GetVertexCount(), Obj->GetTriMesh()->GetTriangleCount()); 1.79 + 1.80 + Obj->material.SetTexture(gc->texman->AddTexture("data/textures/rusty01.jpg"), TextureMap); 1.81 + Obj->material.SetTexture(gc->texman->AddTexture("data/textures/refmap1.jpg"), EnvironmentMap); 1.82 + 1.83 + Obj->material.SetAmbient(Color(0.5f)); 1.84 + Obj->material.SetDiffuse(Color(0.5f)); 1.85 + Obj->material.SetSpecular(Color(175.0f / 256.0f, 95.0f / 256.0f, 17.0f / 256.0f)); 1.86 + Obj->material.SetSpecularPower(90.0f); 1.87 + Obj->material.SpecularEnable = true; 1.88 + mobj->material = Obj->material; 1.89 + 1.90 + Obj->GetTriMesh()->ChangeMode(TriMeshDynamic); 1.91 + mobj->GetTriMesh()->ChangeMode(TriMeshDynamic); 1.92 + 1.93 + Crystals[0] = scene->GetObject("Box114"); 1.94 + Crystals[1] = scene->GetObject("Box115"); 1.95 + Crystals[2] = scene->GetObject("Box116"); 1.96 + Crystals[3] = scene->GetObject("Box117"); 1.97 + Crystals[4] = scene->GetObject("Box118"); 1.98 + 1.99 + for(int i=0; i<5; i++) { 1.100 + scene->RemoveObject(Crystals[i]); 1.101 + } 1.102 + 1.103 + Name = new Object(gc); 1.104 + Name->CreatePlane(1.7f, 0); 1.105 + Name->Scale(1.0f, 0.3f, 1.0f); 1.106 + 1.107 + Fade = new Object(gc); 1.108 + Fade->CreatePlane(3.0f, 0); 1.109 + Fade->material = Material(0.0f, 0.0f, 0.0f); 1.110 + 1.111 + // load name textures 1.112 + for(int i=0; i<8; i++) { 1.113 + char fname[] = "data/textures/Absence/abx.jpg"; 1.114 + fname[24] = '1' + i; 1.115 + NameTex[i] = gc->texman->AddTexture(fname); 1.116 + } 1.117 + 1.118 + cam[3]->Zoom(-1.0f); 1.119 +} 1.120 + 1.121 +DungeonPart::~DungeonPart() { 1.122 + delete scene; 1.123 +} 1.124 + 1.125 +#define INRANGE(a, b) (msec >= a && msec < b) 1.126 + 1.127 +void DungeonPart::MainLoop() { 1.128 + dword msec = timer.GetMilliSec(); 1.129 + float t = (float)msec / 1000.0f; 1.130 + 1.131 + // set the active camera 1.132 + for(int i=0; i<3; i++) { 1.133 + cam[i]->FollowPath(msec); 1.134 + } 1.135 + Vector3 Cam3Pos = cam[3]->GetPosition(); 1.136 + 1.137 + if(msec >= 0 && msec < 40000) { 1.138 + scene->SetActiveCamera(cam[0]); 1.139 + } 1.140 + if(msec >= 39990 && msec < 45000) { 1.141 + scene->SetActiveCamera(cam[1]); 1.142 + } 1.143 + if(msec >= 45000 && msec < 75000) { 1.144 + scene->SetActiveCamera(cam[2]); 1.145 + } 1.146 + 1.147 + if(INRANGE(17000, 18000) || INRANGE(22000, 23000)) { 1.148 + if(INRANGE(22000, 23000)) { 1.149 + cam[3]->Rotate(0.0f, t, 0.0f); 1.150 + } else { 1.151 + cam[3]->Rotate(0.0f, -t, 0.0f); 1.152 + } 1.153 + scene->SetActiveCamera(cam[3]); 1.154 + } 1.155 + 1.156 + gc->Clear(0); 1.157 + gc->ClearZBufferStencil(1.0f, 0); 1.158 + 1.159 + 1.160 + scene->Render(); 1.161 + 1.162 + // Render flames 1.163 + gc->SetLighting(false); 1.164 + gc->SetZWrite(false); 1.165 + int ftexnum = (int)((float)msec / 33.35f) % FLAME_TEXTURES; 1.166 + gc->SetAlphaBlending(true); 1.167 + gc->SetBackfaceCulling(false); 1.168 + gc->SetBlendFunc(BLEND_ONE, BLEND_ONE); 1.169 + gc->SetTextureStageColor(0, TexBlendModulate, TexArgTexture, TexArgCurrent); 1.170 + gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgTexture, TexArgTexture); 1.171 + gc->SetMaterial(Flame[0]->material); 1.172 + gc->SetTexture(1, 0); 1.173 + for(int i=0; i<16; i++) { 1.174 + gc->SetTexture(0, FlameTex[ftexnum]); 1.175 + gc->SetWorldMatrix(Flame[i]->GetWorldTransform()); 1.176 + Flame[i]->RenderBare(); 1.177 + } 1.178 + gc->SetBackfaceCulling(true); 1.179 + gc->SetAlphaBlending(false); 1.180 + gc->SetZWrite(true); 1.181 + gc->SetLighting(true); 1.182 + 1.183 + // render the shadow walls 1.184 + gc->SetAlphaBlending(true); 1.185 + gc->SetBlendFunc(BLEND_DESTCOLOR, BLEND_ZERO); 1.186 + gc->SetTexture(0, ShadowObj[0]->material.Maps[0]); 1.187 + gc->SetTextureStageColor(0, TexBlendModulate, TexArgTexture, TexArgDiffuseColor); 1.188 + gc->SetMaterial(ShadowObj[0]->material); 1.189 + gc->SetWorldMatrix(ShadowObj[0]->GetWorldTransform()); 1.190 + ShadowObj[0]->RenderBare(); 1.191 + gc->SetWorldMatrix(ShadowObj[1]->GetWorldTransform()); 1.192 + ShadowObj[1]->RenderBare(); 1.193 + gc->SetAlphaBlending(false); 1.194 + 1.195 + // render volumetric light 1.196 + gc->SetAlphaBlending(true); 1.197 + gc->SetZWrite(false); 1.198 + 1.199 + 1.200 + LightRays->ResetScaling(); 1.201 + 1.202 + LightRays->material.Alpha = 0.02f; 1.203 + LightRays->material.SetEmissive(1.0f, 1.0f, 1.0f); 1.204 + for(int i=0; i<14; i++) { 1.205 + LightRays->Scale(0.975f, 1.0f, 0.975f); 1.206 + LightRays->Render(); 1.207 + } 1.208 + gc->SetZWrite(true); 1.209 + gc->SetAlphaBlending(false); 1.210 + 1.211 + 1.212 + // The Morphing Object 1.213 + 1.214 + Obj->GetTriMesh()->SetData(mobj->GetTriMesh()->GetVertexArray(), mobj->GetTriMesh()->GetTriangleArray(), mobj->GetTriMesh()->GetVertexCount(), mobj->GetTriMesh()->GetTriangleCount()); 1.215 + 1.216 + dword VertCount = Obj->GetTriMesh()->GetVertexCount(); 1.217 + Vertex *verts = Obj->GetTriMesh()->GetModVertexArray(); 1.218 + for(dword i=0; i<VertCount; i++) { 1.219 + float uangle = DotProduct(verts[i].pos.Normalized(), VECTOR3_I); 1.220 + float vangle = DotProduct(verts[i].pos.Normalized(), VECTOR3_J); 1.221 + 1.222 + float sfact = 0.3f * (sinf(uangle * cosf(t) * 5.0f) + sinf(vangle * 7.0f * sinf(t)) + cosf(uangle * cosf(t*2.0f) * 3.0f) * 1.5f); 1.223 + verts[i].pos += verts[i].pos * sfact; 1.224 + } 1.225 + 1.226 + 1.227 + Obj->GetTriMesh()->CalculateNormals(); 1.228 + Obj->Render(); 1.229 + 1.230 + 1.231 + // make the lava move 1.232 + Matrix3x3 TexMat; 1.233 + TexMat.m[2][0] = t/50.0f; 1.234 + TexMat.m[2][1] = t/70.0f; 1.235 + gc->SetTextureMatrix(TexMat); 1.236 + LavaCrust->Render(); 1.237 + gc->SetTextureMatrix(Matrix4x4()); 1.238 + 1.239 + /////// Render the Crystals /////////// 1.240 +/* 1.241 + float StartRise = 4;//53.0f; 1.242 + float EndRise = 8;//57.0f; 1.243 + float yoffset = -355.0f; 1.244 + 1.245 + if(t >= StartRise && t < EndRise) { 1.246 + for(int i=0; i<5; i++) Crystals[i]->SetTranslation(0.0f, (t - StartRise) / (EndRise - StartRise), 0.0f); 1.247 + } 1.248 +*/ 1.249 + gc->SetShadingMode(FlatShading); 1.250 + for(int i=0; i<5; i++) { 1.251 + Crystals[i]->Render(); 1.252 + } 1.253 + gc->SetShadingMode(GouraudShading); 1.254 + 1.255 + 1.256 + //////////////// render the mirroring marble floor /////////////// 1.257 + 1.258 + // burn the stencil baby 1.259 + gc->SetZWrite(false); 1.260 + gc->SetColorWrite(false, false, false, false); 1.261 + gc->SetStencilBuffering(true); 1.262 + gc->SetStencilFunc(CMP_ALWAYS); 1.263 + gc->SetStencilOp(SOP_KEEP, SOP_KEEP, SOP_INC); 1.264 + 1.265 + for(int i=0; i<3; i++) Floor[i]->Render(); 1.266 + gc->SetZWrite(true); 1.267 + gc->SetColorWrite(true, true, true, true); 1.268 + gc->SetStencilOp(SOP_KEEP, SOP_KEEP, SOP_KEEP); 1.269 + 1.270 + // render the rest of the floor normally 1.271 + Floor[0]->ResetRotation(); 1.272 + Floor[0]->Rotate(0.0f, t/2.0f, 0.0f); 1.273 + Floor[1]->ResetRotation(); 1.274 + Floor[1]->Rotate(0.0f, -t/4.0f, 0.0f); 1.275 + 1.276 + for(int i=0; i<3; i++) Floor[i]->Render(); 1.277 + 1.278 + // render the reflection where stencil > 0 1.279 + gc->SetStencilFunc(CMP_EQUAL); 1.280 + gc->SetStencilReference(1); 1.281 + gc->ClearZBuffer(1.0f); 1.282 + 1.283 + gc->SetFrontFace(CounterClockwise); 1.284 + 1.285 + std::list<Object*> *objlist = scene->GetObjectsList(); 1.286 + std::list<Object*>::iterator iter = objlist->begin(); 1.287 + while(iter != objlist->end()) { 1.288 + (*iter)->Scale(1.0f, -1.0f, 1.0f); 1.289 + float alpha = (*iter)->material.Alpha; 1.290 + (*iter)->material.Alpha = 0.25f; 1.291 + (*iter)->Render(); 1.292 + (*iter)->material.Alpha = alpha; 1.293 + (*iter++)->Scale(1.0f, -1.0f, 1.0f); 1.294 + } 1.295 + 1.296 + gc->SetFrontFace(Clockwise); 1.297 + gc->SetStencilBuffering(false); 1.298 + 1.299 + if(t < 6.0f) { 1.300 + gc->SetAlphaBlending(true); 1.301 + gc->SetLighting(false); 1.302 + gc->SetZBuffering(false); 1.303 + gc->SetBlendFunc(BLEND_ONE, BLEND_ONE); 1.304 + gc->SetMaterial(Material(1.0f, 1.0f, 1.0f)); 1.305 + gc->SetTexture(0, NameTex[(msec >> 6) % 8]); 1.306 + gc->SetTextureStageColor(0, TexBlendSelectArg1, TexArgTexture, TexArgTexture); 1.307 + gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgTexture, TexArgTexture); 1.308 + gc->SetWorldMatrix(Name->GetWorldTransform()); 1.309 + Matrix4x4 ViewMat; 1.310 + ViewMat.Translate(0.0f, 0.0f, 1.0f); 1.311 + gc->SetViewMatrix(ViewMat); 1.312 + Name->RenderBare(); 1.313 + gc->SetLighting(true); 1.314 + 1.315 + // fade in 1.316 + Fade->material.Alpha = min(max(0.0f, (2.0f - t)), 1.0f); 1.317 + Fade->Render(); 1.318 + 1.319 + gc->SetZBuffering(true); 1.320 + gc->SetAlphaBlending(false); 1.321 + } 1.322 + 1.323 + cam[3]->SetPosition(Cam3Pos); 1.324 +} 1.325 \ No newline at end of file