]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
replace sin/cos/acos based functions by cubic functions, let's see if anyone notices...
authorRudolf Polzer <divverent@xonotic.org>
Thu, 24 May 2012 09:55:09 +0000 (11:55 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Thu, 24 May 2012 09:55:09 +0000 (11:55 +0200)
qcsrc/common/util.qc
qcsrc/server/g_subs.qc

index 6e534ffc19464a92777b956353b926f48ddd578e..08744b49f1e7e2d9ba0cf09276dac7870e0407ba 100644 (file)
@@ -2415,4 +2415,26 @@ float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor)
        // (3, [0..3])
        // (3.5, [0.2..2.3])
        // (4, 1)
+
+       /*
+          On another note:
+          inflection point is always at (2s + e - 3) / (3s + 3e - 6).
+
+          s + e - 2 == 0: no inflection
+
+          s + e > 2:
+          0 < inflection < 1 if:
+          0 < 2s + e - 3 < 3s + 3e - 6
+          2s + e > 3 and 2e + s > 3
+
+          s + e < 2:
+          0 < inflection < 1 if:
+          0 > 2s + e - 3 > 3s + 3e - 6
+          2s + e < 3 and 2e + s < 3
+
+          Therefore: there is an inflection point iff:
+          e outside (3 - s)/2 .. 3 - s*2
+          
+          in other words, if (s,e) in triangle (1,1)(0,3)(0,1.5) or in triangle (1,1)(3,0)(1.5,0)
+       */
 }
index 464312b8da89e44be372c02b3b5de9286c091508..4b8ca48b38640c8617e0f04bb8d4e9d97375dc99 100644 (file)
@@ -194,6 +194,7 @@ void SUB_CalcMove_controller_think (void)
                {
                        case 1: // linear
                                break;
+                               // phasepos = cubic_speedfunc(1, 1, phasepos); // identity
                        case 2: // cosine
                                /* old version, good for mathematical reference
                                phasepos = 3.14159265 + (phasepos * 3.14159265); // range: [pi, 2pi]
@@ -202,16 +203,20 @@ void SUB_CalcMove_controller_think (void)
                                phasepos = phasepos / 2; // correct range to [0, 1]
                                */
 
-                               phasepos = (1 - cos(phasepos * 3.14159265)) / 2;
+                               // phasepos = (1 - cos(phasepos * 3.14159265)) / 2;
+                               phasepos = cubic_speedfunc(0, 0, phasepos);
                                break;
                        case 3: // inverted cosine
-                               phasepos = acos(1 - phasepos * 2) / 3.14159265;
+                               // phasepos = acos(1 - phasepos * 2) / 3.14159265;
+                               phasepos = cubic_speedfunc(2, 2, phasepos);
                                break;
                        case 4: // half cosine
-                               phasepos = (1 - cos(phasepos * (3.14159265 / 2)));
+                               // phasepos = (1 - cos(phasepos * (3.14159265 / 2)));
+                               phasepos = cubic_speedfunc(0, 1.5, phasepos);
                                break;
                        case 5: // inverted half cosine
-                               phasepos = sin(phasepos * (3.14159265 / 2));
+                               // phasepos = sin(phasepos * (3.14159265 / 2));
+                               phasepos = cubic_speedfunc(1.5, 0, phasepos);
                                break;
                }
                nextpos = self.origin + (delta * phasepos) + (delta2 * phasepos * phasepos);