1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <sprites/DebrisActionRenderer.h>
22 #include <3dsparse/ModelStore.h>
23 #include <common/Defines.h>
24 #include <GLEXT/GLState.h>
25 #include <graph/ModelRendererStore.h>
26 #include <stdlib.h>
27 
DebrisActionRenderer()28 DebrisActionRenderer::DebrisActionRenderer() :
29 	rotationAng_(0)
30 {
31 	rotationX_ = RAND;
32 	rotationY_ = RAND;
33 	rotationZ_ = RAND;
34 	rotationSpeed_ = 90.0f + 180.0f * RAND;
35 
36 	if (RAND > 0.5f)
37 	{
38 		ModelID id;
39 		id.initFromString("ase", "data/meshes/rock1.ase",
40 			"none");
41 		debris_ = new ModelRendererSimulator(
42 			ModelRendererStore::instance()->loadModel(id));
43 	}
44 	else
45 	{
46 		ModelID id;
47 		id.initFromString("ase", "data/meshes/rock2.ase",
48 			"none");
49 		debris_ = new ModelRendererSimulator(
50 			ModelRendererStore::instance()->loadModel(id));
51 	}
52 	DIALOG_ASSERT(debris_);
53 }
54 
~DebrisActionRenderer()55 DebrisActionRenderer::~DebrisActionRenderer()
56 {
57 	delete debris_;
58 	debris_ = 0;
59 }
60 
simulate(float timepassed)61 void DebrisActionRenderer::simulate(float timepassed)
62 {
63 	rotationAng_ += timepassed * rotationSpeed_;
64 }
65 
draw(Vector & actualPos)66 void DebrisActionRenderer::draw(Vector &actualPos)
67 {
68 	GLState state(GLState::TEXTURE_OFF | GLState::BLEND_OFF);
69 
70 	glColor3f(0.3f, 0.4f, 0.3f);
71 	glPushMatrix();
72 		glTranslatef(actualPos[0], actualPos[1], actualPos[2]);
73 		glRotatef(rotationAng_, rotationX_, rotationY_, rotationZ_);
74 		debris_->draw();
75 	glPopMatrix();
76 }
77