absence_thelab

diff src/treepart.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/treepart.cpp	Thu Oct 23 01:46:07 2014 +0300
     1.3 @@ -0,0 +1,156 @@
     1.4 +#include "treepart.h"
     1.5 +
     1.6 +TreePart::TreePart(GraphicsContext *gc) {
     1.7 +	this->gc = gc;
     1.8 +
     1.9 +	scene = new Scene(gc);
    1.10 +/*
    1.11 +	LeavesParticle = gc->texman->AddTexture("data/textures/leaf.png");
    1.12 +
    1.13 +	leaves = new ParticleSystem(gc);
    1.14 +	leaves->SetPosition(Vector3(0.0f, 800.0f, 0.0f));
    1.15 +	leaves->SetGravitualForce(0.8f);
    1.16 +	leaves->SetFriction(0.05f);
    1.17 +	leaves->SetInitialColor(0.6f, 0.5f, 0.5f);
    1.18 +	leaves->SetDeathColor(0.6f, 0.5f, 0.5f);
    1.19 +	leaves->SetParticleSize(6.0f);
    1.20 +	leaves->SetParticleLife(1000);
    1.21 +	leaves->SetSpawnRadius(1500.0f);
    1.22 +	leaves->SetSpawnRate(20.0f);
    1.23 +	leaves->SetTexture(LeavesParticle);
    1.24 +	leaves->SetShootDirection(Vector3(0.0f, -10.0f, 0.0f));
    1.25 +	leaves->SetMaxDispersionAngle(QuarterPi / 2.0f);
    1.26 +	leaves->SetBlendingMode(BLEND_SRCALPHA, BLEND_INVSRCALPHA);
    1.27 +*/
    1.28 +	WispParticle = gc->texman->AddTexture("data/textures/psys02.jpg");
    1.29 +    
    1.30 +	for(int i=0; i<4; i++) {
    1.31 +        WispParticles[i] = new ParticleSystem(gc);
    1.32 +		WispParticles[i]->SetGravitualForce(0.8f);
    1.33 +		WispParticles[i]->SetFriction(0.06f);
    1.34 +		WispParticles[i]->SetInitialColor(0.7f, 0.8f, 1.0f);
    1.35 +		WispParticles[i]->SetDeathColor(0.2f, 0.2f, 0.5f);
    1.36 +		WispParticles[i]->SetParticleSize(7.5f);
    1.37 +		WispParticles[i]->SetParticleLife(15);
    1.38 +		WispParticles[i]->SetSpawnRadius(0.2f);
    1.39 +		WispParticles[i]->SetSpawnRate(4.0f);
    1.40 +		WispParticles[i]->SetTexture(WispParticle);
    1.41 +		WispParticles[i]->SetShootDirection(Vector3(0.0f, 0.0f, 0.0f));
    1.42 +		WispParticles[i]->SetMaxDispersionAngle(QuarterPi / 2.0f);
    1.43 +		WispParticles[i]->SetBlendingMode(BLEND_ONE, BLEND_ONE);
    1.44 +		WispParticles[i]->SetSpawningDifferenceDispersion(1.0f);
    1.45 +	}
    1.46 +	
    1.47 +	SceneLoader::SetNormalFileSaving(true);
    1.48 +	SceneLoader::SetDataPath("data/textures/");
    1.49 +	SceneLoader::LoadScene("data/geometry/tree2.3ds", &scene);
    1.50 +
    1.51 +	Trees = scene->GetObject("Trees");
    1.52 +	scene->RemoveObject(Trees);
    1.53 +
    1.54 +	for(int i=0; i<3; i++) {
    1.55 +		dummy[i] = new Camera;
    1.56 +	}
    1.57 +
    1.58 +	Object *graves = scene->GetObject("Graves");
    1.59 +	//graves->SetShadowCasting(true);
    1.60 +    
    1.61 +	WispPath[0] = scene->GetCurve("wisp1");
    1.62 +	WispPath[1] = scene->GetCurve("wisp2");
    1.63 +	WispPath[2] = scene->GetCurve("wisp3");
    1.64 +	
    1.65 +	WispPath[0]->SetArcParametrization(true);
    1.66 +	WispPath[1]->SetArcParametrization(true);
    1.67 +	WispPath[2]->SetArcParametrization(true);
    1.68 +
    1.69 +	dummy[0]->SetCameraPath(WispPath[0], 0, 0, 8000);
    1.70 +	dummy[1]->SetCameraPath(WispPath[1], 0, 0, 7000);
    1.71 +	dummy[2]->SetCameraPath(WispPath[2], 0, 0, 10000);
    1.72 +	
    1.73 +	lights[0] = scene->GetLight("wispl1");
    1.74 +	lights[1] = scene->GetLight("wispl2");
    1.75 +	lights[2] = scene->GetLight("wispl3");
    1.76 +	lights[3] = scene->GetLight("wispl04");
    1.77 +
    1.78 +	for(int i=0; i<3; i++) {
    1.79 +		lights[i]->SetRange(250.0f);
    1.80 +		lights[i]->SetColor(Color(0.6f, 0.6f, 0.9f));
    1.81 +	}
    1.82 +	lights[3]->SetColor(Color(0.6f, 0.6f, 0.9f));
    1.83 +
    1.84 +	CamPath = scene->GetCurve("cpath01");
    1.85 +	TargPath = scene->GetCurve("ctarget01");
    1.86 +	
    1.87 +	CamPath->SetArcParametrization(true);
    1.88 +	TargPath->SetArcParametrization(true);
    1.89 +
    1.90 +	cam = scene->GetCamera("Camera02");
    1.91 +	cam->SetClippingPlanes(1.0f, 80000.0f);
    1.92 +	cam->SetCameraPath(CamPath, TargPath, 0, 40000);
    1.93 +	scene->SetActiveCamera(cam);
    1.94 +
    1.95 +	//scene->SetShadows(true);
    1.96 +	//lights[3]->SetShadowCasting(true);
    1.97 +
    1.98 +	Moon = scene->GetObject("Moon");
    1.99 +	scene->RemoveObject(Moon);
   1.100 +
   1.101 +	Stars = scene->GetObject("StarDome");
   1.102 +	scene->RemoveObject(Stars);
   1.103 +
   1.104 +}
   1.105 +
   1.106 +TreePart::~TreePart() {
   1.107 +	delete scene;
   1.108 +	delete leaves;
   1.109 +}
   1.110 +
   1.111 +void TreePart::MainLoop() {
   1.112 +	dword msec = timer.GetMilliSec();
   1.113 +	float t = msec / 1000.0f;
   1.114 +
   1.115 +	float start = 10.0f;
   1.116 +	float end = 10500.0f;
   1.117 +	
   1.118 +	gc->D3DDevice->SetRenderState(D3DRS_FOGENABLE, true);
   1.119 +	gc->D3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
   1.120 +	gc->D3DDevice->SetRenderState(D3DRS_FOGCOLOR, 0);
   1.121 +    gc->D3DDevice->SetRenderState(D3DRS_FOGSTART, *(dword*)(&start));
   1.122 +	gc->D3DDevice->SetRenderState(D3DRS_FOGEND, *(dword*)(&end));
   1.123 +
   1.124 +	cam->FollowPath(msec);
   1.125 +	for(int i=0; i<3; i++) {
   1.126 +		dummy[i]->FollowPath(msec, true);
   1.127 +		lights[i]->SetPosition(dummy[i]->GetPosition());
   1.128 +	}
   1.129 +	lights[3]->SetPosition(cam->GetTargetPosition());
   1.130 +
   1.131 +	gc->Clear(0);
   1.132 +	gc->ClearZBufferStencil(1.0f, 0);
   1.133 +
   1.134 +	scene->Render();
   1.135 +	
   1.136 +	gc->SetZWrite(false);
   1.137 +	Trees->Render();
   1.138 +	gc->SetZWrite(true);
   1.139 +
   1.140 +	//for(int i=0; i<3; i++) {
   1.141 +	//	lights[i]->Draw(gc, 20.0f);
   1.142 +	//}
   1.143 +	//lights[3]->Draw(gc, 30.0f);
   1.144 +
   1.145 +	gc->D3DDevice->SetRenderState(D3DRS_FOGENABLE, false);
   1.146 +
   1.147 +	//leaves->Update(t);
   1.148 +	//leaves->Render();
   1.149 +
   1.150 +	Stars->Render();
   1.151 +	Moon->Render();
   1.152 +
   1.153 +	for(int i=0; i<4; i++) {
   1.154 +        WispParticles[i]->SetPosition(Vector3(lights[i]->GetPosition()));
   1.155 +		WispParticles[i]->Update(t);
   1.156 +		WispParticles[i]->Render();
   1.157 +	}
   1.158 +}
   1.159 +