Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-18 00:13:07 +0000
committerStijn Buys <ingar@osirion.org>2008-07-18 00:13:07 +0000
commitd419f413daa75262cbf9ba3eb271c4028b0b6921 (patch)
tree0d1682946e3b206174839f5ca9fad231f18c9d10 /src
parente7cd0386ce564a4ac1c6ba866afeda54e6e8d1d9 (diff)
oops
Diffstat (limited to 'src')
-rw-r--r--src/render/dust.cc137
-rw-r--r--src/render/dust.h27
2 files changed, 164 insertions, 0 deletions
diff --git a/src/render/dust.cc b/src/render/dust.cc
new file mode 100644
index 0000000..b9e53a5
--- /dev/null
+++ b/src/render/dust.cc
@@ -0,0 +1,137 @@
+/*
+ render/dust.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "render/dust.h"
+#include "render/gl.h"
+#include "core/cvar.h"
+#include "core/core.h"
+#include "math/functions.h"
+#include "sys/sys.h"
+
+namespace render
+{
+
+core::Cvar *r_dust;
+core::Cvar *r_dustsize;
+
+const float MAXDUSTDISTANCE = 8.0f;
+const float MINDUSTDISTANCE = 6.0f;
+const float LOWSPEEDLIMIT = 5.0f;
+const float TRAILLENGHT = 0.25f;
+const float MAXDUSTALPHA = 0.8f;
+float *dust;
+size_t dustsize;
+
+void Dust::init()
+{
+ r_dust = core::Cvar::get("r_dust", "1", core::Cvar::Archive);
+ r_dust->set_info("[bool] render dust");
+
+ r_dustsize = core::Cvar::get("r_dustsize", "128", core::Cvar::Archive);
+ r_dustsize->set_info("[bool] number of dust particles");
+
+ dust = 0;
+ dustsize = (size_t) r_dustsize->value();
+}
+
+void Dust::shutdown()
+{
+ if (dust) {
+ delete dust;
+ dust = 0;
+ dustsize = 0;
+ }
+}
+
+void Dust::draw()
+{
+ if (!r_dust->value()) {
+ if (dust) {
+ delete dust;
+ dust = 0;
+ }
+ return;
+ }
+
+ if (!core::localcontrol()) {
+ return;
+ }
+
+ if ((size_t) r_dustsize->value() != dustsize) {
+ con_debug << " changing dust size..." << std::endl;
+ if (dust) {
+ delete dust;
+ dust = 0;
+ }
+ }
+
+ dustsize = (size_t) r_dustsize->value();
+
+ if (!dustsize) {
+ if (dust) {
+ delete dust;
+ dust = 0;
+ }
+ return;
+ }
+
+ if (!dust) {
+ con_debug << " generating dust..." << std::endl;
+ dust = new float[dustsize*3];
+
+ for (size_t i = 0; i < dustsize; i++) {
+ dust[i*3] = core::localcontrol()->location().x + (math::randomf(2) - 1) * MINDUSTDISTANCE;
+ dust[i*3+1] = core::localcontrol()->location().y + (math::randomf(2) - 1) * MINDUSTDISTANCE;
+ dust[i*3+2] = core::localcontrol()->location().z + (math::randomf(2) - 1) * MINDUSTDISTANCE;
+ }
+ }
+
+ if (!core::localcontrol()->speed())
+ return;
+
+ math::Color color;
+ if (core::localcontrol()->speed() < LOWSPEEDLIMIT) {
+ color.a = core::localcontrol()->speed() / LOWSPEEDLIMIT;
+ }
+ color.a *= MAXDUSTALPHA;
+
+ gl::color(color);
+ gl::begin(gl::Lines);
+ math::Vector3f v;
+
+ for (size_t i = 0; i < dustsize; i++) {
+ v.assign(core::localcontrol()->location());
+ for (size_t j = 0; j < 3; j++)
+ v[j] -= dust[i*3+j];
+
+ if (v.lengthsquared() > (core::localcontrol()->radius() + MAXDUSTDISTANCE)*(core::localcontrol()->radius() + MAXDUSTDISTANCE)) {
+/*
+ v.assign(core::localcontrol()->state()->location());
+ v += core::localcontrol()->state()->axis().forward() * (core::localcontrol()->radius() + math::randomf(MAXDUSTDISTANCE));
+ v += core::localcontrol()->state()->axis().left() * (math::randomf(2*MINDUSTDISTANCE) - MINDUSTDISTANCE);
+ v += core::localcontrol()->state()->axis().up() * (math::randomf(2*MINDUSTDISTANCE) - MINDUSTDISTANCE);
+
+ for (size_t j = 0; j < 3; j++)
+ dust[i*3+j] = v[j];
+*/
+ dust[i*3] = core::localcontrol()->location().x + (math::randomf(2) - 1) * (MAXDUSTDISTANCE + core::localcontrol()->radius());
+ dust[i*3+1] = core::localcontrol()->location().y + (math::randomf(2) - 1) * (MAXDUSTDISTANCE + core::localcontrol()->radius());
+ dust[i*3+2] = core::localcontrol()->location().z + (math::randomf(2) - 1) * (MAXDUSTDISTANCE + core::localcontrol()->radius());
+ }
+
+ glVertex3fv(dust+3*i);
+
+ for (size_t j = 0; j < 3; j++)
+ v[j] = dust[i*3+j];
+ v -= core::localcontrol()->state()->axis().forward() * color.a * TRAILLENGHT;
+ gl::vertex(v);
+ }
+
+ gl::end();
+}
+
+}
+
diff --git a/src/render/dust.h b/src/render/dust.h
new file mode 100644
index 0000000..031743e
--- /dev/null
+++ b/src/render/dust.h
@@ -0,0 +1,27 @@
+/*
+ render/text.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_RENDER_DUST_H__
+#define __INCLUDED_RENDER_DUST_H__
+
+namespace render
+{
+
+/// class to render space dust
+class Dust
+{
+public:
+
+ static void init();
+
+ static void shutdown();
+
+ static void draw();
+};
+
+}
+
+#endif