absence_thelab

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