|
From: <cn...@us...> - 2010-03-03 09:07:43
|
Revision: 685
http://hgengine.svn.sourceforge.net/hgengine/?rev=685&view=rev
Author: cnlohr
Date: 2010-03-03 09:07:37 +0000 (Wed, 03 Mar 2010)
Log Message:
-----------
add utility functions for new tweening template thingie that will be coming soon.
Modified Paths:
--------------
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2010-03-03 08:51:22 UTC (rev 684)
+++ Mercury2/src/MercuryUtil.cpp 2010-03-03 09:07:37 UTC (rev 685)
@@ -3,6 +3,7 @@
#include <Mint.h>
#include <MercuryVector.h>
#include <MercuryBacktrace.h>
+#include <math.h>
#ifdef WIN32
#include <Windows.h>
@@ -298,6 +299,34 @@
#endif
}
+float FLinear( float in, float slice )
+{
+ float fret = (in - 0.5) * slice;
+
+ if( fret > 0.5 ) fret = 0.5;
+ else if( fret < -0.5 ) fret = -0.5;
+ return fret + 0.5;
+}
+
+float FExponential( float in, float powx )
+{
+ return pow( in, powx );
+}
+
+float FStep( float in, float stepplace )
+{
+ return ( in < stepplace )?0:1;
+}
+
+float FSigmoid( float in, float fspeed )
+{
+ float fi = in - 0.5;
+ float fr = ( exp( fi * fspeed ) - 1 ) / ( exp( fi * fspeed ) + 1 );
+ float smax = ( exp( fspeed * 0.5 ) - 1 ) / ( exp( fspeed * 0.5 ) + 1 );
+ return (fr / smax) / 2. + 0.5;
+}
+
+
/* Copyright (c) 2009, Joshua Allen and Charles Lohr
* All rights reserved.
*
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2010-03-03 08:51:22 UTC (rev 684)
+++ Mercury2/src/MercuryUtil.h 2010-03-03 09:07:37 UTC (rev 685)
@@ -135,7 +135,19 @@
MString ConvertToUnformatted( const MString & cf );
///millisecond sleep
-void msleep(uint32_t msec);
+void msleep(uint32_t msec);
+
+///Utility linear function, in = [0..1] out = [0..1]; respectively, if slice >= 1
+float FLinear( float in, float slice = 1. );
+
+///Utility exponential function, in = [0..1] out = [0..1]; respectively; regardless of pow. If pow == 1, would be identical to linear.
+float FExponential( float in, float powx = 1. );
+
+///Utility step function; out = 0 when in < stepplace; out = 1 when in >= stepplace
+float FStep( float in, float stepplace = 1. );
+
+///Utility sigmoid function; in = [0..1] out = [0..1]; speed is the slope of change in the middle.
+float FSigmoid( float in, float fspeed = 1. );
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|