absence_thelab

view src/treepart.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 "treepart.h"
3 TreePart::TreePart(GraphicsContext *gc) {
4 this->gc = gc;
6 scene = new Scene(gc);
7 /*
8 LeavesParticle = gc->texman->AddTexture("data/textures/leaf.png");
10 leaves = new ParticleSystem(gc);
11 leaves->SetPosition(Vector3(0.0f, 800.0f, 0.0f));
12 leaves->SetGravitualForce(0.8f);
13 leaves->SetFriction(0.05f);
14 leaves->SetInitialColor(0.6f, 0.5f, 0.5f);
15 leaves->SetDeathColor(0.6f, 0.5f, 0.5f);
16 leaves->SetParticleSize(6.0f);
17 leaves->SetParticleLife(1000);
18 leaves->SetSpawnRadius(1500.0f);
19 leaves->SetSpawnRate(20.0f);
20 leaves->SetTexture(LeavesParticle);
21 leaves->SetShootDirection(Vector3(0.0f, -10.0f, 0.0f));
22 leaves->SetMaxDispersionAngle(QuarterPi / 2.0f);
23 leaves->SetBlendingMode(BLEND_SRCALPHA, BLEND_INVSRCALPHA);
24 */
25 WispParticle = gc->texman->AddTexture("data/textures/psys02.jpg");
27 for(int i=0; i<4; i++) {
28 WispParticles[i] = new ParticleSystem(gc);
29 WispParticles[i]->SetGravitualForce(0.8f);
30 WispParticles[i]->SetFriction(0.06f);
31 WispParticles[i]->SetInitialColor(0.7f, 0.8f, 1.0f);
32 WispParticles[i]->SetDeathColor(0.2f, 0.2f, 0.5f);
33 WispParticles[i]->SetParticleSize(7.5f);
34 WispParticles[i]->SetParticleLife(15);
35 WispParticles[i]->SetSpawnRadius(0.2f);
36 WispParticles[i]->SetSpawnRate(4.0f);
37 WispParticles[i]->SetTexture(WispParticle);
38 WispParticles[i]->SetShootDirection(Vector3(0.0f, 0.0f, 0.0f));
39 WispParticles[i]->SetMaxDispersionAngle(QuarterPi / 2.0f);
40 WispParticles[i]->SetBlendingMode(BLEND_ONE, BLEND_ONE);
41 WispParticles[i]->SetSpawningDifferenceDispersion(1.0f);
42 }
44 SceneLoader::SetNormalFileSaving(true);
45 SceneLoader::SetDataPath("data/textures/");
46 SceneLoader::LoadScene("data/geometry/tree2.3ds", &scene);
48 Trees = scene->GetObject("Trees");
49 scene->RemoveObject(Trees);
51 for(int i=0; i<3; i++) {
52 dummy[i] = new Camera;
53 }
55 Object *graves = scene->GetObject("Graves");
56 //graves->SetShadowCasting(true);
58 WispPath[0] = scene->GetCurve("wisp1");
59 WispPath[1] = scene->GetCurve("wisp2");
60 WispPath[2] = scene->GetCurve("wisp3");
62 WispPath[0]->SetArcParametrization(true);
63 WispPath[1]->SetArcParametrization(true);
64 WispPath[2]->SetArcParametrization(true);
66 dummy[0]->SetCameraPath(WispPath[0], 0, 0, 8000);
67 dummy[1]->SetCameraPath(WispPath[1], 0, 0, 7000);
68 dummy[2]->SetCameraPath(WispPath[2], 0, 0, 10000);
70 lights[0] = scene->GetLight("wispl1");
71 lights[1] = scene->GetLight("wispl2");
72 lights[2] = scene->GetLight("wispl3");
73 lights[3] = scene->GetLight("wispl04");
75 for(int i=0; i<3; i++) {
76 lights[i]->SetRange(250.0f);
77 lights[i]->SetColor(Color(0.6f, 0.6f, 0.9f));
78 }
79 lights[3]->SetColor(Color(0.6f, 0.6f, 0.9f));
81 CamPath = scene->GetCurve("cpath01");
82 TargPath = scene->GetCurve("ctarget01");
84 CamPath->SetArcParametrization(true);
85 TargPath->SetArcParametrization(true);
87 cam = scene->GetCamera("Camera02");
88 cam->SetClippingPlanes(1.0f, 80000.0f);
89 cam->SetCameraPath(CamPath, TargPath, 0, 40000);
90 scene->SetActiveCamera(cam);
92 //scene->SetShadows(true);
93 //lights[3]->SetShadowCasting(true);
95 Moon = scene->GetObject("Moon");
96 scene->RemoveObject(Moon);
98 Stars = scene->GetObject("StarDome");
99 scene->RemoveObject(Stars);
101 }
103 TreePart::~TreePart() {
104 delete scene;
105 delete leaves;
106 }
108 void TreePart::MainLoop() {
109 dword msec = timer.GetMilliSec();
110 float t = msec / 1000.0f;
112 float start = 10.0f;
113 float end = 10500.0f;
115 gc->D3DDevice->SetRenderState(D3DRS_FOGENABLE, true);
116 gc->D3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
117 gc->D3DDevice->SetRenderState(D3DRS_FOGCOLOR, 0);
118 gc->D3DDevice->SetRenderState(D3DRS_FOGSTART, *(dword*)(&start));
119 gc->D3DDevice->SetRenderState(D3DRS_FOGEND, *(dword*)(&end));
121 cam->FollowPath(msec);
122 for(int i=0; i<3; i++) {
123 dummy[i]->FollowPath(msec, true);
124 lights[i]->SetPosition(dummy[i]->GetPosition());
125 }
126 lights[3]->SetPosition(cam->GetTargetPosition());
128 gc->Clear(0);
129 gc->ClearZBufferStencil(1.0f, 0);
131 scene->Render();
133 gc->SetZWrite(false);
134 Trees->Render();
135 gc->SetZWrite(true);
137 //for(int i=0; i<3; i++) {
138 // lights[i]->Draw(gc, 20.0f);
139 //}
140 //lights[3]->Draw(gc, 30.0f);
142 gc->D3DDevice->SetRenderState(D3DRS_FOGENABLE, false);
144 //leaves->Update(t);
145 //leaves->Render();
147 Stars->Render();
148 Moon->Render();
150 for(int i=0; i<4; i++) {
151 WispParticles[i]->SetPosition(Vector3(lights[i]->GetPosition()));
152 WispParticles[i]->Update(t);
153 WispParticles[i]->Render();
154 }
155 }