Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
lerp.cpp
Go to the documentation of this file.
1
#include "
lerp.h
"
2
3
Transformation
linear_interpolate_uncapped
(
const
Transformation
&A,
const
Transformation
&B,
double
blend )
4
{
5
Quaternion
result;
6
if
(0
/*A.orientation==B.orientation*/
) {
7
result = A.
orientation
;
8
}
else
{
9
const
Quaternion
&
a
= A.
orientation
;
10
const
Quaternion
&
b
= B.
orientation
;
11
double
f
= blend, f0, f1, sadj=1;
12
double
cos_omega =
DotProduct
( a.
v
, b.
v
)+a.
s
*b.
s
;
13
//Adjust signs if necessary.
14
if
(cos_omega < 0) {
15
cos_omega = -cos_omega;
16
sadj = -1;
17
}
18
if
(cos_omega < 0.99) {
19
//Do the spherical interp.
20
double
omega =
acos
( cos_omega );
21
double
isin_omega = 1.0 /
sin
( omega );
22
f0 =
sin
( (1-f)*omega ) * isin_omega;
23
f1 =
sin
( f*omega ) * isin_omega;
24
}
else
{
25
//Quaternions are close; just do straight lerp and avoid division by near-zero.
26
f0 = 1-f;
27
f1 = f;
28
}
29
result.
s
= a.
s
*
float
(f0)+b.
s
*
float
(f1*sadj);
30
result.
v
= a.
v
*
float
(f0)+b.
v
*
float
(f1*sadj);
31
result.
Normalize
();
32
}
33
return
Transformation
( result, A.
position
+(B.
position
-A.
position
)*blend );
34
}
35
src
gfx
lerp.cpp
Generated on Fri May 29 2015 23:07:24 for Vegastrike 0.5.1 rc1 by
1.8.4