#include <valfunc.h>
Inheritance diagram for ValueFunctionPressureS:
Public Member Functions | |
virtual double | GetValue (double Position) |
To read the value of this function at a given position. | |
virtual ValueFunctionID | GetUniqueID (void) |
Protected Member Functions | |
virtual ValueFunctionPressure * | CreateInstance (void) |
Creates a new blank object of the same type as this one. Internal function used in ValueFunctionPressure & ValueFunctionPressureS. | |
Private Member Functions | |
CC_DECLARE_DYNAMIC (ValueFunctionPressureS) |
Definition at line 902 of file valfunc.h.
|
|
|
Creates a new blank object of the same type as this one. Internal function used in ValueFunctionPressure & ValueFunctionPressureS.
Reimplemented from ValueFunctionPressure. Definition at line 3409 of file valfunc.cpp. 03410 { 03411 return(new ValueFunctionPressureS); 03412 }
|
|
Reimplemented from ValueFunctionPressure. Definition at line 909 of file valfunc.h. 00909 { return(ValueFunctionID_PressureS); };
|
|
To read the value of this function at a given position.
The "curve" may be improved in future, but is currently a simple linear interpolation. !!!!TODO: This could cache the last array index it was asked for, and start the search from that index, as we usually ask for values for sequential, close, position values, and this will reduce the searching overhead in most cases. Note that we may step through positions in both positive & negative directions, so it will have to handle this carefully. Note that PressureS functions seldom have very many samples recorded in their tables, due to my wonderfully rampant smoothing, so this may not turn out to be very beneficial. Reimplemented from ValueFunctionPressure. Definition at line 3340 of file valfunc.cpp. 03341 { 03342 // No entries have been recorded! 03343 if (NextFree < 1) 03344 return(0.0); 03345 03346 // If the position is outside the range in our table, return the closest entry 03347 if (Position <= pArray[0].Position) 03348 return(pArray[0].Pressure); 03349 03350 if (Position >= pArray[NextFree-1].Position) 03351 return(pArray[NextFree-1].Pressure); 03352 03353 // Search to find the closest 2 array entries to the position 03354 // We assume the array fills the 0.0 to 1.0 range, so we search from the closest 03355 // "end" of the array to halve the average search time. 03356 INT32 i; 03357 if (Position >= 0.5) 03358 { 03359 i = NextFree; 03360 while (i > 1 && Position < pArray[i-1].Position) 03361 i--; 03362 } 03363 else 03364 { 03365 i = 1; 03366 while (i < NextFree && Position > pArray[i].Position) 03367 i++; 03368 } 03369 03370 ERROR3IF(i < 1 || i >= NextFree, "I've screwed up the scanning loop code (1)"); 03371 ERROR3IF(Position < pArray[i-1].Position || Position > pArray[i].Position, 03372 "I've screwed up the scanning loop code (2)"); 03373 03374 // Otherwise, the position lies between array elements [i-1] and [i], so we 03375 // interpolate between these positions 03376 ERROR3IF((pArray[i].Position - pArray[i-1].Position) <= 0.0, "Pressure array is non-ascending!"); 03377 double MixValue = (Position - pArray[i-1].Position) / 03378 (pArray[i].Position - pArray[i-1].Position); 03379 03380 // And convert the linear mix value into a nice S-curve (180 degrees of sine wave) 03381 // We use a different function on the first and last segments so that you get nicer 03382 // ends to your strokes. (90 degrees of sine wave) 03383 if (i < 2 || i >= NextFree - 1) 03384 MixValue = cos(-MixValue * (Pi / 2.0)); 03385 else 03386 MixValue = (cos(MixValue * Pi) + 1.0) / 2.0; 03387 03388 return((MixValue * pArray[i-1].Pressure) + ((1.0 - MixValue) * pArray[i].Pressure)); 03389 }
|