*** empty log message ***

This commit is contained in:
David Rose 2001-04-04 21:40:58 +00:00
parent 897fdfb0c6
commit ee8db5b5b5
189 changed files with 2300 additions and 16692 deletions

View File

@ -1,61 +0,0 @@
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m
#begin lib_target
#define TARGET linmath
#define LOCAL_LIBS \
putil
#define SOURCES \
cmath.I cmath.h compose_matrix.I compose_matrix.cxx compose_matrix.h \
config_linmath.cxx config_linmath.h coordinateSystem.cxx \
coordinateSystem.h deg_2_rad.h \
ioPtaDatagramLinMath.I ioPtaDatagramLinMath.cxx \
ioPtaDatagramLinMath.h lmatrix.cxx lmatrix.h \
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 \
pta_Vertexf.cxx pta_Vertexf.h vector_Colorf.cxx vector_Colorf.h \
vector_LPoint2f.cxx vector_LPoint2f.h \
vector_LVecBase3f.cxx vector_LVecBase3f.h \
vector_Normalf.cxx \
vector_Normalf.h vector_Vertexf.cxx vector_Vertexf.h
#define INSTALL_HEADERS \
cmath.I cmath.h compose_matrix.I compose_matrix.h config_linmath.h \
coordinateSystem.h deg_2_rad.h ioPtaDatagramLinMath.I \
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 \
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.h nearly_zero.h pta_Colorf.h \
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
#define IGATESCAN all
#end lib_target
#begin test_bin_target
#define TARGET test_math
#define LOCAL_LIBS \
linmath
#define OTHER_LIBS $[OTHER_LIBS] pystub
#define SOURCES \
test_math.cxx
#end test_bin_target

View File

@ -1,49 +0,0 @@
// Filename: cast_to_double.I
// Created by: drose (24May00)
//
////////////////////////////////////////////////////////////////////
INLINE LVecBase2<double> cast_to_double(const LVecBase2<float> &source) {
return LCAST(double, source);
}
INLINE LVecBase3<double> cast_to_double(const LVecBase3<float> &source) {
return LCAST(double, source);
}
INLINE LVecBase4<double> cast_to_double(const LVecBase4<float> &source) {
return LCAST(double, source);
}
INLINE LVector2<double> cast_to_double(const LVector2<float> &source) {
return LCAST(double, source);
}
INLINE LVector3<double> cast_to_double(const LVector3<float> &source) {
return LCAST(double, source);
}
INLINE LVector4<double> cast_to_double(const LVector4<float> &source) {
return LCAST(double, source);
}
INLINE LPoint2<double> cast_to_double(const LPoint2<float> &source) {
return LCAST(double, source);
}
INLINE LPoint3<double> cast_to_double(const LPoint3<float> &source) {
return LCAST(double, source);
}
INLINE LPoint4<double> cast_to_double(const LPoint4<float> &source) {
return LCAST(double, source);
}
INLINE LMatrix3<double> cast_to_double(const LMatrix3<float> &source) {
return LCAST(double, source);
}
INLINE LMatrix4<double> cast_to_double(const LMatrix4<float> &source) {
return LCAST(double, source);
}

View File

@ -1,32 +0,0 @@
// Filename: cast_to_double.h
// Created by: drose (24May00)
//
////////////////////////////////////////////////////////////////////
#ifndef CAST_TO_DOUBLE_H
#define CAST_TO_DOUBLE_H
#include "luse.h"
// The functions in this file are primarily for the benefit of a
// higher-level language that can't take advantage of the LCAST macro.
// These are a number of functions that convert our various math
// objects between floats and doubles.
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"
#endif

View File

@ -1,49 +0,0 @@
// Filename: cast_to_float.I
// Created by: drose (24May00)
//
////////////////////////////////////////////////////////////////////
INLINE LVecBase2<float> cast_to_float(const LVecBase2<double> &source) {
return LCAST(float, source);
}
INLINE LVecBase3<float> cast_to_float(const LVecBase3<double> &source) {
return LCAST(float, source);
}
INLINE LVecBase4<float> cast_to_float(const LVecBase4<double> &source) {
return LCAST(float, source);
}
INLINE LVector2<float> cast_to_float(const LVector2<double> &source) {
return LCAST(float, source);
}
INLINE LVector3<float> cast_to_float(const LVector3<double> &source) {
return LCAST(float, source);
}
INLINE LVector4<float> cast_to_float(const LVector4<double> &source) {
return LCAST(float, source);
}
INLINE LPoint2<float> cast_to_float(const LPoint2<double> &source) {
return LCAST(float, source);
}
INLINE LPoint3<float> cast_to_float(const LPoint3<double> &source) {
return LCAST(float, source);
}
INLINE LPoint4<float> cast_to_float(const LPoint4<double> &source) {
return LCAST(float, source);
}
INLINE LMatrix3<float> cast_to_float(const LMatrix3<double> &source) {
return LCAST(float, source);
}
INLINE LMatrix4<float> cast_to_float(const LMatrix4<double> &source) {
return LCAST(float, source);
}

View File

@ -1,32 +0,0 @@
// Filename: cast_to_float.h
// Created by: drose (24May00)
//
////////////////////////////////////////////////////////////////////
#ifndef CAST_TO_FLOAT_H
#define CAST_TO_FLOAT_H
#include "luse.h"
// The functions in this file are primarily for the benefit of a
// higher-level language that can't take advantage of the LCAST macro.
// These are a number of functions that convert our various math
// objects between floats and doubles.
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"
#endif

View File

@ -1,106 +0,0 @@
// Filename: cmath.I
// Created by: drose (19May00)
//
////////////////////////////////////////////////////////////////////
//Windows has isnan in a different place and with a different name
//than everyone else. Sheesh
#ifdef _WIN32
#include <float.h>
#endif
INLINE float csqrt(float v) {
return sqrtf(v);
}
INLINE float csin(float v) {
return sinf(v);
}
INLINE float ccos(float v) {
return cosf(v);
}
INLINE void
sincosf(float v, float *pSinResult, float *pCosResult) {
// MS VC defines _M_IX86 for x86. gcc should define _X86_
#if defined(_M_IX86) || defined(_X86_)
//#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb
__asm {
mov eax, pSinResult
mov edx, pCosResult
fld v
fsincos
fstp DWORD ptr [edx]
fstp DWORD ptr [eax]
}
#else //!_X86_
*pSinResult = sinf(v);
*pCosResult = cosf(v);
#endif //!_X86_
}
INLINE void
sincos(double v, double *pSinResult, double *pCosResult) {
#if defined(_M_IX86) || defined(_X86_)
//#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb
__asm {
mov eax, pSinResult
mov edx, pCosResult
fld v
fsincos
fstp QWORD ptr [edx]
fstp QWORD ptr [eax]
}
#else //!_X86_
*pSinResult = sin(v);
*pCosResult = cos(v);
#endif //!_X86_
}
INLINE void csincos(float v,float *pSinResult, float *pCosResult) {
sincosf(v,pSinResult,pCosResult);
}
INLINE void csincos(double v,double *pSinResult, double *pCosResult) {
sincos(v,pSinResult,pCosResult);
}
INLINE float cabs(float v) {
return fabs(v);
}
INLINE float catan2(float y, float x) {
return atan2f(y, x);
}
INLINE double csqrt(double v) {
return sqrt(v);
}
INLINE double csin(double v) {
return sin(v);
}
INLINE double ccos(double v) {
return cos(v);
}
INLINE double cabs(double v) {
return fabs(v);
}
INLINE double catan2(double y, double x) {
return atan2(y, x);
}
INLINE bool cnan(double v) {
#ifndef _WIN32
return (isnan(v) != 0);
#else
return (_isnan(v) != 0);
#endif
}

View File

@ -1,40 +0,0 @@
// Filename: cmath.h
// Created by: drose (19May00)
//
////////////////////////////////////////////////////////////////////
#ifndef CMATH_H
#define CMATH_H
#include <pandabase.h>
#include <math.h>
// This file declares a number of C++-style overloading wrappers
// around the standard math library functions, so we can use
// overloading to differentiate on type instead of having to know
// explicitly whether we need to call, for instance, sqrtf() or
// sqrt().
INLINE float csqrt(float v);
INLINE float csin(float v);
INLINE float ccos(float v);
INLINE void csincos(float v, float *pSinResult, float *pCosResult); // does both at once (faster on x86)
INLINE float cabs(float v);
INLINE float catan2(float y, float x);
INLINE double csqrt(double v);
INLINE double csin(double v);
INLINE double ccos(double v);
INLINE double cabs(double v);
INLINE double catan2(double y, double x);
INLINE void csincos(double v, double *pSinResult, double *pCosResult); // does both at once (faster on x86)
// Returns true if the number is nan, false if it's a genuine number
// or infinity.
INLINE bool cnan(double v);
#include "cmath.I"
#endif

View File

@ -1,77 +0,0 @@
// Filename: compose_matrix.I
// Created by: drose (21Feb99)
//
////////////////////////////////////////////////////////////////////
INLINE void
compose_matrix(LMatrix4f &mat,
const float components[9],
CoordinateSystem cs) {
LVector3f scale(components[0],
components[1],
components[2]);
LVector3f hpr(components[3],
components[4],
components[5]);
LVector3f translate(components[6],
components[7],
components[8]);
compose_matrix(mat, scale, hpr, translate, cs);
}
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) {
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);
}
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;
}

View File

@ -1,708 +0,0 @@
// Filename: compose_matrix.cxx
// Created by: drose (27Jan99)
//
////////////////////////////////////////////////////////////////////
#include "compose_matrix.h"
#include "deg_2_rad.h"
#include "config_linmath.h"
#include <math.h>
////////////////////////////////////////////////////////////////////
// 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);
}

View File

@ -1,124 +0,0 @@
// Filename: compose_matrix.h
// Created by: drose (27Jan99)
//
////////////////////////////////////////////////////////////////////
#ifndef COMPOSE_MATRIX_H
#define COMPOSE_MATRIX_H
////////////////////////////////////////////////////////////////////
//
// compose_matrix(), decompose_matrix()
//
// These two functions build and/or extract an affine matrix into
// its constituent parts: scale, hpr, and translate.
//
// The functions here come in two flavors, for doubles and floats.
// They're actually implemented as template functions so could be
// instantiated on any numeric type, but I only bothered to
// instantiate and expose these two. It saves on some cross-library
// pre-linking stuff to have all the templates be hidden.
//
// There are also two additional flavors for 3x3 matrices. These are
// treated as the upper 3x3 part of a general 4x4 matrix, and so can
// only represent rotations and scales.
//
////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include "lmatrix.h"
#include "luse.h"
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 "compose_matrix.I"
#endif

View File

@ -3,6 +3,23 @@
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: compose_matrix
// Description: Computes the 3x3 matrix from scale and rotation.
////////////////////////////////////////////////////////////////////
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: unwind_yup_rotation
// Description: Extracts the rotation about the x, y, and z axes from
@ -12,7 +29,6 @@
// This function assumes the matrix is stored in a
// right-handed Y-up coordinate system.
////////////////////////////////////////////////////////////////////
static void
unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
typedef FLOATNAME(LMatrix3) Matrix;
@ -28,7 +44,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
xy = normalize(xy);
// Compute the rotation about the +Z (back) axis. This is roll.
FLOATTYPE1 roll = rad_2_deg(atan2(xy[1], xy[0]));
FLOATTYPE roll = rad_2_deg(atan2(xy[1], xy[0]));
// Unwind the roll from the axes, and continue.
Matrix rot_z;
@ -45,7 +61,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Compute the rotation about the +Y (up) axis. This is yaw, or
// "heading".
FLOATTYPE1 heading = rad_2_deg(-atan2(xz[1], xz[0]));
FLOATTYPE heading = rad_2_deg(-atan2(xz[1], xz[0]));
// Unwind the heading, and continue.
Matrix rot_y;
@ -61,7 +77,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
yz = normalize(yz);
// Compute the rotation about the +X (right) axis. This is pitch.
FLOATTYPE1 pitch = rad_2_deg(-atan2(yz[0], yz[1]));
FLOATTYPE pitch = rad_2_deg(-atan2(yz[0], yz[1]));
// Unwind the pitch.
Matrix rot_x;
@ -93,10 +109,9 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// This function assumes the matrix is stored in a
// right-handed Y-up coordinate system.
////////////////////////////////////////////////////////////////////
static void
unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
FLOATTYPE1 roll) {
FLOATTYPE roll) {
typedef FLOATNAME(LMatrix3) Matrix;
// Extract the axes from the matrix.
@ -120,7 +135,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// Compute the rotation about the +Y (up) axis. This is yaw, or
// "heading".
FLOATTYPE1 heading = rad_2_deg(-atan2(xz[1], xz[0]));
FLOATTYPE heading = rad_2_deg(-atan2(xz[1], xz[0]));
// Unwind the heading, and continue.
Matrix rot_y;
@ -136,7 +151,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
yz = normalize(yz);
// Compute the rotation about the +X (right) axis. This is pitch.
FLOATTYPE1 pitch = rad_2_deg(-atan2(yz[0], yz[1]));
FLOATTYPE pitch = rad_2_deg(-atan2(yz[0], yz[1]));
// Unwind the pitch.
Matrix rot_x;
@ -167,7 +182,6 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// This function assumes the matrix is stored in a
// right-handed Z-up coordinate system.
////////////////////////////////////////////////////////////////////
static void
unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
typedef FLOATNAME(LMatrix3) Matrix;
@ -184,7 +198,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
xz = normalize(xz);
// Compute the rotation about the -Y (back) axis. This is roll.
FLOATTYPE1 roll = rad_2_deg(atan2(xz[1], xz[0]));
FLOATTYPE roll = rad_2_deg(atan2(xz[1], xz[0]));
if (y[1] < 0.0) {
if (roll < 0.0) {
@ -209,7 +223,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Compute the rotation about the +Z (up) axis. This is yaw, or
// "heading".
FLOATTYPE1 heading = rad_2_deg(atan2(xy[1], xy[0]));
FLOATTYPE heading = rad_2_deg(atan2(xy[1], xy[0]));
// Unwind the heading, and continue.
Matrix rot_z;
@ -225,7 +239,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
yz = normalize(yz);
// Compute the rotation about the +X (right) axis. This is pitch.
FLOATTYPE1 pitch = rad_2_deg(atan2(yz[1], yz[0]));
FLOATTYPE pitch = rad_2_deg(atan2(yz[1], yz[0]));
// Unwind the pitch.
Matrix rot_x;
@ -257,10 +271,9 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// This function assumes the matrix is stored in a
// right-handed Z-up coordinate system.
////////////////////////////////////////////////////////////////////
static void
unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
FLOATTYPE1 roll) {
FLOATTYPE roll) {
typedef FLOATNAME(LMatrix3) Matrix;
// Extract the axes from the matrix.
@ -284,7 +297,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// Compute the rotation about the +Z (up) axis. This is yaw, or
// "heading".
FLOATTYPE1 heading = rad_2_deg(atan2(xy[1], xy[0]));
FLOATTYPE heading = rad_2_deg(atan2(xy[1], xy[0]));
// Unwind the heading, and continue.
Matrix rot_z;
@ -300,7 +313,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
yz = normalize(yz);
// Compute the rotation about the +X (right) axis. This is pitch.
FLOATTYPE1 pitch = rad_2_deg(atan2(yz[1], yz[0]));
FLOATTYPE pitch = rad_2_deg(atan2(yz[1], yz[0]));
// Unwind the pitch.
Matrix rot_x;
@ -329,12 +342,11 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// the matrix, or false if there is also a shear
// component or if the matrix is not affine.
////////////////////////////////////////////////////////////////////
static bool
_decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
CoordinateSystem cs) {
bool
decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
CoordinateSystem cs) {
if (cs == CS_default) {
cs = default_coordinate_system;
}
@ -426,13 +438,12 @@ _decompose_matrix(const FLOATNAME(LMatrix3) &mat,
// by examining the matrix; this helps alleviate roll
// instability due to roundoff errors or gimbal lock.
////////////////////////////////////////////////////////////////////
static bool
_decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATTYPE1 roll,
CoordinateSystem cs) {
bool
decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATTYPE roll,
CoordinateSystem cs) {
if (cs == CS_default) {
cs = default_coordinate_system;
}
@ -510,107 +521,3 @@ _decompose_matrix(const FLOATNAME(LMatrix3) &mat,
return !shear;
}
INLINE bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATTYPE1 components[9],
CoordinateSystem cs) {
FLOATNAME(LVector3) 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;
}
////////////////////////////////////////////////////////////////////
// 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.
////////////////////////////////////////////////////////////////////
INLINE bool
_decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &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.
////////////////////////////////////////////////////////////////////
INLINE bool
_decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &translate,
FLOATTYPE1 roll,
CoordinateSystem cs) {
// Get the translation first.
translate = mat.get_row3(3);
return _decompose_matrix(mat.get_upper_3(), scale, hpr, roll, cs);
}
bool
decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
CoordinateSystem cs) {
return _decompose_matrix(mat, scale, hpr, cs);
}
bool
decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
float roll,
CoordinateSystem cs) {
return _decompose_matrix(mat, scale, hpr, roll, cs);
}
bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &translate,
CoordinateSystem cs) {
return _decompose_matrix(mat, scale, hpr, translate, cs);
}
bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &translate,
float roll,
CoordinateSystem cs) {
return _decompose_matrix(mat, scale, hpr, translate, roll, cs);
}

View File

