back out previous changes temporarily
This commit is contained in:
parent
2dfc0dca85
commit
d7857a6f5a
|
|
@ -12,22 +12,13 @@
|
|||
coordinateSystem.h deg_2_rad.h \
|
||||
ioPtaDatagramLinMath.I ioPtaDatagramLinMath.cxx \
|
||||
ioPtaDatagramLinMath.h lmatrix.cxx lmatrix.h \
|
||||
lmatrix3.I lmatrix3.h lmatrix3.cxx lmatrix3_src.I \
|
||||
lmatrix4.I lmatrix4.h lmatrix4.cxx lmatrix4_src.I \
|
||||
luse.I luse.cxx \
|
||||
luse.h lquaternion.I lquaternion.h lquaternion.cxx lquaternion_src.I \
|
||||
lrotation.I lrotation.h lrotation.cxx lrotation_src.I \
|
||||
lorientation.I lorientation.h lorientation.cxx lorientation_src.I \
|
||||
lpoint2.I lpoint2.h lpoint2.cxx lpoint2_src.I \
|
||||
lpoint3.I lpoint3.h lpoint3.cxx lpoint3_src.I \
|
||||
lpoint4.I lpoint4.h lpoint4.cxx lpoint4_src.I \
|
||||
lvec2_ops.I lvec2_ops.h lvec3_ops.I lvec3_ops.h lvec4_ops.I lvec4_ops.h \
|
||||
lvecBase2.I lvecBase2.h lvecBase2.cxx lvecBase2_src.I \
|
||||
lvecBase3.I lvecBase3.h lvecBase3.cxx lvecBase3_src.I \
|
||||
lvecBase4.I lvecBase4.h lvecBase4.cxx lvecBase4_src.I \
|
||||
lvector2.I lvector2.h lvector2.cxx lvector2_src.I \
|
||||
lvector3.I lvector3.h lvector3.cxx lvector3_src.I \
|
||||
lvector4.I lvector4.h lvector4.cxx lvector4_src.I luse.N\
|
||||
lmatrix3.I lmatrix3.h lmatrix4.I lmatrix4.h \
|
||||
luse.I luse.N luse.cxx \
|
||||
luse.h lquaternion.I lquaternion.h lrotation.I lrotation.h \
|
||||
lvec2_ops.I lvec2_ops.h lvec3_ops.I lvec3_ops.h lvec4_ops.I \
|
||||
lvec4_ops.h lvecBase2.I lvecBase2.h lvecBase3.I lvecBase3.h \
|
||||
lvecBase4.I lvecBase4.h lvector2.I lvector2.h lvector3.I lvector3.h \
|
||||
lvector4.I lvector4.h \
|
||||
mathNumbers.cxx mathNumbers.h nearly_zero.h \
|
||||
pta_Colorf.cxx pta_Colorf.h \
|
||||
pta_Normalf.cxx pta_Normalf.h pta_TexCoordf.cxx pta_TexCoordf.h \
|
||||
|
|
@ -43,8 +34,7 @@
|
|||
ioPtaDatagramLinMath.h lmat_ops.I lmat_ops.h lmatrix.h lmatrix3.I \
|
||||
lmatrix3.h lmatrix4.I lmatrix4.h lorientation.I lorientation.h \
|
||||
lpoint2.I lpoint2.h lpoint3.I lpoint3.h lpoint4.I lpoint4.h \
|
||||
lquaternion.I lquaternion.h \
|
||||
lrotation.I lrotation.h luse.I luse.h \
|
||||
lquaternion.I lquaternion.h lrotation.I lrotation.h luse.I luse.h \
|
||||
lvec2_ops.I lvec2_ops.h lvec3_ops.I lvec3_ops.h lvec4_ops.I \
|
||||
lvec4_ops.h lvecBase2.I lvecBase2.h lvecBase3.I lvecBase3.h \
|
||||
lvecBase4.I lvecBase4.h lvector2.I lvector2.h lvector3.I lvector3.h \
|
||||
|
|
@ -52,8 +42,7 @@
|
|||
pta_Normalf.h pta_TexCoordf.h pta_Vertexf.h vector_Colorf.h \
|
||||
vector_LPoint2f.h vector_LVecBase3f.h \
|
||||
vector_Normalf.h vector_TexCoordf.h \
|
||||
vector_Vertexf.h \
|
||||
fltnames.I dblnames.I
|
||||
vector_Vertexf.h
|
||||
|
||||
#define IGATESCAN all
|
||||
|
||||
|
|
|
|||
|
|
@ -3,47 +3,47 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE LVecBase2d cast_to_double(const LVecBase2f &source) {
|
||||
INLINE LVecBase2<double> cast_to_double(const LVecBase2<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LVecBase3d cast_to_double(const LVecBase3f &source) {
|
||||
INLINE LVecBase3<double> cast_to_double(const LVecBase3<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LVecBase4d cast_to_double(const LVecBase4f &source) {
|
||||
INLINE LVecBase4<double> cast_to_double(const LVecBase4<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LVector2d cast_to_double(const LVector2f &source) {
|
||||
INLINE LVector2<double> cast_to_double(const LVector2<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LVector3d cast_to_double(const LVector3f &source) {
|
||||
INLINE LVector3<double> cast_to_double(const LVector3<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LVector4d cast_to_double(const LVector4f &source) {
|
||||
INLINE LVector4<double> cast_to_double(const LVector4<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LPoint2d cast_to_double(const LPoint2f &source) {
|
||||
INLINE LPoint2<double> cast_to_double(const LPoint2<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LPoint3d cast_to_double(const LPoint3f &source) {
|
||||
INLINE LPoint3<double> cast_to_double(const LPoint3<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LPoint4d cast_to_double(const LPoint4f &source) {
|
||||
INLINE LPoint4<double> cast_to_double(const LPoint4<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LMatrix3d cast_to_double(const LMatrix3f &source) {
|
||||
INLINE LMatrix3<double> cast_to_double(const LMatrix3<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
INLINE LMatrix4d cast_to_double(const LMatrix4f &source) {
|
||||
INLINE LMatrix4<double> cast_to_double(const LMatrix4<float> &source) {
|
||||
return LCAST(double, source);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,17 +13,17 @@
|
|||
// These are a number of functions that convert our various math
|
||||
// objects between floats and doubles.
|
||||
|
||||
INLINE LVecBase2d cast_to_double(const LVecBase2f &source);
|
||||
INLINE LVecBase3d cast_to_double(const LVecBase3f &source);
|
||||
INLINE LVecBase4d cast_to_double(const LVecBase4f &source);
|
||||
INLINE LVector2d cast_to_double(const LVector2f &source);
|
||||
INLINE LVector3d cast_to_double(const LVector3f &source);
|
||||
INLINE LVector4d cast_to_double(const LVector4f &source);
|
||||
INLINE LPoint2d cast_to_double(const LPoint2f &source);
|
||||
INLINE LPoint3d cast_to_double(const LPoint3f &source);
|
||||
INLINE LPoint4d cast_to_double(const LPoint4f &source);
|
||||
INLINE LMatrix3d cast_to_double(const LMatrix3f &source);
|
||||
INLINE LMatrix4d cast_to_double(const LMatrix4f &source);
|
||||
INLINE LVecBase2<double> cast_to_double(const LVecBase2<float> &source);
|
||||
INLINE LVecBase3<double> cast_to_double(const LVecBase3<float> &source);
|
||||
INLINE LVecBase4<double> cast_to_double(const LVecBase4<float> &source);
|
||||
INLINE LVector2<double> cast_to_double(const LVector2<float> &source);
|
||||
INLINE LVector3<double> cast_to_double(const LVector3<float> &source);
|
||||
INLINE LVector4<double> cast_to_double(const LVector4<float> &source);
|
||||
INLINE LPoint2<double> cast_to_double(const LPoint2<float> &source);
|
||||
INLINE LPoint3<double> cast_to_double(const LPoint3<float> &source);
|
||||
INLINE LPoint4<double> cast_to_double(const LPoint4<float> &source);
|
||||
INLINE LMatrix3<double> cast_to_double(const LMatrix3<float> &source);
|
||||
INLINE LMatrix4<double> cast_to_double(const LMatrix4<float> &source);
|
||||
|
||||
#include "cast_to_double.I"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,47 +3,47 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE LVecBase2f cast_to_float(const LVecBase2d &source) {
|
||||
INLINE LVecBase2<float> cast_to_float(const LVecBase2<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LVecBase3f cast_to_float(const LVecBase3d &source) {
|
||||
INLINE LVecBase3<float> cast_to_float(const LVecBase3<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LVecBase4f cast_to_float(const LVecBase4d &source) {
|
||||
INLINE LVecBase4<float> cast_to_float(const LVecBase4<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LVector2f cast_to_float(const LVector2d &source) {
|
||||
INLINE LVector2<float> cast_to_float(const LVector2<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LVector3f cast_to_float(const LVector3d &source) {
|
||||
INLINE LVector3<float> cast_to_float(const LVector3<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LVector4f cast_to_float(const LVector4d &source) {
|
||||
INLINE LVector4<float> cast_to_float(const LVector4<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LPoint2f cast_to_float(const LPoint2d &source) {
|
||||
INLINE LPoint2<float> cast_to_float(const LPoint2<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LPoint3f cast_to_float(const LPoint3d &source) {
|
||||
INLINE LPoint3<float> cast_to_float(const LPoint3<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LPoint4f cast_to_float(const LPoint4d &source) {
|
||||
INLINE LPoint4<float> cast_to_float(const LPoint4<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LMatrix3f cast_to_float(const LMatrix3d &source) {
|
||||
INLINE LMatrix3<float> cast_to_float(const LMatrix3<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
INLINE LMatrix4f cast_to_float(const LMatrix4d &source) {
|
||||
INLINE LMatrix4<float> cast_to_float(const LMatrix4<double> &source) {
|
||||
return LCAST(float, source);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,17 +13,17 @@
|
|||
// These are a number of functions that convert our various math
|
||||
// objects between floats and doubles.
|
||||
|
||||
INLINE LVecBase2f cast_to_float(const LVecBase2d &source);
|
||||
INLINE LVecBase3f cast_to_float(const LVecBase3d &source);
|
||||
INLINE LVecBase4f cast_to_float(const LVecBase4d &source);
|
||||
INLINE LVector2f cast_to_float(const LVector2d &source);
|
||||
INLINE LVector3f cast_to_float(const LVector3d &source);
|
||||
INLINE LVector4f cast_to_float(const LVector4d &source);
|
||||
INLINE LPoint2f cast_to_float(const LPoint2d &source);
|
||||
INLINE LPoint3f cast_to_float(const LPoint3d &source);
|
||||
INLINE LPoint4f cast_to_float(const LPoint4d &source);
|
||||
INLINE LMatrix3f cast_to_float(const LMatrix3d &source);
|
||||
INLINE LMatrix4f cast_to_float(const LMatrix4d &source);
|
||||
INLINE LVecBase2<float> cast_to_float(const LVecBase2<double> &source);
|
||||
INLINE LVecBase3<float> cast_to_float(const LVecBase3<double> &source);
|
||||
INLINE LVecBase4<float> cast_to_float(const LVecBase4<double> &source);
|
||||
INLINE LVector2<float> cast_to_float(const LVector2<double> &source);
|
||||
INLINE LVector3<float> cast_to_float(const LVector3<double> &source);
|
||||
INLINE LVector4<float> cast_to_float(const LVector4<double> &source);
|
||||
INLINE LPoint2<float> cast_to_float(const LPoint2<double> &source);
|
||||
INLINE LPoint3<float> cast_to_float(const LPoint3<double> &source);
|
||||
INLINE LPoint4<float> cast_to_float(const LPoint4<double> &source);
|
||||
INLINE LMatrix3<float> cast_to_float(const LMatrix3<double> &source);
|
||||
INLINE LMatrix4<float> cast_to_float(const LMatrix4<double> &source);
|
||||
|
||||
#include "cast_to_float.I"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,127 +1,77 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Filename: compose_matrix.I
|
||||
// Created by: drose (21Feb99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
BEGIN_PUBLISH
|
||||
|
||||
EXPCL_PANDA INLINE void
|
||||
compose_matrix(FLOATNAME(LMatrix3) &mat,
|
||||
const FLOATNAME(LVecBase3) &scale,
|
||||
const FLOATNAME(LVecBase3) &hpr,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA INLINE void
|
||||
compose_matrix(FLOATNAME(LMatrix4) &mat,
|
||||
const FLOATNAME(LVecBase3) &scale,
|
||||
const FLOATNAME(LVecBase3) &hpr,
|
||||
const FLOATNAME(LVecBase3) &translate,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void
|
||||
compose_matrix(FLOATNAME(LMatrix4) &mat, const float components[9],
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const FLOATNAME(LMatrix3) &mat,
|
||||
FLOATNAME(LVecBase3) &scale,
|
||||
FLOATNAME(LVecBase3) &hpr,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const FLOATNAME(LMatrix3) &mat,
|
||||
FLOATNAME(LVecBase3) &scale,
|
||||
FLOATNAME(LVecBase3) &hpr,
|
||||
float roll,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
|
||||
FLOATNAME(LVecBase3) &scale,
|
||||
FLOATNAME(LVecBase3) &hpr,
|
||||
FLOATNAME(LVecBase3) &translate,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
|
||||
FLOATNAME(LVecBase3) &scale,
|
||||
FLOATNAME(LVecBase3) &hpr,
|
||||
FLOATNAME(LVecBase3) &translate,
|
||||
float roll,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE bool
|
||||
decompose_matrix(const FLOATNAME(LMatrix4) &mat, float components[9],
|
||||
CoordinateSystem CS = CS_default);
|
||||
|
||||
END_PUBLISH
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: compose_matrix
|
||||
// Description: Computes the 3x3 matrix from scale and rotation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void
|
||||
_compose_matrix(FLOATNAME(LMatrix3) &mat,
|
||||
const FLOATNAME(LVecBase3) &scale,
|
||||
const FLOATNAME(LVecBase3) &hpr,
|
||||
CoordinateSystem cs) {
|
||||
mat =
|
||||
FLOATNAME(LMatrix3)::scale_mat(scale) *
|
||||
FLOATNAME(LMatrix3)::rotate_mat(hpr[1], FLOATNAME(LVector3)::right(cs), cs) *
|
||||
FLOATNAME(LMatrix3)::rotate_mat(hpr[0], FLOATNAME(LVector3)::up(cs), cs) *
|
||||
FLOATNAME(LMatrix3)::rotate_mat(hpr[2], FLOATNAME(LVector3)::back(cs), cs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: compose_matrix
|
||||
// Description: Computes the 4x4 matrix according to scale, rotation,
|
||||
// and translation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void
|
||||
_compose_matrix(FLOATNAME(LMatrix4) &mat,
|
||||
const FLOATNAME(LVecBase3) &scale,
|
||||
const FLOATNAME(LVecBase3) &hpr,
|
||||
const FLOATNAME(LVecBase3) &translate,
|
||||
CoordinateSystem cs) {
|
||||
FLOATNAME(LMatrix3) upper3;
|
||||
_compose_matrix(upper3, scale, hpr, cs);
|
||||
mat = FLOATNAME(LMatrix4)(upper3, translate);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
compose_matrix(FLOATNAME(LMatrix4) &mat,
|
||||
const FLOATTYPE1 components[9],
|
||||
compose_matrix(LMatrix4f &mat,
|
||||
const float components[9],
|
||||
CoordinateSystem cs) {
|
||||
FLOATNAME(LVector3) scale(components[0],
|
||||
LVector3f scale(components[0],
|
||||
components[1],
|
||||
components[2]);
|
||||
FLOATNAME(LVector3) hpr(components[3],
|
||||
LVector3f hpr(components[3],
|
||||
components[4],
|
||||
components[5]);
|
||||
FLOATNAME(LVector3) translate(components[6],
|
||||
LVector3f translate(components[6],
|
||||
components[7],
|
||||
components[8]);
|
||||
_compose_matrix(mat, scale, hpr, translate, cs);
|
||||
compose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
|
||||
EXPCL_PANDA INLINE void
|
||||
compose_matrix(FLOATNAME(LMatrix3) &mat,
|
||||
const FLOATNAME(LVecBase3) &scale,
|
||||
const FLOATNAME(LVecBase3) &hpr,
|
||||
INLINE bool
|
||||
decompose_matrix(const LMatrix4f &mat,
|
||||
float components[9],
|
||||
CoordinateSystem cs) {
|
||||
LVector3f scale, hpr, translate;
|
||||
if (!decompose_matrix(mat, scale, hpr, translate, cs)) {
|
||||
return false;
|
||||
}
|
||||
components[0] = scale[0];
|
||||
components[1] = scale[1];
|
||||
components[2] = scale[2];
|
||||
components[3] = hpr[0];
|
||||
components[4] = hpr[1];
|
||||
components[5] = hpr[2];
|
||||
components[6] = translate[0];
|
||||
components[7] = translate[1];
|
||||
components[8] = translate[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
INLINE void
|
||||
compose_matrix(LMatrix4d &mat,
|
||||
const double components[9],
|
||||
CoordinateSystem cs) {
|
||||
_compose_matrix(mat, scale, hpr, cs);
|
||||
LVector3d scale(components[0],
|
||||
components[1],
|
||||
components[2]);
|
||||
LVector3d hpr(components[3],
|
||||
components[4],
|
||||
components[5]);
|
||||
LVector3d translate(components[6],
|
||||
components[7],
|
||||
components[8]);
|
||||
compose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
|
||||
EXPCL_PANDA INLINE void
|
||||
compose_matrix(FLOATNAME(LMatrix4) &mat,
|
||||
const FLOATNAME(LVecBase3) &scale,
|
||||
const FLOATNAME(LVecBase3) &hpr,
|
||||
const FLOATNAME(LVecBase3) &translate,
|
||||
CoordinateSystem cs) {
|
||||
_compose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
INLINE bool
|
||||
decompose_matrix(const LMatrix4d &mat,
|
||||
double components[9],
|
||||
CoordinateSystem cs) {
|
||||
LVector3d scale, hpr, translate;
|
||||
if (!decompose_matrix(mat, scale, hpr, translate, cs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
components[0] = scale[0];
|
||||
components[1] = scale[1];
|
||||
components[2] = scale[2];
|
||||
components[3] = hpr[0];
|
||||
components[4] = hpr[1];
|
||||
components[5] = hpr[2];
|
||||
components[6] = translate[0];
|
||||
components[7] = translate[1];
|
||||
components[8] = translate[2];
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,706 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "compose_matrix.h"
|
||||
#include "deg_2_rad.h"
|
||||
#include "config_linmath.h"
|
||||
#include "compose_matrix.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "compose_matrix_src.I"
|
||||
#include <math.h>
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "compose_matrix_src.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: compose_matrix
|
||||
// Description: Computes the 3x3 matrix from scale and rotation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE void
|
||||
_compose_matrix(LMatrix3<NumType> &mat,
|
||||
const LVecBase3<NumType> &scale,
|
||||
const LVecBase3<NumType> &hpr,
|
||||
CoordinateSystem cs) {
|
||||
mat =
|
||||
LMatrix3<NumType>::scale_mat(scale) *
|
||||
LMatrix3<NumType>::rotate_mat(hpr[1], LVector3<NumType>::right(cs), cs) *
|
||||
LMatrix3<NumType>::rotate_mat(hpr[0], LVector3<NumType>::up(cs), cs) *
|
||||
LMatrix3<NumType>::rotate_mat(hpr[2], LVector3<NumType>::back(cs), cs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: compose_matrix
|
||||
// Description: Computes the 4x4 matrix according to scale, rotation,
|
||||
// and translation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE void
|
||||
_compose_matrix(LMatrix4<NumType> &mat,
|
||||
const LVecBase3<NumType> &scale,
|
||||
const LVecBase3<NumType> &hpr,
|
||||
const LVecBase3<NumType> &translate,
|
||||
CoordinateSystem cs) {
|
||||
LMatrix3<NumType> upper3;
|
||||
_compose_matrix(upper3, scale, hpr, cs);
|
||||
mat = LMatrix4<NumType>(upper3, translate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: unwind_yup_rotation
|
||||
// Description: Extracts the rotation about the x, y, and z axes from
|
||||
// the given hpr & scale matrix. Adjusts the matrix
|
||||
// to eliminate the rotation.
|
||||
//
|
||||
// This function assumes the matrix is stored in a
|
||||
// right-handed Y-up coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
unwind_yup_rotation(LMatrix3<NumType> &mat, LVecBase3<NumType> &hpr) {
|
||||
typedef LMatrix3<NumType> Matrix;
|
||||
|
||||
// Extract the axes from the matrix.
|
||||
LVector3<NumType> x, y, z;
|
||||
x = mat.get_row(0);
|
||||
y = mat.get_row(1);
|
||||
z = mat.get_row(2);
|
||||
|
||||
// Project X onto the XY plane.
|
||||
LVector2<NumType> xy(x[0], x[1]);
|
||||
xy = normalize(xy);
|
||||
|
||||
// Compute the rotation about the +Z (back) axis. This is roll.
|
||||
NumType roll = rad_2_deg(atan2(xy[1], xy[0]));
|
||||
|
||||
// Unwind the roll from the axes, and continue.
|
||||
Matrix rot_z;
|
||||
rot_z = Matrix::rotate_mat(-roll, LVector3<NumType>(0.0, 0.0, 1.0),
|
||||
CS_yup_right);
|
||||
|
||||
x = x * rot_z;
|
||||
y = y * rot_z;
|
||||
z = z * rot_z;
|
||||
|
||||
// Project the rotated X into the XZ plane.
|
||||
LVector2<NumType> xz(x[0], x[2]);
|
||||
xz = normalize(xz);
|
||||
|
||||
// Compute the rotation about the +Y (up) axis. This is yaw, or
|
||||
// "heading".
|
||||
NumType heading = rad_2_deg(-atan2(xz[1], xz[0]));
|
||||
|
||||
// Unwind the heading, and continue.
|
||||
Matrix rot_y;
|
||||
rot_y = Matrix::rotate_mat(-heading, LVector3<NumType>(0.0, 1.0, 0.0),
|
||||
CS_yup_right);
|
||||
|
||||
x = x * rot_y;
|
||||
y = y * rot_y;
|
||||
z = z * rot_y;
|
||||
|
||||
// Project the rotated Z into the YZ plane.
|
||||
LVector2<NumType> yz(z[1], z[2]);
|
||||
yz = normalize(yz);
|
||||
|
||||
// Compute the rotation about the +X (right) axis. This is pitch.
|
||||
NumType pitch = rad_2_deg(-atan2(yz[0], yz[1]));
|
||||
|
||||
// Unwind the pitch.
|
||||
Matrix rot_x;
|
||||
rot_x = Matrix::rotate_mat(-pitch, LVector3<NumType>(1.0, 0.0, 0.0),
|
||||
CS_yup_right);
|
||||
|
||||
x = x * rot_x;
|
||||
y = y * rot_x;
|
||||
z = z * rot_x;
|
||||
|
||||
// Reset the matrix to reflect the unwinding.
|
||||
mat.set_row(0, x);
|
||||
mat.set_row(1, y);
|
||||
mat.set_row(2, z);
|
||||
|
||||
// Return the three rotation components.
|
||||
hpr[0] = heading;
|
||||
hpr[1] = pitch;
|
||||
hpr[2] = roll;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: unwind_yup_rotation
|
||||
// Description: Extracts the rotation about the x, y, and z axes from
|
||||
// the given hpr & scale matrix, given the indicated
|
||||
// roll amount as a hint. Adjusts the matrix to
|
||||
// eliminate the rotation.
|
||||
//
|
||||
// This function assumes the matrix is stored in a
|
||||
// right-handed Y-up coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
unwind_yup_rotation(LMatrix3<NumType> &mat, LVecBase3<NumType> &hpr,
|
||||
NumType roll) {
|
||||
typedef LMatrix3<NumType> Matrix;
|
||||
|
||||
// Extract the axes from the matrix.
|
||||
LVector3<NumType> x, y, z;
|
||||
x = mat.get_row(0);
|
||||
y = mat.get_row(1);
|
||||
z = mat.get_row(2);
|
||||
|
||||
// Unwind the roll from the axes, and continue.
|
||||
Matrix rot_z;
|
||||
rot_z = Matrix::rotate_mat(-roll, LVector3<NumType>(0.0, 0.0, 1.0),
|
||||
CS_yup_right);
|
||||
|
||||
x = x * rot_z;
|
||||
y = y * rot_z;
|
||||
z = z * rot_z;
|
||||
|
||||
// Project the rotated X into the XZ plane.
|
||||
LVector2<NumType> xz(x[0], x[2]);
|
||||
xz = normalize(xz);
|
||||
|
||||
// Compute the rotation about the +Y (up) axis. This is yaw, or
|
||||
// "heading".
|
||||
NumType heading = rad_2_deg(-atan2(xz[1], xz[0]));
|
||||
|
||||
// Unwind the heading, and continue.
|
||||
Matrix rot_y;
|
||||
rot_y = Matrix::rotate_mat(-heading, LVector3<NumType>(0.0, 1.0, 0.0),
|
||||
CS_yup_right);
|
||||
|
||||
x = x * rot_y;
|
||||
y = y * rot_y;
|
||||
z = z * rot_y;
|
||||
|
||||
// Project the rotated Z into the YZ plane.
|
||||
LVector2<NumType> yz(z[1], z[2]);
|
||||
yz = normalize(yz);
|
||||
|
||||
// Compute the rotation about the +X (right) axis. This is pitch.
|
||||
NumType pitch = rad_2_deg(-atan2(yz[0], yz[1]));
|
||||
|
||||
// Unwind the pitch.
|
||||
Matrix rot_x;
|
||||
rot_x = Matrix::rotate_mat(-pitch, LVector3<NumType>(1.0, 0.0, 0.0),
|
||||
CS_yup_right);
|
||||
|
||||
x = x * rot_x;
|
||||
y = y * rot_x;
|
||||
z = z * rot_x;
|
||||
|
||||
// Reset the matrix to reflect the unwinding.
|
||||
mat.set_row(0, x);
|
||||
mat.set_row(1, y);
|
||||
mat.set_row(2, z);
|
||||
|
||||
// Return the three rotation components.
|
||||
hpr[0] = heading;
|
||||
hpr[1] = pitch;
|
||||
hpr[2] = roll;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: unwind_zup_rotation
|
||||
// Description: Extracts the rotation about the x, y, and z axes from
|
||||
// the given hpr & scale matrix. Adjusts the matrix
|
||||
// to eliminate the rotation.
|
||||
//
|
||||
// This function assumes the matrix is stored in a
|
||||
// right-handed Z-up coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
unwind_zup_rotation(LMatrix3<NumType> &mat, LVecBase3<NumType> &hpr) {
|
||||
typedef LMatrix3<NumType> Matrix;
|
||||
|
||||
// Extract the axes from the matrix.
|
||||
LVector3<NumType> x, y, z;
|
||||
x = mat.get_row(0);
|
||||
y = mat.get_row(1);
|
||||
z = mat.get_row(2);
|
||||
|
||||
|
||||
// Project X into the XZ plane.
|
||||
LVector2<NumType> xz(x[0], x[2]);
|
||||
xz = normalize(xz);
|
||||
|
||||
// Compute the rotation about the -Y (back) axis. This is roll.
|
||||
NumType roll = rad_2_deg(atan2(xz[1], xz[0]));
|
||||
|
||||
if (y[1] < 0.0) {
|
||||
if (roll < 0.0) {
|
||||
roll += 180.0;
|
||||
} else {
|
||||
roll -= 180.0;
|
||||
}
|
||||
}
|
||||
|
||||
// Unwind the roll from the axes, and continue.
|
||||
Matrix rot_y;
|
||||
rot_y = Matrix::rotate_mat(roll, LVector3<NumType>(0.0, 1.0, 0.0),
|
||||
CS_zup_right);
|
||||
|
||||
x = x * rot_y;
|
||||
y = y * rot_y;
|
||||
z = z * rot_y;
|
||||
|
||||
// Project the rotated X into the XY plane.
|
||||
LVector2<NumType> xy(x[0], x[1]);
|
||||
xy = normalize(xy);
|
||||
|
||||
// Compute the rotation about the +Z (up) axis. This is yaw, or
|
||||
// "heading".
|
||||
NumType heading = rad_2_deg(atan2(xy[1], xy[0]));
|
||||
|
||||
// Unwind the heading, and continue.
|
||||
Matrix rot_z;
|
||||
rot_z = Matrix::rotate_mat(-heading, LVector3<NumType>(0.0, 0.0, 1.0),
|
||||
CS_zup_right);
|
||||
|
||||
x = x * rot_z;
|
||||
y = y * rot_z;
|
||||
z = z * rot_z;
|
||||
|
||||
// Project the rotated Y into the YZ plane.
|
||||
LVector2<NumType> yz(y[1], y[2]);
|
||||
yz = normalize(yz);
|
||||
|
||||
// Compute the rotation about the +X (right) axis. This is pitch.
|
||||
NumType pitch = rad_2_deg(atan2(yz[1], yz[0]));
|
||||
|
||||
// Unwind the pitch.
|
||||
Matrix rot_x;
|
||||
rot_x = Matrix::rotate_mat(-pitch, LVector3<NumType>(1.0, 0.0, 0.0),
|
||||
CS_zup_right);
|
||||
|
||||
x = x * rot_x;
|
||||
y = y * rot_x;
|
||||
z = z * rot_x;
|
||||
|
||||
// Reset the matrix to reflect the unwinding.
|
||||
mat.set_row(0, x);
|
||||
mat.set_row(1, y);
|
||||
mat.set_row(2, z);
|
||||
|
||||
// Return the three rotation components.
|
||||
hpr[0] = heading;
|
||||
hpr[1] = pitch;
|
||||
hpr[2] = roll;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: unwind_zup_rotation
|
||||
// Description: Extracts the rotation about the x, y, and z axes from
|
||||
// the given hpr & scale matrix, given the indicated
|
||||
// roll amount as a hint. Adjusts the matrix to
|
||||
// eliminate the rotation.
|
||||
//
|
||||
// This function assumes the matrix is stored in a
|
||||
// right-handed Z-up coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
unwind_zup_rotation(LMatrix3<NumType> &mat, LVecBase3<NumType> &hpr,
|
||||
NumType roll) {
|
||||
typedef LMatrix3<NumType> Matrix;
|
||||
|
||||
// Extract the axes from the matrix.
|
||||
LVector3<NumType> x, y, z;
|
||||
x = mat.get_row(0);
|
||||
y = mat.get_row(1);
|
||||
z = mat.get_row(2);
|
||||
|
||||
// Unwind the roll from the axes, and continue.
|
||||
Matrix rot_y;
|
||||
rot_y = Matrix::rotate_mat(roll, LVector3<NumType>(0.0, 1.0, 0.0),
|
||||
CS_zup_right);
|
||||
|
||||
x = x * rot_y;
|
||||
y = y * rot_y;
|
||||
z = z * rot_y;
|
||||
|
||||
// Project the rotated X into the XY plane.
|
||||
LVector2<NumType> xy(x[0], x[1]);
|
||||
xy = normalize(xy);
|
||||
|
||||
// Compute the rotation about the +Z (up) axis. This is yaw, or
|
||||
// "heading".
|
||||
NumType heading = rad_2_deg(atan2(xy[1], xy[0]));
|
||||
|
||||
// Unwind the heading, and continue.
|
||||
Matrix rot_z;
|
||||
rot_z = Matrix::rotate_mat(-heading, LVector3<NumType>(0.0, 0.0, 1.0),
|
||||
CS_zup_right);
|
||||
|
||||
x = x * rot_z;
|
||||
y = y * rot_z;
|
||||
z = z * rot_z;
|
||||
|
||||
// Project the rotated Y into the YZ plane.
|
||||
LVector2<NumType> yz(y[1], y[2]);
|
||||
yz = normalize(yz);
|
||||
|
||||
// Compute the rotation about the +X (right) axis. This is pitch.
|
||||
NumType pitch = rad_2_deg(atan2(yz[1], yz[0]));
|
||||
|
||||
// Unwind the pitch.
|
||||
Matrix rot_x;
|
||||
rot_x = Matrix::rotate_mat(-pitch, LVector3<NumType>(1.0, 0.0, 0.0),
|
||||
CS_zup_right);
|
||||
|
||||
x = x * rot_x;
|
||||
y = y * rot_x;
|
||||
z = z * rot_x;
|
||||
|
||||
// Reset the matrix to reflect the unwinding.
|
||||
mat.set_row(0, x);
|
||||
mat.set_row(1, y);
|
||||
mat.set_row(2, z);
|
||||
|
||||
// Return the three rotation components.
|
||||
hpr[0] = heading;
|
||||
hpr[1] = pitch;
|
||||
hpr[2] = roll;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: decompose_matrix
|
||||
// Description: Extracts out the components of a 3x3 rotation matrix.
|
||||
// Returns true if the scale and hpr completely describe
|
||||
// the matrix, or false if there is also a shear
|
||||
// component or if the matrix is not affine.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static bool
|
||||
_decompose_matrix(const LMatrix3<NumType> &mat,
|
||||
LVecBase3<NumType> &scale,
|
||||
LVecBase3<NumType> &hpr,
|
||||
CoordinateSystem cs) {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
|
||||
// Extract the rotation and scale, according to the coordinate
|
||||
// system of choice.
|
||||
bool shear;
|
||||
|
||||
switch (cs) {
|
||||
case CS_zup_right:
|
||||
{
|
||||
LMatrix3<NumType> rm(mat);
|
||||
unwind_zup_rotation(rm, hpr);
|
||||
scale[0] = rm(0, 0);
|
||||
scale[1] = rm(1, 1);
|
||||
scale[2] = rm(2, 2);
|
||||
shear =
|
||||
(fabs(rm(0, 1)) + fabs(rm(0, 2)) +
|
||||
fabs(rm(1, 0)) + fabs(rm(1, 2)) +
|
||||
fabs(rm(2, 0)) + fabs(rm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_yup_right:
|
||||
{
|
||||
LMatrix3<NumType> rm(mat);
|
||||
unwind_yup_rotation(rm, hpr);
|
||||
scale[0] = rm(0, 0);
|
||||
scale[1] = rm(1, 1);
|
||||
scale[2] = rm(2, 2);
|
||||
shear =
|
||||
(fabs(rm(0, 1)) + fabs(rm(0, 2)) +
|
||||
fabs(rm(1, 0)) + fabs(rm(1, 2)) +
|
||||
fabs(rm(2, 0)) + fabs(rm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_zup_left:
|
||||
{
|
||||
LMatrix3<NumType> lm(mat(0, 0), mat(0, 1), -mat(0, 2),
|
||||
mat(1, 0), mat(1, 1), -mat(1, 2),
|
||||
-mat(2, 0), -mat(2, 1), mat(2, 2));
|
||||
unwind_zup_rotation(lm, hpr);
|
||||
scale[0] = -lm(0, 0);
|
||||
scale[1] = -lm(1, 1);
|
||||
scale[2] = lm(2, 2);
|
||||
shear =
|
||||
(fabs(lm(0, 1)) + fabs(lm(0, 2)) +
|
||||
fabs(lm(1, 0)) + fabs(lm(1, 2)) +
|
||||
fabs(lm(2, 0)) + fabs(lm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_yup_left:
|
||||
{
|
||||
LMatrix3<NumType> lm(mat(0, 0), mat(0, 1), -mat(0, 2),
|
||||
mat(1, 0), mat(1, 1), -mat(1, 2),
|
||||
-mat(2, 0), -mat(2, 1), mat(2, 2));
|
||||
unwind_yup_rotation(lm, hpr);
|
||||
scale[0] = -lm(0, 0);
|
||||
scale[1] = -lm(1, 1);
|
||||
scale[2] = lm(2, 2);
|
||||
shear =
|
||||
(fabs(lm(0, 1)) + fabs(lm(0, 2)) +
|
||||
fabs(lm(1, 0)) + fabs(lm(1, 2)) +
|
||||
fabs(lm(2, 0)) + fabs(lm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
linmath_cat.error()
|
||||
<< "Unexpected coordinate system: " << (int)cs << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return !shear;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: decompose_matrix
|
||||
// Description: Extracts out the components of a 3x3 rotation matrix.
|
||||
// Returns true if the scale and hpr completely describe
|
||||
// the matrix, or false if there is also a shear
|
||||
// component or if the matrix is not affine.
|
||||
//
|
||||
// This flavor of the function accepts an expected roll
|
||||
// amount. This amount will be used as the roll
|
||||
// component, rather than attempting to determine roll
|
||||
// by examining the matrix; this helps alleviate roll
|
||||
// instability due to roundoff errors or gimbal lock.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static bool
|
||||
_decompose_matrix(const LMatrix3<NumType> &mat,
|
||||
LVecBase3<NumType> &scale,
|
||||
LVecBase3<NumType> &hpr,
|
||||
NumType roll,
|
||||
CoordinateSystem cs) {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
|
||||
// Extract the rotation and scale, according to the coordinate
|
||||
// system of choice.
|
||||
bool shear;
|
||||
|
||||
switch (cs) {
|
||||
case CS_zup_right:
|
||||
{
|
||||
LMatrix3<NumType> rm(mat);
|
||||
unwind_zup_rotation(rm, hpr, roll);
|
||||
scale[0] = rm(0, 0);
|
||||
scale[1] = rm(1, 1);
|
||||
scale[2] = rm(2, 2);
|
||||
shear =
|
||||
(fabs(rm(0, 1)) + fabs(rm(0, 2)) +
|
||||
fabs(rm(1, 0)) + fabs(rm(1, 2)) +
|
||||
fabs(rm(2, 0)) + fabs(rm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_yup_right:
|
||||
{
|
||||
LMatrix3<NumType> rm(mat);
|
||||
unwind_yup_rotation(rm, hpr, roll);
|
||||
scale[0] = rm(0, 0);
|
||||
scale[1] = rm(1, 1);
|
||||
scale[2] = rm(2, 2);
|
||||
shear =
|
||||
(fabs(rm(0, 1)) + fabs(rm(0, 2)) +
|
||||
fabs(rm(1, 0)) + fabs(rm(1, 2)) +
|
||||
fabs(rm(2, 0)) + fabs(rm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_zup_left:
|
||||
{
|
||||
LMatrix3<NumType> lm(mat(0, 0), mat(0, 1), -mat(0, 2),
|
||||
mat(1, 0), mat(1, 1), -mat(1, 2),
|
||||
-mat(2, 0), -mat(2, 1), mat(2, 2));
|
||||
unwind_zup_rotation(lm, hpr, roll);
|
||||
scale[0] = -lm(0, 0);
|
||||
scale[1] = -lm(1, 1);
|
||||
scale[2] = lm(2, 2);
|
||||
shear =
|
||||
(fabs(lm(0, 1)) + fabs(lm(0, 2)) +
|
||||
fabs(lm(1, 0)) + fabs(lm(1, 2)) +
|
||||
fabs(lm(2, 0)) + fabs(lm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_yup_left:
|
||||
{
|
||||
LMatrix3<NumType> lm(mat(0, 0), mat(0, 1), -mat(0, 2),
|
||||
mat(1, 0), mat(1, 1), -mat(1, 2),
|
||||
-mat(2, 0), -mat(2, 1), mat(2, 2));
|
||||
unwind_yup_rotation(lm, hpr, roll);
|
||||
scale[0] = -lm(0, 0);
|
||||
scale[1] = -lm(1, 1);
|
||||
scale[2] = lm(2, 2);
|
||||
shear =
|
||||
(fabs(lm(0, 1)) + fabs(lm(0, 2)) +
|
||||
fabs(lm(1, 0)) + fabs(lm(1, 2)) +
|
||||
fabs(lm(2, 0)) + fabs(lm(2, 1))) >= 0.0001;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
linmath_cat.error()
|
||||
<< "Unexpected coordinate system: " << (int)cs << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return !shear;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: decompose_matrix
|
||||
// Description: Extracts out the components of an affine matrix.
|
||||
// Returns true if the scale, hpr, translate
|
||||
// completely describe the matrix, or false if there is
|
||||
// also a shear component or if the matrix is not
|
||||
// affine.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE bool
|
||||
_decompose_matrix(const LMatrix4<NumType> &mat,
|
||||
LVecBase3<NumType> &scale,
|
||||
LVecBase3<NumType> &hpr,
|
||||
LVecBase3<NumType> &translate,
|
||||
CoordinateSystem cs) {
|
||||
// Get the translation first.
|
||||
translate = mat.get_row3(3);
|
||||
return _decompose_matrix(mat.get_upper_3(), scale, hpr, cs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: decompose_matrix
|
||||
// Description: Extracts out the components of an affine matrix.
|
||||
// Returns true if the scale, hpr, translate
|
||||
// completely describe the matrix, or false if there is
|
||||
// also a shear component or if the matrix is not
|
||||
// affine.
|
||||
//
|
||||
// This flavor of the function accepts an expected roll
|
||||
// amount. This amount will be used as the roll
|
||||
// component, rather than attempting to determine roll
|
||||
// by examining the matrix; this helps alleviate roll
|
||||
// instability due to roundoff errors or gimbal lock.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE bool
|
||||
_decompose_matrix(const LMatrix4<NumType> &mat,
|
||||
LVecBase3<NumType> &scale,
|
||||
LVecBase3<NumType> &hpr,
|
||||
LVecBase3<NumType> &translate,
|
||||
NumType roll,
|
||||
CoordinateSystem cs) {
|
||||
// Get the translation first.
|
||||
translate = mat.get_row3(3);
|
||||
return _decompose_matrix(mat.get_upper_3(), scale, hpr, roll, cs);
|
||||
}
|
||||
|
||||
void
|
||||
compose_matrix(LMatrix3f &mat,
|
||||
const LVecBase3f &scale,
|
||||
const LVecBase3f &hpr,
|
||||
CoordinateSystem cs) {
|
||||
_compose_matrix(mat, scale, hpr, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix3f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix3f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
float roll,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, roll, cs);
|
||||
}
|
||||
|
||||
void
|
||||
compose_matrix(LMatrix3d &mat,
|
||||
const LVecBase3d &scale,
|
||||
const LVecBase3d &hpr,
|
||||
CoordinateSystem cs) {
|
||||
_compose_matrix(mat, scale, hpr, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix3d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix3d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
double roll,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, roll, cs);
|
||||
}
|
||||
|
||||
void
|
||||
compose_matrix(LMatrix4f &mat,
|
||||
const LVecBase3f &scale,
|
||||
const LVecBase3f &hpr,
|
||||
const LVecBase3f &translate,
|
||||
CoordinateSystem cs) {
|
||||
_compose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix4f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
LVecBase3f &translate,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix4f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
LVecBase3f &translate,
|
||||
float roll,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, translate, roll, cs);
|
||||
}
|
||||
|
||||
void
|
||||
compose_matrix(LMatrix4d &mat,
|
||||
const LVecBase3d &scale,
|
||||
const LVecBase3d &hpr,
|
||||
const LVecBase3d &translate,
|
||||
CoordinateSystem cs) {
|
||||
_compose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix4d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
LVecBase3d &translate,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, translate, cs);
|
||||
}
|
||||
|
||||
bool
|
||||
decompose_matrix(const LMatrix4d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
LVecBase3d &translate,
|
||||
double roll,
|
||||
CoordinateSystem cs) {
|
||||
return _decompose_matrix(mat, scale, hpr, translate, roll, cs);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,14 +26,98 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "lmatrix.h"
|
||||
#include "luse.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "compose_matrix.I"
|
||||
BEGIN_PUBLISH
|
||||
|
||||
EXPCL_PANDA void
|
||||
compose_matrix(LMatrix3f &mat,
|
||||
const LVecBase3f &scale,
|
||||
const LVecBase3f &hpr,
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const LMatrix3f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const LMatrix3f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
float roll,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA void
|
||||
compose_matrix(LMatrix3d &mat,
|
||||
const LVecBase3d &scale,
|
||||
const LVecBase3d &hpr,
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const LMatrix3d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const LMatrix3d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
double roll,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA void
|
||||
compose_matrix(LMatrix4f &mat,
|
||||
const LVecBase3f &scale,
|
||||
const LVecBase3f &hpr,
|
||||
const LVecBase3f &translate,
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE void compose_matrix(LMatrix4f &mat, const float components[9],
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const LMatrix4f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
LVecBase3f &translate,
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA bool
|
||||
decompose_matrix(const LMatrix4f &mat,
|
||||
LVecBase3f &scale,
|
||||
LVecBase3f &hpr,
|
||||
LVecBase3f &translate,
|
||||
float roll,
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE bool decompose_matrix(const LMatrix4f &mat, float components[9],
|
||||
CoordinateSystem CS = CS_default);
|
||||
|
||||
EXPCL_PANDA void
|
||||
compose_matrix(LMatrix4d &mat,
|
||||
const LVecBase3d &scale,
|
||||
const LVecBase3d &hpr,
|
||||
const LVecBase3d &translate,
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE void compose_matrix(LMatrix4d &mat, const double components[9],
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
bool EXPCL_PANDA
|
||||
decompose_matrix(const LMatrix4d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
LVecBase3d &translate,
|
||||
CoordinateSystem cs = CS_default);
|
||||
bool EXPCL_PANDA
|
||||
decompose_matrix(const LMatrix4d &mat,
|
||||
LVecBase3d &scale,
|
||||
LVecBase3d &hpr,
|
||||
LVecBase3d &translate,
|
||||
double roll,
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE bool decompose_matrix(const LMatrix4d &mat, double components[9],
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
END_PUBLISH
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "compose_matrix.I"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,90 +3,13 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
// vector times matrix3
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator * (const FLOATNAME(LVecBase3) &v, const FLOATNAME(LMatrix3) &m);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LVector2)
|
||||
operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m);
|
||||
|
||||
|
||||
// vector times matrix4
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator * (const FLOATNAME(LVecBase4) &v, const FLOATNAME(LMatrix4) &m);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m);
|
||||
*/
|
||||
#ifdef CPPPARSER
|
||||
// Strictly for the benefit of interrogate, we'll define explicit
|
||||
// 'instantiations' of the above template functions on types float and
|
||||
// double.
|
||||
|
||||
BEGIN_PUBLISH
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator * (const FLOATNAME(LVecBase3) &v, const FLOATNAME(LMatrix3) &m);
|
||||
INLINE FLOATNAME(LVector2)
|
||||
operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m);
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m);
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator * (const FLOATNAME(LVecBase4) &v, const FLOATNAME(LMatrix4) &m);
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m);
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m);
|
||||
|
||||
/*
|
||||
INLINE LVecBase3<double>
|
||||
operator * (const LVecBase3<double> &v, const LMatrix3<double> &m);
|
||||
INLINE LVector2<double>
|
||||
operator * (const LVector2<double> &v, const LMatrix3<double> &m);
|
||||
INLINE LPoint2<double>
|
||||
operator * (const LPoint2<double> &v, const LMatrix3<double> &m);
|
||||
INLINE LVecBase4<double>
|
||||
operator * (const LVecBase4<double> &v, const LMatrix4<double> &m);
|
||||
INLINE LVector3<double>
|
||||
operator * (const LVector3<double> &v, const LMatrix4<double> &m);
|
||||
INLINE LPoint3<double>
|
||||
operator * (const LPoint3<double> &v, const LMatrix4<double> &m);
|
||||
*/
|
||||
|
||||
END_PUBLISH
|
||||
|
||||
#endif // CPPPARSER
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3 times LMatrix3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator * (const FLOATNAME(LVecBase3) &v, const FLOATNAME(LMatrix3) &m) {
|
||||
return m.xform(v);
|
||||
}
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix3) &m) {
|
||||
return m.xform(v);
|
||||
}
|
||||
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix3) &m) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>
|
||||
operator * (const LVecBase3<NumType> &v, const LMatrix3<NumType> &m) {
|
||||
return m.xform(v);
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +17,9 @@ operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix3) &m) {
|
|||
// Function: LVector2 times LMatrix3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2)
|
||||
operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m) {
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>
|
||||
operator * (const LVector2<NumType> &v, const LMatrix3<NumType> &m) {
|
||||
return m.xform_vec(v);
|
||||
}
|
||||
|
||||
|
|
@ -104,9 +27,9 @@ operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m) {
|
|||
// Function: LPoint2 times LMatrix3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m) {
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType>
|
||||
operator * (const LPoint2<NumType> &v, const LMatrix3<NumType> &m) {
|
||||
return m.xform_point(v);
|
||||
}
|
||||
|
||||
|
|
@ -115,30 +38,19 @@ operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m) {
|
|||
// Function: LVecBase4 times LMatrix4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator * (const FLOATNAME(LVecBase4) &v, const FLOATNAME(LMatrix4) &m) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>
|
||||
operator * (const LVecBase4<NumType> &v, const LMatrix4<NumType> &m) {
|
||||
return m.xform(v);
|
||||
}
|
||||
|
||||
INLINE FLOATNAME(LVector4)
|
||||
operator * (const FLOATNAME(LVector4) &v, const FLOATNAME(LMatrix4) &m) {
|
||||
return m.xform(v);
|
||||
}
|
||||
|
||||
INLINE FLOATNAME(LPoint4)
|
||||
operator * (const FLOATNAME(LPoint4) &v, const FLOATNAME(LMatrix4) &m) {
|
||||
return m.xform(v);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector3 times LMatrix4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m) {
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>
|
||||
operator * (const LVector3<NumType> &v, const LMatrix4<NumType> &m) {
|
||||
return m.xform_vec(v);
|
||||
}
|
||||
|
||||
|
|
@ -146,9 +58,9 @@ operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m) {
|
|||
// Function: LPoint3 times LMatrix4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m) {
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType>
|
||||
operator * (const LPoint3<NumType> &v, const LMatrix4<NumType> &m) {
|
||||
return m.xform_point(v);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,71 @@
|
|||
#include "lmatrix3.h"
|
||||
#include "lmatrix4.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lmat_ops.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lmat_ops.I"
|
||||
// vector times matrix3
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>
|
||||
operator * (const LVecBase3<NumType> &v, const LMatrix3<NumType> &m);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>
|
||||
operator * (const LVector2<NumType> &v, const LMatrix3<NumType> &m);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType>
|
||||
operator * (const LPoint2<NumType> &v, const LMatrix3<NumType> &m);
|
||||
|
||||
|
||||
// vector times matrix4
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>
|
||||
operator * (const LVecBase4<NumType> &v, const LMatrix4<NumType> &m);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>
|
||||
operator * (const LVector3<NumType> &v, const LMatrix4<NumType> &m);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType>
|
||||
operator * (const LPoint3<NumType> &v, const LMatrix4<NumType> &m);
|
||||
|
||||
#ifdef CPPPARSER
|
||||
// Strictly for the benefit of interrogate, we'll define explicit
|
||||
// 'instantiations' of the above template functions on types float and
|
||||
// double.
|
||||
|
||||
BEGIN_PUBLISH
|
||||
|
||||
INLINE LVecBase3<float>
|
||||
operator * (const LVecBase3<float> &v, const LMatrix3<float> &m);
|
||||
INLINE LVector2<float>
|
||||
operator * (const LVector2<float> &v, const LMatrix3<float> &m);
|
||||
INLINE LPoint2<float>
|
||||
operator * (const LPoint2<float> &v, const LMatrix3<float> &m);
|
||||
INLINE LVecBase4<float>
|
||||
operator * (const LVecBase4<float> &v, const LMatrix4<float> &m);
|
||||
INLINE LVector3<float>
|
||||
operator * (const LVector3<float> &v, const LMatrix4<float> &m);
|
||||
INLINE LPoint3<float>
|
||||
operator * (const LPoint3<float> &v, const LMatrix4<float> &m);
|
||||
|
||||
INLINE LVecBase3<double>
|
||||
operator * (const LVecBase3<double> &v, const LMatrix3<double> &m);
|
||||
INLINE LVector2<double>
|
||||
operator * (const LVector2<double> &v, const LMatrix3<double> &m);
|
||||
INLINE LPoint2<double>
|
||||
operator * (const LPoint2<double> &v, const LMatrix3<double> &m);
|
||||
INLINE LVecBase4<double>
|
||||
operator * (const LVecBase4<double> &v, const LMatrix4<double> &m);
|
||||
INLINE LVector3<double>
|
||||
operator * (const LVector3<double> &v, const LMatrix4<double> &m);
|
||||
INLINE LPoint3<double>
|
||||
operator * (const LPoint3<double> &v, const LMatrix4<double> &m);
|
||||
|
||||
END_PUBLISH
|
||||
|
||||
#endif // CPPPARSER
|
||||
|
||||
#include "lmat_ops.I"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,18 +7,15 @@
|
|||
#define LMATRIX_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "config_linmath.h"
|
||||
|
||||
#include "lmatrix3.h"
|
||||
#include "lmatrix4.h"
|
||||
|
||||
/*
|
||||
typedef LMatrix3<float> LMatrix3f;
|
||||
typedef LMatrix4<float> LMatrix4f;
|
||||
|
||||
typedef LMatrix3<double> LMatrix3d;
|
||||
typedef LMatrix4<double> LMatrix4d;
|
||||
*/
|
||||
|
||||
// Tell GCC that we'll take care of the instantiation explicitly here.
|
||||
#ifdef __GNUC__
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -7,50 +7,188 @@
|
|||
#define LMATRIX3_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <math.h>
|
||||
#include <typeHandle.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
#include <notify.h>
|
||||
#include <indent.h>
|
||||
#include "deg_2_rad.h"
|
||||
#include "nearly_zero.h"
|
||||
|
||||
#include "coordinateSystem.h"
|
||||
#include "lvecBase3.h"
|
||||
#include "lvecBase2.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lmatrix3.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lmatrix3.I"
|
||||
#include <typeHandle.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a matrix from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
// Class : LMatrix3
|
||||
// Description : This is a 3-by-3 transform matrix. It typically will
|
||||
// represent either a rotation-and-scale (no
|
||||
// translation) matrix in 3-d, or a full affine matrix
|
||||
// (rotation, scale, translation) in 2-d, e.g. for a
|
||||
// texture matrix.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LMatrix3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source) {
|
||||
return FLOATNAME2(LMatrix3)
|
||||
(source(0, 0), source(0, 1), source(0, 2),
|
||||
source(1, 0), source(1, 1), source(1, 2),
|
||||
source(2, 0), source(2, 1), source(2, 2));
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LMatrix3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source) {
|
||||
return FLOATNAME2(LMatrix3)
|
||||
(source(0, 0), source(0, 1), source(0, 2),
|
||||
source(1, 0), source(1, 1), source(1, 2),
|
||||
source(2, 0), source(2, 1), source(2, 2));
|
||||
template<class NumType>
|
||||
class LMatrix3 {
|
||||
PUBLISHED:
|
||||
typedef const NumType *iterator;
|
||||
typedef const NumType *const_iterator;
|
||||
|
||||
INLINE LMatrix3();
|
||||
INLINE LMatrix3(const LMatrix3<NumType> &other);
|
||||
LMatrix3<NumType> &operator = (const LMatrix3<NumType> &other);
|
||||
INLINE LMatrix3<NumType> &operator = (NumType fill_value);
|
||||
INLINE LMatrix3(NumType e00, NumType e01, NumType e02,
|
||||
NumType e10, NumType e11, NumType e12,
|
||||
NumType e20, NumType e21, NumType e22);
|
||||
|
||||
void fill(NumType fill_value);
|
||||
INLINE void set(NumType e00, NumType e01, NumType e02,
|
||||
NumType e10, NumType e11, NumType e12,
|
||||
NumType e20, NumType e21, NumType e22);
|
||||
|
||||
INLINE void set_row(int row, const LVecBase3<NumType> &v);
|
||||
INLINE void set_col(int col, const LVecBase3<NumType> &v);
|
||||
|
||||
INLINE void set_row(int row, const LVecBase2<NumType> &v);
|
||||
INLINE void set_col(int col, const LVecBase2<NumType> &v);
|
||||
|
||||
INLINE LVecBase3<NumType> get_row(int row) const;
|
||||
INLINE LVecBase3<NumType> get_col(int col) const;
|
||||
|
||||
INLINE LVecBase2<NumType> get_row2(int row) const;
|
||||
INLINE LVecBase2<NumType> get_col2(int col) const;
|
||||
|
||||
INLINE NumType &operator () (int row, int col);
|
||||
INLINE NumType operator () (int row, int col) const;
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE NumType get_cell(int row, int col) const;
|
||||
INLINE void set_cell(int row, int col, NumType value);
|
||||
|
||||
INLINE const NumType *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
bool operator == (const LMatrix3<NumType> &other) const;
|
||||
INLINE bool operator != (const LMatrix3<NumType> &other) const;
|
||||
|
||||
INLINE int compare_to(const LMatrix3<NumType> &other) const;
|
||||
int compare_to(const LMatrix3<NumType> &other, NumType threshold) const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
xform(const LVecBase3<NumType> &v) const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
xform_point(const LVecBase2<NumType> &v) const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
xform_vec(const LVecBase2<NumType> &v) const;
|
||||
|
||||
LMatrix3<NumType> operator * (const LMatrix3<NumType> &other) const;
|
||||
LMatrix3<NumType> operator * (NumType scalar) const;
|
||||
LMatrix3<NumType> operator / (NumType scalar) const;
|
||||
|
||||
LMatrix3<NumType> &operator += (const LMatrix3<NumType> &other);
|
||||
LMatrix3<NumType> &operator -= (const LMatrix3<NumType> &other);
|
||||
|
||||
INLINE LMatrix3<NumType> &operator *= (const LMatrix3<NumType> &other);
|
||||
|
||||
LMatrix3<NumType> &operator *= (NumType scalar);
|
||||
LMatrix3<NumType> &operator /= (NumType scalar);
|
||||
|
||||
INLINE NumType determinant() const;
|
||||
|
||||
void transpose_from(const LMatrix3<NumType> &other);
|
||||
INLINE void transpose_in_place();
|
||||
|
||||
bool invert_from(const LMatrix3<NumType> &other);
|
||||
INLINE bool invert_in_place();
|
||||
|
||||
static const LMatrix3<NumType> &ident_mat();
|
||||
|
||||
// A 3x3 matrix is likely to be used for one of two purposes. In
|
||||
// 2-d coordinate space (e.g. texture or surface coordinates), it
|
||||
// can contain a full affine transform, with scale, rotate,
|
||||
// translate. In 3-d coordinate space, it can contain only scale
|
||||
// and/or rotate; e.g., the upper 3x3 rectangle of a full 4x4
|
||||
// matrix.
|
||||
|
||||
// The following named constructors return 3x3 matrices suitable for
|
||||
// affine transforms in 2-d coordinate space.
|
||||
|
||||
static LMatrix3<NumType> translate_mat(const LVecBase2<NumType> &trans);
|
||||
static LMatrix3<NumType> translate_mat(NumType tx, NumType ty);
|
||||
static LMatrix3<NumType> rotate_mat(NumType angle);
|
||||
static LMatrix3<NumType> scale_mat(const LVecBase2<NumType> &scale);
|
||||
static LMatrix3<NumType> scale_mat(NumType sx, NumType sy);
|
||||
|
||||
// The following named constructors return 3x3 matrices suitable for
|
||||
// scale/rotate transforms in 3-d coordinate space.
|
||||
static LMatrix3<NumType> rotate_mat(NumType angle,
|
||||
LVecBase3<NumType> axis,
|
||||
CoordinateSystem cs = CS_default);
|
||||
static LMatrix3<NumType> scale_mat(const LVecBase3<NumType> &scale);
|
||||
static LMatrix3<NumType> scale_mat(NumType sx, NumType sy, NumType sz);
|
||||
|
||||
// We don't have a scale_mat() that takes a single uniform scale
|
||||
// parameter, because it would be ambiguous whether we mean a 2-d or
|
||||
// a 3-d scale.
|
||||
|
||||
|
||||
bool almost_equal(const LMatrix3<NumType> &other,
|
||||
NumType threshold) const;
|
||||
|
||||
INLINE bool almost_equal(const LMatrix3<NumType> &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
INLINE void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
private:
|
||||
INLINE NumType mult_cel(const LMatrix3<NumType> &other, int x, int y) const;
|
||||
INLINE NumType det2(NumType e00, NumType e01, NumType e10, NumType e11) const;
|
||||
|
||||
NumType _data[3 * 3];
|
||||
|
||||
//Functionality for reading and writing from/to a binary source
|
||||
public:
|
||||
void write_datagram(Datagram& destination) const;
|
||||
void read_datagram(DatagramIterator& scan);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream &operator << (ostream &out, const LMatrix3<NumType> &mat) {
|
||||
mat.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType> transpose(const LMatrix3<NumType> &a);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType> invert(const LMatrix3<NumType> &a);
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LMatrix3<NumType2>
|
||||
lcast_to(NumType2 *type, const LMatrix3<NumType> &source);
|
||||
|
||||
#include "lmatrix3.I"
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix3<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix3<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -7,51 +7,182 @@
|
|||
#define LMATRIX4_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <math.h>
|
||||
#include <typeHandle.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
#include <indent.h>
|
||||
|
||||
#include "deg_2_rad.h"
|
||||
#include "nearly_zero.h"
|
||||
|
||||
#include "coordinateSystem.h"
|
||||
#include "lvecBase4.h"
|
||||
#include "lvecBase3.h"
|
||||
#include "lmatrix3.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lmatrix4.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lmatrix4.I"
|
||||
|
||||
#include <typeHandle.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a matrix from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
// Class : LMatrix4
|
||||
// Description : This is a 4-by-4 transform matrix.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LMatrix4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix4) &source) {
|
||||
return FLOATNAME2(LMatrix4)
|
||||
(source(0, 0), source(0, 1), source(0, 2), source(0, 3),
|
||||
source(1, 0), source(1, 1), source(1, 2), source(1, 3),
|
||||
source(2, 0), source(2, 1), source(2, 2), source(2, 3),
|
||||
source(3, 0), source(3, 1), source(3, 2), source(3, 3));
|
||||
template<class NumType>
|
||||
class LMatrix4 {
|
||||
PUBLISHED:
|
||||
typedef const NumType *iterator;
|
||||
typedef const NumType *const_iterator;
|
||||
|
||||
INLINE LMatrix4();
|
||||
INLINE LMatrix4(const LMatrix4<NumType> &other);
|
||||
LMatrix4<NumType> &operator = (const LMatrix4<NumType> &other);
|
||||
INLINE LMatrix4<NumType> &operator = (NumType fill_value);
|
||||
INLINE LMatrix4(NumType e00, NumType e01, NumType e02, NumType e03,
|
||||
NumType e10, NumType e11, NumType e12, NumType e13,
|
||||
NumType e20, NumType e21, NumType e22, NumType e23,
|
||||
NumType e30, NumType e31, NumType e32, NumType e33);
|
||||
|
||||
// Construct a 4x4 matrix given a 3x3 rotation matrix and an optional
|
||||
// translation component.
|
||||
LMatrix4(const LMatrix3<NumType> &upper3);
|
||||
LMatrix4(const LMatrix3<NumType> &upper3,
|
||||
const LVecBase3<NumType> &trans);
|
||||
|
||||
void fill(NumType fill_value);
|
||||
INLINE void set(NumType e00, NumType e01, NumType e02, NumType e03,
|
||||
NumType e10, NumType e11, NumType e12, NumType e13,
|
||||
NumType e20, NumType e21, NumType e22, NumType e23,
|
||||
NumType e30, NumType e31, NumType e32, NumType e33);
|
||||
|
||||
// Get and set the upper 3x3 rotation matrix.
|
||||
INLINE void set_upper_3(const LMatrix3<NumType> &upper3);
|
||||
INLINE LMatrix3<NumType> get_upper_3() const;
|
||||
|
||||
INLINE void set_row(int row, const LVecBase4<NumType> &v);
|
||||
INLINE void set_col(int col, const LVecBase4<NumType> &v);
|
||||
|
||||
INLINE void set_row(int row, const LVecBase3<NumType> &v);
|
||||
INLINE void set_col(int col, const LVecBase3<NumType> &v);
|
||||
|
||||
INLINE LVecBase4<NumType> get_row(int row) const;
|
||||
INLINE LVecBase4<NumType> get_col(int col) const;
|
||||
|
||||
INLINE LVecBase3<NumType> get_row3(int row) const;
|
||||
INLINE LVecBase3<NumType> get_col3(int col) const;
|
||||
|
||||
INLINE NumType &operator () (int row, int col);
|
||||
INLINE NumType operator () (int row, int col) const;
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE NumType get_cell(int row, int col) const;
|
||||
INLINE void set_cell(int row, int col, NumType value);
|
||||
|
||||
INLINE const NumType *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
|
||||
bool operator == (const LMatrix4<NumType> &other) const;
|
||||
INLINE bool operator != (const LMatrix4<NumType> &other) const;
|
||||
|
||||
INLINE int compare_to(const LMatrix4<NumType> &other) const;
|
||||
int compare_to(const LMatrix4<NumType> &other, NumType threshold) const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
xform(const LVecBase4<NumType> &v) const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
xform_point(const LVecBase3<NumType> &v) const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
xform_vec(const LVecBase3<NumType> &v) const;
|
||||
|
||||
LMatrix4<NumType> operator * (const LMatrix4<NumType> &other) const;
|
||||
LMatrix4<NumType> operator * (NumType scalar) const;
|
||||
LMatrix4<NumType> operator / (NumType scalar) const;
|
||||
|
||||
LMatrix4<NumType> &operator += (const LMatrix4<NumType> &other);
|
||||
LMatrix4<NumType> &operator -= (const LMatrix4<NumType> &other);
|
||||
|
||||
INLINE LMatrix4<NumType> &operator *= (const LMatrix4<NumType> &other);
|
||||
|
||||
LMatrix4<NumType> &operator *= (NumType scalar);
|
||||
LMatrix4<NumType> &operator /= (NumType scalar);
|
||||
|
||||
void transpose_from(const LMatrix4<NumType> &other);
|
||||
INLINE void transpose_in_place();
|
||||
|
||||
bool invert_from(const LMatrix4<NumType> &other);
|
||||
bool invert_affine_from(const LMatrix4<NumType> &other);
|
||||
INLINE bool invert_in_place();
|
||||
|
||||
static const LMatrix4<NumType> &ident_mat();
|
||||
static LMatrix4<NumType> translate_mat(const LVecBase3<NumType> &trans);
|
||||
static LMatrix4<NumType> translate_mat(NumType tx, NumType ty, NumType tz);
|
||||
static LMatrix4<NumType> rotate_mat(NumType angle,
|
||||
LVecBase3<NumType> axis,
|
||||
CoordinateSystem cs = CS_default);
|
||||
static LMatrix4<NumType> scale_mat(const LVecBase3<NumType> &scale);
|
||||
static LMatrix4<NumType> scale_mat(NumType sx, NumType sy, NumType sz);
|
||||
static LMatrix4<NumType> scale_mat(NumType scale);
|
||||
|
||||
static const LMatrix4<NumType> &y_to_z_up_mat();
|
||||
static const LMatrix4<NumType> &z_to_y_up_mat();
|
||||
|
||||
static LMatrix4<NumType> convert_mat(CoordinateSystem from,
|
||||
CoordinateSystem to);
|
||||
|
||||
|
||||
bool almost_equal(const LMatrix4<NumType> &other,
|
||||
NumType threshold) const;
|
||||
INLINE bool almost_equal(const LMatrix4<NumType> &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
INLINE void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
private:
|
||||
INLINE NumType mult_cel(const LMatrix4<NumType> &other, int x, int y) const;
|
||||
bool decompose_mat(int index[4]);
|
||||
bool back_sub_mat(int index[4], LMatrix4<NumType> &inv, int row) const;
|
||||
|
||||
NumType _data[4 * 4];
|
||||
|
||||
//Functionality for reading and writing from/to a binary source
|
||||
public:
|
||||
void write_datagram(Datagram& destination) const;
|
||||
void read_datagram(DatagramIterator& scan);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream &operator << (ostream &out, const LMatrix4<NumType> &mat) {
|
||||
mat.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
template<class NumType>
|
||||
INLINE LMatrix4<NumType> transpose(const LMatrix4<NumType> &a);
|
||||
|
||||
INLINE FLOATNAME2(LMatrix4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix4) &source) {
|
||||
return FLOATNAME2(LMatrix4)
|
||||
(source(0, 0), source(0, 1), source(0, 2), source(0, 3),
|
||||
source(1, 0), source(1, 1), source(1, 2), source(1, 3),
|
||||
source(2, 0), source(2, 1), source(2, 2), source(2, 3),
|
||||
source(3, 0), source(3, 1), source(3, 2), source(3, 3));
|
||||
}
|
||||
template<class NumType>
|
||||
INLINE LMatrix4<NumType> invert(const LMatrix4<NumType> &a);
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LMatrix4<NumType2>
|
||||
lcast_to(NumType2 *type, const LMatrix4<NumType> &source);
|
||||
|
||||
|
||||
#include "lmatrix4.I"
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix4<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix4<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,43 +3,20 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Class : LOrientation
|
||||
// Description : This is a unit quaternion representing an orientation.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA FLOATNAME(LOrientation) : public FLOATNAME(LQuaternionBase) {
|
||||
public:
|
||||
INLINE FLOATNAME(LOrientation)();
|
||||
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LQuaternionBase)&);
|
||||
INLINE FLOATNAME(LOrientation)(FLOATTYPE1, FLOATTYPE1, FLOATTYPE1, FLOATTYPE1);
|
||||
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &, float);
|
||||
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &);
|
||||
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &);
|
||||
virtual ~FLOATNAME(LOrientation)();
|
||||
#include "lorientation.h"
|
||||
#include <notify.h>
|
||||
|
||||
INLINE FLOATNAME(LOrientation)
|
||||
operator *(const FLOATNAME(LQuaternionBase)& other) const;
|
||||
|
||||
INLINE FLOATNAME(LOrientation)
|
||||
operator *(const FLOATNAME(LOrientation)& other) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LOrientation<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LOrientation::Default Constructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation)::
|
||||
FLOATNAME(LOrientation)() {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType>::
|
||||
LOrientation() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -47,10 +24,10 @@ FLOATNAME(LOrientation)() {
|
|||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation)::
|
||||
FLOATNAME(LOrientation)(const FLOATNAME(LQuaternionBase)& c) :
|
||||
FLOATNAME(LQuaternionBase)(c) {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType>::
|
||||
LOrientation(const LQuaternionBase<NumType>& c) :
|
||||
LQuaternionBase<NumType>(c) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -58,10 +35,10 @@ FLOATNAME(LOrientation)(const FLOATNAME(LQuaternionBase)& c) :
|
|||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation)::
|
||||
FLOATNAME(LOrientation)(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k) :
|
||||
FLOATNAME(LQuaternionBase)(r, i, j, k) {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType>::
|
||||
LOrientation(NumType r, NumType i, NumType j, NumType k) :
|
||||
LQuaternionBase<NumType>(r, i, j, k) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -69,9 +46,9 @@ FLOATNAME(LOrientation)(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k)
|
|||
// Access: public
|
||||
// Description: vector + twist
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation)::
|
||||
FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &point_at, float twist) {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType>::
|
||||
LOrientation(const LVector3<NumType> &point_at, float twist) {
|
||||
float radians = twist * ((float) MathNumbers::pi / 180.0f);
|
||||
float theta_over_2 = radians / 2.0f;
|
||||
float sin_to2 = sinf(theta_over_2);
|
||||
|
|
@ -87,9 +64,9 @@ FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &point_at, float twist) {
|
|||
// Access: public
|
||||
// Description: matrix3
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation)::
|
||||
FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &m) {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType>::
|
||||
LOrientation(const LMatrix3<NumType> &m) {
|
||||
set(m);
|
||||
}
|
||||
|
||||
|
|
@ -98,21 +75,31 @@ FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &m) {
|
|||
// Access: public
|
||||
// Description: matrix4
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation)::
|
||||
FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &m) {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType>::
|
||||
LOrientation(const LMatrix4<NumType> &m) {
|
||||
set(m);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LOrientation::Destructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
LOrientation<NumType>::
|
||||
~LOrientation() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LOrientation::operator *
|
||||
// Access: public
|
||||
// Description: Orientation * rotation = Orientation
|
||||
// Applies an rotation to an orientation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation) FLOATNAME(LOrientation)::
|
||||
operator *(const FLOATNAME(LQuaternionBase)& other) const {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType> LOrientation<NumType>::
|
||||
operator *(const LQuaternionBase<NumType>& other) const {
|
||||
return multiply(other);
|
||||
}
|
||||
|
||||
|
|
@ -123,8 +110,25 @@ operator *(const FLOATNAME(LQuaternionBase)& other) const {
|
|||
// This is a meaningless operation, and will always
|
||||
// simply return the rhs.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LOrientation) FLOATNAME(LOrientation)::
|
||||
operator *(const FLOATNAME(LOrientation)& other) const {
|
||||
template<class NumType>
|
||||
INLINE LOrientation<NumType> LOrientation<NumType>::
|
||||
operator *(const LOrientation<NumType>& other) const {
|
||||
return other;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LOrientation::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LOrientation<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
// Format a string to describe the type.
|
||||
do_init_type(NumType);
|
||||
string name =
|
||||
"LOrientation<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,41 @@
|
|||
#define __LORIENTATION_H__
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <notify.h>
|
||||
#include "lquaternion.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Class : LOrientation
|
||||
// Description : This is a unit quaternion representing an orientation.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
template <class NumType>
|
||||
class LOrientation : public LQuaternionBase<NumType> {
|
||||
public:
|
||||
INLINE LOrientation();
|
||||
INLINE LOrientation(const LQuaternionBase<NumType>&);
|
||||
INLINE LOrientation(NumType, NumType, NumType, NumType);
|
||||
INLINE LOrientation(const LVector3<NumType> &, float);
|
||||
INLINE LOrientation(const LMatrix3<NumType> &);
|
||||
INLINE LOrientation(const LMatrix4<NumType> &);
|
||||
virtual ~LOrientation();
|
||||
|
||||
INLINE LOrientation<NumType>
|
||||
operator *(const LQuaternionBase<NumType>& other) const;
|
||||
|
||||
INLINE LOrientation<NumType>
|
||||
operator *(const LOrientation<NumType>& other) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "lorientation.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lorientation.I"
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LOrientation<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LOrientation<double>)
|
||||
|
||||
#endif /* __LORIENTATION_H__ */
|
||||
|
|
|
|||
|
|
@ -3,60 +3,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LPoint2
|
||||
// Description : This is a two-component point in space.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LPoint2) : public FLOATNAME(LVecBase2) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LPoint2)();
|
||||
INLINE FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©);
|
||||
INLINE FLOATNAME(LPoint2) &operator = (const FLOATNAME(LVecBase2) ©);
|
||||
INLINE FLOATNAME(LPoint2) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LPoint2)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LPoint2)(FLOATTYPE1 x, FLOATTYPE1 y);
|
||||
|
||||
INLINE static FLOATNAME(LPoint2) zero();
|
||||
INLINE static FLOATNAME(LPoint2) unit_x();
|
||||
INLINE static FLOATNAME(LPoint2) unit_y();
|
||||
|
||||
INLINE FLOATNAME(LPoint2) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)
|
||||
operator + (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator + (const FLOATNAME(LVector2) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)
|
||||
operator - (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE FLOATNAME(LVector2)
|
||||
operator - (const FLOATNAME(LPoint2) &other) const;
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator - (const FLOATNAME(LVector2) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LPoint2) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LPoint2) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LPoint2<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LPoint2::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2)::
|
||||
FLOATNAME(LPoint2)() {
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType>::
|
||||
LPoint2() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -64,9 +21,9 @@ FLOATNAME(LPoint2)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2)::
|
||||
FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) {
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType>::
|
||||
LPoint2(const LVecBase2<NumType> ©) : LVecBase2<NumType>(copy) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -74,10 +31,10 @@ FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) &FLOATNAME(LPoint2)::
|
||||
operator = (const FLOATNAME(LVecBase2) ©) {
|
||||
FLOATNAME(LVecBase2)::operator = (copy);
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> &LPoint2<NumType>::
|
||||
operator = (const LVecBase2<NumType> ©) {
|
||||
LVecBase2<NumType>::operator = (copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -86,10 +43,10 @@ operator = (const FLOATNAME(LVecBase2) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) &FLOATNAME(LPoint2)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
FLOATNAME(LVecBase2)::operator = (fill_value);
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> &LPoint2<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
LVecBase2<NumType>::operator = (fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -98,10 +55,10 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2)::
|
||||
FLOATNAME(LPoint2)(FLOATTYPE1 fill_value) :
|
||||
FLOATNAME(LVecBase2)(fill_value)
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType>::
|
||||
LPoint2(NumType fill_value) :
|
||||
LVecBase2<NumType>(fill_value)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -110,10 +67,10 @@ FLOATNAME(LPoint2)(FLOATTYPE1 fill_value) :
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2)::
|
||||
FLOATNAME(LPoint2)(FLOATTYPE1 x, FLOATTYPE1 y) :
|
||||
FLOATNAME(LVecBase2)(x, y)
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType>::
|
||||
LPoint2(NumType x, NumType y) :
|
||||
LVecBase2<NumType>(x, y)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -122,10 +79,10 @@ FLOATNAME(LPoint2)(FLOATTYPE1 x, FLOATTYPE1 y) :
|
|||
// Access: Public
|
||||
// Description: Returns a zero point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LPoint2)(0.0, 0.0);
|
||||
return LPoint2<NumType>(0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -133,10 +90,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LPoint2)(1.0, 0.0);
|
||||
return LPoint2<NumType>(1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -144,10 +101,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LPoint2)(0.0, 1.0);
|
||||
return LPoint2<NumType>(0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -155,10 +112,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase2)::operator - ();
|
||||
return LVecBase2<NumType>::operator - ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -166,10 +123,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LPoint2)::
|
||||
operator + (const FLOATNAME(LVecBase2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LPoint2<NumType>::
|
||||
operator + (const LVecBase2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -177,10 +134,10 @@ operator + (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
operator + (const FLOATNAME(LVector2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
operator + (const LVector2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -188,10 +145,10 @@ operator + (const FLOATNAME(LVector2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LPoint2)::
|
||||
operator - (const FLOATNAME(LVecBase2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LPoint2<NumType>::
|
||||
operator - (const LVecBase2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -199,10 +156,10 @@ operator - (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LPoint2)::
|
||||
operator - (const FLOATNAME(LPoint2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LPoint2<NumType>::
|
||||
operator - (const LPoint2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -210,10 +167,10 @@ operator - (const FLOATNAME(LPoint2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
operator - (const FLOATNAME(LVector2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
operator - (const LVector2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -221,10 +178,10 @@ operator - (const FLOATNAME(LVector2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LPoint2)(FLOATNAME(LVecBase2)::operator * (scalar));
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LPoint2<NumType>(LVecBase2<NumType>::operator * (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -232,10 +189,37 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LPoint2)(FLOATNAME(LVecBase2)::operator / (scalar));
|
||||
template<class NumType>
|
||||
INLINE LPoint2<NumType> LPoint2<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LPoint2<NumType>(LVecBase2<NumType>::operator / (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LPoint2::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LPoint2<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
LVecBase2<NumType>::init_type();
|
||||
string name =
|
||||
"LPoint2<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name,
|
||||
LVecBase2<NumType>::get_class_type());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint2<NumType2>
|
||||
lcast_to(NumType2 *, const LPoint2<NumType> &source) {
|
||||
return LPoint2<NumType2>(source[0], source[1]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,30 +11,59 @@
|
|||
#include "lvecBase2.h"
|
||||
#include "lvector2.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LPoint2
|
||||
// Description : This is a two-component point in space.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LPoint2 : public LVecBase2<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LPoint2();
|
||||
INLINE LPoint2(const LVecBase2<NumType> ©);
|
||||
INLINE LPoint2<NumType> &operator = (const LVecBase2<NumType> ©);
|
||||
INLINE LPoint2<NumType> &operator = (NumType fill_value);
|
||||
INLINE LPoint2(NumType fill_value);
|
||||
INLINE LPoint2(NumType x, NumType y);
|
||||
|
||||
INLINE static LPoint2<NumType> zero();
|
||||
INLINE static LPoint2<NumType> unit_x();
|
||||
INLINE static LPoint2<NumType> unit_y();
|
||||
|
||||
INLINE LPoint2<NumType> operator - () const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
operator + (const LVecBase2<NumType> &other) const;
|
||||
INLINE LPoint2<NumType>
|
||||
operator + (const LVector2<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
operator - (const LVecBase2<NumType> &other) const;
|
||||
INLINE LVector2<NumType>
|
||||
operator - (const LPoint2<NumType> &other) const;
|
||||
INLINE LPoint2<NumType>
|
||||
operator - (const LVector2<NumType> &other) const;
|
||||
|
||||
INLINE LPoint2<NumType> operator * (NumType scalar) const;
|
||||
INLINE LPoint2<NumType> operator / (NumType scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint2<NumType2>
|
||||
lcast_to(NumType2 *type, const LPoint2<NumType> &source);
|
||||
|
||||
#include "lpoint2.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lpoint2.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LPoint2)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source) {
|
||||
return FLOATNAME2(LPoint2)(source[0], source[1]);
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LPoint2)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source) {
|
||||
return FLOATNAME2(LPoint2)(source[0], source[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint2<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint2<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,74 +3,19 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LPoint3
|
||||
// Description : This is a three-component point in space (as opposed
|
||||
// to a three-component vector, which represents a
|
||||
// direction and a distance). Some of the methods are
|
||||
// slightly different between LPoint3 and LVector3; in
|
||||
// particular, subtraction of two points yields a
|
||||
// vector, while addition of a vector and a point yields
|
||||
// a point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "lvector3.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LPoint3) : public FLOATNAME(LVecBase3) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LPoint3)();
|
||||
INLINE FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©);
|
||||
INLINE FLOATNAME(LPoint3) &operator = (const FLOATNAME(LVecBase3) ©);
|
||||
INLINE FLOATNAME(LPoint3) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LPoint3)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LPoint3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z);
|
||||
|
||||
INLINE static FLOATNAME(LPoint3) zero();
|
||||
INLINE static FLOATNAME(LPoint3) unit_x();
|
||||
INLINE static FLOATNAME(LPoint3) unit_y();
|
||||
INLINE static FLOATNAME(LPoint3) unit_z();
|
||||
|
||||
INLINE FLOATNAME(LPoint3) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator + (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator + (const FLOATNAME(LVector3) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator - (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator - (const FLOATNAME(LPoint3) &other) const;
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator - (const FLOATNAME(LVector3) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LPoint3) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LPoint3) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
// Some special named constructors for LPoint3.
|
||||
|
||||
INLINE static FLOATNAME(LPoint3) origin(CoordinateSystem cs = CS_default);
|
||||
INLINE static FLOATNAME(LPoint3) rfu(FLOATTYPE1 right,
|
||||
FLOATTYPE1 fwd,
|
||||
FLOATTYPE1 up,
|
||||
CoordinateSystem cs = CS_default);
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LPoint3<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LPoint3::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3)::
|
||||
FLOATNAME(LPoint3)() {
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType>::
|
||||
LPoint3() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -78,9 +23,9 @@ FLOATNAME(LPoint3)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3)::
|
||||
FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy) {
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType>::
|
||||
LPoint3(const LVecBase3<NumType> ©) : LVecBase3<NumType>(copy) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -88,10 +33,10 @@ FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) &FLOATNAME(LPoint3)::
|
||||
operator = (const FLOATNAME(LVecBase3) ©) {
|
||||
FLOATNAME(LVecBase3)::operator = (copy);
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> &LPoint3<NumType>::
|
||||
operator = (const LVecBase3<NumType> ©) {
|
||||
LVecBase3<NumType>::operator = (copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -100,10 +45,10 @@ operator = (const FLOATNAME(LVecBase3) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) &FLOATNAME(LPoint3)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
FLOATNAME(LVecBase3)::operator = (fill_value);
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> &LPoint3<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
LVecBase3<NumType>::operator = (fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -112,10 +57,10 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3)::
|
||||
FLOATNAME(LPoint3)(FLOATTYPE1 fill_value) :
|
||||
FLOATNAME(LVecBase3)(fill_value)
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType>::
|
||||
LPoint3(NumType fill_value) :
|
||||
LVecBase3<NumType>(fill_value)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -124,10 +69,10 @@ FLOATNAME(LPoint3)(FLOATTYPE1 fill_value) :
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3)::
|
||||
FLOATNAME(LPoint3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) :
|
||||
FLOATNAME(LVecBase3)(x, y, z)
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType>::
|
||||
LPoint3(NumType x, NumType y, NumType z) :
|
||||
LVecBase3<NumType>(x, y, z)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -136,10 +81,10 @@ FLOATNAME(LPoint3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) :
|
|||
// Access: Public
|
||||
// Description: Returns a zero point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LPoint3)(0.0, 0.0, 0.0);
|
||||
return LPoint3<NumType>(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -147,10 +92,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LPoint3)(1.0, 0.0, 0.0);
|
||||
return LPoint3<NumType>(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -158,10 +103,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LPoint3)(0.0, 1.0, 0.0);
|
||||
return LPoint3<NumType>(0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -169,10 +114,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Z point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
unit_z() {
|
||||
return FLOATNAME(LPoint3)(0.0, 0.0, 1.0);
|
||||
return LPoint3<NumType>(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -180,10 +125,10 @@ unit_z() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase3)::operator - ();
|
||||
return LVecBase3<NumType>::operator - ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -191,10 +136,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LPoint3)::
|
||||
operator + (const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LPoint3<NumType>::
|
||||
operator + (const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -202,10 +147,10 @@ operator + (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
operator + (const FLOATNAME(LVector3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
operator + (const LVector3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -213,10 +158,10 @@ operator + (const FLOATNAME(LVector3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LPoint3)::
|
||||
operator - (const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LPoint3<NumType>::
|
||||
operator - (const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -224,10 +169,10 @@ operator - (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LPoint3)::
|
||||
operator - (const FLOATNAME(LPoint3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LPoint3<NumType>::
|
||||
operator - (const LPoint3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -235,10 +180,10 @@ operator - (const FLOATNAME(LPoint3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
operator - (const FLOATNAME(LVector3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
operator - (const LVector3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -246,10 +191,10 @@ operator - (const FLOATNAME(LVector3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
cross(const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::cross(other);
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
cross(const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::cross(other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -257,10 +202,10 @@ cross(const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LPoint3)(FLOATNAME(LVecBase3)::operator * (scalar));
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LPoint3<NumType>(LVecBase3<NumType>::operator * (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -268,10 +213,10 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LPoint3)(FLOATNAME(LVecBase3)::operator / (scalar));
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LPoint3<NumType>(LVecBase3<NumType>::operator / (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -282,10 +227,10 @@ operator / (FLOATTYPE1 scalar) const {
|
|||
// existing coordinate systems; it's hard to imagine it
|
||||
// ever being different.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
origin(CoordinateSystem) {
|
||||
return FLOATNAME(LPoint3)(0.0, 0.0, 0.0);
|
||||
return LPoint3<NumType>(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -295,11 +240,39 @@ origin(CoordinateSystem) {
|
|||
// displacements from the origin, wherever that maps to
|
||||
// in the given coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
|
||||
rfu(FLOATTYPE1 right_v, FLOATTYPE1 fwd_v, FLOATTYPE1 up_v,
|
||||
template<class NumType>
|
||||
INLINE LPoint3<NumType> LPoint3<NumType>::
|
||||
rfu(NumType right_v, NumType fwd_v, NumType up_v,
|
||||
CoordinateSystem cs) {
|
||||
return origin(cs) +
|
||||
FLOATNAME(LVector3)::rfu(right_v, fwd_v, up_v, cs);
|
||||
LVector3<NumType>::rfu(right_v, fwd_v, up_v, cs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LPoint3::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LPoint3<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
LVecBase3<NumType>::init_type();
|
||||
string name =
|
||||
"LPoint3<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name,
|
||||
LVecBase3<NumType>::get_class_type());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint3<NumType2>
|
||||
lcast_to(NumType2 *, const LPoint3<NumType> &source) {
|
||||
return LPoint3<NumType2>(source[0], source[1], source[2]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,31 +12,74 @@
|
|||
#include "lvecBase3.h"
|
||||
#include "lvector3.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LPoint3
|
||||
// Description : This is a three-component point in space (as opposed
|
||||
// to a three-component vector, which represents a
|
||||
// direction and a distance). Some of the methods are
|
||||
// slightly different between LPoint3 and LVector3; in
|
||||
// particular, subtraction of two points yields a
|
||||
// vector, while addition of a vector and a point yields
|
||||
// a point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LPoint3 : public LVecBase3<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LPoint3();
|
||||
INLINE LPoint3(const LVecBase3<NumType> ©);
|
||||
INLINE LPoint3<NumType> &operator = (const LVecBase3<NumType> ©);
|
||||
INLINE LPoint3<NumType> &operator = (NumType fill_value);
|
||||
INLINE LPoint3(NumType fill_value);
|
||||
INLINE LPoint3(NumType x, NumType y, NumType z);
|
||||
|
||||
INLINE static LPoint3<NumType> zero();
|
||||
INLINE static LPoint3<NumType> unit_x();
|
||||
INLINE static LPoint3<NumType> unit_y();
|
||||
INLINE static LPoint3<NumType> unit_z();
|
||||
|
||||
INLINE LPoint3<NumType> operator - () const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
operator + (const LVecBase3<NumType> &other) const;
|
||||
INLINE LPoint3<NumType>
|
||||
operator + (const LVector3<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
operator - (const LVecBase3<NumType> &other) const;
|
||||
INLINE LVector3<NumType>
|
||||
operator - (const LPoint3<NumType> &other) const;
|
||||
INLINE LPoint3<NumType>
|
||||
operator - (const LVector3<NumType> &other) const;
|
||||
|
||||
INLINE LPoint3<NumType> cross(const LVecBase3<NumType> &other) const;
|
||||
INLINE LPoint3<NumType> operator * (NumType scalar) const;
|
||||
INLINE LPoint3<NumType> operator / (NumType scalar) const;
|
||||
|
||||
// Some special named constructors for LPoint3.
|
||||
|
||||
INLINE static LPoint3<NumType> origin(CoordinateSystem cs = CS_default);
|
||||
INLINE static LPoint3<NumType> rfu(NumType right,
|
||||
NumType fwd,
|
||||
NumType up,
|
||||
CoordinateSystem cs = CS_default);
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint3<NumType2>
|
||||
lcast_to(NumType2 *type, const LPoint3<NumType> &source);
|
||||
|
||||
#include "lpoint3.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lpoint3.I"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LPoint3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source) {
|
||||
return FLOATNAME2(LPoint3)(source[0], source[1], source[2]);
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LPoint3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source) {
|
||||
return FLOATNAME2(LPoint3)(source[0], source[1], source[2]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint3<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint3<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,61 +3,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LPoint4
|
||||
// Description : This is a four-component point in space.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LPoint4) : public FLOATNAME(LVecBase4) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LPoint4)();
|
||||
INLINE FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©);
|
||||
INLINE FLOATNAME(LPoint4) &operator = (const FLOATNAME(LVecBase4) ©);
|
||||
INLINE FLOATNAME(LPoint4) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LPoint4)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LPoint4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w);
|
||||
|
||||
INLINE static FLOATNAME(LPoint4) zero();
|
||||
INLINE static FLOATNAME(LPoint4) unit_x();
|
||||
INLINE static FLOATNAME(LPoint4) unit_y();
|
||||
INLINE static FLOATNAME(LPoint4) unit_z();
|
||||
INLINE static FLOATNAME(LPoint4) unit_w();
|
||||
|
||||
INLINE FLOATNAME(LPoint4) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator + (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE FLOATNAME(LPoint4)
|
||||
operator + (const FLOATNAME(LVector4) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator - (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE FLOATNAME(LVector4)
|
||||
operator - (const FLOATNAME(LPoint4) &other) const;
|
||||
INLINE FLOATNAME(LPoint4)
|
||||
operator - (const FLOATNAME(LVector4) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LPoint4) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LPoint4) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LPoint4<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LPoint4::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4)::
|
||||
FLOATNAME(LPoint4)() {
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType>::
|
||||
LPoint4() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -65,9 +21,9 @@ FLOATNAME(LPoint4)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4)::
|
||||
FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) {
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType>::
|
||||
LPoint4(const LVecBase4<NumType> ©) : LVecBase4<NumType>(copy) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -75,10 +31,10 @@ FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) &FLOATNAME(LPoint4)::
|
||||
operator = (const FLOATNAME(LVecBase4) ©) {
|
||||
FLOATNAME(LVecBase4)::operator = (copy);
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> &LPoint4<NumType>::
|
||||
operator = (const LVecBase4<NumType> ©) {
|
||||
LVecBase4<NumType>::operator = (copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -87,10 +43,10 @@ operator = (const FLOATNAME(LVecBase4) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) &FLOATNAME(LPoint4)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
FLOATNAME(LVecBase4)::operator = (fill_value);
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> &LPoint4<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
LVecBase4<NumType>::operator = (fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -99,10 +55,10 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4)::
|
||||
FLOATNAME(LPoint4)(FLOATTYPE1 fill_value) :
|
||||
FLOATNAME(LVecBase4)(fill_value)
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType>::
|
||||
LPoint4(NumType fill_value) :
|
||||
LVecBase4<NumType>(fill_value)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -111,10 +67,10 @@ FLOATNAME(LPoint4)(FLOATTYPE1 fill_value) :
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4)::
|
||||
FLOATNAME(LPoint4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) :
|
||||
FLOATNAME(LVecBase4)(x, y, z, w)
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType>::
|
||||
LPoint4(NumType x, NumType y, NumType z, NumType w) :
|
||||
LVecBase4<NumType>(x, y, z, w)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -123,10 +79,10 @@ FLOATNAME(LPoint4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) :
|
|||
// Access: Public
|
||||
// Description: Returns a zero point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LPoint4)(0.0, 0.0, 0.0, 0.0);
|
||||
return LPoint4<NumType>(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -134,10 +90,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LPoint4)(1.0, 0.0, 0.0, 0.0);
|
||||
return LPoint4<NumType>(1.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -145,10 +101,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LPoint4)(0.0, 1.0, 0.0, 0.0);
|
||||
return LPoint4<NumType>(0.0, 1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -156,10 +112,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Z point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
unit_z() {
|
||||
return FLOATNAME(LPoint4)(0.0, 0.0, 1.0, 0.0);
|
||||
return LPoint4<NumType>(0.0, 0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -167,10 +123,10 @@ unit_z() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit W point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
unit_w() {
|
||||
return FLOATNAME(LPoint4)(0.0, 0.0, 0.0, 1.0);
|
||||
return LPoint4<NumType>(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -178,10 +134,10 @@ unit_w() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase4)::operator - ();
|
||||
return LVecBase4<NumType>::operator - ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -189,10 +145,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LPoint4)::
|
||||
operator + (const FLOATNAME(LVecBase4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LPoint4<NumType>::
|
||||
operator + (const LVecBase4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -200,10 +156,10 @@ operator + (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
operator + (const FLOATNAME(LVector4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
operator + (const LVector4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -211,10 +167,10 @@ operator + (const FLOATNAME(LVector4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LPoint4)::
|
||||
operator - (const FLOATNAME(LVecBase4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LPoint4<NumType>::
|
||||
operator - (const LVecBase4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -222,10 +178,10 @@ operator - (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LPoint4)::
|
||||
operator - (const FLOATNAME(LPoint4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LPoint4<NumType>::
|
||||
operator - (const LPoint4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -233,10 +189,10 @@ operator - (const FLOATNAME(LPoint4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
operator - (const FLOATNAME(LVector4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
operator - (const LVector4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -244,10 +200,10 @@ operator - (const FLOATNAME(LVector4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LPoint4)(FLOATNAME(LVecBase4)::operator * (scalar));
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LPoint4<NumType>(LVecBase4<NumType>::operator * (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -255,9 +211,37 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LPoint4)(FLOATNAME(LVecBase4)::operator / (scalar));
|
||||
template<class NumType>
|
||||
INLINE LPoint4<NumType> LPoint4<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LPoint4<NumType>(LVecBase4<NumType>::operator / (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LPoint4::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LPoint4<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
LVecBase4<NumType>::init_type();
|
||||
string name =
|
||||
"LPoint4<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name,
|
||||
LVecBase4<NumType>::get_class_type());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint4<NumType2>
|
||||
lcast_to(NumType2 *, const LPoint4<NumType> &source) {
|
||||
return LPoint4<NumType2>(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,33 +11,61 @@
|
|||
#include "lvecBase4.h"
|
||||
#include "lvector4.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LPoint4
|
||||
// Description : This is a four-component point in space.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LPoint4 : public LVecBase4<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LPoint4();
|
||||
INLINE LPoint4(const LVecBase4<NumType> ©);
|
||||
INLINE LPoint4<NumType> &operator = (const LVecBase4<NumType> ©);
|
||||
INLINE LPoint4<NumType> &operator = (NumType fill_value);
|
||||
INLINE LPoint4(NumType fill_value);
|
||||
INLINE LPoint4(NumType x, NumType y, NumType z, NumType w);
|
||||
|
||||
INLINE static LPoint4<NumType> zero();
|
||||
INLINE static LPoint4<NumType> unit_x();
|
||||
INLINE static LPoint4<NumType> unit_y();
|
||||
INLINE static LPoint4<NumType> unit_z();
|
||||
INLINE static LPoint4<NumType> unit_w();
|
||||
|
||||
INLINE LPoint4<NumType> operator - () const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
operator + (const LVecBase4<NumType> &other) const;
|
||||
INLINE LPoint4<NumType>
|
||||
operator + (const LVector4<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
operator - (const LVecBase4<NumType> &other) const;
|
||||
INLINE LVector4<NumType>
|
||||
operator - (const LPoint4<NumType> &other) const;
|
||||
INLINE LPoint4<NumType>
|
||||
operator - (const LVector4<NumType> &other) const;
|
||||
|
||||
INLINE LPoint4<NumType> operator * (NumType scalar) const;
|
||||
INLINE LPoint4<NumType> operator / (NumType scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint4<NumType2>
|
||||
lcast_to(NumType2 *type, const LPoint4<NumType> &source);
|
||||
|
||||
#include "lpoint4.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lpoint4.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME2(LPoint4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source) {
|
||||
return FLOATNAME2(LPoint4)(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
|
||||
INLINE FLOATNAME2(LPoint4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source) {
|
||||
return FLOATNAME2(LPoint4)(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
||||
|
||||
////EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4<float>)
|
||||
////EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4<double>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,127 +3,82 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : FLOATNAME(LQuaternionBase)
|
||||
// Description : This is the base quaternion class
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA FLOATNAME(LQuaternionBase) {
|
||||
protected:
|
||||
INLINE FLOATNAME(LQuaternionBase)
|
||||
multiply(const FLOATNAME(LQuaternionBase)&) const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LQuaternionBase)(void);
|
||||
INLINE FLOATNAME(LQuaternionBase)(const FLOATNAME(LQuaternionBase) &);
|
||||
INLINE FLOATNAME(LQuaternionBase)(FLOATTYPE1, FLOATTYPE1, FLOATTYPE1, FLOATTYPE1);
|
||||
virtual ~FLOATNAME(LQuaternionBase)(void);
|
||||
|
||||
static FLOATNAME(LQuaternionBase) pure_imaginary(const FLOATNAME(LVector3) &);
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)& operator =(const FLOATNAME(LQuaternionBase) &);
|
||||
INLINE bool operator ==(const FLOATNAME(LQuaternionBase) &) const;
|
||||
INLINE bool operator !=(const FLOATNAME(LQuaternionBase) &) const;
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase) operator *(const FLOATNAME(LQuaternionBase) &);
|
||||
INLINE FLOATNAME(LQuaternionBase)& operator *=(const FLOATNAME(LQuaternionBase) &);
|
||||
|
||||
INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &);
|
||||
INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &);
|
||||
|
||||
INLINE bool almost_equal(const FLOATNAME(LQuaternionBase) &, FLOATTYPE1) const;
|
||||
INLINE bool almost_equal(const FLOATNAME(LQuaternionBase) &) const;
|
||||
|
||||
INLINE void output(ostream&) const;
|
||||
|
||||
INLINE void set(FLOATTYPE1, FLOATTYPE1, FLOATTYPE1, FLOATTYPE1);
|
||||
|
||||
void set(const FLOATNAME(LMatrix3) &m);
|
||||
INLINE void set(const FLOATNAME(LMatrix4) &m);
|
||||
|
||||
void extract_to_matrix(FLOATNAME(LMatrix3) &m) const;
|
||||
void extract_to_matrix(FLOATNAME(LMatrix4) &m) const;
|
||||
|
||||
void set_hpr(const FLOATNAME(LVecBase3) &hpr);
|
||||
FLOATNAME(LVecBase3) get_hpr() const;
|
||||
|
||||
INLINE FLOATTYPE1 get_r(void) const;
|
||||
INLINE FLOATTYPE1 get_i(void) const;
|
||||
INLINE FLOATTYPE1 get_j(void) const;
|
||||
INLINE FLOATTYPE1 get_k(void) const;
|
||||
|
||||
INLINE void set_r(FLOATTYPE1 r);
|
||||
INLINE void set_i(FLOATTYPE1 i);
|
||||
INLINE void set_j(FLOATTYPE1 j);
|
||||
INLINE void set_k(FLOATTYPE1 k);
|
||||
|
||||
INLINE void normalize(void);
|
||||
|
||||
static const FLOATNAME(LQuaternionBase) &ident_quat(void);
|
||||
|
||||
private:
|
||||
FLOATTYPE1 _r, _i, _j, _k;
|
||||
public:
|
||||
static TypeHandle get_class_type(void) {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type(void);
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
|
||||
INLINE ostream& operator<<(ostream& os, const FLOATNAME(LQuaternionBase)& q) {
|
||||
q.output(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
BEGIN_PUBLISH
|
||||
INLINE FLOATNAME(LMatrix3)
|
||||
operator * (const FLOATNAME(LMatrix3) &m, const FLOATNAME(LQuaternionBase) &q);
|
||||
INLINE FLOATNAME(LMatrix4)
|
||||
operator * (const FLOATNAME(LMatrix4) &m, const FLOATNAME(LQuaternionBase) &q);
|
||||
END_PUBLISH
|
||||
template<class NumType>
|
||||
TypeHandle LQuaternionBase<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Default Constructor
|
||||
// Function: LQuaternionBase::Default Constructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)::
|
||||
FLOATNAME(LQuaternionBase)(void) {
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType>::
|
||||
LQuaternionBase(void) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Copy Constructor
|
||||
// Function: LQuaternionBase::Copy Constructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)::
|
||||
FLOATNAME(LQuaternionBase)(const FLOATNAME(LQuaternionBase)& c) :
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType>::
|
||||
LQuaternionBase(const LQuaternionBase<NumType>& c) :
|
||||
_r(c._r), _i(c._i), _j(c._j), _k(c._k) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Constructor
|
||||
// Function: LQuaternionBase::Constructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)::
|
||||
FLOATNAME(LQuaternionBase)(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k) {
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType>::
|
||||
LQuaternionBase(NumType r, NumType i, NumType j, NumType k) {
|
||||
set(r, i, j, k);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::set
|
||||
// Function: LQuaternionBase::Destructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
LQuaternionBase<NumType>::
|
||||
~LQuaternionBase() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LQuaternionBase::pure_imaginary_quat
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
LQuaternionBase<NumType> LQuaternionBase<NumType>::
|
||||
pure_imaginary(const LVector3<NumType> &v) {
|
||||
return LQuaternionBase<NumType>(0, v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LQuaternionBase::ident_quat
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
const LQuaternionBase<NumType> &LQuaternionBase<NumType>::
|
||||
ident_quat(void) {
|
||||
static LQuaternionBase<NumType> q(1, 0, 0, 0);
|
||||
return q;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LQuaternionBase::set
|
||||
// Access: public
|
||||
// Description: assignment
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
set(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k) {
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set(NumType r, NumType i, NumType j, NumType k) {
|
||||
_r = r;
|
||||
_i = i;
|
||||
_j = j;
|
||||
|
|
@ -131,13 +86,13 @@ set(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Assignment Operator
|
||||
// Function: LQuaternionBase::Assignment Operator
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)& FLOATNAME(LQuaternionBase)::
|
||||
operator =(const FLOATNAME(LQuaternionBase)& c) {
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType>& LQuaternionBase<NumType>::
|
||||
operator =(const LQuaternionBase<NumType>& c) {
|
||||
_r = c._r;
|
||||
_i = c._i;
|
||||
_j = c._j;
|
||||
|
|
@ -147,13 +102,13 @@ operator =(const FLOATNAME(LQuaternionBase)& c) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Equality Operator
|
||||
// Function: LQuaternionBase::Equality Operator
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LQuaternionBase)::
|
||||
operator ==(const FLOATNAME(LQuaternionBase)& c) const {
|
||||
template<class NumType>
|
||||
INLINE bool LQuaternionBase<NumType>::
|
||||
operator ==(const LQuaternionBase<NumType>& c) const {
|
||||
return (_r == c._r &&
|
||||
_i == c._i &&
|
||||
_j == c._j &&
|
||||
|
|
@ -161,81 +116,81 @@ operator ==(const FLOATNAME(LQuaternionBase)& c) const {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Inequality Operator
|
||||
// Function: LQuaternionBase::Inequality Operator
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LQuaternionBase)::
|
||||
operator !=(const FLOATNAME(LQuaternionBase)& c) const {
|
||||
template<class NumType>
|
||||
INLINE bool LQuaternionBase<NumType>::
|
||||
operator !=(const LQuaternionBase<NumType>& c) const {
|
||||
return !operator==(c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::multiply
|
||||
// Function: LQuaternionBase::multiply
|
||||
// Access: protected
|
||||
// Description: actual multiply call (non virtual)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType> LQuaternionBase<NumType>::
|
||||
multiply(const LQuaternionBase<NumType>& rhs) const {
|
||||
NumType r = (_r * rhs._r) - (_i * rhs._i) - (_j * rhs._j) - (_k * rhs._k);
|
||||
NumType i = (_i * rhs._r) + (_r * rhs._i) - (_k * rhs._j) + (_j * rhs._k);
|
||||
NumType j = (_j * rhs._r) + (_k * rhs._i) + (_r * rhs._j) - (_i * rhs._k);
|
||||
NumType k = (_k * rhs._r) - (_j * rhs._i) + (_i * rhs._j) + (_r * rhs._k);
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase) FLOATNAME(LQuaternionBase)::
|
||||
multiply(const FLOATNAME(LQuaternionBase)& rhs) const {
|
||||
FLOATTYPE1 r = (_r * rhs._r) - (_i * rhs._i) - (_j * rhs._j) - (_k * rhs._k);
|
||||
FLOATTYPE1 i = (_i * rhs._r) + (_r * rhs._i) - (_k * rhs._j) + (_j * rhs._k);
|
||||
FLOATTYPE1 j = (_j * rhs._r) + (_k * rhs._i) + (_r * rhs._j) - (_i * rhs._k);
|
||||
FLOATTYPE1 k = (_k * rhs._r) - (_j * rhs._i) + (_i * rhs._j) + (_r * rhs._k);
|
||||
|
||||
return FLOATNAME(LQuaternionBase)(r, i , j, k);
|
||||
return LQuaternionBase<NumType>(r, i , j, k);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Multiply Operator
|
||||
// Function: LQuaternionBase::Multiply Operator
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase) FLOATNAME(LQuaternionBase)::
|
||||
operator *(const FLOATNAME(LQuaternionBase)& c) {
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType> LQuaternionBase<NumType>::
|
||||
operator *(const LQuaternionBase<NumType>& c) {
|
||||
return multiply(c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Multiply Assignment Operator
|
||||
// Function: LQuaternionBase::Multiply Assignment Operator
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)& FLOATNAME(LQuaternionBase)::
|
||||
operator *=(const FLOATNAME(LQuaternionBase)& c) {
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType>& LQuaternionBase<NumType>::
|
||||
operator *=(const LQuaternionBase<NumType>& c) {
|
||||
(*this) = operator*(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Multiply Operator
|
||||
// Function: LQuaternionBase::Multiply Operator
|
||||
// Access: public
|
||||
// Description: Quat * Matrix = matrix
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix3) FLOATNAME(LQuaternionBase)::
|
||||
operator *(const FLOATNAME(LMatrix3) &m) {
|
||||
FLOATNAME(LMatrix3) result;
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType> LQuaternionBase<NumType>::
|
||||
operator *(const LMatrix3<NumType> &m) {
|
||||
LMatrix3<NumType> result;
|
||||
extract_to_matrix(result);
|
||||
return result * m;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::Multiply Operator
|
||||
// Function: LQuaternionBase::Multiply Operator
|
||||
// Access: public
|
||||
// Description: Quat * Matrix = matrix
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix4) FLOATNAME(LQuaternionBase)::
|
||||
operator *(const FLOATNAME(LMatrix4) &m) {
|
||||
FLOATNAME(LMatrix3) m_upper_3 = m.get_upper_3();
|
||||
FLOATNAME(LMatrix3) this_quat;
|
||||
template<class NumType>
|
||||
INLINE LMatrix4<NumType> LQuaternionBase<NumType>::
|
||||
operator *(const LMatrix4<NumType> &m) {
|
||||
LMatrix3<NumType> m_upper_3 = m.get_upper_3();
|
||||
LMatrix3<NumType> this_quat;
|
||||
extract_to_matrix(this_quat);
|
||||
|
||||
FLOATNAME(LMatrix4) result;
|
||||
LMatrix4<NumType> result;
|
||||
result.set_upper_3(this_quat * m_upper_3);
|
||||
result.set_row(3, m.get_row(3));
|
||||
result.set_col(3, m.get_col(3));
|
||||
|
|
@ -244,14 +199,14 @@ operator *(const FLOATNAME(LMatrix4) &m) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::almost_equal
|
||||
// Function: LQuaternionBase::almost_equal
|
||||
// Access: public
|
||||
// Description: Returns true if two quaternions are memberwise equal
|
||||
// within a specified tolerance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LQuaternionBase)::
|
||||
almost_equal(const FLOATNAME(LQuaternionBase)& c, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE bool LQuaternionBase<NumType>::
|
||||
almost_equal(const LQuaternionBase<NumType>& c, NumType threshold) const {
|
||||
return (IS_THRESHOLD_EQUAL(_r, c._r, threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_i, c._i, threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_j, c._j, threshold) &&
|
||||
|
|
@ -259,24 +214,24 @@ almost_equal(const FLOATNAME(LQuaternionBase)& c, FLOATTYPE1 threshold) const {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::almost_equal
|
||||
// Function: LQuaternionBase::almost_equal
|
||||
// Access: public
|
||||
// Description: Returns true if two quaternions are memberwise equal
|
||||
// within a default tolerance based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LQuaternionBase)::
|
||||
almost_equal(const FLOATNAME(LQuaternionBase)& c) const {
|
||||
return almost_equal(c, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE bool LQuaternionBase<NumType>::
|
||||
almost_equal(const LQuaternionBase<NumType>& c) const {
|
||||
return almost_equal(c, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::output
|
||||
// Function: LQuaternionBase::output
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
output(ostream& os) const {
|
||||
os << MAYBE_ZERO(_r) << " + "
|
||||
<< MAYBE_ZERO(_i) << "i + "
|
||||
|
|
@ -285,102 +240,102 @@ output(ostream& os) const {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::get_r
|
||||
// Function: LQuaternionBase::get_r
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LQuaternionBase)::
|
||||
template<class NumType>
|
||||
INLINE NumType LQuaternionBase<NumType>::
|
||||
get_r(void) const {
|
||||
return _r;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::get_i
|
||||
// Function: LQuaternionBase::get_i
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LQuaternionBase)::
|
||||
template<class NumType>
|
||||
INLINE NumType LQuaternionBase<NumType>::
|
||||
get_i(void) const {
|
||||
return _i;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::get_j
|
||||
// Function: LQuaternionBase::get_j
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LQuaternionBase)::
|
||||
template<class NumType>
|
||||
INLINE NumType LQuaternionBase<NumType>::
|
||||
get_j(void) const {
|
||||
return _j;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::get_k
|
||||
// Function: LQuaternionBase::get_k
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LQuaternionBase)::
|
||||
template<class NumType>
|
||||
INLINE NumType LQuaternionBase<NumType>::
|
||||
get_k(void) const {
|
||||
return _k;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::set_r
|
||||
// Function: LQuaternionBase::set_r
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
set_r(FLOATTYPE1 r) {
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set_r(NumType r) {
|
||||
_r = r;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::set_i
|
||||
// Function: LQuaternionBase::set_i
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
set_i(FLOATTYPE1 i) {
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set_i(NumType i) {
|
||||
_i = i;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::set_j
|
||||
// Function: LQuaternionBase::set_j
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
set_j(FLOATTYPE1 j) {
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set_j(NumType j) {
|
||||
_j = j;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::set_k
|
||||
// Function: LQuaternionBase::set_k
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
set_k(FLOATTYPE1 k) {
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set_k(NumType k) {
|
||||
_k = k;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FLOATNAME(LQuaternionBase)::normalize
|
||||
// Function: LQuaternionBase::normalize
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
normalize(void) {
|
||||
FLOATTYPE1 l = csqrt((_r*_r)+(_i*_i)+(_j*_j)+(_k*_k));
|
||||
NumType l = csqrt((_r*_r)+(_i*_i)+(_j*_j)+(_k*_k));
|
||||
|
||||
if (l == 0.0) {
|
||||
_r = 0.;
|
||||
|
|
@ -396,26 +351,222 @@ normalize(void) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: set
|
||||
// Access: public
|
||||
// Description: Do-While Jones.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LQuaternionBase<NumType>::
|
||||
set(const LMatrix3<NumType> &m) {
|
||||
NumType m00 = m.get_cell(0, 0);
|
||||
NumType m01 = m.get_cell(0, 1);
|
||||
NumType m02 = m.get_cell(0, 2);
|
||||
NumType m10 = m.get_cell(1, 0);
|
||||
NumType m11 = m.get_cell(1, 1);
|
||||
NumType m12 = m.get_cell(1, 2);
|
||||
NumType m20 = m.get_cell(2, 0);
|
||||
NumType m21 = m.get_cell(2, 1);
|
||||
NumType m22 = m.get_cell(2, 2);
|
||||
|
||||
NumType T = m00 + m11 + m22 + 1.;
|
||||
|
||||
if (T > 0.) {
|
||||
// the easy case
|
||||
NumType S = 0.5 / csqrt(T);
|
||||
_r = 0.25 / S;
|
||||
_i = (m21 - m12) * S;
|
||||
_j = (m02 - m20) * S;
|
||||
_k = (m10 - m01) * S;
|
||||
} else {
|
||||
// figure out which column to take as root
|
||||
int c = 0;
|
||||
if (cabs(m00) > cabs(m11)) {
|
||||
if (cabs(m00) > cabs(m22))
|
||||
c = 0;
|
||||
else
|
||||
c = 2;
|
||||
} else if (cabs(m11) > cabs(m22))
|
||||
c = 1;
|
||||
else
|
||||
c = 2;
|
||||
|
||||
NumType S;
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
S = csqrt(1. + m00 - m11 - m22) * 2.;
|
||||
_r = (m12 + m21) / S;
|
||||
_i = 0.5 / S;
|
||||
_j = (m01 + m10) / S;
|
||||
_k = (m02 + m20) / S;
|
||||
break;
|
||||
case 1:
|
||||
S = csqrt(1. + m11 - m00 - m22) * 2.;
|
||||
_r = (m02 + m20) / S;
|
||||
_i = (m01 + m10) / S;
|
||||
_j = 0.5 / S;
|
||||
_k = (m12 + m21) / S;
|
||||
break;
|
||||
case 2:
|
||||
S = csqrt(1. + m22 - m00 - m11) * 2.;
|
||||
_r = (m01 + m10) / S;
|
||||
_i = (m02 + m20) / S;
|
||||
_j = (m12 + m21) / S;
|
||||
_k = 0.5 / S;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: set
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LQuaternionBase)::
|
||||
set(const FLOATNAME(LMatrix4) &m) {
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set(const LMatrix4<NumType> &m) {
|
||||
set(m.get_upper_3());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: extract (LMatrix3)
|
||||
// Access: public
|
||||
// Description: Do-While Jones paper from cary.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LQuaternionBase<NumType>::
|
||||
extract_to_matrix(LMatrix3<NumType> &m) const {
|
||||
NumType N = (_r * _r) + (_i * _i) + (_j * _j) + (_k * _k);
|
||||
NumType s = (N == 0.) ? 0. : (2. / N);
|
||||
NumType xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
|
||||
|
||||
xs = _i * s; ys = _j * s; zs = _k * s;
|
||||
wx = _r * xs; wy = _r * ys; wz = _r * zs;
|
||||
xx = _i * xs; xy = _i * ys; xz = _i * zs;
|
||||
yy = _j * ys; yz = _j * zs; zz = _k * zs;
|
||||
|
||||
m = LMatrix3<NumType>((1. - (yy + zz)), (xy - wz), (xz + wy),
|
||||
(xy + wz), (1. - (xx + zz)), (yz - wx),
|
||||
(xz - wy), (yz + wx), (1. - (xx + yy)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: extract (LMatrix4)
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LQuaternionBase<NumType>::
|
||||
extract_to_matrix(LMatrix4<NumType> &m) const {
|
||||
NumType N = (_r * _r) + (_i * _i) + (_j * _j) + (_k * _k);
|
||||
NumType s = (N == 0.) ? 0. : (2. / N);
|
||||
NumType xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
|
||||
|
||||
xs = _i * s; ys = _j * s; zs = _k * s;
|
||||
wx = _r * xs; wy = _r * ys; wz = _r * zs;
|
||||
xx = _i * xs; xy = _i * ys; xz = _i * zs;
|
||||
yy = _j * ys; yz = _j * zs; zz = _k * zs;
|
||||
|
||||
m = LMatrix4<NumType>((1. - (yy + zz)), (xy - wz), (xz + wy), 0.,
|
||||
(xy + wz), (1. - (xx + zz)), (yz - wx), 0.,
|
||||
(xz - wy), (yz + wx), (1. - (xx + yy)), 0.,
|
||||
0., 0., 0., 1.);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: set_hpr
|
||||
// Access: public
|
||||
// Description: Sets the quaternion as the unit quaternion that
|
||||
// is equivalent to these Euler angles.
|
||||
// (from Real-time Rendering, p.49)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE void LQuaternionBase<NumType>::
|
||||
set_hpr(const LVecBase3<NumType> &hpr) {
|
||||
LQuaternionBase<NumType> quat_h, quat_p, quat_r;
|
||||
|
||||
LVector3<NumType> v = LVector3<NumType>::up();
|
||||
NumType a = deg_2_rad(hpr[0] * 0.5);
|
||||
NumType s,c;
|
||||
|
||||
csincos(a,&s,&c);
|
||||
quat_h.set(c, v[0] * s, v[1] * s, v[2] * s);
|
||||
v = LVector3<NumType>::right();
|
||||
a = deg_2_rad(hpr[1] * 0.5);
|
||||
csincos(a,&s,&c);
|
||||
s = csin(a);
|
||||
quat_p.set(c, v[0] * s, v[1] * s, v[2] * s);
|
||||
v = LVector3<NumType>::forward();
|
||||
a = deg_2_rad(hpr[2] * 0.5);
|
||||
csincos(a,&s,&c);
|
||||
quat_r.set(c, v[0] * s, v[1] * s, v[2] * s);
|
||||
|
||||
(*this) = quat_h * quat_p * quat_r;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: get_hpr
|
||||
// Access: public
|
||||
// Description: Extracts the equivalent Euler angles from the unit
|
||||
// quaternion.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LQuaternionBase<NumType>::
|
||||
get_hpr() const {
|
||||
NumType heading, pitch, roll;
|
||||
NumType N = (_r * _r) + (_i * _i) + (_j * _j) + (_k * _k);
|
||||
NumType s = (N == 0.) ? 0. : (2. / N);
|
||||
NumType xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz, c1, c2, c3, c4;
|
||||
NumType cr, sr, cp, sp, ch, sh;
|
||||
|
||||
xs = _i * s; ys = _j * s; zs = _k * s;
|
||||
wx = _r * xs; wy = _r * ys; wz = _r * zs;
|
||||
xx = _i * xs; xy = _i * ys; xz = _i * zs;
|
||||
yy = _j * ys; yz = _j * zs; zz = _k * zs;
|
||||
c1 = xz - wy;
|
||||
c2 = 1. - (xx + yy);
|
||||
c3 = 1. - (yy + zz);
|
||||
c4 = xy + wz;
|
||||
|
||||
if (c1 == 0.) { // (roll = 0 or 180) or (pitch = +/- 90
|
||||
if (c2 >= 0.) {
|
||||
roll = 0.;
|
||||
ch = c3;
|
||||
sh = c4;
|
||||
cp = c2;
|
||||
} else {
|
||||
roll = 180.;
|
||||
ch = -c3;
|
||||
sh = -c4;
|
||||
cp = -c2;
|
||||
}
|
||||
} else {
|
||||
// this should work all the time, but the above saves some trig operations
|
||||
roll = catan2(-c1, c2);
|
||||
csincos(roll,&sr,&cr);
|
||||
roll = rad_2_deg(roll);
|
||||
ch = (cr * c3) + (sr * (xz + wy));
|
||||
sh = (cr * c4) + (sr * (yz - wx));
|
||||
cp = (cr * c2) - (sr * c1);
|
||||
}
|
||||
sp = yz + wx;
|
||||
heading = rad_2_deg(catan2(sh, ch));
|
||||
pitch = rad_2_deg(catan2(sp, cp));
|
||||
|
||||
return LVecBase3<NumType>(heading, pitch, roll);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: operator *(Matrix3, Quat)
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &m,
|
||||
const FLOATNAME(LQuaternionBase) &q) {
|
||||
FLOATNAME(LMatrix3) q_matrix;
|
||||
template<class NumType>
|
||||
LMatrix3<NumType> operator *(const LMatrix3<NumType> &m,
|
||||
const LQuaternionBase<NumType> &q) {
|
||||
LMatrix3<NumType> q_matrix;
|
||||
q.extract_to_matrix(q_matrix);
|
||||
|
||||
return m * q_matrix;
|
||||
|
|
@ -426,15 +577,15 @@ INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &m,
|
|||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &m,
|
||||
const FLOATNAME(LQuaternionBase) &q) {
|
||||
FLOATNAME(LMatrix4) q_matrix;
|
||||
template<class NumType>
|
||||
LMatrix4<NumType> operator *(const LMatrix4<NumType> &m,
|
||||
const LQuaternionBase<NumType> &q) {
|
||||
LMatrix4<NumType> q_matrix;
|
||||
q.extract_to_matrix(q_matrix);
|
||||
|
||||
// preserve the homogeneous coords and the translate
|
||||
FLOATNAME(LVector4) m_row3 = m.get_row(3);
|
||||
FLOATNAME(LVector4) m_col3 = m.get_col(3);
|
||||
LVector4<NumType> m_row3 = m.get_row(3);
|
||||
LVector4<NumType> m_col3 = m.get_col(3);
|
||||
|
||||
q_matrix = m * q_matrix;
|
||||
q_matrix.set_row(3, m_row3);
|
||||
|
|
@ -443,3 +594,30 @@ INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &m,
|
|||
return q_matrix;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LQuaternionBase::init_type
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LQuaternionBase<NumType>::
|
||||
init_type(void) {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
do_init_type(NumType);
|
||||
string name = "LQuaternionBase<" + get_type_handle(NumType).get_name()
|
||||
+ ">";
|
||||
register_type(_type_handle, name);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a quaternion from one numeric representation
|
||||
// to another one. This is usually invoked using the
|
||||
// macro LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LQuaternionBase<NumType2>
|
||||
lcast_to(NumType2 *, const LQuaternionBase<NumType>& c) {
|
||||
return LQuaternionBase<NumType2>(c.get_r(), c.get_i(), c.get_j(), c.get_k());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,39 +7,117 @@
|
|||
#define __LQUATERNION_H__
|
||||
|
||||
#include "lmatrix.h"
|
||||
#include "lvector3.h"
|
||||
#include "lvector4.h"
|
||||
#include "nearly_zero.h"
|
||||
#include "cmath.h"
|
||||
#include "deg_2_rad.h"
|
||||
|
||||
#include <notify.h>
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lquaternion.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lquaternion.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a quaternion from one numeric representation
|
||||
// to another one. This is usually invoked using the
|
||||
// macro LCAST.
|
||||
// Class : LQuaternionBase
|
||||
// Description : This is the base quaternion class
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LQuaternionBase)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternionBase)& c) {
|
||||
return FLOATNAME2(LQuaternionBase)(c.get_r(), c.get_i(), c.get_j(), c.get_k());
|
||||
template <class NumType>
|
||||
class LQuaternionBase {
|
||||
protected:
|
||||
INLINE LQuaternionBase<NumType>
|
||||
multiply(const LQuaternionBase<NumType>&) const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE LQuaternionBase(void);
|
||||
INLINE LQuaternionBase(const LQuaternionBase<NumType> &);
|
||||
INLINE LQuaternionBase(NumType, NumType, NumType, NumType);
|
||||
virtual ~LQuaternionBase(void);
|
||||
|
||||
static LQuaternionBase<NumType> pure_imaginary(const LVector3<NumType> &);
|
||||
|
||||
INLINE LQuaternionBase<NumType>& operator =(const LQuaternionBase<NumType> &);
|
||||
INLINE bool operator ==(const LQuaternionBase<NumType> &) const;
|
||||
INLINE bool operator !=(const LQuaternionBase<NumType> &) const;
|
||||
|
||||
INLINE LQuaternionBase<NumType> operator *(const LQuaternionBase<NumType> &);
|
||||
INLINE LQuaternionBase<NumType>& operator *=(const LQuaternionBase<NumType> &);
|
||||
|
||||
INLINE LMatrix3<NumType> operator *(const LMatrix3<NumType> &);
|
||||
INLINE LMatrix4<NumType> operator *(const LMatrix4<NumType> &);
|
||||
|
||||
INLINE bool almost_equal(const LQuaternionBase<NumType> &, NumType) const;
|
||||
INLINE bool almost_equal(const LQuaternionBase<NumType> &) const;
|
||||
|
||||
INLINE void output(ostream&) const;
|
||||
|
||||
INLINE void set(NumType, NumType, NumType, NumType);
|
||||
|
||||
void set(const LMatrix3<NumType> &m);
|
||||
INLINE void set(const LMatrix4<NumType> &m);
|
||||
|
||||
void extract_to_matrix(LMatrix3<NumType> &m) const;
|
||||
void extract_to_matrix(LMatrix4<NumType> &m) const;
|
||||
|
||||
INLINE void set_hpr(const LVecBase3<NumType> &hpr);
|
||||
LVecBase3<NumType> get_hpr() const;
|
||||
|
||||
INLINE NumType get_r(void) const;
|
||||
INLINE NumType get_i(void) const;
|
||||
INLINE NumType get_j(void) const;
|
||||
INLINE NumType get_k(void) const;
|
||||
|
||||
INLINE void set_r(NumType r);
|
||||
INLINE void set_i(NumType i);
|
||||
INLINE void set_j(NumType j);
|
||||
INLINE void set_k(NumType k);
|
||||
|
||||
INLINE void normalize(void);
|
||||
|
||||
static const LQuaternionBase<NumType> &ident_quat(void);
|
||||
|
||||
private:
|
||||
NumType _r, _i, _j, _k;
|
||||
public:
|
||||
static TypeHandle get_class_type(void) {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type(void);
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream& operator<<(ostream& os, const LQuaternionBase<NumType>& q) {
|
||||
q.output(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LQuaternionBase)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternionBase)& c) {
|
||||
return FLOATNAME2(LQuaternionBase)(c.get_r(), c.get_i(), c.get_j(), c.get_k());
|
||||
}
|
||||
// matrix times quat
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType>
|
||||
operator * (const LMatrix3<NumType> &m, const LQuaternionBase<NumType> &q);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LMatrix4<NumType>
|
||||
operator * (const LMatrix4<NumType> &m, const LQuaternionBase<NumType> &q);
|
||||
|
||||
// pacify interrogate.
|
||||
#ifdef CPPPARSER
|
||||
BEGIN_PUBLISH
|
||||
INLINE LMatrix3<float>
|
||||
operator * (const LMatrix3<float> &m, const LQuaternionBase<float> &q);
|
||||
INLINE LMatrix4<float>
|
||||
operator * (const LMatrix4<float> &m, const LQuaternionBase<float> &q);
|
||||
INLINE LMatrix3<double>
|
||||
operator * (const LMatrix3<double> &m, const LQuaternionBase<double> &q);
|
||||
INLINE LMatrix4<double>
|
||||
operator * (const LMatrix4<double> &m, const LQuaternionBase<double> &q);
|
||||
END_PUBLISH
|
||||
#endif
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LQuaternionBase<NumType2> lcast_to(NumType2*, const LQuaternionBase<NumType>&);
|
||||
|
||||
#include "lquaternion.I"
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LQuaternionBase<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LQuaternionBase<double>)
|
||||
|
||||
#endif /* __LQUATERNION_H__ */
|
||||
|
|
|
|||
|
|
@ -3,44 +3,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Class : LRotation
|
||||
// Description : This is a unit quaternion representing a rotation.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA FLOATNAME(LRotation) : public FLOATNAME(LQuaternionBase) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LRotation)();
|
||||
INLINE FLOATNAME(LRotation)(const FLOATNAME(LQuaternionBase)&);
|
||||
INLINE FLOATNAME(LRotation)(FLOATTYPE1, FLOATTYPE1, FLOATTYPE1, FLOATTYPE1);
|
||||
INLINE FLOATNAME(LRotation)(const FLOATNAME(LVector3) &, FLOATTYPE1);
|
||||
INLINE FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &);
|
||||
INLINE FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &);
|
||||
INLINE FLOATNAME(LRotation)(FLOATTYPE1, FLOATTYPE1, FLOATTYPE1);
|
||||
virtual ~FLOATNAME(LRotation)();
|
||||
|
||||
INLINE FLOATNAME(LRotation)
|
||||
operator*(const FLOATNAME(LRotation)& other) const;
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase)
|
||||
operator*(const FLOATNAME(LQuaternionBase)& other) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LRotation<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LRotation::Default Constructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)() {
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -48,10 +21,10 @@ FLOATNAME(LRotation)() {
|
|||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)(const FLOATNAME(LQuaternionBase)& c) :
|
||||
FLOATNAME(LQuaternionBase)(c) {
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation(const LQuaternionBase<NumType>& c) :
|
||||
LQuaternionBase<NumType>(c) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -59,10 +32,10 @@ FLOATNAME(LRotation)(const FLOATNAME(LQuaternionBase)& c) :
|
|||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k) :
|
||||
FLOATNAME(LQuaternionBase)(r, i, j, k) {
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation(NumType r, NumType i, NumType j, NumType k) :
|
||||
LQuaternionBase<NumType>(r, i, j, k) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -70,9 +43,9 @@ FLOATNAME(LRotation)(FLOATTYPE1 r, FLOATTYPE1 i, FLOATTYPE1 j, FLOATTYPE1 k) :
|
|||
// Access: public
|
||||
// Description: lmatrix3
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &m) {
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation(const LMatrix3<NumType> &m) {
|
||||
set(m);
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +54,9 @@ FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &m) {
|
|||
// Access: public
|
||||
// Description: lmatrix4
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &m) {
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation(const LMatrix4<NumType> &m) {
|
||||
set(m);
|
||||
}
|
||||
|
||||
|
|
@ -92,12 +65,12 @@ FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &m) {
|
|||
// Access: public
|
||||
// Description: axis + angle (in degrees)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)(const FLOATNAME(LVector3) &axis, FLOATTYPE1 angle) {
|
||||
FLOATTYPE1 radians = angle * ((FLOATTYPE1) MathNumbers::pi / (FLOATTYPE1)180.0);
|
||||
FLOATTYPE1 theta_over_2 = radians / (FLOATTYPE1)2.0;
|
||||
FLOATTYPE1 sin_to2 = csin(theta_over_2);
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation(const LVector3<NumType> &axis, NumType angle) {
|
||||
NumType radians = angle * ((NumType) MathNumbers::pi / (NumType)180.0);
|
||||
NumType theta_over_2 = radians / (NumType)2.0;
|
||||
NumType sin_to2 = csin(theta_over_2);
|
||||
|
||||
set_r(ccos(theta_over_2));
|
||||
set_i(axis[0] * sin_to2);
|
||||
|
|
@ -110,10 +83,20 @@ FLOATNAME(LRotation)(const FLOATNAME(LVector3) &axis, FLOATTYPE1 angle) {
|
|||
// Access: public
|
||||
// Description: Sets the rotation from the given Euler angles.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType>::
|
||||
LRotation(NumType h, NumType p, NumType r) {
|
||||
set_hpr(LVecBase3<NumType>(h, p, r));
|
||||
}
|
||||
|
||||
INLINE FLOATNAME(LRotation)::
|
||||
FLOATNAME(LRotation)(FLOATTYPE1 h, FLOATTYPE1 p, FLOATTYPE1 r) {
|
||||
set_hpr(FLOATNAME(LVecBase3)(h, p, r));
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LRotation::Destructor
|
||||
// Access: public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
LRotation<NumType>::
|
||||
~LRotation() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -121,9 +104,9 @@ FLOATNAME(LRotation)(FLOATTYPE1 h, FLOATTYPE1 p, FLOATTYPE1 r) {
|
|||
// Access: public
|
||||
// Description: Rotation * Rotation = Rotation
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LRotation) FLOATNAME(LRotation)::
|
||||
operator*(const FLOATNAME(LRotation)& other) const {
|
||||
template<class NumType>
|
||||
INLINE LRotation<NumType> LRotation<NumType>::
|
||||
operator*(const LRotation<NumType>& other) const {
|
||||
return multiply(other);
|
||||
}
|
||||
|
||||
|
|
@ -135,10 +118,25 @@ operator*(const FLOATNAME(LRotation)& other) const {
|
|||
// to apply an orientation to a rotation. It simply
|
||||
// returns the rhs.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LQuaternionBase) FLOATNAME(LRotation)::
|
||||
operator*(const FLOATNAME(LQuaternionBase)& other) const {
|
||||
template<class NumType>
|
||||
INLINE LQuaternionBase<NumType> LRotation<NumType>::
|
||||
operator*(const LQuaternionBase<NumType>& other) const {
|
||||
return other;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LRotation::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LRotation<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
// Format a string to describe the type.
|
||||
do_init_type(NumType);
|
||||
string name =
|
||||
"LRotation<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,40 @@
|
|||
|
||||
#include <notify.h>
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Class : LRotation
|
||||
// Description : This is a unit quaternion representing a rotation.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
template <class NumType>
|
||||
class LRotation : public LQuaternionBase<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LRotation();
|
||||
INLINE LRotation(const LQuaternionBase<NumType>&);
|
||||
INLINE LRotation(NumType, NumType, NumType, NumType);
|
||||
INLINE LRotation(const LVector3<NumType> &, NumType);
|
||||
INLINE LRotation(const LMatrix3<NumType> &);
|
||||
INLINE LRotation(const LMatrix4<NumType> &);
|
||||
INLINE LRotation(NumType, NumType, NumType);
|
||||
virtual ~LRotation();
|
||||
|
||||
INLINE LRotation<NumType>
|
||||
operator*(const LRotation<NumType>& other) const;
|
||||
|
||||
INLINE LQuaternionBase<NumType>
|
||||
operator*(const LQuaternionBase<NumType>& other) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "lrotation.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lrotation.I"
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LRotation<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LRotation<double>)
|
||||
|
||||
#endif /* __LROTATION_H__ */
|
||||
|
|
|
|||
|
|
@ -1,44 +1,85 @@
|
|||
forcetype LVecBase2<float>
|
||||
forcetype LVecBase3<float>
|
||||
forcetype LVecBase4<float>
|
||||
|
||||
renametype LPoint2f LPoint2f
|
||||
renametype LPoint3f LPoint3f
|
||||
renametype LPoint4f LPoint4f
|
||||
renametype LPoint2d LPoint2d
|
||||
renametype LPoint3d LPoint3d
|
||||
renametype LPoint4d LPoint4d
|
||||
forcetype LPoint2<float>
|
||||
forcetype LPoint3<float>
|
||||
forcetype LPoint4<float>
|
||||
forcetype LVector2<float>
|
||||
forcetype LVector3<float>
|
||||
forcetype LVector4<float>
|
||||
|
||||
renametype LVecBase2f LVecBase2f
|
||||
renametype LVecBase3f LVecBase3f
|
||||
renametype LVecBase4f LVecBase4f
|
||||
renametype LVecBase2d LVecBase2d
|
||||
renametype LVecBase3d LVecBase3d
|
||||
renametype LVecBase4d LVecBase4d
|
||||
forcetype LMatrix3<float>
|
||||
forcetype LMatrix4<float>
|
||||
|
||||
renametype LVector2f LVector2f
|
||||
renametype LVector3f LVector3f
|
||||
renametype LVector4f LVector4f
|
||||
renametype LVector2d LVector2d
|
||||
renametype LVector3d LVector3d
|
||||
renametype LVector4d LVector4d
|
||||
forcetype LPoint2f
|
||||
forcetype LPoint3f
|
||||
forcetype LPoint4f
|
||||
|
||||
renametype LMatrix3f LMatrix3f
|
||||
renametype LMatrix4f LMatrix4f
|
||||
renametype LMatrix3d LMatrix3d
|
||||
renametype LMatrix4d LMatrix4d
|
||||
forcetype LVector2f
|
||||
forcetype LVector3f
|
||||
forcetype LVector4f
|
||||
|
||||
renametype LQuaternionf LQuaternionf
|
||||
renametype LRotationf LRotationf
|
||||
renametype LOrientationf LOrientationf
|
||||
forcetype Vertexf
|
||||
forcetype Normalf
|
||||
forcetype TexCoordf
|
||||
forcetype Colorf
|
||||
forcetype RGBColorf
|
||||
|
||||
renametype LQuaterniond LQuaterniond
|
||||
renametype LRotationd LRotationd
|
||||
renametype LOrientationd LOrientationd
|
||||
forcetype LMatrix3f
|
||||
forcetype LMatrix4f
|
||||
|
||||
forcetype LVecBase2<double>
|
||||
forcetype LVecBase3<double>
|
||||
forcetype LVecBase4<double>
|
||||
|
||||
forcetype LPoint2<double>
|
||||
forcetype LPoint3<double>
|
||||
forcetype LPoint4<double>
|
||||
forcetype LVector2<double>
|
||||
forcetype LVector3<double>
|
||||
forcetype LVector4<double>
|
||||
|
||||
forcetype LMatrix3<double>
|
||||
forcetype LMatrix4<double>
|
||||
|
||||
forcetype LPoint2d
|
||||
forcetype LPoint3d
|
||||
forcetype LPoint4d
|
||||
|
||||
forcetype LVector2d
|
||||
forcetype LVector3d
|
||||
forcetype LVector4d
|
||||
|
||||
forcetype Vertexd
|
||||
forcetype Normald
|
||||
forcetype TexCoordd
|
||||
forcetype Colord
|
||||
forcetype RGBColord
|
||||
|
||||
forcetype LMatrix3d
|
||||
forcetype LMatrix4d
|
||||
|
||||
forcetype LQuaternionBase<float>
|
||||
forcetype LQuaternionBase<double>
|
||||
forcetype LRotation<float>
|
||||
forcetype LRotation<double>
|
||||
forcetype LOrientation<float>
|
||||
forcetype LOrientation<double>
|
||||
|
||||
forcetype LQuaternionf
|
||||
forcetype LRotationf
|
||||
forcetype LOrientationf
|
||||
forcetype LQuaterniond
|
||||
forcetype LRotationd
|
||||
forcetype LOrientationd
|
||||
|
||||
forcetype PTA_Vertexf
|
||||
renametype PTA_Vertexf PTA_Vertexf
|
||||
forcetype PTA_Normalf
|
||||
renametype PTA_Normalf PTA_Normalf
|
||||
forcetype PTA_TexCoordf
|
||||
renametype PTA_TexCoordf PTA_TexCoordf
|
||||
forcetype PTA_Colorf
|
||||
renametype PTA_Colorf PTA_Colorf
|
||||
|
||||
renametype PTA_Vertexf PTA_Vertexf
|
||||
renametype PTA_Normalf PTA_Normalf
|
||||
renametype PTA_TexCoordf PTA_TexCoordf
|
||||
renametype PTA_Colorf PTA_Colorf
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@
|
|||
// designed for specific uses. These all inherit from LVecBase, which
|
||||
// is the base class of all linear algebra vectors.
|
||||
//
|
||||
// LPoint<P_FLOATTYPE1, N_length>
|
||||
// LPoint<P_numtype, N_length>
|
||||
//
|
||||
// This should be used to represent a specific point in space. It
|
||||
// inherits most properties from LVecBase.
|
||||
//
|
||||
// LVector<P_FLOATTYPE1, N_length>
|
||||
// LVector<P_numtype, N_length>
|
||||
//
|
||||
// This should be used to represent a vector, or a distance between
|
||||
// two points in space.
|
||||
|
|
@ -37,11 +37,11 @@
|
|||
//
|
||||
// This file also defines the following:
|
||||
//
|
||||
// Vertex<P_FLOATTYPE1>, Vertexd, Vertexf
|
||||
// Normal<P_FLOATTYPE1>, Normald, Normalf
|
||||
// TexCoord<P_FLOATTYPE1>, TexCoordd, TexCoordf
|
||||
// Color<P_FLOATTYPE1>, Colord, Colorf
|
||||
// RGBColor<P_FLOATTYPE1>, RGBColord, RGBColorf
|
||||
// Vertex<P_numtype>, Vertexd, Vertexf
|
||||
// Normal<P_numtype>, Normald, Normalf
|
||||
// TexCoord<P_numtype>, TexCoordd, TexCoordf
|
||||
// Color<P_numtype>, Colord, Colorf
|
||||
// RGBColor<P_numtype>, RGBColord, RGBColorf
|
||||
//
|
||||
// These classes are derivations of LPoint or LVector, as appropriate,
|
||||
// and are intended to store a specific kind of rendering attribute.
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
|
||||
|
||||
// Now we define some handy typedefs for these classes.
|
||||
/*
|
||||
|
||||
typedef LVecBase2<float> LVecBase2f;
|
||||
typedef LVecBase3<float> LVecBase3f;
|
||||
typedef LVecBase4<float> LVecBase4f;
|
||||
|
|
@ -85,13 +85,13 @@ typedef LVector4<float> LVector4f;
|
|||
typedef LPoint2<float> LPoint2f;
|
||||
typedef LPoint3<float> LPoint3f;
|
||||
typedef LPoint4<float> LPoint4f;
|
||||
*/
|
||||
|
||||
typedef LPoint3f Vertexf;
|
||||
typedef LVector3f Normalf;
|
||||
typedef LPoint2f TexCoordf;
|
||||
typedef LVecBase4f Colorf;
|
||||
typedef LVecBase3f RGBColorf;
|
||||
/*
|
||||
|
||||
typedef LVecBase2<double> LVecBase2d;
|
||||
typedef LVecBase3<double> LVecBase3d;
|
||||
typedef LVecBase4<double> LVecBase4d;
|
||||
|
|
@ -102,16 +102,13 @@ typedef LVector4<double> LVector4d;
|
|||
typedef LPoint2<double> LPoint2d;
|
||||
typedef LPoint3<double> LPoint3d;
|
||||
typedef LPoint4<double> LPoint4d;
|
||||
*/
|
||||
|
||||
typedef LPoint3d Vertexd;
|
||||
typedef LVector3d Normald;
|
||||
typedef LPoint2d TexCoordd;
|
||||
typedef LVecBase4d Colord;
|
||||
typedef LVecBase3d RGBColord;
|
||||
typedef LQuaternionBasef LQuaternionf;
|
||||
typedef LQuaternionBased LQuaterniond;
|
||||
|
||||
/*
|
||||
typedef LQuaternionBase<float> LQuaternionf;
|
||||
typedef LRotation<float> LRotationf;
|
||||
typedef LOrientation<float> LOrientationf;
|
||||
|
|
@ -119,7 +116,7 @@ typedef LOrientation<float> LOrientationf;
|
|||
typedef LQuaternionBase<double> LQuaterniond;
|
||||
typedef LRotation<double> LRotationd;
|
||||
typedef LOrientation<double> LOrientationd;
|
||||
*/
|
||||
|
||||
/*
|
||||
// Now define explicit instantiations of the output operator functions
|
||||
// for interrogate's benefit. These functions don't actually exist
|
||||
|
|
|
|||
|
|
@ -3,49 +3,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
// When possible, operators have been defined within the classes.
|
||||
// This file defines operator functions outside of classes where
|
||||
// necessary. It also defines some convenient out-of-class wrappers
|
||||
// around in-class functions (like dot, length, normalize).
|
||||
#include <math.h>
|
||||
|
||||
|
||||
// scalar * vec (vec * scalar is defined in class)
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase2) &a);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint2) &a);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LVector2)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector2) &a);
|
||||
|
||||
|
||||
// dot product
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b);
|
||||
|
||||
|
||||
// Length of a vector.
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
length(const FLOATNAME(LVector2) &a);
|
||||
|
||||
|
||||
// A normalized vector.
|
||||
|
||||
INLINE FLOATNAME(LVector2)
|
||||
normalize(const FLOATNAME(LVector2) &v);
|
||||
#include "nearly_zero.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: scalar * LVecBase2
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LVecBase2)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase2) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase2<NumType>
|
||||
operator * (NumType2 scalar, const LVecBase2<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -53,8 +21,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase2) &a) {
|
|||
// Function: scalar * LPoint2
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LPoint2)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint2) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint2<NumType>
|
||||
operator * (NumType2 scalar, const LPoint2<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -62,8 +31,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint2) &a) {
|
|||
// Function: scalar * LVector2
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LVector2)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector2) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector2<NumType>
|
||||
operator * (NumType2 scalar, const LVector2<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -71,19 +41,39 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector2) &a) {
|
|||
// Function: dot product of LVecBase2
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b) {
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
dot(const LVecBase2<NumType> &a, const LVecBase2<NumType> &b) {
|
||||
return a.dot(b);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: cross product of LVecBase2
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>
|
||||
cross(const LVecBase2<NumType> &a, const LVecBase2<NumType> &b) {
|
||||
return a.cross(b);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: cross product of LVector2
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>
|
||||
cross(const LVector2<NumType> &a, const LVector2<NumType> &b) {
|
||||
return LVector2<NumType>(a.cross(b));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: length of a vector
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
length(const FLOATNAME(LVector2) &a) {
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
length(const LVector2<NumType> &a) {
|
||||
return a.length();
|
||||
}
|
||||
|
||||
|
|
@ -92,10 +82,10 @@ length(const FLOATNAME(LVector2) &a) {
|
|||
// Function: normalize
|
||||
// Description: Returns a normalized vector from the given vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2)
|
||||
normalize(const FLOATNAME(LVector2) &v) {
|
||||
FLOATNAME(LVector2) v1 = v;
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>
|
||||
normalize(const LVector2<NumType> &v) {
|
||||
LVector2<NumType> v1 = v;
|
||||
v1.normalize();
|
||||
return v1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,49 @@
|
|||
#ifndef LVEC2_OPS_H
|
||||
#define LVEC2_OPS_H
|
||||
|
||||
#include <math.h>
|
||||
#include "nearly_zero.h"
|
||||
#include "lvecBase2.h"
|
||||
#include "lpoint2.h"
|
||||
#include "lvector2.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lvec2_ops.I"
|
||||
// When possible, operators have been defined within the classes.
|
||||
// This file defines operator functions outside of classes where
|
||||
// necessary. It also defines some convenient out-of-class wrappers
|
||||
// around in-class functions (like dot, length, normalize).
|
||||
|
||||
|
||||
// scalar * vec (vec * scalar is defined in class)
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase2<NumType>
|
||||
operator * (NumType2 scalar, const LVecBase2<NumType> &a);
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint2<NumType>
|
||||
operator * (NumType2 scalar, const LPoint2<NumType> &a);
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector2<NumType>
|
||||
operator * (NumType2 scalar, const LVector2<NumType> &a);
|
||||
|
||||
|
||||
// dot product
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
dot(const LVecBase2<NumType> &a, const LVecBase2<NumType> &b);
|
||||
|
||||
|
||||
// Length of a vector.
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
length(const LVector2<NumType> &a);
|
||||
|
||||
|
||||
// A normalized vector.
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>
|
||||
normalize(const LVector2<NumType> &v);
|
||||
|
||||
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvec2_ops.I"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,60 +3,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
// When possible, operators have been defined within the classes.
|
||||
// This file defines operator functions outside of classes where
|
||||
// necessary. It also defines some convenient out-of-class wrappers
|
||||
// around in-class functions (like dot, length, normalize).
|
||||
|
||||
|
||||
// scalar * vec (vec * scalar is defined in class)
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase3) &a);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint3) &a);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector3) &a);
|
||||
|
||||
|
||||
// dot product
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b);
|
||||
|
||||
|
||||
// cross product
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b);
|
||||
|
||||
|
||||
// Length of a vector.
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
length(const FLOATNAME(LVector3) &a);
|
||||
|
||||
|
||||
// A normalized vector.
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
normalize(const FLOATNAME(LVector3) &v);
|
||||
#include <math.h>
|
||||
|
||||
#include "nearly_zero.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: scalar * LVecBase3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase3) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase3<NumType>
|
||||
operator * (NumType2 scalar, const LVecBase3<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -64,8 +21,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase3) &a) {
|
|||
// Function: scalar * LPoint3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LPoint3)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint3) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint3<NumType>
|
||||
operator * (NumType2 scalar, const LPoint3<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -73,8 +31,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint3) &a) {
|
|||
// Function: scalar * LVector3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LVector3)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector3) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector3<NumType>
|
||||
operator * (NumType2 scalar, const LVector3<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -82,9 +41,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector3) &a) {
|
|||
// Function: dot product of LVecBase3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) {
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
dot(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b) {
|
||||
return a.dot(b);
|
||||
}
|
||||
|
||||
|
|
@ -92,9 +51,9 @@ dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) {
|
|||
// Function: cross product of LVecBase3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>
|
||||
cross(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b) {
|
||||
return a.cross(b);
|
||||
}
|
||||
|
||||
|
|
@ -102,10 +61,10 @@ cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) {
|
|||
// Function: cross product of LVector3
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) {
|
||||
return FLOATNAME(LVector3)(a.cross(b));
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>
|
||||
cross(const LVector3<NumType> &a, const LVector3<NumType> &b) {
|
||||
return LVector3<NumType>(a.cross(b));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -113,9 +72,9 @@ cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) {
|
|||
// Function: length of a vector
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
length(const FLOATNAME(LVector3) &a) {
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
length(const LVector3<NumType> &a) {
|
||||
return a.length();
|
||||
}
|
||||
|
||||
|
|
@ -124,10 +83,10 @@ length(const FLOATNAME(LVector3) &a) {
|
|||
// Function: normalize
|
||||
// Description: Returns a normalized vector from the given vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)
|
||||
normalize(const FLOATNAME(LVector3) &v) {
|
||||
FLOATNAME(LVector3) v1 = v;
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>
|
||||
normalize(const LVector3<NumType> &v) {
|
||||
LVector3<NumType> v1 = v;
|
||||
v1.normalize();
|
||||
return v1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,59 @@
|
|||
#ifndef LVEC3_OPS_H
|
||||
#define LVEC3_OPS_H
|
||||
|
||||
#include <math.h>
|
||||
#include "nearly_zero.h"
|
||||
#include "lvecBase3.h"
|
||||
#include "lpoint3.h"
|
||||
#include "lvector3.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lvec3_ops.I"
|
||||
// When possible, operators have been defined within the classes.
|
||||
// This file defines operator functions outside of classes where
|
||||
// necessary. It also defines some convenient out-of-class wrappers
|
||||
// around in-class functions (like dot, length, normalize).
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvec3_ops.I"
|
||||
|
||||
// scalar * vec (vec * scalar is defined in class)
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase3<NumType>
|
||||
operator * (NumType2 scalar, const LVecBase3<NumType> &a);
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint3<NumType>
|
||||
operator * (NumType2 scalar, const LPoint3<NumType> &a);
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector3<NumType>
|
||||
operator * (NumType2 scalar, const LVector3<NumType> &a);
|
||||
|
||||
|
||||
// dot product
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
dot(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b);
|
||||
|
||||
|
||||
// cross product
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>
|
||||
cross(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b);
|
||||
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>
|
||||
cross(const LVector3<NumType> &a, const LVector3<NumType> &b);
|
||||
|
||||
|
||||
// Length of a vector.
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
length(const LVector3<NumType> &a);
|
||||
|
||||
|
||||
// A normalized vector.
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>
|
||||
normalize(const LVector3<NumType> &v);
|
||||
|
||||
|
||||
|
||||
#include "lvec3_ops.I"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,50 +3,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
// When possible, operators have been defined within the classes.
|
||||
// This file defines operator functions outside of classes where
|
||||
// necessary. It also defines some convenient out-of-class wrappers
|
||||
// around in-class functions (like dot, length, normalize).
|
||||
|
||||
|
||||
// scalar * vec (vec * scalar is defined in class)
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase4) &a);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LPoint4)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint4) &a);
|
||||
|
||||
|
||||
INLINE FLOATNAME(LVector4)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector4) &a);
|
||||
|
||||
|
||||
// dot product
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b);
|
||||
|
||||
|
||||
// Length of a vector.
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
length(const FLOATNAME(LVector4) &a);
|
||||
|
||||
|
||||
// A normalized vector.
|
||||
|
||||
INLINE FLOATNAME(LVector4)
|
||||
normalize(const FLOATNAME(LVector4) &v);
|
||||
#include <math.h>
|
||||
|
||||
#include "nearly_zero.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: scalar * LVecBase4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase4) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase4<NumType>
|
||||
operator * (NumType2 scalar, const LVecBase4<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -54,8 +21,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LVecBase4) &a) {
|
|||
// Function: scalar * LPoint4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LPoint4)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint4) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint4<NumType>
|
||||
operator * (NumType2 scalar, const LPoint4<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -63,8 +31,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LPoint4) &a) {
|
|||
// Function: scalar * LVector4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME(LVector4)
|
||||
operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector4) &a) {
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector4<NumType>
|
||||
operator * (NumType2 scalar, const LVector4<NumType> &a) {
|
||||
return a * scalar;
|
||||
}
|
||||
|
||||
|
|
@ -72,9 +41,9 @@ operator * (FLOATTYPE2 scalar, const FLOATNAME(LVector4) &a) {
|
|||
// Function: dot product of LVecBase4
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b) {
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
dot(const LVecBase4<NumType> &a, const LVecBase4<NumType> &b) {
|
||||
return a.dot(b);
|
||||
}
|
||||
|
||||
|
|
@ -82,9 +51,9 @@ dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b) {
|
|||
// Function: length of a vector
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1
|
||||
length(const FLOATNAME(LVector4) &a) {
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
length(const LVector4<NumType> &a) {
|
||||
return a.length();
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +62,10 @@ length(const FLOATNAME(LVector4) &a) {
|
|||
// Function: normalize
|
||||
// Description: Returns a normalized vector from the given vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4)
|
||||
normalize(const FLOATNAME(LVector4) &v) {
|
||||
FLOATNAME(LVector4) v1 = v;
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType>
|
||||
normalize(const LVector4<NumType> &v) {
|
||||
LVector4<NumType> v1 = v;
|
||||
v1.normalize();
|
||||
return v1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,49 @@
|
|||
#ifndef LVEC4_OPS_H
|
||||
#define LVEC4_OPS_H
|
||||
|
||||
#include <math.h>
|
||||
#include "nearly_zero.h"
|
||||
#include "lvecBase4.h"
|
||||
#include "lpoint4.h"
|
||||
#include "lvector4.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lvec4_ops.I"
|
||||
// When possible, operators have been defined within the classes.
|
||||
// This file defines operator functions outside of classes where
|
||||
// necessary. It also defines some convenient out-of-class wrappers
|
||||
// around in-class functions (like dot, length, normalize).
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvec4_ops.I"
|
||||
|
||||
// scalar * vec (vec * scalar is defined in class)
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase4<NumType>
|
||||
operator * (NumType2 scalar, const LVecBase4<NumType> &a);
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LPoint4<NumType>
|
||||
operator * (NumType2 scalar, const LPoint4<NumType> &a);
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector4<NumType>
|
||||
operator * (NumType2 scalar, const LVector4<NumType> &a);
|
||||
|
||||
|
||||
// dot product
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
dot(const LVecBase4<NumType> &a, const LVecBase4<NumType> &b);
|
||||
|
||||
|
||||
// Length of a vector.
|
||||
template<class NumType>
|
||||
INLINE NumType
|
||||
length(const LVector4<NumType> &a);
|
||||
|
||||
|
||||
// A normalized vector.
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType>
|
||||
normalize(const LVector4<NumType> &v);
|
||||
|
||||
|
||||
|
||||
#include "lvec4_ops.I"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,119 +3,23 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVecBase2
|
||||
// Description : This is the base class for all two-component
|
||||
// vectors and points.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "nearly_zero.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LVecBase2) {
|
||||
PUBLISHED:
|
||||
typedef const FLOATTYPE1 *iterator;
|
||||
typedef const FLOATTYPE1 *const_iterator;
|
||||
#include <notify.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)();
|
||||
INLINE FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©);
|
||||
INLINE FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) ©);
|
||||
INLINE FLOATNAME(LVecBase2) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVecBase2)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVecBase2)(FLOATTYPE1 x, FLOATTYPE1 y);
|
||||
|
||||
INLINE static FLOATNAME(LVecBase2) zero();
|
||||
INLINE static FLOATNAME(LVecBase2) unit_x();
|
||||
INLINE static FLOATNAME(LVecBase2) unit_y();
|
||||
|
||||
INLINE ~FLOATNAME(LVecBase2)();
|
||||
|
||||
INLINE FLOATTYPE1 operator [](int i) const;
|
||||
INLINE FLOATTYPE1 &operator [](int i);
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE FLOATTYPE1 get_cell(int i) const;
|
||||
INLINE FLOATTYPE1 get_x() const;
|
||||
INLINE FLOATTYPE1 get_y() const;
|
||||
INLINE void set_cell(int i, FLOATTYPE1 value);
|
||||
INLINE void set_x(FLOATTYPE1 value);
|
||||
INLINE void set_y(FLOATTYPE1 value);
|
||||
|
||||
INLINE const FLOATTYPE1 *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void fill(FLOATTYPE1 fill_value);
|
||||
INLINE void set(FLOATTYPE1 x, FLOATTYPE1 y);
|
||||
|
||||
INLINE FLOATTYPE1 dot(const FLOATNAME(LVecBase2) &other) const;
|
||||
|
||||
INLINE bool operator < (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE bool operator == (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE bool operator != (const FLOATNAME(LVecBase2) &other) const;
|
||||
|
||||
INLINE int compare_to(const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE int compare_to(const FLOATNAME(LVecBase2) &other,
|
||||
FLOATTYPE1 threshold) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)
|
||||
operator + (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE FLOATNAME(LVecBase2)
|
||||
operator - (const FLOATNAME(LVecBase2) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LVecBase2) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
INLINE void operator += (const FLOATNAME(LVecBase2) &other);
|
||||
INLINE void operator -= (const FLOATNAME(LVecBase2) &other);
|
||||
|
||||
INLINE void operator *= (FLOATTYPE1 scalar);
|
||||
INLINE void operator /= (FLOATTYPE1 scalar);
|
||||
|
||||
INLINE bool almost_equal(const FLOATNAME(LVecBase2) &other,
|
||||
FLOATTYPE1 threshold) const;
|
||||
INLINE bool almost_equal(const FLOATNAME(LVecBase2) &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
FLOATTYPE1 _data[2];
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &destination) const;
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
|
||||
INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase2) &vec) {
|
||||
vec.output(out);
|
||||
return out;
|
||||
}
|
||||
template<class NumType>
|
||||
TypeHandle LVecBase2<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase2::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::
|
||||
FLOATNAME(LVecBase2)() {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::
|
||||
LVecBase2() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -123,9 +27,9 @@ FLOATNAME(LVecBase2)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::
|
||||
FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::
|
||||
LVecBase2(const LVecBase2<NumType> ©) {
|
||||
(*this) = copy;
|
||||
}
|
||||
|
||||
|
|
@ -134,9 +38,9 @@ FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
|
||||
operator = (const FLOATNAME(LVecBase2) ©) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> &LVecBase2<NumType>::
|
||||
operator = (const LVecBase2<NumType> ©) {
|
||||
set(copy[0], copy[1]);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -146,9 +50,9 @@ operator = (const FLOATNAME(LVecBase2) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> &LVecBase2<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
fill(fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -158,9 +62,9 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::
|
||||
FLOATNAME(LVecBase2)(FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::
|
||||
LVecBase2(NumType fill_value) {
|
||||
fill(fill_value);
|
||||
}
|
||||
|
||||
|
|
@ -169,9 +73,9 @@ FLOATNAME(LVecBase2)(FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::
|
||||
FLOATNAME(LVecBase2)(FLOATTYPE1 x, FLOATTYPE1 y) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::
|
||||
LVecBase2(NumType x, NumType y) {
|
||||
set(x, y);
|
||||
}
|
||||
|
||||
|
|
@ -180,10 +84,10 @@ FLOATNAME(LVecBase2)(FLOATTYPE1 x, FLOATTYPE1 y) {
|
|||
// Access: Public
|
||||
// Description: Returns a zero-length vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LVecBase2)(0.0, 0.0);
|
||||
return LVecBase2<NumType>(0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -191,10 +95,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LVecBase2)(1.0, 0.0);
|
||||
return LVecBase2<NumType>(1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -202,10 +106,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LVecBase2)(0.0, 1.0);
|
||||
return LVecBase2<NumType>(0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -213,9 +117,9 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::
|
||||
~FLOATNAME(LVecBase2)() {
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::
|
||||
~LVecBase2() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -223,8 +127,8 @@ INLINE FLOATNAME(LVecBase2)::
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase2<NumType>::
|
||||
operator [](int i) const {
|
||||
nassertr(i >= 0 && i < 2, 0);
|
||||
return _data[i];
|
||||
|
|
@ -235,8 +139,8 @@ operator [](int i) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 &FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE NumType &LVecBase2<NumType>::
|
||||
operator [](int i) {
|
||||
nassertr(i >= 0 && i < 2, _data[0]);
|
||||
return _data[i];
|
||||
|
|
@ -248,8 +152,8 @@ operator [](int i) {
|
|||
// Description: Returns true if any component of the vector is
|
||||
// not-a-number, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase2<NumType>::
|
||||
is_nan() const {
|
||||
return cnan(_data[0]) || cnan(_data[1]);
|
||||
}
|
||||
|
|
@ -259,8 +163,8 @@ is_nan() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase2<NumType>::
|
||||
get_cell(int i) const {
|
||||
nassertr(i >= 0 && i < 2, 0);
|
||||
return _data[i];
|
||||
|
|
@ -271,8 +175,8 @@ get_cell(int i) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase2<NumType>::
|
||||
get_x() const {
|
||||
return _data[0];
|
||||
}
|
||||
|
|
@ -282,8 +186,8 @@ get_x() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase2<NumType>::
|
||||
get_y() const {
|
||||
return _data[1];
|
||||
}
|
||||
|
|
@ -293,9 +197,9 @@ get_y() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
set_cell(int i, FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
set_cell(int i, NumType value) {
|
||||
nassertv(i >= 0 && i < 2);
|
||||
_data[i] = value;
|
||||
}
|
||||
|
|
@ -305,9 +209,9 @@ set_cell(int i, FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
set_x(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
set_x(NumType value) {
|
||||
_data[0] = value;
|
||||
}
|
||||
|
||||
|
|
@ -316,9 +220,9 @@ set_x(FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
set_y(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
set_y(NumType value) {
|
||||
_data[1] = value;
|
||||
}
|
||||
|
||||
|
|
@ -329,8 +233,8 @@ set_y(FLOATTYPE1 value) {
|
|||
// elements in the vector. The next element
|
||||
// occupies the next position consecutively in memory.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE const FLOATTYPE1 *FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE const NumType *LVecBase2<NumType>::
|
||||
get_data() const {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -340,8 +244,8 @@ get_data() const {
|
|||
// Access: Public
|
||||
// Description: Returns the number of elements in the vector, two.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE int LVecBase2<NumType>::
|
||||
get_num_components() const {
|
||||
return 2;
|
||||
}
|
||||
|
|
@ -352,8 +256,8 @@ get_num_components() const {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::iterator LVecBase2<NumType>::
|
||||
begin() {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -364,8 +268,8 @@ begin() {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::iterator LVecBase2<NumType>::
|
||||
end() {
|
||||
return begin() + get_num_components();
|
||||
}
|
||||
|
|
@ -376,8 +280,8 @@ end() {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::const_iterator LVecBase2<NumType>::
|
||||
begin() const {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -388,8 +292,8 @@ begin() const {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType>::const_iterator LVecBase2<NumType>::
|
||||
end() const {
|
||||
return begin() + get_num_components();
|
||||
}
|
||||
|
|
@ -401,9 +305,9 @@ end() const {
|
|||
// fill_value. This is particularly useful for
|
||||
// initializing to zero.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
fill(FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
fill(NumType fill_value) {
|
||||
_data[0] = fill_value;
|
||||
_data[1] = fill_value;
|
||||
}
|
||||
|
|
@ -413,9 +317,9 @@ fill(FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
set(FLOATTYPE1 x, FLOATTYPE1 y) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
set(NumType x, NumType y) {
|
||||
_data[0] = x;
|
||||
_data[1] = y;
|
||||
}
|
||||
|
|
@ -425,9 +329,9 @@ set(FLOATTYPE1 x, FLOATTYPE1 y) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase2)::
|
||||
dot(const FLOATNAME(LVecBase2) &other) const {
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase2<NumType>::
|
||||
dot(const LVecBase2<NumType> &other) const {
|
||||
return _data[0] * other[0] + _data[1] * other[1];
|
||||
}
|
||||
|
||||
|
|
@ -440,9 +344,9 @@ dot(const FLOATNAME(LVecBase2) &other) const {
|
|||
// especially in an STL container. Also see
|
||||
// compare_to().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase2)::
|
||||
operator < (const FLOATNAME(LVecBase2) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase2<NumType>::
|
||||
operator < (const LVecBase2<NumType> &other) const {
|
||||
return (compare_to(other) < 0);
|
||||
}
|
||||
|
||||
|
|
@ -451,9 +355,9 @@ operator < (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase2)::
|
||||
operator == (const FLOATNAME(LVecBase2) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase2<NumType>::
|
||||
operator == (const LVecBase2<NumType> &other) const {
|
||||
return (_data[0] == other[0] &&
|
||||
_data[1] == other[1]);
|
||||
}
|
||||
|
|
@ -463,9 +367,9 @@ operator == (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase2)::
|
||||
operator != (const FLOATNAME(LVecBase2) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase2<NumType>::
|
||||
operator != (const LVecBase2<NumType> &other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
|
|
@ -475,10 +379,10 @@ operator != (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Description: This flavor of compare_to uses a default threshold
|
||||
// value based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase2)::
|
||||
compare_to(const FLOATNAME(LVecBase2) &other) const {
|
||||
return compare_to(other, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE int LVecBase2<NumType>::
|
||||
compare_to(const LVecBase2<NumType> &other) const {
|
||||
return compare_to(other, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -490,9 +394,9 @@ compare_to(const FLOATNAME(LVecBase2) &other) const {
|
|||
// after, 0 if they are equivalent (within the indicated
|
||||
// tolerance).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase2)::
|
||||
compare_to(const FLOATNAME(LVecBase2) &other, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE int LVecBase2<NumType>::
|
||||
compare_to(const LVecBase2<NumType> &other, NumType threshold) const {
|
||||
if (!IS_THRESHOLD_EQUAL(_data[0], other[0], threshold)) {
|
||||
return (_data[0] < other[0]) ? -1 : 1;
|
||||
}
|
||||
|
|
@ -507,10 +411,10 @@ compare_to(const FLOATNAME(LVecBase2) &other, FLOATTYPE1 threshold) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase2)(-_data[0], -_data[1]);
|
||||
return LVecBase2<NumType>(-_data[0], -_data[1]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -518,10 +422,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
operator + (const FLOATNAME(LVecBase2) &other) const {
|
||||
return FLOATNAME(LVecBase2)(_data[0] + other[0],
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
operator + (const LVecBase2<NumType> &other) const {
|
||||
return LVecBase2<NumType>(_data[0] + other[0],
|
||||
_data[1] + other[1]);
|
||||
}
|
||||
|
||||
|
|
@ -530,10 +434,10 @@ operator + (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
operator - (const FLOATNAME(LVecBase2) &other) const {
|
||||
return FLOATNAME(LVecBase2)(_data[0] - other[0],
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
operator - (const LVecBase2<NumType> &other) const {
|
||||
return LVecBase2<NumType>(_data[0] - other[0],
|
||||
_data[1] - other[1]);
|
||||
}
|
||||
|
||||
|
|
@ -542,10 +446,10 @@ operator - (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVecBase2)(_data[0] * scalar,
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LVecBase2<NumType>(_data[0] * scalar,
|
||||
_data[1] * scalar);
|
||||
}
|
||||
|
||||
|
|
@ -554,10 +458,10 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVecBase2)(_data[0] / scalar,
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVecBase2<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LVecBase2<NumType>(_data[0] / scalar,
|
||||
_data[1] / scalar);
|
||||
}
|
||||
|
||||
|
|
@ -566,9 +470,9 @@ operator / (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
operator += (const FLOATNAME(LVecBase2) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
operator += (const LVecBase2<NumType> &other) {
|
||||
_data[0] += other[0];
|
||||
_data[1] += other[1];
|
||||
}
|
||||
|
|
@ -578,9 +482,9 @@ operator += (const FLOATNAME(LVecBase2) &other) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
operator -= (const FLOATNAME(LVecBase2) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
operator -= (const LVecBase2<NumType> &other) {
|
||||
_data[0] -= other[0];
|
||||
_data[1] -= other[1];
|
||||
}
|
||||
|
|
@ -590,9 +494,9 @@ operator -= (const FLOATNAME(LVecBase2) &other) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
operator *= (FLOATTYPE1 scalar) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
operator *= (NumType scalar) {
|
||||
_data[0] *= scalar;
|
||||
_data[1] *= scalar;
|
||||
}
|
||||
|
|
@ -602,9 +506,9 @@ operator *= (FLOATTYPE1 scalar) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
operator /= (FLOATTYPE1 scalar) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
operator /= (NumType scalar) {
|
||||
_data[0] /= scalar;
|
||||
_data[1] /= scalar;
|
||||
}
|
||||
|
|
@ -615,9 +519,9 @@ operator /= (FLOATTYPE1 scalar) {
|
|||
// Description: Returns true if two vectors are memberwise equal
|
||||
// within a specified tolerance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase2)::
|
||||
almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase2<NumType>::
|
||||
almost_equal(const LVecBase2<NumType> &other, NumType threshold) const {
|
||||
return (IS_THRESHOLD_EQUAL(_data[0], other[0], threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_data[1], other[1], threshold));
|
||||
}
|
||||
|
|
@ -628,10 +532,10 @@ almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE1 threshold) const {
|
|||
// Description: Returns true if two vectors are memberwise equal
|
||||
// within a default tolerance based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase2)::
|
||||
almost_equal(const FLOATNAME(LVecBase2) &other) const {
|
||||
return almost_equal(other, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase2<NumType>::
|
||||
almost_equal(const LVecBase2<NumType> &other) const {
|
||||
return almost_equal(other, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -639,20 +543,37 @@ almost_equal(const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
INLINE void LVecBase2<NumType>::
|
||||
output(ostream &out) const {
|
||||
out << MAYBE_ZERO(_data[0]) << " "
|
||||
<< MAYBE_ZERO(_data[1]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase2::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LVecBase2<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
// Format a string to describe the type.
|
||||
do_init_type(NumType);
|
||||
string name =
|
||||
"LVecBase2<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase2::write_datagram
|
||||
// Access: Public
|
||||
// Description: Function to write itself into a datagram
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
void LVecBase2<NumType>::
|
||||
write_datagram(Datagram &destination) const {
|
||||
destination.add_float32(_data[0]);
|
||||
destination.add_float32(_data[1]);
|
||||
|
|
@ -663,12 +584,21 @@ write_datagram(Datagram &destination) const {
|
|||
// Access: Public
|
||||
// Description: Function to read itself from a datagramIterator
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase2)::
|
||||
template<class NumType>
|
||||
void LVecBase2<NumType>::
|
||||
read_datagram(DatagramIterator &source) {
|
||||
_data[0] = source.get_float32();
|
||||
_data[1] = source.get_float32();
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase2<NumType2>
|
||||
lcast_to(NumType2 *, const LVecBase2<NumType> &source) {
|
||||
return LVecBase2<NumType2>(source[0], source[1]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,40 +7,129 @@
|
|||
#define LVECBASE2_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <typeHandle.h>
|
||||
#include <notify.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
#include "cmath.h"
|
||||
#include "nearly_zero.h"
|
||||
|
||||
#include <typeHandle.h>
|
||||
|
||||
class Datagram;
|
||||
class DatagramIterator;
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lvecBase2.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvecBase2.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
// Class : LVecBase2
|
||||
// Description : This is the base class for all two-component
|
||||
// vectors and points.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LVecBase2)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source) {
|
||||
return FLOATNAME2(LVecBase2)(source[0], source[1]);
|
||||
}
|
||||
template<class NumType>
|
||||
class LVecBase2 {
|
||||
PUBLISHED:
|
||||
typedef const NumType *iterator;
|
||||
typedef const NumType *const_iterator;
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LVecBase2)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source) {
|
||||
return FLOATNAME2(LVecBase2)(source[0], source[1]);
|
||||
INLINE LVecBase2();
|
||||
INLINE LVecBase2(const LVecBase2<NumType> ©);
|
||||
INLINE LVecBase2<NumType> &operator = (const LVecBase2<NumType> ©);
|
||||
INLINE LVecBase2<NumType> &operator = (NumType fill_value);
|
||||
INLINE LVecBase2(NumType fill_value);
|
||||
INLINE LVecBase2(NumType x, NumType y);
|
||||
|
||||
INLINE static LVecBase2<NumType> zero();
|
||||
INLINE static LVecBase2<NumType> unit_x();
|
||||
INLINE static LVecBase2<NumType> unit_y();
|
||||
|
||||
INLINE ~LVecBase2();
|
||||
|
||||
INLINE NumType operator [](int i) const;
|
||||
INLINE NumType &operator [](int i);
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE NumType get_cell(int i) const;
|
||||
INLINE NumType get_x() const;
|
||||
INLINE NumType get_y() const;
|
||||
INLINE void set_cell(int i, NumType value);
|
||||
INLINE void set_x(NumType value);
|
||||
INLINE void set_y(NumType value);
|
||||
|
||||
INLINE const NumType *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void fill(NumType fill_value);
|
||||
INLINE void set(NumType x, NumType y);
|
||||
|
||||
INLINE NumType dot(const LVecBase2<NumType> &other) const;
|
||||
|
||||
INLINE bool operator < (const LVecBase2<NumType> &other) const;
|
||||
INLINE bool operator == (const LVecBase2<NumType> &other) const;
|
||||
INLINE bool operator != (const LVecBase2<NumType> &other) const;
|
||||
|
||||
INLINE int compare_to(const LVecBase2<NumType> &other) const;
|
||||
INLINE int compare_to(const LVecBase2<NumType> &other,
|
||||
NumType threshold) const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
operator - () const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
operator + (const LVecBase2<NumType> &other) const;
|
||||
INLINE LVecBase2<NumType>
|
||||
operator - (const LVecBase2<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase2<NumType> operator * (NumType scalar) const;
|
||||
INLINE LVecBase2<NumType> operator / (NumType scalar) const;
|
||||
|
||||
INLINE void operator += (const LVecBase2<NumType> &other);
|
||||
INLINE void operator -= (const LVecBase2<NumType> &other);
|
||||
|
||||
INLINE void operator *= (NumType scalar);
|
||||
INLINE void operator /= (NumType scalar);
|
||||
|
||||
INLINE bool almost_equal(const LVecBase2<NumType> &other,
|
||||
NumType threshold) const;
|
||||
INLINE bool almost_equal(const LVecBase2<NumType> &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
NumType _data[2];
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &destination) const;
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream &operator << (ostream &out, const LVecBase2<NumType> &vec) {
|
||||
vec.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase2<NumType2>
|
||||
lcast_to(NumType2 *type, const LVecBase2<NumType> &source);
|
||||
|
||||
#include "lvecBase2.I"
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase2<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase2<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,125 +3,23 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVecBase3
|
||||
// Description : This is the base class for all three-component
|
||||
// vectors and points.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "nearly_zero.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LVecBase3) {
|
||||
PUBLISHED:
|
||||
typedef const FLOATTYPE1 *iterator;
|
||||
typedef const FLOATTYPE1 *const_iterator;
|
||||
#include <notify.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)();
|
||||
INLINE FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©);
|
||||
INLINE FLOATNAME(LVecBase3) &operator = (const FLOATNAME(LVecBase3) ©);
|
||||
INLINE FLOATNAME(LVecBase3) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVecBase3)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVecBase3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z);
|
||||
|
||||
INLINE static FLOATNAME(LVecBase3) zero();
|
||||
INLINE static FLOATNAME(LVecBase3) unit_x();
|
||||
INLINE static FLOATNAME(LVecBase3) unit_y();
|
||||
INLINE static FLOATNAME(LVecBase3) unit_z();
|
||||
|
||||
INLINE ~FLOATNAME(LVecBase3)();
|
||||
|
||||
INLINE FLOATTYPE1 operator [](int i) const;
|
||||
INLINE FLOATTYPE1 &operator [](int i);
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE FLOATTYPE1 get_cell(int i) const;
|
||||
INLINE FLOATTYPE1 get_x() const;
|
||||
INLINE FLOATTYPE1 get_y() const;
|
||||
INLINE FLOATTYPE1 get_z() const;
|
||||
INLINE void set_cell(int i, FLOATTYPE1 value);
|
||||
INLINE void set_x(FLOATTYPE1 value);
|
||||
INLINE void set_y(FLOATTYPE1 value);
|
||||
INLINE void set_z(FLOATTYPE1 value);
|
||||
|
||||
INLINE const FLOATTYPE1 *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void fill(FLOATTYPE1 fill_value);
|
||||
INLINE void set(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z);
|
||||
|
||||
INLINE FLOATTYPE1 dot(const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &other) const;
|
||||
|
||||
INLINE bool operator < (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE bool operator == (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE bool operator != (const FLOATNAME(LVecBase3) &other) const;
|
||||
|
||||
INLINE int compare_to(const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE int compare_to(const FLOATNAME(LVecBase3) &other,
|
||||
FLOATTYPE1 threshold) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator + (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LVecBase3)
|
||||
operator - (const FLOATNAME(LVecBase3) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LVecBase3) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
INLINE void operator += (const FLOATNAME(LVecBase3) &other);
|
||||
INLINE void operator -= (const FLOATNAME(LVecBase3) &other);
|
||||
|
||||
INLINE void operator *= (FLOATTYPE1 scalar);
|
||||
INLINE void operator /= (FLOATTYPE1 scalar);
|
||||
|
||||
INLINE void cross_into(const FLOATNAME(LVecBase3) &other);
|
||||
|
||||
INLINE bool almost_equal(const FLOATNAME(LVecBase3) &other,
|
||||
FLOATTYPE1 threshold) const;
|
||||
INLINE bool almost_equal(const FLOATNAME(LVecBase3) &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
FLOATTYPE1 _data[3];
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &destination) const;
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
|
||||
INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase3) &vec) {
|
||||
vec.output(out);
|
||||
return out;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LVecBase3<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::
|
||||
FLOATNAME(LVecBase3)() {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::
|
||||
LVecBase3() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -129,9 +27,9 @@ FLOATNAME(LVecBase3)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::
|
||||
FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::
|
||||
LVecBase3(const LVecBase3<NumType> ©) {
|
||||
(*this) = copy;
|
||||
}
|
||||
|
||||
|
|
@ -140,9 +38,9 @@ FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
|
||||
operator = (const FLOATNAME(LVecBase3) ©) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> &LVecBase3<NumType>::
|
||||
operator = (const LVecBase3<NumType> ©) {
|
||||
set(copy[0], copy[1], copy[2]);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -152,9 +50,9 @@ operator = (const FLOATNAME(LVecBase3) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> &LVecBase3<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
fill(fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -164,9 +62,9 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::
|
||||
FLOATNAME(LVecBase3)(FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::
|
||||
LVecBase3(NumType fill_value) {
|
||||
fill(fill_value);
|
||||
}
|
||||
|
||||
|
|
@ -175,9 +73,9 @@ FLOATNAME(LVecBase3)(FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::
|
||||
FLOATNAME(LVecBase3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::
|
||||
LVecBase3(NumType x, NumType y, NumType z) {
|
||||
set(x, y, z);
|
||||
}
|
||||
|
||||
|
|
@ -186,10 +84,10 @@ FLOATNAME(LVecBase3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) {
|
|||
// Access: Public
|
||||
// Description: Returns a zero-length vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LVecBase3)(0.0, 0.0, 0.0);
|
||||
return LVecBase3<NumType>(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -197,10 +95,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LVecBase3)(1.0, 0.0, 0.0);
|
||||
return LVecBase3<NumType>(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -208,10 +106,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LVecBase3)(0.0, 1.0, 0.0);
|
||||
return LVecBase3<NumType>(0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -219,10 +117,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Z vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
unit_z() {
|
||||
return FLOATNAME(LVecBase3)(0.0, 0.0, 1.0);
|
||||
return LVecBase3<NumType>(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -230,9 +128,9 @@ unit_z() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::
|
||||
~FLOATNAME(LVecBase3)() {
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::
|
||||
~LVecBase3() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -240,8 +138,8 @@ INLINE FLOATNAME(LVecBase3)::
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase3<NumType>::
|
||||
operator [](int i) const {
|
||||
nassertr(i >= 0 && i < 3, 0);
|
||||
return _data[i];
|
||||
|
|
@ -252,8 +150,8 @@ operator [](int i) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 &FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE NumType &LVecBase3<NumType>::
|
||||
operator [](int i) {
|
||||
nassertr(i >= 0 && i < 3, _data[0]);
|
||||
return _data[i];
|
||||
|
|
@ -265,8 +163,8 @@ operator [](int i) {
|
|||
// Description: Returns true if any component of the vector is
|
||||
// not-a-number, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase3<NumType>::
|
||||
is_nan() const {
|
||||
return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]);
|
||||
}
|
||||
|
|
@ -276,8 +174,8 @@ is_nan() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase3<NumType>::
|
||||
get_cell(int i) const {
|
||||
nassertr(i >= 0 && i < 3, 0);
|
||||
return _data[i];
|
||||
|
|
@ -288,8 +186,8 @@ get_cell(int i) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase3<NumType>::
|
||||
get_x() const {
|
||||
return _data[0];
|
||||
}
|
||||
|
|
@ -299,8 +197,8 @@ get_x() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase3<NumType>::
|
||||
get_y() const {
|
||||
return _data[1];
|
||||
}
|
||||
|
|
@ -310,8 +208,8 @@ get_y() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase3<NumType>::
|
||||
get_z() const {
|
||||
return _data[2];
|
||||
}
|
||||
|
|
@ -321,9 +219,9 @@ get_z() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
set_cell(int i, FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
set_cell(int i, NumType value) {
|
||||
nassertv(i >= 0 && i < 3);
|
||||
_data[i] = value;
|
||||
}
|
||||
|
|
@ -333,9 +231,9 @@ set_cell(int i, FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
set_x(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
set_x(NumType value) {
|
||||
_data[0] = value;
|
||||
}
|
||||
|
||||
|
|
@ -344,9 +242,9 @@ set_x(FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
set_y(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
set_y(NumType value) {
|
||||
_data[1] = value;
|
||||
}
|
||||
|
||||
|
|
@ -355,9 +253,9 @@ set_y(FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
set_z(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
set_z(NumType value) {
|
||||
_data[2] = value;
|
||||
}
|
||||
|
||||
|
|
@ -368,8 +266,8 @@ set_z(FLOATTYPE1 value) {
|
|||
// elements in the vector. The remaining elements
|
||||
// occupy the next positions consecutively in memory.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE const FLOATTYPE1 *FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE const NumType *LVecBase3<NumType>::
|
||||
get_data() const {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -379,8 +277,8 @@ get_data() const {
|
|||
// Access: Public
|
||||
// Description: Returns the number of elements in the vector, three.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE int LVecBase3<NumType>::
|
||||
get_num_components() const {
|
||||
return 3;
|
||||
}
|
||||
|
|
@ -391,8 +289,8 @@ get_num_components() const {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::iterator LVecBase3<NumType>::
|
||||
begin() {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -403,8 +301,8 @@ begin() {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::iterator LVecBase3<NumType>::
|
||||
end() {
|
||||
return begin() + get_num_components();
|
||||
}
|
||||
|
|
@ -415,8 +313,8 @@ end() {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::const_iterator LVecBase3<NumType>::
|
||||
begin() const {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -427,8 +325,8 @@ begin() const {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType>::const_iterator LVecBase3<NumType>::
|
||||
end() const {
|
||||
return begin() + get_num_components();
|
||||
}
|
||||
|
|
@ -440,9 +338,9 @@ end() const {
|
|||
// fill_value. This is particularly useful for
|
||||
// initializing to zero.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
fill(FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
fill(NumType fill_value) {
|
||||
_data[0] = fill_value;
|
||||
_data[1] = fill_value;
|
||||
_data[2] = fill_value;
|
||||
|
|
@ -453,9 +351,9 @@ fill(FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
set(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
set(NumType x, NumType y, NumType z) {
|
||||
_data[0] = x;
|
||||
_data[1] = y;
|
||||
_data[2] = z;
|
||||
|
|
@ -466,9 +364,9 @@ set(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase3)::
|
||||
dot(const FLOATNAME(LVecBase3) &other) const {
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase3<NumType>::
|
||||
dot(const LVecBase3<NumType> &other) const {
|
||||
return _data[0] * other[0] + _data[1] * other[1] + _data[2] * other[2];
|
||||
}
|
||||
|
||||
|
|
@ -477,10 +375,10 @@ dot(const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
cross(const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)(_data[1] * other[2] - other[1] * _data[2],
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
cross(const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>(_data[1] * other[2] - other[1] * _data[2],
|
||||
other[0] * _data[2] - _data[0] * other[2],
|
||||
_data[0] * other[1] - other[0] * _data[1]);
|
||||
}
|
||||
|
|
@ -494,9 +392,9 @@ cross(const FLOATNAME(LVecBase3) &other) const {
|
|||
// especially in an STL container. Also see
|
||||
// compare_to().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase3)::
|
||||
operator < (const FLOATNAME(LVecBase3) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase3<NumType>::
|
||||
operator < (const LVecBase3<NumType> &other) const {
|
||||
return (compare_to(other) < 0);
|
||||
}
|
||||
|
||||
|
|
@ -505,9 +403,9 @@ operator < (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase3)::
|
||||
operator == (const FLOATNAME(LVecBase3) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase3<NumType>::
|
||||
operator == (const LVecBase3<NumType> &other) const {
|
||||
return (_data[0] == other[0] &&
|
||||
_data[1] == other[1] &&
|
||||
_data[2] == other[2]);
|
||||
|
|
@ -518,9 +416,9 @@ operator == (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase3)::
|
||||
operator != (const FLOATNAME(LVecBase3) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase3<NumType>::
|
||||
operator != (const LVecBase3<NumType> &other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
|
|
@ -530,10 +428,10 @@ operator != (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Description: This flavor of compare_to uses a default threshold
|
||||
// value based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase3)::
|
||||
compare_to(const FLOATNAME(LVecBase3) &other) const {
|
||||
return compare_to(other, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE int LVecBase3<NumType>::
|
||||
compare_to(const LVecBase3<NumType> &other) const {
|
||||
return compare_to(other, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -545,9 +443,9 @@ compare_to(const FLOATNAME(LVecBase3) &other) const {
|
|||
// after, 0 if they are equivalent (within the indicated
|
||||
// tolerance).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase3)::
|
||||
compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE int LVecBase3<NumType>::
|
||||
compare_to(const LVecBase3<NumType> &other, NumType threshold) const {
|
||||
if (!IS_THRESHOLD_EQUAL(_data[0], other[0], threshold)) {
|
||||
return (_data[0] < other[0]) ? -1 : 1;
|
||||
}
|
||||
|
|
@ -565,10 +463,10 @@ compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE1 threshold) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase3)(-_data[0], -_data[1], -_data[2]);
|
||||
return LVecBase3<NumType>(-_data[0], -_data[1], -_data[2]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -576,10 +474,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
operator + (const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)(_data[0] + other[0],
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
operator + (const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>(_data[0] + other[0],
|
||||
_data[1] + other[1],
|
||||
_data[2] + other[2]);
|
||||
}
|
||||
|
|
@ -589,10 +487,10 @@ operator + (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
operator - (const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)(_data[0] - other[0],
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
operator - (const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>(_data[0] - other[0],
|
||||
_data[1] - other[1],
|
||||
_data[2] - other[2]);
|
||||
}
|
||||
|
|
@ -602,10 +500,10 @@ operator - (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVecBase3)(_data[0] * scalar,
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LVecBase3<NumType>(_data[0] * scalar,
|
||||
_data[1] * scalar,
|
||||
_data[2] * scalar);
|
||||
}
|
||||
|
|
@ -615,10 +513,10 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVecBase3)(_data[0] / scalar,
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVecBase3<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LVecBase3<NumType>(_data[0] / scalar,
|
||||
_data[1] / scalar,
|
||||
_data[2] / scalar);
|
||||
}
|
||||
|
|
@ -628,9 +526,9 @@ operator / (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
operator += (const FLOATNAME(LVecBase3) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
operator += (const LVecBase3<NumType> &other) {
|
||||
_data[0] += other[0];
|
||||
_data[1] += other[1];
|
||||
_data[2] += other[2];
|
||||
|
|
@ -641,9 +539,9 @@ operator += (const FLOATNAME(LVecBase3) &other) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
operator -= (const FLOATNAME(LVecBase3) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
operator -= (const LVecBase3<NumType> &other) {
|
||||
_data[0] -= other[0];
|
||||
_data[1] -= other[1];
|
||||
_data[2] -= other[2];
|
||||
|
|
@ -654,9 +552,9 @@ operator -= (const FLOATNAME(LVecBase3) &other) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
operator *= (FLOATTYPE1 scalar) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
operator *= (NumType scalar) {
|
||||
_data[0] *= scalar;
|
||||
_data[1] *= scalar;
|
||||
_data[2] *= scalar;
|
||||
|
|
@ -667,9 +565,9 @@ operator *= (FLOATTYPE1 scalar) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
operator /= (FLOATTYPE1 scalar) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
operator /= (NumType scalar) {
|
||||
_data[0] /= scalar;
|
||||
_data[1] /= scalar;
|
||||
_data[2] /= scalar;
|
||||
|
|
@ -680,9 +578,9 @@ operator /= (FLOATTYPE1 scalar) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
cross_into(const FLOATNAME(LVecBase3) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
cross_into(const LVecBase3<NumType> &other) {
|
||||
(*this) = cross(other);
|
||||
}
|
||||
|
||||
|
|
@ -692,9 +590,9 @@ cross_into(const FLOATNAME(LVecBase3) &other) {
|
|||
// Description: Returns true if two vectors are memberwise equal
|
||||
// within a specified tolerance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase3)::
|
||||
almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase3<NumType>::
|
||||
almost_equal(const LVecBase3<NumType> &other, NumType threshold) const {
|
||||
return (IS_THRESHOLD_EQUAL(_data[0], other[0], threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_data[1], other[1], threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_data[2], other[2], threshold));
|
||||
|
|
@ -706,10 +604,10 @@ almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE1 threshold) const {
|
|||
// Description: Returns true if two vectors are memberwise equal
|
||||
// within a default tolerance based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase3)::
|
||||
almost_equal(const FLOATNAME(LVecBase3) &other) const {
|
||||
return almost_equal(other, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase3<NumType>::
|
||||
almost_equal(const LVecBase3<NumType> &other) const {
|
||||
return almost_equal(other, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -717,22 +615,38 @@ almost_equal(const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
INLINE void LVecBase3<NumType>::
|
||||
output(ostream &out) const {
|
||||
out << MAYBE_ZERO(_data[0]) << " "
|
||||
<< MAYBE_ZERO(_data[1]) << " "
|
||||
<< MAYBE_ZERO(_data[2]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LVecBase3<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
// Format a string to describe the type.
|
||||
do_init_type(NumType);
|
||||
string name =
|
||||
"LVecBase3<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3::write_datagram
|
||||
// Access: Public
|
||||
// Description: Function to write itself into a datagram
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
void LVecBase3<NumType>::
|
||||
write_datagram(Datagram &destination) const {
|
||||
destination.add_float32(_data[0]);
|
||||
destination.add_float32(_data[1]);
|
||||
|
|
@ -744,11 +658,23 @@ write_datagram(Datagram &destination) const {
|
|||
// Access: Public
|
||||
// Description: Function to read itself from a datagramIterator
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase3)::
|
||||
template<class NumType>
|
||||
void LVecBase3<NumType>::
|
||||
read_datagram(DatagramIterator &source) {
|
||||
_data[0] = source.get_float32();
|
||||
_data[1] = source.get_float32();
|
||||
_data[2] = source.get_float32();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase3<NumType2>
|
||||
lcast_to(NumType2 *, const LVecBase3<NumType> &source) {
|
||||
return LVecBase3<NumType2>(source[0], source[1], source[2]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,37 +7,135 @@
|
|||
#define LVECBASE3_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <typeHandle.h>
|
||||
#include <notify.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
#include "cmath.h"
|
||||
#include "nearly_zero.h"
|
||||
|
||||
#include <typeHandle.h>
|
||||
|
||||
class Datagram;
|
||||
class DatagramIterator;
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lvecBase3.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvecBase3.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
// Class : LVecBase3
|
||||
// Description : This is the base class for all three-component
|
||||
// vectors and points.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LVecBase3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source) {
|
||||
return FLOATNAME2(LVecBase3)(source[0], source[1], source[2]);
|
||||
template<class NumType>
|
||||
class LVecBase3 {
|
||||
PUBLISHED:
|
||||
typedef const NumType *iterator;
|
||||
typedef const NumType *const_iterator;
|
||||
|
||||
INLINE LVecBase3();
|
||||
INLINE LVecBase3(const LVecBase3<NumType> ©);
|
||||
INLINE LVecBase3<NumType> &operator = (const LVecBase3<NumType> ©);
|
||||
INLINE LVecBase3<NumType> &operator = (NumType fill_value);
|
||||
INLINE LVecBase3(NumType fill_value);
|
||||
INLINE LVecBase3(NumType x, NumType y, NumType z);
|
||||
|
||||
INLINE static LVecBase3<NumType> zero();
|
||||
INLINE static LVecBase3<NumType> unit_x();
|
||||
INLINE static LVecBase3<NumType> unit_y();
|
||||
INLINE static LVecBase3<NumType> unit_z();
|
||||
|
||||
INLINE ~LVecBase3();
|
||||
|
||||
INLINE NumType operator [](int i) const;
|
||||
INLINE NumType &operator [](int i);
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE NumType get_cell(int i) const;
|
||||
INLINE NumType get_x() const;
|
||||
INLINE NumType get_y() const;
|
||||
INLINE NumType get_z() const;
|
||||
INLINE void set_cell(int i, NumType value);
|
||||
INLINE void set_x(NumType value);
|
||||
INLINE void set_y(NumType value);
|
||||
INLINE void set_z(NumType value);
|
||||
|
||||
INLINE const NumType *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void fill(NumType fill_value);
|
||||
INLINE void set(NumType x, NumType y, NumType z);
|
||||
|
||||
INLINE NumType dot(const LVecBase3<NumType> &other) const;
|
||||
INLINE LVecBase3<NumType> cross(const LVecBase3<NumType> &other) const;
|
||||
|
||||
INLINE bool operator < (const LVecBase3<NumType> &other) const;
|
||||
INLINE bool operator == (const LVecBase3<NumType> &other) const;
|
||||
INLINE bool operator != (const LVecBase3<NumType> &other) const;
|
||||
|
||||
INLINE int compare_to(const LVecBase3<NumType> &other) const;
|
||||
INLINE int compare_to(const LVecBase3<NumType> &other,
|
||||
NumType threshold) const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
operator - () const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
operator + (const LVecBase3<NumType> &other) const;
|
||||
INLINE LVecBase3<NumType>
|
||||
operator - (const LVecBase3<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase3<NumType> operator * (NumType scalar) const;
|
||||
INLINE LVecBase3<NumType> operator / (NumType scalar) const;
|
||||
|
||||
INLINE void operator += (const LVecBase3<NumType> &other);
|
||||
INLINE void operator -= (const LVecBase3<NumType> &other);
|
||||
|
||||
INLINE void operator *= (NumType scalar);
|
||||
INLINE void operator /= (NumType scalar);
|
||||
|
||||
INLINE void cross_into(const LVecBase3<NumType> &other);
|
||||
|
||||
INLINE bool almost_equal(const LVecBase3<NumType> &other,
|
||||
NumType threshold) const;
|
||||
INLINE bool almost_equal(const LVecBase3<NumType> &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
NumType _data[3];
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &destination) const;
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream &operator << (ostream &out, const LVecBase3<NumType> &vec) {
|
||||
vec.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LVecBase3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source) {
|
||||
return FLOATNAME2(LVecBase3)(source[0], source[1], source[2]);
|
||||
}
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase3<NumType2>
|
||||
lcast_to(NumType2 *type, const LVecBase3<NumType> &source);
|
||||
|
||||
#include "lvecBase3.I"
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase3<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase3<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,125 +3,23 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVecBase4
|
||||
// Description : This is the base class for all three-component
|
||||
// vectors and points.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "nearly_zero.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LVecBase4) {
|
||||
PUBLISHED:
|
||||
typedef const FLOATTYPE1 *iterator;
|
||||
typedef const FLOATTYPE1 *const_iterator;
|
||||
#include <notify.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)();
|
||||
INLINE FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©);
|
||||
INLINE FLOATNAME(LVecBase4) &operator = (const FLOATNAME(LVecBase4) ©);
|
||||
INLINE FLOATNAME(LVecBase4) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVecBase4)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVecBase4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w);
|
||||
|
||||
INLINE static FLOATNAME(LVecBase4) zero();
|
||||
INLINE static FLOATNAME(LVecBase4) unit_x();
|
||||
INLINE static FLOATNAME(LVecBase4) unit_y();
|
||||
INLINE static FLOATNAME(LVecBase4) unit_z();
|
||||
INLINE static FLOATNAME(LVecBase4) unit_w();
|
||||
|
||||
INLINE ~FLOATNAME(LVecBase4)();
|
||||
|
||||
INLINE FLOATTYPE1 operator [](int i) const;
|
||||
INLINE FLOATTYPE1 &operator [](int i);
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE FLOATTYPE1 get_cell(int i) const;
|
||||
INLINE FLOATTYPE1 get_x() const;
|
||||
INLINE FLOATTYPE1 get_y() const;
|
||||
INLINE FLOATTYPE1 get_z() const;
|
||||
INLINE FLOATTYPE1 get_w() const;
|
||||
INLINE void set_cell(int i, FLOATTYPE1 value);
|
||||
INLINE void set_x(FLOATTYPE1 value);
|
||||
INLINE void set_y(FLOATTYPE1 value);
|
||||
INLINE void set_z(FLOATTYPE1 value);
|
||||
INLINE void set_w(FLOATTYPE1 value);
|
||||
|
||||
INLINE const FLOATTYPE1 *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void fill(FLOATTYPE1 fill_value);
|
||||
INLINE void set(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w);
|
||||
|
||||
INLINE FLOATTYPE1 dot(const FLOATNAME(LVecBase4) &other) const;
|
||||
|
||||
INLINE bool operator < (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE bool operator == (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE bool operator != (const FLOATNAME(LVecBase4) &other) const;
|
||||
|
||||
INLINE int compare_to(const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE int compare_to(const FLOATNAME(LVecBase4) &other,
|
||||
FLOATTYPE1 threshold) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator + (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE FLOATNAME(LVecBase4)
|
||||
operator - (const FLOATNAME(LVecBase4) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LVecBase4) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
INLINE void operator += (const FLOATNAME(LVecBase4) &other);
|
||||
INLINE void operator -= (const FLOATNAME(LVecBase4) &other);
|
||||
|
||||
INLINE void operator *= (FLOATTYPE1 scalar);
|
||||
INLINE void operator /= (FLOATTYPE1 scalar);
|
||||
|
||||
INLINE bool almost_equal(const FLOATNAME(LVecBase4) &other,
|
||||
FLOATTYPE1 threshold) const;
|
||||
INLINE bool almost_equal(const FLOATNAME(LVecBase4) &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
FLOATTYPE1 _data[4];
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &destination) const;
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
|
||||
INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase4) &vec) {
|
||||
vec.output(out);
|
||||
return out;
|
||||
}
|
||||
template<class NumType>
|
||||
TypeHandle LVecBase4<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase4::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::
|
||||
FLOATNAME(LVecBase4)() {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::
|
||||
LVecBase4() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -129,9 +27,9 @@ FLOATNAME(LVecBase4)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::
|
||||
FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::
|
||||
LVecBase4(const LVecBase4<NumType> ©) {
|
||||
(*this) = copy;
|
||||
}
|
||||
|
||||
|
|
@ -140,9 +38,9 @@ FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
|
||||
operator = (const FLOATNAME(LVecBase4) ©) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> &LVecBase4<NumType>::
|
||||
operator = (const LVecBase4<NumType> ©) {
|
||||
set(copy[0], copy[1], copy[2], copy[3]);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -152,9 +50,9 @@ operator = (const FLOATNAME(LVecBase4) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> &LVecBase4<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
fill(fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -164,9 +62,9 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::
|
||||
FLOATNAME(LVecBase4)(FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::
|
||||
LVecBase4(NumType fill_value) {
|
||||
fill(fill_value);
|
||||
}
|
||||
|
||||
|
|
@ -175,9 +73,9 @@ FLOATNAME(LVecBase4)(FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::
|
||||
FLOATNAME(LVecBase4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::
|
||||
LVecBase4(NumType x, NumType y, NumType z, NumType w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
|
|
@ -186,9 +84,9 @@ FLOATNAME(LVecBase4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::
|
||||
~FLOATNAME(LVecBase4)() {
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::
|
||||
~LVecBase4() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -196,10 +94,10 @@ INLINE FLOATNAME(LVecBase4)::
|
|||
// Access: Public
|
||||
// Description: Returns a zero-length vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LVecBase4)(0.0, 0.0, 0.0, 0.0);
|
||||
return LVecBase4<NumType>(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -207,10 +105,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LVecBase4)(1.0, 0.0, 0.0, 0.0);
|
||||
return LVecBase4<NumType>(1.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -218,10 +116,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LVecBase4)(0.0, 1.0, 0.0, 0.0);
|
||||
return LVecBase4<NumType>(0.0, 1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -229,10 +127,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Z vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
unit_z() {
|
||||
return FLOATNAME(LVecBase4)(0.0, 0.0, 1.0, 0.0);
|
||||
return LVecBase4<NumType>(0.0, 0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -240,10 +138,10 @@ unit_z() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit W vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
unit_w() {
|
||||
return FLOATNAME(LVecBase4)(0.0, 0.0, 0.0, 1.0);
|
||||
return LVecBase4<NumType>(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -251,8 +149,8 @@ unit_w() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
operator [](int i) const {
|
||||
nassertr(i >= 0 && i < 4, 0);
|
||||
return _data[i];
|
||||
|
|
@ -263,8 +161,8 @@ operator [](int i) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 &FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType &LVecBase4<NumType>::
|
||||
operator [](int i) {
|
||||
nassertr(i >= 0 && i < 4, _data[0]);
|
||||
return _data[i];
|
||||
|
|
@ -276,8 +174,8 @@ operator [](int i) {
|
|||
// Description: Returns true if any component of the vector is
|
||||
// not-a-number, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase4<NumType>::
|
||||
is_nan() const {
|
||||
return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || cnan(_data[3]);
|
||||
}
|
||||
|
|
@ -287,8 +185,8 @@ is_nan() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
get_cell(int i) const {
|
||||
nassertr(i >= 0 && i < 4, 0);
|
||||
return _data[i];
|
||||
|
|
@ -299,8 +197,8 @@ get_cell(int i) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
get_x() const {
|
||||
return _data[0];
|
||||
}
|
||||
|
|
@ -310,8 +208,8 @@ get_x() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
get_y() const {
|
||||
return _data[1];
|
||||
}
|
||||
|
|
@ -321,8 +219,8 @@ get_y() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
get_z() const {
|
||||
return _data[2];
|
||||
}
|
||||
|
|
@ -332,8 +230,8 @@ get_z() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
get_w() const {
|
||||
return _data[3];
|
||||
}
|
||||
|
|
@ -343,9 +241,9 @@ get_w() const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
set_cell(int i, FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
set_cell(int i, NumType value) {
|
||||
nassertv(i >= 0 && i < 4);
|
||||
_data[i] = value;
|
||||
}
|
||||
|
|
@ -355,9 +253,9 @@ set_cell(int i, FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
set_x(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
set_x(NumType value) {
|
||||
_data[0] = value;
|
||||
}
|
||||
|
||||
|
|
@ -366,9 +264,9 @@ set_x(FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
set_y(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
set_y(NumType value) {
|
||||
_data[1] = value;
|
||||
}
|
||||
|
||||
|
|
@ -377,9 +275,9 @@ set_y(FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
set_z(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
set_z(NumType value) {
|
||||
_data[2] = value;
|
||||
}
|
||||
|
||||
|
|
@ -388,9 +286,9 @@ set_z(FLOATTYPE1 value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
set_w(FLOATTYPE1 value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
set_w(NumType value) {
|
||||
_data[3] = value;
|
||||
}
|
||||
|
||||
|
|
@ -401,8 +299,8 @@ set_w(FLOATTYPE1 value) {
|
|||
// elements in the vector. The remaining elements
|
||||
// occupy the next positions consecutively in memory.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE const FLOATTYPE1 *FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE const NumType *LVecBase4<NumType>::
|
||||
get_data() const {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -412,8 +310,8 @@ get_data() const {
|
|||
// Access: Public
|
||||
// Description: Returns the number of elements in the vector, four.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE int LVecBase4<NumType>::
|
||||
get_num_components() const {
|
||||
return 4;
|
||||
}
|
||||
|
|
@ -424,8 +322,8 @@ get_num_components() const {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::iterator LVecBase4<NumType>::
|
||||
begin() {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -436,8 +334,8 @@ begin() {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::iterator LVecBase4<NumType>::
|
||||
end() {
|
||||
return begin() + get_num_components();
|
||||
}
|
||||
|
|
@ -448,8 +346,8 @@ end() {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::const_iterator LVecBase4<NumType>::
|
||||
begin() const {
|
||||
return _data;
|
||||
}
|
||||
|
|
@ -460,8 +358,8 @@ begin() const {
|
|||
// Description: Returns an iterator that may be used to traverse the
|
||||
// elements of the matrix, STL-style.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType>::const_iterator LVecBase4<NumType>::
|
||||
end() const {
|
||||
return begin() + get_num_components();
|
||||
}
|
||||
|
|
@ -473,9 +371,9 @@ end() const {
|
|||
// fill_value. This is particularly useful for
|
||||
// initializing to zero.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
fill(FLOATTYPE1 fill_value) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
fill(NumType fill_value) {
|
||||
_data[0] = fill_value;
|
||||
_data[1] = fill_value;
|
||||
_data[2] = fill_value;
|
||||
|
|
@ -487,9 +385,9 @@ fill(FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
set(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
set(NumType x, NumType y, NumType z, NumType w) {
|
||||
_data[0] = x;
|
||||
_data[1] = y;
|
||||
_data[2] = z;
|
||||
|
|
@ -501,9 +399,9 @@ set(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVecBase4)::
|
||||
dot(const FLOATNAME(LVecBase4) &other) const {
|
||||
template<class NumType>
|
||||
INLINE NumType LVecBase4<NumType>::
|
||||
dot(const LVecBase4<NumType> &other) const {
|
||||
return
|
||||
_data[0] * other[0] + _data[1] * other[1] +
|
||||
_data[2] * other[2] + _data[3] * other[3];
|
||||
|
|
@ -518,9 +416,9 @@ dot(const FLOATNAME(LVecBase4) &other) const {
|
|||
// especially in an STL container. Also see
|
||||
// compare_to().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase4)::
|
||||
operator < (const FLOATNAME(LVecBase4) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase4<NumType>::
|
||||
operator < (const LVecBase4<NumType> &other) const {
|
||||
return (compare_to(other) < 0);
|
||||
}
|
||||
|
||||
|
|
@ -529,9 +427,9 @@ operator < (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase4)::
|
||||
operator == (const FLOATNAME(LVecBase4) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase4<NumType>::
|
||||
operator == (const LVecBase4<NumType> &other) const {
|
||||
return (_data[0] == other[0] &&
|
||||
_data[1] == other[1] &&
|
||||
_data[2] == other[2] &&
|
||||
|
|
@ -543,9 +441,9 @@ operator == (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase4)::
|
||||
operator != (const FLOATNAME(LVecBase4) &other) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase4<NumType>::
|
||||
operator != (const LVecBase4<NumType> &other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
|
|
@ -555,10 +453,10 @@ operator != (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Description: This flavor of compare_to uses a default threshold
|
||||
// value based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase4)::
|
||||
compare_to(const FLOATNAME(LVecBase4) &other) const {
|
||||
return compare_to(other, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE int LVecBase4<NumType>::
|
||||
compare_to(const LVecBase4<NumType> &other) const {
|
||||
return compare_to(other, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -570,9 +468,9 @@ compare_to(const FLOATNAME(LVecBase4) &other) const {
|
|||
// after, 0 if they are equivalent (within the indicated
|
||||
// tolerance).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE int FLOATNAME(LVecBase4)::
|
||||
compare_to(const FLOATNAME(LVecBase4) &other, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE int LVecBase4<NumType>::
|
||||
compare_to(const LVecBase4<NumType> &other, NumType threshold) const {
|
||||
if (!IS_THRESHOLD_EQUAL(_data[0], other[0], threshold)) {
|
||||
return (_data[0] < other[0]) ? -1 : 1;
|
||||
}
|
||||
|
|
@ -593,10 +491,10 @@ compare_to(const FLOATNAME(LVecBase4) &other, FLOATTYPE1 threshold) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase4)(-_data[0], -_data[1], -_data[2], -_data[3]);
|
||||
return LVecBase4<NumType>(-_data[0], -_data[1], -_data[2], -_data[3]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -604,10 +502,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
operator + (const FLOATNAME(LVecBase4) &other) const {
|
||||
return FLOATNAME(LVecBase4)(_data[0] + other[0],
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
operator + (const LVecBase4<NumType> &other) const {
|
||||
return LVecBase4<NumType>(_data[0] + other[0],
|
||||
_data[1] + other[1],
|
||||
_data[2] + other[2],
|
||||
_data[3] + other[3]);
|
||||
|
|
@ -618,10 +516,10 @@ operator + (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
operator - (const FLOATNAME(LVecBase4) &other) const {
|
||||
return FLOATNAME(LVecBase4)(_data[0] - other[0],
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
operator - (const LVecBase4<NumType> &other) const {
|
||||
return LVecBase4<NumType>(_data[0] - other[0],
|
||||
_data[1] - other[1],
|
||||
_data[2] - other[2],
|
||||
_data[3] - other[3]);
|
||||
|
|
@ -632,10 +530,10 @@ operator - (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVecBase4)(_data[0] * scalar,
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LVecBase4<NumType>(_data[0] * scalar,
|
||||
_data[1] * scalar,
|
||||
_data[2] * scalar,
|
||||
_data[3] * scalar);
|
||||
|
|
@ -646,10 +544,10 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVecBase4)(_data[0] / scalar,
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVecBase4<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LVecBase4<NumType>(_data[0] / scalar,
|
||||
_data[1] / scalar,
|
||||
_data[2] / scalar,
|
||||
_data[3] / scalar);
|
||||
|
|
@ -660,9 +558,9 @@ operator / (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
operator += (const FLOATNAME(LVecBase4) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
operator += (const LVecBase4<NumType> &other) {
|
||||
_data[0] += other[0];
|
||||
_data[1] += other[1];
|
||||
_data[2] += other[2];
|
||||
|
|
@ -674,9 +572,9 @@ operator += (const FLOATNAME(LVecBase4) &other) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
operator -= (const FLOATNAME(LVecBase4) &other) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
operator -= (const LVecBase4<NumType> &other) {
|
||||
_data[0] -= other[0];
|
||||
_data[1] -= other[1];
|
||||
_data[2] -= other[2];
|
||||
|
|
@ -688,9 +586,9 @@ operator -= (const FLOATNAME(LVecBase4) &other) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
operator *= (FLOATTYPE1 scalar) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
operator *= (NumType scalar) {
|
||||
_data[0] *= scalar;
|
||||
_data[1] *= scalar;
|
||||
_data[2] *= scalar;
|
||||
|
|
@ -702,9 +600,9 @@ operator *= (FLOATTYPE1 scalar) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
operator /= (FLOATTYPE1 scalar) {
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
operator /= (NumType scalar) {
|
||||
_data[0] /= scalar;
|
||||
_data[1] /= scalar;
|
||||
_data[2] /= scalar;
|
||||
|
|
@ -717,9 +615,9 @@ operator /= (FLOATTYPE1 scalar) {
|
|||
// Description: Returns true if two vectors are memberwise equal
|
||||
// within a specified tolerance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase4)::
|
||||
almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE1 threshold) const {
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase4<NumType>::
|
||||
almost_equal(const LVecBase4<NumType> &other, NumType threshold) const {
|
||||
return (IS_THRESHOLD_EQUAL(_data[0], other[0], threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_data[1], other[1], threshold) &&
|
||||
IS_THRESHOLD_EQUAL(_data[2], other[2], threshold) &&
|
||||
|
|
@ -732,10 +630,10 @@ almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE1 threshold) const {
|
|||
// Description: Returns true if two vectors are memberwise equal
|
||||
// within a default tolerance based on the numeric type.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVecBase4)::
|
||||
almost_equal(const FLOATNAME(LVecBase4) &other) const {
|
||||
return almost_equal(other, NEARLY_ZERO(FLOATTYPE1));
|
||||
template<class NumType>
|
||||
INLINE bool LVecBase4<NumType>::
|
||||
almost_equal(const LVecBase4<NumType> &other) const {
|
||||
return almost_equal(other, NEARLY_ZERO(NumType));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -743,8 +641,8 @@ almost_equal(const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
INLINE void LVecBase4<NumType>::
|
||||
output(ostream &out) const {
|
||||
out << MAYBE_ZERO(_data[0]) << " "
|
||||
<< MAYBE_ZERO(_data[1]) << " "
|
||||
|
|
@ -752,13 +650,31 @@ output(ostream &out) const {
|
|||
<< MAYBE_ZERO(_data[3]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase4::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LVecBase4<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
// Format a string to describe the type.
|
||||
do_init_type(NumType);
|
||||
string name =
|
||||
"LVecBase4<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase4::write_datagram
|
||||
// Access: Public
|
||||
// Description: Function to write itself into a datagram
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
void LVecBase4<NumType>::
|
||||
write_datagram(Datagram &destination) const {
|
||||
destination.add_float32(_data[0]);
|
||||
destination.add_float32(_data[1]);
|
||||
|
|
@ -771,8 +687,8 @@ write_datagram(Datagram &destination) const {
|
|||
// Access: Public
|
||||
// Description: Function to read itself from a datagramIterator
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(LVecBase4)::
|
||||
template<class NumType>
|
||||
void LVecBase4<NumType>::
|
||||
read_datagram(DatagramIterator &source) {
|
||||
_data[0] = source.get_float32();
|
||||
_data[1] = source.get_float32();
|
||||
|
|
@ -781,5 +697,14 @@ read_datagram(DatagramIterator &source) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase4<NumType2>
|
||||
lcast_to(NumType2 *, const LVecBase4<NumType> &source) {
|
||||
return LVecBase4<NumType2>(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,42 +7,135 @@
|
|||
#define LVECBASE4_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <typeHandle.h>
|
||||
#include <notify.h>
|
||||
#include <datagram.h>
|
||||
#include <datagramIterator.h>
|
||||
|
||||
#include "cmath.h"
|
||||
#include "nearly_zero.h"
|
||||
|
||||
#include <typeHandle.h>
|
||||
|
||||
class Datagram;
|
||||
class DatagramIterator;
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "lvecBase4.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvecBase4.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
// Class : LVecBase4
|
||||
// Description : This is the base class for all three-component
|
||||
// vectors and points.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LVecBase4 {
|
||||
PUBLISHED:
|
||||
typedef const NumType *iterator;
|
||||
typedef const NumType *const_iterator;
|
||||
|
||||
INLINE FLOATNAME2(LVecBase4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source) {
|
||||
return FLOATNAME2(LVecBase4)(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
INLINE LVecBase4();
|
||||
INLINE LVecBase4(const LVecBase4<NumType> ©);
|
||||
INLINE LVecBase4<NumType> &operator = (const LVecBase4<NumType> ©);
|
||||
INLINE LVecBase4<NumType> &operator = (NumType fill_value);
|
||||
INLINE LVecBase4(NumType fill_value);
|
||||
INLINE LVecBase4(NumType x, NumType y, NumType z, NumType w);
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LVecBase4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source) {
|
||||
return FLOATNAME2(LVecBase4)(source[0], source[1], source[2], source[3]);
|
||||
INLINE static LVecBase4<NumType> zero();
|
||||
INLINE static LVecBase4<NumType> unit_x();
|
||||
INLINE static LVecBase4<NumType> unit_y();
|
||||
INLINE static LVecBase4<NumType> unit_z();
|
||||
INLINE static LVecBase4<NumType> unit_w();
|
||||
|
||||
INLINE ~LVecBase4();
|
||||
|
||||
INLINE NumType operator [](int i) const;
|
||||
INLINE NumType &operator [](int i);
|
||||
|
||||
INLINE bool is_nan() const;
|
||||
|
||||
INLINE NumType get_cell(int i) const;
|
||||
INLINE NumType get_x() const;
|
||||
INLINE NumType get_y() const;
|
||||
INLINE NumType get_z() const;
|
||||
INLINE NumType get_w() const;
|
||||
INLINE void set_cell(int i, NumType value);
|
||||
INLINE void set_x(NumType value);
|
||||
INLINE void set_y(NumType value);
|
||||
INLINE void set_z(NumType value);
|
||||
INLINE void set_w(NumType value);
|
||||
|
||||
INLINE const NumType *get_data() const;
|
||||
INLINE int get_num_components() const;
|
||||
|
||||
public:
|
||||
INLINE iterator begin();
|
||||
INLINE iterator end();
|
||||
|
||||
INLINE const_iterator begin() const;
|
||||
INLINE const_iterator end() const;
|
||||
|
||||
PUBLISHED:
|
||||
INLINE void fill(NumType fill_value);
|
||||
INLINE void set(NumType x, NumType y, NumType z, NumType w);
|
||||
|
||||
INLINE NumType dot(const LVecBase4<NumType> &other) const;
|
||||
|
||||
INLINE bool operator < (const LVecBase4<NumType> &other) const;
|
||||
INLINE bool operator == (const LVecBase4<NumType> &other) const;
|
||||
INLINE bool operator != (const LVecBase4<NumType> &other) const;
|
||||
|
||||
INLINE int compare_to(const LVecBase4<NumType> &other) const;
|
||||
INLINE int compare_to(const LVecBase4<NumType> &other,
|
||||
NumType threshold) const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
operator - () const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
operator + (const LVecBase4<NumType> &other) const;
|
||||
INLINE LVecBase4<NumType>
|
||||
operator - (const LVecBase4<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase4<NumType> operator * (NumType scalar) const;
|
||||
INLINE LVecBase4<NumType> operator / (NumType scalar) const;
|
||||
|
||||
INLINE void operator += (const LVecBase4<NumType> &other);
|
||||
INLINE void operator -= (const LVecBase4<NumType> &other);
|
||||
|
||||
INLINE void operator *= (NumType scalar);
|
||||
INLINE void operator /= (NumType scalar);
|
||||
|
||||
INLINE bool almost_equal(const LVecBase4<NumType> &other,
|
||||
NumType threshold) const;
|
||||
INLINE bool almost_equal(const LVecBase4<NumType> &other) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
NumType _data[4];
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &destination) const;
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream &operator << (ostream &out, const LVecBase4<NumType> &vec) {
|
||||
vec.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVecBase4<NumType2>
|
||||
lcast_to(NumType2 *type, const LVecBase4<NumType> &source);
|
||||
|
||||
#include "lvecBase4.I"
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase4<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase4<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,56 +3,19 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVector2
|
||||
// Description : This is a two-component vector offset.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "cmath.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LVector2) : public FLOATNAME(LVecBase2) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LVector2)();
|
||||
INLINE FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©);
|
||||
INLINE FLOATNAME(LVector2) &operator = (const FLOATNAME(LVecBase2) ©);
|
||||
INLINE FLOATNAME(LVector2) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVector2)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVector2)(FLOATTYPE1 x, FLOATTYPE1 y);
|
||||
|
||||
INLINE static FLOATNAME(LVector2) zero();
|
||||
INLINE static FLOATNAME(LVector2) unit_x();
|
||||
INLINE static FLOATNAME(LVector2) unit_y();
|
||||
|
||||
INLINE FLOATNAME(LVector2) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2)operator + (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE FLOATNAME(LVector2) operator + (const FLOATNAME(LVector2) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const;
|
||||
INLINE FLOATNAME(LVector2) operator - (const FLOATNAME(LVector2) &other) const;
|
||||
|
||||
INLINE FLOATTYPE1 length() const;
|
||||
INLINE FLOATTYPE1 length_squared() const;
|
||||
INLINE bool normalize();
|
||||
INLINE FLOATNAME(LVector2) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LVector2) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LVector2<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector2::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2)::
|
||||
FLOATNAME(LVector2)() {
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>::
|
||||
LVector2() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -60,9 +23,9 @@ FLOATNAME(LVector2)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2)::
|
||||
FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) {
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>::
|
||||
LVector2(const LVecBase2<NumType> ©) : LVecBase2<NumType>(copy) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -70,10 +33,10 @@ FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(cop
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) &FLOATNAME(LVector2)::
|
||||
operator = (const FLOATNAME(LVecBase2) ©) {
|
||||
FLOATNAME(LVecBase2)::operator = (copy);
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> &LVector2<NumType>::
|
||||
operator = (const LVecBase2<NumType> ©) {
|
||||
LVecBase2<NumType>::operator = (copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -82,10 +45,10 @@ operator = (const FLOATNAME(LVecBase2) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) &FLOATNAME(LVector2)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
FLOATNAME(LVecBase2)::operator = (fill_value);
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> &LVector2<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
LVecBase2<NumType>::operator = (fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -94,10 +57,10 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2)::
|
||||
FLOATNAME(LVector2)(FLOATTYPE1 fill_value) :
|
||||
FLOATNAME(LVecBase2)(fill_value)
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>::
|
||||
LVector2(NumType fill_value) :
|
||||
LVecBase2<NumType>(fill_value)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -106,10 +69,10 @@ FLOATNAME(LVector2)(FLOATTYPE1 fill_value) :
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2)::
|
||||
FLOATNAME(LVector2)(FLOATTYPE1 x, FLOATTYPE1 y) :
|
||||
FLOATNAME(LVecBase2)(x, y)
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType>::
|
||||
LVector2(NumType x, NumType y) :
|
||||
LVecBase2<NumType>(x, y)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -118,10 +81,10 @@ FLOATNAME(LVector2)(FLOATTYPE1 x, FLOATTYPE1 y) :
|
|||
// Access: Public
|
||||
// Description: Returns a zero-length vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LVector2)(0.0, 0.0);
|
||||
return LVector2<NumType>(0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -129,10 +92,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LVector2)(1.0, 0.0);
|
||||
return LVector2<NumType>(1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -140,10 +103,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LVector2)(0.0, 1.0);
|
||||
return LVector2<NumType>(0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -151,10 +114,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase2)::operator - ();
|
||||
return LVecBase2<NumType>::operator - ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -162,10 +125,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVector2)::
|
||||
operator + (const FLOATNAME(LVecBase2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVector2<NumType>::
|
||||
operator + (const LVecBase2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -173,10 +136,10 @@ operator + (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
operator + (const FLOATNAME(LVector2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
operator + (const LVector2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -184,10 +147,10 @@ operator + (const FLOATNAME(LVector2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase2) FLOATNAME(LVector2)::
|
||||
operator - (const FLOATNAME(LVecBase2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase2<NumType> LVector2<NumType>::
|
||||
operator - (const LVecBase2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -195,10 +158,10 @@ operator - (const FLOATNAME(LVecBase2) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
operator - (const FLOATNAME(LVector2) &other) const {
|
||||
return FLOATNAME(LVecBase2)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
operator - (const LVector2<NumType> &other) const {
|
||||
return LVecBase2<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -207,8 +170,8 @@ operator - (const FLOATNAME(LVector2) &other) const {
|
|||
// Description: Returns the length of the vector, by the Pythagorean
|
||||
// theorem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVector2<NumType>::
|
||||
length() const {
|
||||
return csqrt((*this).dot(*this));
|
||||
}
|
||||
|
|
@ -219,8 +182,8 @@ length() const {
|
|||
// Description: Returns the square of the vector's length, cheap and
|
||||
// easy.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVector2<NumType>::
|
||||
length_squared() const {
|
||||
return (*this).dot(*this);
|
||||
}
|
||||
|
|
@ -232,15 +195,15 @@ length_squared() const {
|
|||
// vector was normalized, false if it was a zero-length
|
||||
// vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVector2)::
|
||||
template<class NumType>
|
||||
INLINE bool LVector2<NumType>::
|
||||
normalize() {
|
||||
FLOATTYPE1 l2 = length_squared();
|
||||
if (l2 == (FLOATTYPE1)0.0) {
|
||||
NumType l2 = length_squared();
|
||||
if (l2 == (NumType)0.0) {
|
||||
set(0.0, 0.0);
|
||||
return false;
|
||||
|
||||
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(FLOATTYPE1) * NEARLY_ZERO(FLOATTYPE1))) {
|
||||
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) {
|
||||
(*this) /= csqrt(l2);
|
||||
}
|
||||
|
||||
|
|
@ -252,10 +215,10 @@ normalize() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (scalar));
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LVector2<NumType>(LVecBase2<NumType>::operator * (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -263,9 +226,37 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector2) FLOATNAME(LVector2)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator / (scalar));
|
||||
template<class NumType>
|
||||
INLINE LVector2<NumType> LVector2<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LVector2<NumType>(LVecBase2<NumType>::operator / (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector2::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LVector2<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
LVecBase2<NumType>::init_type();
|
||||
string name =
|
||||
"LVector2<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name,
|
||||
LVecBase2<NumType>::get_class_type());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector2<NumType2>
|
||||
lcast_to(NumType2 *, const LVector2<NumType> &source) {
|
||||
return LVector2<NumType2>(source[0], source[1]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,35 +7,63 @@
|
|||
#define LVECTOR2_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "cmath.h"
|
||||
#include "config_linmath.h"
|
||||
|
||||
#include "lvecBase2.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVector2
|
||||
// Description : This is a two-component vector offset.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LVector2 : public LVecBase2<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LVector2();
|
||||
INLINE LVector2(const LVecBase2<NumType> ©);
|
||||
INLINE LVector2<NumType> &operator = (const LVecBase2<NumType> ©);
|
||||
INLINE LVector2<NumType> &operator = (NumType fill_value);
|
||||
INLINE LVector2(NumType fill_value);
|
||||
INLINE LVector2(NumType x, NumType y);
|
||||
|
||||
INLINE static LVector2<NumType> zero();
|
||||
INLINE static LVector2<NumType> unit_x();
|
||||
INLINE static LVector2<NumType> unit_y();
|
||||
|
||||
INLINE LVector2<NumType> operator - () const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
operator + (const LVecBase2<NumType> &other) const;
|
||||
INLINE LVector2<NumType>
|
||||
operator + (const LVector2<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase2<NumType>
|
||||
operator - (const LVecBase2<NumType> &other) const;
|
||||
INLINE LVector2<NumType>
|
||||
operator - (const LVector2<NumType> &other) const;
|
||||
|
||||
INLINE NumType length() const;
|
||||
INLINE NumType length_squared() const;
|
||||
INLINE bool normalize();
|
||||
INLINE LVector2<NumType> operator * (NumType scalar) const;
|
||||
INLINE LVector2<NumType> operator / (NumType scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector2<NumType2>
|
||||
lcast_to(NumType2 *type, const LVector2<NumType> &source);
|
||||
|
||||
#include "lvector2.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvector2.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LVector2)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source) {
|
||||
return FLOATNAME2(LVector2)(source[0], source[1]);
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
|
||||
INLINE FLOATNAME2(LVector2)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source) {
|
||||
return FLOATNAME2(LVector2)(source[0], source[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector2<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector2<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,79 +3,20 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVector3
|
||||
// Description : This is a three-component vector distance (as opposed
|
||||
// to a three-component point, which represents a
|
||||
// particular point in space). Some of the methods are
|
||||
// slightly different between LPoint3 and LVector3; in
|
||||
// particular, subtraction of two points yields a
|
||||
// vector, while addition of a vector and a point yields
|
||||
// a point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "config_linmath.h"
|
||||
#include "cmath.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LVector3) : public FLOATNAME(LVecBase3) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LVector3)();
|
||||
INLINE FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©);
|
||||
INLINE FLOATNAME(LVector3) &operator = (const FLOATNAME(LVecBase3) ©);
|
||||
INLINE FLOATNAME(LVector3) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVector3)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVector3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z);
|
||||
|
||||
INLINE static FLOATNAME(LVector3) zero();
|
||||
INLINE static FLOATNAME(LVector3) unit_x();
|
||||
INLINE static FLOATNAME(LVector3) unit_y();
|
||||
INLINE static FLOATNAME(LVector3) unit_z();
|
||||
|
||||
INLINE FLOATNAME(LVector3) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LVector3) operator + (const FLOATNAME(LVector3) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) const;
|
||||
|
||||
INLINE FLOATTYPE1 length() const;
|
||||
INLINE FLOATTYPE1 length_squared() const;
|
||||
INLINE bool normalize();
|
||||
INLINE FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE FLOATNAME(LVector3) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LVector3) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
// Some special named constructors for LVector3.
|
||||
|
||||
INLINE static FLOATNAME(LVector3) up(CoordinateSystem cs = CS_default);
|
||||
INLINE static FLOATNAME(LVector3) right(CoordinateSystem cs = CS_default);
|
||||
INLINE static FLOATNAME(LVector3) forward(CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE static FLOATNAME(LVector3) down(CoordinateSystem cs = CS_default);
|
||||
INLINE static FLOATNAME(LVector3) left(CoordinateSystem cs = CS_default);
|
||||
INLINE static FLOATNAME(LVector3) back(CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE static FLOATNAME(LVector3) rfu(FLOATTYPE1 right,
|
||||
FLOATTYPE1 fwd,
|
||||
FLOATTYPE1 up,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LVector3<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector3::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)::
|
||||
FLOATNAME(LVector3)() {
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>::
|
||||
LVector3() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -83,9 +24,9 @@ FLOATNAME(LVector3)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)::
|
||||
FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy) {
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>::
|
||||
LVector3(const LVecBase3<NumType> ©) : LVecBase3<NumType>(copy) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -93,10 +34,10 @@ FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(cop
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) &FLOATNAME(LVector3)::
|
||||
operator = (const FLOATNAME(LVecBase3) ©) {
|
||||
FLOATNAME(LVecBase3)::operator = (copy);
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> &LVector3<NumType>::
|
||||
operator = (const LVecBase3<NumType> ©) {
|
||||
LVecBase3<NumType>::operator = (copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -105,10 +46,10 @@ operator = (const FLOATNAME(LVecBase3) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) &FLOATNAME(LVector3)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
FLOATNAME(LVecBase3)::operator = (fill_value);
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> &LVector3<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
LVecBase3<NumType>::operator = (fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -117,10 +58,10 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)::
|
||||
FLOATNAME(LVector3)(FLOATTYPE1 fill_value) :
|
||||
FLOATNAME(LVecBase3)(fill_value)
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>::
|
||||
LVector3(NumType fill_value) :
|
||||
LVecBase3<NumType>(fill_value)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -129,10 +70,10 @@ FLOATNAME(LVector3)(FLOATTYPE1 fill_value) :
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3)::
|
||||
FLOATNAME(LVector3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) :
|
||||
FLOATNAME(LVecBase3)(x, y, z)
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType>::
|
||||
LVector3(NumType x, NumType y, NumType z) :
|
||||
LVecBase3<NumType>(x, y, z)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -141,10 +82,10 @@ FLOATNAME(LVector3)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z) :
|
|||
// Access: Public
|
||||
// Description: Returns a zero-length vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, 0.0);
|
||||
return LVector3<NumType>(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -152,10 +93,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LVector3)(1.0, 0.0, 0.0);
|
||||
return LVector3<NumType>(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -163,10 +104,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LVector3)(0.0, 1.0, 0.0);
|
||||
return LVector3<NumType>(0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -174,10 +115,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Z vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
unit_z() {
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, 1.0);
|
||||
return LVector3<NumType>(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -185,10 +126,10 @@ unit_z() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase3)::operator - ();
|
||||
return LVecBase3<NumType>::operator - ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -196,10 +137,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVector3)::
|
||||
operator + (const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVector3<NumType>::
|
||||
operator + (const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -207,10 +148,10 @@ operator + (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
operator + (const FLOATNAME(LVector3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
operator + (const LVector3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -218,10 +159,10 @@ operator + (const FLOATNAME(LVector3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase3) FLOATNAME(LVector3)::
|
||||
operator - (const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase3<NumType> LVector3<NumType>::
|
||||
operator - (const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -229,10 +170,10 @@ operator - (const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
operator - (const FLOATNAME(LVector3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
operator - (const LVector3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -241,8 +182,8 @@ operator - (const FLOATNAME(LVector3) &other) const {
|
|||
// Description: Returns the length of the vector, by the Pythagorean
|
||||
// theorem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVector3<NumType>::
|
||||
length() const {
|
||||
return csqrt((*this).dot(*this));
|
||||
}
|
||||
|
|
@ -253,8 +194,8 @@ length() const {
|
|||
// Description: Returns the square of the vector's length, cheap and
|
||||
// easy.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVector3<NumType>::
|
||||
length_squared() const {
|
||||
return (*this).dot(*this);
|
||||
}
|
||||
|
|
@ -266,15 +207,15 @@ length_squared() const {
|
|||
// vector was normalized, false if it was a zero-length
|
||||
// vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE bool LVector3<NumType>::
|
||||
normalize() {
|
||||
FLOATTYPE1 l2 = length_squared();
|
||||
if (l2 == (FLOATTYPE1)0.0) {
|
||||
NumType l2 = length_squared();
|
||||
if (l2 == (NumType)0.0) {
|
||||
set(0.0, 0.0, 0.0);
|
||||
return false;
|
||||
|
||||
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(FLOATTYPE1) * NEARLY_ZERO(FLOATTYPE1))) {
|
||||
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) {
|
||||
(*this) /= csqrt(l2);
|
||||
}
|
||||
|
||||
|
|
@ -286,10 +227,10 @@ normalize() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
cross(const FLOATNAME(LVecBase3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::cross(other);
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
cross(const LVecBase3<NumType> &other) const {
|
||||
return LVecBase3<NumType>::cross(other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -297,10 +238,10 @@ cross(const FLOATNAME(LVecBase3) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVector3)(FLOATNAME(LVecBase3)::operator * (scalar));
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LVector3<NumType>(LVecBase3<NumType>::operator * (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -308,10 +249,10 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVector3)(FLOATNAME(LVecBase3)::operator / (scalar));
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LVector3<NumType>(LVecBase3<NumType>::operator / (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -320,8 +261,8 @@ operator / (FLOATTYPE1 scalar) const {
|
|||
// Description: Returns the up vector for the given coordinate
|
||||
// system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
LVector3<NumType> LVector3<NumType>::
|
||||
up(CoordinateSystem cs) {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
|
|
@ -329,16 +270,16 @@ up(CoordinateSystem cs) {
|
|||
switch (cs) {
|
||||
case CS_zup_right:
|
||||
case CS_zup_left:
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, 1.0);
|
||||
return LVector3<NumType>(0.0, 0.0, 1.0);
|
||||
|
||||
case CS_yup_right:
|
||||
case CS_yup_left:
|
||||
return FLOATNAME(LVector3)(0.0, 1.0, 0.0);
|
||||
return LVector3<NumType>(0.0, 1.0, 0.0);
|
||||
|
||||
default:
|
||||
linmath_cat.error()
|
||||
<< "Invalid coordinate system!\n";
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, 0.0);
|
||||
return LVector3<NumType>(0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -348,10 +289,10 @@ up(CoordinateSystem cs) {
|
|||
// Description: Returns the right vector for the given coordinate
|
||||
// system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
right(CoordinateSystem) {
|
||||
return FLOATNAME(LVector3)(1.0, 0.0, 0.0);
|
||||
return LVector3<NumType>(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -360,29 +301,29 @@ right(CoordinateSystem) {
|
|||
// Description: Returns the forward vector for the given coordinate
|
||||
// system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
LVector3<NumType> LVector3<NumType>::
|
||||
forward(CoordinateSystem cs) {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
switch (cs) {
|
||||
case CS_zup_right:
|
||||
return FLOATNAME(LVector3)(0.0, 1.0, 0.0);
|
||||
return LVector3<NumType>(0.0, 1.0, 0.0);
|
||||
|
||||
case CS_zup_left:
|
||||
return FLOATNAME(LVector3)(0.0, -1.0, 0.0);
|
||||
return LVector3<NumType>(0.0, -1.0, 0.0);
|
||||
|
||||
case CS_yup_right:
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, -1.0);
|
||||
return LVector3<NumType>(0.0, 0.0, -1.0);
|
||||
|
||||
case CS_yup_left:
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, 1.0);
|
||||
return LVector3<NumType>(0.0, 0.0, 1.0);
|
||||
|
||||
default:
|
||||
linmath_cat.error()
|
||||
<< "Invalid coordinate system!\n";
|
||||
return FLOATNAME(LVector3)(0.0, 0.0, 0.0);
|
||||
return LVector3<NumType>(0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -392,8 +333,8 @@ forward(CoordinateSystem cs) {
|
|||
// Description: Returns the down vector for the given coordinate
|
||||
// system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
down(CoordinateSystem cs) {
|
||||
return -up(cs);
|
||||
}
|
||||
|
|
@ -404,8 +345,8 @@ down(CoordinateSystem cs) {
|
|||
// Description: Returns the left vector for the given coordinate
|
||||
// system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
left(CoordinateSystem cs) {
|
||||
return -right(cs);
|
||||
}
|
||||
|
|
@ -416,8 +357,8 @@ left(CoordinateSystem cs) {
|
|||
// Description: Returns the back vector for the given coordinate
|
||||
// system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
back(CoordinateSystem cs) {
|
||||
return -forward(cs);
|
||||
}
|
||||
|
|
@ -429,10 +370,38 @@ back(CoordinateSystem cs) {
|
|||
// forward, and up components, in whatever way the
|
||||
// coordinate system represents that vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(LVector3)::
|
||||
rfu(FLOATTYPE1 right_v, FLOATTYPE1 fwd_v, FLOATTYPE1 up_v,
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> LVector3<NumType>::
|
||||
rfu(NumType right_v, NumType fwd_v, NumType up_v,
|
||||
CoordinateSystem cs) {
|
||||
return forward(cs) * fwd_v + up(cs) * up_v + right(cs) * right_v;
|
||||
return fwd_v * forward(cs) + up_v * up(cs) + right_v * right(cs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector3::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LVector3<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
LVecBase3<NumType>::init_type();
|
||||
string name =
|
||||
"LVector3<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name,
|
||||
LVecBase3<NumType>::get_class_type());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector3<NumType2>
|
||||
lcast_to(NumType2 *, const LVector3<NumType> &source) {
|
||||
return LVector3<NumType2>(source[0], source[1], source[2]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,37 +9,85 @@
|
|||
#include <pandabase.h>
|
||||
|
||||
#include "coordinateSystem.h"
|
||||
#include "cmath.h"
|
||||
#include "config_linmath.h"
|
||||
#include "lvecBase3.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVector3
|
||||
// Description : This is a three-component vector distance (as opposed
|
||||
// to a three-component point, which represents a
|
||||
// particular point in space). Some of the methods are
|
||||
// slightly different between LPoint3 and LVector3; in
|
||||
// particular, subtraction of two points yields a
|
||||
// vector, while addition of a vector and a point yields
|
||||
// a point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LVector3 : public LVecBase3<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LVector3();
|
||||
INLINE LVector3(const LVecBase3<NumType> ©);
|
||||
INLINE LVector3<NumType> &operator = (const LVecBase3<NumType> ©);
|
||||
INLINE LVector3<NumType> &operator = (NumType fill_value);
|
||||
INLINE LVector3(NumType fill_value);
|
||||
INLINE LVector3(NumType x, NumType y, NumType z);
|
||||
|
||||
INLINE static LVector3<NumType> zero();
|
||||
INLINE static LVector3<NumType> unit_x();
|
||||
INLINE static LVector3<NumType> unit_y();
|
||||
INLINE static LVector3<NumType> unit_z();
|
||||
|
||||
INLINE LVector3<NumType> operator - () const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
operator + (const LVecBase3<NumType> &other) const;
|
||||
INLINE LVector3<NumType>
|
||||
operator + (const LVector3<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase3<NumType>
|
||||
operator - (const LVecBase3<NumType> &other) const;
|
||||
INLINE LVector3<NumType>
|
||||
operator - (const LVector3<NumType> &other) const;
|
||||
|
||||
INLINE NumType length() const;
|
||||
INLINE NumType length_squared() const;
|
||||
INLINE bool normalize();
|
||||
INLINE LVector3<NumType> cross(const LVecBase3<NumType> &other) const;
|
||||
INLINE LVector3<NumType> operator * (NumType scalar) const;
|
||||
INLINE LVector3<NumType> operator / (NumType scalar) const;
|
||||
|
||||
// Some special named constructors for LVector3.
|
||||
|
||||
static LVector3<NumType> up(CoordinateSystem cs = CS_default);
|
||||
INLINE static LVector3<NumType> right(CoordinateSystem cs = CS_default);
|
||||
static LVector3<NumType> forward(CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE static LVector3<NumType> down(CoordinateSystem cs = CS_default);
|
||||
INLINE static LVector3<NumType> left(CoordinateSystem cs = CS_default);
|
||||
INLINE static LVector3<NumType> back(CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE static LVector3<NumType> rfu(NumType right,
|
||||
NumType fwd,
|
||||
NumType up,
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
// Cast to a different numeric type
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector3<NumType2>
|
||||
lcast_to(NumType2 *type, const LVector3<NumType> &source);
|
||||
|
||||
#include "lvector3.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvector3.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME2(LVector3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source) {
|
||||
return FLOATNAME2(LVector3)(source[0], source[1], source[2]);
|
||||
}
|
||||
|
||||
|
||||
#include "fltnames.I"
|
||||
|
||||
INLINE FLOATNAME2(LVector3)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source) {
|
||||
return FLOATNAME2(LVector3)(source[0], source[1], source[2]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector3<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector3<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,58 +3,20 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVector4
|
||||
// Description : This is a four-component vector distance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "cmath.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(LVector4) : public FLOATNAME(LVecBase4) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(LVector4)();
|
||||
INLINE FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©);
|
||||
INLINE FLOATNAME(LVector4) &operator = (const FLOATNAME(LVecBase4) ©);
|
||||
INLINE FLOATNAME(LVector4) &operator = (FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVector4)(FLOATTYPE1 fill_value);
|
||||
INLINE FLOATNAME(LVector4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w);
|
||||
|
||||
INLINE static FLOATNAME(LVector4) zero();
|
||||
INLINE static FLOATNAME(LVector4) unit_x();
|
||||
INLINE static FLOATNAME(LVector4) unit_y();
|
||||
INLINE static FLOATNAME(LVector4) unit_z();
|
||||
INLINE static FLOATNAME(LVector4) unit_w();
|
||||
|
||||
INLINE FLOATNAME(LVector4) operator - () const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) operator + (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE FLOATNAME(LVector4) operator + (const FLOATNAME(LVector4) &other) const;
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const;
|
||||
INLINE FLOATNAME(LVector4) operator - (const FLOATNAME(LVector4) &other) const;
|
||||
|
||||
INLINE FLOATTYPE1 length() const;
|
||||
INLINE FLOATTYPE1 length_squared() const;
|
||||
INLINE bool normalize();
|
||||
INLINE FLOATNAME(LVector4) operator * (FLOATTYPE1 scalar) const;
|
||||
INLINE FLOATNAME(LVector4) operator / (FLOATTYPE1 scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
template<class NumType>
|
||||
TypeHandle LVector4<NumType>::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector4::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4)::
|
||||
FLOATNAME(LVector4)() {
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType>::
|
||||
LVector4() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -62,9 +24,9 @@ FLOATNAME(LVector4)() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4)::
|
||||
FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) {
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType>::
|
||||
LVector4(const LVecBase4<NumType> ©) : LVecBase4<NumType>(copy) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -72,10 +34,10 @@ FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(cop
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) &FLOATNAME(LVector4)::
|
||||
operator = (const FLOATNAME(LVecBase4) ©) {
|
||||
FLOATNAME(LVecBase4)::operator = (copy);
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> &LVector4<NumType>::
|
||||
operator = (const LVecBase4<NumType> ©) {
|
||||
LVecBase4<NumType>::operator = (copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -84,10 +46,10 @@ operator = (const FLOATNAME(LVecBase4) ©) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) &FLOATNAME(LVector4)::
|
||||
operator = (FLOATTYPE1 fill_value) {
|
||||
FLOATNAME(LVecBase4)::operator = (fill_value);
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> &LVector4<NumType>::
|
||||
operator = (NumType fill_value) {
|
||||
LVecBase4<NumType>::operator = (fill_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -96,10 +58,10 @@ operator = (FLOATTYPE1 fill_value) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4)::
|
||||
FLOATNAME(LVector4)(FLOATTYPE1 fill_value) :
|
||||
FLOATNAME(LVecBase4)(fill_value)
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType>::
|
||||
LVector4(NumType fill_value) :
|
||||
LVecBase4<NumType>(fill_value)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -108,10 +70,10 @@ FLOATNAME(LVector4)(FLOATTYPE1 fill_value) :
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4)::
|
||||
FLOATNAME(LVector4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) :
|
||||
FLOATNAME(LVecBase4)(x, y, z, w)
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType>::
|
||||
LVector4(NumType x, NumType y, NumType z, NumType w) :
|
||||
LVecBase4<NumType>(x, y, z, w)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -120,10 +82,10 @@ FLOATNAME(LVector4)(FLOATTYPE1 x, FLOATTYPE1 y, FLOATTYPE1 z, FLOATTYPE1 w) :
|
|||
// Access: Public
|
||||
// Description: Returns a zero-length vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
zero() {
|
||||
return FLOATNAME(LVector4)(0.0, 0.0, 0.0, 0.0);
|
||||
return LVector4<NumType>(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -131,10 +93,10 @@ zero() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit X vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
unit_x() {
|
||||
return FLOATNAME(LVector4)(1.0, 0.0, 0.0, 0.0);
|
||||
return LVector4<NumType>(1.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -142,10 +104,10 @@ unit_x() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Y vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
unit_y() {
|
||||
return FLOATNAME(LVector4)(0.0, 1.0, 0.0, 0.0);
|
||||
return LVector4<NumType>(0.0, 1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -153,10 +115,10 @@ unit_y() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit Z vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
unit_z() {
|
||||
return FLOATNAME(LVector4)(0.0, 0.0, 1.0, 0.0);
|
||||
return LVector4<NumType>(0.0, 0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -164,10 +126,10 @@ unit_z() {
|
|||
// Access: Public
|
||||
// Description: Returns a unit W vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
unit_w() {
|
||||
return FLOATNAME(LVector4)(0.0, 0.0, 0.0, 1.0);
|
||||
return LVector4<NumType>(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -175,10 +137,10 @@ unit_w() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
operator - () const {
|
||||
return FLOATNAME(LVecBase4)::operator - ();
|
||||
return LVecBase4<NumType>::operator - ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -186,10 +148,10 @@ operator - () const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVector4)::
|
||||
operator + (const FLOATNAME(LVecBase4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVector4<NumType>::
|
||||
operator + (const LVecBase4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -197,10 +159,10 @@ operator + (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
operator + (const FLOATNAME(LVector4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator + (other);
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
operator + (const LVector4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator + (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -208,10 +170,10 @@ operator + (const FLOATNAME(LVector4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVecBase4) FLOATNAME(LVector4)::
|
||||
operator - (const FLOATNAME(LVecBase4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVecBase4<NumType> LVector4<NumType>::
|
||||
operator - (const LVecBase4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -219,10 +181,10 @@ operator - (const FLOATNAME(LVecBase4) &other) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
operator - (const FLOATNAME(LVector4) &other) const {
|
||||
return FLOATNAME(LVecBase4)::operator - (other);
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
operator - (const LVector4<NumType> &other) const {
|
||||
return LVecBase4<NumType>::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -231,8 +193,8 @@ operator - (const FLOATNAME(LVector4) &other) const {
|
|||
// Description: Returns the length of the vector, by the Pythagorean
|
||||
// theorem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVector4<NumType>::
|
||||
length() const {
|
||||
return csqrt((*this).dot(*this));
|
||||
}
|
||||
|
|
@ -243,8 +205,8 @@ length() const {
|
|||
// Description: Returns the square of the vector's length, cheap and
|
||||
// easy.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE NumType LVector4<NumType>::
|
||||
length_squared() const {
|
||||
return (*this).dot(*this);
|
||||
}
|
||||
|
|
@ -256,15 +218,15 @@ length_squared() const {
|
|||
// vector was normalized, false if it was a zero-length
|
||||
// vector.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(LVector4)::
|
||||
template<class NumType>
|
||||
INLINE bool LVector4<NumType>::
|
||||
normalize() {
|
||||
FLOATTYPE1 l2 = length_squared();
|
||||
if (l2 == (FLOATTYPE1)0.0) {
|
||||
NumType l2 = length_squared();
|
||||
if (l2 == (NumType)0.0) {
|
||||
set(0.0, 0.0, 0.0, 0.0);
|
||||
return false;
|
||||
|
||||
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(FLOATTYPE1) * NEARLY_ZERO(FLOATTYPE1))) {
|
||||
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) {
|
||||
(*this) /= csqrt(l2);
|
||||
}
|
||||
|
||||
|
|
@ -276,10 +238,10 @@ normalize() {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
operator * (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (scalar));
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
operator * (NumType scalar) const {
|
||||
return LVector4<NumType>(LVecBase4<NumType>::operator * (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -287,9 +249,37 @@ operator * (FLOATTYPE1 scalar) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector4) FLOATNAME(LVector4)::
|
||||
operator / (FLOATTYPE1 scalar) const {
|
||||
return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator / (scalar));
|
||||
template<class NumType>
|
||||
INLINE LVector4<NumType> LVector4<NumType>::
|
||||
operator / (NumType scalar) const {
|
||||
return LVector4<NumType>(LVecBase4<NumType>::operator / (scalar));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector4::init_type
|
||||
// Access: Public, Static
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
void LVector4<NumType>::
|
||||
init_type() {
|
||||
if (_type_handle == TypeHandle::none()) {
|
||||
LVecBase4<NumType>::init_type();
|
||||
string name =
|
||||
"LVector4<" + get_type_handle(NumType).get_name() + ">";
|
||||
register_type(_type_handle, name,
|
||||
LVecBase4<NumType>::get_class_type());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector4<NumType2>
|
||||
lcast_to(NumType2 *, const LVector4<NumType> &source) {
|
||||
return LVector4<NumType2>(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,34 +7,64 @@
|
|||
#define LVECTOR4_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "cmath.h"
|
||||
#include "config_linmath.h"
|
||||
|
||||
#include "lvecBase4.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : LVector4
|
||||
// Description : This is a four-component vector distance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class LVector4 : public LVecBase4<NumType> {
|
||||
PUBLISHED:
|
||||
INLINE LVector4();
|
||||
INLINE LVector4(const LVecBase4<NumType> ©);
|
||||
INLINE LVector4<NumType> &operator = (const LVecBase4<NumType> ©);
|
||||
INLINE LVector4<NumType> &operator = (NumType fill_value);
|
||||
INLINE LVector4(NumType fill_value);
|
||||
INLINE LVector4(NumType x, NumType y, NumType z, NumType w);
|
||||
|
||||
INLINE static LVector4<NumType> zero();
|
||||
INLINE static LVector4<NumType> unit_x();
|
||||
INLINE static LVector4<NumType> unit_y();
|
||||
INLINE static LVector4<NumType> unit_z();
|
||||
INLINE static LVector4<NumType> unit_w();
|
||||
|
||||
INLINE LVector4<NumType> operator - () const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
operator + (const LVecBase4<NumType> &other) const;
|
||||
INLINE LVector4<NumType>
|
||||
operator + (const LVector4<NumType> &other) const;
|
||||
|
||||
INLINE LVecBase4<NumType>
|
||||
operator - (const LVecBase4<NumType> &other) const;
|
||||
INLINE LVector4<NumType>
|
||||
operator - (const LVector4<NumType> &other) const;
|
||||
|
||||
INLINE NumType length() const;
|
||||
INLINE NumType length_squared() const;
|
||||
INLINE bool normalize();
|
||||
INLINE LVector4<NumType> operator * (NumType scalar) const;
|
||||
INLINE LVector4<NumType> operator / (NumType scalar) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type();
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
template<class NumType, class NumType2>
|
||||
INLINE LVector4<NumType2>
|
||||
lcast_to(NumType2 *type, const LVector4<NumType> &source);
|
||||
|
||||
#include "lvector4.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "lvector4.I"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: lcast_to
|
||||
// Description: Converts a vector from one numeric representation to
|
||||
// another one. This is usually invoked using the macro
|
||||
// LCAST.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FLOATNAME2(LVector4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source) {
|
||||
return FLOATNAME2(LVector4)(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
||||
#include "fltnames.I"
|
||||
INLINE FLOATNAME2(LVector4)
|
||||
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source) {
|
||||
return FLOATNAME2(LVector4)(source[0], source[1], source[2], source[3]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector4<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector4<double>)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ get_nearly_zero_value(float) {
|
|||
// NEARLY_ZERO(float) returns a number that is considered to be so
|
||||
// close to zero as not to matter for a float. NEARLY_ZERO(double)
|
||||
// returns a similar, smaller number for a double.
|
||||
#define NEARLY_ZERO(FLOATTYPE1) (get_nearly_zero_value((FLOATTYPE1)0))
|
||||
#define NEARLY_ZERO(NumType) (get_nearly_zero_value((NumType)0))
|
||||
|
||||
// IS_NEARLY_ZERO(value) returns true if the value is very close to
|
||||
// zero.
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
config_mathutil.h \
|
||||
fftCompressor.cxx fftCompressor.h \
|
||||
finiteBoundingVolume.cxx finiteBoundingVolume.h \
|
||||
frustum.I frustum.h frustum.N plane.N\
|
||||
frustum.I frustum.h \
|
||||
geometricBoundingVolume.I geometricBoundingVolume.cxx \
|
||||
geometricBoundingVolume.h look_at.I look_at.cxx look_at.h look_at_src.I\
|
||||
geometricBoundingVolume.h look_at.I look_at.cxx look_at.h \
|
||||
omniBoundingVolume.I omniBoundingVolume.cxx omniBoundingVolume.h \
|
||||
plane.I plane.cxx plane.h rotate_to.cxx rotate_to_src.I rotate_to.h
|
||||
plane.I plane.N plane.cxx plane.h rotate_to.cxx rotate_to.h
|
||||
|
||||
#define INSTALL_HEADERS \
|
||||
boundingHexahedron.I boundingHexahedron.h boundingLine.I \
|
||||
|
|
|
|||
|
|
@ -6,50 +6,10 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Includes
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "mathutil.h"
|
||||
#include "config_mathutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Defines
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : Frustum
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA FLOATNAME(Frustum) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(Frustum)();
|
||||
|
||||
INLINE void make_ortho_2D(void);
|
||||
INLINE void make_ortho_2D(FLOATTYPE1 l, FLOATTYPE1 r, FLOATTYPE1 t, FLOATTYPE1 b);
|
||||
|
||||
INLINE void make_ortho(FLOATTYPE1 fnear, FLOATTYPE1 ffar);
|
||||
INLINE void make_ortho(FLOATTYPE1 fnear, FLOATTYPE1 ffar,
|
||||
FLOATTYPE1 l, FLOATTYPE1 r, FLOATTYPE1 t, FLOATTYPE1 b);
|
||||
|
||||
INLINE void make_perspective_hfov(FLOATTYPE1 xfov, FLOATTYPE1 aspect,
|
||||
FLOATTYPE1 fnear, FLOATTYPE1 ffar);
|
||||
INLINE void make_perspective_vfov(FLOATTYPE1 yfov, FLOATTYPE1 aspect,
|
||||
FLOATTYPE1 fnear, FLOATTYPE1 ffar);
|
||||
INLINE void make_perspective(FLOATTYPE1 xfov, FLOATTYPE1 yfov, FLOATTYPE1 fnear,
|
||||
FLOATTYPE1 ffar);
|
||||
INLINE void get_perspective_params(FLOATTYPE1 &yfov, FLOATTYPE1 &aspect,
|
||||
FLOATTYPE1 &fnear, FLOATTYPE1 &ffar) const;
|
||||
INLINE void get_perspective_params(FLOATTYPE1 &xfov, FLOATTYPE1 &yfov,
|
||||
FLOATTYPE1 &aspect, FLOATTYPE1 &fnear,
|
||||
FLOATTYPE1 &ffar) const;
|
||||
|
||||
public:
|
||||
INLINE FLOATNAME(LMatrix4)
|
||||
get_perspective_projection_mat(CoordinateSystem cs = CS_default) const;
|
||||
|
||||
INLINE FLOATNAME(LMatrix4)
|
||||
get_ortho_projection_mat(CoordinateSystem cs = CS_default) const;
|
||||
|
||||
public:
|
||||
FLOATTYPE1 _l, _r, _b, _t;
|
||||
FLOATTYPE1 _fnear, _ffar;
|
||||
};
|
||||
|
||||
#include <math.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
|
|
@ -60,9 +20,9 @@ public:
|
|||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Frustum)::
|
||||
FLOATNAME(Frustum)() {
|
||||
template<class P_numtype>
|
||||
Frustum<P_numtype>::
|
||||
Frustum() {
|
||||
_fnear = 1.4142;
|
||||
_ffar = 10.0;
|
||||
_l = -1;
|
||||
|
|
@ -76,8 +36,8 @@ FLOATNAME(Frustum)() {
|
|||
// Access:
|
||||
// Description: Sets up a two-dimensional orthographic frustum
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::make_ortho_2D(void) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::make_ortho_2D(void) {
|
||||
make_ortho(-1, 1);
|
||||
}
|
||||
|
||||
|
|
@ -86,9 +46,9 @@ INLINE void FLOATNAME(Frustum)::make_ortho_2D(void) {
|
|||
// Access:
|
||||
// Description: Sets up a two-dimensional orthographic frustum
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
make_ortho_2D(FLOATTYPE1 l, FLOATTYPE1 r, FLOATTYPE1 t, FLOATTYPE1 b) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
make_ortho_2D(P_numtype l, P_numtype r, P_numtype t, P_numtype b) {
|
||||
make_ortho(-1, 1, l, r, t, b);
|
||||
}
|
||||
|
||||
|
|
@ -97,8 +57,8 @@ make_ortho_2D(FLOATTYPE1 l, FLOATTYPE1 r, FLOATTYPE1 t, FLOATTYPE1 b) {
|
|||
// Access:
|
||||
// Description: Behaves like gluOrtho
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::make_ortho(FLOATTYPE1 fnear, FLOATTYPE1 ffar) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::make_ortho(P_numtype fnear, P_numtype ffar) {
|
||||
_fnear = fnear;
|
||||
_ffar = ffar;
|
||||
_l = -1;
|
||||
|
|
@ -112,10 +72,10 @@ INLINE void FLOATNAME(Frustum)::make_ortho(FLOATTYPE1 fnear, FLOATTYPE1 ffar) {
|
|||
// Access:
|
||||
// Description: Behaves like gluOrtho
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
make_ortho(FLOATTYPE1 fnear, FLOATTYPE1 ffar, FLOATTYPE1 l, FLOATTYPE1 r,
|
||||
FLOATTYPE1 t, FLOATTYPE1 b) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
make_ortho(P_numtype fnear, P_numtype ffar, P_numtype l, P_numtype r,
|
||||
P_numtype t, P_numtype b) {
|
||||
_fnear = fnear;
|
||||
_ffar = ffar;
|
||||
_l = l;
|
||||
|
|
@ -146,10 +106,10 @@ make_ortho(FLOATTYPE1 fnear, FLOATTYPE1 ffar, FLOATTYPE1 l, FLOATTYPE1 r,
|
|||
// W yfov
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
make_perspective_hfov(FLOATTYPE1 hfov, FLOATTYPE1 aspect, FLOATTYPE1 fnear,
|
||||
FLOATTYPE1 ffar) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
make_perspective_hfov(P_numtype hfov, P_numtype aspect, P_numtype fnear,
|
||||
P_numtype ffar) {
|
||||
_fnear = fnear;
|
||||
_ffar = ffar;
|
||||
_r = tan(deg_2_rad(hfov) * 0.5) * _fnear;
|
||||
|
|
@ -158,10 +118,10 @@ make_perspective_hfov(FLOATTYPE1 hfov, FLOATTYPE1 aspect, FLOATTYPE1 fnear,
|
|||
_b = -_t;
|
||||
}
|
||||
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
make_perspective_vfov(FLOATTYPE1 yfov, FLOATTYPE1 aspect, FLOATTYPE1 fnear,
|
||||
FLOATTYPE1 ffar) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
make_perspective_vfov(P_numtype yfov, P_numtype aspect, P_numtype fnear,
|
||||
P_numtype ffar) {
|
||||
_fnear = fnear;
|
||||
_ffar = ffar;
|
||||
_t = tan(deg_2_rad(yfov) * 0.5) * _fnear;
|
||||
|
|
@ -170,10 +130,10 @@ make_perspective_vfov(FLOATTYPE1 yfov, FLOATTYPE1 aspect, FLOATTYPE1 fnear,
|
|||
_l = -_r;
|
||||
}
|
||||
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
make_perspective(FLOATTYPE1 xfov, FLOATTYPE1 yfov, FLOATTYPE1 fnear,
|
||||
FLOATTYPE1 ffar) {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
make_perspective(P_numtype xfov, P_numtype yfov, P_numtype fnear,
|
||||
P_numtype ffar) {
|
||||
_fnear = fnear;
|
||||
_ffar = ffar;
|
||||
_t = tan(deg_2_rad(yfov) * 0.5) * _fnear;
|
||||
|
|
@ -187,10 +147,10 @@ make_perspective(FLOATTYPE1 xfov, FLOATTYPE1 yfov, FLOATTYPE1 fnear,
|
|||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
get_perspective_params(FLOATTYPE1& yfov, FLOATTYPE1& aspect,
|
||||
FLOATTYPE1& fnear, FLOATTYPE1& ffar) const {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
get_perspective_params(P_numtype& yfov, P_numtype& aspect,
|
||||
P_numtype& fnear, P_numtype& ffar) const {
|
||||
yfov = rad_2_deg(atan(_t / _fnear)) * 2.0;
|
||||
aspect = _r / _t;
|
||||
fnear = _fnear;
|
||||
|
|
@ -202,10 +162,10 @@ get_perspective_params(FLOATTYPE1& yfov, FLOATTYPE1& aspect,
|
|||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Frustum)::
|
||||
get_perspective_params(FLOATTYPE1& xfov, FLOATTYPE1& yfov, FLOATTYPE1& aspect,
|
||||
FLOATTYPE1& fnear, FLOATTYPE1& ffar) const {
|
||||
template<class P_numtype>
|
||||
void Frustum<P_numtype>::
|
||||
get_perspective_params(P_numtype& xfov, P_numtype& yfov, P_numtype& aspect,
|
||||
P_numtype& fnear, P_numtype& ffar) const {
|
||||
xfov = rad_2_deg(atan(_r / _fnear)) * 2.0;
|
||||
get_perspective_params(yfov, aspect, fnear, ffar);
|
||||
}
|
||||
|
|
@ -217,45 +177,45 @@ get_perspective_params(FLOATTYPE1& xfov, FLOATTYPE1& yfov, FLOATTYPE1& aspect,
|
|||
// perspective transform defined by the frustum,
|
||||
// accordinate to the indicated coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix4) FLOATNAME(Frustum)::
|
||||
template<class P_numtype>
|
||||
LMatrix4<P_numtype> Frustum<P_numtype>::
|
||||
get_perspective_projection_mat(CoordinateSystem cs) const {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
|
||||
FLOATTYPE1 a = (2.0 * _fnear) / (_r - _l);
|
||||
FLOATTYPE1 b = (_t + _b) / (_t - _b);
|
||||
FLOATTYPE1 c = (_ffar + _fnear) / (_ffar - _fnear);
|
||||
FLOATTYPE1 d = (_r + _l) / (_r - _l);
|
||||
FLOATTYPE1 e = (2.0 * _fnear) / (_t - _b);
|
||||
FLOATTYPE1 f = (-2.0 * _ffar * _fnear) / (_ffar - _fnear);
|
||||
P_numtype a = (2.0 * _fnear) / (_r - _l);
|
||||
P_numtype b = (_t + _b) / (_t - _b);
|
||||
P_numtype c = (_ffar + _fnear) / (_ffar - _fnear);
|
||||
P_numtype d = (_r + _l) / (_r - _l);
|
||||
P_numtype e = (2.0 * _fnear) / (_t - _b);
|
||||
P_numtype f = (-2.0 * _ffar * _fnear) / (_ffar - _fnear);
|
||||
|
||||
switch (cs) {
|
||||
case CS_zup_right:
|
||||
return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0,
|
||||
return LMatrix4<P_numtype>( a, 0.0, 0.0, 0.0,
|
||||
0.0, -b, c, 1.0,
|
||||
d, e, 0.0, 0.0,
|
||||
0.0, 0.0, f, 0.0);
|
||||
|
||||
case CS_yup_right:
|
||||
return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0,
|
||||
return LMatrix4<P_numtype>( a, 0.0, 0.0, 0.0,
|
||||
0.0, e, 0.0, 0.0,
|
||||
d, b, -c,-1.0,
|
||||
0.0, 0.0, f, 0.0);
|
||||
|
||||
case CS_zup_left:
|
||||
return FLOATNAME(LMatrix4)::convert_mat(CS_zup_right, CS_zup_left) *
|
||||
return LMatrix4<P_numtype>::convert_mat(CS_zup_right, CS_zup_left) *
|
||||
get_perspective_projection_mat(CS_zup_right);
|
||||
|
||||
case CS_yup_left:
|
||||
return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_yup_left) *
|
||||
return LMatrix4<P_numtype>::convert_mat(CS_yup_right, CS_yup_left) *
|
||||
get_perspective_projection_mat(CS_yup_right);
|
||||
|
||||
default:
|
||||
mathutil_cat.error()
|
||||
<< "Invalid coordinate system!\n";
|
||||
return FLOATNAME(LMatrix4)::ident_mat();
|
||||
return LMatrix4<P_numtype>::ident_mat();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -266,42 +226,42 @@ get_perspective_projection_mat(CoordinateSystem cs) const {
|
|||
// orthographic transform defined by the frustum,
|
||||
// accordinate to the indicated coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix4) FLOATNAME(Frustum)::
|
||||
template<class P_numtype>
|
||||
LMatrix4<P_numtype> Frustum<P_numtype>::
|
||||
get_ortho_projection_mat(CoordinateSystem cs) const {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
|
||||
FLOATTYPE1 a = 2.0 / (_r - _l);
|
||||
FLOATTYPE1 b = 2.0 / (_t - _b);
|
||||
FLOATTYPE1 c = 2.0 / (_ffar - _fnear);
|
||||
FLOATTYPE1 d = (_r + _l) / (_r - _l);
|
||||
FLOATTYPE1 e = (_t + _b) / (_t - _b);
|
||||
FLOATTYPE1 f = (_ffar + _fnear) / (_ffar - _fnear);
|
||||
P_numtype a = 2.0 / (_r - _l);
|
||||
P_numtype b = 2.0 / (_t - _b);
|
||||
P_numtype c = 2.0 / (_ffar - _fnear);
|
||||
P_numtype d = (_r + _l) / (_r - _l);
|
||||
P_numtype e = (_t + _b) / (_t - _b);
|
||||
P_numtype f = (_ffar + _fnear) / (_ffar - _fnear);
|
||||
|
||||
switch (cs) {
|
||||
case CS_zup_right:
|
||||
return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_zup_right) *
|
||||
return LMatrix4<P_numtype>::convert_mat(CS_yup_right, CS_zup_right) *
|
||||
get_ortho_projection_mat(CS_yup_right);
|
||||
|
||||
case CS_yup_right:
|
||||
return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0,
|
||||
return LMatrix4<P_numtype>( a, 0.0, 0.0, 0.0,
|
||||
0.0, b, 0.0, 0.0,
|
||||
0.0, 0.0, -c, 0.0,
|
||||
-d, -e, -f, 1.0);
|
||||
|
||||
case CS_zup_left:
|
||||
return FLOATNAME(LMatrix4)::convert_mat(CS_zup_right, CS_zup_left) *
|
||||
return LMatrix4<P_numtype>::convert_mat(CS_zup_right, CS_zup_left) *
|
||||
get_ortho_projection_mat(CS_zup_right);
|
||||
|
||||
case CS_yup_left:
|
||||
return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_yup_left) *
|
||||
return LMatrix4<P_numtype>::convert_mat(CS_yup_right, CS_yup_left) *
|
||||
get_ortho_projection_mat(CS_yup_right);
|
||||
|
||||
default:
|
||||
mathutil_cat.error()
|
||||
<< "Invalid coordinate system!\n";
|
||||
return FLOATNAME(LMatrix4)::ident_mat();
|
||||
return LMatrix4<P_numtype>::ident_mat();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,2 @@
|
|||
forcetype Frustumf
|
||||
renametype Frustumf Frustumf
|
||||
forcetype Frustumd
|
||||
renametype Frustumd Frustumd
|
||||
forcetype Frustum<float>
|
||||
forcetype Frustum<double>
|
||||
|
|
|
|||
|
|
@ -10,15 +10,56 @@
|
|||
// Includes
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include <pandabase.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <luse.h>
|
||||
#include "mathutil.h"
|
||||
#include "config_mathutil.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Defines
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : Frustum
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class P_numtype>
|
||||
class EXPCL_PANDA Frustum {
|
||||
PUBLISHED:
|
||||
Frustum();
|
||||
|
||||
void make_ortho_2D(void);
|
||||
void make_ortho_2D(P_numtype l, P_numtype r, P_numtype t, P_numtype b);
|
||||
|
||||
void make_ortho(P_numtype fnear, P_numtype ffar);
|
||||
void make_ortho(P_numtype fnear, P_numtype ffar,
|
||||
P_numtype l, P_numtype r, P_numtype t, P_numtype b);
|
||||
|
||||
void make_perspective_hfov(P_numtype xfov, P_numtype aspect,
|
||||
P_numtype fnear, P_numtype ffar);
|
||||
void make_perspective_vfov(P_numtype yfov, P_numtype aspect,
|
||||
P_numtype fnear, P_numtype ffar);
|
||||
void make_perspective(P_numtype xfov, P_numtype yfov, P_numtype fnear,
|
||||
P_numtype ffar);
|
||||
void get_perspective_params(P_numtype &yfov, P_numtype &aspect,
|
||||
P_numtype &fnear, P_numtype &ffar) const;
|
||||
void get_perspective_params(P_numtype &xfov, P_numtype &yfov,
|
||||
P_numtype &aspect, P_numtype &fnear,
|
||||
P_numtype &ffar) const;
|
||||
|
||||
public:
|
||||
LMatrix4<P_numtype>
|
||||
get_perspective_projection_mat(CoordinateSystem cs = CS_default) const;
|
||||
|
||||
LMatrix4<P_numtype>
|
||||
get_ortho_projection_mat(CoordinateSystem cs = CS_default) const;
|
||||
|
||||
public:
|
||||
P_numtype _l, _r, _b, _t;
|
||||
P_numtype _fnear, _ffar;
|
||||
};
|
||||
|
||||
#include "frustum.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "frustum.I"
|
||||
typedef Frustum<float> Frustumf;
|
||||
typedef Frustum<double> Frustumd;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,86 +3,77 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
// These functions return a matrix that rotates between a coordinate
|
||||
// system defined with the given forward and up vectors, and the
|
||||
// standard coordinate system with y-forward and z-up. They differ
|
||||
// only in their behavior when the supplied forward and up vectors are
|
||||
// not perpendicular; in this case, look_at will match the forward
|
||||
// vector precisely, while heads_up will match the up vector
|
||||
// precisely.
|
||||
|
||||
// Since these functions only return a rotation matrix, the
|
||||
// translation component is always zero. There are flavors of these
|
||||
// functions that simply return the upper 3x3 part of the matrix, and
|
||||
// flavors that return the whole 4x4 matrix with a zero bottom row.
|
||||
|
||||
BEGIN_PUBLISH
|
||||
|
||||
// Flavors for float-type arithmetic.
|
||||
|
||||
EXPCL_PANDA void
|
||||
heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA void
|
||||
look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
CoordinateSystem cs);
|
||||
INLINE void look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
CoordinateSystem cs);
|
||||
|
||||
|
||||
INLINE void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
CoordinateSystem cs);
|
||||
INLINE void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
CoordinateSystem cs);
|
||||
|
||||
END_PUBLISH
|
||||
|
||||
|
||||
INLINE void
|
||||
heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) {
|
||||
heads_up(mat, fwd, FLOATNAME(LVector3)::up(cs), cs);
|
||||
heads_up(LMatrix3f &mat, const LVector3f &fwd, CoordinateSystem cs) {
|
||||
heads_up(mat, fwd, LVector3f::up(cs), cs);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) {
|
||||
look_at(mat, fwd, FLOATNAME(LVector3)::up(cs), cs);
|
||||
look_at(LMatrix3f &mat, const LVector3f &fwd, CoordinateSystem cs) {
|
||||
look_at(mat, fwd, LVector3f::up(cs), cs);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
const FLOATNAME(LVector3) &up, CoordinateSystem cs) {
|
||||
FLOATNAME(LMatrix3) mat3;
|
||||
heads_up(LMatrix4f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up, CoordinateSystem cs) {
|
||||
LMatrix3f mat3;
|
||||
heads_up(mat3, fwd, up, cs);
|
||||
mat = FLOATNAME(LMatrix4)(mat3);
|
||||
mat = LMatrix4f(mat3);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd,
|
||||
const FLOATNAME(LVector3) &up, CoordinateSystem cs) {
|
||||
FLOATNAME(LMatrix3) mat3;
|
||||
look_at(LMatrix4f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up, CoordinateSystem cs) {
|
||||
LMatrix3f mat3;
|
||||
look_at(mat3, fwd, up, cs);
|
||||
mat = FLOATNAME(LMatrix4)(mat3);
|
||||
mat = LMatrix4f(mat3);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) {
|
||||
heads_up(mat, fwd, FLOATNAME(LVector3)::up(cs), cs);
|
||||
heads_up(LMatrix4f &mat, const LVector3f &fwd, CoordinateSystem cs) {
|
||||
heads_up(mat, fwd, LVector3f::up(cs), cs);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) {
|
||||
look_at(mat, fwd, FLOATNAME(LVector3)::up(cs), cs);
|
||||
look_at(LMatrix4f &mat, const LVector3f &fwd, CoordinateSystem cs) {
|
||||
look_at(mat, fwd, LVector3f::up(cs), cs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
INLINE void
|
||||
heads_up(LMatrix3d &mat, const LVector3d &fwd, CoordinateSystem cs) {
|
||||
heads_up(mat, fwd, LVector3d::up(cs), cs);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
look_at(LMatrix3d &mat, const LVector3d &fwd, CoordinateSystem cs) {
|
||||
look_at(mat, fwd, LVector3d::up(cs), cs);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
heads_up(LMatrix4d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up, CoordinateSystem cs) {
|
||||
LMatrix3d mat3;
|
||||
heads_up(mat3, fwd, up, cs);
|
||||
mat = LMatrix4d(mat3);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
look_at(LMatrix4d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up, CoordinateSystem cs) {
|
||||
LMatrix3d mat3;
|
||||
look_at(mat3, fwd, up, cs);
|
||||
mat = LMatrix4d(mat3);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
heads_up(LMatrix4d &mat, const LVector3d &fwd, CoordinateSystem cs) {
|
||||
heads_up(mat, fwd, LVector3d::up(cs), cs);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
look_at(LMatrix4d &mat, const LVector3d &fwd, CoordinateSystem cs) {
|
||||
look_at(mat, fwd, LVector3d::up(cs), cs);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,337 @@
|
|||
// Created by: drose (25Apr97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Includes
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "look_at.h"
|
||||
#include <cmath.h>
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "look_at_src.I"
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType>
|
||||
make_xi_mat(const LVector2<NumType> &x) {
|
||||
return LMatrix3<NumType>(1, 0, 0,
|
||||
0, x[0], x[1],
|
||||
0, -x[1], x[0]);
|
||||
}
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "look_at_src.I"
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType>
|
||||
make_x_mat(const LVector2<NumType> &x) {
|
||||
return LMatrix3<NumType>(1, 0, 0,
|
||||
0, x[1], x[0],
|
||||
0, -x[0], x[1]);
|
||||
}
|
||||
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType>
|
||||
make_y_mat(const LVector2<NumType> &y) {
|
||||
return LMatrix3<NumType>(y[1], 0, -y[0],
|
||||
0, 1, 0,
|
||||
y[0], 0, y[1]);
|
||||
}
|
||||
|
||||
template<class NumType>
|
||||
INLINE LMatrix3<NumType>
|
||||
make_z_mat(const LVector2<NumType> &z) {
|
||||
return LMatrix3<NumType>(z[1], -z[0], 0,
|
||||
z[0], z[1], 0,
|
||||
0, 0, 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: heads_up
|
||||
// Description: Given two vectors defining a forward direction and an
|
||||
// up vector, constructs the matrix that rotates things
|
||||
// from the defined coordinate system to y-forward and
|
||||
// z-up. The up vector will be rotated to z-up first,
|
||||
// then the forward vector will be rotated as nearly to
|
||||
// y-forward as possible. This will only have a
|
||||
// different effect from look_at() if the forward and up
|
||||
// vectors are not perpendicular.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
_heads_up(LMatrix3<NumType> &mat, const LVector3<NumType> &fwd,
|
||||
const LVector3<NumType> &up, CoordinateSystem cs) {
|
||||
if (cs == CS_zup_right || cs == CS_zup_left) {
|
||||
// Z-up.
|
||||
|
||||
// y is the projection of the up vector into the XZ plane. Its
|
||||
// angle to the Z axis is the amount to rotate about the Y axis to
|
||||
// bring the up vector into the YZ plane.
|
||||
|
||||
LVector2<NumType> y(up[0], up[2]);
|
||||
NumType d = dot(y, y);
|
||||
if (d==0.0) {
|
||||
y = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
y /= csqrt(d);
|
||||
}
|
||||
|
||||
// x is the up vector rotated into the YZ plane. Its angle to the Z
|
||||
// axis is the amount to rotate about the X axis to bring the up
|
||||
// vector to the Z axis.
|
||||
|
||||
LVector2<NumType> x(up[1], up[0]*y[0]+up[2]*y[1]);
|
||||
d = dot(x, x);
|
||||
if (d==0.0) {
|
||||
x = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
x /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now apply both rotations to the forward vector. This will rotate
|
||||
// the forward vector by the same amount we would have had to rotate
|
||||
// the up vector to bring it to the Z axis. If the vectors were
|
||||
// perpendicular, this will put the forward vector somewhere in the
|
||||
// XY plane.
|
||||
|
||||
// z is the projection of the newly rotated fwd vector into the XY
|
||||
// plane. Its angle to the Y axis is the amount to rotate about the
|
||||
// Z axis in order to bring the fwd vector to the Y axis.
|
||||
LVector2<NumType> z(fwd[0]*y[1] - fwd[2]*y[0],
|
||||
-fwd[0]*y[0]*x[0] + fwd[1]*x[1] - fwd[2]*y[1]*x[0]);
|
||||
d = dot(z, z);
|
||||
if (d==0.0) {
|
||||
z = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
z /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now build the net rotation matrix.
|
||||
if (cs == CS_zup_right) {
|
||||
mat =
|
||||
make_z_mat(z) *
|
||||
make_x_mat(x) *
|
||||
make_y_mat(y);
|
||||
} else { // cs == CS_zup_left
|
||||
mat =
|
||||
make_z_mat(z) *
|
||||
make_x_mat(-x) *
|
||||
make_y_mat(-y);
|
||||
}
|
||||
} else {
|
||||
// Y-up.
|
||||
|
||||
// z is the projection of the forward vector into the XY plane. Its
|
||||
// angle to the Y axis is the amount to rotate about the Z axis to
|
||||
// bring the forward vector into the YZ plane.
|
||||
|
||||
LVector2<NumType> z(up[0], up[1]);
|
||||
NumType d = dot(z, z);
|
||||
if (d==0.0) {
|
||||
z = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
z /= csqrt(d);
|
||||
}
|
||||
|
||||
// x is the forward vector rotated into the YZ plane. Its angle to
|
||||
// the Y axis is the amount to rotate about the X axis to bring the
|
||||
// forward vector to the Y axis.
|
||||
|
||||
LVector2<NumType> x(up[0]*z[0] + up[1]*z[1], up[2]);
|
||||
d = dot(x, x);
|
||||
if (d==0.0) {
|
||||
x = LVector2<NumType>(1.0, 0.0);
|
||||
} else {
|
||||
x /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now apply both rotations to the up vector. This will rotate
|
||||
// the up vector by the same amount we would have had to rotate
|
||||
// the forward vector to bring it to the Y axis. If the vectors were
|
||||
// perpendicular, this will put the up vector somewhere in the
|
||||
// XZ plane.
|
||||
|
||||
// y is the projection of the newly rotated up vector into the XZ
|
||||
// plane. Its angle to the Z axis is the amount to rotate about the
|
||||
// Y axis in order to bring the up vector to the Z axis.
|
||||
LVector2<NumType> y(fwd[0]*z[1] - fwd[1]*z[0],
|
||||
-fwd[0]*x[1]*z[0] - fwd[1]*x[1]*z[1] + fwd[2]*x[0]);
|
||||
d = dot(y, y);
|
||||
if (d==0.0) {
|
||||
y = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
y /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now build the net rotation matrix.
|
||||
if (cs == CS_yup_right) {
|
||||
mat =
|
||||
make_y_mat(y) *
|
||||
make_xi_mat(-x) *
|
||||
make_z_mat(-z);
|
||||
} else { // cs == CS_yup_left
|
||||
mat =
|
||||
make_y_mat(y) *
|
||||
make_xi_mat(x) *
|
||||
make_z_mat(z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: look_at
|
||||
// Description: Given two vectors defining a forward direction and an
|
||||
// up vector, constructs the matrix that rotates things
|
||||
// from the defined coordinate system to y-forward and
|
||||
// z-up. The forward vector will be rotated to
|
||||
// y-forward first, then the up vector will be rotated
|
||||
// as nearly to z-up as possible. This will only have a
|
||||
// different effect from heads_up() if the forward and
|
||||
// up vectors are not perpendicular.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
_look_at(LMatrix3<NumType> &mat, const LVector3<NumType> &fwd,
|
||||
const LVector3<NumType> &up, CoordinateSystem cs) {
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
|
||||
if (cs == CS_zup_right || cs == CS_zup_left) {
|
||||
// Z-up.
|
||||
|
||||
// z is the projection of the forward vector into the XY plane. Its
|
||||
// angle to the Y axis is the amount to rotate about the Z axis to
|
||||
// bring the forward vector into the YZ plane.
|
||||
|
||||
LVector2<NumType> z(fwd[0], fwd[1]);
|
||||
NumType d = dot(z, z);
|
||||
if (d==0.0) {
|
||||
z = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
z /= csqrt(d);
|
||||
}
|
||||
|
||||
// x is the forward vector rotated into the YZ plane. Its angle to
|
||||
// the Y axis is the amount to rotate about the X axis to bring the
|
||||
// forward vector to the Y axis.
|
||||
|
||||
LVector2<NumType> x(fwd[0]*z[0] + fwd[1]*z[1], fwd[2]);
|
||||
d = dot(x, x);
|
||||
if (d==0.0) {
|
||||
x = LVector2<NumType>(1.0, 0.0);
|
||||
} else {
|
||||
x /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now apply both rotations to the up vector. This will rotate
|
||||
// the up vector by the same amount we would have had to rotate
|
||||
// the forward vector to bring it to the Y axis. If the vectors were
|
||||
// perpendicular, this will put the up vector somewhere in the
|
||||
// XZ plane.
|
||||
|
||||
// y is the projection of the newly rotated up vector into the XZ
|
||||
// plane. Its angle to the Z axis is the amount to rotate about the
|
||||
// Y axis in order to bring the up vector to the Z axis.
|
||||
LVector2<NumType> y(up[0]*z[1] - up[1]*z[0],
|
||||
-up[0]*x[1]*z[0] - up[1]*x[1]*z[1] + up[2]*x[0]);
|
||||
d = dot(y, y);
|
||||
if (d==0.0) {
|
||||
y = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
y /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now build the net rotation matrix.
|
||||
if (cs == CS_zup_right) {
|
||||
mat =
|
||||
make_y_mat(y) *
|
||||
make_xi_mat(x) *
|
||||
make_z_mat(z);
|
||||
} else { // cs == CS_zup_left
|
||||
mat =
|
||||
make_y_mat(-y) *
|
||||
make_xi_mat(-x) *
|
||||
make_z_mat(z);
|
||||
}
|
||||
} else {
|
||||
// Y-up.
|
||||
|
||||
// y is the projection of the up vector into the XZ plane. Its
|
||||
// angle to the Z axis is the amount to rotate about the Y axis to
|
||||
// bring the up vector into the YZ plane.
|
||||
|
||||
LVector2<NumType> y(fwd[0], fwd[2]);
|
||||
NumType d = dot(y, y);
|
||||
if (d==0.0) {
|
||||
y = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
y /= csqrt(d);
|
||||
}
|
||||
|
||||
// x is the up vector rotated into the YZ plane. Its angle to the Z
|
||||
// axis is the amount to rotate about the X axis to bring the up
|
||||
// vector to the Z axis.
|
||||
|
||||
LVector2<NumType> x(fwd[1], fwd[0]*y[0]+fwd[2]*y[1]);
|
||||
d = dot(x, x);
|
||||
if (d==0.0) {
|
||||
x = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
x /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now apply both rotations to the forward vector. This will rotate
|
||||
// the forward vector by the same amount we would have had to rotate
|
||||
// the up vector to bring it to the Z axis. If the vectors were
|
||||
// perpendicular, this will put the forward vector somewhere in the
|
||||
// XY plane.
|
||||
|
||||
// z is the projection of the newly rotated fwd vector into the XY
|
||||
// plane. Its angle to the Y axis is the amount to rotate about the
|
||||
// Z axis in order to bring the fwd vector to the Y axis.
|
||||
LVector2<NumType> z(up[0]*y[1] - up[2]*y[0],
|
||||
-up[0]*y[0]*x[0] + up[1]*x[1] - up[2]*y[1]*x[0]);
|
||||
d = dot(z, z);
|
||||
if (d==0.0) {
|
||||
z = LVector2<NumType>(0.0, 1.0);
|
||||
} else {
|
||||
z /= csqrt(d);
|
||||
}
|
||||
|
||||
// Now build the net rotation matrix.
|
||||
if (cs == CS_yup_right) {
|
||||
mat =
|
||||
make_z_mat(z) *
|
||||
make_x_mat(x) *
|
||||
make_y_mat(-y);
|
||||
} else { // cs == CS_yup_left
|
||||
mat =
|
||||
make_z_mat(-z) *
|
||||
make_x_mat(-x) *
|
||||
make_y_mat(-y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The following functions are the non-template functions that are
|
||||
// actually exported.
|
||||
|
||||
void
|
||||
heads_up(LMatrix3f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up, CoordinateSystem cs) {
|
||||
_heads_up(mat, fwd, up, cs);
|
||||
}
|
||||
|
||||
void
|
||||
look_at(LMatrix3f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up, CoordinateSystem cs) {
|
||||
_look_at(mat, fwd, up, cs);
|
||||
}
|
||||
|
||||
void
|
||||
heads_up(LMatrix3d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up, CoordinateSystem cs) {
|
||||
_heads_up(mat, fwd, up, cs);
|
||||
}
|
||||
|
||||
void
|
||||
look_at(LMatrix3d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up, CoordinateSystem cs) {
|
||||
_look_at(mat, fwd, up, cs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,86 @@
|
|||
// Includes
|
||||
///////////////////////////////////////////////////////////////////
|
||||
#include <pandabase.h>
|
||||
#include "cmath.h"
|
||||
#include "coordinateSystem.h"
|
||||
#include "luse.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "look_at.I"
|
||||
#include <luse.h>
|
||||
#include <coordinateSystem.h>
|
||||
|
||||
// These functions return a matrix that rotates between a coordinate
|
||||
// system defined with the given forward and up vectors, and the
|
||||
// standard coordinate system with y-forward and z-up. They differ
|
||||
// only in their behavior when the supplied forward and up vectors are
|
||||
// not perpendicular; in this case, look_at will match the forward
|
||||
// vector precisely, while heads_up will match the up vector
|
||||
// precisely.
|
||||
|
||||
// Since these functions only return a rotation matrix, the
|
||||
// translation component is always zero. There are flavors of these
|
||||
// functions that simply return the upper 3x3 part of the matrix, and
|
||||
// flavors that return the whole 4x4 matrix with a zero bottom row.
|
||||
|
||||
BEGIN_PUBLISH
|
||||
|
||||
// Flavors for float-type arithmetic.
|
||||
|
||||
EXPCL_PANDA void
|
||||
heads_up(LMatrix3f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up = LVector3f::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA void
|
||||
look_at(LMatrix3f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up = LVector3f::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void heads_up(LMatrix3f &mat, const LVector3f &fwd,
|
||||
CoordinateSystem cs);
|
||||
INLINE void look_at(LMatrix3f &mat, const LVector3f &fwd,
|
||||
CoordinateSystem cs);
|
||||
|
||||
|
||||
INLINE void heads_up(LMatrix4f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up = LVector3f::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE void look_at(LMatrix4f &mat, const LVector3f &fwd,
|
||||
const LVector3f &up = LVector3f::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void heads_up(LMatrix4f &mat, const LVector3f &fwd,
|
||||
CoordinateSystem cs);
|
||||
INLINE void look_at(LMatrix4f &mat, const LVector3f &fwd,
|
||||
CoordinateSystem cs);
|
||||
|
||||
|
||||
// Flavors for double-type arithmetic.
|
||||
|
||||
EXPCL_PANDA void
|
||||
heads_up(LMatrix3d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up = LVector3d::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
EXPCL_PANDA void
|
||||
look_at(LMatrix3d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up = LVector3d::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void heads_up(LMatrix3d &mat, const LVector3d &fwd,
|
||||
CoordinateSystem cs);
|
||||
INLINE void look_at(LMatrix3d &mat, const LVector3d &fwd,
|
||||
CoordinateSystem cs);
|
||||
|
||||
|
||||
INLINE void heads_up(LMatrix4d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up = LVector3d::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
INLINE void look_at(LMatrix4d &mat, const LVector3d &fwd,
|
||||
const LVector3d &up = LVector3d::up(),
|
||||
CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE void heads_up(LMatrix4d &mat, const LVector3d &fwd,
|
||||
CoordinateSystem cs);
|
||||
INLINE void look_at(LMatrix4d &mat, const LVector3d &fwd,
|
||||
CoordinateSystem cs);
|
||||
|
||||
END_PUBLISH
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "look_at.I"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,53 +2,14 @@
|
|||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : FLOATNAME(Plane)
|
||||
// Description :
|
||||
// Includes
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "mathutil.h"
|
||||
|
||||
class EXPCL_PANDA FLOATNAME(Plane) {
|
||||
PUBLISHED:
|
||||
INLINE FLOATNAME(Plane)(void);
|
||||
INLINE FLOATNAME(Plane)(const FLOATNAME(Plane) ©);
|
||||
INLINE FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b,
|
||||
const FLOATNAME(LPoint3) &c);
|
||||
INLINE FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal,
|
||||
const FLOATNAME(LPoint3) &point);
|
||||
|
||||
INLINE FLOATNAME(Plane)& operator = (const FLOATNAME(Plane)& copy);
|
||||
|
||||
INLINE FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix3) &mat) const;
|
||||
INLINE FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix4) &mat) const;
|
||||
|
||||
INLINE FLOATNAME(LMatrix4) get_reflection_mat(void) const;
|
||||
|
||||
INLINE FLOATNAME(LVector3) get_normal() const;
|
||||
INLINE FLOATNAME(LPoint3) get_point() const;
|
||||
INLINE FLOATTYPE1 dist_to_plane(const FLOATNAME(LPoint3) &point) const;
|
||||
INLINE bool intersects_line(FLOATNAME(LPoint3) &intersection_point,
|
||||
const FLOATNAME(LPoint3) &p1,
|
||||
const FLOATNAME(LPoint3) &p2) const;
|
||||
INLINE bool intersects_line(FLOATTYPE1 &t,
|
||||
const FLOATNAME(LPoint3) &from,
|
||||
const FLOATNAME(LVector3) &delta) const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
INLINE void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &dest);
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
FLOATTYPE1 _a, _b, _c, _d;
|
||||
};
|
||||
|
||||
INLINE ostream &operator << (ostream &out, const FLOATNAME(Plane) &p) {
|
||||
p.output(out);
|
||||
return out;
|
||||
}
|
||||
#include <nearly_zero.h>
|
||||
#include <cmath.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
|
|
@ -61,9 +22,9 @@ INLINE ostream &operator << (ostream &out, const FLOATNAME(Plane) &p) {
|
|||
// intersect the origin, perpendicular to the Z axis.
|
||||
// It's not clear how useful a default plane is.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane)::
|
||||
FLOATNAME(Plane)(void) {
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType>::
|
||||
Plane(void) {
|
||||
_a = 0.0;
|
||||
_b = 0.0;
|
||||
_c = 1.0;
|
||||
|
|
@ -75,9 +36,9 @@ FLOATNAME(Plane)(void) {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane)::
|
||||
FLOATNAME(Plane)(const FLOATNAME(Plane) ©) :
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType>::
|
||||
Plane(const Plane<NumType> ©) :
|
||||
_a(copy._a),
|
||||
_b(copy._b),
|
||||
_c(copy._c),
|
||||
|
|
@ -93,13 +54,13 @@ FLOATNAME(Plane)(const FLOATNAME(Plane) ©) :
|
|||
// viewed from the end of the normal vector, looking
|
||||
// down).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane)::
|
||||
FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b,
|
||||
const FLOATNAME(LPoint3) &c) {
|
||||
FLOATNAME(LVector3) u = b - a;
|
||||
FLOATNAME(LVector3) v = c - a;
|
||||
FLOATNAME(LVector3) p = normalize(cross(u, v));
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType>::
|
||||
Plane(const LPoint3<NumType> &a, const LPoint3<NumType> &b,
|
||||
const LPoint3<NumType> &c) {
|
||||
LVector3<NumType> u = b - a;
|
||||
LVector3<NumType> v = c - a;
|
||||
LVector3<NumType> p = normalize(cross(u, v));
|
||||
|
||||
_a = p[0];
|
||||
_b = p[1];
|
||||
|
|
@ -113,10 +74,10 @@ FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b,
|
|||
// Description: Constructs a plane given a surface normal vector and
|
||||
// a point within the plane.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane)::
|
||||
FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, const FLOATNAME(LPoint3) &point) {
|
||||
FLOATNAME(LVector3) p = normalize(normal);
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType>::
|
||||
Plane(const LVector3<NumType> &normal, const LPoint3<NumType> &point) {
|
||||
LVector3<NumType> p = normalize(normal);
|
||||
|
||||
_a = p[0];
|
||||
_b = p[1];
|
||||
|
|
@ -129,9 +90,9 @@ FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, const FLOATNAME(LPoint3) &po
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane)& FLOATNAME(Plane)::
|
||||
operator = (const FLOATNAME(Plane)& p) {
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType>& Plane<NumType>::
|
||||
operator = (const Plane<NumType>& p) {
|
||||
_a = p._a;
|
||||
_b = p._b;
|
||||
_c = p._c;
|
||||
|
|
@ -144,12 +105,12 @@ operator = (const FLOATNAME(Plane)& p) {
|
|||
// Access: Public
|
||||
// Description: Transforms the plane by the indicated matrix.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane) FLOATNAME(Plane)::
|
||||
operator * (const FLOATNAME(LMatrix3) &mat) const {
|
||||
FLOATNAME(LVector3) new_normal = get_normal() * mat;
|
||||
FLOATNAME(LPoint3) new_point = get_point() * mat;
|
||||
return FLOATNAME(Plane)(new_normal, new_point);
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType> Plane<NumType>::
|
||||
operator * (const LMatrix3<NumType> &mat) const {
|
||||
LVector3<NumType> new_normal = get_normal() * mat;
|
||||
LPoint3<NumType> new_point = get_point() * mat;
|
||||
return Plane<NumType>(new_normal, new_point);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -157,12 +118,12 @@ operator * (const FLOATNAME(LMatrix3) &mat) const {
|
|||
// Access: Public
|
||||
// Description: Transforms the plane by the indicated matrix.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(Plane) FLOATNAME(Plane)::
|
||||
operator * (const FLOATNAME(LMatrix4) &mat) const {
|
||||
FLOATNAME(LVector3) new_normal = get_normal() * mat;
|
||||
FLOATNAME(LPoint3) new_point = get_point() * mat;
|
||||
return FLOATNAME(Plane)(new_normal, new_point);
|
||||
template<class NumType>
|
||||
INLINE Plane<NumType> Plane<NumType>::
|
||||
operator * (const LMatrix4<NumType> &mat) const {
|
||||
LVector3<NumType> new_normal = get_normal() * mat;
|
||||
LPoint3<NumType> new_point = get_point() * mat;
|
||||
return Plane<NumType>(new_normal, new_point);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -172,16 +133,16 @@ operator * (const FLOATNAME(LMatrix4) &mat) const {
|
|||
// perspective transform defined by the frustum,
|
||||
// accordinate to the indicated coordinate system.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LMatrix4) FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
LMatrix4<NumType> Plane<NumType>::
|
||||
get_reflection_mat(void) const {
|
||||
|
||||
FLOATTYPE1 aa = _a * _a; FLOATTYPE1 ab = _a * _b; FLOATTYPE1 ac = _a * _c;
|
||||
FLOATTYPE1 ad = _a * _d;
|
||||
FLOATTYPE1 bb = _b * _b; FLOATTYPE1 bc = _b * _c; FLOATTYPE1 bd = _b * _d;
|
||||
FLOATTYPE1 cc = _c * _c; FLOATTYPE1 cd = _c * _d;
|
||||
NumType aa = _a * _a; NumType ab = _a * _b; NumType ac = _a * _c;
|
||||
NumType ad = _a * _d;
|
||||
NumType bb = _b * _b; NumType bc = _b * _c; NumType bd = _b * _d;
|
||||
NumType cc = _c * _c; NumType cd = _c * _d;
|
||||
|
||||
return FLOATNAME(LMatrix4)( 1-2*aa, -2*ab, -2*ac, 0,
|
||||
return LMatrix4<NumType>( 1-2*aa, -2*ab, -2*ac, 0,
|
||||
-2*ab, 1-2*bb, -2*bc, 0,
|
||||
-2*ac, -2*bc, 1-2*cc, 0,
|
||||
-2*ad, -2*bd, -2*cd, 1 );
|
||||
|
|
@ -192,10 +153,10 @@ get_reflection_mat(void) const {
|
|||
// Access: Public
|
||||
// Description: Returns the surface normal of the plane.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LVector3) FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
INLINE LVector3<NumType> Plane<NumType>::
|
||||
get_normal() const {
|
||||
return FLOATNAME(LVector3)(_a, _b, _c);
|
||||
return LVector3<NumType>(_a, _b, _c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -205,19 +166,19 @@ get_normal() const {
|
|||
// used along with the normal returned by get_normal()
|
||||
// to reconstruct the plane.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATNAME(LPoint3) FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
LPoint3<NumType> Plane<NumType>::
|
||||
get_point() const {
|
||||
// Choose the denominator based on the largest axis in the normal.
|
||||
if (cabs(_a) >= cabs(_b) && cabs(_a) >= cabs(_c)) {
|
||||
nassertr(_a != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0));
|
||||
return FLOATNAME(LPoint3)(-_d / _a, 0.0, 0.0);
|
||||
nassertr(_a != 0.0, LPoint3<NumType>(0.0, 0.0, 0.0));
|
||||
return LPoint3<NumType>(-_d / _a, 0.0, 0.0);
|
||||
} else if (cabs(_b) >= cabs(_c)) {
|
||||
nassertr(_b != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0));
|
||||
return FLOATNAME(LPoint3)(0.0, -_d / _b, 0.0);
|
||||
nassertr(_b != 0.0, LPoint3<NumType>(0.0, 0.0, 0.0));
|
||||
return LPoint3<NumType>(0.0, -_d / _b, 0.0);
|
||||
} else {
|
||||
nassertr(_c != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0));
|
||||
return FLOATNAME(LPoint3)(0.0, 0.0, -_d / _c);
|
||||
nassertr(_c != 0.0, LPoint3<NumType>(0.0, 0.0, 0.0));
|
||||
return LPoint3<NumType>(0.0, 0.0, -_d / _c);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,9 +192,9 @@ get_point() const {
|
|||
// the plane (on the opposite side from the normal).
|
||||
// It's zero if the point is exactly in the plane.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE FLOATTYPE1 FLOATNAME(Plane)::
|
||||
dist_to_plane(const FLOATNAME(LPoint3) &point) const {
|
||||
template<class NumType>
|
||||
INLINE NumType Plane<NumType>::
|
||||
dist_to_plane(const LPoint3<NumType> &point) const {
|
||||
return (_a * point[0] + _b * point[1] + _c * point[2] + _d);
|
||||
}
|
||||
|
||||
|
|
@ -247,12 +208,12 @@ dist_to_plane(const FLOATNAME(LPoint3) &point) const {
|
|||
// bearing on the intersection test. If true, sets
|
||||
// intersection_point to the point of intersection.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(Plane)::
|
||||
intersects_line(FLOATNAME(LPoint3) &intersection_point,
|
||||
const FLOATNAME(LPoint3) &p1,
|
||||
const FLOATNAME(LPoint3) &p2) const {
|
||||
FLOATTYPE1 t;
|
||||
template<class NumType>
|
||||
INLINE bool Plane<NumType>::
|
||||
intersects_line(LPoint3<NumType> &intersection_point,
|
||||
const LPoint3<NumType> &p1,
|
||||
const LPoint3<NumType> &p2) const {
|
||||
NumType t;
|
||||
if (!intersects_line(t, p1, p2 - p1)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -277,12 +238,12 @@ intersects_line(FLOATNAME(LPoint3) &intersection_point,
|
|||
// point from, and t == 1.0 implies at point from +
|
||||
// delta, with other values of t accordingly.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE bool FLOATNAME(Plane)::
|
||||
intersects_line(FLOATTYPE1 &t,
|
||||
const FLOATNAME(LPoint3) &from,
|
||||
const FLOATNAME(LVector3) &delta) const {
|
||||
FLOATTYPE1 denom = dot(get_normal(), delta);
|
||||
template<class NumType>
|
||||
INLINE bool Plane<NumType>::
|
||||
intersects_line(NumType &t,
|
||||
const LPoint3<NumType> &from,
|
||||
const LVector3<NumType> &delta) const {
|
||||
NumType denom = dot(get_normal(), delta);
|
||||
if (IS_NEARLY_ZERO(denom)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -296,8 +257,8 @@ intersects_line(FLOATTYPE1 &t,
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
void Plane<NumType>::
|
||||
output(ostream &out) const {
|
||||
out << "Plane(" << _a << " " << _b << " " << _c << " " << _d << ")";
|
||||
}
|
||||
|
|
@ -307,8 +268,8 @@ output(ostream &out) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
void Plane<NumType>::
|
||||
write(ostream &out, int indent_level) const {
|
||||
indent(out, indent_level) << *this << "\n";
|
||||
}
|
||||
|
|
@ -318,8 +279,8 @@ write(ostream &out, int indent_level) const {
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE void FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
void Plane<NumType>::
|
||||
write_datagram(Datagram &dest)
|
||||
{
|
||||
dest.add_float32(_a);
|
||||
|
|
@ -333,9 +294,8 @@ write_datagram(Datagram &dest)
|
|||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
INLINE void FLOATNAME(Plane)::
|
||||
template<class NumType>
|
||||
void Plane<NumType>::
|
||||
read_datagram(DatagramIterator &source)
|
||||
{
|
||||
_a = source.get_float32();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,2 @@
|
|||
forcetype Planef
|
||||
renametype Planef Planef
|
||||
forcetype Planed
|
||||
renametype Planed Planed
|
||||
forcetype Plane<float>
|
||||
forcetype Plane<double>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Filename: FLOATNAME(Plane).h
|
||||
// Filename: plane.h
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
#ifndef Plane_H
|
||||
#define Plane_H
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Includes
|
||||
|
|
@ -13,17 +13,76 @@
|
|||
|
||||
#include <luse.h>
|
||||
#include <indent.h>
|
||||
#include <nearly_zero.h>
|
||||
#include <cmath.h>
|
||||
#include "mathutil.h"
|
||||
|
||||
class Datagram;
|
||||
class DatagramIterator;
|
||||
|
||||
#include "fltnames.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Defines
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : Plane
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
class Plane {
|
||||
PUBLISHED:
|
||||
INLINE Plane(void);
|
||||
INLINE Plane(const Plane ©);
|
||||
INLINE Plane(const LPoint3<NumType> &a, const LPoint3<NumType> &b,
|
||||
const LPoint3<NumType> &c);
|
||||
INLINE Plane(const LVector3<NumType> &normal,
|
||||
const LPoint3<NumType> &point);
|
||||
|
||||
INLINE Plane& operator = (const Plane& copy);
|
||||
|
||||
INLINE Plane operator * (const LMatrix3<NumType> &mat) const;
|
||||
INLINE Plane operator * (const LMatrix4<NumType> &mat) const;
|
||||
|
||||
|
||||
LMatrix4<NumType>
|
||||
get_reflection_mat(void) const;
|
||||
|
||||
INLINE LVector3<NumType> get_normal() const;
|
||||
LPoint3<NumType> get_point() const;
|
||||
INLINE NumType dist_to_plane(const LPoint3<NumType> &point) const;
|
||||
INLINE bool intersects_line(LPoint3<NumType> &intersection_point,
|
||||
const LPoint3<NumType> &p1,
|
||||
const LPoint3<NumType> &p2) const;
|
||||
INLINE bool intersects_line(NumType &t,
|
||||
const LPoint3<NumType> &from,
|
||||
const LVector3<NumType> &delta) const;
|
||||
|
||||
void output(ostream &out) const;
|
||||
void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
public:
|
||||
INLINE void write_datagram(Datagram &dest);
|
||||
INLINE void read_datagram(DatagramIterator &source);
|
||||
|
||||
public:
|
||||
NumType _a, _b, _c, _d;
|
||||
};
|
||||
|
||||
template<class NumType>
|
||||
INLINE ostream &operator << (ostream &out, const Plane<NumType> &p) {
|
||||
p.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, Plane<float>)
|
||||
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, Plane<double>)
|
||||
|
||||
typedef Plane<float> Planef;
|
||||
typedef Plane<double> Planed;
|
||||
|
||||
#include "plane.I"
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "plane.I"
|
||||
|
||||
// Tell GCC that we'll take care of the instantiation explicitly here.
|
||||
#ifdef __GNUC__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,11 +4,89 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <pandabase.h>
|
||||
#include <math.h>
|
||||
#include "rotate_to.h"
|
||||
#include "luse.h"
|
||||
|
||||
#include "fltnames.I"
|
||||
#include "rotate_to_src.I"
|
||||
#include <math.h>
|
||||
|
||||
#include "dblnames.I"
|
||||
#include "rotate_to_src.I"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: _rotate_to
|
||||
// Description: Computes the matrix necessary to rotate vector a onto
|
||||
// vector b. It is assumed that both vectors are
|
||||
// normalized.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class NumType>
|
||||
static void
|
||||
_rotate_to(LMatrix3<NumType> &mat,
|
||||
const LVector3<NumType> &a, const LVector3<NumType> &b) {
|
||||
NumType cos_theta = a.dot(b);
|
||||
|
||||
LVector3<NumType> axis = a.cross(b);
|
||||
NumType sin_theta = length(axis);
|
||||
|
||||
// Check for collinear vectors
|
||||
if (sin_theta < 0.0001) {
|
||||
// The vectors are collinear.
|
||||
|
||||
if (cos_theta < 0.0) {
|
||||
// The vectors are opposite; choose an arbitrary axis
|
||||
// perpendicular to a.
|
||||
LVector3<NumType> absa(fabs(a[0]), fabs(a[1]), fabs(a[2]));
|
||||
LVector3<NumType> lca(0., 0., 0.);
|
||||
lca[absa[0]<=absa[1] ? absa[0]<=absa[2] ? 0 : 2
|
||||
: absa[1]<=absa[2] ? 1 : 2] = 1.0;
|
||||
|
||||
axis = normalize(a.cross(lca));
|
||||
} else {
|
||||
mat = LMatrix3<NumType>::ident_mat();
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
// The vectors are not collinear; determine the best axis.
|
||||
axis /= sin_theta;
|
||||
}
|
||||
|
||||
NumType x = axis[0];
|
||||
NumType y = axis[1];
|
||||
NumType z = axis[2];
|
||||
|
||||
NumType t = 1.0 - cos_theta;
|
||||
|
||||
mat(0, 0) = t * x * x + cos_theta;
|
||||
mat(0, 1) = t * x * y + sin_theta * z;
|
||||
mat(0, 2) = t * x * z - sin_theta * y;
|
||||
|
||||
mat(1, 0) = t * y * x - sin_theta * z;
|
||||
mat(1, 1) = t * y * y + cos_theta;
|
||||
mat(1, 2) = t * y * z + sin_theta * x;
|
||||
|
||||
mat(2, 0) = t * z * x + sin_theta * y;
|
||||
mat(2, 1) = t * z * y - sin_theta * x;
|
||||
mat(2, 2) = t * z * z + cos_theta;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
rotate_to(LMatrix3f &mat, const LVector3f &a, const LVector3f &b) {
|
||||
_rotate_to(mat, a, b);
|
||||
}
|
||||
|
||||
void
|
||||
rotate_to(LMatrix3d &mat, const LVector3d &a, const LVector3d &b) {
|
||||
_rotate_to(mat, a, b);
|
||||
}
|
||||
|
||||
void
|
||||
rotate_to(LMatrix4f &mat, const LVector3f &a, const LVector3f &b) {
|
||||
LMatrix3f m3;
|
||||
_rotate_to(m3, a, b);
|
||||
mat = LMatrix4f(m3);
|
||||
}
|
||||
|
||||
void
|
||||
rotate_to(LMatrix4d &mat, const LVector3d &a, const LVector3d &b) {
|
||||
LMatrix3d m3;
|
||||
_rotate_to(m3, a, b);
|
||||
mat = LMatrix4d(m3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <math.h>
|
||||
#include <pandabase.h>
|
||||
|
||||
#include "lmatrix.h"
|
||||
#include "luse.h"
|
||||
|
||||
BEGIN_PUBLISH
|
||||
|
|
|
|||
Loading…
Reference in New Issue