24 |
#ifndef COORD_H |
#ifndef COORD_H |
25 |
#define COORD_H |
#define COORD_H |
26 |
|
|
27 |
#define SWAP(_a,_b) \ |
#include "Common/Math.h" |
|
({typeof(_a) _SWAP_aux = (_a); \ |
|
|
(_a) = (_b); (_b) = _SWAP_aux; }) |
|
28 |
|
|
29 |
/* 3D position */ |
/* 3D position */ |
30 |
typedef struct { |
typedef struct { |
72 |
static inline coord_t |
static inline coord_t |
73 |
InterpolateCoord (coord_t coord1, coord_t coord2, double t) |
InterpolateCoord (coord_t coord1, coord_t coord2, double t) |
74 |
{ |
{ |
|
NSCParameterAssert (t >= 0.0); |
|
|
NSCParameterAssert (t <= 1.0); |
|
|
|
|
75 |
return AddCoord (coord1, |
return AddCoord (coord1, |
76 |
MultCoord (SubCoord (coord2, coord1), |
MultCoord (SubCoord (coord2, coord1), |
77 |
t)); |
t)); |
80 |
static inline coord_t |
static inline coord_t |
81 |
NormalizeVector (coord_t vector) |
NormalizeVector (coord_t vector) |
82 |
{ |
{ |
83 |
double norm = sqrt(vector.x * vector.x |
double norm = sqrt(SQUARE(vector.x) |
84 |
+ vector.y * vector.y |
+ SQUARE(vector.y) |
85 |
+ vector.z * vector.z); |
+ SQUARE(vector.z)); |
86 |
|
|
87 |
NSCParemeterAssert (norm != 0); |
NSCParameterAssert (norm != 0); |
88 |
|
|
89 |
vector.x /= norm; |
vector.x /= norm; |
90 |
vector.y /= norm; |
vector.y /= norm; |