absence_thelab

diff src/beginpart.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/beginpart.cpp	Thu Oct 23 01:46:07 2014 +0300
     1.3 @@ -0,0 +1,135 @@
     1.4 +#include "beginpart.h"
     1.5 +
     1.6 +BeginPart::BeginPart(GraphicsContext *gc) {
     1.7 +	this->gc = 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/begin.3ds", &scene);
    1.14 +
    1.15 +	light = new DirLight(Vector3(0.0f, 0.0f, 1.0f));
    1.16 +	light->SetIntensity(1.5f);
    1.17 +	scene->AddLight(light);
    1.18 +
    1.19 +	// get stuff
    1.20 +	Logo1 = scene->GetObject("LogoT");
    1.21 +	scene->RemoveObject(Logo1);
    1.22 +
    1.23 +	Logo2 = scene->GetObject("LogoB");
    1.24 +	scene->RemoveObject(Logo2);
    1.25 +
    1.26 +	VolumeLogo = scene->GetObject("VolumeLogo");
    1.27 +	scene->RemoveObject(VolumeLogo);
    1.28 +	
    1.29 +	Latin1 = scene->GetObject("Latin1");	
    1.30 +	Latin2 = scene->GetObject("Latin2");	
    1.31 +	Lines[0] = scene->GetObject("Lines1");
    1.32 +	Lines[1] = scene->GetObject("Lines2");
    1.33 +	TheLabText[0] = scene->GetObject("LabText1");
    1.34 +	TheLabText[1] = scene->GetObject("LabText2");
    1.35 +
    1.36 +	scene->RemoveObject(scene->GetObject("Plane01"));
    1.37 +
    1.38 +	gc->SetTextureTransformState(0, TexTransform2D);
    1.39 +}
    1.40 +
    1.41 +BeginPart::~BeginPart() {
    1.42 +	delete scene;
    1.43 +}
    1.44 +
    1.45 +#define psin(x) (sinf(x) / 2.0f + 0.5f)
    1.46 +#define pcos(x) (cosf(x) / 2.0f + 0.5f)
    1.47 +
    1.48 +void BeginPart::MainLoop() {
    1.49 +	dword msec = timer.GetMilliSec();
    1.50 +	float t = (float)msec / 1000.0f;
    1.51 +
    1.52 +	const float StartCycle = 2.5f;
    1.53 +	const float EndCycle = 5.0f;
    1.54 +	const float StartFade = 9.0f;
    1.55 +
    1.56 +
    1.57 +	Latin1->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, 0,t/4,1));
    1.58 +	Latin2->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, 0,t/2,1));
    1.59 +	Lines[0]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t*2.0f,0,1));
    1.60 +	Lines[1]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t/2.0f,0,1));
    1.61 +	TheLabText[0]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t,0,1));
    1.62 +	TheLabText[1]->SetTextureMatrix(Matrix3x3(1,0,0, 0,1,0, t/3,0,1));
    1.63 +
    1.64 +	gc->Clear(0);
    1.65 +	gc->ClearZBufferStencil(1.0f, 0);
    1.66 +
    1.67 +	gc->SetZBuffering(false);
    1.68 +
    1.69 +	scene->Render();
    1.70 +
    1.71 +	gc->SetAlphaBlending(true);
    1.72 +	gc->SetTextureStageColor(0, TexBlendModulate, TexArgCurrent, TexArgTexture);
    1.73 +	gc->SetTextureStageAlpha(0, TexBlendModulate, TexArgCurrent, TexArgTexture);
    1.74 +	gc->SetBlendFunc(BLEND_ONE, BLEND_ONE);
    1.75 +
    1.76 +	Matrix3x3 TexMat;
    1.77 +	
    1.78 +	// render shit
    1.79 +	Logo1->SetTranslation(0.0f, max(0.8f - t, 0) * 50.0f, 0.0f);
    1.80 +	Logo2->SetTranslation(0.0f, -max(0.8f - t, 0) * 50.0f, 0.0f);
    1.81 +	
    1.82 +	if(t > StartCycle) {
    1.83 +        Logo1->material.Diffuse.r += (t-StartCycle) * 0.005f;
    1.84 +		Logo1->material.Diffuse.g -= (t-StartCycle) * 0.005f;
    1.85 +		Logo1->material.Diffuse.b -= (t-StartCycle) * 0.005f;
    1.86 +		if(Logo1->material.Diffuse.r > 0.5f) Logo1->material.Diffuse.r = 0.5f;
    1.87 +		if(Logo1->material.Diffuse.g < 0.0f) Logo1->material.Diffuse.g = 0.0f;
    1.88 +		if(Logo1->material.Diffuse.b < 0.0f) Logo1->material.Diffuse.b = 0.0f;
    1.89 +
    1.90 +		Logo2->material.Diffuse.r += (t-StartCycle) * 0.005f;
    1.91 +		Logo2->material.Diffuse.g -= (t-StartCycle) * 0.005f;
    1.92 +		Logo2->material.Diffuse.b -= (t-StartCycle) * 0.005f;
    1.93 +		if(Logo2->material.Diffuse.r > 0.5f) Logo2->material.Diffuse.r = 0.5f;
    1.94 +		if(Logo2->material.Diffuse.g < 0.0f) Logo2->material.Diffuse.g = 0.0f;
    1.95 +		if(Logo2->material.Diffuse.b < 0.0f) Logo2->material.Diffuse.b = 0.0f;
    1.96 +	}
    1.97 +	
    1.98 +	gc->SetMaterial(Logo1->material);
    1.99 +	gc->SetTexture(0, Logo1->material.Maps[TextureMap]);
   1.100 +	
   1.101 +	gc->SetWorldMatrix(Logo1->GetWorldTransform());
   1.102 +	Logo1->RenderBare();
   1.103 +
   1.104 +	gc->SetWorldMatrix(Logo2->GetWorldTransform());
   1.105 +	Logo2->RenderBare();
   1.106 +
   1.107 +	if(t > EndCycle) {
   1.108 +		Color color(Logo1->material.Diffuse.r, Logo1->material.Diffuse.g, Logo1->material.Diffuse.b);
   1.109 +		VolumeLogo->material.SetDiffuse(color);
   1.110 +		gc->SetTexture(0, VolumeLogo->material.Maps[TextureMap]);
   1.111 +		
   1.112 +		float xoffs = sinf(t/2.0f) * 4.0f;
   1.113 +		float yoffs = sinf(t) * 1.5f;//-(t - 2.0f*EndCycle);
   1.114 +		for(int i=0; i<min(10, (int)((t-EndCycle)*30.0f)); i++) {
   1.115 +			Matrix4x4 mat;
   1.116 +			mat.SetTranslation(xoffs * ((float)i * 0.5f), yoffs * ((float)i * 0.5f), 0.0f);
   1.117 +
   1.118 +			float ScaleFactor = 1.0f + (float)i * 0.2f;
   1.119 +			Matrix4x4 ScaleMat;
   1.120 +			ScaleMat.SetScaling(ScaleFactor, ScaleFactor, ScaleFactor);
   1.121 +
   1.122 +			VolumeLogo->material.Diffuse.r -= 0.08f;
   1.123 +			VolumeLogo->material.Diffuse.g -= 0.08f;
   1.124 +			VolumeLogo->material.Diffuse.b -= 0.08f;
   1.125 +
   1.126 +			gc->SetWorldMatrix(VolumeLogo->GetWorldTransform() * mat * ScaleMat);
   1.127 +			VolumeLogo->RenderBare();
   1.128 +		}
   1.129 +	}
   1.130 +
   1.131 +	Material OrigMat = VolumeLogo->material;
   1.132 +	VolumeLogo->material = Material(0.0f, 0.0f, 0.0f, max((t - StartFade) / 2.0f, 0.0f));
   1.133 +	VolumeLogo->Render();
   1.134 +	VolumeLogo->material = OrigMat;
   1.135 +
   1.136 +	gc->SetZBuffering(true);
   1.137 +	gc->SetAlphaBlending(false);
   1.138 +}
   1.139 \ No newline at end of file