@ -0,0 +1,60 @@
////////////////////////////////////////////////////////////////////
// Filename: compose_matrix_src.h
// Created by: drose (21Feb99)
//
////////////////////////////////////////////////////////////////////
BEGIN_PUBLISH
EXPCL_PANDA void
compose_matrix(FLOATNAME(LMatrix3) &mat,
const FLOATNAME(LVecBase3) &scale,
const FLOATNAME(LVecBase3) &hpr,
CoordinateSystem cs = CS_default);
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 FLOATTYPE 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,
FLOATTYPE roll,
CoordinateSystem cs = CS_default);
INLINE bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &translate,
CoordinateSystem cs = CS_default);
INLINE bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &translate,
FLOATTYPE roll,
CoordinateSystem cs = CS_default);
INLINE bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATTYPE components[9],
CoordinateSystem CS = CS_default);
END_PUBLISH
#include "compose_matrix_src.I"

View File

@ -1,57 +0,0 @@
// Filename: config_linmath.cxx
// Created by: drose (23Feb00)
//
////////////////////////////////////////////////////////////////////
#include "config_linmath.h"
#include "luse.h"
#include "coordinateSystem.h"
#include <dconfig.h>
Configure(config_linmath);
NotifyCategoryDef(linmath, "");
ConfigureFn(config_linmath) {
LVecBase2f::init_type();
LVecBase3f::init_type();
LVecBase4f::init_type();
LVector2f::init_type();
LVector3f::init_type();
LVector4f::init_type();
LPoint2f::init_type();
LPoint3f::init_type();
LPoint4f::init_type();
LMatrix3f::init_type();
LMatrix4f::init_type();
LVecBase2d::init_type();
LVecBase3d::init_type();
LVecBase4d::init_type();
LVector2d::init_type();
LVector3d::init_type();
LVector4d::init_type();
LPoint2d::init_type();
LPoint3d::init_type();
LPoint4d::init_type();
LMatrix3d::init_type();
LMatrix4d::init_type();
LQuaternionf::init_type();
LRotationf::init_type();
LOrientationf::init_type();
LQuaterniond::init_type();
LRotationd::init_type();
LOrientationd::init_type();
string csstr = config_linmath.GetString("coordinate-system", "default");
CoordinateSystem cs = parse_coordinate_system_string(csstr);
if (cs == CS_invalid) {
linmath_cat.error()
<< "Unexpected coordinate-system string: " << csstr << "\n";
cs = CS_default;
}
default_coordinate_system = (cs == CS_default) ? CS_zup_right : cs;
}

View File

@ -1,14 +0,0 @@
// Filename: config_linmath.h
// Created by: drose (23Feb00)
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_LINMATH_H
#define CONFIG_LINMATH_H
#include <pandabase.h>
#include <notifyCategoryProxy.h>
NotifyCategoryDecl(linmath, EXPCL_PANDA, EXPTP_PANDA);
#endif

View File

@ -1,96 +0,0 @@
// Filename: coordinateSystem.cxx
// Created by: drose (24Sep99)
//
////////////////////////////////////////////////////////////////////
#include "coordinateSystem.h"
#include "config_linmath.h"
#include <dconfig.h>
#include <notify.h>
#include <ctype.h>
#include <string>
CoordinateSystem default_coordinate_system;
CoordinateSystem
parse_coordinate_system_string(const string &str) {
// First, make sure the string is lowercase before we compare it, so
// we'll be case-insensitive.
string lstr = str;
for (string::iterator si = lstr.begin();
si != lstr.end();
++si) {
(*si) = tolower(*si);
}
if (lstr == "default") {
return CS_default;
} else if (lstr == "z-up" || lstr == "z-up-right") {
return CS_zup_right;
} else if (lstr == "y-up" || lstr == "y-up-right") {
return CS_yup_right;
} else if (lstr == "z-up-left") {
return CS_zup_left;
} else if (lstr == "y-up-left") {
return CS_yup_left;
}
return CS_invalid;
}
bool
is_right_handed(CoordinateSystem cs) {
if (cs == CS_default) {
cs = default_coordinate_system;
}
switch (cs) {
case CS_zup_right:
case CS_yup_right:
return true;
case CS_zup_left:
case CS_yup_left:
return false;
default:
linmath_cat.error()
<< "Invalid coordinate system value: " << (int)cs << "\n";
nassertr(false, false);
return false;
}
}
ostream &
operator << (ostream &out, CoordinateSystem cs) {
switch (cs) {
case CS_default:
return out << "default";
case CS_zup_right:
return out << "zup_right";
case CS_yup_right:
return out << "yup_right";
case CS_zup_left:
return out << "zup_left";
case CS_yup_left:
return out << "yup_left";
case CS_invalid:
return out << "invalid";
}
linmath_cat.error()
<< "Invalid coordinate_system value: " << (int)cs << "\n";
nassertr(false, out);
return out;
}

View File

@ -1,46 +0,0 @@
// Filename: coordinateSystem.h
// Created by: drose (24Sep99)
//
////////////////////////////////////////////////////////////////////
#ifndef COORDINATESYSTEM_H
#define COORDINATESYSTEM_H
#include <pandabase.h>
#include <typedef.h>
#include <string>
BEGIN_PUBLISH
enum CoordinateSystem {
// The CS_default entry does not refer to a particular coordinate
// system, but rather to the value stored in
// default_coordinate_system, which in turn is loaded from the
// Configrc variable "coordinate-system".
CS_default,
CS_zup_right,
CS_yup_right,
CS_zup_left,
CS_yup_left,
// CS_invalid is not a coordinate system at all. It can be used in
// user-input processing code to indicate a contradictory coordinate
// system request.
CS_invalid,
};
END_PUBLISH
extern CoordinateSystem EXPCL_PANDA default_coordinate_system;
CoordinateSystem EXPCL_PANDA parse_coordinate_system_string(const string &str);
bool EXPCL_PANDA is_right_handed(CoordinateSystem cs = CS_default);
ostream EXPCL_PANDA &operator << (ostream &out, CoordinateSystem cs);
#endif

View File

@ -0,0 +1,22 @@
// Filename: dbl2fltnames.h
// Created by: drose (04Apr01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//
// This file is used particularly by lcast_to.h and lcast_to.cxx to
// define functions that convert from type double to type float.
//
////////////////////////////////////////////////////////////////////
#include "fltnames.h"
#undef FLOATTYPE2
#undef FLOATNAME2
#undef FLOATTOKEN2
#define FLOATTYPE2 double
#define FLOATNAME2(ARG) ARG##d
#define FLOATTOKEN2 'd'

View File

@ -1,9 +0,0 @@
#undef FLOATTYPE1
#undef FLOATTYPE2
#undef FLOATNAME
#undef FLOATNAME2
#define FLOATTYPE1 double
#define FLOATTYPE2 float
#define FLOATNAME(ARG) ARG##d
#define FLOATNAME2(ARG) ARG##f

View File

@ -0,0 +1,33 @@
// Filename: fltnames.h
// Created by: cxgeorge (04Apr01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//
// This file is used throughout this directory, in conjunction with
// dblnames.h, to implement a poor man's template of the linmath
// objects on numeric type. The idea is to #include either fltnames.h
// or dblnames.h (or, in theory, intnames.h or any other numeric type
// we wanted to implement) and then to include the various *_src.h
// and/or *_src.cxx files that actually define the linmath objects.
//
// We do this instead of using actual templates to avoid some of the
// inherent problems with templates: compiler complexity and
// distributed code bloat, for instance; plus it allows us to
// implement #if-based specialization on numeric type for compilers
// (like VC++) that don't completely support template specialization.
// That and the fact that VC++ seems to have a particularly bad time
// with templates in general.
//
////////////////////////////////////////////////////////////////////
#undef FLOATTYPE
#undef FLOATNAME
#undef FLOATTOKEN
#define FLOATTYPE double
#define FLOATNAME(ARG) ARG##d
#define FLOATTOKEN 'd'

View File

@ -1,19 +0,0 @@
// Filename: deg_2_rad.h
// Created by: drose (29Sep99)
//
////////////////////////////////////////////////////////////////////
#ifndef DEG_2_RAD_H
#define DEG_2_RAD_H
#include <pandabase.h>
#include "mathNumbers.h"
BEGIN_PUBLISH
INLINE double deg_2_rad( double f ) { return f * MathNumbers::pi / 180.0; }
INLINE double rad_2_deg( double f ) { return f * 180.0 / MathNumbers::pi; }
END_PUBLISH
#endif

View File

@ -0,0 +1,22 @@
// Filename: flt2dblnames.h
// Created by: drose (04Apr01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//
// This file is used particularly by lcast_to.h and lcast_to.cxx to
// define functions that convert from type float to type double.
//
////////////////////////////////////////////////////////////////////
#include "dblnames.h"
#undef FLOATTYPE2
#undef FLOATNAME2
#undef FLOATTOKEN2
#define FLOATTYPE2 float
#define FLOATNAME2(ARG) ARG##f
#define FLOATTOKEN2 'f'

View File

@ -1,9 +0,0 @@
#undef FLOATTYPE1
#undef FLOATTYPE2
#undef FLOATNAME
#undef FLOATNAME2
#define FLOATTYPE1 float
#define FLOATTYPE2 double
#define FLOATNAME(ARG) ARG##f
#define FLOATNAME2(ARG) ARG##d

View File

@ -0,0 +1,33 @@
// Filename: fltnames.h
// Created by: cxgeorge (04Apr01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//
// This file is used throughout this directory, in conjunction with
// dblnames.h, to implement a poor man's template of the linmath
// objects on numeric type. The idea is to #include either fltnames.h
// or dblnames.h (or, in theory, intnames.h or any other numeric type
// we wanted to implement) and then to include the various *_src.h
// and/or *_src.cxx files that actually define the linmath objects.
//
// We do this instead of using actual templates to avoid some of the
// inherent problems with templates: compiler complexity and
// distributed code bloat, for instance; plus it allows us to
// implement #if-based specialization on numeric type for compilers
// (like VC++) that don't completely support template specialization.
// That and the fact that VC++ seems to have a particularly bad time
// with templates in general.
//
////////////////////////////////////////////////////////////////////
#undef FLOATTYPE
#undef FLOATNAME
#undef FLOATTOKEN
#define FLOATTYPE float
#define FLOATNAME(ARG) ARG##f
#define FLOATTOKEN 'f'

View File

@ -1,45 +0,0 @@
// Filename: ioPtaDatagramLinMath.I
// Created by: jason (26Jun00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: IoPtaDatagamLinMath::write_datagram
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
template<class LinMathElement>
void IoPtaDatagramLinMath<LinMathElement>::
write_datagram(Datagram &dest, CPTA(LinMathElement) array)
{
dest.add_uint32(array.size());
for(int i = 0; i < (int)array.size(); i++)
{
array[i].write_datagram(dest);
}
}
////////////////////////////////////////////////////////////////////
// Function: IoPtaDatagamLinMath::read_datagram
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
template<class LinMathElement>
PTA(LinMathElement) IoPtaDatagramLinMath<LinMathElement>::
read_datagram(DatagramIterator &source)
{
PTA(LinMathElement) array;
LinMathElement temp;
int size = source.get_uint32();
for(int i = 0; i < size; i++)
{
temp.read_datagram(source);
array.push_back(temp);
}
return array;
}

View File

@ -1,11 +0,0 @@
// Filename: ioPtaDatagramLinMath.cxx
// Created by: drose (29Jun00)
//
////////////////////////////////////////////////////////////////////
#include "ioPtaDatagramLinMath.h"
// Tell GCC that we'll take care of the instantiation explicitly here.
#ifdef __GNUC__
#pragma implementation
#endif

View File

@ -1,62 +0,0 @@
// Filename: ioPtaDatagramLinMath.h
// Created by: jason (26Jun00)
//
////////////////////////////////////////////////////////////////////
#ifndef _IO_PTA_DATAGRAM_LINMATH
#define _IO_PTA_DATAGRAM_LINMATH
#include <pandabase.h>
#include "luse.h"
#include "pta_Vertexf.h"
#include "pta_Colorf.h"
#include "pta_Normalf.h"
#include "pta_TexCoordf.h"
#include <pointerToArray.h>
class Datagram;
class DatagramIterator;
///////////////////////////////////////////////////////////////////
// Class : IoPtaDatagramLinMath
// Description : This class is used to read and write a PTA_something
// (where something is some kind of LinMath object like
// LMatrix4f or LVector3f) from a Datagram, in support
// of Bam. It's not intended to be constructed; it's
// just a convenient place to scope these static methods
// which should be called directly.
////////////////////////////////////////////////////////////////////
template<class LinMathElement>
class IoPtaDatagramLinMath {
public:
static void write_datagram(Datagram &dest, CPTA(LinMathElement) array);
static PTA(LinMathElement) read_datagram(DatagramIterator &source);
};
#include "ioPtaDatagramLinMath.I"
// Now export all of the likely template classes for Windows' benefit.
// This must be done in this file, and not in the individual pta_*
// files, because it's important that this export command be the first
// appearance of a particular template instantiation.
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath<Colorf>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath<Normalf>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath<TexCoordf>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath<Vertexf>)
typedef IoPtaDatagramLinMath<Colorf> IPD_Colorf;
typedef IoPtaDatagramLinMath<Normalf> IPD_Normalf;
typedef IoPtaDatagramLinMath<TexCoordf> IPD_TexCoordf;
typedef IoPtaDatagramLinMath<Vertexf> IPD_Vertexf;
// Tell GCC that we'll take care of the instantiation explicitly here.
#ifdef __GNUC__
#pragma interface
#endif
#endif

View File

@ -0,0 +1,27 @@
// Filename: lcast_to.h
// Created by: drose (03Apr01)
//
////////////////////////////////////////////////////////////////////
#ifndef LCAST_TO_H
#define LCAST_TO_H
////////////////////////////////////////////////////////////////////
//
// This file defines the various lcast_to() functions on the types
// defined within this module. It is assumed that all the types have
// already been defined.
//
// The lcast_to() functions are invoked by the LCAST macro to convert
// a linmath object from one numeric type to another.
//
////////////////////////////////////////////////////////////////////
#include "dbl2fltnames.h"
#include "lcast_to_src.h"
#include "flt2dblnames.h"
#include "lcast_to_src.h"
#endif

View File

@ -0,0 +1,67 @@
INLINE FLOATNAME2(LVecBase2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source) {
return FLOATNAME2(LVecBase2)(source[0], source[1]);
}
INLINE FLOATNAME2(LVecBase3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source) {
return FLOATNAME2(LVecBase3)(source[0], source[1], source[2]);
}
INLINE FLOATNAME2(LVecBase4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source) {
return FLOATNAME2(LVecBase4)(source[0], source[1], source[2], source[3]);
}
INLINE FLOATNAME2(LVector2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source) {
return FLOATNAME2(LVector2)(source[0], source[1]);
}
INLINE FLOATNAME2(LVector3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source) {
return FLOATNAME2(LVector3)(source[0], source[1], source[2]);
}
INLINE FLOATNAME2(LVector4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source) {
return FLOATNAME2(LVector4)(source[0], source[1], source[2], source[3]);
}
INLINE FLOATNAME2(LPoint2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source) {
return FLOATNAME2(LPoint2)(source[0], source[1]);
}
INLINE FLOATNAME2(LPoint3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source) {
return FLOATNAME2(LPoint3)(source[0], source[1], source[2]);
}
INLINE FLOATNAME2(LPoint4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source) {
return FLOATNAME2(LPoint4)(source[0], source[1], source[2], source[3]);
}
INLINE FLOATNAME2(LQuaternion)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternion)& c) {
return FLOATNAME2(LQuaternion)(c.get_r(), c.get_i(), c.get_j(), c.get_k());
}
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));
}
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));
}

View File

@ -0,0 +1,42 @@
// Filename: lcast_to_src.h
// Created by: drose (03Apr01)
//
////////////////////////////////////////////////////////////////////
INLINE FLOATNAME2(LVecBase2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source);
INLINE FLOATNAME2(LVecBase3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source);
INLINE FLOATNAME2(LVecBase4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source);
INLINE FLOATNAME2(LVector2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source);
INLINE FLOATNAME2(LVector3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source);
INLINE FLOATNAME2(LVector4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source);
INLINE FLOATNAME2(LPoint2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source);
INLINE FLOATNAME2(LPoint3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source);
INLINE FLOATNAME2(LPoint4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source);
INLINE FLOATNAME2(LQuaternion)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternion)& c);
INLINE FLOATNAME2(LMatrix3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source);
INLINE FLOATNAME2(LMatrix4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix4) &source);
#include "lcast_to_src.I"

View File

@ -1,85 +0,0 @@
// Filename: lmat_ops.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LMAT_OPS_H
#define LMAT_OPS_H
#include "lvecBase3.h"
#include "lpoint3.h"
#include "lvector3.h"
#include "lvecBase4.h"
#include "lpoint4.h"
#include "lvector4.h"
#include "lmatrix3.h"
#include "lmatrix4.h"
// 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

View File

