From 1e1676a34a96ab7cd299829c4e33513199a97380 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 12 Jun 2013 06:14:55 +0000 Subject: [PATCH] more render improvements --- source/glest_game/game/game_camera.cpp | 6 +- source/glest_game/graphics/renderer.cpp | 4 +- source/glest_game/world/world.cpp | 2 +- .../shared_lib/include/graphics/quaternion.h | 8 +- source/shared_lib/include/graphics/vec.h | 69 ++++++----- .../graphics/gl/particle_renderer_gl.cpp | 2 +- source/shared_lib/sources/graphics/pixmap.cpp | 33 +++-- .../sources/graphics/quaternion.cpp | 114 ++++++++++-------- 8 files changed, 129 insertions(+), 109 deletions(-) diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index fe648116..b7963262 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -240,9 +240,9 @@ Quad2i GameCamera::computeVisibleQuad() { Vec2f v1(std::sin(degToRad(viewDegree - hAng - fov)), std::cos(degToRad(viewDegree - hAng - fov))); Vec2f v2(std::sin(degToRad(viewDegree - hAng + fov)), std::cos(degToRad(viewDegree - hAng + fov))); - v.normalize(false); - v1.normalize(false); - v2.normalize(false); + v.normalize(); + v1.normalize(); + v2.normalize(); Vec2f p = Vec2f(pos.x, pos.z) - v * dist; Vec2i p1(static_cast(p.x + v1.x * nearDist), static_cast(p.y + v1.y * nearDist)); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 009e719f..b7b40c04 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -8139,14 +8139,14 @@ void Renderer::renderArrow(const Vec3f &pos1, const Vec3f &pos2, const float blendDelay= 5.f; Vec3f dir= Vec3f(pos2-pos1); - float len= dir.length(false); + float len= dir.length(); if(len>maxlen) { return; } float alphaFactor= clamp((maxlen-len)/blendDelay, 0.f, 1.f); - dir.normalize(false); + dir.normalize(); Vec3f normal= dir.cross(Vec3f(0, 1, 0)); Vec3f pos2Left= pos2 + normal*(width-0.05f) - dir*arrowEndSize*width; diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index a9bd85e8..7279735d 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -2349,7 +2349,7 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) { } //explore - float posLength = currRelPos.length(); + double posLength = currRelPos.length(); //if(Vec2i(0).dist(currRelPos) < surfSightRange + indirectSightRange + 1) { if(posLength < surfSightRange + indirectSightRange + 1) { sc->setExplored(teamIndex, true); diff --git a/source/shared_lib/include/graphics/quaternion.h b/source/shared_lib/include/graphics/quaternion.h index af3d3fb6..2e8c6183 100644 --- a/source/shared_lib/include/graphics/quaternion.h +++ b/source/shared_lib/include/graphics/quaternion.h @@ -66,7 +66,7 @@ public: Quaternion(); Quaternion(float w, const Vec3f &v); Quaternion(const EulerAngles &eulerAngles); - Quaternion(const AxisAngle &axisAngle); + //Quaternion(const AxisAngle &axisAngle); //initializers void setMultIdentity(); @@ -75,9 +75,9 @@ public: void setEuler(const EulerAngles &eulerAngles); //unary operators - float length(); + //float length(); Quaternion conjugate(); - void normalize(); + //void normalize(); //binary operators Quaternion operator + (const Quaternion &q) const; @@ -91,7 +91,7 @@ public: //conversions Matrix3f toMatrix3() const; Matrix4f toMatrix4() const; - AxisAngle toAxisAngle() const; + //AxisAngle toAxisAngle() const; //local axis Vec3f getLocalXAxis() const; diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index 861754f8..ca79c58f 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -213,32 +213,36 @@ public: return x < v.x || (x == v.x && y < v.y); } - inline float length(bool requireAccuracy=true) const { -#ifdef USE_STREFLOP - if(requireAccuracy == true) { - return static_cast(streflop::sqrt(static_cast(x*x + y*y))); - } - return static_cast(std::sqrt(static_cast(x*x + y*y))); -#else - return static_cast(sqrt(static_cast(x*x + y*y))); -#endif + inline double length() const { +//#ifdef USE_STREFLOP +// if(requireAccuracy == true) { +// return static_cast(streflop::sqrt(static_cast(x*x + y*y))); +// } +// return static_cast(std::sqrt(static_cast(x*x + y*y))); +//#else +// return static_cast(sqrt(static_cast(x*x + y*y))); +//#endif + return static_cast(std::sqrt(static_cast(x*x + y*y))); } - inline void normalize(bool requireAccuracy=true){ - T m= length(requireAccuracy); + inline void normalize(){ + T m= length(); x/= m; y/= m; } - inline Vec2 rotate(float rad){ - const float -#ifdef USE_STREFLOP - c = streflop::cosf(rad), - s = streflop::sinf(rad); -#else - c = cosf(rad), - s = sinf(rad); -#endif + inline Vec2 rotate(float rad) { +// const float +//#ifdef USE_STREFLOP +// c = streflop::cosf(rad), +// s = streflop::sinf(rad); +//#else +// c = cosf(rad), +// s = sinf(rad); +//#endif + double c = std::cos(rad), + s = std::sin(rad); + return Vec2(x*c-y*s,x*s+y*c); } @@ -447,25 +451,26 @@ public: return Vec3(v-*this).length(); } - inline float length(bool requireAccuracy=true) const { -#ifdef USE_STREFLOP - if(requireAccuracy == true) { - return static_cast(streflop::sqrt(static_cast(x*x + y*y + z*z))); - } - return static_cast(std::sqrt(x*x + y*y + z*z)); -#else - return static_cast(sqrt(x*x + y*y + z*z)); -#endif + inline double length() const { +//#ifdef USE_STREFLOP +// if(requireAccuracy == true) { +// return static_cast(streflop::sqrt(static_cast(x*x + y*y + z*z))); +// } +// return static_cast(std::sqrt(x*x + y*y + z*z)); +//#else +// return static_cast(sqrt(x*x + y*y + z*z)); +//#endif + return static_cast(std::sqrt(x*x + y*y + z*z)); } - inline void normalize(bool requireAccuracy=true){ - T m= length(requireAccuracy); + inline void normalize() { + T m= length(); x/= m; y/= m; z/= m; } - inline Vec3 getNormalized() const{ + inline Vec3 getNormalized() const { T m= length(); return Vec3(x/m, y/m, z/m); } diff --git a/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp index dca3a4c3..d8d8f1ac 100644 --- a/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/particle_renderer_gl.cpp @@ -250,7 +250,7 @@ void ParticleRendererGl::renderModel(GameParticleSystem *ps, ModelRenderer *mr){ // float angleV= radToDeg(atan2(flatDirection.length(), direction.y)) - 90.f; //#endif - float angleV= radToDeg(std::atan2(flatDirection.length(false), direction.y)) - 90.f; + float angleV= radToDeg(std::atan2(flatDirection.length(), direction.y)) - 90.f; glRotatef(angleV, rotVector.x, rotVector.y, rotVector.z); //#ifdef USE_STREFLOP diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 80701290..48818605 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -1209,19 +1209,26 @@ void Pixmap2D::splat(const Pixmap2D *leftUp, const Pixmap2D *rightUp, const Pixm float distRd= splatDist(Vec2i(i, j), Vec2i(w, h)); const float powFactor= 2.0f; -#ifdef USE_STREFLOP - distLu= streflop::pow(static_cast(distLu), static_cast(powFactor)); - distRu= streflop::pow(static_cast(distRu), static_cast(powFactor)); - distLd= streflop::pow(static_cast(distLd), static_cast(powFactor)); - distRd= streflop::pow(static_cast(distRd), static_cast(powFactor)); - avg= streflop::pow(static_cast(avg), static_cast(powFactor)); -#else - distLu= pow(distLu, powFactor); - distRu= pow(distRu, powFactor); - distLd= pow(distLd, powFactor); - distRd= pow(distRd, powFactor); - avg= pow(avg, powFactor); -#endif +//#ifdef USE_STREFLOP +// distLu= streflop::pow(static_cast(distLu), static_cast(powFactor)); +// distRu= streflop::pow(static_cast(distRu), static_cast(powFactor)); +// distLd= streflop::pow(static_cast(distLd), static_cast(powFactor)); +// distRd= streflop::pow(static_cast(distRd), static_cast(powFactor)); +// avg= streflop::pow(static_cast(avg), static_cast(powFactor)); +//#else +// distLu= pow(distLu, powFactor); +// distRu= pow(distRu, powFactor); +// distLd= pow(distLd, powFactor); +// distRd= pow(distRd, powFactor); +// avg= pow(avg, powFactor); +//#endif + + distLu = std::pow(distLu, powFactor); + distRu = std::pow(distRu, powFactor); + distLd = std::pow(distLd, powFactor); + distRd = std::pow(distRd, powFactor); + avg = std::pow(avg, powFactor); + float lu= distLu>avg? 0: ((avg-distLu))*random.randRange(0.5f, 1.0f); float ru= distRu>avg? 0: ((avg-distRu))*random.randRange(0.5f, 1.0f); float ld= distLd>avg? 0: ((avg-distLd))*random.randRange(0.5f, 1.0f); diff --git a/source/shared_lib/sources/graphics/quaternion.cpp b/source/shared_lib/sources/graphics/quaternion.cpp index 28619732..cdf6df4a 100644 --- a/source/shared_lib/sources/graphics/quaternion.cpp +++ b/source/shared_lib/sources/graphics/quaternion.cpp @@ -52,9 +52,9 @@ Quaternion::Quaternion(const EulerAngles &eulerAngles){ setEuler(eulerAngles); } -Quaternion::Quaternion(const AxisAngle &axisAngle){ - setAxisAngle(axisAngle); -} +//Quaternion::Quaternion(const AxisAngle &axisAngle){ +// setAxisAngle(axisAngle); +//} void Quaternion::setMultIdentity(){ w= 1.0f; @@ -66,42 +66,50 @@ void Quaternion::setAddIdentity(){ v= Vec3f(0.0f); } -void Quaternion::setAxisAngle(const AxisAngle &axisAngle){ -#ifdef USE_STREFLOP - w= streflop::cosf(static_cast(axisAngle.angle/2.0f)); - v.x= axisAngle.axis.x * streflop::sinf(static_cast(axisAngle.angle/2.0f)); - v.y= axisAngle.axis.y * streflop::sinf(static_cast(axisAngle.angle/2.0f)); - v.z= axisAngle.axis.z * streflop::sinf(static_cast(axisAngle.angle/2.0f)); -#else - w= cosf(axisAngle.angle/2.0f); - v.x= axisAngle.axis.x * sinf(axisAngle.angle/2.0f); - v.y= axisAngle.axis.y * sinf(axisAngle.angle/2.0f); - v.z= axisAngle.axis.z * sinf(axisAngle.angle/2.0f); -#endif -} +//void Quaternion::setAxisAngle(const AxisAngle &axisAngle){ +//#ifdef USE_STREFLOP +// w= streflop::cosf(static_cast(axisAngle.angle/2.0f)); +// v.x= axisAngle.axis.x * streflop::sinf(static_cast(axisAngle.angle/2.0f)); +// v.y= axisAngle.axis.y * streflop::sinf(static_cast(axisAngle.angle/2.0f)); +// v.z= axisAngle.axis.z * streflop::sinf(static_cast(axisAngle.angle/2.0f)); +//#else +// w= cosf(axisAngle.angle/2.0f); +// v.x= axisAngle.axis.x * sinf(axisAngle.angle/2.0f); +// v.y= axisAngle.axis.y * sinf(axisAngle.angle/2.0f); +// v.z= axisAngle.axis.z * sinf(axisAngle.angle/2.0f); +//#endif +//} void Quaternion::setEuler(const EulerAngles &eulerAngles){ Quaternion qx, qy, qz, qr; -#ifdef USE_STREFLOP - qx.w= streflop::cosf(static_cast(eulerAngles.x/2.0f)); - qx.v= Vec3f(streflop::sinf(static_cast(eulerAngles.x/2.0f)), 0.0f, 0.0f); +//#ifdef USE_STREFLOP +// qx.w= streflop::cosf(static_cast(eulerAngles.x/2.0f)); +// qx.v= Vec3f(streflop::sinf(static_cast(eulerAngles.x/2.0f)), 0.0f, 0.0f); +// +// qy.w= streflop::cosf(static_cast(eulerAngles.y/2.0f)); +// qy.v= Vec3f(0.0f, streflop::sinf(static_cast(eulerAngles.y/2.0f)), 0.0f); +// +// qz.w= streflop::cosf(static_cast(eulerAngles.z/2.0f)); +// qz.v= Vec3f(0.0f, 0.0f, streflop::sinf(static_cast(eulerAngles.z/2.0f))); +//#else +// qx.w= cosf(eulerAngles.x/2.0f); +// qx.v= Vec3f(sinf(eulerAngles.x/2.0f), 0.0f, 0.0f); +// +// qy.w= cosf(eulerAngles.y/2.0f); +// qy.v= Vec3f(0.0f, sinf(eulerAngles.y/2.0f), 0.0f); +// +// qz.w= cosf(eulerAngles.z/2.0f); +// qz.v= Vec3f(0.0f, 0.0f, sinf(eulerAngles.z/2.0f)); +//#endif + qx.w= std::cos(eulerAngles.x/2.0f); + qx.v= Vec3f(std::sin(eulerAngles.x/2.0f), 0.0f, 0.0f); - qy.w= streflop::cosf(static_cast(eulerAngles.y/2.0f)); - qy.v= Vec3f(0.0f, streflop::sinf(static_cast(eulerAngles.y/2.0f)), 0.0f); + qy.w= std::cos(eulerAngles.y/2.0f); + qy.v= Vec3f(0.0f, std::sin(eulerAngles.y/2.0f), 0.0f); - qz.w= streflop::cosf(static_cast(eulerAngles.z/2.0f)); - qz.v= Vec3f(0.0f, 0.0f, streflop::sinf(static_cast(eulerAngles.z/2.0f))); -#else - qx.w= cosf(eulerAngles.x/2.0f); - qx.v= Vec3f(sinf(eulerAngles.x/2.0f), 0.0f, 0.0f); - - qy.w= cosf(eulerAngles.y/2.0f); - qy.v= Vec3f(0.0f, sinf(eulerAngles.y/2.0f), 0.0f); - - qz.w= cosf(eulerAngles.z/2.0f); - qz.v= Vec3f(0.0f, 0.0f, sinf(eulerAngles.z/2.0f)); -#endif + qz.w= std::cos(eulerAngles.z/2.0f); + qz.v= Vec3f(0.0f, 0.0f, std::sin(eulerAngles.z/2.0f)); qr= qx*qy*qz; @@ -109,23 +117,23 @@ void Quaternion::setEuler(const EulerAngles &eulerAngles){ v= qr.v; } -float Quaternion::length(){ -#ifdef USE_STREFLOP - return streflop::sqrt(static_cast(w*w+v.x*v.x+v.y*v.y+v.z*v.z)); -#else - return sqrt(w*w+v.x*v.x+v.y*v.y+v.z*v.z); -#endif -} +//float Quaternion::length(){ +//#ifdef USE_STREFLOP +// return streflop::sqrt(static_cast(w*w+v.x*v.x+v.y*v.y+v.z*v.z)); +//#else +// return sqrt(w*w+v.x*v.x+v.y*v.y+v.z*v.z); +//#endif +//} Quaternion Quaternion::conjugate(){ return Quaternion(w, -v); } -void Quaternion::normalize(){ - float il= 1.f/length(); - w*= il; - v= v*il; -} +//void Quaternion::normalize(){ +// float il= 1.f/length(); +// w*= il; +// v= v*il; +//} Quaternion Quaternion::operator + (const Quaternion &q) const{ return Quaternion(w +q.w, v+q.v); @@ -204,14 +212,14 @@ Matrix4f Quaternion::toMatrix4() const{ return rm; } -AxisAngle Quaternion::toAxisAngle() const{ - float scale= 1.0f/(v.x*v.x + v.y*v.y + v.z*v.z); -#ifdef USE_STREFLOP - return AxisAngle(v*scale, 2*streflop::acosf(static_cast(w))); -#else - return AxisAngle(v*scale, 2*acosf(w)); -#endif -} +//AxisAngle Quaternion::toAxisAngle() const{ +// float scale= 1.0f/(v.x*v.x + v.y*v.y + v.z*v.z); +//#ifdef USE_STREFLOP +// return AxisAngle(v*scale, 2*streflop::acosf(static_cast(w))); +//#else +// return AxisAngle(v*scale, 2*acosf(w)); +//#endif +//} Vec3f Quaternion::getLocalXAxis() const{ return Vec3f(