Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alphacurve.cpp
Go to the documentation of this file.
1 #include "alphacurve.h"
2 
3 //GET ALPHA CURVE
4 //***************************************************
5 //parametric Bezier curve spline for 3 points, 2 segments
6 //X(T) Y(T), where X(0) = X0, and X(1) = X1. <same for y>, hence no need for X calculations concernign Y return. but here just for kicks.
7 //***************************************************
8 int get_alpha( int _query,
9  int _maxrez_x,
10  int _min,
11  int _max,
12  double _focus,
13  double _concavity,
14  int _tail_mode_start,
15  int _tail_mode_end )
16 {
17  //INPUT
18  int query = _query;
19  int min = _min;
20  int max = _max;
21  double focus = _focus;
22  double concavity = _concavity;
23  int maxrez_x = _maxrez_x;
24  int tail_mode_start = _tail_mode_start;
25  int tail_mode_end = _tail_mode_end;
26  //INPUT
27  //FIX DATA
28  if (min < 0) min = 0; //error-test
29  if (max > 255) max = 255; //error-test
30  if (max < min) {
31  min = 0;
32  max = 255;
33  } //error-test
34  if (concavity > 1.0) concavity = 1; //error-test
35  if (concavity < -1.0) concavity = -1; //error-test
36  if (query > maxrez_x) query = maxrez_x; //error-test
37  if (query < 0) query = 0; //error-test
38  if (focus < .2) focus = .2; //error-test
39  if (focus > .8) focus = .8; //error-test
40  //TAIL MODES CAN BE NEGATIVE BECAUSE THAT IS IGNORED
41  //EXCESSIVE POSITICE VALUES WILL MAKE 255|0 RESULTS.
42  //DEPENDING ON THE RESOLUTION AND LIMITS, DIFFERENT SLOPES WILL HIT THE RANGE AT DIFFERNT SETTINGS
43  //I LEAVE THIS UNCAPPED, AND UP TO AN INTELLIGENT PERSON TO UNDERSTAND WHY IT BEHAVES SO IF THEY ENTER 10000000000
44  int half = int(maxrez_x*focus); //half-the-work-point
45  double _t = 0.0;
46  if (query > half) _t = double(query-half)/double(maxrez_x-half); //set parameter to second half
47  else _t = double(query)/double(half); //set parameter to first half
48  int center_y = int( ( ( double(max-min)/double(maxrez_x) )*(half) )+min );
49  int delta = 0; //difference from linear
50  if (concavity < 0) delta = max-center_y; //go down by concavity
51  else delta = center_y-min; //go up by convexity (-concavity)
52  //FIX DATA
53 
54  //POINTS
55 //double x0 = 0; // start point X
56  double y0 = min; //start point Y
57 //double x1 = half; // mid point X
58  double y1 = center_y-(concavity*delta);
59 //double x2 = maxrez_x; // end point X
60  double y2 = max; //end point Y
61  if (y1 > max) y1 = max; //error-test
62  if (y1 < min) y1 = min; //error-test
63  //POINTS
64 
65  //SLOPES
66 //double vx0 = double(x1-x0); // slope/T X
67  double vy0 = double(y1-y0); //slope/T Y
68 //double vx1 = double(x2-x0); // mid point slope (flat if at top/bottom, so there is no clipping, due to this, range capped to .2 -> .8 instead of 0 -> 1)
69  if (concavity < 0) concavity *= double(-1.0); //concavity ABSOLUTE
70  double vy1 = ( double(y2-y0)/double(2) )*(double(1.0)-concavity);
71 //double vx2 = double(x2-x1); // end point slope X
72  double vy2 = double(y2-y1); //end point slope Y
73  if ( !(tail_mode_start < 0) ) vy0 = tail_mode_start; //for over riding slopes 0 = flat, 100 or so = vertical
74  if ( !(tail_mode_end < 0) ) vy2 = tail_mode_end; //for over riding slopes
75  //SLOPES
76 
77  //INTERPOLATE
78 //int xt = 0;
79  int yt = 0;
80  if (query <= half) {
81  double _t0 = _t;
82 //xt = x0 + (vx0 * _t0)
83 //+ ( ((3*(x1-x0)) - ((2*vx0) + vx1) ) * pow(_t0,2) )
84 //+ ( ((2*(x0-x1))+(vx0+vx1) ) * pow(_t0,3));
85 
86  yt = int( y0+(vy0*_t0)
87  +( ( ( 3*(y1-y0) )-( (2*vy0)+vy1 ) )*pow( _t0, 2 ) )
88  +( ( ( 2*(y0-y1) )+(vy0+vy1) )*pow( _t0, 3 ) ) );
89  } else {
90  double _t1 = _t;
91 //xt = x1 + (vx1 * _t1)
92 //+ (( (3*(x2-x1)) - ((2*vx1) + vx2) ) * pow(_t1,2))
93 //+ (( (2*(x1-x2))+(vx1+vx2) ) * pow(_t1,3));
94  yt = int( y1+(vy1*_t1)
95  +( ( ( 3*(y2-y1) )-( (2*vy1)+vy2 ) )*pow( _t1, 2 ) )
96  +( ( ( 2*(y1-y2) )+(vy1+vy2) )*pow( _t1, 3 ) ) );
97  }
98  int return_alpha = yt;
99  if (return_alpha < min) return_alpha = min; //error-test
100  if (return_alpha > max) return_alpha = max; //error-test
101  //INTERPOLATE
102 
103  return return_alpha;
104 }
105 //***************************************************
106