@ -1,15 +1,26 @@
// Filename: lmat_ops.I
// Filename: lmat_ops_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: LVecBase3 times LMatrix3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>
operator * (const LVecBase3<NumType> &v, const LMatrix3<NumType> &m) {
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) {
return m.xform(v);
}
@ -17,9 +28,9 @@ operator * (const LVecBase3<NumType> &v, const LMatrix3<NumType> &m) {
// Function: LVector2 times LMatrix3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector2<NumType>
operator * (const LVector2<NumType> &v, const LMatrix3<NumType> &m) {
INLINE FLOATNAME(LVector2)
operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m) {
return m.xform_vec(v);
}
@ -27,9 +38,9 @@ operator * (const LVector2<NumType> &v, const LMatrix3<NumType> &m) {
// Function: LPoint2 times LMatrix3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType>
operator * (const LPoint2<NumType> &v, const LMatrix3<NumType> &m) {
INLINE FLOATNAME(LPoint2)
operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m) {
return m.xform_point(v);
}
@ -38,19 +49,30 @@ operator * (const LPoint2<NumType> &v, const LMatrix3<NumType> &m) {
// Function: LVecBase4 times LMatrix4
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>
operator * (const LVecBase4<NumType> &v, const LMatrix4<NumType> &m) {
INLINE FLOATNAME(LVecBase4)
operator * (const FLOATNAME(LVecBase4) &v, const FLOATNAME(LMatrix4) &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:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector3<NumType>
operator * (const LVector3<NumType> &v, const LMatrix4<NumType> &m) {
INLINE FLOATNAME(LVector3)
operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m) {
return m.xform_vec(v);
}
@ -58,9 +80,9 @@ operator * (const LVector3<NumType> &v, const LMatrix4<NumType> &m) {
// Function: LPoint3 times LMatrix4
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType>
operator * (const LPoint3<NumType> &v, const LMatrix4<NumType> &m) {
INLINE FLOATNAME(LPoint3)
operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m) {
return m.xform_point(v);
}

View File

@ -0,0 +1,33 @@
// Filename: lmat_ops_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
BEGIN_PUBLISH
// 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);
END_PUBLISH
#include "lmat_ops_src.I"

View File

@ -1,13 +0,0 @@
// Filename: lmatrix.cxx
// Created by: drose (22Feb99)
//
////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include "lmatrix.h"
// This tells GCC to explicitly instantiate the templates defined in
// lmatrix.h and leave them here.
#ifdef __GNUC__
#pragma implementation
#endif

View File

@ -1,25 +0,0 @@
// Filename: lmatrix.h
// Created by: drose (15Jan99)
//
////////////////////////////////////////////////////////////////////
#ifndef LMATRIX_H
#define LMATRIX_H
#include <pandabase.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__
#pragma interface
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
// Filename: lmatrix3.cxx
// Created by: drose (29Jan99)
//
////////////////////////////////////////////////////////////////////
#include "config_linmath.h"
#include "lmatrix3.h"
#include "fltnames.I"
#include "lmatrix3_src.I"
#include "dblnames.I"
#include "lmatrix3_src.I"

View File

@ -1,194 +0,0 @@
// Filename: lmatrix3.h
// Created by: drose (29Jan99)
//
////////////////////////////////////////////////////////////////////
#ifndef LMATRIX3_H
#define LMATRIX3_H
#include <pandabase.h>
#include "coordinateSystem.h"
#include "lvecBase3.h"
#include "lvecBase2.h"
#include <typeHandle.h>
#include <datagram.h>
#include <datagramIterator.h>
////////////////////////////////////////////////////////////////////
// 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.
////////////////////////////////////////////////////////////////////
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

View File

@ -1,10 +1,15 @@
// Filename: lmatrix3.I
// Filename: lmatrix3_src.h
// Created by: drose (29Jan99)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LMatrix3)::_type_handle;
FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::_ident_mat =
FLOATNAME(LMatrix3)(1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0);
////////////////////////////////////////////////////////////////////
// Function: LMatrix3::fill
// Access: Public
@ -14,7 +19,7 @@ TypeHandle FLOATNAME(LMatrix3)::_type_handle;
////////////////////////////////////////////////////////////////////
void FLOATNAME(LMatrix3)::
fill(FLOATTYPE1 fill_value) {
fill(FLOATTYPE fill_value) {
set(fill_value, fill_value, fill_value,
fill_value, fill_value, fill_value,
fill_value, fill_value, fill_value);
@ -40,7 +45,7 @@ operator == (const FLOATNAME(LMatrix3) &other) const {
}
int FLOATNAME(LMatrix3)::
compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE1 threshold) const {
compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const {
for (int i = 0; i < 9; i++) {
if (!IS_THRESHOLD_EQUAL(_data[i], other._data[i], threshold)) {
return (_data[i] < other._data[i]) ? -1 : 1;
@ -57,7 +62,7 @@ compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE1 threshold) const {
////////////////////////////////////////////////////////////////////
bool FLOATNAME(LMatrix3)::
almost_equal(const FLOATNAME(LMatrix3) &other, FLOATTYPE1 threshold) const {
almost_equal(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const {
return (IS_THRESHOLD_EQUAL((*this)(0, 0), other(0, 0), threshold) &&
IS_THRESHOLD_EQUAL((*this)(0, 1), other(0, 1), threshold) &&
IS_THRESHOLD_EQUAL((*this)(0, 2), other(0, 2), threshold) &&
@ -79,9 +84,8 @@ void FLOATNAME(LMatrix3)::
init_type() {
if (_type_handle == TypeHandle::none()) {
// Format a string to describe the type.
do_init_type(FLOATTYPE1);
string name =
"LMatrix3<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LMatrix3";
name += FLOATTOKEN;
register_type(_type_handle, name);
}
}

View File

@ -0,0 +1,167 @@
// Filename: lmatrix3_src.h
// Created by: drose (29Jan99)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// 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.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LMatrix3) {
PUBLISHED:
typedef const FLOATTYPE *iterator;
typedef const FLOATTYPE *const_iterator;
INLINE FLOATNAME(LMatrix3)();
INLINE FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) &other);
INLINE FLOATNAME(LMatrix3) &operator = (const FLOATNAME(LMatrix3) &other);
INLINE FLOATNAME(LMatrix3) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22);
void fill(FLOATTYPE fill_value);
INLINE void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22);
INLINE void set_row(int row, const FLOATNAME(LVecBase3) &v);
INLINE void set_col(int col, const FLOATNAME(LVecBase3) &v);
INLINE void set_row(int row, const FLOATNAME(LVecBase2) &v);
INLINE void set_col(int col, const FLOATNAME(LVecBase2) &v);
INLINE FLOATNAME(LVecBase3) get_row(int row) const;
INLINE FLOATNAME(LVecBase3) get_col(int col) const;
INLINE FLOATNAME(LVecBase2) get_row2(int row) const;
INLINE FLOATNAME(LVecBase2) get_col2(int col) const;
INLINE FLOATTYPE &operator () (int row, int col);
INLINE FLOATTYPE operator () (int row, int col) const;
INLINE bool is_nan() const;
INLINE FLOATTYPE get_cell(int row, int col) const;
INLINE void set_cell(int row, int col, FLOATTYPE value);
INLINE const FLOATTYPE *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 FLOATNAME(LMatrix3) &other) const;
INLINE bool operator != (const FLOATNAME(LMatrix3) &other) const;
INLINE int compare_to(const FLOATNAME(LMatrix3) &other) const;
int compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const;
INLINE FLOATNAME(LVecBase3)
xform(const FLOATNAME(LVecBase3) &v) const;
INLINE FLOATNAME(LVecBase2)
xform_point(const FLOATNAME(LVecBase2) &v) const;
INLINE FLOATNAME(LVecBase2)
xform_vec(const FLOATNAME(LVecBase2) &v) const;
INLINE FLOATNAME(LMatrix3) operator * (const FLOATNAME(LMatrix3) &other) const;
INLINE FLOATNAME(LMatrix3) operator * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LMatrix3) operator / (FLOATTYPE scalar) const;
INLINE FLOATNAME(LMatrix3) &operator += (const FLOATNAME(LMatrix3) &other);
INLINE FLOATNAME(LMatrix3) &operator -= (const FLOATNAME(LMatrix3) &other);
INLINE FLOATNAME(LMatrix3) &operator *= (const FLOATNAME(LMatrix3) &other);
INLINE FLOATNAME(LMatrix3) &operator *= (FLOATTYPE scalar);
INLINE FLOATNAME(LMatrix3) &operator /= (FLOATTYPE scalar);
INLINE FLOATTYPE determinant() const;
INLINE void transpose_from(const FLOATNAME(LMatrix3) &other);
INLINE void transpose_in_place();
INLINE bool invert_from(const FLOATNAME(LMatrix3) &other);
INLINE bool invert_in_place();
static INLINE const FLOATNAME(LMatrix3) &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 INLINE FLOATNAME(LMatrix3) translate_mat(const FLOATNAME(LVecBase2) &trans);
static INLINE FLOATNAME(LMatrix3) translate_mat(FLOATTYPE tx, FLOATTYPE ty);
static INLINE FLOATNAME(LMatrix3) rotate_mat(FLOATTYPE angle);
static INLINE FLOATNAME(LMatrix3) scale_mat(const FLOATNAME(LVecBase2) &scale);
static INLINE FLOATNAME(LMatrix3) scale_mat(FLOATTYPE sx, FLOATTYPE sy);
// The following named constructors return 3x3 matrices suitable for
// scale/rotate transforms in 3-d coordinate space.
static INLINE FLOATNAME(LMatrix3) rotate_mat(FLOATTYPE angle,
FLOATNAME(LVecBase3) axis,
CoordinateSystem cs = CS_default);
static INLINE FLOATNAME(LMatrix3) scale_mat(const FLOATNAME(LVecBase3) &scale);
static INLINE FLOATNAME(LMatrix3) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE 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 FLOATNAME(LMatrix3) &other,
FLOATTYPE threshold) const;
INLINE bool almost_equal(const FLOATNAME(LMatrix3) &other) const;
INLINE void output(ostream &out) const;
INLINE void write(ostream &out, int indent_level = 0) const;
private:
INLINE FLOATTYPE mult_cel(const FLOATNAME(LMatrix3) &other, int x, int y) const;
INLINE FLOATTYPE det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const;
FLOATTYPE _data[3 * 3];
static FLOATNAME(LMatrix3) _ident_mat;
//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;
};
INLINE ostream &operator << (ostream &out, const FLOATNAME(LMatrix3) &mat) {
mat.output(out);
return out;
}
INLINE FLOATNAME(LMatrix3) transpose(const FLOATNAME(LMatrix3) &a);
INLINE FLOATNAME(LMatrix3) invert(const FLOATNAME(LMatrix3) &a);
#include "lmatrix3_src.I"

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
// Filename: lmatrix3.cxx
// Created by: drose (29Jan99)
//
////////////////////////////////////////////////////////////////////
#include "config_linmath.h"
#include "lmatrix4.h"
#include "fltnames.I"
#include "lmatrix4_src.I"
#include "dblnames.I"
#include "lmatrix4_src.I"

View File

@ -1,188 +0,0 @@
// Filename: lmatrix4.h
// Created by: drose (29Jan99)
//
////////////////////////////////////////////////////////////////////
#ifndef LMATRIX4_H
#define LMATRIX4_H
#include <pandabase.h>
#include "coordinateSystem.h"
#include "lvecBase4.h"
#include "lvecBase3.h"
#include "lmatrix3.h"
#include <typeHandle.h>
#include <datagram.h>
#include <datagramIterator.h>
////////////////////////////////////////////////////////////////////
// Class : LMatrix4
// Description : This is a 4-by-4 transform matrix.
////////////////////////////////////////////////////////////////////
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;
}
template<class NumType>
INLINE LMatrix4<NumType> transpose(const LMatrix4<NumType> &a);
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

View File

@ -1,10 +1,28 @@
// Filename: lmatrix4_src.I
// Filename: lmatrix4_src.cxx
// Created by: drose (15Jan99)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LMatrix4)::_type_handle;
const FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::_ident_mat =
FLOATNAME(LMatrix4)(1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
const FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::_y_to_z_up_mat =
FLOATNAME(LMatrix4)(1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0,-1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0);
const FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::_z_to_y_up_mat =
FLOATNAME(LMatrix4)(1.0, 0.0, 0.0, 0.0,
0.0, 0.0,-1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0);
////////////////////////////////////////////////////////////////////
// Function: LMatrix4::Equality Operator
// Access: Public
@ -105,7 +123,7 @@ convert_mat(CoordinateSystem from, CoordinateSystem to) {
////////////////////////////////////////////////////////////////////
bool FLOATNAME(LMatrix4)::
almost_equal(const FLOATNAME(LMatrix4) &other, FLOATTYPE1 threshold) const {
almost_equal(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const {
return (IS_THRESHOLD_EQUAL((*this)(0, 0), other(0, 0), threshold) &&
IS_THRESHOLD_EQUAL((*this)(0, 1), other(0, 1), threshold) &&
IS_THRESHOLD_EQUAL((*this)(0, 2), other(0, 2), threshold) &&
@ -134,11 +152,11 @@ almost_equal(const FLOATNAME(LMatrix4) &other, FLOATTYPE1 threshold) const {
bool FLOATNAME(LMatrix4)::
decompose_mat(int index[4]) {
int i, j, k;
FLOATTYPE1 vv[4];
FLOATTYPE vv[4];
for (i = 0; i < 4; i++) {
FLOATTYPE1 big = 0.0;
FLOATTYPE big = 0.0;
for (j = 0; j < 4; j++) {
FLOATTYPE1 temp = fabs((*this)(i,j));
FLOATTYPE temp = fabs((*this)(i,j));
if (temp > big) {
big = temp;
}
@ -152,23 +170,23 @@ decompose_mat(int index[4]) {
for (j = 0; j < 4; j++) {
for (i = 0; i < j; i++) {
FLOATTYPE1 sum = (*this)(i,j);
FLOATTYPE sum = (*this)(i,j);
for (k = 0; k < i; k++) {
sum -= (*this)(i,k) * (*this)(k,j);
}
(*this)(i,j) = sum;
}
FLOATTYPE1 big = 0.0;
FLOATTYPE big = 0.0;
int imax = -1;
for (i = j; i < 4; i++) {
FLOATTYPE1 sum = (*this)(i,j);
FLOATTYPE sum = (*this)(i,j);
for (k = 0; k < j; k++) {
sum -= (*this)(i,k) * (*this)(k,j);
}
(*this)(i,j) = sum;
FLOATTYPE1 dum = vv[i] * fabs(sum);
FLOATTYPE dum = vv[i] * fabs(sum);
if (dum >= big) {
big = dum;
imax = i;
@ -177,7 +195,7 @@ decompose_mat(int index[4]) {
nassertr(imax >= 0, false);
if (j != imax) {
for (k = 0; k < 4; k++) {
FLOATTYPE1 dum = (*this)(imax,k);
FLOATTYPE dum = (*this)(imax,k);
(*this)(imax,k) = (*this)(j,k);
(*this)(j,k) = dum;
}
@ -186,11 +204,11 @@ decompose_mat(int index[4]) {
index[j] = imax;
if ((*this)(j,j) == 0.0) {
(*this)(j,j) = NEARLY_ZERO(FLOATTYPE1);
(*this)(j,j) = NEARLY_ZERO(FLOATTYPE);
}
if (j != 4 - 1) {
FLOATTYPE1 dum = 1.0 / (*this)(j,j);
FLOATTYPE dum = 1.0 / (*this)(j,j);
for (i = j + 1; i < 4; i++) {
(*this)(i,j) *= dum;
}
@ -211,7 +229,7 @@ back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const {
int i, j;
for (i = 0; i < 4; i++) {
int ip = index[i];
FLOATTYPE1 sum = inv(row, ip);
FLOATTYPE sum = inv(row, ip);
inv(row, ip) = inv(row, i);
if (ii >= 0) {
for (j = ii; j <= i - 1; j++) {
@ -225,7 +243,7 @@ back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const {
}
for (i = 4 - 1; i >= 0; i--) {
FLOATTYPE1 sum = inv(row, i);
FLOATTYPE sum = inv(row, i);
for (j = i + 1; j < 4; j++) {
sum -= (*this)(i,j) * inv(row, j);
}
@ -245,9 +263,8 @@ void FLOATNAME(LMatrix4)::
init_type() {
if (_type_handle == TypeHandle::none()) {
// Format a string to describe the type.
do_init_type(FLOATTYPE1);
string name =
"LMatrix4<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LMatrix4";
name += FLOATTOKEN;
register_type(_type_handle, name);
}
}
@ -299,7 +316,7 @@ read_datagram(DatagramIterator &scan)
////////////////////////////////////////////////////////////////////
int FLOATNAME(LMatrix4)::
compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE1 threshold) const {
compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const {
for (int i = 0; i < 16; i++) {
if (!IS_THRESHOLD_EQUAL(_data[i], other._data[i], threshold)) {
return (_data[i] < other._data[i]) ? -1 : 1;

View File

@ -0,0 +1,160 @@
// Filename: lmatrix4_src.h
// Created by: drose (15Jan99)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : LMatrix4
// Description : This is a 4-by-4 transform matrix.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LMatrix4) {
PUBLISHED:
typedef const FLOATTYPE *iterator;
typedef const FLOATTYPE *const_iterator;
INLINE FLOATNAME(LMatrix4)();
INLINE FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix4) &other);
INLINE FLOATNAME(LMatrix4) &operator = (const FLOATNAME(LMatrix4) &other);
INLINE FLOATNAME(LMatrix4) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03,
FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13,
FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23,
FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33);
// Construct a 4x4 matrix given a 3x3 rotation matrix and an optional
// translation component.
INLINE FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3);
INLINE FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3,const FLOATNAME(LVecBase3) &trans);
INLINE void fill(FLOATTYPE fill_value);
INLINE void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03,
FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13,
FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23,
FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33);
// Get and set the upper 3x3 rotation matrix.
INLINE void set_upper_3(const FLOATNAME(LMatrix3) &upper3);
INLINE FLOATNAME(LMatrix3) get_upper_3() const;
INLINE void set_row(int row, const FLOATNAME(LVecBase4) &v);
INLINE void set_col(int col, const FLOATNAME(LVecBase4) &v);
INLINE void set_row(int row, const FLOATNAME(LVecBase3) &v);
INLINE void set_col(int col, const FLOATNAME(LVecBase3) &v);
INLINE FLOATNAME(LVecBase4) get_row(int row) const;
INLINE FLOATNAME(LVecBase4) get_col(int col) const;
INLINE FLOATNAME(LVecBase3) get_row3(int row) const;
INLINE FLOATNAME(LVecBase3) get_col3(int col) const;
INLINE FLOATTYPE &operator () (int row, int col);
INLINE FLOATTYPE operator () (int row, int col) const;
INLINE bool is_nan() const;
INLINE FLOATTYPE get_cell(int row, int col) const;
INLINE void set_cell(int row, int col, FLOATTYPE value);
INLINE const FLOATTYPE *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 FLOATNAME(LMatrix4) &other) const;
INLINE bool operator != (const FLOATNAME(LMatrix4) &other) const;
INLINE int compare_to(const FLOATNAME(LMatrix4) &other) const;
int compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const;
INLINE FLOATNAME(LVecBase4)
xform(const FLOATNAME(LVecBase4) &v) const;
INLINE FLOATNAME(LVecBase3)
xform_point(const FLOATNAME(LVecBase3) &v) const;
INLINE FLOATNAME(LVecBase3)
xform_vec(const FLOATNAME(LVecBase3) &v) const;
INLINE FLOATNAME(LMatrix4) operator * (const FLOATNAME(LMatrix4) &other) const;
INLINE FLOATNAME(LMatrix4) operator * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LMatrix4) operator / (FLOATTYPE scalar) const;
INLINE FLOATNAME(LMatrix4) &operator += (const FLOATNAME(LMatrix4) &other);
INLINE FLOATNAME(LMatrix4) &operator -= (const FLOATNAME(LMatrix4) &other);
INLINE FLOATNAME(LMatrix4) &operator *= (const FLOATNAME(LMatrix4) &other);
INLINE FLOATNAME(LMatrix4) &operator *= (FLOATTYPE scalar);
INLINE FLOATNAME(LMatrix4) &operator /= (FLOATTYPE scalar);
INLINE void transpose_from(const FLOATNAME(LMatrix4) &other);
INLINE void transpose_in_place();
INLINE bool invert_from(const FLOATNAME(LMatrix4) &other);
INLINE bool invert_affine_from(const FLOATNAME(LMatrix4) &other);
INLINE bool invert_in_place();
INLINE static const FLOATNAME(LMatrix4) &ident_mat();
INLINE static FLOATNAME(LMatrix4) translate_mat(const FLOATNAME(LVecBase3) &trans);
INLINE static FLOATNAME(LMatrix4) translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz);
INLINE static FLOATNAME(LMatrix4) rotate_mat(FLOATTYPE angle,
FLOATNAME(LVecBase3) axis,
CoordinateSystem cs = CS_default);
INLINE static FLOATNAME(LMatrix4) scale_mat(const FLOATNAME(LVecBase3) &scale);
INLINE static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz);
INLINE static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE scale);
INLINE static const FLOATNAME(LMatrix4) &y_to_z_up_mat();
INLINE static const FLOATNAME(LMatrix4) &z_to_y_up_mat();
static FLOATNAME(LMatrix4) convert_mat(CoordinateSystem from,
CoordinateSystem to);
bool almost_equal(const FLOATNAME(LMatrix4) &other,
FLOATTYPE threshold) const;
INLINE bool almost_equal(const FLOATNAME(LMatrix4) &other) const;
INLINE void output(ostream &out) const;
INLINE void write(ostream &out, int indent_level = 0) const;
private:
INLINE FLOATTYPE mult_cel(const FLOATNAME(LMatrix4) &other, int x, int y) const;
bool decompose_mat(int index[4]);
bool back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const;
FLOATTYPE _data[4 * 4];
static const FLOATNAME(LMatrix4) _ident_mat;
static const FLOATNAME(LMatrix4) _y_to_z_up_mat;
static const FLOATNAME(LMatrix4) _z_to_y_up_mat;
//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;
};
INLINE ostream &operator << (ostream &out, const FLOATNAME(LMatrix4) &mat) {
mat.output(out);
return out;
}
INLINE FLOATNAME(LMatrix4) transpose(const FLOATNAME(LMatrix4) &a);
INLINE FLOATNAME(LMatrix4) invert(const FLOATNAME(LMatrix4) &a);
#include "lmatrix4_src.I"

View File

@ -1,134 +0,0 @@
// Filename: lorientation.I
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
#include "lorientation.h"
#include <notify.h>
template<class NumType>
TypeHandle LOrientation<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Default Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LOrientation<NumType>::
LOrientation() {
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Copy Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LOrientation<NumType>::
LOrientation(const LQuaternionBase<NumType>& c) :
LQuaternionBase<NumType>(c) {
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LOrientation<NumType>::
LOrientation(NumType r, NumType i, NumType j, NumType k) :
LQuaternionBase<NumType>(r, i, j, k) {
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Constructor
// Access: public
// Description: vector + 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);
set_r(cosf(theta_over_2));
set_i(point_at[0] * sin_to2);
set_j(point_at[1] * sin_to2);
set_k(point_at[2] * sin_to2);
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Constructor
// Access: public
// Description: matrix3
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LOrientation<NumType>::
LOrientation(const LMatrix3<NumType> &m) {
set(m);
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Constructor
// Access: public
// Description: matrix4
////////////////////////////////////////////////////////////////////
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.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LOrientation<NumType> LOrientation<NumType>::
operator *(const LQuaternionBase<NumType>& other) const {
return multiply(other);
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::operator *
// Access: public
// Description: Orientation * Orientation
// This is a meaningless operation, and will always
// simply return the rhs.
////////////////////////////////////////////////////////////////////
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);
}
}

View File

@ -1,13 +0,0 @@
// Filename: lorientation.h
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
#include "lorientation.h"
#include "fltnames.I"
#include "lorientation_src.I"
#include "dblnames.I"
#include "lorientation_src.I"

View File

@ -1,47 +0,0 @@
// Filename: lorientation.h
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
#ifndef __LORIENTATION_H__
#define __LORIENTATION_H__
#include <pandabase.h>
#include "lquaternion.h"
////////////////////////////////////////////////////////////////////////
// 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"
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LOrientation<float>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LOrientation<double>)
#endif /* __LORIENTATION_H__ */

View File

@ -1,33 +0,0 @@
// Filename: lorientation.I
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LOrientation)::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LOrientation::init_type
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
void FLOATNAME(LOrientation)::
init_type() {
if (_type_handle == TypeHandle::none()) {
// Format a string to describe the type.
do_init_type(FLOATTYPE1);
string name =
"LOrientation<" + get_type_handle(FLOATTYPE1).get_name() + ">";
register_type(_type_handle, name);
}
}
////////////////////////////////////////////////////////////////////
// Function: LOrientation::Destructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
FLOATNAME(LOrientation)::
~FLOATNAME(LOrientation)() {
}

View File

@ -0,0 +1,22 @@
// Filename: lorientation_src.h
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LOrientation)::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LOrientation::init_type
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
void FLOATNAME(LOrientation)::
init_type() {
if (_type_handle == TypeHandle::none()) {
FLOATNAME(LQuaternion)::init_type();
string name = "LOrientation";
name += FLOATTOKEN;
register_type(_type_handle, name,
FLOATNAME(LQuaternion)::get_class_type());
}
}

View File

@ -0,0 +1,34 @@
// Filename: lorientation_src.h
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Class : LOrientation
// Description : This is a unit quaternion representing an orientation.
////////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LOrientation) : public FLOATNAME(LQuaternion) {
public:
INLINE FLOATNAME(LOrientation)();
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LQuaternion)&);
INLINE FLOATNAME(LOrientation)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE);
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &, float);
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &);
INLINE FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &);
INLINE FLOATNAME(LOrientation)
operator *(const FLOATNAME(LQuaternion)& 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;
};
#include "lorientation_src.I"

View File

@ -1,225 +0,0 @@
// Filename: lpoint2.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
template<class NumType>
TypeHandle LPoint2<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LPoint2::Default Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType>::
LPoint2() {
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType>::
LPoint2(const LVecBase2<NumType> &copy) : LVecBase2<NumType>(copy) {
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> &LPoint2<NumType>::
operator = (const LVecBase2<NumType> &copy) {
LVecBase2<NumType>::operator = (copy);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::Copy Fill Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> &LPoint2<NumType>::
operator = (NumType fill_value) {
LVecBase2<NumType>::operator = (fill_value);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType>::
LPoint2(NumType fill_value) :
LVecBase2<NumType>(fill_value)
{
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType>::
LPoint2(NumType x, NumType y) :
LVecBase2<NumType>(x, y)
{
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::zero Named Constructor
// Access: Public
// Description: Returns a zero point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
zero() {
return LPoint2<NumType>(0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::unit_x Named Constructor
// Access: Public
// Description: Returns a unit X point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
unit_x() {
return LPoint2<NumType>(1.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::unit_y Named Constructor
// Access: Public
// Description: Returns a unit Y point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
unit_y() {
return LPoint2<NumType>(0.0, 1.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::unary -
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
operator - () const {
return LVecBase2<NumType>::operator - ();
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::point + vecbase
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LPoint2<NumType>::
operator + (const LVecBase2<NumType> &other) const {
return LVecBase2<NumType>::operator + (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::point + vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
operator + (const LVector2<NumType> &other) const {
return LVecBase2<NumType>::operator + (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::point - vecbase
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LPoint2<NumType>::
operator - (const LVecBase2<NumType> &other) const {
return LVecBase2<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::point - point
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector2<NumType> LPoint2<NumType>::
operator - (const LPoint2<NumType> &other) const {
return LVecBase2<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::point - vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
operator - (const LVector2<NumType> &other) const {
return LVecBase2<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::operator * scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint2<NumType> LPoint2<NumType>::
operator * (NumType scalar) const {
return LPoint2<NumType>(LVecBase2<NumType>::operator * (scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::operator / scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}

View File

@ -1,13 +0,0 @@
// Filename: lpoint2.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "lpoint2.h"
#include "fltnames.I"
#include "lpoint2_src.I"
#include "dblnames.I"
#include "lpoint2_src.I"

View File

@ -1,69 +0,0 @@
// Filename: lpoint2.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LPOINT2_H
#define LPOINT2_H
#include <pandabase.h>
#include "lvecBase2.h"
#include "lvector2.h"
////////////////////////////////////////////////////////////////////
// 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> &copy);
INLINE LPoint2<NumType> &operator = (const LVecBase2<NumType> &copy);
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"
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint2<float>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint2<double>)
#endif

View File

@ -1,4 +1,4 @@
// Filename: lpoint2.I
// Filename: lpoint2_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
@ -15,8 +15,8 @@ void FLOATNAME(LPoint2)::
init_type() {
if (_type_handle == TypeHandle::none()) {
FLOATNAME(LVecBase2)::init_type();
string name =
"LPoint2<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LPoint2";
name += FLOATTOKEN;
register_type(_type_handle, name,
FLOATNAME(LVecBase2)::get_class_type());
}

View File

@ -0,0 +1,51 @@
// Filename: lpoint2_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// 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) &copy);
INLINE FLOATNAME(LPoint2) &operator = (const FLOATNAME(LVecBase2) &copy);
INLINE FLOATNAME(LPoint2) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LPoint2)(FLOATTYPE fill_value);
INLINE FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y);
INLINE static const FLOATNAME(LPoint2) &zero();
INLINE static const FLOATNAME(LPoint2) &unit_x();
INLINE static const 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 * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
#include "lpoint2_src.I"

View File

@ -1,278 +0,0 @@
// Filename: lpoint3.I
// Created by: drose (25Sep99)
//
////////////////////////////////////////////////////////////////////
#include "lvector3.h"
template<class NumType>
TypeHandle LPoint3<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LPoint3::Default Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType>::
LPoint3() {
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType>::
LPoint3(const LVecBase3<NumType> &copy) : LVecBase3<NumType>(copy) {
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> &LPoint3<NumType>::
operator = (const LVecBase3<NumType> &copy) {
LVecBase3<NumType>::operator = (copy);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::Copy Fill Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> &LPoint3<NumType>::
operator = (NumType fill_value) {
LVecBase3<NumType>::operator = (fill_value);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType>::
LPoint3(NumType fill_value) :
LVecBase3<NumType>(fill_value)
{
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType>::
LPoint3(NumType x, NumType y, NumType z) :
LVecBase3<NumType>(x, y, z)
{
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::zero Named Constructor
// Access: Public
// Description: Returns a zero point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
zero() {
return LPoint3<NumType>(0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::unit_x Named Constructor
// Access: Public
// Description: Returns a unit X point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
unit_x() {
return LPoint3<NumType>(1.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::unit_y Named Constructor
// Access: Public
// Description: Returns a unit Y point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
unit_y() {
return LPoint3<NumType>(0.0, 1.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::unit_z Named Constructor
// Access: Public
// Description: Returns a unit Z point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
unit_z() {
return LPoint3<NumType>(0.0, 0.0, 1.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::unary -
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
operator - () const {
return LVecBase3<NumType>::operator - ();
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::point + vecbase
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LPoint3<NumType>::
operator + (const LVecBase3<NumType> &other) const {
return LVecBase3<NumType>::operator + (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::point + vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
operator + (const LVector3<NumType> &other) const {
return LVecBase3<NumType>::operator + (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::point - vecbase
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LPoint3<NumType>::
operator - (const LVecBase3<NumType> &other) const {
return LVecBase3<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::point - point
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector3<NumType> LPoint3<NumType>::
operator - (const LPoint3<NumType> &other) const {
return LVecBase3<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::point - vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
operator - (const LVector3<NumType> &other) const {
return LVecBase3<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::cross
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
cross(const LVecBase3<NumType> &other) const {
return LVecBase3<NumType>::cross(other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::operator * scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
operator * (NumType scalar) const {
return LPoint3<NumType>(LVecBase3<NumType>::operator * (scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::operator / scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
operator / (NumType scalar) const {
return LPoint3<NumType>(LVecBase3<NumType>::operator / (scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::origin
// Access: Public, Static
// Description: Returns the origin of the indicated coordinate
// system. This is always 0, 0, 0 with all of our
// existing coordinate systems; it's hard to imagine it
// ever being different.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
origin(CoordinateSystem) {
return LPoint3<NumType>(0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::rfu
// Access: Public, Static
// Description: Returns a point described by right, forward, up
// displacements from the origin, wherever that maps to
// in the given coordinate system.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint3<NumType> LPoint3<NumType>::
rfu(NumType right_v, NumType fwd_v, NumType up_v,
CoordinateSystem cs) {
return origin(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]);
}

View File

@ -1,13 +0,0 @@
// Filename: lpoint2.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "lpoint3.h"
#include "fltnames.I"
#include "lpoint3_src.I"
#include "dblnames.I"
#include "lpoint3_src.I"

View File

@ -1,85 +0,0 @@
// Filename: lpoint3.h
// Created by: drose (25Sep99)
//
////////////////////////////////////////////////////////////////////
#ifndef LPOINT3_H
#define LPOINT3_H
#include <pandabase.h>
#include "coordinateSystem.h"
#include "lvecBase3.h"
#include "lvector3.h"
////////////////////////////////////////////////////////////////////
// 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> &copy);
INLINE LPoint3<NumType> &operator = (const LVecBase3<NumType> &copy);
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"
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint3<float>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint3<double>)
#endif

View File

@ -1,4 +1,4 @@
// Filename: lpoint3.I
// Filename: lpoint3_src.h
// Created by: drose (25Sep99)
//
////////////////////////////////////////////////////////////////////
@ -15,8 +15,8 @@ void FLOATNAME(LPoint3)::
init_type() {
if (_type_handle == TypeHandle::none()) {
FLOATNAME(LVecBase3)::init_type();
string name =
"LPoint3<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LPoint3";
name += FLOATTOKEN;
register_type(_type_handle, name,
FLOATNAME(LVecBase3)::get_class_type());
}

View File

@ -0,0 +1,65 @@
// Filename: lpoint3_src.h
// Created by: drose (25Sep99)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// 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.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LPoint3) : public FLOATNAME(LVecBase3) {
PUBLISHED:
INLINE FLOATNAME(LPoint3)();
INLINE FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) &copy);
INLINE FLOATNAME(LPoint3) &operator = (const FLOATNAME(LVecBase3) &copy);
INLINE FLOATNAME(LPoint3) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LPoint3)(FLOATTYPE fill_value);
INLINE FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
INLINE static const FLOATNAME(LPoint3) &zero();
INLINE static const FLOATNAME(LPoint3) &unit_x();
INLINE static const FLOATNAME(LPoint3) &unit_y();
INLINE static const 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 * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LPoint3) operator / (FLOATTYPE scalar) const;
// Some special named constructors for LPoint3.
INLINE static FLOATNAME(LPoint3) origin(CoordinateSystem cs = CS_default);
INLINE static FLOATNAME(LPoint3) rfu(FLOATTYPE right,
FLOATTYPE fwd,
FLOATTYPE up,
CoordinateSystem cs = CS_default);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
#include "lpoint3_src.I"

View File

@ -1,247 +0,0 @@
// Filename: lpoint4.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
template<class NumType>
TypeHandle LPoint4<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LPoint4::Default Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType>::
LPoint4() {
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType>::
LPoint4(const LVecBase4<NumType> &copy) : LVecBase4<NumType>(copy) {
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> &LPoint4<NumType>::
operator = (const LVecBase4<NumType> &copy) {
LVecBase4<NumType>::operator = (copy);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::Copy Fill Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> &LPoint4<NumType>::
operator = (NumType fill_value) {
LVecBase4<NumType>::operator = (fill_value);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType>::
LPoint4(NumType fill_value) :
LVecBase4<NumType>(fill_value)
{
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType>::
LPoint4(NumType x, NumType y, NumType z, NumType w) :
LVecBase4<NumType>(x, y, z, w)
{
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::zero Named Constructor
// Access: Public
// Description: Returns a zero point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
zero() {
return LPoint4<NumType>(0.0, 0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::unit_x Named Constructor
// Access: Public
// Description: Returns a unit X point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
unit_x() {
return LPoint4<NumType>(1.0, 0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::unit_y Named Constructor
// Access: Public
// Description: Returns a unit Y point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
unit_y() {
return LPoint4<NumType>(0.0, 1.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::unit_z Named Constructor
// Access: Public
// Description: Returns a unit Z point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
unit_z() {
return LPoint4<NumType>(0.0, 0.0, 1.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::unit_w Named Constructor
// Access: Public
// Description: Returns a unit W point.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
unit_w() {
return LPoint4<NumType>(0.0, 0.0, 0.0, 1.0);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::unary -
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
operator - () const {
return LVecBase4<NumType>::operator - ();
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::point + vecbase
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LPoint4<NumType>::
operator + (const LVecBase4<NumType> &other) const {
return LVecBase4<NumType>::operator + (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::point + vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
operator + (const LVector4<NumType> &other) const {
return LVecBase4<NumType>::operator + (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::point - vecbase
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LPoint4<NumType>::
operator - (const LVecBase4<NumType> &other) const {
return LVecBase4<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::point - point
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector4<NumType> LPoint4<NumType>::
operator - (const LPoint4<NumType> &other) const {
return LVecBase4<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::point - vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
operator - (const LVector4<NumType> &other) const {
return LVecBase4<NumType>::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::operator * scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LPoint4<NumType> LPoint4<NumType>::
operator * (NumType scalar) const {
return LPoint4<NumType>(LVecBase4<NumType>::operator * (scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::operator / scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}

View File

@ -1,13 +0,0 @@
// Filename: lpoint2.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "lpoint4.h"
#include "fltnames.I"
#include "lpoint4_src.I"
#include "dblnames.I"
#include "lpoint4_src.I"

View File

@ -1,71 +0,0 @@
// Filename: lpoint4.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LPOINT4_H
#define LPOINT4_H
#include <pandabase.h>
#include "lvecBase4.h"
#include "lvector4.h"
////////////////////////////////////////////////////////////////////
// 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> &copy);
INLINE LPoint4<NumType> &operator = (const LVecBase4<NumType> &copy);
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"
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4<float>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4<double>)
#endif

View File

@ -1,4 +1,4 @@
// Filename: lpoint4.I
// Filename: lpoint4_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
@ -15,8 +15,8 @@ void FLOATNAME(LPoint4)::
init_type() {
if (_type_handle == TypeHandle::none()) {
FLOATNAME(LVecBase4)::init_type();
string name =
"LPoint4<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LPoint4";
name += FLOATTOKEN;
register_type(_type_handle, name,
FLOATNAME(LVecBase4)::get_class_type());
}

View File

@ -0,0 +1,52 @@
// Filename: lpoint4_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// 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) &copy);
INLINE FLOATNAME(LPoint4) &operator = (const FLOATNAME(LVecBase4) &copy);
INLINE FLOATNAME(LPoint4) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LPoint4)(FLOATTYPE fill_value);
INLINE FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w);
INLINE static const FLOATNAME(LPoint4) &zero();
INLINE static const FLOATNAME(LPoint4) &unit_x();
INLINE static const FLOATNAME(LPoint4) &unit_y();
INLINE static const FLOATNAME(LPoint4) &unit_z();
INLINE static const 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 * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
#include "lpoint4_src.I"

View File

@ -1,623 +0,0 @@
// Filename: lquaternion.I
// Created by: frang (06Jun00)
//
////////////////////////////////////////////////////////////////////
template<class NumType>
TypeHandle LQuaternionBase<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Default Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LQuaternionBase<NumType>::
LQuaternionBase(void) {
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Copy Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LQuaternionBase<NumType>::
LQuaternionBase(const LQuaternionBase<NumType>& c) :
_r(c._r), _i(c._i), _j(c._j), _k(c._k) {
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LQuaternionBase<NumType>::
LQuaternionBase(NumType r, NumType i, NumType j, NumType k) {
set(r, i, j, k);
}
////////////////////////////////////////////////////////////////////
// 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
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
set(NumType r, NumType i, NumType j, NumType k) {
_r = r;
_i = i;
_j = j;
_k = k;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Assignment Operator
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LQuaternionBase<NumType>& LQuaternionBase<NumType>::
operator =(const LQuaternionBase<NumType>& c) {
_r = c._r;
_i = c._i;
_j = c._j;
_k = c._k;
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Equality Operator
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LQuaternionBase<NumType>::
operator ==(const LQuaternionBase<NumType>& c) const {
return (_r == c._r &&
_i == c._i &&
_j == c._j &&
_k == c._k);
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Inequality Operator
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LQuaternionBase<NumType>::
operator !=(const LQuaternionBase<NumType>& c) const {
return !operator==(c);
}
////////////////////////////////////////////////////////////////////
// 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);
return LQuaternionBase<NumType>(r, i , j, k);
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Multiply Operator
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LQuaternionBase<NumType> LQuaternionBase<NumType>::
operator *(const LQuaternionBase<NumType>& c) {
return multiply(c);
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Multiply Assignment Operator
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LQuaternionBase<NumType>& LQuaternionBase<NumType>::
operator *=(const LQuaternionBase<NumType>& c) {
(*this) = operator*(c);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Multiply Operator
// Access: public
// Description: Quat * Matrix = matrix
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LMatrix3<NumType> LQuaternionBase<NumType>::
operator *(const LMatrix3<NumType> &m) {
LMatrix3<NumType> result;
extract_to_matrix(result);
return result * m;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::Multiply Operator
// Access: public
// Description: Quat * Matrix = matrix
////////////////////////////////////////////////////////////////////
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);
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));
return result;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::almost_equal
// Access: public
// Description: Returns true if two quaternions are memberwise equal
// within a specified tolerance.
////////////////////////////////////////////////////////////////////
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) &&
IS_THRESHOLD_EQUAL(_k, c._k, threshold));
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::almost_equal
// Access: public
// Description: Returns true if two quaternions are memberwise equal
// within a default tolerance based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LQuaternionBase<NumType>::
almost_equal(const LQuaternionBase<NumType>& c) const {
return almost_equal(c, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::output
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
output(ostream& os) const {
os << MAYBE_ZERO(_r) << " + "
<< MAYBE_ZERO(_i) << "i + "
<< MAYBE_ZERO(_j) << "j + "
<< MAYBE_ZERO(_k) << "k";
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::get_r
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LQuaternionBase<NumType>::
get_r(void) const {
return _r;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::get_i
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LQuaternionBase<NumType>::
get_i(void) const {
return _i;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::get_j
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LQuaternionBase<NumType>::
get_j(void) const {
return _j;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::get_k
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LQuaternionBase<NumType>::
get_k(void) const {
return _k;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::set_r
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
set_r(NumType r) {
_r = r;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::set_i
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
set_i(NumType i) {
_i = i;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::set_j
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
set_j(NumType j) {
_j = j;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::set_k
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
set_k(NumType k) {
_k = k;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternionBase::normalize
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LQuaternionBase<NumType>::
normalize(void) {
NumType l = csqrt((_r*_r)+(_i*_i)+(_j*_j)+(_k*_k));
if (l == 0.0) {
_r = 0.;
_i = 0.;
_j = 0.;
_k = 0.;
} else {
l = 1. / l;
_r *= l;
_i *= l;
_j *= l;
_k *= l;
}
}
////////////////////////////////////////////////////////////////////
// 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:
////////////////////////////////////////////////////////////////////
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:
////////////////////////////////////////////////////////////////////
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;
}
////////////////////////////////////////////////////////////////////
// Function: operator *(Matrix4, Quat)
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
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
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);
q_matrix.set_col(3, m_col3);
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());
}

View File

@ -1,13 +0,0 @@
// Filename: lquaternion.cxx
// Created by: frang (06Jun00)
//
////////////////////////////////////////////////////////////////////
#include "lquaternion.h"
#include "fltnames.I"
#include "lquaternion_src.I"
#include "dblnames.I"
#include "lquaternion_src.I"

View File

@ -1,123 +0,0 @@
// Filename: lquaternion.h
// Created by: frang (06Jun00)
//
////////////////////////////////////////////////////////////////////
#ifndef __LQUATERNION_H__
#define __LQUATERNION_H__
#include "lmatrix.h"
#include "nearly_zero.h"
#include "cmath.h"
#include "deg_2_rad.h"
#include <notify.h>
////////////////////////////////////////////////////////////////////
// Class : LQuaternionBase
// Description : This is the base quaternion class
////////////////////////////////////////////////////////////////////
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;
}
// 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__ */

View File

@ -1,25 +1,17 @@
TypeHandle FLOATNAME(LQuaternionBase)::_type_handle;
TypeHandle FLOATNAME(LQuaternion)::_type_handle;
const FLOATNAME(LQuaternion) FLOATNAME(LQuaternion)::_ident_quat =
FLOATNAME(LQuaternion)(1.0, 0.0, 0.0, 0.0);
////////////////////////////////////////////////////////////////////
// Function: FLOATNAME(LQuaternionBase)::Destructor
// Function: FLOATNAME(LQuaternion)::pure_imaginary_quat
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
FLOATNAME(LQuaternionBase)::
~FLOATNAME(LQuaternionBase)() {
}
////////////////////////////////////////////////////////////////////
// Function: FLOATNAME(LQuaternionBase)::pure_imaginary_quat
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
FLOATNAME(LQuaternionBase) FLOATNAME(LQuaternionBase)::
FLOATNAME(LQuaternion) FLOATNAME(LQuaternion)::
pure_imaginary(const FLOATNAME(LVector3) &v) {
return FLOATNAME(LQuaternionBase)(0, v[0], v[1], v[2]);
return FLOATNAME(LQuaternion)(0, v[0], v[1], v[2]);
}
////////////////////////////////////////////////////////////////////
@ -27,17 +19,16 @@ pure_imaginary(const FLOATNAME(LVector3) &v) {
// Access: public
// Description: Do-While Jones paper from cary.
////////////////////////////////////////////////////////////////////
void FLOATNAME(LQuaternionBase)::
void FLOATNAME(LQuaternion)::
extract_to_matrix(FLOATNAME(LMatrix3) &m) const {
FLOATTYPE1 N = (_r * _r) + (_i * _i) + (_j * _j) + (_k * _k);
FLOATTYPE1 s = (N == 0.) ? 0. : (2. / N);
FLOATTYPE1 xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
FLOATTYPE N = (_data[0] * _data[0]) + (_data[1] * _data[1]) + (_data[2] * _data[2]) + (_data[3] * _data[3]);
FLOATTYPE s = (N == 0.) ? 0. : (2. / N);
FLOATTYPE 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;
xs = _data[1] * s; ys = _data[2] * s; zs = _data[3] * s;
wx = _data[0] * xs; wy = _data[0] * ys; wz = _data[0] * zs;
xx = _data[1] * xs; xy = _data[1] * ys; xz = _data[1] * zs;
yy = _data[2] * ys; yz = _data[2] * zs; zz = _data[3] * zs;
m = FLOATNAME(LMatrix3)((1. - (yy + zz)), (xy - wz), (xz + wy),
(xy + wz), (1. - (xx + zz)), (yz - wx),
@ -49,17 +40,16 @@ extract_to_matrix(FLOATNAME(LMatrix3) &m) const {
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
void FLOATNAME(LQuaternionBase)::
void FLOATNAME(LQuaternion)::
extract_to_matrix(FLOATNAME(LMatrix4) &m) const {
FLOATTYPE1 N = (_r * _r) + (_i * _i) + (_j * _j) + (_k * _k);
FLOATTYPE1 s = (N == 0.) ? 0. : (2. / N);
FLOATTYPE1 xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
FLOATTYPE N = (_data[0] * _data[0]) + (_data[1] * _data[1]) + (_data[2] * _data[2]) + (_data[3] * _data[3]);
FLOATTYPE s = (N == 0.) ? 0. : (2. / N);
FLOATTYPE 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;
xs = _data[1] * s; ys = _data[2] * s; zs = _data[3] * s;
wx = _data[0] * xs; wy = _data[0] * ys; wz = _data[0] * zs;
xx = _data[1] * xs; xy = _data[1] * ys; xz = _data[1] * zs;
yy = _data[2] * ys; yz = _data[2] * zs; zz = _data[3] * zs;
m = FLOATNAME(LMatrix4)((1. - (yy + zz)), (xy - wz), (xz + wy), 0.,
(xy + wz), (1. - (xx + zz)), (yz - wx), 0.,
@ -74,14 +64,13 @@ extract_to_matrix(FLOATNAME(LMatrix4) &m) const {
// is equivalent to these Euler angles.
// (from Real-time Rendering, p.49)
////////////////////////////////////////////////////////////////////
void FLOATNAME(LQuaternionBase)::
void FLOATNAME(LQuaternion)::
set_hpr(const FLOATNAME(LVecBase3) &hpr) {
FLOATNAME(LQuaternionBase) quat_h, quat_p, quat_r;
FLOATNAME(LQuaternion) quat_h, quat_p, quat_r;
FLOATNAME(LVector3) v = FLOATNAME(LVector3)::up();
FLOATTYPE1 a = deg_2_rad(hpr[0] * 0.5);
FLOATTYPE1 s,c;
FLOATTYPE a = deg_2_rad(hpr[0] * 0.5);
FLOATTYPE s,c;
csincos(a,&s,&c);
quat_h.set(c, v[0] * s, v[1] * s, v[2] * s);
@ -104,19 +93,18 @@ set_hpr(const FLOATNAME(LVecBase3) &hpr) {
// Description: Extracts the equivalent Euler angles from the unit
// quaternion.
////////////////////////////////////////////////////////////////////
FLOATNAME(LVecBase3) FLOATNAME(LQuaternionBase)::
FLOATNAME(LVecBase3) FLOATNAME(LQuaternion)::
get_hpr() const {
FLOATTYPE1 heading, pitch, roll;
FLOATTYPE1 N = (_r * _r) + (_i * _i) + (_j * _j) + (_k * _k);
FLOATTYPE1 s = (N == 0.) ? 0. : (2. / N);
FLOATTYPE1 xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz, c1, c2, c3, c4;
FLOATTYPE1 cr, sr, cp, sp, ch, sh;
FLOATTYPE heading, pitch, roll;
FLOATTYPE N = (_data[0] * _data[0]) + (_data[1] * _data[1]) + (_data[2] * _data[2]) + (_data[3] * _data[3]);
FLOATTYPE s = (N == 0.) ? 0. : (2. / N);
FLOATTYPE xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz, c1, c2, c3, c4;
FLOATTYPE 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;
xs = _data[1] * s; ys = _data[2] * s; zs = _data[3] * s;
wx = _data[0] * xs; wy = _data[0] * ys; wz = _data[0] * zs;
xx = _data[1] * xs; xy = _data[1] * ys; xz = _data[1] * zs;
yy = _data[2] * ys; yz = _data[2] * zs; zz = _data[3] * zs;
c1 = xz - wy;
c2 = 1. - (xx + yy);
c3 = 1. - (yy + zz);
@ -151,32 +139,31 @@ get_hpr() const {
}
////////////////////////////////////////////////////////////////////
// Function: set
// Function: set_from_matrix
// Access: public
// Description: Do-While Jones.
////////////////////////////////////////////////////////////////////
void FLOATNAME(LQuaternion)::
set_from_matrix(const FLOATNAME(LMatrix3) &m) {
FLOATTYPE m00 = m.get_cell(0, 0);
FLOATTYPE m01 = m.get_cell(0, 1);
FLOATTYPE m02 = m.get_cell(0, 2);
FLOATTYPE m10 = m.get_cell(1, 0);
FLOATTYPE m11 = m.get_cell(1, 1);
FLOATTYPE m12 = m.get_cell(1, 2);
FLOATTYPE m20 = m.get_cell(2, 0);
FLOATTYPE m21 = m.get_cell(2, 1);
FLOATTYPE m22 = m.get_cell(2, 2);
void FLOATNAME(LQuaternionBase)::
set(const FLOATNAME(LMatrix3) &m) {
FLOATTYPE1 m00 = m.get_cell(0, 0);
FLOATTYPE1 m01 = m.get_cell(0, 1);
FLOATTYPE1 m02 = m.get_cell(0, 2);
FLOATTYPE1 m10 = m.get_cell(1, 0);
FLOATTYPE1 m11 = m.get_cell(1, 1);
FLOATTYPE1 m12 = m.get_cell(1, 2);
FLOATTYPE1 m20 = m.get_cell(2, 0);
FLOATTYPE1 m21 = m.get_cell(2, 1);
FLOATTYPE1 m22 = m.get_cell(2, 2);
FLOATTYPE1 T = m00 + m11 + m22 + 1.;
FLOATTYPE T = m00 + m11 + m22 + 1.;
if (T > 0.) {
// the easy case
FLOATTYPE1 S = 0.5 / csqrt(T);
_r = 0.25 / S;
_i = (m21 - m12) * S;
_j = (m02 - m20) * S;
_k = (m10 - m01) * S;
FLOATTYPE S = 0.5 / csqrt(T);
_data[0] = 0.25 / S;
_data[1] = (m21 - m12) * S;
_data[2] = (m02 - m20) * S;
_data[3] = (m10 - m01) * S;
} else {
// figure out which column to take as root
int c = 0;
@ -190,58 +177,46 @@ set(const FLOATNAME(LMatrix3) &m) {
else
c = 2;
FLOATTYPE1 S;
FLOATTYPE 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;
_data[0] = (m12 + m21) / S;
_data[1] = 0.5 / S;
_data[2] = (m01 + m10) / S;
_data[3] = (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;
_data[0] = (m02 + m20) / S;
_data[1] = (m01 + m10) / S;
_data[2] = 0.5 / S;
_data[3] = (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;
_data[0] = (m01 + m10) / S;
_data[1] = (m02 + m20) / S;
_data[2] = (m12 + m21) / S;
_data[3] = 0.5 / S;
break;
}
}
}
////////////////////////////////////////////////////////////////////
// Function: FLOATNAME(LQuaternionBase)::ident_quat
// Function: LQuaternion::init_type
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
const FLOATNAME(LQuaternionBase) &FLOATNAME(LQuaternionBase)::
ident_quat(void) {
static FLOATNAME(LQuaternionBase) q(1, 0, 0, 0);
return q;
}
////////////////////////////////////////////////////////////////////
// Function: FLOATNAME(LQuaternionBase)::init_type
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
void FLOATNAME(LQuaternionBase)::
init_type(void) {
void FLOATNAME(LQuaternion)::
init_type() {
if (_type_handle == TypeHandle::none()) {
do_init_type(FLOATTYPE1);
string name = "FLOATNAME(LQuaternionBase)<" + get_type_handle(FLOATTYPE1).get_name()
+ ">";
register_type(_type_handle, name);
FLOATNAME(LVecBase4)::init_type();
string name = "LQuaternion";
name += FLOATTOKEN;
register_type(_type_handle, name,
FLOATNAME(LVecBase4)::get_class_type());
}
}

View File

@ -0,0 +1,80 @@
// Filename: lquaternion_src.h
// Created by: frang (06Jun00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : FLOATNAME(LQuaternion)
// Description : This is the base quaternion class
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LQuaternion) : public FLOATNAME(LVecBase4) {
protected:
INLINE FLOATNAME(LQuaternion)
multiply(const FLOATNAME(LQuaternion)&) const;
PUBLISHED:
INLINE FLOATNAME(LQuaternion)();
INLINE FLOATNAME(LQuaternion)(const FLOATNAME(LQuaternion) &);
INLINE FLOATNAME(LQuaternion)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE);
static FLOATNAME(LQuaternion) pure_imaginary(const FLOATNAME(LVector3) &);
INLINE FLOATNAME(LQuaternion) operator *(const FLOATNAME(LQuaternion) &);
INLINE FLOATNAME(LQuaternion)& operator *=(const FLOATNAME(LQuaternion) &);
INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &);
INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &);
INLINE bool almost_equal(const FLOATNAME(LQuaternion) &, FLOATTYPE) const;
INLINE bool almost_equal(const FLOATNAME(LQuaternion) &) const;
INLINE void output(ostream&) const;
void extract_to_matrix(FLOATNAME(LMatrix3) &m) const;
void extract_to_matrix(FLOATNAME(LMatrix4) &m) const;
void set_from_matrix(const FLOATNAME(LMatrix3) &m);
INLINE void set_from_matrix(const FLOATNAME(LMatrix4) &m);
void set_hpr(const FLOATNAME(LVecBase3) &hpr);
FLOATNAME(LVecBase3) get_hpr() const;
INLINE FLOATTYPE get_r() const;
INLINE FLOATTYPE get_i() const;
INLINE FLOATTYPE get_j() const;
INLINE FLOATTYPE get_k() const;
INLINE void set_r(FLOATTYPE r);
INLINE void set_i(FLOATTYPE i);
INLINE void set_j(FLOATTYPE j);
INLINE void set_k(FLOATTYPE k);
INLINE bool normalize();
INLINE static const FLOATNAME(LQuaternion) &ident_quat();
private:
static const FLOATNAME(LQuaternion) _ident_quat;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
INLINE ostream& operator<<(ostream& os, const FLOATNAME(LQuaternion)& q) {
q.output(os);
return os;
}
BEGIN_PUBLISH
INLINE FLOATNAME(LMatrix3)
operator * (const FLOATNAME(LMatrix3) &m, const FLOATNAME(LQuaternion) &q);
INLINE FLOATNAME(LMatrix4)
operator * (const FLOATNAME(LMatrix4) &m, const FLOATNAME(LQuaternion) &q);
END_PUBLISH
#include "lquaternion_src.I"

View File

@ -1,142 +0,0 @@
// Filename: lrotation.I
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
template<class NumType>
TypeHandle LRotation<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LRotation::Default Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LRotation<NumType>::
LRotation() {
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Copy Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LRotation<NumType>::
LRotation(const LQuaternionBase<NumType>& c) :
LQuaternionBase<NumType>(c) {
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Constructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LRotation<NumType>::
LRotation(NumType r, NumType i, NumType j, NumType k) :
LQuaternionBase<NumType>(r, i, j, k) {
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Constructor
// Access: public
// Description: lmatrix3
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LRotation<NumType>::
LRotation(const LMatrix3<NumType> &m) {
set(m);
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Constructor
// Access: public
// Description: lmatrix4
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LRotation<NumType>::
LRotation(const LMatrix4<NumType> &m) {
set(m);
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Constructor
// Access: public
// Description: axis + angle (in degrees)
////////////////////////////////////////////////////////////////////
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);
set_j(axis[1] * sin_to2);
set_k(axis[2] * sin_to2);
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Constructor
// 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));
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::Destructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
LRotation<NumType>::
~LRotation() {
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::operator *
// Access: public
// Description: Rotation * Rotation = Rotation
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LRotation<NumType> LRotation<NumType>::
operator*(const LRotation<NumType>& other) const {
return multiply(other);
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::operator *
// Access: public
// Description: Rotation * Orientation = Orientation
// This is another meaningless operation, attempting
// to apply an orientation to a rotation. It simply
// returns the rhs.
////////////////////////////////////////////////////////////////////
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);
}
}

View File

@ -1,13 +0,0 @@
// Filename: lrotation.I
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
#include "lrotation.h"
#include "fltnames.I"
#include "lrotation_src.I"
#include "dblnames.I"
#include "lrotation_src.I"

View File

@ -1,51 +0,0 @@
// Filename: lrotation.h
// Created by: frang, charles (07Jun00)
//
////////////////////////////////////////////////////////////////////
#ifndef __LROTATION_H__
#define __LROTATION_H__
#include <pandabase.h>
#include "lquaternion.h"
#include "cmath.h"
#include <notify.h>
////////////////////////////////////////////////////////////////////////
// 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"
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LRotation<float>)
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LRotation<double>)
#endif /* __LROTATION_H__ */

View File

@ -1,34 +1,24 @@
// Filename: lrotation.I
// Filename: lrotation_src.h
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LRotation)::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LRotation::Destructor
// Access: public
// Description:
////////////////////////////////////////////////////////////////////
FLOATNAME(LRotation)::
~FLOATNAME(LRotation)() {
}
////////////////////////////////////////////////////////////////////
// Function: LRotation::init_type
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
void FLOATNAME(LRotation)::
init_type() {
if (_type_handle == TypeHandle::none()) {
FLOATNAME(LQuaternion)::init_type();
// Format a string to describe the type.
do_init_type(FLOATTYPE1);
string name =
"LRotation<" + get_type_handle(FLOATTYPE1).get_name() + ">";
register_type(_type_handle, name);
string name = "LRotation";
name += FLOATTOKEN;
register_type(_type_handle, name,
FLOATNAME(LQuaternion)::get_class_type());
}
}

View File

@ -0,0 +1,35 @@
// Filename: lrotation_src.h
// Created by: frang, charles (23Jun00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Class : LRotation
// Description : This is a unit quaternion representing a rotation.
////////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LRotation) : public FLOATNAME(LQuaternion) {
PUBLISHED:
INLINE FLOATNAME(LRotation)();
INLINE FLOATNAME(LRotation)(const FLOATNAME(LQuaternion)&);
INLINE FLOATNAME(LRotation)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE);
INLINE FLOATNAME(LRotation)(const FLOATNAME(LVector3) &, FLOATTYPE);
INLINE FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &);
INLINE FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &);
INLINE FLOATNAME(LRotation)(FLOATTYPE, FLOATTYPE, FLOATTYPE);
INLINE FLOATNAME(LRotation)
operator*(const FLOATNAME(LRotation)& other) const;
INLINE FLOATNAME(LQuaternion)
operator*(const FLOATNAME(LQuaternion)& other) const;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
#include "lrotation_src.I"

View File

@ -1,4 +0,0 @@
// Filename: luse.I
// Created by: drose (13Jan99)
//
////////////////////////////////////////////////////////////////////

View File

@ -1,85 +0,0 @@
forcetype LVecBase2<float>
forcetype LVecBase3<float>
forcetype LVecBase4<float>
forcetype LPoint2<float>
forcetype LPoint3<float>
forcetype LPoint4<float>
forcetype LVector2<float>
forcetype LVector3<float>
forcetype LVector4<float>
forcetype LMatrix3<float>
forcetype LMatrix4<float>
forcetype LPoint2f
forcetype LPoint3f
forcetype LPoint4f
forcetype LVector2f
forcetype LVector3f
forcetype LVector4f
forcetype Vertexf
forcetype Normalf
forcetype TexCoordf
forcetype Colorf
forcetype RGBColorf
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
forcetype PTA_Normalf
forcetype PTA_TexCoordf
forcetype PTA_Colorf
renametype PTA_Vertexf PTA_Vertexf
renametype PTA_Normalf PTA_Normalf
renametype PTA_TexCoordf PTA_TexCoordf
renametype PTA_Colorf PTA_Colorf

View File

@ -1,14 +0,0 @@
// Filename: luse.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "luse.h"
// This tells GCC to explicitly instantiate the templates defined in
// luse.h and leave them here.
#ifdef __GNUC__
#pragma implementation
#endif

View File

@ -1,144 +0,0 @@
// Filename: luse.h
// Created by: drose (13Jan99)
//
////////////////////////////////////////////////////////////////////
#ifndef LUSE_H
#define LUSE_H
////////////////////////////////////////////////////////////////////
//
// This file defines a number of vector-based classes that are
// designed for specific uses. These all inherit from LVecBase, which
// is the base class of all linear algebra vectors.
//
// LPoint<P_numtype, N_length>
//
// This should be used to represent a specific point in space. It
// inherits most properties from LVecBase.
//
// LVector<P_numtype, N_length>
//
// This should be used to represent a vector, or a distance between
// two points in space.
//
// The distinction between LPoint and LVector is worth emphasizing.
// They differ in some subtle typing behavior (vector - vector =
// vector, point + vector = point, point - point = vector) and also in
// the way they are transformed when multiplied by a matrix (a point
// gets the translation component of the matrix, while the vector does
// not). Also, vector has length() and normalize() functions defined
// for it, while point does not.
//
// LPoint and LVector should be used whenever the concept of "point"
// or "vector" applies. If neither applies--for instance, if you are
// storing a plane equation in a vector or some such nonsense--use the
// base class, LVecBase.
//
// This file also defines the following:
//
// 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.
// (Color is a four-component color; RGBColor is three-component.)
//
////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include "lvec2_ops.h"
#include "lvec3_ops.h"
#include "lvec4_ops.h"
#include "lmat_ops.h"
#include "lmatrix.h"
#include "lquaternion.h"
#include "lrotation.h"
#include "lorientation.h"
// This macro defines the cast-to-another-numeric-type operator for
// all of the things defined in this package. It works by virtue of
// there being an appropriate lcast_to() template function defined for
// each class.
#define LCAST(numeric_type, object) lcast_to((numeric_type *)0, object)
// Tell GCC that we'll take care of the instantiation explicitly here.
#ifdef __GNUC__
#pragma interface
#endif
// Now we define some handy typedefs for these classes.
typedef LVecBase2<float> LVecBase2f;
typedef LVecBase3<float> LVecBase3f;
typedef LVecBase4<float> LVecBase4f;
typedef LVector2<float> LVector2f;
typedef LVector3<float> LVector3f;
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;
typedef LVector2<double> LVector2d;
typedef LVector3<double> LVector3d;
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 LQuaternionBase<float> LQuaternionf;
typedef LRotation<float> LRotationf;
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
// anywhere, but interrogate can't know how to instantiate template
// functions, so we pretend these are real functions.
#ifdef CPPPARSER
INLINE ostream &operator << (ostream &out, const LVecBase2f &vec);
INLINE ostream &operator << (ostream &out, const LVecBase3f &vec);
INLINE ostream &operator << (ostream &out, const LVecBase4f &vec);
INLINE ostream &operator << (ostream &out, const LMatrix3f &mat);
INLINE ostream &operator << (ostream &out, const LMatrix4f &mat);
INLINE ostream &operator << (ostream &out, const LQuaternionf &q);
INLINE ostream &operator << (ostream &out, const LVecBase2d &vec);
INLINE ostream &operator << (ostream &out, const LVecBase3d &vec);
INLINE ostream &operator << (ostream &out, const LVecBase4d &vec);
INLINE ostream &operator << (ostream &out, const LMatrix3d &mat);
INLINE ostream &operator << (ostream &out, const LMatrix4d &mat);
INLINE ostream &operator << (ostream &out, const LQuaterniond &q);
#endif
*/
#endif

View File

@ -1,54 +0,0 @@
// Filename: lvec2_ops.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LVEC2_OPS_H
#define LVEC2_OPS_H
#include "lvecBase2.h"
#include "lpoint2.h"
#include "lvector2.h"
// 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 "lvec2_ops.I"
#endif

View File

@ -1,19 +1,14 @@
// Filename: lvec2_ops.I
// Filename: lvec2_ops_src.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include <math.h>
#include "nearly_zero.h"
////////////////////////////////////////////////////////////////////
// Function: scalar * LVecBase2
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LVecBase2<NumType>
operator * (NumType2 scalar, const LVecBase2<NumType> &a) {
INLINE FLOATNAME(LVecBase2)
operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase2) &a) {
return a * scalar;
}
@ -21,9 +16,8 @@ operator * (NumType2 scalar, const LVecBase2<NumType> &a) {
// Function: scalar * LPoint2
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LPoint2<NumType>
operator * (NumType2 scalar, const LPoint2<NumType> &a) {
INLINE FLOATNAME(LPoint2)
operator * (FLOATTYPE scalar, const FLOATNAME(LPoint2) &a) {
return a * scalar;
}
@ -31,9 +25,8 @@ operator * (NumType2 scalar, const LPoint2<NumType> &a) {
// Function: scalar * LVector2
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LVector2<NumType>
operator * (NumType2 scalar, const LVector2<NumType> &a) {
INLINE FLOATNAME(LVector2)
operator * (FLOATTYPE scalar, const FLOATNAME(LVector2) &a) {
return a * scalar;
}
@ -41,51 +34,27 @@ operator * (NumType2 scalar, const LVector2<NumType> &a) {
// Function: dot product of LVecBase2
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType
dot(const LVecBase2<NumType> &a, const LVecBase2<NumType> &b) {
INLINE FLOATTYPE
dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &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:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType
length(const LVector2<NumType> &a) {
INLINE FLOATTYPE
length(const FLOATNAME(LVector2) &a) {
return a.length();
}
////////////////////////////////////////////////////////////////////
// Function: normalize
// Description: Returns a normalized vector from the given vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector2<NumType>
normalize(const LVector2<NumType> &v) {
LVector2<NumType> v1 = v;
INLINE FLOATNAME(LVector2)
normalize(const FLOATNAME(LVector2) &v) {
FLOATNAME(LVector2) v1 = v;
v1.normalize();
return v1;
}

View File

@ -0,0 +1,40 @@
// Filename: lvec2_ops_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
// 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(LVecBase2)
operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase2) &a);
INLINE FLOATNAME(LPoint2)
operator * (FLOATTYPE scalar, const FLOATNAME(LPoint2) &a);
INLINE FLOATNAME(LVector2)
operator * (FLOATTYPE scalar, const FLOATNAME(LVector2) &a);
// dot product
INLINE FLOATTYPE
dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b);
// Length of a vector.
INLINE FLOATTYPE
length(const FLOATNAME(LVector2) &a);
// A normalized vector.
INLINE FLOATNAME(LVector2)
normalize(const FLOATNAME(LVector2) &v);
#include "lvec2_ops_src.I"

View File

@ -1,64 +0,0 @@
// Filename: lvec3_ops.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LVEC3_OPS_H
#define LVEC3_OPS_H
#include "lvecBase3.h"
#include "lpoint3.h"
#include "lvector3.h"
// 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 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

View File

@ -1,19 +1,15 @@
// Filename: lvec3_ops.I
// Filename: lvec3_ops_src.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include <math.h>
#include "nearly_zero.h"
////////////////////////////////////////////////////////////////////
// Function: scalar * LVecBase3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LVecBase3<NumType>
operator * (NumType2 scalar, const LVecBase3<NumType> &a) {
INLINE FLOATNAME(LVecBase3)
operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase3) &a) {
return a * scalar;
}
@ -21,9 +17,8 @@ operator * (NumType2 scalar, const LVecBase3<NumType> &a) {
// Function: scalar * LPoint3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LPoint3<NumType>
operator * (NumType2 scalar, const LPoint3<NumType> &a) {
INLINE FLOATNAME(LPoint3)
operator * (FLOATTYPE scalar, const FLOATNAME(LPoint3) &a) {
return a * scalar;
}
@ -31,9 +26,8 @@ operator * (NumType2 scalar, const LPoint3<NumType> &a) {
// Function: scalar * LVector3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LVector3<NumType>
operator * (NumType2 scalar, const LVector3<NumType> &a) {
INLINE FLOATNAME(LVector3)
operator * (FLOATTYPE scalar, const FLOATNAME(LVector3) &a) {
return a * scalar;
}
@ -41,9 +35,9 @@ operator * (NumType2 scalar, const LVector3<NumType> &a) {
// Function: dot product of LVecBase3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType
dot(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b) {
INLINE FLOATTYPE
dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) {
return a.dot(b);
}
@ -51,9 +45,9 @@ dot(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b) {
// Function: cross product of LVecBase3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>
cross(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b) {
INLINE FLOATNAME(LVecBase3)
cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) {
return a.cross(b);
}
@ -61,10 +55,10 @@ cross(const LVecBase3<NumType> &a, const LVecBase3<NumType> &b) {
// Function: cross product of LVector3
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector3<NumType>
cross(const LVector3<NumType> &a, const LVector3<NumType> &b) {
return LVector3<NumType>(a.cross(b));
INLINE FLOATNAME(LVector3)
cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) {
return FLOATNAME(LVector3)(a.cross(b));
}
@ -72,9 +66,9 @@ cross(const LVector3<NumType> &a, const LVector3<NumType> &b) {
// Function: length of a vector
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType
length(const LVector3<NumType> &a) {
INLINE FLOATTYPE
length(const FLOATNAME(LVector3) &a) {
return a.length();
}
@ -83,10 +77,10 @@ length(const LVector3<NumType> &a) {
// Function: normalize
// Description: Returns a normalized vector from the given vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector3<NumType>
normalize(const LVector3<NumType> &v) {
LVector3<NumType> v1 = v;
INLINE FLOATNAME(LVector3)
normalize(const FLOATNAME(LVector3) &v) {
FLOATNAME(LVector3) v1 = v;
v1.normalize();
return v1;
}

View File

@ -0,0 +1,44 @@
// Filename: lvec3_ops_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
// 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 * (FLOATTYPE scalar, const FLOATNAME(LVecBase3) &a);
INLINE FLOATNAME(LPoint3)
operator * (FLOATTYPE scalar, const FLOATNAME(LPoint3) &a);
INLINE FLOATNAME(LVector3)
operator * (FLOATTYPE scalar, const FLOATNAME(LVector3) &a);
// dot product
INLINE FLOATTYPE
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 FLOATTYPE
length(const FLOATNAME(LVector3) &a);
// A normalized vector.
INLINE FLOATNAME(LVector3)
normalize(const FLOATNAME(LVector3) &v);
#include "lvec3_ops_src.I"

View File

@ -1,54 +0,0 @@
// Filename: lvec4_ops.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LVEC4_OPS_H
#define LVEC4_OPS_H
#include "lvecBase4.h"
#include "lpoint4.h"
#include "lvector4.h"
// 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 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

View File

@ -1,19 +1,14 @@
// Filename: lvec4_ops.I
// Filename: lvec4_ops_src.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include <math.h>
#include "nearly_zero.h"
////////////////////////////////////////////////////////////////////
// Function: scalar * LVecBase4
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LVecBase4<NumType>
operator * (NumType2 scalar, const LVecBase4<NumType> &a) {
INLINE FLOATNAME(LVecBase4)
operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase4) &a) {
return a * scalar;
}
@ -21,9 +16,8 @@ operator * (NumType2 scalar, const LVecBase4<NumType> &a) {
// Function: scalar * LPoint4
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LPoint4<NumType>
operator * (NumType2 scalar, const LPoint4<NumType> &a) {
INLINE FLOATNAME(LPoint4)
operator * (FLOATTYPE scalar, const FLOATNAME(LPoint4) &a) {
return a * scalar;
}
@ -31,9 +25,8 @@ operator * (NumType2 scalar, const LPoint4<NumType> &a) {
// Function: scalar * LVector4
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType, class NumType2>
INLINE LVector4<NumType>
operator * (NumType2 scalar, const LVector4<NumType> &a) {
INLINE FLOATNAME(LVector4)
operator * (FLOATTYPE scalar, const FLOATNAME(LVector4) &a) {
return a * scalar;
}
@ -41,9 +34,9 @@ operator * (NumType2 scalar, const LVector4<NumType> &a) {
// Function: dot product of LVecBase4
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType
dot(const LVecBase4<NumType> &a, const LVecBase4<NumType> &b) {
INLINE FLOATTYPE
dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b) {
return a.dot(b);
}
@ -51,9 +44,9 @@ dot(const LVecBase4<NumType> &a, const LVecBase4<NumType> &b) {
// Function: length of a vector
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType
length(const LVector4<NumType> &a) {
INLINE FLOATTYPE
length(const FLOATNAME(LVector4) &a) {
return a.length();
}
@ -62,10 +55,10 @@ length(const LVector4<NumType> &a) {
// Function: normalize
// Description: Returns a normalized vector from the given vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVector4<NumType>
normalize(const LVector4<NumType> &v) {
LVector4<NumType> v1 = v;
INLINE FLOATNAME(LVector4)
normalize(const FLOATNAME(LVector4) &v) {
FLOATNAME(LVector4) v1 = v;
v1.normalize();
return v1;
}

View File

@ -0,0 +1,38 @@
// Filename: lvec4_ops_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
// 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 * (FLOATTYPE scalar, const FLOATNAME(LVecBase4) &a);
INLINE FLOATNAME(LPoint4)
operator * (FLOATTYPE scalar, const FLOATNAME(LPoint4) &a);
INLINE FLOATNAME(LVector4)
operator * (FLOATTYPE scalar, const FLOATNAME(LVector4) &a);
// dot product
INLINE FLOATTYPE
dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b);
// Length of a vector.
INLINE FLOATTYPE
length(const FLOATNAME(LVector4) &a);
// A normalized vector.
INLINE FLOATNAME(LVector4)
normalize(const FLOATNAME(LVector4) &v);
#include "lvec4_ops_src.I"

View File

@ -1,604 +0,0 @@
// Filename: lvecBase2.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "nearly_zero.h"
#include <notify.h>
#include <datagram.h>
#include <datagramIterator.h>
template<class NumType>
TypeHandle LVecBase2<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Default Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::
LVecBase2() {
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::
LVecBase2(const LVecBase2<NumType> &copy) {
(*this) = copy;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> &LVecBase2<NumType>::
operator = (const LVecBase2<NumType> &copy) {
set(copy[0], copy[1]);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Fill Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> &LVecBase2<NumType>::
operator = (NumType fill_value) {
fill(fill_value);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::
LVecBase2(NumType fill_value) {
fill(fill_value);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::
LVecBase2(NumType x, NumType y) {
set(x, y);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::zero Named Constructor
// Access: Public
// Description: Returns a zero-length vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LVecBase2<NumType>::
zero() {
return LVecBase2<NumType>(0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::unit_x Named Constructor
// Access: Public
// Description: Returns a unit X vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LVecBase2<NumType>::
unit_x() {
return LVecBase2<NumType>(1.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::unit_y Named Constructor
// Access: Public
// Description: Returns a unit Y vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LVecBase2<NumType>::
unit_y() {
return LVecBase2<NumType>(0.0, 1.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::
~LVecBase2() {
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Indexing Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase2<NumType>::
operator [](int i) const {
nassertr(i >= 0 && i < 2, 0);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::Indexing Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType &LVecBase2<NumType>::
operator [](int i) {
nassertr(i >= 0 && i < 2, _data[0]);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::is_nan
// Access: Public
// Description: Returns true if any component of the vector is
// not-a-number, false otherwise.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase2<NumType>::
is_nan() const {
return cnan(_data[0]) || cnan(_data[1]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::get_cell
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase2<NumType>::
get_cell(int i) const {
nassertr(i >= 0 && i < 2, 0);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::get_x
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase2<NumType>::
get_x() const {
return _data[0];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::get_y
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase2<NumType>::
get_y() const {
return _data[1];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::set_cell
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
set_cell(int i, NumType value) {
nassertv(i >= 0 && i < 2);
_data[i] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::set_x
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
set_x(NumType value) {
_data[0] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::set_y
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
set_y(NumType value) {
_data[1] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::get_data
// Access: Public
// Description: Returns the address of the first of the two data
// elements in the vector. The next element
// occupies the next position consecutively in memory.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE const NumType *LVecBase2<NumType>::
get_data() const {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::get_num_components
// Access: Public
// Description: Returns the number of elements in the vector, two.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE int LVecBase2<NumType>::
get_num_components() const {
return 2;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::begin
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::iterator LVecBase2<NumType>::
begin() {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::end
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::iterator LVecBase2<NumType>::
end() {
return begin() + get_num_components();
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::begin
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::const_iterator LVecBase2<NumType>::
begin() const {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::end
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType>::const_iterator LVecBase2<NumType>::
end() const {
return begin() + get_num_components();
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::fill
// Access: Public
// Description: Sets each element of the vector to the indicated
// fill_value. This is particularly useful for
// initializing to zero.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
fill(NumType fill_value) {
_data[0] = fill_value;
_data[1] = fill_value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::set
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
set(NumType x, NumType y) {
_data[0] = x;
_data[1] = y;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::dot
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase2<NumType>::
dot(const LVecBase2<NumType> &other) const {
return _data[0] * other[0] + _data[1] * other[1];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator <
// Access: Public
// Description: This performs a lexicographical comparison. It's of
// questionable mathematical meaning, but sometimes has
// a practical purpose for sorting unique vectors,
// especially in an STL container. Also see
// compare_to().
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase2<NumType>::
operator < (const LVecBase2<NumType> &other) const {
return (compare_to(other) < 0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator ==
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase2<NumType>::
operator == (const LVecBase2<NumType> &other) const {
return (_data[0] == other[0] &&
_data[1] == other[1]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator !=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase2<NumType>::
operator != (const LVecBase2<NumType> &other) const {
return !operator == (other);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::compare_to
// Access: Public
// Description: This flavor of compare_to uses a default threshold
// value based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE int LVecBase2<NumType>::
compare_to(const LVecBase2<NumType> &other) const {
return compare_to(other, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::compare_to
// Access: Public
// Description: Sorts vectors lexicographically, componentwise.
// Returns a number less than 0 if this vector sorts
// before the other one, greater than zero if it sorts
// after, 0 if they are equivalent (within the indicated
// tolerance).
////////////////////////////////////////////////////////////////////
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;
}
if (!IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)) {
return (_data[1] < other[1]) ? -1 : 1;
}
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::unary -
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LVecBase2<NumType>::
operator - () const {
return LVecBase2<NumType>(-_data[0], -_data[1]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::vector + vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::vector - vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::vector * scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LVecBase2<NumType>::
operator * (NumType scalar) const {
return LVecBase2<NumType>(_data[0] * scalar,
_data[1] * scalar);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::vector / scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase2<NumType> LVecBase2<NumType>::
operator / (NumType scalar) const {
return LVecBase2<NumType>(_data[0] / scalar,
_data[1] / scalar);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator +=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
operator += (const LVecBase2<NumType> &other) {
_data[0] += other[0];
_data[1] += other[1];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator -=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
operator -= (const LVecBase2<NumType> &other) {
_data[0] -= other[0];
_data[1] -= other[1];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator *=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
operator *= (NumType scalar) {
_data[0] *= scalar;
_data[1] *= scalar;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator /=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase2<NumType>::
operator /= (NumType scalar) {
_data[0] /= scalar;
_data[1] /= scalar;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::almost_equal
// Access: Public
// Description: Returns true if two vectors are memberwise equal
// within a specified tolerance.
////////////////////////////////////////////////////////////////////
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));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::almost_equal
// Access: Public
// Description: Returns true if two vectors are memberwise equal
// within a default tolerance based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase2<NumType>::
almost_equal(const LVecBase2<NumType> &other) const {
return almost_equal(other, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::output
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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
////////////////////////////////////////////////////////////////////
template<class NumType>
void LVecBase2<NumType>::
write_datagram(Datagram &destination) const {
destination.add_float32(_data[0]);
destination.add_float32(_data[1]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::read_datagram
// Access: Public
// Description: Function to read itself from a datagramIterator
////////////////////////////////////////////////////////////////////
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]);
}

View File

@ -1,13 +0,0 @@
// Filename: lvecBase2.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "lvecBase2.h"
#include "fltnames.I"
#include "lvecBase2_src.I"
#include "dblnames.I"
#include "lvecBase2_src.I"

View File

@ -1,135 +0,0 @@
// Filename: lvecBase2.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LVECBASE2_H
#define LVECBASE2_H
#include <pandabase.h>
#include "cmath.h"
#include <typeHandle.h>
class Datagram;
class DatagramIterator;
////////////////////////////////////////////////////////////////////
// Class : LVecBase2
// Description : This is the base class for all two-component
// vectors and points.
////////////////////////////////////////////////////////////////////
template<class NumType>
class LVecBase2 {
PUBLISHED:
typedef const NumType *iterator;
typedef const NumType *const_iterator;
INLINE LVecBase2();
INLINE LVecBase2(const LVecBase2<NumType> &copy);
INLINE LVecBase2<NumType> &operator = (const LVecBase2<NumType> &copy);
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

View File

@ -1,23 +1,28 @@
// Filename: lvecBase2.I
// Filename: lvecBase2_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LVecBase2)::_type_handle;
const FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::_zero =
FLOATNAME(LVecBase2)(0.0, 0.0);
const FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::_unit_x =
FLOATNAME(LVecBase2)(1.0, 0.0);
const FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::_unit_y =
FLOATNAME(LVecBase2)(0.0, 1.0);
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::init_type
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
void FLOATNAME(LVecBase2)::
init_type() {
if (_type_handle == TypeHandle::none()) {
// Format a string to describe the type.
do_init_type(FLOATTYPE1);
string name =
"LVecBase2<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LVecBase2";
name += FLOATTOKEN;
register_type(_type_handle, name);
}
}

View File

@ -0,0 +1,115 @@
// Filename: lvecBase2_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : LVecBase2
// Description : This is the base class for all two-component
// vectors and points.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LVecBase2) {
PUBLISHED:
typedef const FLOATTYPE *iterator;
typedef const FLOATTYPE *const_iterator;
INLINE FLOATNAME(LVecBase2)();
INLINE FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) &copy);
INLINE FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) &copy);
INLINE FLOATNAME(LVecBase2) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LVecBase2)(FLOATTYPE fill_value);
INLINE FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y);
INLINE static const FLOATNAME(LVecBase2) &zero();
INLINE static const FLOATNAME(LVecBase2) &unit_x();
INLINE static const FLOATNAME(LVecBase2) &unit_y();
INLINE ~FLOATNAME(LVecBase2)();
INLINE FLOATTYPE operator [](int i) const;
INLINE FLOATTYPE &operator [](int i);
INLINE bool is_nan() const;
INLINE FLOATTYPE get_cell(int i) const;
INLINE FLOATTYPE get_x() const;
INLINE FLOATTYPE get_y() const;
INLINE void set_cell(int i, FLOATTYPE value);
INLINE void set_x(FLOATTYPE value);
INLINE void set_y(FLOATTYPE value);
INLINE const FLOATTYPE *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(FLOATTYPE fill_value);
INLINE void set(FLOATTYPE x, FLOATTYPE y);
INLINE FLOATTYPE 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,
FLOATTYPE 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 * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LVecBase2) operator / (FLOATTYPE scalar) const;
INLINE void operator += (const FLOATNAME(LVecBase2) &other);
INLINE void operator -= (const FLOATNAME(LVecBase2) &other);
INLINE void operator *= (FLOATTYPE scalar);
INLINE void operator /= (FLOATTYPE scalar);
INLINE bool almost_equal(const FLOATNAME(LVecBase2) &other,
FLOATTYPE threshold) const;
INLINE bool almost_equal(const FLOATNAME(LVecBase2) &other) const;
INLINE void output(ostream &out) const;
protected:
FLOATTYPE _data[2];
private:
static const FLOATNAME(LVecBase2) _zero;
static const FLOATNAME(LVecBase2) _unit_x;
static const FLOATNAME(LVecBase2) _unit_y;
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;
}
#include "lvecBase2_src.I"

View File

@ -1,680 +0,0 @@
// Filename: lvecBase3.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "nearly_zero.h"
#include <notify.h>
#include <datagram.h>
#include <datagramIterator.h>
template<class NumType>
TypeHandle LVecBase3<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Default Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::
LVecBase3() {
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::
LVecBase3(const LVecBase3<NumType> &copy) {
(*this) = copy;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> &LVecBase3<NumType>::
operator = (const LVecBase3<NumType> &copy) {
set(copy[0], copy[1], copy[2]);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Fill Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> &LVecBase3<NumType>::
operator = (NumType fill_value) {
fill(fill_value);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::
LVecBase3(NumType fill_value) {
fill(fill_value);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::
LVecBase3(NumType x, NumType y, NumType z) {
set(x, y, z);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::zero Named Constructor
// Access: Public
// Description: Returns a zero-length vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
zero() {
return LVecBase3<NumType>(0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::unit_x Named Constructor
// Access: Public
// Description: Returns a unit X vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
unit_x() {
return LVecBase3<NumType>(1.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::unit_y Named Constructor
// Access: Public
// Description: Returns a unit Y vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
unit_y() {
return LVecBase3<NumType>(0.0, 1.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::unit_z Named Constructor
// Access: Public
// Description: Returns a unit Z vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
unit_z() {
return LVecBase3<NumType>(0.0, 0.0, 1.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::
~LVecBase3() {
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Indexing Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase3<NumType>::
operator [](int i) const {
nassertr(i >= 0 && i < 3, 0);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::Indexing Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType &LVecBase3<NumType>::
operator [](int i) {
nassertr(i >= 0 && i < 3, _data[0]);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::is_nan
// Access: Public
// Description: Returns true if any component of the vector is
// not-a-number, false otherwise.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase3<NumType>::
is_nan() const {
return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_cell
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase3<NumType>::
get_cell(int i) const {
nassertr(i >= 0 && i < 3, 0);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_x
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase3<NumType>::
get_x() const {
return _data[0];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_y
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase3<NumType>::
get_y() const {
return _data[1];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_z
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase3<NumType>::
get_z() const {
return _data[2];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::set_cell
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
set_cell(int i, NumType value) {
nassertv(i >= 0 && i < 3);
_data[i] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::set_x
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
set_x(NumType value) {
_data[0] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::set_y
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
set_y(NumType value) {
_data[1] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::set_z
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
set_z(NumType value) {
_data[2] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_data
// Access: Public
// Description: Returns the address of the first of the three data
// elements in the vector. The remaining elements
// occupy the next positions consecutively in memory.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE const NumType *LVecBase3<NumType>::
get_data() const {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_num_components
// Access: Public
// Description: Returns the number of elements in the vector, three.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE int LVecBase3<NumType>::
get_num_components() const {
return 3;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::begin
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::iterator LVecBase3<NumType>::
begin() {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::end
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::iterator LVecBase3<NumType>::
end() {
return begin() + get_num_components();
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::begin
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::const_iterator LVecBase3<NumType>::
begin() const {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::end
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType>::const_iterator LVecBase3<NumType>::
end() const {
return begin() + get_num_components();
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::fill
// Access: Public
// Description: Sets each element of the vector to the indicated
// fill_value. This is particularly useful for
// initializing to zero.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
fill(NumType fill_value) {
_data[0] = fill_value;
_data[1] = fill_value;
_data[2] = fill_value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::set
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
set(NumType x, NumType y, NumType z) {
_data[0] = x;
_data[1] = y;
_data[2] = z;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::dot
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::cross
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator <
// Access: Public
// Description: This performs a lexicographical comparison. It's of
// questionable mathematical meaning, but sometimes has
// a practical purpose for sorting unique vectors,
// especially in an STL container. Also see
// compare_to().
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase3<NumType>::
operator < (const LVecBase3<NumType> &other) const {
return (compare_to(other) < 0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator ==
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator !=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase3<NumType>::
operator != (const LVecBase3<NumType> &other) const {
return !operator == (other);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::compare_to
// Access: Public
// Description: This flavor of compare_to uses a default threshold
// value based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE int LVecBase3<NumType>::
compare_to(const LVecBase3<NumType> &other) const {
return compare_to(other, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::compare_to
// Access: Public
// Description: Sorts vectors lexicographically, componentwise.
// Returns a number less than 0 if this vector sorts
// before the other one, greater than zero if it sorts
// after, 0 if they are equivalent (within the indicated
// tolerance).
////////////////////////////////////////////////////////////////////
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;
}
if (!IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)) {
return (_data[1] < other[1]) ? -1 : 1;
}
if (!IS_THRESHOLD_EQUAL(_data[2], other[2], threshold)) {
return (_data[2] < other[2]) ? -1 : 1;
}
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::unary -
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
operator - () const {
return LVecBase3<NumType>(-_data[0], -_data[1], -_data[2]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector + vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector - vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector * scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
operator * (NumType scalar) const {
return LVecBase3<NumType>(_data[0] * scalar,
_data[1] * scalar,
_data[2] * scalar);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector / scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase3<NumType> LVecBase3<NumType>::
operator / (NumType scalar) const {
return LVecBase3<NumType>(_data[0] / scalar,
_data[1] / scalar,
_data[2] / scalar);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator +=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
operator += (const LVecBase3<NumType> &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator -=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
operator -= (const LVecBase3<NumType> &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator *=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
operator *= (NumType scalar) {
_data[0] *= scalar;
_data[1] *= scalar;
_data[2] *= scalar;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator /=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
operator /= (NumType scalar) {
_data[0] /= scalar;
_data[1] /= scalar;
_data[2] /= scalar;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::cross product (with assigment)
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase3<NumType>::
cross_into(const LVecBase3<NumType> &other) {
(*this) = cross(other);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::almost_equal
// Access: Public
// Description: Returns true if two vectors are memberwise equal
// within a specified tolerance.
////////////////////////////////////////////////////////////////////
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));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::almost_equal
// Access: Public
// Description: Returns true if two vectors are memberwise equal
// within a default tolerance based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase3<NumType>::
almost_equal(const LVecBase3<NumType> &other) const {
return almost_equal(other, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::output
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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
////////////////////////////////////////////////////////////////////
template<class NumType>
void LVecBase3<NumType>::
write_datagram(Datagram &destination) const {
destination.add_float32(_data[0]);
destination.add_float32(_data[1]);
destination.add_float32(_data[2]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::read_datagram
// Access: Public
// Description: Function to read itself from a datagramIterator
////////////////////////////////////////////////////////////////////
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]);
}

View File

@ -1,13 +0,0 @@
// Filename: lvecBase3.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "lvecBase3.h"
#include "fltnames.I"
#include "lvecBase3_src.I"
#include "dblnames.I"
#include "lvecBase3_src.I"

View File

@ -1,141 +0,0 @@
// Filename: lvecBase3.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#ifndef LVECBASE3_H
#define LVECBASE3_H
#include <pandabase.h>
#include "cmath.h"
#include <typeHandle.h>
class Datagram;
class DatagramIterator;
////////////////////////////////////////////////////////////////////
// Class : LVecBase3
// Description : This is the base class for all three-component
// vectors and points.
////////////////////////////////////////////////////////////////////
template<class NumType>
class LVecBase3 {
PUBLISHED:
typedef const NumType *iterator;
typedef const NumType *const_iterator;
INLINE LVecBase3();
INLINE LVecBase3(const LVecBase3<NumType> &copy);
INLINE LVecBase3<NumType> &operator = (const LVecBase3<NumType> &copy);
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;
}
// 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

View File

@ -1,10 +1,19 @@
// Filename: lvecBase3.I
// Filename: lvecBase3_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
TypeHandle FLOATNAME(LVecBase3)::_type_handle;
const FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::_zero =
FLOATNAME(LVecBase3)(0.0, 0.0, 0.0);
const FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::_unit_x =
FLOATNAME(LVecBase3)(1.0, 0.0, 0.0);
const FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::_unit_y =
FLOATNAME(LVecBase3)(0.0, 1.0, 0.0);
const FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::_unit_z =
FLOATNAME(LVecBase3)(0.0, 0.0, 1.0);
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::init_type
// Access: Public, Static
@ -15,9 +24,8 @@ void FLOATNAME(LVecBase3)::
init_type() {
if (_type_handle == TypeHandle::none()) {
// Format a string to describe the type.
do_init_type(FLOATTYPE1);
string name =
"LVecBase3<" + get_type_handle(FLOATTYPE1).get_name() + ">";
string name = "LVecBase3";
name += FLOATTOKEN;
register_type(_type_handle, name);
}
}

View File

@ -0,0 +1,122 @@
// Filename: lvecBase3_src.h
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : LVecBase3
// Description : This is the base class for all three-component
// vectors and points.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA FLOATNAME(LVecBase3) {
PUBLISHED:
typedef const FLOATTYPE *iterator;
typedef const FLOATTYPE *const_iterator;
INLINE FLOATNAME(LVecBase3)();
INLINE FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) &copy);
INLINE FLOATNAME(LVecBase3) &operator = (const FLOATNAME(LVecBase3) &copy);
INLINE FLOATNAME(LVecBase3) &operator = (FLOATTYPE fill_value);
INLINE FLOATNAME(LVecBase3)(FLOATTYPE fill_value);
INLINE FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
INLINE static const FLOATNAME(LVecBase3) &zero();
INLINE static const FLOATNAME(LVecBase3) &unit_x();
INLINE static const FLOATNAME(LVecBase3) &unit_y();
INLINE static const FLOATNAME(LVecBase3) &unit_z();
INLINE ~FLOATNAME(LVecBase3)();
INLINE FLOATTYPE operator [](int i) const;
INLINE FLOATTYPE &operator [](int i);
INLINE bool is_nan() const;
INLINE FLOATTYPE get_cell(int i) const;
INLINE FLOATTYPE get_x() const;
INLINE FLOATTYPE get_y() const;
INLINE FLOATTYPE get_z() const;
INLINE void set_cell(int i, FLOATTYPE value);
INLINE void set_x(FLOATTYPE value);
INLINE void set_y(FLOATTYPE value);
INLINE void set_z(FLOATTYPE value);
INLINE const FLOATTYPE *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(FLOATTYPE fill_value);
INLINE void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
INLINE FLOATTYPE 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,
FLOATTYPE 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 * (FLOATTYPE scalar) const;
INLINE FLOATNAME(LVecBase3) operator / (FLOATTYPE scalar) const;
INLINE void operator += (const FLOATNAME(LVecBase3) &other);
INLINE void operator -= (const FLOATNAME(LVecBase3) &other);
INLINE void operator *= (FLOATTYPE scalar);
INLINE void operator /= (FLOATTYPE scalar);
INLINE void cross_into(const FLOATNAME(LVecBase3) &other);
INLINE bool almost_equal(const FLOATNAME(LVecBase3) &other,
FLOATTYPE threshold) const;
INLINE bool almost_equal(const FLOATNAME(LVecBase3) &other) const;
INLINE void output(ostream &out) const;
protected:
FLOATTYPE _data[3];
private:
static const FLOATNAME(LVecBase3) _zero;
static const FLOATNAME(LVecBase3) _unit_x;
static const FLOATNAME(LVecBase3) _unit_y;
static const FLOATNAME(LVecBase3) _unit_z;
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;
};
#include "lvecBase3_src.I"

View File

@ -1,710 +0,0 @@
// Filename: lvecBase4.I
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "nearly_zero.h"
#include <notify.h>
#include <datagram.h>
#include <datagramIterator.h>
template<class NumType>
TypeHandle LVecBase4<NumType>::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Default Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::
LVecBase4() {
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::
LVecBase4(const LVecBase4<NumType> &copy) {
(*this) = copy;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> &LVecBase4<NumType>::
operator = (const LVecBase4<NumType> &copy) {
set(copy[0], copy[1], copy[2], copy[3]);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Fill Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> &LVecBase4<NumType>::
operator = (NumType fill_value) {
fill(fill_value);
return *this;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::
LVecBase4(NumType fill_value) {
fill(fill_value);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::
LVecBase4(NumType x, NumType y, NumType z, NumType w) {
set(x, y, z, w);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::
~LVecBase4() {
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::zero Named Constructor
// Access: Public
// Description: Returns a zero-length vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LVecBase4<NumType>::
zero() {
return LVecBase4<NumType>(0.0, 0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::unit_x Named Constructor
// Access: Public
// Description: Returns a unit X vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LVecBase4<NumType>::
unit_x() {
return LVecBase4<NumType>(1.0, 0.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::unit_y Named Constructor
// Access: Public
// Description: Returns a unit Y vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LVecBase4<NumType>::
unit_y() {
return LVecBase4<NumType>(0.0, 1.0, 0.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::unit_z Named Constructor
// Access: Public
// Description: Returns a unit Z vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LVecBase4<NumType>::
unit_z() {
return LVecBase4<NumType>(0.0, 0.0, 1.0, 0.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::unit_w Named Constructor
// Access: Public
// Description: Returns a unit W vector.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LVecBase4<NumType>::
unit_w() {
return LVecBase4<NumType>(0.0, 0.0, 0.0, 1.0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Indexing Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase4<NumType>::
operator [](int i) const {
nassertr(i >= 0 && i < 4, 0);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::Indexing Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType &LVecBase4<NumType>::
operator [](int i) {
nassertr(i >= 0 && i < 4, _data[0]);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::is_nan
// Access: Public
// Description: Returns true if any component of the vector is
// not-a-number, false otherwise.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase4<NumType>::
is_nan() const {
return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || cnan(_data[3]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_cell
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase4<NumType>::
get_cell(int i) const {
nassertr(i >= 0 && i < 4, 0);
return _data[i];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_x
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase4<NumType>::
get_x() const {
return _data[0];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_y
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase4<NumType>::
get_y() const {
return _data[1];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_z
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase4<NumType>::
get_z() const {
return _data[2];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_w
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE NumType LVecBase4<NumType>::
get_w() const {
return _data[3];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::set_cell
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
set_cell(int i, NumType value) {
nassertv(i >= 0 && i < 4);
_data[i] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::set_x
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
set_x(NumType value) {
_data[0] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::set_y
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
set_y(NumType value) {
_data[1] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::set_z
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
set_z(NumType value) {
_data[2] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::set_w
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
set_w(NumType value) {
_data[3] = value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_data
// Access: Public
// Description: Returns the address of the first of the four data
// elements in the vector. The remaining elements
// occupy the next positions consecutively in memory.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE const NumType *LVecBase4<NumType>::
get_data() const {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::get_num_components
// Access: Public
// Description: Returns the number of elements in the vector, four.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE int LVecBase4<NumType>::
get_num_components() const {
return 4;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::begin
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::iterator LVecBase4<NumType>::
begin() {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::end
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::iterator LVecBase4<NumType>::
end() {
return begin() + get_num_components();
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::begin
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::const_iterator LVecBase4<NumType>::
begin() const {
return _data;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::end
// Access: Public
// Description: Returns an iterator that may be used to traverse the
// elements of the matrix, STL-style.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType>::const_iterator LVecBase4<NumType>::
end() const {
return begin() + get_num_components();
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::fill
// Access: Public
// Description: Sets each element of the vector to the indicated
// fill_value. This is particularly useful for
// initializing to zero.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
fill(NumType fill_value) {
_data[0] = fill_value;
_data[1] = fill_value;
_data[2] = fill_value;
_data[3] = fill_value;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::set
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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;
_data[3] = w;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::dot
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator <
// Access: Public
// Description: This performs a lexicographical comparison. It's of
// questionable mathematical meaning, but sometimes has
// a practical purpose for sorting unique vectors,
// especially in an STL container. Also see
// compare_to().
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase4<NumType>::
operator < (const LVecBase4<NumType> &other) const {
return (compare_to(other) < 0);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator ==
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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] &&
_data[3] == other[3]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator !=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase4<NumType>::
operator != (const LVecBase4<NumType> &other) const {
return !operator == (other);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::compare_to
// Access: Public
// Description: This flavor of compare_to uses a default threshold
// value based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE int LVecBase4<NumType>::
compare_to(const LVecBase4<NumType> &other) const {
return compare_to(other, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::compare_to
// Access: Public
// Description: Sorts vectors lexicographically, componentwise.
// Returns a number less than 0 if this vector sorts
// before the other one, greater than zero if it sorts
// after, 0 if they are equivalent (within the indicated
// tolerance).
////////////////////////////////////////////////////////////////////
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;
}
if (!IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)) {
return (_data[1] < other[1]) ? -1 : 1;
}
if (!IS_THRESHOLD_EQUAL(_data[2], other[2], threshold)) {
return (_data[2] < other[2]) ? -1 : 1;
}
if (!IS_THRESHOLD_EQUAL(_data[3], other[3], threshold)) {
return (_data[3] < other[3]) ? -1 : 1;
}
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::unary -
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE LVecBase4<NumType> LVecBase4<NumType>::
operator - () const {
return LVecBase4<NumType>(-_data[0], -_data[1], -_data[2], -_data[3]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::vector + vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::vector - vector
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::vector * scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::vector / scalar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
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);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator +=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
operator += (const LVecBase4<NumType> &other) {
_data[0] += other[0];
_data[1] += other[1];
_data[2] += other[2];
_data[3] += other[3];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator -=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
operator -= (const LVecBase4<NumType> &other) {
_data[0] -= other[0];
_data[1] -= other[1];
_data[2] -= other[2];
_data[3] -= other[3];
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator *=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
operator *= (NumType scalar) {
_data[0] *= scalar;
_data[1] *= scalar;
_data[2] *= scalar;
_data[3] *= scalar;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator /=
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
operator /= (NumType scalar) {
_data[0] /= scalar;
_data[1] /= scalar;
_data[2] /= scalar;
_data[3] /= scalar;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::almost_equal
// Access: Public
// Description: Returns true if two vectors are memberwise equal
// within a specified tolerance.
////////////////////////////////////////////////////////////////////
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) &&
IS_THRESHOLD_EQUAL(_data[3], other[3], threshold));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::almost_equal
// Access: Public
// Description: Returns true if two vectors are memberwise equal
// within a default tolerance based on the numeric type.
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE bool LVecBase4<NumType>::
almost_equal(const LVecBase4<NumType> &other) const {
return almost_equal(other, NEARLY_ZERO(NumType));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::output
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
template<class NumType>
INLINE void LVecBase4<NumType>::
output(ostream &out) const {
out << MAYBE_ZERO(_data[0]) << " "
<< MAYBE_ZERO(_data[1]) << " "
<< MAYBE_ZERO(_data[2]) << " "
<< 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
////////////////////////////////////////////////////////////////////
template<class NumType>
void LVecBase4<NumType>::
write_datagram(Datagram &destination) const {
destination.add_float32(_data[0]);
destination.add_float32(_data[1]);
destination.add_float32(_data[2]);
destination.add_float32(_data[3]);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::read_datagram
// Access: Public
// Description: Function to read itself from a datagramIterator
////////////////////////////////////////////////////////////////////
template<class NumType>
void LVecBase4<NumType>::
read_datagram(DatagramIterator &source) {
_data[0] = source.get_float32();
_data[1] = source.get_float32();
_data[2] = source.get_float32();
_data[3] = 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 LVecBase4<NumType2>
lcast_to(NumType2 *, const LVecBase4<NumType> &source) {
return LVecBase4<NumType2>(source[0], source[1], source[2], source[3]);
}

View File

@ -1,13 +0,0 @@
// Filename: lvecBase4.cxx
// Created by: drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
#include "lvecBase4.h"
#include "fltnames.I"
#include "lvecBase4_src.I"
#include "dblnames.I"
#include "lvecBase4_src.I"

Some files were not shown because too many files have changed in this diff Show More