From 160ba62230a88f589e91322655e1d85d53589289 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 31 Jul 2008 20:05:06 +0000 Subject: faster dust calculations --- src/render/dust.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/render/dust.cc') diff --git a/src/render/dust.cc b/src/render/dust.cc index 64969e3..b1d4077 100644 --- a/src/render/dust.cc +++ b/src/render/dust.cc @@ -65,6 +65,7 @@ void Dust::draw() free(dust); dust = 0; } + dustsize = 0; return; } @@ -75,14 +76,13 @@ void Dust::draw() dust = 0; } } - - dustsize = (size_t) r_dustsize->value(); - - if (!dustsize) { + + if (dustsize <= 0) { if (dust) { free(dust); dust = 0; } + dustsize = 0; return; } @@ -95,6 +95,7 @@ void Dust::draw() if (!dust) { con_debug << " generating dust..." << std::endl; + dust = (float *) malloc(sizeof(float) * dustsize* 3); for (size_t i = 0; i < dustsize; i++) { @@ -120,21 +121,20 @@ void Dust::draw() 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() + DUSTDISTANCE)*(core::localcontrol()->radius() + DUSTDISTANCE)) { - - dust[i*3] = core::localcontrol()->location().x + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius()); - dust[i*3+1] = core::localcontrol()->location().y + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius()); - dust[i*3+2] = core::localcontrol()->location().z + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius()); + float dsquare = 0; + for (size_t j = 0; j < 3; j++) { + dsquare += (core::localcontrol()->location()[j] - dust[i*3+j]) * (core::localcontrol()->location()[j] - dust[i*3+j]); + v[j] = dust[i*3+j] - Camera::eye()[j]; } - for (size_t j = 0; j < 3; j++) - v[j] = dust[i*3+j]; - v -= Camera::eye(); + if (dsquare > (core::localcontrol()->radius() + DUSTDISTANCE)*(core::localcontrol()->radius() + DUSTDISTANCE)) { + for (size_t j = 0; j < 3; j++) { + dust[i*3+j] = core::localcontrol()->location()[j] + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius()); + v[j] = dust[i*3+j] - Camera::eye()[j]; + } + } gl::vertex(v); + v -= core::localcontrol()->state()->axis().forward() * traillength; gl::vertex(v); } -- cgit v1.2.3