root/OpenSceneGraph/trunk/src/osgPlugins/3ds/lib3ds/lib3ds_math.c @ 10853

Revision 10853, 2.0 kB (checked in by robert, 5 years ago)

From Sukender,
"Here is our freshly baked 3DS reader/writer (named 'v0.5' to differentiate from previous one). Changes are against trunk rev. 10819.
Short changelog (from rev 10819):
- Added 3DS writer
- Sync'd with latest lib3DS
- Added options, especially "flattenMatrixTransforms" to get the "old" behaviour (else the reader correctly maps to OSG the transforms from the 3DS file).

What should be done:
- Check with pivot points, with and without "flattenMatrixTransforms" option.
- We ran tests on it, but we can never be 100% sure there is no bug. Testing from the community would of course be helpful."

RevLine 
[10853]1/*
2    Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
3    All rights reserved.
4   
5    This program is free  software: you can redistribute it and/or modify
6    it under the terms of the GNU Lesser General Public License as published
7    by the Free Software Foundation, either version 2.1 of the License, or
8    (at your option) any later version.
9
10    Thisprogram  is  distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    GNU Lesser General Public License for more details.
14   
15    You should  have received a copy of the GNU Lesser General Public License
16    along with  this program; If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "lib3ds_impl.h"
19
20
21float
22lib3ds_math_ease(float fp, float fc, float fn, float ease_from, float ease_to) {
23    double s, step;
24    double tofrom;
25    double a;
26
27    s = step = (float)(fc - fp) / (fn - fp);
28    tofrom = ease_to + ease_from;
29    if (tofrom != 0.0) {
30        if (tofrom > 1.0) {
31            ease_to = (float)(ease_to / tofrom);
32            ease_from = (float)(ease_from / tofrom);
33        }
34        a = 1.0 / (2.0 - (ease_to + ease_from));
35
36        if (step < ease_from) s = a / ease_from * step * step;
37        else {
38            if ((1.0 - ease_to) <= step) {
39                step = 1.0 - step;
40                s = 1.0 - a / ease_to * step * step;
41            } else {
42                s = ((2.0 * step) - ease_from) * a;
43            }
44        }
45    }
46    return((float)s);
47}
48
49
50void
51lib3ds_math_cubic_interp(float *v, float *a, float *p, float *q, float *b, int n, float t) {
52    float x, y, z, w;
53    int i;
54
55    x = 2 * t * t * t - 3 * t * t + 1;
56    y = -2 * t * t * t + 3 * t * t;
57    z = t * t * t - 2 * t * t + t;
58    w = t * t * t - t * t;
59    for (i = 0; i < n; ++i) {
60        v[i] = x * a[i] + y * b[i] + z * p[i] + w * q[i];
61    }
62}
Note: See TracBrowser for help on using the browser.