From c1203c1cea66936d350ace041907a660fd8ddc15 Mon Sep 17 00:00:00 2001 From: Vincent Gee Date: Tue, 4 Nov 2014 06:51:50 -0500 Subject: [PATCH 1/2] Dev forest wind emitter improvement So the problem is that when your inside the sphere it won't render so it might make someone think that it's not working right. So what I did was determine if the camera is inside the sphere. If the camera is inside the sphere, then I find the distance from the center of the sphere to the camera Round down and use that as the radius to draw the sphere. That way if someone zooms in or out, their screen is still showing the sphere. --- Engine/source/forest/forestWindEmitter.cpp | 22 +++++++++++++++++++++- Engine/source/math/mPoint3.h | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Engine/source/forest/forestWindEmitter.cpp b/Engine/source/forest/forestWindEmitter.cpp index f997dfa94..1f59ab0e7 100644 --- a/Engine/source/forest/forestWindEmitter.cpp +++ b/Engine/source/forest/forestWindEmitter.cpp @@ -39,6 +39,8 @@ #include "T3D/gameBase/processList.h" #include "console/engineAPI.h" +#include "T3D/gameBase/gameConnection.h" + ConsoleDocClass( ForestWindEmitter, "@brief Object responsible for simulating wind in a level.\n\n" @@ -513,9 +515,27 @@ void ForestWindEmitter::_renderEmitterInfo( ObjectRenderInst *ri, SceneRenderSta drawer->drawArrow( desc, pos, pos + (windVec * mWindStrength), ColorI( 0, 0, 255, 255 ) );//Point3F( -235.214, 219.589, 34.0991 ), Point3F( -218.814, 244.731, 37.5587 ), ColorI( 255, 255, 0, 255 ) );// drawer->drawArrow( desc, pos, pos + (mWind->getTarget() * mWindStrength ), ColorI( 255, 0, 0, 85 ) ); + + S32 useRadius = mWindRadius; // Draw a 2D circle for the wind radius. if ( isRadialEmitter() ) - drawer->drawSphere( desc, mWindRadius, pos, ColorI( 255, 0, 0, 80 ) ); + { + + //So the problem is that when your inside the sphere it won't render so it might make someone + //think that it's not working right. So what I did was determine if the camera is inside the sphere. + //If the camera is inside the sphere, then I find the distance from the center of the sphere to the camera + //Round down and use that as the radius to draw the sphere. + //That way if someone zooms in or out, their screen is still showing the sphere. + GameConnection * gc = GameConnection::getConnectionToServer(); + GameBase* gb = gc->getCameraObject(); + if (gb) + { + Point3F camPos = gb->getPosition(); + if ( getPosition().isInsideSphere( camPos, mWindRadius ) ) + useRadius = getPosition().distanceTo(camPos); + } + drawer->drawSphere( desc, useRadius, pos, ColorI( 255, 0, 0, 80 ) ); + } } F32 ForestWindEmitter::getStrength() const diff --git a/Engine/source/math/mPoint3.h b/Engine/source/math/mPoint3.h index 5a85c6cd0..9a0524ad0 100644 --- a/Engine/source/math/mPoint3.h +++ b/Engine/source/math/mPoint3.h @@ -123,6 +123,22 @@ class Point3F void interpolate(const Point3F&, const Point3F&, F32); void zero(); + F32 distanceTo(Point3F loc) + { + F32 xSqr = (this->x - loc.x) * (this->x - loc.x); + F32 ySqr = (this->y - loc.y) * (this->y - loc.y); + F32 zSqr = (this->z - loc.z) * (this->z - loc.z); + + F32 mySqr = xSqr + ySqr + zSqr; + + return sqrt(mySqr); + } + + bool isInsideSphere(Point3F pt, F32 Radius) + { + return ( (( this->x - pt.x) * ( this->x - pt.x) ) + (( this->y - pt.y) * ( this->y - pt.y) ) + (( this->z - pt.z) * ( this->z - pt.z) ) <= (Radius * Radius)); + } + /// Returns the smallest absolute value. F32 least() const; From 540e68aadb2471be38e5d7994a2b33552e15364f Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Mon, 26 Jan 2015 00:16:38 +1100 Subject: [PATCH 2/2] Undid changes to Point3F. --- Engine/source/forest/forestWindEmitter.cpp | 24 ++++++++-------------- Engine/source/math/mPoint3.h | 16 --------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/Engine/source/forest/forestWindEmitter.cpp b/Engine/source/forest/forestWindEmitter.cpp index 1f59ab0e7..67dc3fc12 100644 --- a/Engine/source/forest/forestWindEmitter.cpp +++ b/Engine/source/forest/forestWindEmitter.cpp @@ -515,25 +515,19 @@ void ForestWindEmitter::_renderEmitterInfo( ObjectRenderInst *ri, SceneRenderSta drawer->drawArrow( desc, pos, pos + (windVec * mWindStrength), ColorI( 0, 0, 255, 255 ) );//Point3F( -235.214, 219.589, 34.0991 ), Point3F( -218.814, 244.731, 37.5587 ), ColorI( 255, 255, 0, 255 ) );// drawer->drawArrow( desc, pos, pos + (mWind->getTarget() * mWindStrength ), ColorI( 255, 0, 0, 85 ) ); - S32 useRadius = mWindRadius; // Draw a 2D circle for the wind radius. if ( isRadialEmitter() ) { - - //So the problem is that when your inside the sphere it won't render so it might make someone - //think that it's not working right. So what I did was determine if the camera is inside the sphere. - //If the camera is inside the sphere, then I find the distance from the center of the sphere to the camera - //Round down and use that as the radius to draw the sphere. - //That way if someone zooms in or out, their screen is still showing the sphere. - GameConnection * gc = GameConnection::getConnectionToServer(); - GameBase* gb = gc->getCameraObject(); - if (gb) - { - Point3F camPos = gb->getPosition(); - if ( getPosition().isInsideSphere( camPos, mWindRadius ) ) - useRadius = getPosition().distanceTo(camPos); - } + // If the camera is close to the sphere, shrink the sphere so it remains visible. + GameConnection* gc = GameConnection::getConnectionToServer(); + GameBase* gb; + if ( gc && (gb = gc->getCameraObject()) ) + { + F32 camDist = (gb->getPosition() - getPosition()).len(); + if ( camDist < mWindRadius ) + useRadius = camDist; + } drawer->drawSphere( desc, useRadius, pos, ColorI( 255, 0, 0, 80 ) ); } } diff --git a/Engine/source/math/mPoint3.h b/Engine/source/math/mPoint3.h index 9a0524ad0..5a85c6cd0 100644 --- a/Engine/source/math/mPoint3.h +++ b/Engine/source/math/mPoint3.h @@ -123,22 +123,6 @@ class Point3F void interpolate(const Point3F&, const Point3F&, F32); void zero(); - F32 distanceTo(Point3F loc) - { - F32 xSqr = (this->x - loc.x) * (this->x - loc.x); - F32 ySqr = (this->y - loc.y) * (this->y - loc.y); - F32 zSqr = (this->z - loc.z) * (this->z - loc.z); - - F32 mySqr = xSqr + ySqr + zSqr; - - return sqrt(mySqr); - } - - bool isInsideSphere(Point3F pt, F32 Radius) - { - return ( (( this->x - pt.x) * ( this->x - pt.x) ) + (( this->y - pt.y) * ( this->y - pt.y) ) + (( this->z - pt.z) * ( this->z - pt.z) ) <= (Radius * Radius)); - } - /// Returns the smallest absolute value. F32 least() const;