📄 ivu_linear.hxx
字号:
inline void inline_set_vert_to_area_defined_by_three_points(const IVP_U_Point *tp0,const IVP_U_Point *tp1,const IVP_U_Point *tp2);
inline void inline_set_vert_to_area_defined_by_three_points(const IVP_U_Float_Point *tp0,const IVP_U_Float_Point *tp1,const IVP_U_Point *tp2);
inline void inline_set_vert_to_area_defined_by_three_points(const IVP_U_Float_Point *tp0,const IVP_U_Float_Point *tp1,const IVP_U_Float_Point *tp2);
void set_interpolate(const IVP_U_Point *p0,const IVP_U_Point *p1, IVP_DOUBLE s); /* linear interpolation between p0 and p1:
* this = p1 * s + p0 * (1.0f-s) */
void set_interpolate(const IVP_U_Float_Point *p0,const IVP_U_Float_Point *p1, IVP_DOUBLE s); /* linear interpolation between p0 and p1:
* this = p1 * s + p0 * (1.0f-s) */
#endif
/***** The following function change 'this' ****/
// INTERN_START
IVP_BOOL is_parallel(const IVP_U_Point *v2, IVP_DOUBLE eps) const; // checks length of crossproduct against eps
void calc_an_orthogonal(const IVP_U_Point *ip);
void solve_quadratic_equation_fast(const IVP_U_Point *a); /* Solve a->k[0]*x*x + a->k[1]*x + a->k[2] = 0,
* this->k[0] = term under squareroot, this->k[1] = smaller value
* this->k[2] = greater value,
* if this->k[0] < 0: no result.
* Uses fast squareroot */
void solve_quadratic_equation_accurate(const IVP_U_Point *a); /* Solve a->k[0]*x*x + a->k[1]*x + a->k[2] = 0,
* this->k[0] = term under squareroot, this->k[1] = smaller value
* this->k[2] = greater value,
* if this->k[0] < 0: no result. */
// INTERN_END
void set_orthogonal_part(const IVP_U_Point *vector,const IVP_U_Point *normal_v); //project vector on surface given by normal_v
void set_orthogonal_part(const IVP_U_Point *vector,const IVP_U_Float_Point *normal_v); //project vector on surface given by normal_v
IVP_RETURN_TYPE set_crossing(IVP_U_Hesse *h0, IVP_U_Hesse *h1, IVP_U_Hesse *h2); // set this to the crossing of three areas
void rotate(IVP_COORDINATE_INDEX axis, IVP_FLOAT angle); // rotate the point around origin
void line_min(const IVP_U_Point *p); // sets this to linewise min
void line_max(const IVP_U_Point *p); // sets this to linewise max
void print(const char *comment = 0);
IVP_U_Point(){;};
inline IVP_U_Point(const IVP_U_Float_Point &p);
IVP_U_Point(IVP_DOUBLE x, IVP_DOUBLE y,IVP_DOUBLE z){ k[0] = x; k[1] = y; k[2] = z;};
inline void byte_swap() { IVP_ASSERT( 0 && "No byte swap for doubles yet"); CORE; }
} IVP_ALIGN_16;
class IVP_Inline_Math {
public:
static inline IVP_RETURN_TYPE invert_2x2_matrix(const IVP_DOUBLE a1_in, const IVP_DOUBLE b1_in,
const IVP_DOUBLE a2_in, const IVP_DOUBLE b2_in,
IVP_DOUBLE *i_a1_out, IVP_DOUBLE *i_b1_out,
IVP_DOUBLE *i_a2_out, IVP_DOUBLE *i_b2_out);
static inline IVP_FLOAT approx5_sin(IVP_FLOAT angle); // fifth order approximation
static inline IVP_FLOAT approx5_cos(IVP_FLOAT angle); // fifth order approximation of cos
static inline IVP_FLOAT save_acosf(IVP_FLOAT x); // slow and save acos
static inline IVP_FLOAT fast_asin(IVP_FLOAT x); // for documentation see ivu_linear_macros.hxx
static inline IVP_FLOAT upper_limit_asin(IVP_FLOAT angle); // for documentation see ivu_linear_macros.hxx
static inline IVP_FLOAT fast_approx_asin(IVP_FLOAT angle); // "
static inline IVP_FLOAT fast_anywhere_asin(IVP_FLOAT angle); // "
static IVP_FLOAT isqrt_float(IVP_FLOAT quad); // "
static IVP_DOUBLE isqrt_double(IVP_DOUBLE quad); // "
static inline int int_div_2(int a); //workaround for compiler bug in CodeWarrior1.6
#if defined(IVP_NO_DOUBLE) && !defined(SUN)
static IVP_DOUBLE fabsd(IVP_DOUBLE f){ return fabsf(f); };
#ifdef PSXII
static IVP_DOUBLE ivp_sqrtf(IVP_DOUBLE x){
__asm__ __volatile__ (" \
.set noreorder \
sqrt.s %0, %0 \
.set reorder \
" : "+f" (x) :); \
return x; \
}
#else
static IVP_DOUBLE ivp_sqrtf(IVP_DOUBLE f){ return sqrtf(f); };
#endif
static IVP_DOUBLE sqrtd(IVP_DOUBLE f){ return ivp_sqrtf(f); };
static IVP_DOUBLE ivp_sinf(IVP_DOUBLE f) { return sinf(f); };
static IVP_DOUBLE ivp_cosf(IVP_DOUBLE f) { return cosf(f); };
static IVP_DOUBLE sind(IVP_DOUBLE f) { return sinf(f); };
static IVP_DOUBLE cosd(IVP_DOUBLE f) { return cosf(f); };
static IVP_DOUBLE acosd(IVP_DOUBLE f){ return acosf(f); };
static IVP_DOUBLE asind(IVP_DOUBLE f){ return asinf(f); };
static IVP_DOUBLE atand(IVP_DOUBLE f){ return atanf(f); };
static IVP_DOUBLE ivp_expf(IVP_DOUBLE f) { return expf(f); };
static IVP_DOUBLE atan2d(IVP_DOUBLE f1, IVP_DOUBLE f2){ return atan2f(f1,f2); };
#else
static IVP_DOUBLE fabsd(IVP_DOUBLE f){ return fabs(f); };
static IVP_DOUBLE ivp_sqrtf(IVP_DOUBLE f){ return sqrt(f); };
static IVP_DOUBLE sqrtd(IVP_DOUBLE f){ return sqrt(f); };
static IVP_DOUBLE ivp_sinf(IVP_DOUBLE f) { return sin(f); };
static IVP_DOUBLE ivp_cosf(IVP_DOUBLE f) { return cos(f); };
static IVP_DOUBLE sind(IVP_DOUBLE f) { return sin(f); };
static IVP_DOUBLE cosd(IVP_DOUBLE f) { return cos(f); };
static IVP_DOUBLE acosd(IVP_DOUBLE f){ return acos(f); };
static IVP_DOUBLE asind(IVP_DOUBLE f){ return asin(f); };
static IVP_DOUBLE atand(IVP_DOUBLE f){ return atan(f); };
static IVP_DOUBLE ivp_expf(IVP_DOUBLE f) { return exp(f); };
static IVP_DOUBLE atan2d(IVP_DOUBLE f1, IVP_DOUBLE f2){ return atan2(f1,f2); };
#endif
};
/********************************************************************************
* Name: IVP_U_Hesse
* Description: A convenient way to define a plane,
* and e.g. for calculating the distance from a point to that
* plane.
********************************************************************************/
class IVP_U_Hesse: public IVP_U_Point {
public:
#if !defined(IVP_VECTOR_UNIT_DOUBLE)
IVP_DOUBLE hesse_val;
#endif
void calc_hesse(const IVP_U_Point *p0,const IVP_U_Point *p1,const IVP_U_Point *p2);
void calc_hesse(const IVP_U_Float_Point *p0, const IVP_U_Float_Point *p1, const IVP_U_Float_Point *p2);
void calc_hesse_val(const IVP_U_Point *p0);
void proj_on_plane(const IVP_U_Point *p, IVP_U_Point *result) const; // sets result to a point on the plane and nearest to p
void mult_hesse(IVP_DOUBLE factor); // scale the hesse
void normize(); // normize hesse (->super.calc_quad_length() == 1.0f)
#if !defined(IVP_NO_DOUBLE)
inline IVP_DOUBLE get_dist(const IVP_U_Point *p) const; // get the distance between a point and the plane
#endif
inline IVP_DOUBLE get_dist(const IVP_U_Float_Point *p) const; // get the distance between a point and the plane
IVP_RETURN_TYPE calc_intersect_with(const IVP_U_Straight *straight, // calc the intersection between a straight and the plane
IVP_U_Point *point_out) const;
void byte_swap() { ivp_byte_swap4( (uint&) hesse_val ); IVP_U_Point::byte_swap(); }
};
/********************************************************************************
* Name: IVP_U_Float_Hesse
* Description: A convenient way to define a plane,
* and e.g. for calculating the distance from a point to that
* plane. (Float version)
********************************************************************************/
class IVP_U_Float_Hesse: public IVP_U_Float_Point {
public:
#if !defined(IVP_VECTOR_UNIT_FLOAT)
IVP_FLOAT hesse_val;
#endif
void set4(const IVP_U_Float_Hesse *h){ this->set(h); this->hesse_val = h->hesse_val;};
void calc_hesse(const IVP_U_Float_Point *p0,const IVP_U_Float_Point *p1,const IVP_U_Float_Point *p2);
void calc_hesse_val(const IVP_U_Float_Point *p0);
void proj_on_plane(const IVP_U_Float_Point *p, IVP_U_Float_Point *result) const; // sets result to a point on the plane and nearest to p
void mult_hesse(IVP_DOUBLE factor); // scale the hesse
void normize(); // normize hesse (->super.calc_quad_length() == 1.0f)
// get the distance between a point and the plane
inline IVP_DOUBLE get_dist(const IVP_U_Float_Point *p) const; // get the distance between a point and the plane
IVP_U_Float_Hesse(){;};
IVP_U_Float_Hesse(IVP_DOUBLE xi, IVP_DOUBLE yi, IVP_DOUBLE zi, IVP_DOUBLE val) { k[0]=(IVP_FLOAT)xi; k[1]=(IVP_FLOAT)yi; k[2]=(IVP_FLOAT)zi; hesse_val=val; }
void byte_swap() { ivp_byte_swap4( (uint&) hesse_val ); IVP_U_Float_Point::byte_swap(); }
};
typedef IVP_U_Float_Hesse IVP_U_Float_Point4;
/********************************************************************************
* Name: IVP_U_Matrix3
* Description: A rotation matrix in a three dimensional space
* Attention: syntax is different to syntax of IVP_U_Point.
* All transformations using inverted matrices assume that
* matrices are orthonormized !!!.
* To invert any matrix, use real_invert
********************************************************************************/
class IVP_U_Matrix3 {
protected:
IVP_U_Point rows[3]; // use get_elem and set_elem to access elements
public:
inline IVP_DOUBLE get_elem(int row, int col) const { return rows[row].k[col];};
inline void set_elem(int row, int col, IVP_DOUBLE val){ rows[row].k[col] = val; };
inline void inline_mmult3(const IVP_U_Matrix3 *mb, IVP_U_Matrix3 *m_out )const;
inline void inline_mimult3(const IVP_U_Matrix3 *mb, IVP_U_Matrix3 *m_out )const;
void mmult3(const IVP_U_Matrix3 *mb, IVP_U_Matrix3 *m_out )const; // m_out = this * mb, note: note: in place operation allowed
void mimult3(const IVP_U_Matrix3 *mb, IVP_U_Matrix3 *m_out )const; // m_out = (this^-1) * mb, note: in place operation allowed
void mi2mult3(const IVP_U_Matrix3 *mb, IVP_U_Matrix3 *m_out )const; // m_out = this * (mb^-1), note: in place operation allowed
#if !defined(IVP_NO_DOUBLE)
inline void inline_vmult3(const IVP_U_Point *p_in, IVP_U_Point * p_out ) const; // p_out = this * p_in
void vmult3 (const IVP_U_Point *p_in, IVP_U_Point * p_out ) const; // p_out = this * p_in
#endif
inline void inline_vmult3 (const IVP_U_Float_Point *p_in, IVP_U_Float_Point * p_out ) const; // p_out = this * p_in
void vmult3 (const IVP_U_Float_Point *p_in, IVP_U_Float_Point * p_out ) const; // p_out = this * p_in
#if !defined(IVP_NO_DOUBLE)
inline void inline_vimult3(const IVP_U_Point *p_in, IVP_U_Point * p_out ) const; // p_out = (this^-1) * p_in
void vimult3(const IVP_U_Point *p_in, IVP_U_Point * p_out ) const; // p_out = (this^-1) * p_in
#endif
inline void inline_vimult3( const IVP_U_Float_Point *p_in, IVP_U_Float_Point * p_out ) const; // assembler version
void vimult3(const IVP_U_Float_Point *p_in, IVP_U_Float_Point * p_out ) const; // p_out = (this^-1) * p_in
void orthogonize(); // all vectors are in a right hand system, keeps z vector
IVP_RETURN_TYPE normize(); // all column vectors get length 1.0
IVP_RETURN_TYPE orthonormize(); // both of above
IVP_DOUBLE quad_rot_distance_to(const IVP_U_Matrix3 *m2); // sum of quad diff of mm
/********************************************************************************
* Name: calc_eigen_vector
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -