absence_thelab

view src/beginpart.cpp @ 1:4d5933c261c3

todo and .hgignore
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 02:18:43 +0300
parents
children
line source
1 #include "beginpart.h"
3 BeginPart::BeginPart(GraphicsContext *gc) {
4 this->gc = gc;
6 this->gc = gc;
8 SceneLoader::SetNormalFileSaving(true);
9 SceneLoader::SetDataPath("data/textures/");
10 SceneLoader::LoadScene("data/geometry/begin.3ds", &scene);
12 light = new DirLight(Vector3(0.0f, 0.0f, 1.0f));
13 light->SetIntensity(1.5f);
14 scene->AddLight(light);
16 // get stuff
17 Logo1 = scene->GetObject("LogoT");
18 scene->RemoveObject(Logo1);
20 Logo2 = scene->GetObject("LogoB");
21 scene->RemoveObject(Logo2);
23 VolumeLogo = scene->GetObject("VolumeLogo");
24 scene->RemoveObject(VolumeLogo);
26 Latin1 = scene->GetObject("Latin1");
27 Latin2 = scene->GetObject("Latin2");
28 Lines[0] = scene->GetObject("Lines1");
29 Lines[1] = scene->GetObject("Lines2");
30 TheLabText[0] = scene->GetObject("LabText1");
31 TheLabText[1] = scene->GetObject("LabText2");
33 scene->RemoveObject(scene->GetObject("Plane01"));
35 gc->SetTextureTransformState(0, TexTransform2D);
36 }
38 BeginPart::~BeginPart() {
39 delete scene;
40 }
42 #define psin(x) (sinf(x) / 2.0f + 0.5f)
43 #define pcos(x) (cosf(x) / 2.0f + 0.5f)
45 void BeginPart::MainLoop() {
46 dword msec = timer.GetMilliSec();
47 float t = (float)msec / 1000.0f;
49 const float StartCycle = 2.5f;
50 const float EndCycle = 5.0f;
51 const float StartFade = 9.0f;
54 Latin1->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, 0,t/4,1));
55 Latin2->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, 0,t/2,1));
56 Lines[0]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t*2.0f,0,1));
57 Lines[1]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t/2.0f,0,1));
58 TheLabText[0]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t,0,1));
59 TheLabText[1]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t/3,0,1));
61 gc->Clear(0);
62 gc->ClearZBufferStencil(1.0f, 0);
64 gc->SetZBuffering(false);
66 scene->Render();
68 gc->SetAlphaBlending(true);
69 gc->SetTextureStageColor(0, TexBlendModulate, TexArgCurrent, TexArgTexture);
70 gc->SetTextureStageAlpha(0, TexBlendModulate, TexArgCurrent, TexArgTexture);
71 gc->SetBlendFunc(BLEND_ONE, BLEND_ONE);
73 Matrix3x3 TexMat;
75 // render shit
76 Logo1->SetTranslation(0.0f, max(0.8f - t, 0) * 50.0f, 0.0f);
77 Logo2->SetTranslation(0.0f, -max(0.8f - t, 0) * 50.0f, 0.0f);
79 if(t > StartCycle) {
80 Logo1->material.Diffuse.r += (t-StartCycle) * 0.005f;
81 Logo1->material.Diffuse.g -= (t-StartCycle) * 0.005f;
82 Logo1->material.Diffuse.b -= (t-StartCycle) * 0.005f;
83 if(Logo1->material.Diffuse.r > 0.5f) Logo1->material.Diffuse.r = 0.5f;
84 if(Logo1->material.Diffuse.g < 0.0f) Logo1->material.Diffuse.g = 0.0f;
85 if(Logo1->material.Diffuse.b < 0.0f) Logo1->material.Diffuse.b = 0.0f;
87 Logo2->material.Diffuse.r += (t-StartCycle) * 0.005f;
88 Logo2->material.Diffuse.g -= (t-StartCycle) * 0.005f;
89 Logo2->material.Diffuse.b -= (t-StartCycle) * 0.005f;
90 if(Logo2->material.Diffuse.r > 0.5f) Logo2->material.Diffuse.r = 0.5f;
91 if(Logo2->material.Diffuse.g < 0.0f) Logo2->material.Diffuse.g = 0.0f;
92 if(Logo2->material.Diffuse.b < 0.0f) Logo2->material.Diffuse.b = 0.0f;
93 }
95 gc->SetMaterial(Logo1->material);
96 gc->SetTexture(0, Logo1->material.Maps[TextureMap]);
98 gc->SetWorldMatrix(Logo1->GetWorldTransform());
99 Logo1->RenderBare();
101 gc->SetWorldMatrix(Logo2->GetWorldTransform());
102 Logo2->RenderBare();
104 if(t > EndCycle) {
105 Color color(Logo1->material.Diffuse.r, Logo1->material.Diffuse.g, Logo1->material.Diffuse.b);
106 VolumeLogo->material.SetDiffuse(color);
107 gc->SetTexture(0, VolumeLogo->material.Maps[TextureMap]);
109 float xoffs = sinf(t/2.0f) * 4.0f;
110 float yoffs = sinf(t) * 1.5f;//-(t - 2.0f*EndCycle);
111 for(int i=0; i<min(10, (int)((t-EndCycle)*30.0f)); i++) {
112 Matrix4x4 mat;
113 mat.SetTranslation(xoffs * ((float)i * 0.5f), yoffs * ((float)i * 0.5f), 0.0f);
115 float ScaleFactor = 1.0f + (float)i * 0.2f;
116 Matrix4x4 ScaleMat;
117 ScaleMat.SetScaling(ScaleFactor, ScaleFactor, ScaleFactor);
119 VolumeLogo->material.Diffuse.r -= 0.08f;
120 VolumeLogo->material.Diffuse.g -= 0.08f;
121 VolumeLogo->material.Diffuse.b -= 0.08f;
123 gc->SetWorldMatrix(VolumeLogo->GetWorldTransform() * mat * ScaleMat);
124 VolumeLogo->RenderBare();
125 }
126 }
128 Material OrigMat = VolumeLogo->material;
129 VolumeLogo->material = Material(0.0f, 0.0f, 0.0f, max((t - StartFade) / 2.0f, 0.0f));
130 VolumeLogo->Render();
131 VolumeLogo->material = OrigMat;
133 gc->SetZBuffering(true);
134 gc->SetAlphaBlending(false);