absence_thelab
diff src/greetspart.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/greetspart.cpp Thu Oct 23 01:46:07 2014 +0300 1.3 @@ -0,0 +1,97 @@ 1.4 +#include "greetspart.h" 1.5 +#include "nwt/widget.h" 1.6 + 1.7 +extern Widget *win; 1.8 + 1.9 +GreetsPart::GreetsPart(GraphicsContext *gc) { 1.10 + this->gc = gc; 1.11 + 1.12 + gc->Clear(0); 1.13 + gc->ClearZBufferStencil(1.0f, 0); 1.14 + 1.15 + 1.16 + SceneLoader::SetNormalFileSaving(false); 1.17 + SceneLoader::SetDataPath("data/textures/"); 1.18 + SceneLoader::LoadScene("data/geometry/greets.3ds", &scene); 1.19 + SceneLoader::SetNormalFileSaving(true); 1.20 + 1.21 + Parchment = scene->GetObject("Plane01"); 1.22 + //Scroll1 = scene->GetObject("Object01"); 1.23 + //Scroll2 = scene->GetObject("Object02"); 1.24 + 1.25 + // load the flame textures 1.26 + for(int i=0; i<52; i++) { 1.27 + char num[3]; 1.28 + itoa(i, num, 10); 1.29 + string fname = string("data/textures/flame/flame") + (i < 10 ? string("0") : string("")) + string(num) + string(".jpg"); 1.30 + FlameTex[i] = gc->texman->LoadTexture(fname.c_str()); 1.31 + } 1.32 + 1.33 + flame = scene->GetObject("Plane02"); 1.34 + scene->RemoveObject(flame); 1.35 + 1.36 + Parchment->SetScaling(9.0f, 1.0f, 1.0f); 1.37 + 1.38 + Bottle = scene->GetObject("Bottle"); 1.39 + scene->RemoveObject(Bottle); 1.40 + 1.41 + light = scene->GetLight("Omni01"); 1.42 + 1.43 + scene->SetShadows(true); 1.44 + light->SetShadowCasting(true); 1.45 + //scene->GetObject("CHolder")->SetShadowCasting(true); 1.46 + scene->GetObject("Candle")->SetShadowCasting(true); 1.47 + //scene->GetObject("Bottle01")->SetShadowCasting(true); 1.48 + 1.49 + const Light *l[] = {light}; 1.50 + scene->GetObject("Cylinder01")->CalculateShadows(l, 1); 1.51 + scene->GetObject("Cylinder02")->CalculateShadows(l, 1); 1.52 + scene->GetObject("Bottle01")->CalculateShadows(l, 1); 1.53 + scene->GetObject("Plane01")->CalculateShadows(l, 1); 1.54 + 1.55 + scene->SetAmbientLight(Color(0.58f, 0.3f, 0.3f)); 1.56 + 1.57 + LightPos = light->GetPosition(); 1.58 + light->SetIntensity(0.5f); 1.59 + light->SetAttenuation(0.0f, 0.1f, 0.0f); 1.60 + 1.61 +} 1.62 + 1.63 +GreetsPart::~GreetsPart() { 1.64 + delete scene; 1.65 +} 1.66 + 1.67 +void GreetsPart::MainLoop() { 1.68 + 1.69 + gc->Clear(0); 1.70 + gc->ClearZBufferStencil(1.0f, 0); 1.71 + 1.72 + Vector3 LightPosDiff(frand(0.005f) - 0.0025f, frand(0.005f) - 0.0025f, frand(0.005f) - 0.0025f); 1.73 + light->SetPosition(LightPos + LightPosDiff); 1.74 + 1.75 + light->SetIntensity(0.5f + (frand(0.1f) - 0.05f)); 1.76 + 1.77 + dword msec = timer.GetMilliSec(); 1.78 + float t = msec / 1000.0f; 1.79 + 1.80 + scene->Render(); 1.81 + 1.82 + Bottle->Render(); 1.83 + 1.84 + gc->SetLighting(false); 1.85 + int ftexnum = (int)((float)msec / 33.35f) % 52; 1.86 + gc->SetAlphaBlending(true); 1.87 + gc->SetBackfaceCulling(false); 1.88 + gc->SetBlendFunc(BLEND_ONE, BLEND_ONE); 1.89 + gc->SetTextureStageColor(0, TexBlendSelectArg1, TexArgTexture, TexArgCurrent); 1.90 + gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgTexture, TexArgTexture); 1.91 + gc->SetMaterial(Material(1.0f, 1.0f, 1.0f)); 1.92 + gc->SetTextureCoordIndex(0, 0); 1.93 + gc->SetTexture(1, 0); 1.94 + gc->SetTexture(0, FlameTex[ftexnum]); 1.95 + gc->SetWorldMatrix(flame->GetWorldTransform()); 1.96 + flame->RenderBare(); 1.97 + gc->SetBackfaceCulling(true); 1.98 + gc->SetAlphaBlending(false); 1.99 + gc->SetLighting(true); 1.100 +} 1.101 \ No newline at end of file