absence_thelab
view src/greetspart.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 "greetspart.h"
2 #include "nwt/widget.h"
4 extern Widget *win;
6 GreetsPart::GreetsPart(GraphicsContext *gc) {
7 this->gc = gc;
9 gc->Clear(0);
10 gc->ClearZBufferStencil(1.0f, 0);
13 SceneLoader::SetNormalFileSaving(false);
14 SceneLoader::SetDataPath("data/textures/");
15 SceneLoader::LoadScene("data/geometry/greets.3ds", &scene);
16 SceneLoader::SetNormalFileSaving(true);
18 Parchment = scene->GetObject("Plane01");
19 //Scroll1 = scene->GetObject("Object01");
20 //Scroll2 = scene->GetObject("Object02");
22 // load the flame textures
23 for(int i=0; i<52; i++) {
24 char num[3];
25 itoa(i, num, 10);
26 string fname = string("data/textures/flame/flame") + (i < 10 ? string("0") : string("")) + string(num) + string(".jpg");
27 FlameTex[i] = gc->texman->LoadTexture(fname.c_str());
28 }
30 flame = scene->GetObject("Plane02");
31 scene->RemoveObject(flame);
33 Parchment->SetScaling(9.0f, 1.0f, 1.0f);
35 Bottle = scene->GetObject("Bottle");
36 scene->RemoveObject(Bottle);
38 light = scene->GetLight("Omni01");
40 scene->SetShadows(true);
41 light->SetShadowCasting(true);
42 //scene->GetObject("CHolder")->SetShadowCasting(true);
43 scene->GetObject("Candle")->SetShadowCasting(true);
44 //scene->GetObject("Bottle01")->SetShadowCasting(true);
46 const Light *l[] = {light};
47 scene->GetObject("Cylinder01")->CalculateShadows(l, 1);
48 scene->GetObject("Cylinder02")->CalculateShadows(l, 1);
49 scene->GetObject("Bottle01")->CalculateShadows(l, 1);
50 scene->GetObject("Plane01")->CalculateShadows(l, 1);
52 scene->SetAmbientLight(Color(0.58f, 0.3f, 0.3f));
54 LightPos = light->GetPosition();
55 light->SetIntensity(0.5f);
56 light->SetAttenuation(0.0f, 0.1f, 0.0f);
58 }
60 GreetsPart::~GreetsPart() {
61 delete scene;
62 }
64 void GreetsPart::MainLoop() {
66 gc->Clear(0);
67 gc->ClearZBufferStencil(1.0f, 0);
69 Vector3 LightPosDiff(frand(0.005f) - 0.0025f, frand(0.005f) - 0.0025f, frand(0.005f) - 0.0025f);
70 light->SetPosition(LightPos + LightPosDiff);
72 light->SetIntensity(0.5f + (frand(0.1f) - 0.05f));
74 dword msec = timer.GetMilliSec();
75 float t = msec / 1000.0f;
77 scene->Render();
79 Bottle->Render();
81 gc->SetLighting(false);
82 int ftexnum = (int)((float)msec / 33.35f) % 52;
83 gc->SetAlphaBlending(true);
84 gc->SetBackfaceCulling(false);
85 gc->SetBlendFunc(BLEND_ONE, BLEND_ONE);
86 gc->SetTextureStageColor(0, TexBlendSelectArg1, TexArgTexture, TexArgCurrent);
87 gc->SetTextureStageAlpha(0, TexBlendSelectArg1, TexArgTexture, TexArgTexture);
88 gc->SetMaterial(Material(1.0f, 1.0f, 1.0f));
89 gc->SetTextureCoordIndex(0, 0);
90 gc->SetTexture(1, 0);
91 gc->SetTexture(0, FlameTex[ftexnum]);
92 gc->SetWorldMatrix(flame->GetWorldTransform());
93 flame->RenderBare();
94 gc->SetBackfaceCulling(true);
95 gc->SetAlphaBlending(false);
96 gc->SetLighting(true);
97 }