From ee8db5b5b57acf918d2bcf9305b61019d481ab30 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 4 Apr 2001 21:40:58 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/linmath/Sources.pp | 61 - panda/src/linmath/cast_to_double.I | 49 - panda/src/linmath/cast_to_double.h | 32 - panda/src/linmath/cast_to_float.I | 49 - panda/src/linmath/cast_to_float.h | 32 - panda/src/linmath/cmath.I | 106 -- panda/src/linmath/cmath.h | 40 - panda/src/linmath/compose_matrix.I | 77 - panda/src/linmath/compose_matrix.cxx | 708 -------- panda/src/linmath/compose_matrix.h | 124 -- ...se_matrix_src.I => compose_matrix_src.cxx} | 173 +- panda/src/linmath/compose_matrix_src.h | 60 + panda/src/linmath/config_linmath.cxx | 57 - panda/src/linmath/config_linmath.h | 14 - panda/src/linmath/coordinateSystem.cxx | 96 -- panda/src/linmath/coordinateSystem.h | 46 - panda/src/linmath/dbl2fltnames.h | 22 + panda/src/linmath/dblnames.I | 9 - panda/src/linmath/dblnames.h | 33 + panda/src/linmath/deg_2_rad.h | 19 - panda/src/linmath/flt2dblnames.h | 22 + panda/src/linmath/fltnames.I | 9 - panda/src/linmath/fltnames.h | 33 + panda/src/linmath/ioPtaDatagramLinMath.I | 45 - panda/src/linmath/ioPtaDatagramLinMath.cxx | 11 - panda/src/linmath/ioPtaDatagramLinMath.h | 62 - panda/src/linmath/lcast_to.h | 27 + panda/src/linmath/lcast_to_src.I | 67 + panda/src/linmath/lcast_to_src.h | 42 + panda/src/linmath/lmat_ops.h | 85 - .../linmath/{lmat_ops.I => lmat_ops_src.I} | 60 +- panda/src/linmath/lmat_ops_src.h | 33 + panda/src/linmath/lmatrix.cxx | 13 - panda/src/linmath/lmatrix.h | 25 - panda/src/linmath/lmatrix3.I | 1110 ------------ panda/src/linmath/lmatrix3.cxx | 15 - panda/src/linmath/lmatrix3.h | 194 --- .../{lmatrix3_src.I => lmatrix3_src.cxx} | 18 +- panda/src/linmath/lmatrix3_src.h | 167 ++ panda/src/linmath/lmatrix4.I | 1517 ----------------- panda/src/linmath/lmatrix4.cxx | 15 - panda/src/linmath/lmatrix4.h | 188 -- .../{lmatrix4_src.I => lmatrix4_src.cxx} | 53 +- panda/src/linmath/lmatrix4_src.h | 160 ++ panda/src/linmath/lorientation.I | 134 -- panda/src/linmath/lorientation.cxx | 13 - panda/src/linmath/lorientation.h | 47 - panda/src/linmath/lorientation_src.I | 33 - panda/src/linmath/lorientation_src.cxx | 22 + panda/src/linmath/lorientation_src.h | 34 + panda/src/linmath/lpoint2.I | 225 --- panda/src/linmath/lpoint2.cxx | 13 - panda/src/linmath/lpoint2.h | 69 - .../{lpoint2_src.I => lpoint2_src.cxx} | 6 +- panda/src/linmath/lpoint2_src.h | 51 + panda/src/linmath/lpoint3.I | 278 --- panda/src/linmath/lpoint3.cxx | 13 - panda/src/linmath/lpoint3.h | 85 - .../{lpoint3_src.I => lpoint3_src.cxx} | 6 +- panda/src/linmath/lpoint3_src.h | 65 + panda/src/linmath/lpoint4.I | 247 --- panda/src/linmath/lpoint4.cxx | 13 - panda/src/linmath/lpoint4.h | 71 - .../{lpoint4_src.I => lpoint4_src.cxx} | 6 +- panda/src/linmath/lpoint4_src.h | 52 + panda/src/linmath/lquaternion.I | 623 ------- panda/src/linmath/lquaternion.cxx | 13 - panda/src/linmath/lquaternion.h | 123 -- ...{lquaternion_src.I => lquaternion_src.cxx} | 177 +- panda/src/linmath/lquaternion_src.h | 80 + panda/src/linmath/lrotation.I | 142 -- panda/src/linmath/lrotation.cxx | 13 - panda/src/linmath/lrotation.h | 51 - .../{lrotation_src.I => lrotation_src.cxx} | 22 +- panda/src/linmath/lrotation_src.h | 35 + panda/src/linmath/luse.I | 4 - panda/src/linmath/luse.N | 85 - panda/src/linmath/luse.cxx | 14 - panda/src/linmath/luse.h | 144 -- panda/src/linmath/lvec2_ops.h | 54 - .../linmath/{lvec2_ops.I => lvec2_ops_src.I} | 59 +- panda/src/linmath/lvec2_ops_src.h | 40 + panda/src/linmath/lvec3_ops.h | 64 - .../linmath/{lvec3_ops.I => lvec3_ops_src.I} | 54 +- panda/src/linmath/lvec3_ops_src.h | 44 + panda/src/linmath/lvec4_ops.h | 54 - .../linmath/{lvec4_ops.I => lvec4_ops_src.I} | 41 +- panda/src/linmath/lvec4_ops_src.h | 38 + panda/src/linmath/lvecBase2.I | 604 ------- panda/src/linmath/lvecBase2.cxx | 13 - panda/src/linmath/lvecBase2.h | 135 -- .../{lvecBase2_src.I => lvecBase2_src.cxx} | 15 +- panda/src/linmath/lvecBase2_src.h | 115 ++ panda/src/linmath/lvecBase3.I | 680 -------- panda/src/linmath/lvecBase3.cxx | 13 - panda/src/linmath/lvecBase3.h | 141 -- .../{lvecBase3_src.I => lvecBase3_src.cxx} | 16 +- panda/src/linmath/lvecBase3_src.h | 122 ++ panda/src/linmath/lvecBase4.I | 710 -------- panda/src/linmath/lvecBase4.cxx | 13 - panda/src/linmath/lvecBase4.h | 141 -- panda/src/linmath/lvecBase4_src.I | 23 - panda/src/linmath/lvecBase4_src.cxx | 33 + panda/src/linmath/lvecBase4_src.h | 122 ++ panda/src/linmath/lvector2.I | 262 --- panda/src/linmath/lvector2.cxx | 13 - panda/src/linmath/lvector2.h | 69 - .../{lvector2_src.I => lvector2_src.cxx} | 6 +- panda/src/linmath/lvector2_src.h | 47 + panda/src/linmath/lvector3.I | 407 ----- panda/src/linmath/lvector3.cxx | 13 - panda/src/linmath/lvector3.h | 93 - .../{lvector3_src.I => lvector3_src.cxx} | 6 +- panda/src/linmath/lvector3_src.h | 70 + panda/src/linmath/lvector4.I | 285 ---- panda/src/linmath/lvector4.cxx | 13 - panda/src/linmath/lvector4.h | 70 - .../{lvector4_src.I => lvector4_src.cxx} | 6 +- panda/src/linmath/lvector4_src.h | 49 + panda/src/linmath/mathNumbers.cxx | 10 - panda/src/linmath/mathNumbers.h | 17 - panda/src/linmath/nearly_zero.h | 58 - panda/src/linmath/pta_Colorf.cxx | 11 - panda/src/linmath/pta_Colorf.h | 37 - panda/src/linmath/pta_Normalf.cxx | 11 - panda/src/linmath/pta_Normalf.h | 37 - panda/src/linmath/pta_TexCoordf.cxx | 11 - panda/src/linmath/pta_TexCoordf.h | 37 - panda/src/linmath/pta_Vertexf.cxx | 11 - panda/src/linmath/pta_Vertexf.h | 37 - panda/src/linmath/test_math.cxx | 147 -- panda/src/linmath/vector_Colorf.cxx | 11 - panda/src/linmath/vector_Colorf.h | 32 - panda/src/linmath/vector_LPoint2f.cxx | 11 - panda/src/linmath/vector_LPoint2f.h | 32 - panda/src/linmath/vector_LVecBase3f.cxx | 11 - panda/src/linmath/vector_LVecBase3f.h | 32 - panda/src/linmath/vector_Normalf.cxx | 11 - panda/src/linmath/vector_Normalf.h | 32 - panda/src/linmath/vector_TexCoordf.h | 20 - panda/src/linmath/vector_Vertexf.cxx | 11 - panda/src/linmath/vector_Vertexf.h | 32 - panda/src/mathutil/Sources.pp | 49 - panda/src/mathutil/boundingHexahedron.I | 30 - panda/src/mathutil/boundingHexahedron.cxx | 336 ---- panda/src/mathutil/boundingHexahedron.h | 109 -- panda/src/mathutil/boundingLine.I | 33 - panda/src/mathutil/boundingLine.cxx | 114 -- panda/src/mathutil/boundingLine.h | 81 - panda/src/mathutil/boundingSphere.I | 33 - panda/src/mathutil/boundingSphere.cxx | 455 ----- panda/src/mathutil/boundingSphere.h | 94 - panda/src/mathutil/boundingVolume.I | 112 -- panda/src/mathutil/boundingVolume.cxx | 191 --- panda/src/mathutil/boundingVolume.h | 147 -- panda/src/mathutil/config_mathutil.cxx | 32 - panda/src/mathutil/config_mathutil.h | 20 - panda/src/mathutil/fftCompressor.cxx | 849 --------- panda/src/mathutil/fftCompressor.h | 83 - panda/src/mathutil/finiteBoundingVolume.cxx | 8 - panda/src/mathutil/finiteBoundingVolume.h | 63 - panda/src/mathutil/frustum.N | 2 - panda/src/mathutil/frustum.h | 65 - .../src/mathutil/{frustum.I => frustum_src.I} | 124 +- panda/src/mathutil/frustum_src.h | 45 + panda/src/mathutil/geometricBoundingVolume.I | 108 -- .../src/mathutil/geometricBoundingVolume.cxx | 30 - panda/src/mathutil/geometricBoundingVolume.h | 76 - panda/src/mathutil/look_at.I | 79 - panda/src/mathutil/look_at.cxx | 342 ---- panda/src/mathutil/look_at.h | 95 -- .../{look_at_src.I => look_at_src.cxx} | 41 +- panda/src/mathutil/look_at_src.h | 50 + panda/src/mathutil/mathHelpers.I | 14 - panda/src/mathutil/mathHelpers.h | 24 - panda/src/mathutil/mathutil.h | 23 - panda/src/mathutil/omniBoundingVolume.I | 14 - panda/src/mathutil/omniBoundingVolume.cxx | 187 -- panda/src/mathutil/omniBoundingVolume.h | 76 - panda/src/mathutil/plane.N | 2 - panda/src/mathutil/plane.cxx | 14 - panda/src/mathutil/plane.h | 88 - panda/src/mathutil/{plane.I => plane_src.I} | 160 +- panda/src/mathutil/plane_src.cxx | 47 + panda/src/mathutil/plane_src.h | 53 + panda/src/mathutil/rotate_to.cxx | 92 - panda/src/mathutil/rotate_to.h | 35 - .../{rotate_to_src.I => rotate_to_src.cxx} | 15 +- panda/src/mathutil/test_mathutil.cxx | 53 - 189 files changed, 2300 insertions(+), 16692 deletions(-) delete mode 100644 panda/src/linmath/Sources.pp delete mode 100644 panda/src/linmath/cast_to_double.I delete mode 100644 panda/src/linmath/cast_to_double.h delete mode 100644 panda/src/linmath/cast_to_float.I delete mode 100644 panda/src/linmath/cast_to_float.h delete mode 100644 panda/src/linmath/cmath.I delete mode 100644 panda/src/linmath/cmath.h delete mode 100644 panda/src/linmath/compose_matrix.I delete mode 100644 panda/src/linmath/compose_matrix.cxx delete mode 100644 panda/src/linmath/compose_matrix.h rename panda/src/linmath/{compose_matrix_src.I => compose_matrix_src.cxx} (78%) create mode 100644 panda/src/linmath/compose_matrix_src.h delete mode 100644 panda/src/linmath/config_linmath.cxx delete mode 100644 panda/src/linmath/config_linmath.h delete mode 100644 panda/src/linmath/coordinateSystem.cxx delete mode 100644 panda/src/linmath/coordinateSystem.h create mode 100644 panda/src/linmath/dbl2fltnames.h delete mode 100644 panda/src/linmath/dblnames.I create mode 100644 panda/src/linmath/dblnames.h delete mode 100644 panda/src/linmath/deg_2_rad.h create mode 100644 panda/src/linmath/flt2dblnames.h delete mode 100644 panda/src/linmath/fltnames.I create mode 100644 panda/src/linmath/fltnames.h delete mode 100644 panda/src/linmath/ioPtaDatagramLinMath.I delete mode 100644 panda/src/linmath/ioPtaDatagramLinMath.cxx delete mode 100644 panda/src/linmath/ioPtaDatagramLinMath.h create mode 100644 panda/src/linmath/lcast_to.h create mode 100644 panda/src/linmath/lcast_to_src.I create mode 100644 panda/src/linmath/lcast_to_src.h delete mode 100644 panda/src/linmath/lmat_ops.h rename panda/src/linmath/{lmat_ops.I => lmat_ops_src.I} (56%) create mode 100644 panda/src/linmath/lmat_ops_src.h delete mode 100644 panda/src/linmath/lmatrix.cxx delete mode 100644 panda/src/linmath/lmatrix.h delete mode 100644 panda/src/linmath/lmatrix3.I delete mode 100644 panda/src/linmath/lmatrix3.cxx delete mode 100644 panda/src/linmath/lmatrix3.h rename panda/src/linmath/{lmatrix3_src.I => lmatrix3_src.cxx} (90%) create mode 100644 panda/src/linmath/lmatrix3_src.h delete mode 100644 panda/src/linmath/lmatrix4.I delete mode 100644 panda/src/linmath/lmatrix4.cxx delete mode 100644 panda/src/linmath/lmatrix4.h rename panda/src/linmath/{lmatrix4_src.I => lmatrix4_src.cxx} (87%) create mode 100644 panda/src/linmath/lmatrix4_src.h delete mode 100644 panda/src/linmath/lorientation.I delete mode 100644 panda/src/linmath/lorientation.cxx delete mode 100644 panda/src/linmath/lorientation.h delete mode 100644 panda/src/linmath/lorientation_src.I create mode 100644 panda/src/linmath/lorientation_src.cxx create mode 100644 panda/src/linmath/lorientation_src.h delete mode 100644 panda/src/linmath/lpoint2.I delete mode 100644 panda/src/linmath/lpoint2.cxx delete mode 100644 panda/src/linmath/lpoint2.h rename panda/src/linmath/{lpoint2_src.I => lpoint2_src.cxx} (84%) create mode 100644 panda/src/linmath/lpoint2_src.h delete mode 100644 panda/src/linmath/lpoint3.I delete mode 100644 panda/src/linmath/lpoint3.cxx delete mode 100644 panda/src/linmath/lpoint3.h rename panda/src/linmath/{lpoint3_src.I => lpoint3_src.cxx} (84%) create mode 100644 panda/src/linmath/lpoint3_src.h delete mode 100644 panda/src/linmath/lpoint4.I delete mode 100644 panda/src/linmath/lpoint4.cxx delete mode 100644 panda/src/linmath/lpoint4.h rename panda/src/linmath/{lpoint4_src.I => lpoint4_src.cxx} (84%) create mode 100644 panda/src/linmath/lpoint4_src.h delete mode 100644 panda/src/linmath/lquaternion.I delete mode 100644 panda/src/linmath/lquaternion.cxx delete mode 100644 panda/src/linmath/lquaternion.h rename panda/src/linmath/{lquaternion_src.I => lquaternion_src.cxx} (52%) create mode 100644 panda/src/linmath/lquaternion_src.h delete mode 100644 panda/src/linmath/lrotation.I delete mode 100644 panda/src/linmath/lrotation.cxx delete mode 100644 panda/src/linmath/lrotation.h rename panda/src/linmath/{lrotation_src.I => lrotation_src.cxx} (53%) create mode 100644 panda/src/linmath/lrotation_src.h delete mode 100644 panda/src/linmath/luse.I delete mode 100644 panda/src/linmath/luse.N delete mode 100644 panda/src/linmath/luse.cxx delete mode 100644 panda/src/linmath/luse.h delete mode 100644 panda/src/linmath/lvec2_ops.h rename panda/src/linmath/{lvec2_ops.I => lvec2_ops_src.I} (50%) create mode 100644 panda/src/linmath/lvec2_ops_src.h delete mode 100644 panda/src/linmath/lvec3_ops.h rename panda/src/linmath/{lvec3_ops.I => lvec3_ops_src.I} (65%) create mode 100644 panda/src/linmath/lvec3_ops_src.h delete mode 100644 panda/src/linmath/lvec4_ops.h rename panda/src/linmath/{lvec4_ops.I => lvec4_ops_src.I} (66%) create mode 100644 panda/src/linmath/lvec4_ops_src.h delete mode 100644 panda/src/linmath/lvecBase2.I delete mode 100644 panda/src/linmath/lvecBase2.cxx delete mode 100644 panda/src/linmath/lvecBase2.h rename panda/src/linmath/{lvecBase2_src.I => lvecBase2_src.cxx} (60%) create mode 100644 panda/src/linmath/lvecBase2_src.h delete mode 100644 panda/src/linmath/lvecBase3.I delete mode 100644 panda/src/linmath/lvecBase3.cxx delete mode 100644 panda/src/linmath/lvecBase3.h rename panda/src/linmath/{lvecBase3_src.I => lvecBase3_src.cxx} (53%) create mode 100644 panda/src/linmath/lvecBase3_src.h delete mode 100644 panda/src/linmath/lvecBase4.I delete mode 100644 panda/src/linmath/lvecBase4.cxx delete mode 100644 panda/src/linmath/lvecBase4.h delete mode 100644 panda/src/linmath/lvecBase4_src.I create mode 100644 panda/src/linmath/lvecBase4_src.cxx create mode 100644 panda/src/linmath/lvecBase4_src.h delete mode 100644 panda/src/linmath/lvector2.I delete mode 100644 panda/src/linmath/lvector2.cxx delete mode 100644 panda/src/linmath/lvector2.h rename panda/src/linmath/{lvector2_src.I => lvector2_src.cxx} (84%) create mode 100644 panda/src/linmath/lvector2_src.h delete mode 100644 panda/src/linmath/lvector3.I delete mode 100644 panda/src/linmath/lvector3.cxx delete mode 100644 panda/src/linmath/lvector3.h rename panda/src/linmath/{lvector3_src.I => lvector3_src.cxx} (84%) create mode 100644 panda/src/linmath/lvector3_src.h delete mode 100644 panda/src/linmath/lvector4.I delete mode 100644 panda/src/linmath/lvector4.cxx delete mode 100644 panda/src/linmath/lvector4.h rename panda/src/linmath/{lvector4_src.I => lvector4_src.cxx} (84%) create mode 100644 panda/src/linmath/lvector4_src.h delete mode 100644 panda/src/linmath/mathNumbers.cxx delete mode 100644 panda/src/linmath/mathNumbers.h delete mode 100644 panda/src/linmath/nearly_zero.h delete mode 100644 panda/src/linmath/pta_Colorf.cxx delete mode 100644 panda/src/linmath/pta_Colorf.h delete mode 100644 panda/src/linmath/pta_Normalf.cxx delete mode 100644 panda/src/linmath/pta_Normalf.h delete mode 100644 panda/src/linmath/pta_TexCoordf.cxx delete mode 100644 panda/src/linmath/pta_TexCoordf.h delete mode 100644 panda/src/linmath/pta_Vertexf.cxx delete mode 100644 panda/src/linmath/pta_Vertexf.h delete mode 100644 panda/src/linmath/test_math.cxx delete mode 100644 panda/src/linmath/vector_Colorf.cxx delete mode 100644 panda/src/linmath/vector_Colorf.h delete mode 100644 panda/src/linmath/vector_LPoint2f.cxx delete mode 100644 panda/src/linmath/vector_LPoint2f.h delete mode 100644 panda/src/linmath/vector_LVecBase3f.cxx delete mode 100644 panda/src/linmath/vector_LVecBase3f.h delete mode 100644 panda/src/linmath/vector_Normalf.cxx delete mode 100644 panda/src/linmath/vector_Normalf.h delete mode 100644 panda/src/linmath/vector_TexCoordf.h delete mode 100644 panda/src/linmath/vector_Vertexf.cxx delete mode 100644 panda/src/linmath/vector_Vertexf.h delete mode 100644 panda/src/mathutil/Sources.pp delete mode 100644 panda/src/mathutil/boundingHexahedron.I delete mode 100644 panda/src/mathutil/boundingHexahedron.cxx delete mode 100644 panda/src/mathutil/boundingHexahedron.h delete mode 100644 panda/src/mathutil/boundingLine.I delete mode 100644 panda/src/mathutil/boundingLine.cxx delete mode 100644 panda/src/mathutil/boundingLine.h delete mode 100644 panda/src/mathutil/boundingSphere.I delete mode 100644 panda/src/mathutil/boundingSphere.cxx delete mode 100644 panda/src/mathutil/boundingSphere.h delete mode 100644 panda/src/mathutil/boundingVolume.I delete mode 100644 panda/src/mathutil/boundingVolume.cxx delete mode 100644 panda/src/mathutil/boundingVolume.h delete mode 100644 panda/src/mathutil/config_mathutil.cxx delete mode 100644 panda/src/mathutil/config_mathutil.h delete mode 100644 panda/src/mathutil/fftCompressor.cxx delete mode 100644 panda/src/mathutil/fftCompressor.h delete mode 100644 panda/src/mathutil/finiteBoundingVolume.cxx delete mode 100644 panda/src/mathutil/finiteBoundingVolume.h delete mode 100644 panda/src/mathutil/frustum.N delete mode 100644 panda/src/mathutil/frustum.h rename panda/src/mathutil/{frustum.I => frustum_src.I} (64%) create mode 100644 panda/src/mathutil/frustum_src.h delete mode 100644 panda/src/mathutil/geometricBoundingVolume.I delete mode 100644 panda/src/mathutil/geometricBoundingVolume.cxx delete mode 100644 panda/src/mathutil/geometricBoundingVolume.h delete mode 100644 panda/src/mathutil/look_at.I delete mode 100644 panda/src/mathutil/look_at.cxx delete mode 100644 panda/src/mathutil/look_at.h rename panda/src/mathutil/{look_at_src.I => look_at_src.cxx} (94%) create mode 100644 panda/src/mathutil/look_at_src.h delete mode 100644 panda/src/mathutil/mathHelpers.I delete mode 100644 panda/src/mathutil/mathHelpers.h delete mode 100644 panda/src/mathutil/mathutil.h delete mode 100644 panda/src/mathutil/omniBoundingVolume.I delete mode 100644 panda/src/mathutil/omniBoundingVolume.cxx delete mode 100644 panda/src/mathutil/omniBoundingVolume.h delete mode 100644 panda/src/mathutil/plane.N delete mode 100644 panda/src/mathutil/plane.cxx delete mode 100644 panda/src/mathutil/plane.h rename panda/src/mathutil/{plane.I => plane_src.I} (60%) create mode 100644 panda/src/mathutil/plane_src.cxx create mode 100644 panda/src/mathutil/plane_src.h delete mode 100644 panda/src/mathutil/rotate_to.cxx delete mode 100644 panda/src/mathutil/rotate_to.h rename panda/src/mathutil/{rotate_to_src.I => rotate_to_src.cxx} (89%) delete mode 100644 panda/src/mathutil/test_mathutil.cxx diff --git a/panda/src/linmath/Sources.pp b/panda/src/linmath/Sources.pp deleted file mode 100644 index b47d1b7a8a..0000000000 --- a/panda/src/linmath/Sources.pp +++ /dev/null @@ -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 - diff --git a/panda/src/linmath/cast_to_double.I b/panda/src/linmath/cast_to_double.I deleted file mode 100644 index 352cfb196a..0000000000 --- a/panda/src/linmath/cast_to_double.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: cast_to_double.I -// Created by: drose (24May00) -// -//////////////////////////////////////////////////////////////////// - -INLINE LVecBase2 cast_to_double(const LVecBase2 &source) { - return LCAST(double, source); -} - -INLINE LVecBase3 cast_to_double(const LVecBase3 &source) { - return LCAST(double, source); -} - -INLINE LVecBase4 cast_to_double(const LVecBase4 &source) { - return LCAST(double, source); -} - -INLINE LVector2 cast_to_double(const LVector2 &source) { - return LCAST(double, source); -} - -INLINE LVector3 cast_to_double(const LVector3 &source) { - return LCAST(double, source); -} - -INLINE LVector4 cast_to_double(const LVector4 &source) { - return LCAST(double, source); -} - -INLINE LPoint2 cast_to_double(const LPoint2 &source) { - return LCAST(double, source); -} - -INLINE LPoint3 cast_to_double(const LPoint3 &source) { - return LCAST(double, source); -} - -INLINE LPoint4 cast_to_double(const LPoint4 &source) { - return LCAST(double, source); -} - -INLINE LMatrix3 cast_to_double(const LMatrix3 &source) { - return LCAST(double, source); -} - -INLINE LMatrix4 cast_to_double(const LMatrix4 &source) { - return LCAST(double, source); -} - diff --git a/panda/src/linmath/cast_to_double.h b/panda/src/linmath/cast_to_double.h deleted file mode 100644 index fd22d87951..0000000000 --- a/panda/src/linmath/cast_to_double.h +++ /dev/null @@ -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 cast_to_double(const LVecBase2 &source); -INLINE LVecBase3 cast_to_double(const LVecBase3 &source); -INLINE LVecBase4 cast_to_double(const LVecBase4 &source); -INLINE LVector2 cast_to_double(const LVector2 &source); -INLINE LVector3 cast_to_double(const LVector3 &source); -INLINE LVector4 cast_to_double(const LVector4 &source); -INLINE LPoint2 cast_to_double(const LPoint2 &source); -INLINE LPoint3 cast_to_double(const LPoint3 &source); -INLINE LPoint4 cast_to_double(const LPoint4 &source); -INLINE LMatrix3 cast_to_double(const LMatrix3 &source); -INLINE LMatrix4 cast_to_double(const LMatrix4 &source); - -#include "cast_to_double.I" - -#endif - - diff --git a/panda/src/linmath/cast_to_float.I b/panda/src/linmath/cast_to_float.I deleted file mode 100644 index 980c3dde28..0000000000 --- a/panda/src/linmath/cast_to_float.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: cast_to_float.I -// Created by: drose (24May00) -// -//////////////////////////////////////////////////////////////////// - -INLINE LVecBase2 cast_to_float(const LVecBase2 &source) { - return LCAST(float, source); -} - -INLINE LVecBase3 cast_to_float(const LVecBase3 &source) { - return LCAST(float, source); -} - -INLINE LVecBase4 cast_to_float(const LVecBase4 &source) { - return LCAST(float, source); -} - -INLINE LVector2 cast_to_float(const LVector2 &source) { - return LCAST(float, source); -} - -INLINE LVector3 cast_to_float(const LVector3 &source) { - return LCAST(float, source); -} - -INLINE LVector4 cast_to_float(const LVector4 &source) { - return LCAST(float, source); -} - -INLINE LPoint2 cast_to_float(const LPoint2 &source) { - return LCAST(float, source); -} - -INLINE LPoint3 cast_to_float(const LPoint3 &source) { - return LCAST(float, source); -} - -INLINE LPoint4 cast_to_float(const LPoint4 &source) { - return LCAST(float, source); -} - -INLINE LMatrix3 cast_to_float(const LMatrix3 &source) { - return LCAST(float, source); -} - -INLINE LMatrix4 cast_to_float(const LMatrix4 &source) { - return LCAST(float, source); -} - diff --git a/panda/src/linmath/cast_to_float.h b/panda/src/linmath/cast_to_float.h deleted file mode 100644 index c8a6cbf5c5..0000000000 --- a/panda/src/linmath/cast_to_float.h +++ /dev/null @@ -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 cast_to_float(const LVecBase2 &source); -INLINE LVecBase3 cast_to_float(const LVecBase3 &source); -INLINE LVecBase4 cast_to_float(const LVecBase4 &source); -INLINE LVector2 cast_to_float(const LVector2 &source); -INLINE LVector3 cast_to_float(const LVector3 &source); -INLINE LVector4 cast_to_float(const LVector4 &source); -INLINE LPoint2 cast_to_float(const LPoint2 &source); -INLINE LPoint3 cast_to_float(const LPoint3 &source); -INLINE LPoint4 cast_to_float(const LPoint4 &source); -INLINE LMatrix3 cast_to_float(const LMatrix3 &source); -INLINE LMatrix4 cast_to_float(const LMatrix4 &source); - -#include "cast_to_float.I" - -#endif - - diff --git a/panda/src/linmath/cmath.I b/panda/src/linmath/cmath.I deleted file mode 100644 index e6865ce5a9..0000000000 --- a/panda/src/linmath/cmath.I +++ /dev/null @@ -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 -#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 -} - - diff --git a/panda/src/linmath/cmath.h b/panda/src/linmath/cmath.h deleted file mode 100644 index ccb164edbb..0000000000 --- a/panda/src/linmath/cmath.h +++ /dev/null @@ -1,40 +0,0 @@ -// Filename: cmath.h -// Created by: drose (19May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef CMATH_H -#define CMATH_H - -#include - -#include - -// 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 - diff --git a/panda/src/linmath/compose_matrix.I b/panda/src/linmath/compose_matrix.I deleted file mode 100644 index b0c6c1f5e5..0000000000 --- a/panda/src/linmath/compose_matrix.I +++ /dev/null @@ -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; -} diff --git a/panda/src/linmath/compose_matrix.cxx b/panda/src/linmath/compose_matrix.cxx deleted file mode 100644 index 6b5dcb84b9..0000000000 --- a/panda/src/linmath/compose_matrix.cxx +++ /dev/null @@ -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 - -//////////////////////////////////////////////////////////////////// -// Function: compose_matrix -// Description: Computes the 3x3 matrix from scale and rotation. -//////////////////////////////////////////////////////////////////// -template -INLINE void -_compose_matrix(LMatrix3 &mat, - const LVecBase3 &scale, - const LVecBase3 &hpr, - CoordinateSystem cs) { - mat = - LMatrix3::scale_mat(scale) * - LMatrix3::rotate_mat(hpr[1], LVector3::right(cs), cs) * - LMatrix3::rotate_mat(hpr[0], LVector3::up(cs), cs) * - LMatrix3::rotate_mat(hpr[2], LVector3::back(cs), cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: compose_matrix -// Description: Computes the 4x4 matrix according to scale, rotation, -// and translation. -//////////////////////////////////////////////////////////////////// -template -INLINE void -_compose_matrix(LMatrix4 &mat, - const LVecBase3 &scale, - const LVecBase3 &hpr, - const LVecBase3 &translate, - CoordinateSystem cs) { - LMatrix3 upper3; - _compose_matrix(upper3, scale, hpr, cs); - mat = LMatrix4(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 -static void -unwind_yup_rotation(LMatrix3 &mat, LVecBase3 &hpr) { - typedef LMatrix3 Matrix; - - // Extract the axes from the matrix. - LVector3 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 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(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 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(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 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(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 -static void -unwind_yup_rotation(LMatrix3 &mat, LVecBase3 &hpr, - NumType roll) { - typedef LMatrix3 Matrix; - - // Extract the axes from the matrix. - LVector3 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(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 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(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 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(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 -static void -unwind_zup_rotation(LMatrix3 &mat, LVecBase3 &hpr) { - typedef LMatrix3 Matrix; - - // Extract the axes from the matrix. - LVector3 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 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(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 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(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 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(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 -static void -unwind_zup_rotation(LMatrix3 &mat, LVecBase3 &hpr, - NumType roll) { - typedef LMatrix3 Matrix; - - // Extract the axes from the matrix. - LVector3 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(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 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(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 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(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 -static bool -_decompose_matrix(const LMatrix3 &mat, - LVecBase3 &scale, - LVecBase3 &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 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 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 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 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 -static bool -_decompose_matrix(const LMatrix3 &mat, - LVecBase3 &scale, - LVecBase3 &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 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 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 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 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 -INLINE bool -_decompose_matrix(const LMatrix4 &mat, - LVecBase3 &scale, - LVecBase3 &hpr, - 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. -//////////////////////////////////////////////////////////////////// -template -INLINE bool -_decompose_matrix(const LMatrix4 &mat, - LVecBase3 &scale, - LVecBase3 &hpr, - LVecBase3 &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); -} - diff --git a/panda/src/linmath/compose_matrix.h b/panda/src/linmath/compose_matrix.h deleted file mode 100644 index 014e3499c8..0000000000 --- a/panda/src/linmath/compose_matrix.h +++ /dev/null @@ -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 - -#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 - diff --git a/panda/src/linmath/compose_matrix_src.I b/panda/src/linmath/compose_matrix_src.cxx similarity index 78% rename from panda/src/linmath/compose_matrix_src.I rename to panda/src/linmath/compose_matrix_src.cxx index f304f294ba..3bd941c943 100644 --- a/panda/src/linmath/compose_matrix_src.I +++ b/panda/src/linmath/compose_matrix_src.cxx @@ -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); -} - diff --git a/panda/src/linmath/compose_matrix_src.h b/panda/src/linmath/compose_matrix_src.h new file mode 100644 index 0000000000..079005b6f2 --- /dev/null +++ b/panda/src/linmath/compose_matrix_src.h @@ -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" diff --git a/panda/src/linmath/config_linmath.cxx b/panda/src/linmath/config_linmath.cxx deleted file mode 100644 index fe57f8026d..0000000000 --- a/panda/src/linmath/config_linmath.cxx +++ /dev/null @@ -1,57 +0,0 @@ -// Filename: config_linmath.cxx -// Created by: drose (23Feb00) -// -//////////////////////////////////////////////////////////////////// - -#include "config_linmath.h" -#include "luse.h" -#include "coordinateSystem.h" - -#include - -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; -} diff --git a/panda/src/linmath/config_linmath.h b/panda/src/linmath/config_linmath.h deleted file mode 100644 index c850e7bdcf..0000000000 --- a/panda/src/linmath/config_linmath.h +++ /dev/null @@ -1,14 +0,0 @@ -// Filename: config_linmath.h -// Created by: drose (23Feb00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_LINMATH_H -#define CONFIG_LINMATH_H - -#include -#include - -NotifyCategoryDecl(linmath, EXPCL_PANDA, EXPTP_PANDA); - -#endif diff --git a/panda/src/linmath/coordinateSystem.cxx b/panda/src/linmath/coordinateSystem.cxx deleted file mode 100644 index c1317ade4b..0000000000 --- a/panda/src/linmath/coordinateSystem.cxx +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: coordinateSystem.cxx -// Created by: drose (24Sep99) -// -//////////////////////////////////////////////////////////////////// - -#include "coordinateSystem.h" -#include "config_linmath.h" - -#include -#include - -#include -#include - -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; -} diff --git a/panda/src/linmath/coordinateSystem.h b/panda/src/linmath/coordinateSystem.h deleted file mode 100644 index f82b0efa2e..0000000000 --- a/panda/src/linmath/coordinateSystem.h +++ /dev/null @@ -1,46 +0,0 @@ -// Filename: coordinateSystem.h -// Created by: drose (24Sep99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef COORDINATESYSTEM_H -#define COORDINATESYSTEM_H - -#include - -#include - -#include - -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 - diff --git a/panda/src/linmath/dbl2fltnames.h b/panda/src/linmath/dbl2fltnames.h new file mode 100644 index 0000000000..9bd3dffa63 --- /dev/null +++ b/panda/src/linmath/dbl2fltnames.h @@ -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' diff --git a/panda/src/linmath/dblnames.I b/panda/src/linmath/dblnames.I deleted file mode 100644 index d0e41aca3e..0000000000 --- a/panda/src/linmath/dblnames.I +++ /dev/null @@ -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 diff --git a/panda/src/linmath/dblnames.h b/panda/src/linmath/dblnames.h new file mode 100644 index 0000000000..404285b4e5 --- /dev/null +++ b/panda/src/linmath/dblnames.h @@ -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' diff --git a/panda/src/linmath/deg_2_rad.h b/panda/src/linmath/deg_2_rad.h deleted file mode 100644 index b7a29d9b30..0000000000 --- a/panda/src/linmath/deg_2_rad.h +++ /dev/null @@ -1,19 +0,0 @@ -// Filename: deg_2_rad.h -// Created by: drose (29Sep99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef DEG_2_RAD_H -#define DEG_2_RAD_H - -#include - -#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 - diff --git a/panda/src/linmath/flt2dblnames.h b/panda/src/linmath/flt2dblnames.h new file mode 100644 index 0000000000..6ca31b51e9 --- /dev/null +++ b/panda/src/linmath/flt2dblnames.h @@ -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' diff --git a/panda/src/linmath/fltnames.I b/panda/src/linmath/fltnames.I deleted file mode 100644 index ecfc18fb4d..0000000000 --- a/panda/src/linmath/fltnames.I +++ /dev/null @@ -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 diff --git a/panda/src/linmath/fltnames.h b/panda/src/linmath/fltnames.h new file mode 100644 index 0000000000..1f043c6586 --- /dev/null +++ b/panda/src/linmath/fltnames.h @@ -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' diff --git a/panda/src/linmath/ioPtaDatagramLinMath.I b/panda/src/linmath/ioPtaDatagramLinMath.I deleted file mode 100644 index 0c73bd82ce..0000000000 --- a/panda/src/linmath/ioPtaDatagramLinMath.I +++ /dev/null @@ -1,45 +0,0 @@ -// Filename: ioPtaDatagramLinMath.I -// Created by: jason (26Jun00) -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: IoPtaDatagamLinMath::write_datagram -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void IoPtaDatagramLinMath:: -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 -PTA(LinMathElement) IoPtaDatagramLinMath:: -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; -} - - diff --git a/panda/src/linmath/ioPtaDatagramLinMath.cxx b/panda/src/linmath/ioPtaDatagramLinMath.cxx deleted file mode 100644 index d14e9caf82..0000000000 --- a/panda/src/linmath/ioPtaDatagramLinMath.cxx +++ /dev/null @@ -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 diff --git a/panda/src/linmath/ioPtaDatagramLinMath.h b/panda/src/linmath/ioPtaDatagramLinMath.h deleted file mode 100644 index 7076e53464..0000000000 --- a/panda/src/linmath/ioPtaDatagramLinMath.h +++ /dev/null @@ -1,62 +0,0 @@ -// Filename: ioPtaDatagramLinMath.h -// Created by: jason (26Jun00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef _IO_PTA_DATAGRAM_LINMATH -#define _IO_PTA_DATAGRAM_LINMATH - -#include - -#include "luse.h" -#include "pta_Vertexf.h" -#include "pta_Colorf.h" -#include "pta_Normalf.h" -#include "pta_TexCoordf.h" - -#include - -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 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) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, IoPtaDatagramLinMath) - - -typedef IoPtaDatagramLinMath IPD_Colorf; -typedef IoPtaDatagramLinMath IPD_Normalf; -typedef IoPtaDatagramLinMath IPD_TexCoordf; -typedef IoPtaDatagramLinMath IPD_Vertexf; - - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/lcast_to.h b/panda/src/linmath/lcast_to.h new file mode 100644 index 0000000000..4752567836 --- /dev/null +++ b/panda/src/linmath/lcast_to.h @@ -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 + diff --git a/panda/src/linmath/lcast_to_src.I b/panda/src/linmath/lcast_to_src.I new file mode 100644 index 0000000000..49b3420053 --- /dev/null +++ b/panda/src/linmath/lcast_to_src.I @@ -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)); +} diff --git a/panda/src/linmath/lcast_to_src.h b/panda/src/linmath/lcast_to_src.h new file mode 100644 index 0000000000..90ef16af01 --- /dev/null +++ b/panda/src/linmath/lcast_to_src.h @@ -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" diff --git a/panda/src/linmath/lmat_ops.h b/panda/src/linmath/lmat_ops.h deleted file mode 100644 index 1703b1ac56..0000000000 --- a/panda/src/linmath/lmat_ops.h +++ /dev/null @@ -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 -INLINE LVecBase3 -operator * (const LVecBase3 &v, const LMatrix3 &m); - -template -INLINE LVector2 -operator * (const LVector2 &v, const LMatrix3 &m); - -template -INLINE LPoint2 -operator * (const LPoint2 &v, const LMatrix3 &m); - - -// vector times matrix4 -template -INLINE LVecBase4 -operator * (const LVecBase4 &v, const LMatrix4 &m); - -template -INLINE LVector3 -operator * (const LVector3 &v, const LMatrix4 &m); - -template -INLINE LPoint3 -operator * (const LPoint3 &v, const LMatrix4 &m); - -#ifdef CPPPARSER -// Strictly for the benefit of interrogate, we'll define explicit -// 'instantiations' of the above template functions on types float and -// double. - -BEGIN_PUBLISH - -INLINE LVecBase3 -operator * (const LVecBase3 &v, const LMatrix3 &m); -INLINE LVector2 -operator * (const LVector2 &v, const LMatrix3 &m); -INLINE LPoint2 -operator * (const LPoint2 &v, const LMatrix3 &m); -INLINE LVecBase4 -operator * (const LVecBase4 &v, const LMatrix4 &m); -INLINE LVector3 -operator * (const LVector3 &v, const LMatrix4 &m); -INLINE LPoint3 -operator * (const LPoint3 &v, const LMatrix4 &m); - -INLINE LVecBase3 -operator * (const LVecBase3 &v, const LMatrix3 &m); -INLINE LVector2 -operator * (const LVector2 &v, const LMatrix3 &m); -INLINE LPoint2 -operator * (const LPoint2 &v, const LMatrix3 &m); -INLINE LVecBase4 -operator * (const LVecBase4 &v, const LMatrix4 &m); -INLINE LVector3 -operator * (const LVector3 &v, const LMatrix4 &m); -INLINE LPoint3 -operator * (const LPoint3 &v, const LMatrix4 &m); - -END_PUBLISH - -#endif // CPPPARSER - -#include "lmat_ops.I" - -#endif diff --git a/panda/src/linmath/lmat_ops.I b/panda/src/linmath/lmat_ops_src.I similarity index 56% rename from panda/src/linmath/lmat_ops.I rename to panda/src/linmath/lmat_ops_src.I index 802ebec4c2..4f0cbfd515 100644 --- a/panda/src/linmath/lmat_ops.I +++ b/panda/src/linmath/lmat_ops_src.I @@ -1,15 +1,26 @@ -// Filename: lmat_ops.I +// Filename: lmat_ops_src.h // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// // Function: LVecBase3 times LMatrix3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 -operator * (const LVecBase3 &v, const LMatrix3 &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 &v, const LMatrix3 &m) { // Function: LVector2 times LMatrix3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVector2 -operator * (const LVector2 &v, const LMatrix3 &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 &v, const LMatrix3 &m) { // Function: LPoint2 times LMatrix3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 -operator * (const LPoint2 &v, const LMatrix3 &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 &v, const LMatrix3 &m) { // Function: LVecBase4 times LMatrix4 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 -operator * (const LVecBase4 &v, const LMatrix4 &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 -INLINE LVector3 -operator * (const LVector3 &v, const LMatrix4 &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 &v, const LMatrix4 &m) { // Function: LPoint3 times LMatrix4 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 -operator * (const LPoint3 &v, const LMatrix4 &m) { + +INLINE FLOATNAME(LPoint3) +operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m) { return m.xform_point(v); } diff --git a/panda/src/linmath/lmat_ops_src.h b/panda/src/linmath/lmat_ops_src.h new file mode 100644 index 0000000000..9114e95b82 --- /dev/null +++ b/panda/src/linmath/lmat_ops_src.h @@ -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" diff --git a/panda/src/linmath/lmatrix.cxx b/panda/src/linmath/lmatrix.cxx deleted file mode 100644 index fd0042df3c..0000000000 --- a/panda/src/linmath/lmatrix.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Filename: lmatrix.cxx -// Created by: drose (22Feb99) -// -//////////////////////////////////////////////////////////////////// - -#include -#include "lmatrix.h" - -// This tells GCC to explicitly instantiate the templates defined in -// lmatrix.h and leave them here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/lmatrix.h b/panda/src/linmath/lmatrix.h deleted file mode 100644 index d56cbf2a5a..0000000000 --- a/panda/src/linmath/lmatrix.h +++ /dev/null @@ -1,25 +0,0 @@ -// Filename: lmatrix.h -// Created by: drose (15Jan99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LMATRIX_H -#define LMATRIX_H - -#include - -#include "lmatrix3.h" -#include "lmatrix4.h" - -typedef LMatrix3 LMatrix3f; -typedef LMatrix4 LMatrix4f; - -typedef LMatrix3 LMatrix3d; -typedef LMatrix4 LMatrix4d; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/lmatrix3.I b/panda/src/linmath/lmatrix3.I deleted file mode 100644 index d39aa4f972..0000000000 --- a/panda/src/linmath/lmatrix3.I +++ /dev/null @@ -1,1110 +0,0 @@ -// Filename: lmatrix3.I -// Created by: drose (29Jan99) -// -//////////////////////////////////////////////////////////////////// - -#include - -#include "deg_2_rad.h" -#include "nearly_zero.h" - -#include -#include - -#include - -template -TypeHandle LMatrix3::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3:: -LMatrix3() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3:: -LMatrix3(const LMatrix3 ©) { - (*this) = copy; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix3 &LMatrix3:: -operator = (const LMatrix3 ©) { - set(copy(0, 0), copy(0, 1), copy(0, 2), - copy(1, 0), copy(1, 1), copy(1, 2), - copy(2, 0), copy(2, 1), copy(2, 2)); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Fill Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 &LMatrix3:: -operator = (NumType fill_value) { - fill(fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3:: -LMatrix3(NumType e00, NumType e01, NumType e02, - NumType e10, NumType e11, NumType e12, - NumType e20, NumType e21, NumType e22) { - set(e00, e01, e02, - e10, e11, e12, - e20, e21, e22); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::fill -// Access: Public -// Description: Sets each element of the matrix to the indicated -// fill_value. This is of questionable value, but is -// sometimes useful when initializing to zero. -//////////////////////////////////////////////////////////////////// -template -void LMatrix3:: -fill(NumType fill_value) { - set(fill_value, fill_value, fill_value, - fill_value, fill_value, fill_value, - fill_value, fill_value, fill_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::set -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -set(NumType e00, NumType e01, NumType e02, - NumType e10, NumType e11, NumType e12, - NumType e20, NumType e21, NumType e22) { - (*this)(0, 0) = e00; - (*this)(0, 1) = e01; - (*this)(0, 2) = e02; - (*this)(1, 0) = e10; - (*this)(1, 1) = e11; - (*this)(1, 2) = e12; - (*this)(2, 0) = e20; - (*this)(2, 1) = e21; - (*this)(2, 2) = e22; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::set_row -// Access: Public -// Description: Replaces the indicated row of the matrix from a -// three-component vector. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -set_row(int row, const LVecBase3 &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; - (*this)(row, 2) = v[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::set_column -// Access: Public -// Description: Replaces the indicated column of the matrix from a -// three-component vector. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -set_col(int col, const LVecBase3 &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; - (*this)(2, col) = v[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::set_row -// Access: Public -// Description: Replaces the indicated row of the matrix from a -// two-component vector, ignoring the last column. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -set_row(int row, const LVecBase2 &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::set_column -// Access: Public -// Description: Replaces the indicated column of the matrix from a -// two-component vector, ignoring the last row. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -set_col(int col, const LVecBase2 &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_row -// Access: Public -// Description: Returns the indicated row of the matrix as a -// three-component vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix3:: -get_row(int row) const { - return LVecBase3((*this)(row, 0), (*this)(row, 1), (*this)(row, 2)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_col -// Access: Public -// Description: Returns the indicated column of the matrix as a -// three-component vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix3:: -get_col(int col) const { - return LVecBase3((*this)(0, col), (*this)(1, col), (*this)(2, col)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_row2 -// Access: Public -// Description: Returns the indicated row of the matrix as a -// two-component vector, ignoring the last column. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LMatrix3:: -get_row2(int row) const { - return LVecBase2((*this)(row, 0), (*this)(row, 1)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_col2 -// Access: Public -// Description: Returns the indicated column of the matrix as a -// two-component vector, ignoring the last row. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LMatrix3:: -get_col2(int col) const { - return LVecBase2((*this)(0, col), (*this)(1, col)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Indexing operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType &LMatrix3:: -operator () (int row, int col) { - nassertr(row >= 0 && row < 3, _data[0]); - nassertr(col >= 0 && col < 3, _data[0]); - return _data[row * 3 + col]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Indexing operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix3:: -operator () (int row, int col) const { - nassertr(row >= 0 && row < 3, 0.0); - nassertr(col >= 0 && col < 3, 0.0); - return _data[row * 3 + col]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::is_nan -// Access: Public -// Description: Returns true if any component of the matrix is -// not-a-number, false otherwise. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix3:: -is_nan() const { - return - cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || - cnan(_data[3]) || cnan(_data[4]) || cnan(_data[5]) || - cnan(_data[6]) || cnan(_data[7]) || cnan(_data[8]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_cell -// Access: Public -// Description: Returns a particular element of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix3:: -get_cell(int row, int col) const { - nassertr(row >= 0 && row < 3, 0.0); - nassertr(col >= 0 && col < 3, 0.0); - return _data[row * 3 + col]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::set_cell -// Access: Public -// Description: Changes a particular element of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -set_cell(int row, int col, NumType value) { - nassertv(row >= 0 && row < 3); - nassertv(col >= 0 && col < 3); - _data[row * 3 + col] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_data -// Access: Public -// Description: Returns the address of the first of the nine data -// elements in the matrix. The remaining elements -// occupy the next eight positions in row-major order. -//////////////////////////////////////////////////////////////////// -template -INLINE const NumType *LMatrix3:: -get_data() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::get_num_components -// Access: Public -// Description: Returns the number of elements in the matrix, nine. -//////////////////////////////////////////////////////////////////// -template -INLINE int LMatrix3:: -get_num_components() const { - return 9; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::begin -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3::iterator LMatrix3:: -begin() { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::end -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3::iterator LMatrix3:: -end() { - return begin() + get_num_components(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::begin -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3::const_iterator LMatrix3:: -begin() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::end -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3::const_iterator LMatrix3:: -end() const { - return begin() + get_num_components(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Equality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -bool LMatrix3:: -operator == (const LMatrix3 &other) const { - return ((*this)(0, 0) == other(0, 0) && - (*this)(0, 1) == other(0, 1) && - (*this)(0, 2) == other(0, 2) && - (*this)(1, 0) == other(1, 0) && - (*this)(1, 1) == other(1, 1) && - (*this)(1, 2) == other(1, 2) && - (*this)(2, 0) == other(2, 0) && - (*this)(2, 1) == other(2, 1) && - (*this)(2, 2) == other(2, 2)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix3:: -operator != (const LMatrix3 &other) const { - return !operator == (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::compare_to -// Access: Public -// Description: This flavor of compare_to uses a default threshold -// value based on the numeric type. -//////////////////////////////////////////////////////////////////// -template -INLINE int LMatrix3:: -compare_to(const LMatrix3 &other) const { - return compare_to(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::compare_to -// Access: Public -// Description: Sorts matrices lexicographically, componentwise. -// Returns a number less than 0 if this matrix sorts -// before the other one, greater than zero if it sorts -// after, 0 if they are equivalent (within the indicated -// tolerance). -//////////////////////////////////////////////////////////////////// -template -int LMatrix3:: -compare_to(const LMatrix3 &other, NumType 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; - } - } - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::xform -// Access: Public -// Description: 3-component vector or point times matrix. This is a -// fully general operation. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix3:: -xform(const LVecBase3 &v) const { - return LVecBase3(v.dot(get_col(0)), - v.dot(get_col(1)), - v.dot(get_col(2))); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::xform_point -// Access: Public -// Description: The matrix transforms a 2-component point (including -// translation component) and returns the result. This -// assumes the matrix is an affine transform. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LMatrix3:: -xform_point(const LVecBase2 &v) const { - return LVecBase2(v.dot(get_col2(0)) + (*this)(2, 0), - v.dot(get_col2(1)) + (*this)(2, 1)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::xform_vec -// Access: Public -// Description: The matrix transforms a 2-component vector (without -// translation component) and returns the result. This -// assumes the matrix is an affine transform. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LMatrix3:: -xform_vec(const LVecBase2 &v) const { - return LVecBase2(v.dot(get_col2(0)), - v.dot(get_col2(1))); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::mult_cel -// Access: Private -// Description: Returns one cell of the result of a matrix-matrix -// multiplication operation. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix3:: -mult_cel(const LMatrix3 &other, int row, int col) const { - return get_row(row).dot(other.get_col(col)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix * matrix -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -operator * (const LMatrix3 &other) const { - LMatrix3 t; - - t(0, 0) = mult_cel(other, 0, 0); - t(0, 1) = mult_cel(other, 0, 1); - t(0, 2) = mult_cel(other, 0, 2); - - t(1, 0) = mult_cel(other, 1, 0); - t(1, 1) = mult_cel(other, 1, 1); - t(1, 2) = mult_cel(other, 1, 2); - - t(2, 0) = mult_cel(other, 2, 0); - t(2, 1) = mult_cel(other, 2, 1); - t(2, 2) = mult_cel(other, 2, 2); - - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -operator * (NumType scalar) const { - LMatrix3 t; - - t(0, 0) = (*this)(0, 0) * scalar; - t(0, 1) = (*this)(0, 1) * scalar; - t(0, 2) = (*this)(0, 2) * scalar; - - t(1, 0) = (*this)(1, 0) * scalar; - t(1, 1) = (*this)(1, 1) * scalar; - t(1, 2) = (*this)(1, 2) * scalar; - - t(2, 0) = (*this)(2, 0) * scalar; - t(2, 1) = (*this)(2, 1) * scalar; - t(2, 2) = (*this)(2, 2) * scalar; - - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -operator / (NumType scalar) const { - LMatrix3 t; - - t(0, 0) = (*this)(0, 0) / scalar; - t(0, 1) = (*this)(0, 1) / scalar; - t(0, 2) = (*this)(0, 2) / scalar; - - t(1, 0) = (*this)(1, 0) / scalar; - t(1, 1) = (*this)(1, 1) / scalar; - t(1, 2) = (*this)(1, 2) / scalar; - - t(2, 0) = (*this)(2, 0) / scalar; - t(2, 1) = (*this)(2, 1) / scalar; - t(2, 2) = (*this)(2, 2) / scalar; - - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix += matrix -// Access: Public -// Description: Performs a memberwise addition between two matrices. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 &LMatrix3:: -operator += (const LMatrix3 &other) { - (*this)(0, 0) += other(0, 0); - (*this)(0, 1) += other(0, 1); - (*this)(0, 2) += other(0, 2); - - (*this)(1, 0) += other(1, 0); - (*this)(1, 1) += other(1, 1); - (*this)(1, 2) += other(1, 2); - - (*this)(2, 0) += other(2, 0); - (*this)(2, 1) += other(2, 1); - (*this)(2, 2) += other(2, 2); - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix -= matrix -// Access: Public -// Description: Performs a memberwise subtraction between two matrices. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 &LMatrix3:: -operator -= (const LMatrix3 &other) { - (*this)(0, 0) -= other(0, 0); - (*this)(0, 1) -= other(0, 1); - (*this)(0, 2) -= other(0, 2); - - (*this)(1, 0) -= other(1, 0); - (*this)(1, 1) -= other(1, 1); - (*this)(1, 2) -= other(1, 2); - - (*this)(2, 0) -= other(2, 0); - (*this)(2, 1) -= other(2, 1); - (*this)(2, 2) -= other(2, 2); - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix *= matrix -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 &LMatrix3:: -operator *= (const LMatrix3 &other) { - (*this) = (*this) * other; - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix *= scalar -// Access: Public -// Description: Performs a memberwise scale. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 &LMatrix3:: -operator *= (NumType scalar) { - (*this)(0, 0) *= scalar; - (*this)(0, 1) *= scalar; - (*this)(0, 2) *= scalar; - - (*this)(1, 0) *= scalar; - (*this)(1, 1) *= scalar; - (*this)(1, 2) *= scalar; - - (*this)(2, 0) *= scalar; - (*this)(2, 1) *= scalar; - (*this)(2, 2) *= scalar; - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::matrix /= scalar -// Access: Public -// Description: Performs a memberwise scale. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 &LMatrix3:: -operator /= (NumType scalar) { - (*this)(0, 0) /= scalar; - (*this)(0, 1) /= scalar; - (*this)(0, 2) /= scalar; - - (*this)(1, 0) /= scalar; - (*this)(1, 1) /= scalar; - (*this)(1, 2) /= scalar; - - (*this)(2, 0) /= scalar; - (*this)(2, 1) /= scalar; - (*this)(2, 2) /= scalar; - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::transpose_from -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -void LMatrix3:: -transpose_from(const LMatrix3 &other) { - (*this)(0, 0) = other(0, 0); - (*this)(0, 1) = other(1, 0); - (*this)(0, 2) = other(2, 0); - - (*this)(1, 0) = other(0, 1); - (*this)(1, 1) = other(1, 1); - (*this)(1, 2) = other(2, 1); - - (*this)(2, 0) = other(0, 2); - (*this)(2, 1) = other(1, 2); - (*this)(2, 2) = other(2, 2); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::transpose_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -transpose_in_place() { - LMatrix3 temp = (*this); - transpose_from(temp); -} - -// Matrix inversion code from Numerical Recipes in C. - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::det2 -// Access: Private, Static -// Description: Returns the determinant of a 2x2 matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix3:: -det2(NumType e00, NumType e01, NumType e10, NumType e11) const { - return (e00 * e11 - e10 * e01); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::determinant -// Access: Public -// Description: Returns the determinant of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix3:: -determinant() const { - return - (*this)(0,0) * det2((*this)(1,1),(*this)(1,2),(*this)(2,1),(*this)(2,2)) - -(*this)(0,1) * det2((*this)(1,0),(*this)(1,2),(*this)(2,0),(*this)(2,2)) - +(*this)(0,2) * det2((*this)(1,0),(*this)(1,1),(*this)(2,0),(*this)(2,1)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::invert_from -// Access: Public -// Description: Computes the inverse of the other matrix, and stores -// the result in this matrix. This is a fully general -// operation and makes no assumptions about the type of -// transform represented by the matrix. -// -// The other matrix must be a different object than this -// matrix. However, if you need to invert a matrix in -// place, see invert_in_place. -// -// The return value is true if the matrix was -// successfully inverted, false if the was a -// singularity. -//////////////////////////////////////////////////////////////////// -template -bool LMatrix3:: -invert_from(const LMatrix3 &other) { - NumType d = other.determinant(); - - if (IS_NEARLY_ZERO(d)) { - linmath_cat.warning() - << "Tried to invert singular LMatrix3.\n"; - (*this) = ident_mat(); - return false; - } - - d = 1.0 / d; - (*this)(0,0) = d * det2(other(1,1), other(1,2), other(2,1), other(2,2)); - (*this)(1,0) = -d * det2(other(1,0), other(1,2), other(2,0), other(2,2)); - (*this)(2,0) = d * det2(other(1,0), other(1,1), other(2,0), other(2,1)); - - (*this)(0,1) = -d * det2(other(0,1), other(0,2), other(2,1), other(2,2)); - (*this)(1,1) = d * det2(other(0,0), other(0,2), other(2,0), other(2,2)); - (*this)(2,1) = -d * det2(other(0,0), other(0,1), other(2,0), other(2,1)); - - (*this)(0,2) = d * det2(other(0,1), other(0,2), other(1,1), other(1,2)); - (*this)(1,2) = -d * det2(other(0,0), other(0,2), other(1,0), other(1,2)); - (*this)(2,2) = d * det2(other(0,0), other(0,1), other(1,0), other(1,1)); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::invert_in_place -// Access: Public -// Description: Inverts the current matrix. Returns true if the -// inverse is successful, false if the matrix was -// singular. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix3:: -invert_in_place() { - LMatrix3 temp = (*this); - return invert_from(temp); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::ident_mat -// Access: Public, Static -// Description: Returns an identity matrix. -//////////////////////////////////////////////////////////////////// -template -const LMatrix3 &LMatrix3:: -ident_mat() { - static LMatrix3 mat(1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0); - return mat; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::translate_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// translation. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -translate_mat(const LVecBase2 &trans) { - return LMatrix3(1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - trans[0], trans[1], 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::translate_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// translation. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -translate_mat(NumType tx, NumType ty) { - return LMatrix3(1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - tx, ty, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::rotate_mat -// Access: Public, Static -// Description: Returns a matrix that rotates by the given angle in -// degrees counterclockwise. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -rotate_mat(NumType angle) { - double angle_rad=deg_2_rad(angle); - double s,c; - csincos(angle_rad,&s,&c); - return LMatrix3( c, s, 0.0, - -s, c, 0.0, - 0.0, 0.0, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// scale in each of the two axes. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -scale_mat(const LVecBase2 &scale) { - return LMatrix3(scale[0], 0.0, 0.0, - 0.0, scale[1], 0.0, - 0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// scale in each of the two axes. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -scale_mat(NumType sx, NumType sy) { - return LMatrix3(sx, 0.0, 0.0, - 0.0, sy, 0.0, - 0.0, 0.0, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::rotate_mat -// Access: Public, Static -// Description: Returns a matrix that rotates by the given angle in -// degrees counterclockwise about the indicated vector. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -rotate_mat(NumType angle, LVecBase3 axis, - CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - LMatrix3 mat; - - if (!is_right_handed(cs)) { - // In a left-handed coordinate system, counterclockwise is the - // other direction. - angle = -angle; - } - - // Normalize the axis. - NumType length = axis.dot(axis); - nassertr(length != 0.0, ident_mat()); - NumType recip_length=1.0f/length; - axis *= recip_length; - - double angle_rad=deg_2_rad(angle); - double s,c; - csincos(angle_rad,&s,&c); - double t = 1.0 - c; - - mat(0, 0) = t * axis[0] * axis[0] + c; - mat(0, 1) = t * axis[0] * axis[1] + s * axis[2]; - mat(0, 2) = t * axis[0] * axis[2] - s * axis[1]; - - mat(1, 0) = t * axis[1] * axis[0] - s * axis[2]; - mat(1, 1) = t * axis[1] * axis[1] + c; - mat(1, 2) = t * axis[1] * axis[2] + s * axis[0]; - - mat(2, 0) = t * axis[2] * axis[0] + s * axis[1]; - mat(2, 1) = t * axis[2] * axis[1] - s * axis[0]; - mat(2, 2) = t * axis[2] * axis[2] + c; - - return mat; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// scale in each of the three axes. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -scale_mat(const LVecBase3 &scale) { - return LMatrix3(scale[0], 0.0, 0.0, - 0.0, scale[1], 0.0, - 0.0, 0.0, scale[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// scale in each of the three axes. -//////////////////////////////////////////////////////////////////// -template -LMatrix3 LMatrix3:: -scale_mat(NumType sx, NumType sy, NumType sz) { - return LMatrix3(sx, 0.0, 0.0, - 0.0, sy, 0.0, - 0.0, 0.0, sz); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::almost_equal -// Access: Public -// Description: Returns true if two matrices are memberwise equal -// within a specified tolerance. -//////////////////////////////////////////////////////////////////// -template -bool LMatrix3:: -almost_equal(const LMatrix3 &other, NumType 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) && - IS_THRESHOLD_EQUAL((*this)(1, 0), other(1, 0), threshold) && - IS_THRESHOLD_EQUAL((*this)(1, 1), other(1, 1), threshold) && - IS_THRESHOLD_EQUAL((*this)(1, 2), other(1, 2), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 0), other(2, 0), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 1), other(2, 1), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 2), other(2, 2), threshold)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::almost_equal -// Access: Public -// Description: Returns true if two matrices are memberwise equal -// within a default tolerance based on the numeric type. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix3:: -almost_equal(const LMatrix3 &other) const { - return almost_equal(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -output(ostream &out) const { - out << "[ " - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) - << " ] [ " - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) - << " ] [ " - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) - << " ]"; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix3:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) - << "\n"; - indent(out, indent_level) - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) - << "\n"; - indent(out, indent_level) - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) - << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LMatrix3:: -init_type() { - if (_type_handle == TypeHandle::none()) { - // Format a string to describe the type. - do_init_type(NumType); - string name = - "LMatrix3<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::write_datagram -// Description: Writes the matrix to the datagram -//////////////////////////////////////////////////////////////////// -template -void LMatrix3:: -write_datagram(Datagram &destination) const -{ - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - destination.add_float32(get_cell(i,j)); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::read_datagram -// Description: Reads itself out of the datagram -//////////////////////////////////////////////////////////////////// -template -void LMatrix3:: -read_datagram(DatagramIterator &scan) -{ - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - set_cell(i, j, scan.get_float32()); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::transpose -// Description: Transposes the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 -transpose(const LMatrix3 &a) { - LMatrix3 result; - result.transpose_from(a); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::invert -// Description: Inverts the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 -invert(const LMatrix3 &a) { - LMatrix3 result; - bool nonsingular = result.invert_from(a); - nassertr(nonsingular, LMatrix3::ident_mat()); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: lcast_to -// Description: Converts a matrix from one numeric representation to -// another one. This is usually invoked using the macro -// LCAST. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 -lcast_to(NumType2 *, const LMatrix3 &source) { - return 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)); -} diff --git a/panda/src/linmath/lmatrix3.cxx b/panda/src/linmath/lmatrix3.cxx deleted file mode 100644 index 79e5aff7dc..0000000000 --- a/panda/src/linmath/lmatrix3.cxx +++ /dev/null @@ -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" - - diff --git a/panda/src/linmath/lmatrix3.h b/panda/src/linmath/lmatrix3.h deleted file mode 100644 index 75cb1324a5..0000000000 --- a/panda/src/linmath/lmatrix3.h +++ /dev/null @@ -1,194 +0,0 @@ -// Filename: lmatrix3.h -// Created by: drose (29Jan99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LMATRIX3_H -#define LMATRIX3_H - -#include - -#include "coordinateSystem.h" -#include "lvecBase3.h" -#include "lvecBase2.h" - -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// 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 LMatrix3 { -PUBLISHED: - typedef const NumType *iterator; - typedef const NumType *const_iterator; - - INLINE LMatrix3(); - INLINE LMatrix3(const LMatrix3 &other); - LMatrix3 &operator = (const LMatrix3 &other); - INLINE LMatrix3 &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 &v); - INLINE void set_col(int col, const LVecBase3 &v); - - INLINE void set_row(int row, const LVecBase2 &v); - INLINE void set_col(int col, const LVecBase2 &v); - - INLINE LVecBase3 get_row(int row) const; - INLINE LVecBase3 get_col(int col) const; - - INLINE LVecBase2 get_row2(int row) const; - INLINE LVecBase2 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 &other) const; - INLINE bool operator != (const LMatrix3 &other) const; - - INLINE int compare_to(const LMatrix3 &other) const; - int compare_to(const LMatrix3 &other, NumType threshold) const; - - INLINE LVecBase3 - xform(const LVecBase3 &v) const; - - INLINE LVecBase2 - xform_point(const LVecBase2 &v) const; - - INLINE LVecBase2 - xform_vec(const LVecBase2 &v) const; - - LMatrix3 operator * (const LMatrix3 &other) const; - LMatrix3 operator * (NumType scalar) const; - LMatrix3 operator / (NumType scalar) const; - - LMatrix3 &operator += (const LMatrix3 &other); - LMatrix3 &operator -= (const LMatrix3 &other); - - INLINE LMatrix3 &operator *= (const LMatrix3 &other); - - LMatrix3 &operator *= (NumType scalar); - LMatrix3 &operator /= (NumType scalar); - - INLINE NumType determinant() const; - - void transpose_from(const LMatrix3 &other); - INLINE void transpose_in_place(); - - bool invert_from(const LMatrix3 &other); - INLINE bool invert_in_place(); - - static const 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 LMatrix3 translate_mat(const LVecBase2 &trans); - static LMatrix3 translate_mat(NumType tx, NumType ty); - static LMatrix3 rotate_mat(NumType angle); - static LMatrix3 scale_mat(const LVecBase2 &scale); - static LMatrix3 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 rotate_mat(NumType angle, - LVecBase3 axis, - CoordinateSystem cs = CS_default); - static LMatrix3 scale_mat(const LVecBase3 &scale); - static LMatrix3 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 &other, - NumType threshold) const; - - INLINE bool almost_equal(const LMatrix3 &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 &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 -INLINE ostream &operator << (ostream &out, const LMatrix3 &mat) { - mat.output(out); - return out; -} - -template -INLINE LMatrix3 transpose(const LMatrix3 &a); - -template -INLINE LMatrix3 invert(const LMatrix3 &a); - -// Cast to a different numeric type -template -INLINE LMatrix3 -lcast_to(NumType2 *type, const LMatrix3 &source); - -#include "lmatrix3.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix3) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix3) - -#endif diff --git a/panda/src/linmath/lmatrix3_src.I b/panda/src/linmath/lmatrix3_src.cxx similarity index 90% rename from panda/src/linmath/lmatrix3_src.I rename to panda/src/linmath/lmatrix3_src.cxx index 7cebc12ddb..2ded892eb0 100644 --- a/panda/src/linmath/lmatrix3_src.I +++ b/panda/src/linmath/lmatrix3_src.cxx @@ -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); } } diff --git a/panda/src/linmath/lmatrix3_src.h b/panda/src/linmath/lmatrix3_src.h new file mode 100644 index 0000000000..f50103780d --- /dev/null +++ b/panda/src/linmath/lmatrix3_src.h @@ -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" diff --git a/panda/src/linmath/lmatrix4.I b/panda/src/linmath/lmatrix4.I deleted file mode 100644 index 282c5bd80b..0000000000 --- a/panda/src/linmath/lmatrix4.I +++ /dev/null @@ -1,1517 +0,0 @@ -// Filename: lmatrix.I -// Created by: drose (15Jan99) -// -//////////////////////////////////////////////////////////////////// - -#include - -#include "deg_2_rad.h" -#include "nearly_zero.h" -#include "config_linmath.h" - -#include - -#include - -template -TypeHandle LMatrix4::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4:: -LMatrix4() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4:: -LMatrix4(const LMatrix4 ©) { - (*this) = copy; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 &LMatrix4:: -operator = (const LMatrix4 ©) { - set(copy(0, 0), copy(0, 1), copy(0, 2), copy(0, 3), - copy(1, 0), copy(1, 1), copy(1, 2), copy(1, 3), - copy(2, 0), copy(2, 1), copy(2, 2), copy(2, 3), - copy(3, 0), copy(3, 1), copy(3, 2), copy(3, 3)); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Fill Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4 &LMatrix4:: -operator = (NumType fill_value) { - fill(fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4:: -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) { - set(e00, e01, e02, e03, - e10, e11, e12, e13, - e20, e21, e22, e23, - e30, e31, e32, e33); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Constructor, upper 3x3 -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4:: -LMatrix4(const LMatrix3 &upper3) { - set(upper3(0, 0), upper3(0, 1), upper3(0, 2), 0.0, - upper3(1, 0), upper3(1, 1), upper3(1, 2), 0.0, - upper3(2, 0), upper3(2, 1), upper3(2, 2), 0.0, - 0.0, 0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Constructor, upper 3x3 plus translation -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4:: -LMatrix4(const LMatrix3 &upper3, - const LVecBase3 &trans) { - set(upper3(0, 0), upper3(0, 1), upper3(0, 2), 0.0, - upper3(1, 0), upper3(1, 1), upper3(1, 2), 0.0, - upper3(2, 0), upper3(2, 1), upper3(2, 2), 0.0, - trans[0], trans[1], trans[2], 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::fill -// Access: Public -// Description: Sets each element of the matrix to the indicated -// fill_value. This is of questionable value, but is -// sometimes useful when initializing to zero. -//////////////////////////////////////////////////////////////////// -template -void LMatrix4:: -fill(NumType fill_value) { - set(fill_value, fill_value, fill_value, fill_value, - fill_value, fill_value, fill_value, fill_value, - fill_value, fill_value, fill_value, fill_value, - fill_value, fill_value, fill_value, fill_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -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) { - (*this)(0, 0) = e00; - (*this)(0, 1) = e01; - (*this)(0, 2) = e02; - (*this)(0, 3) = e03; - - (*this)(1, 0) = e10; - (*this)(1, 1) = e11; - (*this)(1, 2) = e12; - (*this)(1, 3) = e13; - - (*this)(2, 0) = e20; - (*this)(2, 1) = e21; - (*this)(2, 2) = e22; - (*this)(2, 3) = e23; - - (*this)(3, 0) = e30; - (*this)(3, 1) = e31; - (*this)(3, 2) = e32; - (*this)(3, 3) = e33; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set_upper_3 -// Access: Public -// Description: Sets the upper 3x3 submatrix. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -set_upper_3(const LMatrix3 &upper3) { - (*this)(0, 0) = upper3(0, 0); - (*this)(0, 1) = upper3(0, 1); - (*this)(0, 2) = upper3(0, 2); - - (*this)(1, 0) = upper3(1, 0); - (*this)(1, 1) = upper3(1, 1); - (*this)(1, 2) = upper3(1, 2); - - (*this)(2, 0) = upper3(2, 0); - (*this)(2, 1) = upper3(2, 1); - (*this)(2, 2) = upper3(2, 2); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_upper_3 -// Access: Public -// Description: Retrieves the upper 3x3 submatrix. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 LMatrix4:: -get_upper_3() const { - return LMatrix3 - ((*this)(0, 0), (*this)(0, 1), (*this)(0, 2), - (*this)(1, 0), (*this)(1, 1), (*this)(1, 2), - (*this)(2, 0), (*this)(2, 1), (*this)(2, 2)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set_row -// Access: Public -// Description: Replaces the indicated row of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -set_row(int row, const LVecBase4 &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; - (*this)(row, 2) = v[2]; - (*this)(row, 3) = v[3]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set_col -// Access: Public -// Description: Replaces the indicated column of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -set_col(int col, const LVecBase4 &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; - (*this)(2, col) = v[2]; - (*this)(3, col) = v[3]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set_row -// Access: Public -// Description: Replaces the indicated row of the matrix with the -// indicated 3-component vector, ignoring the last -// column. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -set_row(int row, const LVecBase3 &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; - (*this)(row, 2) = v[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set_col -// Access: Public -// Description: Replaces the indicated column of the matrix with the -// indicated 3-component vector, ignoring the last -// row. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -set_col(int col, const LVecBase3 &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; - (*this)(2, col) = v[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_row -// Access: Public -// Description: Retrieves the indicated row of the matrix as a -// 4-component vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LMatrix4:: -get_row(int row) const { - return LVecBase4((*this)(row, 0), - (*this)(row, 1), - (*this)(row, 2), - (*this)(row, 3)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_col -// Access: Public -// Description: Retrieves the indicated column of the matrix as a -// 4-component vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LMatrix4:: -get_col(int col) const { - return LVecBase4((*this)(0, col), - (*this)(1, col), - (*this)(2, col), - (*this)(3, col)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_row3 -// Access: Public -// Description: Retrieves the row column of the matrix as a -// 3-component vector, ignoring the last column. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix4:: -get_row3(int row) const { - return LVecBase3((*this)(row, 0), - (*this)(row, 1), - (*this)(row, 2)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_col3 -// Access: Public -// Description: Retrieves the indicated column of the matrix as a -// 3-component vector, ignoring the last row. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix4:: -get_col3(int col) const { - return LVecBase3((*this)(0, col), - (*this)(1, col), - (*this)(2, col)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Indexing operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType &LMatrix4:: -operator () (int row, int col) { - nassertr(row >= 0 && row < 4, _data[0]); - nassertr(col >= 0 && col < 4, _data[0]); - return _data[row * 4 + col]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Indexing operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix4:: -operator () (int row, int col) const { - nassertr(row >= 0 && row < 4, 0.0); - nassertr(col >= 0 && col < 4, 0.0); - return _data[row * 4 + col]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::is_nan -// Access: Public -// Description: Returns true if any component of the matrix is -// not-a-number, false otherwise. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix4:: -is_nan() const { - return - cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || cnan(_data[3]) || - cnan(_data[4]) || cnan(_data[5]) || cnan(_data[6]) || cnan(_data[7]) || - cnan(_data[8]) || cnan(_data[9]) || cnan(_data[10]) || cnan(_data[11]) || - cnan(_data[12]) || cnan(_data[13]) || cnan(_data[14]) || cnan(_data[15]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_cell -// Access: Public -// Description: Returns a particular element of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix4:: -get_cell(int row, int col) const { - nassertr(row >= 0 && row < 4, 0.0); - nassertr(col >= 0 && col < 4, 0.0); - return _data[row * 4 + col]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::set_cell -// Access: Public -// Description: Changes a particular element of the matrix. -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -set_cell(int row, int col, NumType value) { - nassertv(row >= 0 && row < 4); - nassertv(col >= 0 && col < 4); - _data[row * 4 + col] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_data -// Access: Public -// Description: Returns the address of the first of the nine data -// elements in the matrix. The remaining elements -// occupy the next eight positions in row-major order. -//////////////////////////////////////////////////////////////////// -template -INLINE const NumType *LMatrix4:: -get_data() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::get_num_components -// Access: Public -// Description: Returns the number of elements in the matrix, 16. -//////////////////////////////////////////////////////////////////// -template -INLINE int LMatrix4:: -get_num_components() const { - return 16; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::begin -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4::iterator LMatrix4:: -begin() { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::end -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4::iterator LMatrix4:: -end() { - return begin() + 16; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::begin -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4::const_iterator LMatrix4:: -begin() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::end -// Access: Public -// Description: Returns an iterator that may be used to traverse the -// elements of the matrix, STL-style. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4::const_iterator LMatrix4:: -end() const { - return begin() + 16; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Equality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -bool LMatrix4:: -operator == (const LMatrix4 &other) const { - return ((*this)(0, 0) == other(0, 0) && - (*this)(0, 1) == other(0, 1) && - (*this)(0, 2) == other(0, 2) && - (*this)(0, 3) == other(0, 3) && - (*this)(1, 0) == other(1, 0) && - (*this)(1, 1) == other(1, 1) && - (*this)(1, 2) == other(1, 2) && - (*this)(1, 3) == other(1, 3) && - (*this)(2, 0) == other(2, 0) && - (*this)(2, 1) == other(2, 1) && - (*this)(2, 2) == other(2, 2) && - (*this)(2, 3) == other(2, 3) && - (*this)(3, 0) == other(3, 0) && - (*this)(3, 1) == other(3, 1) && - (*this)(3, 2) == other(3, 2) && - (*this)(3, 3) == other(3, 3)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix4:: -operator != (const LMatrix4 &other) const { - return !operator == (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::compare_to -// Access: Public -// Description: This flavor of compare_to uses a default threshold -// value based on the numeric type. -//////////////////////////////////////////////////////////////////// -template -INLINE int LMatrix4:: -compare_to(const LMatrix4 &other) const { - return compare_to(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::compare_to -// Access: Public -// Description: Sorts matrices lexicographically, componentwise. -// Returns a number less than 0 if this matrix sorts -// before the other one, greater than zero if it sorts -// after, 0 if they are equivalent (within the indicated -// tolerance). -//////////////////////////////////////////////////////////////////// -template -int LMatrix4:: -compare_to(const LMatrix4 &other, NumType 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; - } - } - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::xform -// Access: Public -// Description: 4-component vector or point times matrix. This is a -// fully general operation. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LMatrix4:: -xform(const LVecBase4 &v) const { - return LVecBase4(v.dot(get_col(0)), - v.dot(get_col(1)), - v.dot(get_col(2)), - v.dot(get_col(3))); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::xform_point -// Access: Public -// Description: The matrix transforms a 3-component point (including -// translation component) and returns the result. This -// assumes the matrix is an affine transform. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix4:: -xform_point(const LVecBase3 &v) const { - return LVecBase3(v.dot(get_col3(0)) + (*this)(3, 0), - v.dot(get_col3(1)) + (*this)(3, 1), - v.dot(get_col3(2)) + (*this)(3, 2)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::xform_vec -// Access: Public -// Description: The matrix transforms a 3-component vector (without -// translation component) and returns the result. This -// assumes the matrix is an affine transform. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LMatrix4:: -xform_vec(const LVecBase3 &v) const { - return LVecBase3(v.dot(get_col3(0)), - v.dot(get_col3(1)), - v.dot(get_col3(2))); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::mult_cel -// Access: Private -// Description: Returns one cell of the result of a matrix-matrix -// multiplication operation. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LMatrix4:: -mult_cel(const LMatrix4 &other, int row, int col) const { - return get_row(row).dot(other.get_col(col)); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix * matrix -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -operator * (const LMatrix4 &other) const { - LMatrix4 t; - - t(0, 0) = mult_cel(other, 0, 0); - t(0, 1) = mult_cel(other, 0, 1); - t(0, 2) = mult_cel(other, 0, 2); - t(0, 3) = mult_cel(other, 0, 3); - - t(1, 0) = mult_cel(other, 1, 0); - t(1, 1) = mult_cel(other, 1, 1); - t(1, 2) = mult_cel(other, 1, 2); - t(1, 3) = mult_cel(other, 1, 3); - - t(2, 0) = mult_cel(other, 2, 0); - t(2, 1) = mult_cel(other, 2, 1); - t(2, 2) = mult_cel(other, 2, 2); - t(2, 3) = mult_cel(other, 2, 3); - - t(3, 0) = mult_cel(other, 3, 0); - t(3, 1) = mult_cel(other, 3, 1); - t(3, 2) = mult_cel(other, 3, 2); - t(3, 3) = mult_cel(other, 3, 3); - - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -operator * (NumType scalar) const { - LMatrix4 t; - - t(0, 0) = (*this)(0, 0) * scalar; - t(0, 1) = (*this)(0, 1) * scalar; - t(0, 2) = (*this)(0, 2) * scalar; - t(0, 3) = (*this)(0, 3) * scalar; - - t(1, 0) = (*this)(1, 0) * scalar; - t(1, 1) = (*this)(1, 1) * scalar; - t(1, 2) = (*this)(1, 2) * scalar; - t(1, 3) = (*this)(1, 3) * scalar; - - t(2, 0) = (*this)(2, 0) * scalar; - t(2, 1) = (*this)(2, 1) * scalar; - t(2, 2) = (*this)(2, 2) * scalar; - t(2, 3) = (*this)(2, 3) * scalar; - - t(3, 0) = (*this)(3, 0) * scalar; - t(3, 1) = (*this)(3, 1) * scalar; - t(3, 2) = (*this)(3, 2) * scalar; - t(3, 3) = (*this)(3, 3) * scalar; - - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -operator / (NumType scalar) const { - LMatrix4 t; - - t(0, 0) = (*this)(0, 0) / scalar; - t(0, 1) = (*this)(0, 1) / scalar; - t(0, 2) = (*this)(0, 2) / scalar; - t(0, 3) = (*this)(0, 3) / scalar; - - t(1, 0) = (*this)(1, 0) / scalar; - t(1, 1) = (*this)(1, 1) / scalar; - t(1, 2) = (*this)(1, 2) / scalar; - t(1, 3) = (*this)(1, 3) / scalar; - - t(2, 0) = (*this)(2, 0) / scalar; - t(2, 1) = (*this)(2, 1) / scalar; - t(2, 2) = (*this)(2, 2) / scalar; - t(2, 3) = (*this)(2, 3) / scalar; - - t(3, 0) = (*this)(3, 0) / scalar; - t(3, 1) = (*this)(3, 1) / scalar; - t(3, 2) = (*this)(3, 2) / scalar; - t(3, 3) = (*this)(3, 3) / scalar; - - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix += matrix -// Access: Public -// Description: Performs a memberwise addition between two matrices. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 &LMatrix4:: -operator += (const LMatrix4 &other) { - (*this)(0, 0) += other(0, 0); - (*this)(0, 1) += other(0, 1); - (*this)(0, 2) += other(0, 2); - (*this)(0, 3) += other(0, 3); - - (*this)(1, 0) += other(1, 0); - (*this)(1, 1) += other(1, 1); - (*this)(1, 2) += other(1, 2); - (*this)(1, 3) += other(1, 3); - - (*this)(2, 0) += other(2, 0); - (*this)(2, 1) += other(2, 1); - (*this)(2, 2) += other(2, 2); - (*this)(2, 3) += other(2, 3); - - (*this)(3, 0) += other(3, 0); - (*this)(3, 1) += other(3, 1); - (*this)(3, 2) += other(3, 2); - (*this)(3, 3) += other(3, 3); - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix -= matrix -// Access: Public -// Description: Performs a memberwise addition between two matrices. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 &LMatrix4:: -operator -= (const LMatrix4 &other) { - (*this)(0, 0) -= other(0, 0); - (*this)(0, 1) -= other(0, 1); - (*this)(0, 2) -= other(0, 2); - (*this)(0, 3) -= other(0, 3); - - (*this)(1, 0) -= other(1, 0); - (*this)(1, 1) -= other(1, 1); - (*this)(1, 2) -= other(1, 2); - (*this)(1, 3) -= other(1, 3); - - (*this)(2, 0) -= other(2, 0); - (*this)(2, 1) -= other(2, 1); - (*this)(2, 2) -= other(2, 2); - (*this)(2, 3) -= other(2, 3); - - (*this)(3, 0) -= other(3, 0); - (*this)(3, 1) -= other(3, 1); - (*this)(3, 2) -= other(3, 2); - (*this)(3, 3) -= other(3, 3); - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix *= matrix -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4 &LMatrix4:: -operator *= (const LMatrix4 &other) { - (*this) = (*this) * other; - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix *= scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 &LMatrix4:: -operator *= (NumType scalar) { - (*this)(0, 0) *= scalar; - (*this)(0, 1) *= scalar; - (*this)(0, 2) *= scalar; - (*this)(0, 3) *= scalar; - - (*this)(1, 0) *= scalar; - (*this)(1, 1) *= scalar; - (*this)(1, 2) *= scalar; - (*this)(1, 3) *= scalar; - - (*this)(2, 0) *= scalar; - (*this)(2, 1) *= scalar; - (*this)(2, 2) *= scalar; - (*this)(2, 3) *= scalar; - - (*this)(3, 0) *= scalar; - (*this)(3, 1) *= scalar; - (*this)(3, 2) *= scalar; - (*this)(3, 3) *= scalar; - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::matrix /= scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 &LMatrix4:: -operator /= (NumType scalar) { - (*this)(0, 0) /= scalar; - (*this)(0, 1) /= scalar; - (*this)(0, 2) /= scalar; - (*this)(0, 3) /= scalar; - - (*this)(1, 0) /= scalar; - (*this)(1, 1) /= scalar; - (*this)(1, 2) /= scalar; - (*this)(1, 3) /= scalar; - - (*this)(2, 0) /= scalar; - (*this)(2, 1) /= scalar; - (*this)(2, 2) /= scalar; - (*this)(2, 3) /= scalar; - - (*this)(3, 0) /= scalar; - (*this)(3, 1) /= scalar; - (*this)(3, 2) /= scalar; - (*this)(3, 3) /= scalar; - - return *this; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::transpose_from -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -void LMatrix4:: -transpose_from(const LMatrix4 &other) { - (*this)(0, 0) = other(0, 0); - (*this)(0, 1) = other(1, 0); - (*this)(0, 2) = other(2, 0); - (*this)(0, 3) = other(3, 0); - - (*this)(1, 0) = other(0, 1); - (*this)(1, 1) = other(1, 1); - (*this)(1, 2) = other(2, 1); - (*this)(1, 3) = other(3, 1); - - (*this)(2, 0) = other(0, 2); - (*this)(2, 1) = other(1, 2); - (*this)(2, 2) = other(2, 2); - (*this)(2, 3) = other(3, 2); - - (*this)(3, 0) = other(0, 3); - (*this)(3, 1) = other(1, 3); - (*this)(3, 2) = other(2, 3); - (*this)(3, 3) = other(3, 3); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::transpose_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -transpose_in_place() { - LMatrix4 temp = (*this); - transpose_from(temp); -} - - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::invert_from -// Access: Public -// Description: Computes the inverse of the other matrix, and stores -// the result in this matrix. This is a fully general -// operation and makes no assumptions about the type of -// transform represented by the matrix. -// -// The other matrix must be a different object than this -// matrix. However, if you need to invert a matrix in -// place, see invert_in_place. -// -// The return value is true if the matrix was -// successfully inverted, false if the was a -// singularity. -//////////////////////////////////////////////////////////////////// -template -bool LMatrix4:: -invert_from(const LMatrix4 &other) { - if (IS_NEARLY_EQUAL(other(3, 0), 0.0) && - IS_NEARLY_EQUAL(other(3, 1), 0.0) && - IS_NEARLY_EQUAL(other(3, 2), 0.0) && - IS_NEARLY_EQUAL(other(3, 3), 1.0)) { - return invert_affine_from(other); - } - - (*this) = other; - - int index[4]; - - if (!decompose_mat(index)) { - linmath_cat.warning() - << "Tried to invert singular LMatrix4.\n"; - return false; - } - - LMatrix4 inv = LMatrix4::ident_mat(); - int row; - - for (row = 0; row < 4; row++) { - back_sub_mat(index, inv, row); - } - - transpose_from(inv); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::invert_affine_from -// Access: Public -// Description: Performs an invert of the indicated matrix, storing -// the result in this matrix. The calculation is only -// correct of the other matrix represents an affine -// transform. -// -// The other matrix must be a different object than this -// matrix. However, if you need to invert a matrix in -// place, see invert_in_place. -// -// The return value is true if the matrix was -// successfully inverted, false if the was a -// singularity. -//////////////////////////////////////////////////////////////////// -template -bool LMatrix4:: -invert_affine_from(const LMatrix4 &other) { - LMatrix3 rot; - rot.invert_from(other.get_upper_3()); - - set_upper_3(rot); - set_col(3, LVecBase4(0.0, 0.0, 0.0, 1.0)); - - // compute -C*inv(A) - for (int i = 0; i < 3; i++) { - (*this)(3, i) = 0.0; - for (int j = 0; j < 3; j++) { - (*this)(3, i) -= other(3, j) * (*this)(j, i); - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::invert_in_place -// Access: Public -// Description: Inverts the current matrix. Returns true if the -// inverse is successful, false if the matrix was -// singular. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix4:: -invert_in_place() { - LMatrix4 temp = (*this); - return invert_from(temp); -} - - - - - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::ident_mat -// Access: Public, Static -// Description: Returns an identity matrix. -//////////////////////////////////////////////////////////////////// -template -const LMatrix4 &LMatrix4:: -ident_mat() { - static LMatrix4 mat(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); - return mat; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::translate_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// translation. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -translate_mat(const LVecBase3 &trans) { - return 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, - trans[0], trans[1], trans[2], 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::translate_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// translation. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -translate_mat(NumType tx, NumType ty, NumType tz) { - return 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, - tx, ty, tz, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::rotate_mat -// Access: Public, Static -// Description: Returns a matrix that rotates by the given angle in -// degrees counterclockwise about the indicated vector. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -rotate_mat(NumType angle, LVecBase3 axis, - CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - LMatrix4 mat; - - if (!is_right_handed(cs)) { - // In a left-handed coordinate system, counterclockwise is the - // other direction. - angle = -angle; - } - - // Normalize the axis. - NumType length2 = axis.dot(axis); - // Cannot rotate about a zero-length axis. - nassertr(length2 != 0.0, ident_mat()); - NumType recip_sqrt_length2=1.0f/csqrt(length2); - axis *= recip_sqrt_length2; - - double angle_rad=deg_2_rad(angle); - double s,c; - csincos(angle_rad,&s,&c); - double t = 1.0 - c; - - mat(0, 0) = t * axis[0] * axis[0] + c; - mat(0, 1) = t * axis[0] * axis[1] + s * axis[2]; - mat(0, 2) = t * axis[0] * axis[2] - s * axis[1]; - mat(0, 3) = 0.0; - - mat(1, 0) = t * axis[1] * axis[0] - s * axis[2]; - mat(1, 1) = t * axis[1] * axis[1] + c; - mat(1, 2) = t * axis[1] * axis[2] + s * axis[0]; - mat(1, 3) = 0.0; - - mat(2, 0) = t * axis[2] * axis[0] + s * axis[1]; - mat(2, 1) = t * axis[2] * axis[1] - s * axis[0]; - mat(2, 2) = t * axis[2] * axis[2] + c; - mat(2, 3) = 0.0; - - mat(3, 0) = 0.0; - mat(3, 1) = 0.0; - mat(3, 2) = 0.0; - mat(3, 3) = 1.0; - - return mat; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// scale in each of the three axes. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -scale_mat(const LVecBase3 &scale) { - return LMatrix4(scale[0], 0.0, 0.0, 0.0, - 0.0, scale[1], 0.0, 0.0, - 0.0, 0.0, scale[2], 0.0, - 0.0, 0.0, 0.0, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// scale in each of the three axes. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -scale_mat(NumType sx, NumType sy, NumType sz) { - return LMatrix4(sx, 0.0, 0.0, 0.0, - 0.0, sy, 0.0, 0.0, - 0.0, 0.0, sz, 0.0, - 0.0, 0.0, 0.0, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::scale_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// uniform scale. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -scale_mat(NumType scale) { - return LMatrix4(scale, 0.0, 0.0, 0.0, - 0.0, scale, 0.0, 0.0, - 0.0, 0.0, scale, 0.0, - 0.0, 0.0, 0.0, 1.0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::y_to_z_up_mat -// Access: Public, Static -// Description: Returns a matrix that transforms from the Y-up -// coordinate system to the Z-up coordinate system. -//////////////////////////////////////////////////////////////////// -template -const LMatrix4 &LMatrix4:: -y_to_z_up_mat() { - static LMatrix4 mat(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); - return mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::z_to_y_up_mat -// Access: Public, Static -// Description: Returns a matrix that transforms from the Y-up -// coordinate system to the Z-up coordinate system. -//////////////////////////////////////////////////////////////////// -template -const LMatrix4 &LMatrix4:: -z_to_y_up_mat() { - static LMatrix4 mat(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); - return mat; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix::convert_mat -// Access: Public, Static -// Description: Returns a matrix that transforms from the indicated -// coordinate system to the indicated coordinate system. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 LMatrix4:: -convert_mat(CoordinateSystem from, CoordinateSystem to) { - if (from == CS_default) { - from = default_coordinate_system; - } - if (to == CS_default) { - to = default_coordinate_system; - } - switch (from) { - case CS_zup_left: - switch (to) { - case CS_zup_left: return ident_mat(); - case CS_yup_left: return z_to_y_up_mat(); - case CS_zup_right: return scale_mat(1.0, -1.0, 1.0); - case CS_yup_right: return scale_mat(1.0, -1.0, 1.0) * z_to_y_up_mat(); - default: break; - } - break; - - case CS_yup_left: - switch (to) { - case CS_zup_left: return y_to_z_up_mat(); - case CS_yup_left: return ident_mat(); - case CS_zup_right: return scale_mat(1.0, 1.0, -1.0) * y_to_z_up_mat(); - case CS_yup_right: return scale_mat(1.0, 1.0, -1.0); - default: break; - } - break; - - case CS_zup_right: - switch (to) { - case CS_zup_left: return scale_mat(1.0, -1.0, 1.0); - case CS_yup_left: return scale_mat(1.0, -1.0, 1.0) * z_to_y_up_mat(); - case CS_zup_right: return ident_mat(); - case CS_yup_right: return z_to_y_up_mat(); - default: break; - } - break; - - case CS_yup_right: - switch (to) { - case CS_zup_left: return scale_mat(1.0, 1.0, -1.0) * y_to_z_up_mat(); - case CS_yup_left: return scale_mat(1.0, 1.0, -1.0); - case CS_zup_right: return y_to_z_up_mat(); - case CS_yup_right: return ident_mat(); - default: break; - } - break; - - default: - break; - } - - linmath_cat.error() - << "Invalid coordinate system value!\n"; - return ident_mat(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::almost_equal -// Access: Public -// Description: Returns true if two matrices are memberwise equal -// within a specified tolerance. -//////////////////////////////////////////////////////////////////// -template -bool LMatrix4:: -almost_equal(const LMatrix4 &other, NumType 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) && - IS_THRESHOLD_EQUAL((*this)(0, 3), other(0, 3), threshold) && - IS_THRESHOLD_EQUAL((*this)(1, 0), other(1, 0), threshold) && - IS_THRESHOLD_EQUAL((*this)(1, 1), other(1, 1), threshold) && - IS_THRESHOLD_EQUAL((*this)(1, 2), other(1, 2), threshold) && - IS_THRESHOLD_EQUAL((*this)(1, 3), other(1, 3), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 0), other(2, 0), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 1), other(2, 1), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 2), other(2, 2), threshold) && - IS_THRESHOLD_EQUAL((*this)(2, 3), other(2, 3), threshold) && - IS_THRESHOLD_EQUAL((*this)(3, 0), other(3, 0), threshold) && - IS_THRESHOLD_EQUAL((*this)(3, 1), other(3, 1), threshold) && - IS_THRESHOLD_EQUAL((*this)(3, 2), other(3, 2), threshold) && - IS_THRESHOLD_EQUAL((*this)(3, 3), other(3, 3), threshold)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::almost_equal -// Access: Public -// Description: Returns true if two matrices are memberwise equal -// within a default tolerance based on the numeric type. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LMatrix4:: -almost_equal(const LMatrix4 &other) const { - return almost_equal(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -output(ostream &out) const { - out << "[ " - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) << " " - << MAYBE_ZERO((*this)(0, 3)) - << " ] [ " - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) << " " - << MAYBE_ZERO((*this)(1, 3)) - << " ] [ " - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) << " " - << MAYBE_ZERO((*this)(2, 3)) - << " ] [ " - << MAYBE_ZERO((*this)(3, 0)) << " " - << MAYBE_ZERO((*this)(3, 1)) << " " - << MAYBE_ZERO((*this)(3, 2)) << " " - << MAYBE_ZERO((*this)(3, 3)) - << " ]"; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LMatrix4:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) << " " - << MAYBE_ZERO((*this)(0, 3)) - << "\n"; - indent(out, indent_level) - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) << " " - << MAYBE_ZERO((*this)(1, 3)) - << "\n"; - indent(out, indent_level) - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) << " " - << MAYBE_ZERO((*this)(2, 3)) - << "\n"; - indent(out, indent_level) - << MAYBE_ZERO((*this)(3, 0)) << " " - << MAYBE_ZERO((*this)(3, 1)) << " " - << MAYBE_ZERO((*this)(3, 2)) << " " - << MAYBE_ZERO((*this)(3, 3)) - << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::decompose_mat -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -template -bool LMatrix4:: -decompose_mat(int index[4]) { - int i, j, k; - NumType vv[4]; - for (i = 0; i < 4; i++) { - NumType big = 0.0; - for (j = 0; j < 4; j++) { - NumType temp = fabs((*this)(i,j)); - if (temp > big) { - big = temp; - } - } - - if (IS_NEARLY_ZERO(big)) { - return false; - } - vv[i] = 1.0 / big; - } - - for (j = 0; j < 4; j++) { - for (i = 0; i < j; i++) { - NumType sum = (*this)(i,j); - for (k = 0; k < i; k++) { - sum -= (*this)(i,k) * (*this)(k,j); - } - (*this)(i,j) = sum; - } - - NumType big = 0.0; - int imax = -1; - for (i = j; i < 4; i++) { - NumType sum = (*this)(i,j); - for (k = 0; k < j; k++) { - sum -= (*this)(i,k) * (*this)(k,j); - } - (*this)(i,j) = sum; - - NumType dum = vv[i] * fabs(sum); - if (dum >= big) { - big = dum; - imax = i; - } - } - nassertr(imax >= 0, false); - if (j != imax) { - for (k = 0; k < 4; k++) { - NumType dum = (*this)(imax,k); - (*this)(imax,k) = (*this)(j,k); - (*this)(j,k) = dum; - } - vv[imax] = vv[j]; - } - index[j] = imax; - - if ((*this)(j,j) == 0.0) { - (*this)(j,j) = NEARLY_ZERO(NumType); - } - - if (j != 4 - 1) { - NumType dum = 1.0 / (*this)(j,j); - for (i = j + 1; i < 4; i++) { - (*this)(i,j) *= dum; - } - } - } - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::back_sub_mat -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -template -bool LMatrix4:: -back_sub_mat(int index[4], LMatrix4 &inv, int row) const { - int ii = -1; - int i, j; - for (i = 0; i < 4; i++) { - int ip = index[i]; - NumType sum = inv(row, ip); - inv(row, ip) = inv(row, i); - if (ii >= 0) { - for (j = ii; j <= i - 1; j++) { - sum -= (*this)(i,j) * inv(row, j); - } - } else if (sum) { - ii = i; - } - - inv(row, i) = sum; - } - - for (i = 4 - 1; i >= 0; i--) { - NumType sum = inv(row, i); - for (j = i + 1; j < 4; j++) { - sum -= (*this)(i,j) * inv(row, j); - } - inv(row, i) = sum / (*this)(i,i); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LMatrix4:: -init_type() { - if (_type_handle == TypeHandle::none()) { - // Format a string to describe the type. - do_init_type(NumType); - string name = - "LMatrix4<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::write_datagram -// Description: Writes the matrix to the datagram -//////////////////////////////////////////////////////////////////// -template -void LMatrix4:: -write_datagram(Datagram &destination) const -{ - for(int i = 0; i < 4; i++) - { - for(int j = 0; j < 4; j++) - { - destination.add_float32(get_cell(i,j)); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::read_datagram -// Description: Reads itself out of the datagram -//////////////////////////////////////////////////////////////////// -template -void LMatrix4:: -read_datagram(DatagramIterator &scan) -{ - for(int i = 0; i < 4; i++) - { - for(int j = 0; j < 4; j++) - { - set_cell(i, j, scan.get_float32()); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::transpose -// Description: Transposes the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4 -transpose(const LMatrix4 &a) { - LMatrix4 result; - result.transpose_from(a); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::invert -// Description: Inverts the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4 -invert(const LMatrix4 &a) { - LMatrix4 result; - bool nonsingular = result.invert_from(a); - nassertr(nonsingular, LMatrix4::ident_mat()); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: lcast_to -// Description: Converts a matrix from one numeric representation to -// another one. This is usually invoked using the macro -// LCAST. -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4 -lcast_to(NumType2 *, const LMatrix4 &source) { - return 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)); -} diff --git a/panda/src/linmath/lmatrix4.cxx b/panda/src/linmath/lmatrix4.cxx deleted file mode 100644 index ae6b092168..0000000000 --- a/panda/src/linmath/lmatrix4.cxx +++ /dev/null @@ -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" - - diff --git a/panda/src/linmath/lmatrix4.h b/panda/src/linmath/lmatrix4.h deleted file mode 100644 index 1d813d07c3..0000000000 --- a/panda/src/linmath/lmatrix4.h +++ /dev/null @@ -1,188 +0,0 @@ -// Filename: lmatrix4.h -// Created by: drose (29Jan99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LMATRIX4_H -#define LMATRIX4_H - -#include - -#include "coordinateSystem.h" -#include "lvecBase4.h" -#include "lvecBase3.h" -#include "lmatrix3.h" - -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : LMatrix4 -// Description : This is a 4-by-4 transform matrix. -//////////////////////////////////////////////////////////////////// -template -class LMatrix4 { -PUBLISHED: - typedef const NumType *iterator; - typedef const NumType *const_iterator; - - INLINE LMatrix4(); - INLINE LMatrix4(const LMatrix4 &other); - LMatrix4 &operator = (const LMatrix4 &other); - INLINE LMatrix4 &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 &upper3); - LMatrix4(const LMatrix3 &upper3, - const LVecBase3 &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 &upper3); - INLINE LMatrix3 get_upper_3() const; - - INLINE void set_row(int row, const LVecBase4 &v); - INLINE void set_col(int col, const LVecBase4 &v); - - INLINE void set_row(int row, const LVecBase3 &v); - INLINE void set_col(int col, const LVecBase3 &v); - - INLINE LVecBase4 get_row(int row) const; - INLINE LVecBase4 get_col(int col) const; - - INLINE LVecBase3 get_row3(int row) const; - INLINE LVecBase3 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 &other) const; - INLINE bool operator != (const LMatrix4 &other) const; - - INLINE int compare_to(const LMatrix4 &other) const; - int compare_to(const LMatrix4 &other, NumType threshold) const; - - INLINE LVecBase4 - xform(const LVecBase4 &v) const; - - INLINE LVecBase3 - xform_point(const LVecBase3 &v) const; - - INLINE LVecBase3 - xform_vec(const LVecBase3 &v) const; - - LMatrix4 operator * (const LMatrix4 &other) const; - LMatrix4 operator * (NumType scalar) const; - LMatrix4 operator / (NumType scalar) const; - - LMatrix4 &operator += (const LMatrix4 &other); - LMatrix4 &operator -= (const LMatrix4 &other); - - INLINE LMatrix4 &operator *= (const LMatrix4 &other); - - LMatrix4 &operator *= (NumType scalar); - LMatrix4 &operator /= (NumType scalar); - - void transpose_from(const LMatrix4 &other); - INLINE void transpose_in_place(); - - bool invert_from(const LMatrix4 &other); - bool invert_affine_from(const LMatrix4 &other); - INLINE bool invert_in_place(); - - static const LMatrix4 &ident_mat(); - static LMatrix4 translate_mat(const LVecBase3 &trans); - static LMatrix4 translate_mat(NumType tx, NumType ty, NumType tz); - static LMatrix4 rotate_mat(NumType angle, - LVecBase3 axis, - CoordinateSystem cs = CS_default); - static LMatrix4 scale_mat(const LVecBase3 &scale); - static LMatrix4 scale_mat(NumType sx, NumType sy, NumType sz); - static LMatrix4 scale_mat(NumType scale); - - static const LMatrix4 &y_to_z_up_mat(); - static const LMatrix4 &z_to_y_up_mat(); - - static LMatrix4 convert_mat(CoordinateSystem from, - CoordinateSystem to); - - - bool almost_equal(const LMatrix4 &other, - NumType threshold) const; - INLINE bool almost_equal(const LMatrix4 &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 &other, int x, int y) const; - bool decompose_mat(int index[4]); - bool back_sub_mat(int index[4], LMatrix4 &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 -INLINE ostream &operator << (ostream &out, const LMatrix4 &mat) { - mat.output(out); - return out; -} - -template -INLINE LMatrix4 transpose(const LMatrix4 &a); - -template -INLINE LMatrix4 invert(const LMatrix4 &a); - -// Cast to a different numeric type -template -INLINE LMatrix4 -lcast_to(NumType2 *type, const LMatrix4 &source); - - -#include "lmatrix4.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix4) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LMatrix4) - -#endif diff --git a/panda/src/linmath/lmatrix4_src.I b/panda/src/linmath/lmatrix4_src.cxx similarity index 87% rename from panda/src/linmath/lmatrix4_src.I rename to panda/src/linmath/lmatrix4_src.cxx index 3379ed3fde..1e3e974bef 100644 --- a/panda/src/linmath/lmatrix4_src.I +++ b/panda/src/linmath/lmatrix4_src.cxx @@ -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; diff --git a/panda/src/linmath/lmatrix4_src.h b/panda/src/linmath/lmatrix4_src.h new file mode 100644 index 0000000000..deec2430ca --- /dev/null +++ b/panda/src/linmath/lmatrix4_src.h @@ -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" diff --git a/panda/src/linmath/lorientation.I b/panda/src/linmath/lorientation.I deleted file mode 100644 index d4454a6228..0000000000 --- a/panda/src/linmath/lorientation.I +++ /dev/null @@ -1,134 +0,0 @@ -// Filename: lorientation.I -// Created by: frang, charles (23Jun00) -// -//////////////////////////////////////////////////////////////////// - -#include "lorientation.h" -#include - -template -TypeHandle LOrientation::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::Default Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LOrientation:: -LOrientation() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::Copy Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LOrientation:: -LOrientation(const LQuaternionBase& c) : - LQuaternionBase(c) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LOrientation:: -LOrientation(NumType r, NumType i, NumType j, NumType k) : - LQuaternionBase(r, i, j, k) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::Constructor -// Access: public -// Description: vector + twist -//////////////////////////////////////////////////////////////////// -template -INLINE LOrientation:: -LOrientation(const LVector3 &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 -INLINE LOrientation:: -LOrientation(const LMatrix3 &m) { - set(m); -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::Constructor -// Access: public -// Description: matrix4 -//////////////////////////////////////////////////////////////////// -template -INLINE LOrientation:: -LOrientation(const LMatrix4 &m) { - set(m); -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::Destructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -LOrientation:: -~LOrientation() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::operator * -// Access: public -// Description: Orientation * rotation = Orientation -// Applies an rotation to an orientation. -//////////////////////////////////////////////////////////////////// -template -INLINE LOrientation LOrientation:: -operator *(const LQuaternionBase& 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 -INLINE LOrientation LOrientation:: -operator *(const LOrientation& other) const { - return other; -} - -//////////////////////////////////////////////////////////////////// -// Function: LOrientation::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LOrientation:: -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); - } -} diff --git a/panda/src/linmath/lorientation.cxx b/panda/src/linmath/lorientation.cxx deleted file mode 100644 index c3c2edc69e..0000000000 --- a/panda/src/linmath/lorientation.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lorientation.h b/panda/src/linmath/lorientation.h deleted file mode 100644 index 20a77490b0..0000000000 --- a/panda/src/linmath/lorientation.h +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: lorientation.h -// Created by: frang, charles (23Jun00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef __LORIENTATION_H__ -#define __LORIENTATION_H__ - -#include -#include "lquaternion.h" - -//////////////////////////////////////////////////////////////////////// -// Class : LOrientation -// Description : This is a unit quaternion representing an orientation. -//////////////////////////////////////////////////////////////////////// -template -class LOrientation : public LQuaternionBase { -public: - INLINE LOrientation(); - INLINE LOrientation(const LQuaternionBase&); - INLINE LOrientation(NumType, NumType, NumType, NumType); - INLINE LOrientation(const LVector3 &, float); - INLINE LOrientation(const LMatrix3 &); - INLINE LOrientation(const LMatrix4 &); - virtual ~LOrientation(); - - INLINE LOrientation - operator *(const LQuaternionBase& other) const; - - INLINE LOrientation - operator *(const LOrientation& 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) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LOrientation) - -#endif /* __LORIENTATION_H__ */ diff --git a/panda/src/linmath/lorientation_src.I b/panda/src/linmath/lorientation_src.I deleted file mode 100644 index a4d579c3cb..0000000000 --- a/panda/src/linmath/lorientation_src.I +++ /dev/null @@ -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)() { -} diff --git a/panda/src/linmath/lorientation_src.cxx b/panda/src/linmath/lorientation_src.cxx new file mode 100644 index 0000000000..77abe68bd1 --- /dev/null +++ b/panda/src/linmath/lorientation_src.cxx @@ -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()); + } +} diff --git a/panda/src/linmath/lorientation_src.h b/panda/src/linmath/lorientation_src.h new file mode 100644 index 0000000000..33ddabcddb --- /dev/null +++ b/panda/src/linmath/lorientation_src.h @@ -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" diff --git a/panda/src/linmath/lpoint2.I b/panda/src/linmath/lpoint2.I deleted file mode 100644 index 695472aea5..0000000000 --- a/panda/src/linmath/lpoint2.I +++ /dev/null @@ -1,225 +0,0 @@ -// Filename: lpoint2.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle LPoint2::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2:: -LPoint2() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2:: -LPoint2(const LVecBase2 ©) : LVecBase2(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 &LPoint2:: -operator = (const LVecBase2 ©) { - LVecBase2::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 &LPoint2:: -operator = (NumType fill_value) { - LVecBase2::operator = (fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2:: -LPoint2(NumType fill_value) : - LVecBase2(fill_value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2:: -LPoint2(NumType x, NumType y) : - LVecBase2(x, y) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::zero Named Constructor -// Access: Public -// Description: Returns a zero point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -zero() { - return LPoint2(0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -unit_x() { - return LPoint2(1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -unit_y() { - return LPoint2(0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::unary - -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -operator - () const { - return LVecBase2::operator - (); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::point + vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LPoint2:: -operator + (const LVecBase2 &other) const { - return LVecBase2::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::point + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -operator + (const LVector2 &other) const { - return LVecBase2::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::point - vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LPoint2:: -operator - (const LVecBase2 &other) const { - return LVecBase2::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::point - point -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LPoint2:: -operator - (const LPoint2 &other) const { - return LVecBase2::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::point - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -operator - (const LVector2 &other) const { - return LVecBase2::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::operator * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -operator * (NumType scalar) const { - return LPoint2(LVecBase2::operator * (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::operator / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 LPoint2:: -operator / (NumType scalar) const { - return LPoint2(LVecBase2::operator / (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LPoint2:: -init_type() { - if (_type_handle == TypeHandle::none()) { - LVecBase2::init_type(); - string name = - "LPoint2<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name, - LVecBase2::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 -INLINE LPoint2 -lcast_to(NumType2 *, const LPoint2 &source) { - return LPoint2(source[0], source[1]); -} diff --git a/panda/src/linmath/lpoint2.cxx b/panda/src/linmath/lpoint2.cxx deleted file mode 100644 index cbe09d5d21..0000000000 --- a/panda/src/linmath/lpoint2.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lpoint2.h b/panda/src/linmath/lpoint2.h deleted file mode 100644 index c444f5f68a..0000000000 --- a/panda/src/linmath/lpoint2.h +++ /dev/null @@ -1,69 +0,0 @@ -// Filename: lpoint2.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LPOINT2_H -#define LPOINT2_H - -#include - -#include "lvecBase2.h" -#include "lvector2.h" - -//////////////////////////////////////////////////////////////////// -// Class : LPoint2 -// Description : This is a two-component point in space. -//////////////////////////////////////////////////////////////////// -template -class LPoint2 : public LVecBase2 { -PUBLISHED: - INLINE LPoint2(); - INLINE LPoint2(const LVecBase2 ©); - INLINE LPoint2 &operator = (const LVecBase2 ©); - INLINE LPoint2 &operator = (NumType fill_value); - INLINE LPoint2(NumType fill_value); - INLINE LPoint2(NumType x, NumType y); - - INLINE static LPoint2 zero(); - INLINE static LPoint2 unit_x(); - INLINE static LPoint2 unit_y(); - - INLINE LPoint2 operator - () const; - - INLINE LVecBase2 - operator + (const LVecBase2 &other) const; - INLINE LPoint2 - operator + (const LVector2 &other) const; - - INLINE LVecBase2 - operator - (const LVecBase2 &other) const; - INLINE LVector2 - operator - (const LPoint2 &other) const; - INLINE LPoint2 - operator - (const LVector2 &other) const; - - INLINE LPoint2 operator * (NumType scalar) const; - INLINE LPoint2 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 -INLINE LPoint2 -lcast_to(NumType2 *type, const LPoint2 &source); - -#include "lpoint2.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint2) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint2) - -#endif diff --git a/panda/src/linmath/lpoint2_src.I b/panda/src/linmath/lpoint2_src.cxx similarity index 84% rename from panda/src/linmath/lpoint2_src.I rename to panda/src/linmath/lpoint2_src.cxx index 38e61d0583..45a19d84d7 100644 --- a/panda/src/linmath/lpoint2_src.I +++ b/panda/src/linmath/lpoint2_src.cxx @@ -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()); } diff --git a/panda/src/linmath/lpoint2_src.h b/panda/src/linmath/lpoint2_src.h new file mode 100644 index 0000000000..876082987b --- /dev/null +++ b/panda/src/linmath/lpoint2_src.h @@ -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) ©); + INLINE FLOATNAME(LPoint2) &operator = (const FLOATNAME(LVecBase2) ©); + 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" diff --git a/panda/src/linmath/lpoint3.I b/panda/src/linmath/lpoint3.I deleted file mode 100644 index 14bd5d1326..0000000000 --- a/panda/src/linmath/lpoint3.I +++ /dev/null @@ -1,278 +0,0 @@ -// Filename: lpoint3.I -// Created by: drose (25Sep99) -// -//////////////////////////////////////////////////////////////////// - -#include "lvector3.h" - -template -TypeHandle LPoint3::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3:: -LPoint3() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3:: -LPoint3(const LVecBase3 ©) : LVecBase3(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 &LPoint3:: -operator = (const LVecBase3 ©) { - LVecBase3::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 &LPoint3:: -operator = (NumType fill_value) { - LVecBase3::operator = (fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3:: -LPoint3(NumType fill_value) : - LVecBase3(fill_value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3:: -LPoint3(NumType x, NumType y, NumType z) : - LVecBase3(x, y, z) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::zero Named Constructor -// Access: Public -// Description: Returns a zero point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -zero() { - return LPoint3(0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -unit_x() { - return LPoint3(1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -unit_y() { - return LPoint3(0.0, 1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::unit_z Named Constructor -// Access: Public -// Description: Returns a unit Z point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -unit_z() { - return LPoint3(0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::unary - -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -operator - () const { - return LVecBase3::operator - (); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::point + vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LPoint3:: -operator + (const LVecBase3 &other) const { - return LVecBase3::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::point + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -operator + (const LVector3 &other) const { - return LVecBase3::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::point - vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LPoint3:: -operator - (const LVecBase3 &other) const { - return LVecBase3::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::point - point -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LPoint3:: -operator - (const LPoint3 &other) const { - return LVecBase3::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::point - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -operator - (const LVector3 &other) const { - return LVecBase3::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::cross -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -cross(const LVecBase3 &other) const { - return LVecBase3::cross(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::operator * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -operator * (NumType scalar) const { - return LPoint3(LVecBase3::operator * (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::operator / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 LPoint3:: -operator / (NumType scalar) const { - return LPoint3(LVecBase3::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 -INLINE LPoint3 LPoint3:: -origin(CoordinateSystem) { - return LPoint3(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 -INLINE LPoint3 LPoint3:: -rfu(NumType right_v, NumType fwd_v, NumType up_v, - CoordinateSystem cs) { - return origin(cs) + - LVector3::rfu(right_v, fwd_v, up_v, cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LPoint3:: -init_type() { - if (_type_handle == TypeHandle::none()) { - LVecBase3::init_type(); - string name = - "LPoint3<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name, - LVecBase3::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 -INLINE LPoint3 -lcast_to(NumType2 *, const LPoint3 &source) { - return LPoint3(source[0], source[1], source[2]); -} diff --git a/panda/src/linmath/lpoint3.cxx b/panda/src/linmath/lpoint3.cxx deleted file mode 100644 index cb664eca32..0000000000 --- a/panda/src/linmath/lpoint3.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lpoint3.h b/panda/src/linmath/lpoint3.h deleted file mode 100644 index 07de1ab8c6..0000000000 --- a/panda/src/linmath/lpoint3.h +++ /dev/null @@ -1,85 +0,0 @@ -// Filename: lpoint3.h -// Created by: drose (25Sep99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LPOINT3_H -#define LPOINT3_H - -#include - -#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 LPoint3 : public LVecBase3 { -PUBLISHED: - INLINE LPoint3(); - INLINE LPoint3(const LVecBase3 ©); - INLINE LPoint3 &operator = (const LVecBase3 ©); - INLINE LPoint3 &operator = (NumType fill_value); - INLINE LPoint3(NumType fill_value); - INLINE LPoint3(NumType x, NumType y, NumType z); - - INLINE static LPoint3 zero(); - INLINE static LPoint3 unit_x(); - INLINE static LPoint3 unit_y(); - INLINE static LPoint3 unit_z(); - - INLINE LPoint3 operator - () const; - - INLINE LVecBase3 - operator + (const LVecBase3 &other) const; - INLINE LPoint3 - operator + (const LVector3 &other) const; - - INLINE LVecBase3 - operator - (const LVecBase3 &other) const; - INLINE LVector3 - operator - (const LPoint3 &other) const; - INLINE LPoint3 - operator - (const LVector3 &other) const; - - INLINE LPoint3 cross(const LVecBase3 &other) const; - INLINE LPoint3 operator * (NumType scalar) const; - INLINE LPoint3 operator / (NumType scalar) const; - - // Some special named constructors for LPoint3. - - INLINE static LPoint3 origin(CoordinateSystem cs = CS_default); - INLINE static LPoint3 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 -INLINE LPoint3 -lcast_to(NumType2 *type, const LPoint3 &source); - -#include "lpoint3.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint3) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint3) - -#endif diff --git a/panda/src/linmath/lpoint3_src.I b/panda/src/linmath/lpoint3_src.cxx similarity index 84% rename from panda/src/linmath/lpoint3_src.I rename to panda/src/linmath/lpoint3_src.cxx index 54ca7617ef..83fba2c687 100644 --- a/panda/src/linmath/lpoint3_src.I +++ b/panda/src/linmath/lpoint3_src.cxx @@ -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()); } diff --git a/panda/src/linmath/lpoint3_src.h b/panda/src/linmath/lpoint3_src.h new file mode 100644 index 0000000000..74e24f9483 --- /dev/null +++ b/panda/src/linmath/lpoint3_src.h @@ -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) ©); + INLINE FLOATNAME(LPoint3) &operator = (const FLOATNAME(LVecBase3) ©); + 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" diff --git a/panda/src/linmath/lpoint4.I b/panda/src/linmath/lpoint4.I deleted file mode 100644 index c1dd818c71..0000000000 --- a/panda/src/linmath/lpoint4.I +++ /dev/null @@ -1,247 +0,0 @@ -// Filename: lpoint4.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle LPoint4::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4:: -LPoint4() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4:: -LPoint4(const LVecBase4 ©) : LVecBase4(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 &LPoint4:: -operator = (const LVecBase4 ©) { - LVecBase4::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 &LPoint4:: -operator = (NumType fill_value) { - LVecBase4::operator = (fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4:: -LPoint4(NumType fill_value) : - LVecBase4(fill_value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4:: -LPoint4(NumType x, NumType y, NumType z, NumType w) : - LVecBase4(x, y, z, w) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::zero Named Constructor -// Access: Public -// Description: Returns a zero point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -zero() { - return LPoint4(0.0, 0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -unit_x() { - return LPoint4(1.0, 0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -unit_y() { - return LPoint4(0.0, 1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::unit_z Named Constructor -// Access: Public -// Description: Returns a unit Z point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -unit_z() { - return LPoint4(0.0, 0.0, 1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::unit_w Named Constructor -// Access: Public -// Description: Returns a unit W point. -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -unit_w() { - return LPoint4(0.0, 0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::unary - -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -operator - () const { - return LVecBase4::operator - (); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::point + vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LPoint4:: -operator + (const LVecBase4 &other) const { - return LVecBase4::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::point + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -operator + (const LVector4 &other) const { - return LVecBase4::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::point - vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LPoint4:: -operator - (const LVecBase4 &other) const { - return LVecBase4::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::point - point -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LPoint4:: -operator - (const LPoint4 &other) const { - return LVecBase4::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::point - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -operator - (const LVector4 &other) const { - return LVecBase4::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::operator * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -operator * (NumType scalar) const { - return LPoint4(LVecBase4::operator * (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::operator / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 LPoint4:: -operator / (NumType scalar) const { - return LPoint4(LVecBase4::operator / (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LPoint4:: -init_type() { - if (_type_handle == TypeHandle::none()) { - LVecBase4::init_type(); - string name = - "LPoint4<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name, - LVecBase4::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 -INLINE LPoint4 -lcast_to(NumType2 *, const LPoint4 &source) { - return LPoint4(source[0], source[1], source[2], source[3]); -} diff --git a/panda/src/linmath/lpoint4.cxx b/panda/src/linmath/lpoint4.cxx deleted file mode 100644 index bb7f69f1e0..0000000000 --- a/panda/src/linmath/lpoint4.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lpoint4.h b/panda/src/linmath/lpoint4.h deleted file mode 100644 index f0ddf00156..0000000000 --- a/panda/src/linmath/lpoint4.h +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: lpoint4.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LPOINT4_H -#define LPOINT4_H - -#include - -#include "lvecBase4.h" -#include "lvector4.h" - -//////////////////////////////////////////////////////////////////// -// Class : LPoint4 -// Description : This is a four-component point in space. -//////////////////////////////////////////////////////////////////// -template -class LPoint4 : public LVecBase4 { -PUBLISHED: - INLINE LPoint4(); - INLINE LPoint4(const LVecBase4 ©); - INLINE LPoint4 &operator = (const LVecBase4 ©); - INLINE LPoint4 &operator = (NumType fill_value); - INLINE LPoint4(NumType fill_value); - INLINE LPoint4(NumType x, NumType y, NumType z, NumType w); - - INLINE static LPoint4 zero(); - INLINE static LPoint4 unit_x(); - INLINE static LPoint4 unit_y(); - INLINE static LPoint4 unit_z(); - INLINE static LPoint4 unit_w(); - - INLINE LPoint4 operator - () const; - - INLINE LVecBase4 - operator + (const LVecBase4 &other) const; - INLINE LPoint4 - operator + (const LVector4 &other) const; - - INLINE LVecBase4 - operator - (const LVecBase4 &other) const; - INLINE LVector4 - operator - (const LPoint4 &other) const; - INLINE LPoint4 - operator - (const LVector4 &other) const; - - INLINE LPoint4 operator * (NumType scalar) const; - INLINE LPoint4 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 -INLINE LPoint4 -lcast_to(NumType2 *type, const LPoint4 &source); - -#include "lpoint4.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LPoint4) - -#endif diff --git a/panda/src/linmath/lpoint4_src.I b/panda/src/linmath/lpoint4_src.cxx similarity index 84% rename from panda/src/linmath/lpoint4_src.I rename to panda/src/linmath/lpoint4_src.cxx index 15fa748d30..4c385038fc 100644 --- a/panda/src/linmath/lpoint4_src.I +++ b/panda/src/linmath/lpoint4_src.cxx @@ -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()); } diff --git a/panda/src/linmath/lpoint4_src.h b/panda/src/linmath/lpoint4_src.h new file mode 100644 index 0000000000..46c71db230 --- /dev/null +++ b/panda/src/linmath/lpoint4_src.h @@ -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) ©); + INLINE FLOATNAME(LPoint4) &operator = (const FLOATNAME(LVecBase4) ©); + 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" diff --git a/panda/src/linmath/lquaternion.I b/panda/src/linmath/lquaternion.I deleted file mode 100644 index e5e22d1f33..0000000000 --- a/panda/src/linmath/lquaternion.I +++ /dev/null @@ -1,623 +0,0 @@ -// Filename: lquaternion.I -// Created by: frang (06Jun00) -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle LQuaternionBase::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Default Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LQuaternionBase:: -LQuaternionBase(void) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Copy Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LQuaternionBase:: -LQuaternionBase(const LQuaternionBase& c) : - _r(c._r), _i(c._i), _j(c._j), _k(c._k) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LQuaternionBase:: -LQuaternionBase(NumType r, NumType i, NumType j, NumType k) { - set(r, i, j, k); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Destructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -LQuaternionBase:: -~LQuaternionBase() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::pure_imaginary_quat -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -LQuaternionBase LQuaternionBase:: -pure_imaginary(const LVector3 &v) { - return LQuaternionBase(0, v[0], v[1], v[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::ident_quat -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -const LQuaternionBase &LQuaternionBase:: -ident_quat(void) { - static LQuaternionBase q(1, 0, 0, 0); - return q; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::set -// Access: public -// Description: assignment -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -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 -INLINE LQuaternionBase& LQuaternionBase:: -operator =(const LQuaternionBase& c) { - _r = c._r; - _i = c._i; - _j = c._j; - _k = c._k; - - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Equality Operator -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LQuaternionBase:: -operator ==(const LQuaternionBase& c) const { - return (_r == c._r && - _i == c._i && - _j == c._j && - _k == c._k); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Inequality Operator -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LQuaternionBase:: -operator !=(const LQuaternionBase& c) const { - return !operator==(c); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::multiply -// Access: protected -// Description: actual multiply call (non virtual) -//////////////////////////////////////////////////////////////////// -template -INLINE LQuaternionBase LQuaternionBase:: -multiply(const LQuaternionBase& 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(r, i , j, k); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Multiply Operator -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LQuaternionBase LQuaternionBase:: -operator *(const LQuaternionBase& c) { - return multiply(c); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Multiply Assignment Operator -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LQuaternionBase& LQuaternionBase:: -operator *=(const LQuaternionBase& c) { - (*this) = operator*(c); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Multiply Operator -// Access: public -// Description: Quat * Matrix = matrix -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix3 LQuaternionBase:: -operator *(const LMatrix3 &m) { - LMatrix3 result; - extract_to_matrix(result); - return result * m; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::Multiply Operator -// Access: public -// Description: Quat * Matrix = matrix -//////////////////////////////////////////////////////////////////// -template -INLINE LMatrix4 LQuaternionBase:: -operator *(const LMatrix4 &m) { - LMatrix3 m_upper_3 = m.get_upper_3(); - LMatrix3 this_quat; - extract_to_matrix(this_quat); - - LMatrix4 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 -INLINE bool LQuaternionBase:: -almost_equal(const LQuaternionBase& 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 -INLINE bool LQuaternionBase:: -almost_equal(const LQuaternionBase& c) const { - return almost_equal(c, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::output -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -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 -INLINE NumType LQuaternionBase:: -get_r(void) const { - return _r; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::get_i -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LQuaternionBase:: -get_i(void) const { - return _i; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::get_j -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LQuaternionBase:: -get_j(void) const { - return _j; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::get_k -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LQuaternionBase:: -get_k(void) const { - return _k; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::set_r -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -set_r(NumType r) { - _r = r; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::set_i -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -set_i(NumType i) { - _i = i; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::set_j -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -set_j(NumType j) { - _j = j; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::set_k -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -set_k(NumType k) { - _k = k; -} - -//////////////////////////////////////////////////////////////////// -// Function: LQuaternionBase::normalize -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LQuaternionBase:: -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 -void LQuaternionBase:: -set(const LMatrix3 &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 -INLINE void LQuaternionBase:: -set(const LMatrix4 &m) { - set(m.get_upper_3()); -} - -//////////////////////////////////////////////////////////////////// -// Function: extract (LMatrix3) -// Access: public -// Description: Do-While Jones paper from cary. -//////////////////////////////////////////////////////////////////// -template -void LQuaternionBase:: -extract_to_matrix(LMatrix3 &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((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 -void LQuaternionBase:: -extract_to_matrix(LMatrix4 &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((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 -INLINE void LQuaternionBase:: -set_hpr(const LVecBase3 &hpr) { - LQuaternionBase quat_h, quat_p, quat_r; - - LVector3 v = LVector3::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::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::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 -INLINE LVecBase3 LQuaternionBase:: -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(heading, pitch, roll); -} - -//////////////////////////////////////////////////////////////////// -// Function: operator *(Matrix3, Quat) -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix3 operator *(const LMatrix3 &m, - const LQuaternionBase &q) { - LMatrix3 q_matrix; - q.extract_to_matrix(q_matrix); - - return m * q_matrix; -} - -//////////////////////////////////////////////////////////////////// -// Function: operator *(Matrix4, Quat) -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -LMatrix4 operator *(const LMatrix4 &m, - const LQuaternionBase &q) { - LMatrix4 q_matrix; - q.extract_to_matrix(q_matrix); - - // preserve the homogeneous coords and the translate - LVector4 m_row3 = m.get_row(3); - LVector4 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 -void LQuaternionBase:: -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 -INLINE LQuaternionBase -lcast_to(NumType2 *, const LQuaternionBase& c) { - return LQuaternionBase(c.get_r(), c.get_i(), c.get_j(), c.get_k()); -} diff --git a/panda/src/linmath/lquaternion.cxx b/panda/src/linmath/lquaternion.cxx deleted file mode 100644 index 00421a7136..0000000000 --- a/panda/src/linmath/lquaternion.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lquaternion.h b/panda/src/linmath/lquaternion.h deleted file mode 100644 index 86ecfc17b9..0000000000 --- a/panda/src/linmath/lquaternion.h +++ /dev/null @@ -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 - -//////////////////////////////////////////////////////////////////// -// Class : LQuaternionBase -// Description : This is the base quaternion class -//////////////////////////////////////////////////////////////////// -template -class LQuaternionBase { -protected: - INLINE LQuaternionBase - multiply(const LQuaternionBase&) const; - -PUBLISHED: - INLINE LQuaternionBase(void); - INLINE LQuaternionBase(const LQuaternionBase &); - INLINE LQuaternionBase(NumType, NumType, NumType, NumType); - virtual ~LQuaternionBase(void); - - static LQuaternionBase pure_imaginary(const LVector3 &); - - INLINE LQuaternionBase& operator =(const LQuaternionBase &); - INLINE bool operator ==(const LQuaternionBase &) const; - INLINE bool operator !=(const LQuaternionBase &) const; - - INLINE LQuaternionBase operator *(const LQuaternionBase &); - INLINE LQuaternionBase& operator *=(const LQuaternionBase &); - - INLINE LMatrix3 operator *(const LMatrix3 &); - INLINE LMatrix4 operator *(const LMatrix4 &); - - INLINE bool almost_equal(const LQuaternionBase &, NumType) const; - INLINE bool almost_equal(const LQuaternionBase &) const; - - INLINE void output(ostream&) const; - - INLINE void set(NumType, NumType, NumType, NumType); - - void set(const LMatrix3 &m); - INLINE void set(const LMatrix4 &m); - - void extract_to_matrix(LMatrix3 &m) const; - void extract_to_matrix(LMatrix4 &m) const; - - INLINE void set_hpr(const LVecBase3 &hpr); - LVecBase3 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 &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 -INLINE ostream& operator<<(ostream& os, const LQuaternionBase& q) { - q.output(os); - return os; -} - -// matrix times quat -template -INLINE LMatrix3 -operator * (const LMatrix3 &m, const LQuaternionBase &q); - -template -INLINE LMatrix4 -operator * (const LMatrix4 &m, const LQuaternionBase &q); - -// pacify interrogate. -#ifdef CPPPARSER -BEGIN_PUBLISH -INLINE LMatrix3 -operator * (const LMatrix3 &m, const LQuaternionBase &q); -INLINE LMatrix4 -operator * (const LMatrix4 &m, const LQuaternionBase &q); -INLINE LMatrix3 -operator * (const LMatrix3 &m, const LQuaternionBase &q); -INLINE LMatrix4 -operator * (const LMatrix4 &m, const LQuaternionBase &q); -END_PUBLISH -#endif - -// Cast to a different numeric type -template -INLINE LQuaternionBase lcast_to(NumType2*, const LQuaternionBase&); - -#include "lquaternion.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LQuaternionBase) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LQuaternionBase) - -#endif /* __LQUATERNION_H__ */ diff --git a/panda/src/linmath/lquaternion_src.I b/panda/src/linmath/lquaternion_src.cxx similarity index 52% rename from panda/src/linmath/lquaternion_src.I rename to panda/src/linmath/lquaternion_src.cxx index d2439b0891..bddcef84e6 100644 --- a/panda/src/linmath/lquaternion_src.I +++ b/panda/src/linmath/lquaternion_src.cxx @@ -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()); } } diff --git a/panda/src/linmath/lquaternion_src.h b/panda/src/linmath/lquaternion_src.h new file mode 100644 index 0000000000..bd9785f524 --- /dev/null +++ b/panda/src/linmath/lquaternion_src.h @@ -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" diff --git a/panda/src/linmath/lrotation.I b/panda/src/linmath/lrotation.I deleted file mode 100644 index b324feae17..0000000000 --- a/panda/src/linmath/lrotation.I +++ /dev/null @@ -1,142 +0,0 @@ -// Filename: lrotation.I -// Created by: frang, charles (23Jun00) -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle LRotation::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Default Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation:: -LRotation() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Copy Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation:: -LRotation(const LQuaternionBase& c) : - LQuaternionBase(c) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Constructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation:: -LRotation(NumType r, NumType i, NumType j, NumType k) : - LQuaternionBase(r, i, j, k) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Constructor -// Access: public -// Description: lmatrix3 -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation:: -LRotation(const LMatrix3 &m) { - set(m); -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Constructor -// Access: public -// Description: lmatrix4 -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation:: -LRotation(const LMatrix4 &m) { - set(m); -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Constructor -// Access: public -// Description: axis + angle (in degrees) -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation:: -LRotation(const LVector3 &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 -INLINE LRotation:: -LRotation(NumType h, NumType p, NumType r) { - set_hpr(LVecBase3(h, p, r)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::Destructor -// Access: public -// Description: -//////////////////////////////////////////////////////////////////// -template -LRotation:: -~LRotation() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::operator * -// Access: public -// Description: Rotation * Rotation = Rotation -//////////////////////////////////////////////////////////////////// -template -INLINE LRotation LRotation:: -operator*(const LRotation& 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 -INLINE LQuaternionBase LRotation:: -operator*(const LQuaternionBase& other) const { - return other; -} - -//////////////////////////////////////////////////////////////////// -// Function: LRotation::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LRotation:: -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); - } -} diff --git a/panda/src/linmath/lrotation.cxx b/panda/src/linmath/lrotation.cxx deleted file mode 100644 index 67b4c5f29a..0000000000 --- a/panda/src/linmath/lrotation.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lrotation.h b/panda/src/linmath/lrotation.h deleted file mode 100644 index 766ac0f8a8..0000000000 --- a/panda/src/linmath/lrotation.h +++ /dev/null @@ -1,51 +0,0 @@ -// Filename: lrotation.h -// Created by: frang, charles (07Jun00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef __LROTATION_H__ -#define __LROTATION_H__ - -#include -#include "lquaternion.h" -#include "cmath.h" - -#include - -//////////////////////////////////////////////////////////////////////// -// Class : LRotation -// Description : This is a unit quaternion representing a rotation. -//////////////////////////////////////////////////////////////////////// -template -class LRotation : public LQuaternionBase { -PUBLISHED: - INLINE LRotation(); - INLINE LRotation(const LQuaternionBase&); - INLINE LRotation(NumType, NumType, NumType, NumType); - INLINE LRotation(const LVector3 &, NumType); - INLINE LRotation(const LMatrix3 &); - INLINE LRotation(const LMatrix4 &); - INLINE LRotation(NumType, NumType, NumType); - virtual ~LRotation(); - - INLINE LRotation - operator*(const LRotation& other) const; - - INLINE LQuaternionBase - operator*(const LQuaternionBase& 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) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LRotation) - -#endif /* __LROTATION_H__ */ diff --git a/panda/src/linmath/lrotation_src.I b/panda/src/linmath/lrotation_src.cxx similarity index 53% rename from panda/src/linmath/lrotation_src.I rename to panda/src/linmath/lrotation_src.cxx index af033b6e6f..0c5cfedf2e 100644 --- a/panda/src/linmath/lrotation_src.I +++ b/panda/src/linmath/lrotation_src.cxx @@ -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()); } } diff --git a/panda/src/linmath/lrotation_src.h b/panda/src/linmath/lrotation_src.h new file mode 100644 index 0000000000..e7243fda0f --- /dev/null +++ b/panda/src/linmath/lrotation_src.h @@ -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" diff --git a/panda/src/linmath/luse.I b/panda/src/linmath/luse.I deleted file mode 100644 index 13fd2a7957..0000000000 --- a/panda/src/linmath/luse.I +++ /dev/null @@ -1,4 +0,0 @@ -// Filename: luse.I -// Created by: drose (13Jan99) -// -//////////////////////////////////////////////////////////////////// diff --git a/panda/src/linmath/luse.N b/panda/src/linmath/luse.N deleted file mode 100644 index 182014e3f1..0000000000 --- a/panda/src/linmath/luse.N +++ /dev/null @@ -1,85 +0,0 @@ -forcetype LVecBase2 -forcetype LVecBase3 -forcetype LVecBase4 - -forcetype LPoint2 -forcetype LPoint3 -forcetype LPoint4 -forcetype LVector2 -forcetype LVector3 -forcetype LVector4 - -forcetype LMatrix3 -forcetype LMatrix4 - -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 -forcetype LVecBase3 -forcetype LVecBase4 - -forcetype LPoint2 -forcetype LPoint3 -forcetype LPoint4 -forcetype LVector2 -forcetype LVector3 -forcetype LVector4 - -forcetype LMatrix3 -forcetype LMatrix4 - -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 -forcetype LQuaternionBase -forcetype LRotation -forcetype LRotation -forcetype LOrientation -forcetype LOrientation - -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 diff --git a/panda/src/linmath/luse.cxx b/panda/src/linmath/luse.cxx deleted file mode 100644 index c33fcdf794..0000000000 --- a/panda/src/linmath/luse.cxx +++ /dev/null @@ -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 - - diff --git a/panda/src/linmath/luse.h b/panda/src/linmath/luse.h deleted file mode 100644 index e626faa63a..0000000000 --- a/panda/src/linmath/luse.h +++ /dev/null @@ -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 -// -// This should be used to represent a specific point in space. It -// inherits most properties from LVecBase. -// -// LVector -// -// 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, Vertexd, Vertexf -// Normal, Normald, Normalf -// TexCoord, TexCoordd, TexCoordf -// Color, Colord, Colorf -// RGBColor, 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 - -#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 LVecBase2f; -typedef LVecBase3 LVecBase3f; -typedef LVecBase4 LVecBase4f; - -typedef LVector2 LVector2f; -typedef LVector3 LVector3f; -typedef LVector4 LVector4f; -typedef LPoint2 LPoint2f; -typedef LPoint3 LPoint3f; -typedef LPoint4 LPoint4f; - -typedef LPoint3f Vertexf; -typedef LVector3f Normalf; -typedef LPoint2f TexCoordf; -typedef LVecBase4f Colorf; -typedef LVecBase3f RGBColorf; - -typedef LVecBase2 LVecBase2d; -typedef LVecBase3 LVecBase3d; -typedef LVecBase4 LVecBase4d; - -typedef LVector2 LVector2d; -typedef LVector3 LVector3d; -typedef LVector4 LVector4d; -typedef LPoint2 LPoint2d; -typedef LPoint3 LPoint3d; -typedef LPoint4 LPoint4d; - -typedef LPoint3d Vertexd; -typedef LVector3d Normald; -typedef LPoint2d TexCoordd; -typedef LVecBase4d Colord; -typedef LVecBase3d RGBColord; - -typedef LQuaternionBase LQuaternionf; -typedef LRotation LRotationf; -typedef LOrientation LOrientationf; - -typedef LQuaternionBase LQuaterniond; -typedef LRotation LRotationd; -typedef LOrientation 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 - diff --git a/panda/src/linmath/lvec2_ops.h b/panda/src/linmath/lvec2_ops.h deleted file mode 100644 index 07ada43cd4..0000000000 --- a/panda/src/linmath/lvec2_ops.h +++ /dev/null @@ -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 -INLINE LVecBase2 -operator * (NumType2 scalar, const LVecBase2 &a); - -template -INLINE LPoint2 -operator * (NumType2 scalar, const LPoint2 &a); - -template -INLINE LVector2 -operator * (NumType2 scalar, const LVector2 &a); - - -// dot product -template -INLINE NumType -dot(const LVecBase2 &a, const LVecBase2 &b); - - -// Length of a vector. -template -INLINE NumType -length(const LVector2 &a); - - -// A normalized vector. -template -INLINE LVector2 -normalize(const LVector2 &v); - - - -#include "lvec2_ops.I" - -#endif diff --git a/panda/src/linmath/lvec2_ops.I b/panda/src/linmath/lvec2_ops_src.I similarity index 50% rename from panda/src/linmath/lvec2_ops.I rename to panda/src/linmath/lvec2_ops_src.I index d63fd182c0..a487d0d55d 100644 --- a/panda/src/linmath/lvec2_ops.I +++ b/panda/src/linmath/lvec2_ops_src.I @@ -1,19 +1,14 @@ -// Filename: lvec2_ops.I +// Filename: lvec2_ops_src.I // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// -#include - -#include "nearly_zero.h" - //////////////////////////////////////////////////////////////////// // Function: scalar * LVecBase2 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 -operator * (NumType2 scalar, const LVecBase2 &a) { +INLINE FLOATNAME(LVecBase2) +operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase2) &a) { return a * scalar; } @@ -21,9 +16,8 @@ operator * (NumType2 scalar, const LVecBase2 &a) { // Function: scalar * LPoint2 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LPoint2 -operator * (NumType2 scalar, const LPoint2 &a) { +INLINE FLOATNAME(LPoint2) +operator * (FLOATTYPE scalar, const FLOATNAME(LPoint2) &a) { return a * scalar; } @@ -31,9 +25,8 @@ operator * (NumType2 scalar, const LPoint2 &a) { // Function: scalar * LVector2 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVector2 -operator * (NumType2 scalar, const LVector2 &a) { +INLINE FLOATNAME(LVector2) +operator * (FLOATTYPE scalar, const FLOATNAME(LVector2) &a) { return a * scalar; } @@ -41,51 +34,27 @@ operator * (NumType2 scalar, const LVector2 &a) { // Function: dot product of LVecBase2 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE NumType -dot(const LVecBase2 &a, const LVecBase2 &b) { +INLINE FLOATTYPE +dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b) { return a.dot(b); } -//////////////////////////////////////////////////////////////////// -// Function: cross product of LVecBase2 -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 -cross(const LVecBase2 &a, const LVecBase2 &b) { - return a.cross(b); -} - -//////////////////////////////////////////////////////////////////// -// Function: cross product of LVector2 -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 -cross(const LVector2 &a, const LVector2 &b) { - return LVector2(a.cross(b)); -} - //////////////////////////////////////////////////////////////////// // Function: length of a vector // Description: //////////////////////////////////////////////////////////////////// -template -INLINE NumType -length(const LVector2 &a) { +INLINE FLOATTYPE +length(const FLOATNAME(LVector2) &a) { return a.length(); } - //////////////////////////////////////////////////////////////////// // Function: normalize // Description: Returns a normalized vector from the given vector. //////////////////////////////////////////////////////////////////// -template -INLINE LVector2 -normalize(const LVector2 &v) { - LVector2 v1 = v; +INLINE FLOATNAME(LVector2) +normalize(const FLOATNAME(LVector2) &v) { + FLOATNAME(LVector2) v1 = v; v1.normalize(); return v1; } diff --git a/panda/src/linmath/lvec2_ops_src.h b/panda/src/linmath/lvec2_ops_src.h new file mode 100644 index 0000000000..1ab59d8a77 --- /dev/null +++ b/panda/src/linmath/lvec2_ops_src.h @@ -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" + + + diff --git a/panda/src/linmath/lvec3_ops.h b/panda/src/linmath/lvec3_ops.h deleted file mode 100644 index 3330e380d7..0000000000 --- a/panda/src/linmath/lvec3_ops.h +++ /dev/null @@ -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 -INLINE LVecBase3 -operator * (NumType2 scalar, const LVecBase3 &a); - -template -INLINE LPoint3 -operator * (NumType2 scalar, const LPoint3 &a); - -template -INLINE LVector3 -operator * (NumType2 scalar, const LVector3 &a); - - -// dot product -template -INLINE NumType -dot(const LVecBase3 &a, const LVecBase3 &b); - - -// cross product -template -INLINE LVecBase3 -cross(const LVecBase3 &a, const LVecBase3 &b); - -template -INLINE LVector3 -cross(const LVector3 &a, const LVector3 &b); - - -// Length of a vector. -template -INLINE NumType -length(const LVector3 &a); - - -// A normalized vector. -template -INLINE LVector3 -normalize(const LVector3 &v); - - - -#include "lvec3_ops.I" - -#endif diff --git a/panda/src/linmath/lvec3_ops.I b/panda/src/linmath/lvec3_ops_src.I similarity index 65% rename from panda/src/linmath/lvec3_ops.I rename to panda/src/linmath/lvec3_ops_src.I index 1e0d1ef116..7afc6ca9df 100644 --- a/panda/src/linmath/lvec3_ops.I +++ b/panda/src/linmath/lvec3_ops_src.I @@ -1,19 +1,15 @@ -// Filename: lvec3_ops.I +// Filename: lvec3_ops_src.I // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// -#include - -#include "nearly_zero.h" //////////////////////////////////////////////////////////////////// // Function: scalar * LVecBase3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 -operator * (NumType2 scalar, const LVecBase3 &a) { +INLINE FLOATNAME(LVecBase3) +operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase3) &a) { return a * scalar; } @@ -21,9 +17,8 @@ operator * (NumType2 scalar, const LVecBase3 &a) { // Function: scalar * LPoint3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LPoint3 -operator * (NumType2 scalar, const LPoint3 &a) { +INLINE FLOATNAME(LPoint3) +operator * (FLOATTYPE scalar, const FLOATNAME(LPoint3) &a) { return a * scalar; } @@ -31,9 +26,8 @@ operator * (NumType2 scalar, const LPoint3 &a) { // Function: scalar * LVector3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVector3 -operator * (NumType2 scalar, const LVector3 &a) { +INLINE FLOATNAME(LVector3) +operator * (FLOATTYPE scalar, const FLOATNAME(LVector3) &a) { return a * scalar; } @@ -41,9 +35,9 @@ operator * (NumType2 scalar, const LVector3 &a) { // Function: dot product of LVecBase3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE NumType -dot(const LVecBase3 &a, const LVecBase3 &b) { + +INLINE FLOATTYPE +dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) { return a.dot(b); } @@ -51,9 +45,9 @@ dot(const LVecBase3 &a, const LVecBase3 &b) { // Function: cross product of LVecBase3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 -cross(const LVecBase3 &a, const LVecBase3 &b) { + +INLINE FLOATNAME(LVecBase3) +cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) { return a.cross(b); } @@ -61,10 +55,10 @@ cross(const LVecBase3 &a, const LVecBase3 &b) { // Function: cross product of LVector3 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVector3 -cross(const LVector3 &a, const LVector3 &b) { - return LVector3(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 &a, const LVector3 &b) { // Function: length of a vector // Description: //////////////////////////////////////////////////////////////////// -template -INLINE NumType -length(const LVector3 &a) { + +INLINE FLOATTYPE +length(const FLOATNAME(LVector3) &a) { return a.length(); } @@ -83,10 +77,10 @@ length(const LVector3 &a) { // Function: normalize // Description: Returns a normalized vector from the given vector. //////////////////////////////////////////////////////////////////// -template -INLINE LVector3 -normalize(const LVector3 &v) { - LVector3 v1 = v; + +INLINE FLOATNAME(LVector3) +normalize(const FLOATNAME(LVector3) &v) { + FLOATNAME(LVector3) v1 = v; v1.normalize(); return v1; } diff --git a/panda/src/linmath/lvec3_ops_src.h b/panda/src/linmath/lvec3_ops_src.h new file mode 100644 index 0000000000..4cbe427c02 --- /dev/null +++ b/panda/src/linmath/lvec3_ops_src.h @@ -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" diff --git a/panda/src/linmath/lvec4_ops.h b/panda/src/linmath/lvec4_ops.h deleted file mode 100644 index cd46d676c8..0000000000 --- a/panda/src/linmath/lvec4_ops.h +++ /dev/null @@ -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 -INLINE LVecBase4 -operator * (NumType2 scalar, const LVecBase4 &a); - -template -INLINE LPoint4 -operator * (NumType2 scalar, const LPoint4 &a); - -template -INLINE LVector4 -operator * (NumType2 scalar, const LVector4 &a); - - -// dot product -template -INLINE NumType -dot(const LVecBase4 &a, const LVecBase4 &b); - - -// Length of a vector. -template -INLINE NumType -length(const LVector4 &a); - - -// A normalized vector. -template -INLINE LVector4 -normalize(const LVector4 &v); - - - -#include "lvec4_ops.I" - -#endif diff --git a/panda/src/linmath/lvec4_ops.I b/panda/src/linmath/lvec4_ops_src.I similarity index 66% rename from panda/src/linmath/lvec4_ops.I rename to panda/src/linmath/lvec4_ops_src.I index 9ffc7ee191..91033ecba9 100644 --- a/panda/src/linmath/lvec4_ops.I +++ b/panda/src/linmath/lvec4_ops_src.I @@ -1,19 +1,14 @@ -// Filename: lvec4_ops.I +// Filename: lvec4_ops_src.I // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// -#include - -#include "nearly_zero.h" - //////////////////////////////////////////////////////////////////// // Function: scalar * LVecBase4 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 -operator * (NumType2 scalar, const LVecBase4 &a) { +INLINE FLOATNAME(LVecBase4) +operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase4) &a) { return a * scalar; } @@ -21,9 +16,8 @@ operator * (NumType2 scalar, const LVecBase4 &a) { // Function: scalar * LPoint4 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LPoint4 -operator * (NumType2 scalar, const LPoint4 &a) { +INLINE FLOATNAME(LPoint4) +operator * (FLOATTYPE scalar, const FLOATNAME(LPoint4) &a) { return a * scalar; } @@ -31,9 +25,8 @@ operator * (NumType2 scalar, const LPoint4 &a) { // Function: scalar * LVector4 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE LVector4 -operator * (NumType2 scalar, const LVector4 &a) { +INLINE FLOATNAME(LVector4) +operator * (FLOATTYPE scalar, const FLOATNAME(LVector4) &a) { return a * scalar; } @@ -41,9 +34,9 @@ operator * (NumType2 scalar, const LVector4 &a) { // Function: dot product of LVecBase4 // Description: //////////////////////////////////////////////////////////////////// -template -INLINE NumType -dot(const LVecBase4 &a, const LVecBase4 &b) { + +INLINE FLOATTYPE +dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b) { return a.dot(b); } @@ -51,9 +44,9 @@ dot(const LVecBase4 &a, const LVecBase4 &b) { // Function: length of a vector // Description: //////////////////////////////////////////////////////////////////// -template -INLINE NumType -length(const LVector4 &a) { + +INLINE FLOATTYPE +length(const FLOATNAME(LVector4) &a) { return a.length(); } @@ -62,10 +55,10 @@ length(const LVector4 &a) { // Function: normalize // Description: Returns a normalized vector from the given vector. //////////////////////////////////////////////////////////////////// -template -INLINE LVector4 -normalize(const LVector4 &v) { - LVector4 v1 = v; + +INLINE FLOATNAME(LVector4) +normalize(const FLOATNAME(LVector4) &v) { + FLOATNAME(LVector4) v1 = v; v1.normalize(); return v1; } diff --git a/panda/src/linmath/lvec4_ops_src.h b/panda/src/linmath/lvec4_ops_src.h new file mode 100644 index 0000000000..e4a1fe918d --- /dev/null +++ b/panda/src/linmath/lvec4_ops_src.h @@ -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" diff --git a/panda/src/linmath/lvecBase2.I b/panda/src/linmath/lvecBase2.I deleted file mode 100644 index 52717507fd..0000000000 --- a/panda/src/linmath/lvecBase2.I +++ /dev/null @@ -1,604 +0,0 @@ -// Filename: lvecBase2.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "nearly_zero.h" - -#include -#include -#include - -template -TypeHandle LVecBase2::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2:: -LVecBase2() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2:: -LVecBase2(const LVecBase2 ©) { - (*this) = copy; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 &LVecBase2:: -operator = (const LVecBase2 ©) { - set(copy[0], copy[1]); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Fill Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 &LVecBase2:: -operator = (NumType fill_value) { - fill(fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2:: -LVecBase2(NumType fill_value) { - fill(fill_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2:: -LVecBase2(NumType x, NumType y) { - set(x, y); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::zero Named Constructor -// Access: Public -// Description: Returns a zero-length vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -zero() { - return LVecBase2(0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -unit_x() { - return LVecBase2(1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -unit_y() { - return LVecBase2(0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2:: -~LVecBase2() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Indexing Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase2:: -operator [](int i) const { - nassertr(i >= 0 && i < 2, 0); - return _data[i]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Indexing Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType &LVecBase2:: -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 -INLINE bool LVecBase2:: -is_nan() const { - return cnan(_data[0]) || cnan(_data[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::get_cell -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase2:: -get_cell(int i) const { - nassertr(i >= 0 && i < 2, 0); - return _data[i]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::get_x -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase2:: -get_x() const { - return _data[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::get_y -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase2:: -get_y() const { - return _data[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::set_cell -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -set_cell(int i, NumType value) { - nassertv(i >= 0 && i < 2); - _data[i] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::set_x -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -set_x(NumType value) { - _data[0] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::set_y -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -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 -INLINE const NumType *LVecBase2:: -get_data() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::get_num_components -// Access: Public -// Description: Returns the number of elements in the vector, two. -//////////////////////////////////////////////////////////////////// -template -INLINE int LVecBase2:: -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 -INLINE LVecBase2::iterator LVecBase2:: -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 -INLINE LVecBase2::iterator LVecBase2:: -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 -INLINE LVecBase2::const_iterator LVecBase2:: -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 -INLINE LVecBase2::const_iterator LVecBase2:: -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 -INLINE void LVecBase2:: -fill(NumType fill_value) { - _data[0] = fill_value; - _data[1] = fill_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::set -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -set(NumType x, NumType y) { - _data[0] = x; - _data[1] = y; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::dot -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase2:: -dot(const LVecBase2 &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 -INLINE bool LVecBase2:: -operator < (const LVecBase2 &other) const { - return (compare_to(other) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::operator == -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVecBase2:: -operator == (const LVecBase2 &other) const { - return (_data[0] == other[0] && - _data[1] == other[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::operator != -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVecBase2:: -operator != (const LVecBase2 &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 -INLINE int LVecBase2:: -compare_to(const LVecBase2 &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 -INLINE int LVecBase2:: -compare_to(const LVecBase2 &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 -INLINE LVecBase2 LVecBase2:: -operator - () const { - return LVecBase2(-_data[0], -_data[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::vector + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -operator + (const LVecBase2 &other) const { - return LVecBase2(_data[0] + other[0], - _data[1] + other[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::vector - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -operator - (const LVecBase2 &other) const { - return LVecBase2(_data[0] - other[0], - _data[1] - other[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::vector * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -operator * (NumType scalar) const { - return LVecBase2(_data[0] * scalar, - _data[1] * scalar); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::vector / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVecBase2:: -operator / (NumType scalar) const { - return LVecBase2(_data[0] / scalar, - _data[1] / scalar); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::operator += -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -operator += (const LVecBase2 &other) { - _data[0] += other[0]; - _data[1] += other[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::operator -= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -operator -= (const LVecBase2 &other) { - _data[0] -= other[0]; - _data[1] -= other[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::operator *= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -operator *= (NumType scalar) { - _data[0] *= scalar; - _data[1] *= scalar; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::operator /= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -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 -INLINE bool LVecBase2:: -almost_equal(const LVecBase2 &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 -INLINE bool LVecBase2:: -almost_equal(const LVecBase2 &other) const { - return almost_equal(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase2:: -output(ostream &out) const { - out << MAYBE_ZERO(_data[0]) << " " - << MAYBE_ZERO(_data[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LVecBase2:: -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 -void LVecBase2:: -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 -void LVecBase2:: -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 -INLINE LVecBase2 -lcast_to(NumType2 *, const LVecBase2 &source) { - return LVecBase2(source[0], source[1]); -} diff --git a/panda/src/linmath/lvecBase2.cxx b/panda/src/linmath/lvecBase2.cxx deleted file mode 100644 index cc89c56c83..0000000000 --- a/panda/src/linmath/lvecBase2.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lvecBase2.h b/panda/src/linmath/lvecBase2.h deleted file mode 100644 index 77c9c8e376..0000000000 --- a/panda/src/linmath/lvecBase2.h +++ /dev/null @@ -1,135 +0,0 @@ -// Filename: lvecBase2.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LVECBASE2_H -#define LVECBASE2_H - -#include - -#include "cmath.h" - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : LVecBase2 -// Description : This is the base class for all two-component -// vectors and points. -//////////////////////////////////////////////////////////////////// -template -class LVecBase2 { -PUBLISHED: - typedef const NumType *iterator; - typedef const NumType *const_iterator; - - INLINE LVecBase2(); - INLINE LVecBase2(const LVecBase2 ©); - INLINE LVecBase2 &operator = (const LVecBase2 ©); - INLINE LVecBase2 &operator = (NumType fill_value); - INLINE LVecBase2(NumType fill_value); - INLINE LVecBase2(NumType x, NumType y); - - INLINE static LVecBase2 zero(); - INLINE static LVecBase2 unit_x(); - INLINE static LVecBase2 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 &other) const; - - INLINE bool operator < (const LVecBase2 &other) const; - INLINE bool operator == (const LVecBase2 &other) const; - INLINE bool operator != (const LVecBase2 &other) const; - - INLINE int compare_to(const LVecBase2 &other) const; - INLINE int compare_to(const LVecBase2 &other, - NumType threshold) const; - - INLINE LVecBase2 - operator - () const; - - INLINE LVecBase2 - operator + (const LVecBase2 &other) const; - INLINE LVecBase2 - operator - (const LVecBase2 &other) const; - - INLINE LVecBase2 operator * (NumType scalar) const; - INLINE LVecBase2 operator / (NumType scalar) const; - - INLINE void operator += (const LVecBase2 &other); - INLINE void operator -= (const LVecBase2 &other); - - INLINE void operator *= (NumType scalar); - INLINE void operator /= (NumType scalar); - - INLINE bool almost_equal(const LVecBase2 &other, - NumType threshold) const; - INLINE bool almost_equal(const LVecBase2 &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 -INLINE ostream &operator << (ostream &out, const LVecBase2 &vec) { - vec.output(out); - return out; -} - - -// Cast to a different numeric type -template -INLINE LVecBase2 -lcast_to(NumType2 *type, const LVecBase2 &source); - -#include "lvecBase2.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase2) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase2) - -#endif diff --git a/panda/src/linmath/lvecBase2_src.I b/panda/src/linmath/lvecBase2_src.cxx similarity index 60% rename from panda/src/linmath/lvecBase2_src.I rename to panda/src/linmath/lvecBase2_src.cxx index 4d4e04ed5f..2f17f901f5 100644 --- a/panda/src/linmath/lvecBase2_src.I +++ b/panda/src/linmath/lvecBase2_src.cxx @@ -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); } } diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h new file mode 100644 index 0000000000..42e5b56184 --- /dev/null +++ b/panda/src/linmath/lvecBase2_src.h @@ -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) ©); + INLINE FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) ©); + 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" diff --git a/panda/src/linmath/lvecBase3.I b/panda/src/linmath/lvecBase3.I deleted file mode 100644 index c69fd85da8..0000000000 --- a/panda/src/linmath/lvecBase3.I +++ /dev/null @@ -1,680 +0,0 @@ -// Filename: lvecBase3.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "nearly_zero.h" - -#include -#include -#include - -template -TypeHandle LVecBase3::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3:: -LVecBase3() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3:: -LVecBase3(const LVecBase3 ©) { - (*this) = copy; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 &LVecBase3:: -operator = (const LVecBase3 ©) { - set(copy[0], copy[1], copy[2]); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Fill Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 &LVecBase3:: -operator = (NumType fill_value) { - fill(fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3:: -LVecBase3(NumType fill_value) { - fill(fill_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3:: -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 -INLINE LVecBase3 LVecBase3:: -zero() { - return LVecBase3(0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -unit_x() { - return LVecBase3(1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -unit_y() { - return LVecBase3(0.0, 1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::unit_z Named Constructor -// Access: Public -// Description: Returns a unit Z vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -unit_z() { - return LVecBase3(0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3:: -~LVecBase3() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Indexing Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase3:: -operator [](int i) const { - nassertr(i >= 0 && i < 3, 0); - return _data[i]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Indexing Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType &LVecBase3:: -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 -INLINE bool LVecBase3:: -is_nan() const { - return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::get_cell -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase3:: -get_cell(int i) const { - nassertr(i >= 0 && i < 3, 0); - return _data[i]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::get_x -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase3:: -get_x() const { - return _data[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::get_y -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase3:: -get_y() const { - return _data[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::get_z -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase3:: -get_z() const { - return _data[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::set_cell -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -set_cell(int i, NumType value) { - nassertv(i >= 0 && i < 3); - _data[i] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::set_x -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -set_x(NumType value) { - _data[0] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::set_y -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -set_y(NumType value) { - _data[1] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::set_z -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -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 -INLINE const NumType *LVecBase3:: -get_data() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::get_num_components -// Access: Public -// Description: Returns the number of elements in the vector, three. -//////////////////////////////////////////////////////////////////// -template -INLINE int LVecBase3:: -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 -INLINE LVecBase3::iterator LVecBase3:: -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 -INLINE LVecBase3::iterator LVecBase3:: -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 -INLINE LVecBase3::const_iterator LVecBase3:: -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 -INLINE LVecBase3::const_iterator LVecBase3:: -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 -INLINE void LVecBase3:: -fill(NumType fill_value) { - _data[0] = fill_value; - _data[1] = fill_value; - _data[2] = fill_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::set -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -set(NumType x, NumType y, NumType z) { - _data[0] = x; - _data[1] = y; - _data[2] = z; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::dot -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase3:: -dot(const LVecBase3 &other) const { - return _data[0] * other[0] + _data[1] * other[1] + _data[2] * other[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::cross -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -cross(const LVecBase3 &other) const { - return LVecBase3(_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 -INLINE bool LVecBase3:: -operator < (const LVecBase3 &other) const { - return (compare_to(other) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::operator == -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVecBase3:: -operator == (const LVecBase3 &other) const { - return (_data[0] == other[0] && - _data[1] == other[1] && - _data[2] == other[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::operator != -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVecBase3:: -operator != (const LVecBase3 &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 -INLINE int LVecBase3:: -compare_to(const LVecBase3 &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 -INLINE int LVecBase3:: -compare_to(const LVecBase3 &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 -INLINE LVecBase3 LVecBase3:: -operator - () const { - return LVecBase3(-_data[0], -_data[1], -_data[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::vector + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -operator + (const LVecBase3 &other) const { - return LVecBase3(_data[0] + other[0], - _data[1] + other[1], - _data[2] + other[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::vector - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -operator - (const LVecBase3 &other) const { - return LVecBase3(_data[0] - other[0], - _data[1] - other[1], - _data[2] - other[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::vector * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -operator * (NumType scalar) const { - return LVecBase3(_data[0] * scalar, - _data[1] * scalar, - _data[2] * scalar); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::vector / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVecBase3:: -operator / (NumType scalar) const { - return LVecBase3(_data[0] / scalar, - _data[1] / scalar, - _data[2] / scalar); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::operator += -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -operator += (const LVecBase3 &other) { - _data[0] += other[0]; - _data[1] += other[1]; - _data[2] += other[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::operator -= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -operator -= (const LVecBase3 &other) { - _data[0] -= other[0]; - _data[1] -= other[1]; - _data[2] -= other[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::operator *= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -operator *= (NumType scalar) { - _data[0] *= scalar; - _data[1] *= scalar; - _data[2] *= scalar; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::operator /= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -operator /= (NumType scalar) { - _data[0] /= scalar; - _data[1] /= scalar; - _data[2] /= scalar; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::cross product (with assigment) -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -cross_into(const LVecBase3 &other) { - (*this) = cross(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::almost_equal -// Access: Public -// Description: Returns true if two vectors are memberwise equal -// within a specified tolerance. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVecBase3:: -almost_equal(const LVecBase3 &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 -INLINE bool LVecBase3:: -almost_equal(const LVecBase3 &other) const { - return almost_equal(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase3:: -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 -void LVecBase3:: -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 -void LVecBase3:: -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 -void LVecBase3:: -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 -INLINE LVecBase3 -lcast_to(NumType2 *, const LVecBase3 &source) { - return LVecBase3(source[0], source[1], source[2]); -} diff --git a/panda/src/linmath/lvecBase3.cxx b/panda/src/linmath/lvecBase3.cxx deleted file mode 100644 index 271c0727b5..0000000000 --- a/panda/src/linmath/lvecBase3.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lvecBase3.h b/panda/src/linmath/lvecBase3.h deleted file mode 100644 index 15b75c083f..0000000000 --- a/panda/src/linmath/lvecBase3.h +++ /dev/null @@ -1,141 +0,0 @@ -// Filename: lvecBase3.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LVECBASE3_H -#define LVECBASE3_H - -#include - -#include "cmath.h" - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : LVecBase3 -// Description : This is the base class for all three-component -// vectors and points. -//////////////////////////////////////////////////////////////////// -template -class LVecBase3 { -PUBLISHED: - typedef const NumType *iterator; - typedef const NumType *const_iterator; - - INLINE LVecBase3(); - INLINE LVecBase3(const LVecBase3 ©); - INLINE LVecBase3 &operator = (const LVecBase3 ©); - INLINE LVecBase3 &operator = (NumType fill_value); - INLINE LVecBase3(NumType fill_value); - INLINE LVecBase3(NumType x, NumType y, NumType z); - - INLINE static LVecBase3 zero(); - INLINE static LVecBase3 unit_x(); - INLINE static LVecBase3 unit_y(); - INLINE static LVecBase3 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 &other) const; - INLINE LVecBase3 cross(const LVecBase3 &other) const; - - INLINE bool operator < (const LVecBase3 &other) const; - INLINE bool operator == (const LVecBase3 &other) const; - INLINE bool operator != (const LVecBase3 &other) const; - - INLINE int compare_to(const LVecBase3 &other) const; - INLINE int compare_to(const LVecBase3 &other, - NumType threshold) const; - - INLINE LVecBase3 - operator - () const; - - INLINE LVecBase3 - operator + (const LVecBase3 &other) const; - INLINE LVecBase3 - operator - (const LVecBase3 &other) const; - - INLINE LVecBase3 operator * (NumType scalar) const; - INLINE LVecBase3 operator / (NumType scalar) const; - - INLINE void operator += (const LVecBase3 &other); - INLINE void operator -= (const LVecBase3 &other); - - INLINE void operator *= (NumType scalar); - INLINE void operator /= (NumType scalar); - - INLINE void cross_into(const LVecBase3 &other); - - INLINE bool almost_equal(const LVecBase3 &other, - NumType threshold) const; - INLINE bool almost_equal(const LVecBase3 &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 -INLINE ostream &operator << (ostream &out, const LVecBase3 &vec) { - vec.output(out); - return out; -} - - -// Cast to a different numeric type -template -INLINE LVecBase3 -lcast_to(NumType2 *type, const LVecBase3 &source); - -#include "lvecBase3.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase3) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase3) - -#endif diff --git a/panda/src/linmath/lvecBase3_src.I b/panda/src/linmath/lvecBase3_src.cxx similarity index 53% rename from panda/src/linmath/lvecBase3_src.I rename to panda/src/linmath/lvecBase3_src.cxx index af00fb3576..601425f837 100644 --- a/panda/src/linmath/lvecBase3_src.I +++ b/panda/src/linmath/lvecBase3_src.cxx @@ -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); } } diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h new file mode 100644 index 0000000000..67dfc31866 --- /dev/null +++ b/panda/src/linmath/lvecBase3_src.h @@ -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) ©); + INLINE FLOATNAME(LVecBase3) &operator = (const FLOATNAME(LVecBase3) ©); + 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" diff --git a/panda/src/linmath/lvecBase4.I b/panda/src/linmath/lvecBase4.I deleted file mode 100644 index e2e96e2475..0000000000 --- a/panda/src/linmath/lvecBase4.I +++ /dev/null @@ -1,710 +0,0 @@ -// Filename: lvecBase4.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "nearly_zero.h" - -#include -#include -#include - -template -TypeHandle LVecBase4::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4:: -LVecBase4() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4:: -LVecBase4(const LVecBase4 ©) { - (*this) = copy; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 &LVecBase4:: -operator = (const LVecBase4 ©) { - set(copy[0], copy[1], copy[2], copy[3]); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Fill Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 &LVecBase4:: -operator = (NumType fill_value) { - fill(fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4:: -LVecBase4(NumType fill_value) { - fill(fill_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4:: -LVecBase4(NumType x, NumType y, NumType z, NumType w) { - set(x, y, z, w); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4:: -~LVecBase4() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::zero Named Constructor -// Access: Public -// Description: Returns a zero-length vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -zero() { - return LVecBase4(0.0, 0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -unit_x() { - return LVecBase4(1.0, 0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -unit_y() { - return LVecBase4(0.0, 1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::unit_z Named Constructor -// Access: Public -// Description: Returns a unit Z vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -unit_z() { - return LVecBase4(0.0, 0.0, 1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::unit_w Named Constructor -// Access: Public -// Description: Returns a unit W vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -unit_w() { - return LVecBase4(0.0, 0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Indexing Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase4:: -operator [](int i) const { - nassertr(i >= 0 && i < 4, 0); - return _data[i]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Indexing Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType &LVecBase4:: -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 -INLINE bool LVecBase4:: -is_nan() const { - return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || cnan(_data[3]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::get_cell -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase4:: -get_cell(int i) const { - nassertr(i >= 0 && i < 4, 0); - return _data[i]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::get_x -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase4:: -get_x() const { - return _data[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::get_y -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase4:: -get_y() const { - return _data[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::get_z -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase4:: -get_z() const { - return _data[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::get_w -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVecBase4:: -get_w() const { - return _data[3]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::set_cell -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -set_cell(int i, NumType value) { - nassertv(i >= 0 && i < 4); - _data[i] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::set_x -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -set_x(NumType value) { - _data[0] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::set_y -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -set_y(NumType value) { - _data[1] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::set_z -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -set_z(NumType value) { - _data[2] = value; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::set_w -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -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 -INLINE const NumType *LVecBase4:: -get_data() const { - return _data; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::get_num_components -// Access: Public -// Description: Returns the number of elements in the vector, four. -//////////////////////////////////////////////////////////////////// -template -INLINE int LVecBase4:: -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 -INLINE LVecBase4::iterator LVecBase4:: -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 -INLINE LVecBase4::iterator LVecBase4:: -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 -INLINE LVecBase4::const_iterator LVecBase4:: -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 -INLINE LVecBase4::const_iterator LVecBase4:: -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 -INLINE void LVecBase4:: -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 -INLINE void LVecBase4:: -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 -INLINE NumType LVecBase4:: -dot(const LVecBase4 &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 -INLINE bool LVecBase4:: -operator < (const LVecBase4 &other) const { - return (compare_to(other) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::operator == -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVecBase4:: -operator == (const LVecBase4 &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 -INLINE bool LVecBase4:: -operator != (const LVecBase4 &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 -INLINE int LVecBase4:: -compare_to(const LVecBase4 &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 -INLINE int LVecBase4:: -compare_to(const LVecBase4 &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 -INLINE LVecBase4 LVecBase4:: -operator - () const { - return LVecBase4(-_data[0], -_data[1], -_data[2], -_data[3]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::vector + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -operator + (const LVecBase4 &other) const { - return LVecBase4(_data[0] + other[0], - _data[1] + other[1], - _data[2] + other[2], - _data[3] + other[3]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::vector - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -operator - (const LVecBase4 &other) const { - return LVecBase4(_data[0] - other[0], - _data[1] - other[1], - _data[2] - other[2], - _data[3] - other[3]); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::vector * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -operator * (NumType scalar) const { - return LVecBase4(_data[0] * scalar, - _data[1] * scalar, - _data[2] * scalar, - _data[3] * scalar); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::vector / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVecBase4:: -operator / (NumType scalar) const { - return LVecBase4(_data[0] / scalar, - _data[1] / scalar, - _data[2] / scalar, - _data[3] / scalar); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::operator += -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -operator += (const LVecBase4 &other) { - _data[0] += other[0]; - _data[1] += other[1]; - _data[2] += other[2]; - _data[3] += other[3]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::operator -= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -operator -= (const LVecBase4 &other) { - _data[0] -= other[0]; - _data[1] -= other[1]; - _data[2] -= other[2]; - _data[3] -= other[3]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::operator *= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -operator *= (NumType scalar) { - _data[0] *= scalar; - _data[1] *= scalar; - _data[2] *= scalar; - _data[3] *= scalar; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::operator /= -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -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 -INLINE bool LVecBase4:: -almost_equal(const LVecBase4 &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 -INLINE bool LVecBase4:: -almost_equal(const LVecBase4 &other) const { - return almost_equal(other, NEARLY_ZERO(NumType)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void LVecBase4:: -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 -void LVecBase4:: -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 -void LVecBase4:: -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 -void LVecBase4:: -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 -INLINE LVecBase4 -lcast_to(NumType2 *, const LVecBase4 &source) { - return LVecBase4(source[0], source[1], source[2], source[3]); -} diff --git a/panda/src/linmath/lvecBase4.cxx b/panda/src/linmath/lvecBase4.cxx deleted file mode 100644 index b8ffd2affb..0000000000 --- a/panda/src/linmath/lvecBase4.cxx +++ /dev/null @@ -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" - diff --git a/panda/src/linmath/lvecBase4.h b/panda/src/linmath/lvecBase4.h deleted file mode 100644 index 8332171620..0000000000 --- a/panda/src/linmath/lvecBase4.h +++ /dev/null @@ -1,141 +0,0 @@ -// Filename: lvecBase4.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LVECBASE4_H -#define LVECBASE4_H - -#include - -#include "cmath.h" - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : LVecBase4 -// Description : This is the base class for all three-component -// vectors and points. -//////////////////////////////////////////////////////////////////// -template -class LVecBase4 { -PUBLISHED: - typedef const NumType *iterator; - typedef const NumType *const_iterator; - - INLINE LVecBase4(); - INLINE LVecBase4(const LVecBase4 ©); - INLINE LVecBase4 &operator = (const LVecBase4 ©); - INLINE LVecBase4 &operator = (NumType fill_value); - INLINE LVecBase4(NumType fill_value); - INLINE LVecBase4(NumType x, NumType y, NumType z, NumType w); - - INLINE static LVecBase4 zero(); - INLINE static LVecBase4 unit_x(); - INLINE static LVecBase4 unit_y(); - INLINE static LVecBase4 unit_z(); - INLINE static LVecBase4 unit_w(); - - INLINE ~LVecBase4(); - - INLINE NumType operator [](int i) const; - INLINE NumType &operator [](int i); - - INLINE bool is_nan() const; - - INLINE NumType get_cell(int i) const; - INLINE NumType get_x() const; - INLINE NumType get_y() const; - INLINE NumType get_z() const; - INLINE NumType get_w() const; - INLINE void set_cell(int i, NumType value); - INLINE void set_x(NumType value); - INLINE void set_y(NumType value); - INLINE void set_z(NumType value); - INLINE void set_w(NumType value); - - INLINE const NumType *get_data() const; - INLINE int get_num_components() const; - -public: - INLINE iterator begin(); - INLINE iterator end(); - - INLINE const_iterator begin() const; - INLINE const_iterator end() const; - -PUBLISHED: - INLINE void fill(NumType fill_value); - INLINE void set(NumType x, NumType y, NumType z, NumType w); - - INLINE NumType dot(const LVecBase4 &other) const; - - INLINE bool operator < (const LVecBase4 &other) const; - INLINE bool operator == (const LVecBase4 &other) const; - INLINE bool operator != (const LVecBase4 &other) const; - - INLINE int compare_to(const LVecBase4 &other) const; - INLINE int compare_to(const LVecBase4 &other, - NumType threshold) const; - - INLINE LVecBase4 - operator - () const; - - INLINE LVecBase4 - operator + (const LVecBase4 &other) const; - INLINE LVecBase4 - operator - (const LVecBase4 &other) const; - - INLINE LVecBase4 operator * (NumType scalar) const; - INLINE LVecBase4 operator / (NumType scalar) const; - - INLINE void operator += (const LVecBase4 &other); - INLINE void operator -= (const LVecBase4 &other); - - INLINE void operator *= (NumType scalar); - INLINE void operator /= (NumType scalar); - - INLINE bool almost_equal(const LVecBase4 &other, - NumType threshold) const; - INLINE bool almost_equal(const LVecBase4 &other) const; - - INLINE void output(ostream &out) const; - -private: - NumType _data[4]; - -public: - INLINE void write_datagram(Datagram &destination) const; - INLINE void read_datagram(DatagramIterator &source); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type(); - -private: - static TypeHandle _type_handle; -}; - -template -INLINE ostream &operator << (ostream &out, const LVecBase4 &vec) { - vec.output(out); - return out; -} - - -// Cast to a different numeric type -template -INLINE LVecBase4 -lcast_to(NumType2 *type, const LVecBase4 &source); - -#include "lvecBase4.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase4) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVecBase4) - -#endif diff --git a/panda/src/linmath/lvecBase4_src.I b/panda/src/linmath/lvecBase4_src.I deleted file mode 100644 index 5689c4da59..0000000000 --- a/panda/src/linmath/lvecBase4_src.I +++ /dev/null @@ -1,23 +0,0 @@ -// Filename: lvecBase4.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -TypeHandle FLOATNAME(LVecBase4)::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// - -void FLOATNAME(LVecBase4):: -init_type() { - if (_type_handle == TypeHandle::none()) { - // Format a string to describe the type. - do_init_type(FLOATTYPE1); - string name = - "LVecBase4<" + get_type_handle(FLOATTYPE1).get_name() + ">"; - register_type(_type_handle, name); - } -} diff --git a/panda/src/linmath/lvecBase4_src.cxx b/panda/src/linmath/lvecBase4_src.cxx new file mode 100644 index 0000000000..b5818617b3 --- /dev/null +++ b/panda/src/linmath/lvecBase4_src.cxx @@ -0,0 +1,33 @@ +// Filename: lvecBase4_src.h +// Created by: drose (08Mar00) +// +//////////////////////////////////////////////////////////////////// + +TypeHandle FLOATNAME(LVecBase4)::_type_handle; + +const FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::_zero = + FLOATNAME(LVecBase4)(0.0, 0.0, 0.0, 0.0); +const FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::_unit_x = + FLOATNAME(LVecBase4)(1.0, 0.0, 0.0, 0.0); +const FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::_unit_y = + FLOATNAME(LVecBase4)(0.0, 1.0, 0.0, 0.0); +const FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::_unit_z = + FLOATNAME(LVecBase4)(0.0, 0.0, 1.0, 0.0); +const FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::_unit_w = + FLOATNAME(LVecBase4)(0.0, 0.0, 0.0, 1.0); + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase4::init_type +// Access: Public, Static +// Description: +//////////////////////////////////////////////////////////////////// + +void FLOATNAME(LVecBase4):: +init_type() { + if (_type_handle == TypeHandle::none()) { + // Format a string to describe the type. + string name = "LVecBase4"; + name += FLOATTOKEN; + register_type(_type_handle, name); + } +} diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h new file mode 100644 index 0000000000..a60a736d18 --- /dev/null +++ b/panda/src/linmath/lvecBase4_src.h @@ -0,0 +1,122 @@ +// Filename: lvecBase4_src.h +// Created by: drose (08Mar00) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Class : LVecBase4 +// Description : This is the base class for all three-component +// vectors and points. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA FLOATNAME(LVecBase4) { +PUBLISHED: + typedef const FLOATTYPE *iterator; + typedef const FLOATTYPE *const_iterator; + + INLINE FLOATNAME(LVecBase4)(); + INLINE FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©); + INLINE FLOATNAME(LVecBase4) &operator = (const FLOATNAME(LVecBase4) ©); + INLINE FLOATNAME(LVecBase4) &operator = (FLOATTYPE fill_value); + INLINE FLOATNAME(LVecBase4)(FLOATTYPE fill_value); + INLINE FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + + INLINE static const FLOATNAME(LVecBase4) &zero(); + INLINE static const FLOATNAME(LVecBase4) &unit_x(); + INLINE static const FLOATNAME(LVecBase4) &unit_y(); + INLINE static const FLOATNAME(LVecBase4) &unit_z(); + INLINE static const FLOATNAME(LVecBase4) &unit_w(); + + INLINE ~FLOATNAME(LVecBase4)(); + + 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 FLOATTYPE get_w() 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 void set_w(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, FLOATTYPE w); + + INLINE FLOATTYPE dot(const FLOATNAME(LVecBase4) &other) const; + + INLINE bool operator < (const FLOATNAME(LVecBase4) &other) const; + INLINE bool operator == (const FLOATNAME(LVecBase4) &other) const; + INLINE bool operator != (const FLOATNAME(LVecBase4) &other) const; + + INLINE int compare_to(const FLOATNAME(LVecBase4) &other) const; + INLINE int compare_to(const FLOATNAME(LVecBase4) &other, + FLOATTYPE threshold) const; + + INLINE FLOATNAME(LVecBase4) operator - () const; + + INLINE FLOATNAME(LVecBase4) + operator + (const FLOATNAME(LVecBase4) &other) const; + INLINE FLOATNAME(LVecBase4) + operator - (const FLOATNAME(LVecBase4) &other) const; + + INLINE FLOATNAME(LVecBase4) operator * (FLOATTYPE scalar) const; + INLINE FLOATNAME(LVecBase4) operator / (FLOATTYPE scalar) const; + + INLINE void operator += (const FLOATNAME(LVecBase4) &other); + INLINE void operator -= (const FLOATNAME(LVecBase4) &other); + + INLINE void operator *= (FLOATTYPE scalar); + INLINE void operator /= (FLOATTYPE scalar); + + INLINE bool almost_equal(const FLOATNAME(LVecBase4) &other, + FLOATTYPE threshold) const; + INLINE bool almost_equal(const FLOATNAME(LVecBase4) &other) const; + + INLINE void output(ostream &out) const; + +protected: + FLOATTYPE _data[4]; + +private: + static const FLOATNAME(LVecBase4) _zero; + static const FLOATNAME(LVecBase4) _unit_x; + static const FLOATNAME(LVecBase4) _unit_y; + static const FLOATNAME(LVecBase4) _unit_z; + static const FLOATNAME(LVecBase4) _unit_w; + +public: + INLINE void write_datagram(Datagram &destination) const; + INLINE void read_datagram(DatagramIterator &source); + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type(); + +private: + static TypeHandle _type_handle; +}; + +INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase4) &vec) { + vec.output(out); + return out; +} + +#include "lvecBase4_src.I" diff --git a/panda/src/linmath/lvector2.I b/panda/src/linmath/lvector2.I deleted file mode 100644 index 78be371947..0000000000 --- a/panda/src/linmath/lvector2.I +++ /dev/null @@ -1,262 +0,0 @@ -// Filename: lvector2.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "cmath.h" - -template -TypeHandle LVector2::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2:: -LVector2() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2:: -LVector2(const LVecBase2 ©) : LVecBase2(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 &LVector2:: -operator = (const LVecBase2 ©) { - LVecBase2::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 &LVector2:: -operator = (NumType fill_value) { - LVecBase2::operator = (fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2:: -LVector2(NumType fill_value) : - LVecBase2(fill_value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2:: -LVector2(NumType x, NumType y) : - LVecBase2(x, y) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::zero Named Constructor -// Access: Public -// Description: Returns a zero-length vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -zero() { - return LVector2(0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -unit_x() { - return LVector2(1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -unit_y() { - return LVector2(0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::unary - -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -operator - () const { - return LVecBase2::operator - (); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::vector + vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVector2:: -operator + (const LVecBase2 &other) const { - return LVecBase2::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::vector + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -operator + (const LVector2 &other) const { - return LVecBase2::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::vector - vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase2 LVector2:: -operator - (const LVecBase2 &other) const { - return LVecBase2::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::vector - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -operator - (const LVector2 &other) const { - return LVecBase2::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::length -// Access: Public -// Description: Returns the length of the vector, by the Pythagorean -// theorem. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVector2:: -length() const { - return csqrt((*this).dot(*this)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::length_squared -// Access: Public -// Description: Returns the square of the vector's length, cheap and -// easy. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVector2:: -length_squared() const { - return (*this).dot(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::normalize -// Access: Public -// Description: Normalizes the vector in place. Returns true if the -// vector was normalized, false if it was a zero-length -// vector. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVector2:: -normalize() { - NumType l2 = length_squared(); - if (l2 == (NumType)0.0) { - set(0.0, 0.0); - return false; - - } else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) { - (*this) /= csqrt(l2); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::operator * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -operator * (NumType scalar) const { - return LVector2(LVecBase2::operator * (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::operator / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector2 LVector2:: -operator / (NumType scalar) const { - return LVector2(LVecBase2::operator / (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector2::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LVector2:: -init_type() { - if (_type_handle == TypeHandle::none()) { - LVecBase2::init_type(); - string name = - "LVector2<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name, - LVecBase2::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 -INLINE LVector2 -lcast_to(NumType2 *, const LVector2 &source) { - return LVector2(source[0], source[1]); -} diff --git a/panda/src/linmath/lvector2.cxx b/panda/src/linmath/lvector2.cxx deleted file mode 100644 index ddb26638e8..0000000000 --- a/panda/src/linmath/lvector2.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Filename: lvector2.cxx -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "lvector2.h" - -#include "fltnames.I" -#include "lvector2_src.I" - -#include "dblnames.I" -#include "lvector2_src.I" - diff --git a/panda/src/linmath/lvector2.h b/panda/src/linmath/lvector2.h deleted file mode 100644 index 42f3406722..0000000000 --- a/panda/src/linmath/lvector2.h +++ /dev/null @@ -1,69 +0,0 @@ -// Filename: lvector2.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LVECTOR2_H -#define LVECTOR2_H - -#include - -#include "lvecBase2.h" - -//////////////////////////////////////////////////////////////////// -// Class : LVector2 -// Description : This is a two-component vector offset. -//////////////////////////////////////////////////////////////////// -template -class LVector2 : public LVecBase2 { -PUBLISHED: - INLINE LVector2(); - INLINE LVector2(const LVecBase2 ©); - INLINE LVector2 &operator = (const LVecBase2 ©); - INLINE LVector2 &operator = (NumType fill_value); - INLINE LVector2(NumType fill_value); - INLINE LVector2(NumType x, NumType y); - - INLINE static LVector2 zero(); - INLINE static LVector2 unit_x(); - INLINE static LVector2 unit_y(); - - INLINE LVector2 operator - () const; - - INLINE LVecBase2 - operator + (const LVecBase2 &other) const; - INLINE LVector2 - operator + (const LVector2 &other) const; - - INLINE LVecBase2 - operator - (const LVecBase2 &other) const; - INLINE LVector2 - operator - (const LVector2 &other) const; - - INLINE NumType length() const; - INLINE NumType length_squared() const; - INLINE bool normalize(); - INLINE LVector2 operator * (NumType scalar) const; - INLINE LVector2 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 -INLINE LVector2 -lcast_to(NumType2 *type, const LVector2 &source); - -#include "lvector2.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector2) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector2) - -#endif diff --git a/panda/src/linmath/lvector2_src.I b/panda/src/linmath/lvector2_src.cxx similarity index 84% rename from panda/src/linmath/lvector2_src.I rename to panda/src/linmath/lvector2_src.cxx index 9cd27a10b9..71b61292ef 100644 --- a/panda/src/linmath/lvector2_src.I +++ b/panda/src/linmath/lvector2_src.cxx @@ -1,4 +1,4 @@ -// Filename: lvector2.I +// Filename: lvector2_src.h // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// @@ -15,8 +15,8 @@ void FLOATNAME(LVector2):: init_type() { if (_type_handle == TypeHandle::none()) { FLOATNAME(LVecBase2)::init_type(); - string name = - "LVector2<" + get_type_handle(FLOATTYPE1).get_name() + ">"; + string name = "LVector2"; + name += FLOATTOKEN; register_type(_type_handle, name, FLOATNAME(LVecBase2)::get_class_type()); } diff --git a/panda/src/linmath/lvector2_src.h b/panda/src/linmath/lvector2_src.h new file mode 100644 index 0000000000..933baef968 --- /dev/null +++ b/panda/src/linmath/lvector2_src.h @@ -0,0 +1,47 @@ +// Filename: lvector2_src.h +// Created by: drose (08Mar00) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Class : LVector2 +// Description : This is a two-component vector offset. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA FLOATNAME(LVector2) : public FLOATNAME(LVecBase2) { +PUBLISHED: + INLINE FLOATNAME(LVector2)(); + INLINE FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©); + INLINE FLOATNAME(LVector2) &operator = (const FLOATNAME(LVecBase2) ©); + INLINE FLOATNAME(LVector2) &operator = (FLOATTYPE fill_value); + INLINE FLOATNAME(LVector2)(FLOATTYPE fill_value); + INLINE FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y); + + INLINE static const FLOATNAME(LVector2) &zero(); + INLINE static const FLOATNAME(LVector2) &unit_x(); + INLINE static const FLOATNAME(LVector2) &unit_y(); + + INLINE FLOATNAME(LVector2) operator - () const; + + INLINE FLOATNAME(LVecBase2)operator + (const FLOATNAME(LVecBase2) &other) const; + INLINE FLOATNAME(LVector2) operator + (const FLOATNAME(LVector2) &other) const; + + INLINE FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const; + INLINE FLOATNAME(LVector2) operator - (const FLOATNAME(LVector2) &other) const; + + INLINE FLOATTYPE length() const; + INLINE FLOATTYPE length_squared() const; + INLINE bool normalize(); + INLINE FLOATNAME(LVector2) operator * (FLOATTYPE scalar) const; + INLINE FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const; + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type(); + +private: + static TypeHandle _type_handle; +}; + +#include "lvector2_src.I" diff --git a/panda/src/linmath/lvector3.I b/panda/src/linmath/lvector3.I deleted file mode 100644 index 81aa9a66a2..0000000000 --- a/panda/src/linmath/lvector3.I +++ /dev/null @@ -1,407 +0,0 @@ -// Filename: lvector3.I -// Created by: drose (24Sep99) -// -//////////////////////////////////////////////////////////////////// - -#include "config_linmath.h" -#include "cmath.h" - -template -TypeHandle LVector3::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3:: -LVector3() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3:: -LVector3(const LVecBase3 ©) : LVecBase3(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 &LVector3:: -operator = (const LVecBase3 ©) { - LVecBase3::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 &LVector3:: -operator = (NumType fill_value) { - LVecBase3::operator = (fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3:: -LVector3(NumType fill_value) : - LVecBase3(fill_value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3:: -LVector3(NumType x, NumType y, NumType z) : - LVecBase3(x, y, z) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::zero Named Constructor -// Access: Public -// Description: Returns a zero-length vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -zero() { - return LVector3(0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -unit_x() { - return LVector3(1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -unit_y() { - return LVector3(0.0, 1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::unit_z Named Constructor -// Access: Public -// Description: Returns a unit Z vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -unit_z() { - return LVector3(0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::unary - -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -operator - () const { - return LVecBase3::operator - (); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::vector + vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVector3:: -operator + (const LVecBase3 &other) const { - return LVecBase3::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::vector + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -operator + (const LVector3 &other) const { - return LVecBase3::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::vector - vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase3 LVector3:: -operator - (const LVecBase3 &other) const { - return LVecBase3::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::vector - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -operator - (const LVector3 &other) const { - return LVecBase3::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::length -// Access: Public -// Description: Returns the length of the vector, by the Pythagorean -// theorem. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVector3:: -length() const { - return csqrt((*this).dot(*this)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::length_squared -// Access: Public -// Description: Returns the square of the vector's length, cheap and -// easy. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVector3:: -length_squared() const { - return (*this).dot(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::normalize -// Access: Public -// Description: Normalizes the vector in place. Returns true if the -// vector was normalized, false if it was a zero-length -// vector. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVector3:: -normalize() { - NumType l2 = length_squared(); - if (l2 == (NumType)0.0) { - set(0.0, 0.0, 0.0); - return false; - - } else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) { - (*this) /= csqrt(l2); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::cross -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -cross(const LVecBase3 &other) const { - return LVecBase3::cross(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::operator * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -operator * (NumType scalar) const { - return LVector3(LVecBase3::operator * (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::operator / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -operator / (NumType scalar) const { - return LVector3(LVecBase3::operator / (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::up -// Access: Public, Static -// Description: Returns the up vector for the given coordinate -// system. -//////////////////////////////////////////////////////////////////// -template -LVector3 LVector3:: -up(CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - switch (cs) { - case CS_zup_right: - case CS_zup_left: - return LVector3(0.0, 0.0, 1.0); - - case CS_yup_right: - case CS_yup_left: - return LVector3(0.0, 1.0, 0.0); - - default: - linmath_cat.error() - << "Invalid coordinate system!\n"; - return LVector3(0.0, 0.0, 0.0); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::right -// Access: Public, Static -// Description: Returns the right vector for the given coordinate -// system. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -right(CoordinateSystem) { - return LVector3(1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::forward -// Access: Public, Static -// Description: Returns the forward vector for the given coordinate -// system. -//////////////////////////////////////////////////////////////////// -template -LVector3 LVector3:: -forward(CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - switch (cs) { - case CS_zup_right: - return LVector3(0.0, 1.0, 0.0); - - case CS_zup_left: - return LVector3(0.0, -1.0, 0.0); - - case CS_yup_right: - return LVector3(0.0, 0.0, -1.0); - - case CS_yup_left: - return LVector3(0.0, 0.0, 1.0); - - default: - linmath_cat.error() - << "Invalid coordinate system!\n"; - return LVector3(0.0, 0.0, 0.0); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::down -// Access: Public, Static -// Description: Returns the down vector for the given coordinate -// system. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -down(CoordinateSystem cs) { - return -up(cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::left -// Access: Public, Static -// Description: Returns the left vector for the given coordinate -// system. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -left(CoordinateSystem cs) { - return -right(cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::back -// Access: Public, Static -// Description: Returns the back vector for the given coordinate -// system. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -back(CoordinateSystem cs) { - return -forward(cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::rfu -// Access: Public, Static -// Description: Returns a vector that is described by its right, -// forward, and up components, in whatever way the -// coordinate system represents that vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector3 LVector3:: -rfu(NumType right_v, NumType fwd_v, NumType up_v, - CoordinateSystem cs) { - return fwd_v * forward(cs) + up_v * up(cs) + right_v * right(cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LVector3:: -init_type() { - if (_type_handle == TypeHandle::none()) { - LVecBase3::init_type(); - string name = - "LVector3<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name, - LVecBase3::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 -INLINE LVector3 -lcast_to(NumType2 *, const LVector3 &source) { - return LVector3(source[0], source[1], source[2]); -} diff --git a/panda/src/linmath/lvector3.cxx b/panda/src/linmath/lvector3.cxx deleted file mode 100644 index 682de0871b..0000000000 --- a/panda/src/linmath/lvector3.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Filename: lvector3.cxx -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "lvector3.h" - -#include "fltnames.I" -#include "lvector3_src.I" - -#include "dblnames.I" -#include "lvector3_src.I" - diff --git a/panda/src/linmath/lvector3.h b/panda/src/linmath/lvector3.h deleted file mode 100644 index f2c2e3c117..0000000000 --- a/panda/src/linmath/lvector3.h +++ /dev/null @@ -1,93 +0,0 @@ -// Filename: lvector3.h -// Created by: drose (24Sep99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LVECTOR3_H -#define LVECTOR3_H - -#include - -#include "coordinateSystem.h" -#include "lvecBase3.h" - -//////////////////////////////////////////////////////////////////// -// Class : LVector3 -// Description : This is a three-component vector distance (as opposed -// to a three-component point, which represents a -// particular point in space). Some of the methods are -// slightly different between LPoint3 and LVector3; in -// particular, subtraction of two points yields a -// vector, while addition of a vector and a point yields -// a point. -//////////////////////////////////////////////////////////////////// -template -class LVector3 : public LVecBase3 { -PUBLISHED: - INLINE LVector3(); - INLINE LVector3(const LVecBase3 ©); - INLINE LVector3 &operator = (const LVecBase3 ©); - INLINE LVector3 &operator = (NumType fill_value); - INLINE LVector3(NumType fill_value); - INLINE LVector3(NumType x, NumType y, NumType z); - - INLINE static LVector3 zero(); - INLINE static LVector3 unit_x(); - INLINE static LVector3 unit_y(); - INLINE static LVector3 unit_z(); - - INLINE LVector3 operator - () const; - - INLINE LVecBase3 - operator + (const LVecBase3 &other) const; - INLINE LVector3 - operator + (const LVector3 &other) const; - - INLINE LVecBase3 - operator - (const LVecBase3 &other) const; - INLINE LVector3 - operator - (const LVector3 &other) const; - - INLINE NumType length() const; - INLINE NumType length_squared() const; - INLINE bool normalize(); - INLINE LVector3 cross(const LVecBase3 &other) const; - INLINE LVector3 operator * (NumType scalar) const; - INLINE LVector3 operator / (NumType scalar) const; - - // Some special named constructors for LVector3. - - static LVector3 up(CoordinateSystem cs = CS_default); - INLINE static LVector3 right(CoordinateSystem cs = CS_default); - static LVector3 forward(CoordinateSystem cs = CS_default); - - INLINE static LVector3 down(CoordinateSystem cs = CS_default); - INLINE static LVector3 left(CoordinateSystem cs = CS_default); - INLINE static LVector3 back(CoordinateSystem cs = CS_default); - - INLINE static LVector3 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 -INLINE LVector3 -lcast_to(NumType2 *type, const LVector3 &source); - -#include "lvector3.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector3) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector3) - -#endif diff --git a/panda/src/linmath/lvector3_src.I b/panda/src/linmath/lvector3_src.cxx similarity index 84% rename from panda/src/linmath/lvector3_src.I rename to panda/src/linmath/lvector3_src.cxx index d70e218672..c8101a2454 100644 --- a/panda/src/linmath/lvector3_src.I +++ b/panda/src/linmath/lvector3_src.cxx @@ -1,4 +1,4 @@ -// Filename: lvector3.I +// Filename: lvector3_src.h // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// @@ -15,8 +15,8 @@ void FLOATNAME(LVector3):: init_type() { if (_type_handle == TypeHandle::none()) { FLOATNAME(LVecBase3)::init_type(); - string name = - "LVector3<" + get_type_handle(FLOATTYPE1).get_name() + ">"; + string name = "LVector3"; + name += FLOATTOKEN; register_type(_type_handle, name, FLOATNAME(LVecBase3)::get_class_type()); } diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h new file mode 100644 index 0000000000..770de70156 --- /dev/null +++ b/panda/src/linmath/lvector3_src.h @@ -0,0 +1,70 @@ +// Filename: lvector3_src.h +// Created by: drose (24Sep99) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Class : LVector3 +// Description : This is a three-component vector distance (as opposed +// to a three-component point, which represents a +// particular point in space). Some of the methods are +// slightly different between LPoint3 and LVector3; in +// particular, subtraction of two points yields a +// vector, while addition of a vector and a point yields +// a point. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA FLOATNAME(LVector3) : public FLOATNAME(LVecBase3) { +PUBLISHED: + INLINE FLOATNAME(LVector3)(); + INLINE FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©); + INLINE FLOATNAME(LVector3) &operator = (const FLOATNAME(LVecBase3) ©); + INLINE FLOATNAME(LVector3) &operator = (FLOATTYPE fill_value); + INLINE FLOATNAME(LVector3)(FLOATTYPE fill_value); + INLINE FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); + + INLINE static const FLOATNAME(LVector3) &zero(); + INLINE static const FLOATNAME(LVector3) &unit_x(); + INLINE static const FLOATNAME(LVector3) &unit_y(); + INLINE static const FLOATNAME(LVector3) &unit_z(); + + INLINE FLOATNAME(LVector3) operator - () const; + + INLINE FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const; + INLINE FLOATNAME(LVector3) operator + (const FLOATNAME(LVector3) &other) const; + + INLINE FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const; + INLINE FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) const; + + INLINE FLOATTYPE length() const; + INLINE FLOATTYPE length_squared() const; + INLINE bool normalize(); + INLINE FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const; + INLINE FLOATNAME(LVector3) operator * (FLOATTYPE scalar) const; + INLINE FLOATNAME(LVector3) operator / (FLOATTYPE scalar) const; + + // Some special named constructors for LVector3. + + INLINE static FLOATNAME(LVector3) up(CoordinateSystem cs = CS_default); + INLINE static FLOATNAME(LVector3) right(CoordinateSystem cs = CS_default); + INLINE static FLOATNAME(LVector3) forward(CoordinateSystem cs = CS_default); + + INLINE static FLOATNAME(LVector3) down(CoordinateSystem cs = CS_default); + INLINE static FLOATNAME(LVector3) left(CoordinateSystem cs = CS_default); + INLINE static FLOATNAME(LVector3) back(CoordinateSystem cs = CS_default); + + INLINE static FLOATNAME(LVector3) rfu(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 "lvector3_src.I" diff --git a/panda/src/linmath/lvector4.I b/panda/src/linmath/lvector4.I deleted file mode 100644 index 841f0ee850..0000000000 --- a/panda/src/linmath/lvector4.I +++ /dev/null @@ -1,285 +0,0 @@ -// Filename: lvector4.I -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "cmath.h" - - -template -TypeHandle LVector4::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4:: -LVector4() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4:: -LVector4(const LVecBase4 ©) : LVecBase4(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 &LVector4:: -operator = (const LVecBase4 ©) { - LVecBase4::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 &LVector4:: -operator = (NumType fill_value) { - LVecBase4::operator = (fill_value); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4:: -LVector4(NumType fill_value) : - LVecBase4(fill_value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4:: -LVector4(NumType x, NumType y, NumType z, NumType w) : - LVecBase4(x, y, z, w) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::zero Named Constructor -// Access: Public -// Description: Returns a zero-length vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -zero() { - return LVector4(0.0, 0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::unit_x Named Constructor -// Access: Public -// Description: Returns a unit X vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -unit_x() { - return LVector4(1.0, 0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::unit_y Named Constructor -// Access: Public -// Description: Returns a unit Y vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -unit_y() { - return LVector4(0.0, 1.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::unit_z Named Constructor -// Access: Public -// Description: Returns a unit Z vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -unit_z() { - return LVector4(0.0, 0.0, 1.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::unit_w Named Constructor -// Access: Public -// Description: Returns a unit W vector. -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -unit_w() { - return LVector4(0.0, 0.0, 0.0, 1.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::unary - -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -operator - () const { - return LVecBase4::operator - (); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::vector + vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVector4:: -operator + (const LVecBase4 &other) const { - return LVecBase4::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::vector + vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -operator + (const LVector4 &other) const { - return LVecBase4::operator + (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::vector - vecbase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVecBase4 LVector4:: -operator - (const LVecBase4 &other) const { - return LVecBase4::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::vector - vector -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -operator - (const LVector4 &other) const { - return LVecBase4::operator - (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::length -// Access: Public -// Description: Returns the length of the vector, by the Pythagorean -// theorem. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVector4:: -length() const { - return csqrt((*this).dot(*this)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::length_squared -// Access: Public -// Description: Returns the square of the vector's length, cheap and -// easy. -//////////////////////////////////////////////////////////////////// -template -INLINE NumType LVector4:: -length_squared() const { - return (*this).dot(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::normalize -// Access: Public -// Description: Normalizes the vector in place. Returns true if the -// vector was normalized, false if it was a zero-length -// vector. -//////////////////////////////////////////////////////////////////// -template -INLINE bool LVector4:: -normalize() { - NumType l2 = length_squared(); - if (l2 == (NumType)0.0) { - set(0.0, 0.0, 0.0, 0.0); - return false; - - } else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) { - (*this) /= csqrt(l2); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::operator * scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -operator * (NumType scalar) const { - return LVector4(LVecBase4::operator * (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::operator / scalar -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE LVector4 LVector4:: -operator / (NumType scalar) const { - return LVector4(LVecBase4::operator / (scalar)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -template -void LVector4:: -init_type() { - if (_type_handle == TypeHandle::none()) { - LVecBase4::init_type(); - string name = - "LVector4<" + get_type_handle(NumType).get_name() + ">"; - register_type(_type_handle, name, - LVecBase4::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 -INLINE LVector4 -lcast_to(NumType2 *, const LVector4 &source) { - return LVector4(source[0], source[1], source[2], source[3]); -} diff --git a/panda/src/linmath/lvector4.cxx b/panda/src/linmath/lvector4.cxx deleted file mode 100644 index 2c254c9578..0000000000 --- a/panda/src/linmath/lvector4.cxx +++ /dev/null @@ -1,13 +0,0 @@ -// Filename: lvector4.cxx -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include "lvector4.h" - -#include "fltnames.I" -#include "lvector4_src.I" - -#include "dblnames.I" -#include "lvector4_src.I" - diff --git a/panda/src/linmath/lvector4.h b/panda/src/linmath/lvector4.h deleted file mode 100644 index 37164261c2..0000000000 --- a/panda/src/linmath/lvector4.h +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: lvector4.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LVECTOR4_H -#define LVECTOR4_H - -#include - -#include "lvecBase4.h" - -//////////////////////////////////////////////////////////////////// -// Class : LVector4 -// Description : This is a four-component vector distance. -//////////////////////////////////////////////////////////////////// -template -class LVector4 : public LVecBase4 { -PUBLISHED: - INLINE LVector4(); - INLINE LVector4(const LVecBase4 ©); - INLINE LVector4 &operator = (const LVecBase4 ©); - INLINE LVector4 &operator = (NumType fill_value); - INLINE LVector4(NumType fill_value); - INLINE LVector4(NumType x, NumType y, NumType z, NumType w); - - INLINE static LVector4 zero(); - INLINE static LVector4 unit_x(); - INLINE static LVector4 unit_y(); - INLINE static LVector4 unit_z(); - INLINE static LVector4 unit_w(); - - INLINE LVector4 operator - () const; - - INLINE LVecBase4 - operator + (const LVecBase4 &other) const; - INLINE LVector4 - operator + (const LVector4 &other) const; - - INLINE LVecBase4 - operator - (const LVecBase4 &other) const; - INLINE LVector4 - operator - (const LVector4 &other) const; - - INLINE NumType length() const; - INLINE NumType length_squared() const; - INLINE bool normalize(); - INLINE LVector4 operator * (NumType scalar) const; - INLINE LVector4 operator / (NumType scalar) const; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type(); - -private: - static TypeHandle _type_handle; -}; - -template -INLINE LVector4 -lcast_to(NumType2 *type, const LVector4 &source); - -#include "lvector4.I" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector4) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, LVector4) - -#endif diff --git a/panda/src/linmath/lvector4_src.I b/panda/src/linmath/lvector4_src.cxx similarity index 84% rename from panda/src/linmath/lvector4_src.I rename to panda/src/linmath/lvector4_src.cxx index d434b1a388..0db8689019 100644 --- a/panda/src/linmath/lvector4_src.I +++ b/panda/src/linmath/lvector4_src.cxx @@ -1,4 +1,4 @@ -// Filename: lvector4.I +// Filename: lvector4_src.h // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// @@ -15,8 +15,8 @@ void FLOATNAME(LVector4):: init_type() { if (_type_handle == TypeHandle::none()) { FLOATNAME(LVecBase4)::init_type(); - string name = - "LVector4<" + get_type_handle(FLOATTYPE1).get_name() + ">"; + string name = "LVector4"; + name += FLOATTOKEN; register_type(_type_handle, name, FLOATNAME(LVecBase4)::get_class_type()); } diff --git a/panda/src/linmath/lvector4_src.h b/panda/src/linmath/lvector4_src.h new file mode 100644 index 0000000000..267181d2c6 --- /dev/null +++ b/panda/src/linmath/lvector4_src.h @@ -0,0 +1,49 @@ +// Filename: lvector4_src.h +// Created by: drose (08Mar00) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Class : LVector4 +// Description : This is a four-component vector distance. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA FLOATNAME(LVector4) : public FLOATNAME(LVecBase4) { +PUBLISHED: + INLINE FLOATNAME(LVector4)(); + INLINE FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©); + INLINE FLOATNAME(LVector4) &operator = (const FLOATNAME(LVecBase4) ©); + INLINE FLOATNAME(LVector4) &operator = (FLOATTYPE fill_value); + INLINE FLOATNAME(LVector4)(FLOATTYPE fill_value); + INLINE FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + + INLINE static const FLOATNAME(LVector4) &zero(); + INLINE static const FLOATNAME(LVector4) &unit_x(); + INLINE static const FLOATNAME(LVector4) &unit_y(); + INLINE static const FLOATNAME(LVector4) &unit_z(); + INLINE static const FLOATNAME(LVector4) &unit_w(); + + INLINE FLOATNAME(LVector4) operator - () const; + + INLINE FLOATNAME(LVecBase4) operator + (const FLOATNAME(LVecBase4) &other) const; + INLINE FLOATNAME(LVector4) operator + (const FLOATNAME(LVector4) &other) const; + + INLINE FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const; + INLINE FLOATNAME(LVector4) operator - (const FLOATNAME(LVector4) &other) const; + + INLINE FLOATTYPE length() const; + INLINE FLOATTYPE length_squared() const; + INLINE bool normalize(); + INLINE FLOATNAME(LVector4) operator * (FLOATTYPE scalar) const; + INLINE FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const; + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type(); + +private: + static TypeHandle _type_handle; +}; + +#include "lvector4_src.I" diff --git a/panda/src/linmath/mathNumbers.cxx b/panda/src/linmath/mathNumbers.cxx deleted file mode 100644 index 1788a6e080..0000000000 --- a/panda/src/linmath/mathNumbers.cxx +++ /dev/null @@ -1,10 +0,0 @@ -// Filename: mathNumbers.cxx -// Created by: mike (24Sep99) -// -//////////////////////////////////////////////////////////////////// - -#include "mathNumbers.h" -#include - -const double MathNumbers::pi = 4.0 * atan(1); -const double MathNumbers::ln2 = log(2); diff --git a/panda/src/linmath/mathNumbers.h b/panda/src/linmath/mathNumbers.h deleted file mode 100644 index c71eaf11f5..0000000000 --- a/panda/src/linmath/mathNumbers.h +++ /dev/null @@ -1,17 +0,0 @@ -// Filename: mathNumbers.h -// Created by: mike (23Jan99) -// -//////////////////////////////////////////////////////////////////// -// -#ifndef MATHNUMBERS_H -#define MATHNUMBERS_H - -#include - -class EXPCL_PANDA MathNumbers { -PUBLISHED: - static const double pi; - static const double ln2; -}; - -#endif diff --git a/panda/src/linmath/nearly_zero.h b/panda/src/linmath/nearly_zero.h deleted file mode 100644 index 31de0a048a..0000000000 --- a/panda/src/linmath/nearly_zero.h +++ /dev/null @@ -1,58 +0,0 @@ -// Filename: nearly_zero.h -// Created by: drose (08Mar00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef NEARLY_ZERO_H -#define NEARLY_ZERO_H - - -// The following two functions are defined just to make the -// NEARLY_ZERO() macro work. They each return a suitable nearly-zero -// value for their corresponding numeric type. -INLINE double -get_nearly_zero_value(double) { - return 1.0e-12; -} - -INLINE float -get_nearly_zero_value(float) { - return 1.0e-6f; -} - - -// IS_THRESHOLD_ZERO(value, threshold) returns true if the value is -// within threshold of zero. -#define IS_THRESHOLD_ZERO(value, threshold) \ - ((value) < (threshold) && (value) > -(threshold)) - -// IS_THRESHOLD_EQUAL(value1, value2, threshold) returns true if the -// two values are within threshold of each other. -#define IS_THRESHOLD_EQUAL(value1, value2, threshold) \ - (IS_THRESHOLD_ZERO((value1) - (value2), threshold)) - - -// NEARLY_ZERO(float) returns a number that is considered to be so -// close to zero as not to matter for a float. NEARLY_ZERO(double) -// returns a similar, smaller number for a double. -#define NEARLY_ZERO(NumType) (get_nearly_zero_value((NumType)0)) - -// IS_NEARLY_ZERO(value) returns true if the value is very close to -// zero. -#define IS_NEARLY_ZERO(value) \ - (IS_THRESHOLD_ZERO(value, get_nearly_zero_value(value))) - -// IS_NEARLY_EQUAL(value1, value2) returns true if the two values are -// very close to each other. -#define IS_NEARLY_EQUAL(value1, value2) \ - IS_NEARLY_ZERO((value1) - (value2)) - - -// MAYBE_ZERO(value) returns 0 if the value is nearly zero, and the -// value itself otherwise. -#define MAYBE_ZERO(value) \ - (IS_NEARLY_ZERO(value) ? 0.0 : value) - - -#endif - diff --git a/panda/src/linmath/pta_Colorf.cxx b/panda/src/linmath/pta_Colorf.cxx deleted file mode 100644 index fe648db736..0000000000 --- a/panda/src/linmath/pta_Colorf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: pta_Colorf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "pta_Colorf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/pta_Colorf.h b/panda/src/linmath/pta_Colorf.h deleted file mode 100644 index e7f4f0a28b..0000000000 --- a/panda/src/linmath/pta_Colorf.h +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: pta_Colorf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef PTA_COLORF_H -#define PTA_COLORF_H - -#include - -#include "vector_Colorf.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PTA_Colorf -// Description : A pta of Colorfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a pta of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the pta again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, RefCountObj); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase >); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToArray) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerToArray) - -typedef PointerToArray PTA_Colorf; -typedef ConstPointerToArray CPTA_Colorf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/pta_Normalf.cxx b/panda/src/linmath/pta_Normalf.cxx deleted file mode 100644 index 596e3595a8..0000000000 --- a/panda/src/linmath/pta_Normalf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: pta_Normalf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "pta_Normalf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/pta_Normalf.h b/panda/src/linmath/pta_Normalf.h deleted file mode 100644 index 12df8d4eae..0000000000 --- a/panda/src/linmath/pta_Normalf.h +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: pta_Normalf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef PTA_NORMALF_H -#define PTA_NORMALF_H - -#include - -#include "vector_Normalf.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PTA_Normalf -// Description : A pta of Normalfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a pta of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the pta again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, RefCountObj); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase >); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToArray) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerToArray) - -typedef PointerToArray PTA_Normalf; -typedef ConstPointerToArray CPTA_Normalf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/pta_TexCoordf.cxx b/panda/src/linmath/pta_TexCoordf.cxx deleted file mode 100644 index 149e36b800..0000000000 --- a/panda/src/linmath/pta_TexCoordf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: pta_TexCoordf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "pta_TexCoordf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/pta_TexCoordf.h b/panda/src/linmath/pta_TexCoordf.h deleted file mode 100644 index ae321bac5b..0000000000 --- a/panda/src/linmath/pta_TexCoordf.h +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: pta_TexCoordf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef PTA_TEXCOORDF_H -#define PTA_TEXCOORDF_H - -#include - -#include "vector_TexCoordf.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PTA_TexCoordf -// Description : A pta of TexCoordfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a pta of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the pta again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, RefCountObj); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase >); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToArray) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerToArray) - -typedef PointerToArray PTA_TexCoordf; -typedef ConstPointerToArray CPTA_TexCoordf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/pta_Vertexf.cxx b/panda/src/linmath/pta_Vertexf.cxx deleted file mode 100644 index 1c145bc5b0..0000000000 --- a/panda/src/linmath/pta_Vertexf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: pta_Vertexf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "pta_Vertexf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/pta_Vertexf.h b/panda/src/linmath/pta_Vertexf.h deleted file mode 100644 index 7f3eed9c9b..0000000000 --- a/panda/src/linmath/pta_Vertexf.h +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: pta_Vertexf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef PTA_VERTEXF_H -#define PTA_VERTEXF_H - -#include - -#include "vector_Vertexf.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PTA_Vertexf -// Description : A pta of Vertexfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a pta of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the pta again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, RefCountObj); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase >); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToArray); -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerToArray); - -typedef PointerToArray PTA_Vertexf; -typedef ConstPointerToArray CPTA_Vertexf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/test_math.cxx b/panda/src/linmath/test_math.cxx deleted file mode 100644 index 2fd7c4aa83..0000000000 --- a/panda/src/linmath/test_math.cxx +++ /dev/null @@ -1,147 +0,0 @@ -// Filename: test_math.cxx -// Created by: drose (14Jan99) -// -//////////////////////////////////////////////////////////////////// - -#include "luse.h" -#include "lmatrix.h" -#include "compose_matrix.h" - -#include -#include - -void test() { - LMatrix4f x = LMatrix4f::ident_mat(); - LMatrix4f y = LMatrix4f::ident_mat(); - - LMatrix4f z = x * y; -} - -int main(int argc, char *argv[]) { - test(); - - /* - - LOrientationf orientation; // = LQuaternionf::ident_quat(); - orientation.set(LMatrix4f::rotate_mat(-45.0f, LVector3f(0, 0, 1))); - LRotationf rotation(LMatrix4f::rotate_mat(45.0f, LVector3f(0, 0, 1))); - - nout << "Orientation: " << orientation << endl; - nout << "Rotation: " << rotation << endl; - - LQuaternionf composition = orientation * rotation; - - nout << "Composition (o * r): " << composition << endl; - composition.normalize(); - nout << "Composition (after normalize): " << composition << endl; - - LPoint3f p(1, 0, 0); - LMatrix4f m = LMatrix4f::ident_mat(); - - composition.extract_to_matrix(m); - cout << "Rotation => Matrix: " << m << endl; - cout << "Point: " << p << endl; - cout << "Matrix * Point: " << m * p << endl; - */ - - /* - LMatrix4d x = LMatrix4d::ident_mat(); - LMatrix4d y = LMatrix4d::rotate_mat(90.0, LVector3d::up()); - LMatrix4d a = LMatrix4d::translate_mat(10.0, 10.0, 0.0); - - nout << "x is " << x << "\ny is " << y << "\n" - << "x * y is " << x * y << "\n" - << "y * x is " << y * x << "\n" - << "invert(x) is " << invert(x) << "\n" - << "invert(y) is " << invert(y) << "\n" - << "y * a is " << y * a << "\n" - << "invert(y * a) is " << invert(y * a) << "\n" - << "invert(invert(y * a)) is " << invert(invert(y * a)) << "\n" - << "(y * a) * invert(y * a) is " << (y * a) * invert(y * a) << "\n" - << "a * y is " << a * y << "\n" - << "invert(a * y) is " << invert(a * y) << "\n" - << "invert(invert(a * y)) is " << invert(invert(a * y)) << "\n"; - - nout << "a is " << a << "\n" - << "a * y is " << a * y << "\n" - << "y * a is " << y * a << "\n"; - - LVector3d r = LVector3d::right(); - nout << "r is " << r << "\n" - << "r * x is " << r * x << "\n" - << "r * y is " << r * y << "\n" - << "r * invert(y) is " << r * invert(y) << "\n" - << "r * a is " << r * a << "\n"; - - LPoint3d p(0.0, 1.0, 1.0); - nout << "p is " << p << "\n" - << "p * x is " << p * x << "\n" - << "p * y is " << p * y << "\n" - << "p * invert(y) is " << p * invert(y) << "\n" - << "p * a is " << p * a << "\n"; - - LVecBase4d q(0.0, 1.0, 1.0, 1.0); - nout << "q is " << q << "\n" - << "q * x is " << q * x << "\n" - << "q * y is " << q * y << "\n" - << "q * invert(y) is " << q * invert(y) << "\n" - << "q * a is " << q * a << "\n"; - - Normald v1(0,0,1), v2(1,1,1); - Vertexd p1(1,0,1), p2(1,2,3); - Colorf c1(1,1,1,1), c2(0,0,0,0); - - p2 = p2 - v1; - - nout << "v1 = " << v1 - << "\nv2 = " << v2 - << "\np1 = " << p1 - << "\np2 = " << p2 - << "\nc1 = " << c1 - << "\n(c1 == c2) = " << (c1 == c2) - << "\n"; - - { - LVecBase3f hpr(0.0, 0.0, 0.0); - LVecBase3f scale(1.0, 1.0, 1.0); - - if (argc > 3) { - hpr.set(atof(argv[1]), atof(argv[2]), atof(argv[3])); - } - if (argc > 6) { - scale.set(atof(argv[4]), atof(argv[5]), atof(argv[6])); - } - - cerr << "< hpr = " << hpr << " scale = " << scale << "\n"; - LMatrix3f mat; - compose_matrix(mat, scale, hpr); - - if (decompose_matrix(mat, scale, hpr)) { - nout << "> hpr = " << hpr << " scale = " << scale << "\n"; - } else { - nout << "Cannot decompose\n"; - } - } - */ - - /* - for (int p = -90; p < 90; p += 10) { - for (int x = -10; x < 10; x += 5) { - LVecBase3f hpr(0, p, 0); - LVecBase3f xyz(x, x, x); - LVecBase3f scale(1, 1, 1); - nout << "\n< hpr = " << hpr << " xyz = " << xyz << "\n"; - LMatrix4f mat; - compose_matrix(mat, scale, hpr, xyz); - if (decompose_matrix(mat, scale, hpr, xyz)) { - nout << "> hpr = " << hpr << " xyz = " << xyz << "\n"; - } else { - nout << "Cannot decompose\n"; - } - } - } - */ - - return(0); -} - diff --git a/panda/src/linmath/vector_Colorf.cxx b/panda/src/linmath/vector_Colorf.cxx deleted file mode 100644 index b5eb7311c5..0000000000 --- a/panda/src/linmath/vector_Colorf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: vector_Colorf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "vector_Colorf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/vector_Colorf.h b/panda/src/linmath/vector_Colorf.h deleted file mode 100644 index 753483c87b..0000000000 --- a/panda/src/linmath/vector_Colorf.h +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: vector_Colorf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_COLORF_H -#define VECTOR_COLORF_H - -#include - -#include "luse.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : vector_Colorf -// Description : A vector of Colorfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a vector of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, std::vector) -typedef vector vector_Colorf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/vector_LPoint2f.cxx b/panda/src/linmath/vector_LPoint2f.cxx deleted file mode 100644 index cbf77ba3c6..0000000000 --- a/panda/src/linmath/vector_LPoint2f.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: vector_LPoint2f.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "vector_LPoint2f.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/vector_LPoint2f.h b/panda/src/linmath/vector_LPoint2f.h deleted file mode 100644 index 2be164f9c9..0000000000 --- a/panda/src/linmath/vector_LPoint2f.h +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: vector_LPoint2f.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_LPOINT2F_H -#define VECTOR_LPOINT2F_H - -#include - -#include "luse.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : vector_LPoint2f -// Description : A vector of LPoint2fs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a vector of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, std::vector) -typedef vector vector_LPoint2f; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/vector_LVecBase3f.cxx b/panda/src/linmath/vector_LVecBase3f.cxx deleted file mode 100644 index 7827bb89f9..0000000000 --- a/panda/src/linmath/vector_LVecBase3f.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: vector_LVecBase3f.cxx -// Created by: drose (11Dec00) -// -//////////////////////////////////////////////////////////////////// - -#include "vector_LVecBase3f.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/vector_LVecBase3f.h b/panda/src/linmath/vector_LVecBase3f.h deleted file mode 100644 index 5d152529f7..0000000000 --- a/panda/src/linmath/vector_LVecBase3f.h +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: vector_LVecBase3f.h -// Created by: drose (11Dec00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_LVECBASE3F_H -#define VECTOR_LVECBASE3F_H - -#include - -#include "luse.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : vector_LVecBase3f -// Description : A vector of LVecBase3fs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a vector of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, std::vector) -typedef vector vector_LVecBase3f; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/vector_Normalf.cxx b/panda/src/linmath/vector_Normalf.cxx deleted file mode 100644 index 1e9805076e..0000000000 --- a/panda/src/linmath/vector_Normalf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: vector_Normalf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "vector_Normalf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/vector_Normalf.h b/panda/src/linmath/vector_Normalf.h deleted file mode 100644 index 22c1577615..0000000000 --- a/panda/src/linmath/vector_Normalf.h +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: vector_Normalf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_NORMALF_H -#define VECTOR_NORMALF_H - -#include - -#include "luse.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : vector_Normalf -// Description : A vector of Normalfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a vector of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, std::vector) -typedef vector vector_Normalf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/linmath/vector_TexCoordf.h b/panda/src/linmath/vector_TexCoordf.h deleted file mode 100644 index f3153b1d7e..0000000000 --- a/panda/src/linmath/vector_TexCoordf.h +++ /dev/null @@ -1,20 +0,0 @@ -// Filename: vector_TexCoordf.h -// Created by: drose (11May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_TEXCOORDF_H -#define VECTOR_TEXCOORDF_H - -#include - -#include "vector_LPoint2f.h" - -//////////////////////////////////////////////////////////////////// -// Class : vector_TexCoordf -// Description : This is just another name for vector_LPoint2f. -//////////////////////////////////////////////////////////////////// - -typedef vector_LPoint2f vector_TexCoordf; - -#endif diff --git a/panda/src/linmath/vector_Vertexf.cxx b/panda/src/linmath/vector_Vertexf.cxx deleted file mode 100644 index 40d732c49f..0000000000 --- a/panda/src/linmath/vector_Vertexf.cxx +++ /dev/null @@ -1,11 +0,0 @@ -// Filename: vector_Vertexf.cxx -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#include "vector_Vertexf.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/linmath/vector_Vertexf.h b/panda/src/linmath/vector_Vertexf.h deleted file mode 100644 index a043f6c30e..0000000000 --- a/panda/src/linmath/vector_Vertexf.h +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: vector_Vertexf.h -// Created by: drose (10May00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_VERTEXF_H -#define VECTOR_VERTEXF_H - -#include - -#include "luse.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : vector_Vertexf -// Description : A vector of Vertexfs. This class is defined once here, -// and exported to PANDA.DLL; other packages that want -// to use a vector of this type (whether they need to -// export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, std::vector) -typedef vector vector_Vertexf; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/mathutil/Sources.pp b/panda/src/mathutil/Sources.pp deleted file mode 100644 index 96a7be4047..0000000000 --- a/panda/src/mathutil/Sources.pp +++ /dev/null @@ -1,49 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET mathutil - #define LOCAL_LIBS \ - linmath putil - #define USE_FFTW yes - #define UNIX_SYS_LIBS m - - #define SOURCES \ - boundingHexahedron.I boundingHexahedron.cxx boundingHexahedron.h \ - boundingLine.I boundingLine.cxx boundingLine.h boundingSphere.I \ - boundingSphere.cxx boundingSphere.h boundingVolume.I \ - boundingVolume.cxx boundingVolume.h config_mathutil.cxx \ - config_mathutil.h \ - fftCompressor.cxx fftCompressor.h \ - finiteBoundingVolume.cxx finiteBoundingVolume.h \ - frustum.I frustum.h \ - geometricBoundingVolume.I geometricBoundingVolume.cxx \ - geometricBoundingVolume.h look_at.I look_at.cxx look_at.h \ - omniBoundingVolume.I omniBoundingVolume.cxx omniBoundingVolume.h \ - plane.I plane.N plane.cxx plane.h rotate_to.cxx rotate_to.h - - #define INSTALL_HEADERS \ - boundingHexahedron.I boundingHexahedron.h boundingLine.I \ - boundingLine.h boundingSphere.I boundingSphere.h boundingVolume.I \ - boundingVolume.h config_mathutil.h \ - fftCompressor.h \ - finiteBoundingVolume.h frustum.I \ - frustum.h geometricBoundingVolume.I geometricBoundingVolume.h \ - look_at.I look_at.h mathHelpers.I mathHelpers.h mathutil.h \ - omniBoundingVolume.I omniBoundingVolume.h plane.I plane.h \ - rotate_to.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_mathutil - #define LOCAL_LIBS \ - mathutil - - #define SOURCES \ - test_mathutil.cxx - -#end test_bin_target - diff --git a/panda/src/mathutil/boundingHexahedron.I b/panda/src/mathutil/boundingHexahedron.I deleted file mode 100644 index 6a2069bfac..0000000000 --- a/panda/src/mathutil/boundingHexahedron.I +++ /dev/null @@ -1,30 +0,0 @@ -// Filename: boundingHexahedron.I -// Created by: drose (03Oct99) -// -//////////////////////////////////////////////////////////////////// - -INLINE BoundingHexahedron:: -BoundingHexahedron() { -} - -INLINE int BoundingHexahedron:: -get_num_points() const { - return num_points; -} - -INLINE LPoint3f BoundingHexahedron:: -get_point(int n) const { - nassertr(n >= 0 && n < num_points, LPoint3f(0.0, 0.0, 0.0)); - return _points[n]; -} - -INLINE int BoundingHexahedron:: -get_num_planes() const { - return num_planes; -} - -INLINE Planef BoundingHexahedron:: -get_plane(int n) const { - nassertr(n >= 0 && n < num_planes, Planef()); - return _planes[n]; -} diff --git a/panda/src/mathutil/boundingHexahedron.cxx b/panda/src/mathutil/boundingHexahedron.cxx deleted file mode 100644 index 84206f1aea..0000000000 --- a/panda/src/mathutil/boundingHexahedron.cxx +++ /dev/null @@ -1,336 +0,0 @@ -// Filename: boundingHexahedron.cxx -// Created by: drose (03Oct99) -// -//////////////////////////////////////////////////////////////////// - -#include "boundingHexahedron.h" -#include "boundingSphere.h" -#include "config_mathutil.h" - -#include -#include - -TypeHandle BoundingHexahedron::_type_handle; - -BoundingHexahedron:: -BoundingHexahedron(const Frustumf &frustum, bool is_ortho, - CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - - float fs = 1.0; - if (!is_ortho) { - fs = frustum._ffar / frustum._fnear; - } - - // We build the points based on a Z-up right-handed frustum. If the - // requested coordinate system is otherwise, we'll convert it in a - // second pass. - _points[0].set(frustum._l * fs, frustum._ffar, frustum._b * fs); - _points[1].set(frustum._r * fs, frustum._ffar, frustum._b * fs); - _points[2].set(frustum._r * fs, frustum._ffar, frustum._t * fs); - _points[3].set(frustum._l * fs, frustum._ffar, frustum._t * fs); - _points[4].set(frustum._l, frustum._fnear, frustum._b); - _points[5].set(frustum._r, frustum._fnear, frustum._b); - _points[6].set(frustum._r, frustum._fnear, frustum._t); - _points[7].set(frustum._l, frustum._fnear, frustum._t); - - _flags = 0; - - // Now fix the coordinate system, if necessary. - if (cs == CS_zup_right) { - set_centroid(); - set_planes(); - } else { - xform(LMatrix4f::convert_mat(CS_zup_right, cs)); - } -} - -BoundingVolume *BoundingHexahedron:: -make_copy() const { - return new BoundingHexahedron(*this); -} - -LPoint3f BoundingHexahedron:: -get_min() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - int i; - LPoint3f m = _points[0]; - for (i = 1; i < num_points; i++) { - m.set(min(m[0], _points[i][0]), - min(m[1], _points[i][1]), - min(m[2], _points[i][2])); - } - return m; -} - -LPoint3f BoundingHexahedron:: -get_max() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - int i; - LPoint3f m = _points[0]; - for (i = 1; i < num_points; i++) { - m.set(max(m[0], _points[i][0]), - max(m[1], _points[i][1]), - max(m[2], _points[i][2])); - } - return m; -} - -LPoint3f BoundingHexahedron:: -get_approx_center() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - return _centroid; -} - -void BoundingHexahedron:: -xform(const LMatrix4f &mat) { - if (!is_empty() && !is_infinite()) { - for (int i = 0; i < num_points; i++) { - _points[i] = _points[i] * mat; - } - set_centroid(); - set_planes(); - } -} - -void BoundingHexahedron:: -output(ostream &out) const { - if (is_empty()) { - out << "bhexahedron, empty"; - } else if (is_infinite()) { - out << "bhexahedron, infinite"; - } else { - out << "bhexahedron, min " << get_min() << " max " << get_max(); - } -} - -void BoundingHexahedron:: -write(ostream &out, int indent_level) const { - if (is_empty()) { - indent(out, indent_level) << "bhexahedron, empty\n"; - } else if (is_infinite()) { - out << "bhexahedron, infinite\n"; - } else { - indent(out, indent_level) - << "bhexahedron, min " << get_min() << " max " << get_max() << ":\n"; - int i; - for (i = 0; i < num_points; i++) { - indent(out, indent_level + 2) << _points[i] << "\n"; - } - indent(out, indent_level + 2) << "centroid is " << _centroid << "\n"; - } -} - -bool BoundingHexahedron:: -extend_other(BoundingVolume *other) const { - return other->extend_by_hexahedron(this); -} - -bool BoundingHexahedron:: -around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const { - return other->around_hexahedrons(first, last); -} - -int BoundingHexahedron:: -contains_other(const BoundingVolume *other) const { - return other->contains_hexahedron(this); -} - - -bool BoundingHexahedron:: -extend_by_point(const LPoint3f &) { - mathutil_cat.error() - << "BoundingHexahedron::extend_by_point() called\n"; - return false; -} - -bool BoundingHexahedron:: -extend_by_sphere(const BoundingSphere *) { - mathutil_cat.error() - << "BoundingHexahedron::extend_by_sphere() called\n"; - return false; -} - -bool BoundingHexahedron:: -extend_by_hexahedron(const BoundingHexahedron *) { - mathutil_cat.error() - << "BoundingHexahedron::extend_by_hexahedron() called\n"; - return false; -} - -bool BoundingHexahedron:: -around_points(const LPoint3f *, const LPoint3f *) { - mathutil_cat.error() - << "BoundingHexahedron::around_points() called\n"; - return false; -} - -bool BoundingHexahedron:: -around_spheres(const BoundingVolume **, - const BoundingVolume **) { - mathutil_cat.error() - << "BoundingHexahedron::around_spheres() called\n"; - return false; -} - -bool BoundingHexahedron:: -around_hexahedrons(const BoundingVolume **, - const BoundingVolume **) { - mathutil_cat.error() - << "BoundingHexahedron::around_hexahedrons() called\n"; - return false; -} - -int BoundingHexahedron:: -contains_point(const LPoint3f &point) const { - if (is_empty()) { - return IF_no_intersection; - - } else if (is_infinite()) { - return IF_possible | IF_some | IF_all; - - } else { - // The hexahedron contains the point iff the point is behind all of - // the planes. - for (int i = 0; i < num_planes; i++) { - const Planef &p = _planes[i]; - if (p.dist_to_plane(point) > 0.0) { - return IF_no_intersection; - } - } - return IF_possible | IF_some | IF_all; - } -} - -int BoundingHexahedron:: -contains_lineseg(const LPoint3f &a, const LPoint3f &b) const { - if (is_empty()) { - return IF_no_intersection; - - } else if (is_infinite()) { - return IF_possible | IF_some | IF_all; - - } else { - // The hexahedron does not contains the line segment if both points - // are in front of any one plane. - for (int i = 0; i < num_planes; i++) { - const Planef &p = _planes[i]; - if (p.dist_to_plane(a) > 0.0 || - p.dist_to_plane(b) > 0.0) { - return IF_no_intersection; - } - } - - // If there is no plane that both points are in front of, the - // hexahedron may or may not contain the line segment. For the - // moment, we won't bother to check that more thoroughly, though. - return IF_possible; - } -} - -int BoundingHexahedron:: -contains_sphere(const BoundingSphere *sphere) const { - nassertr(!is_empty(), 0); - - // The hexahedron contains the sphere iff the sphere is at least - // partly behind all of the planes. - const LPoint3f ¢er = sphere->get_center(); - float radius = sphere->get_radius(); - - int result = IF_possible | IF_some | IF_all; - - for (int i = 0; i < num_planes; i++) { - const Planef &p = _planes[i]; - float dist = p.dist_to_plane(center); - - if (dist > radius) { - // The sphere is completely in front of this plane; it's thus - // completely outside of the hexahedron. - return IF_no_intersection; - - } else if (dist > -radius) { - // The sphere is not completely behind this plane, but some of - // it is. - result &= ~IF_all; - } - } - - return result; -} - -int BoundingHexahedron:: -contains_hexahedron(const BoundingHexahedron *hexahedron) const { - nassertr(!is_empty(), 0); - nassertr(!hexahedron->is_empty(), 0); - - // Check minmax. - LPoint3f min1 = get_min(); - LPoint3f min2 = hexahedron->get_min(); - LPoint3f max1 = get_max(); - LPoint3f max2 = hexahedron->get_max(); - - if (min1[0] > max2[0] || min1[1] > max2[1] || min1[2] > max2[2] || - min2[0] > max1[0] || min2[1] > max1[1] || min2[2] > max1[2] || - max1[0] < min2[0] || max1[1] < min2[1] || max1[2] < min2[2] || - max2[0] < min1[0] || max2[1] < min1[1] || max2[2] < min1[2]) { - return IF_no_intersection; - } - - int result = IF_possible | IF_all; - - for (int i = 0; i < num_points; i++) { - if (contains_point(hexahedron->_points[i])) { - result |= IF_some; - } else { - result &= ~IF_all; - } - } - - return result; -} - -void BoundingHexahedron:: -set_planes() { - _planes[0] = Planef(_points[0], _points[3], _points[2]); - - // Test to see if we have accidentally inverted our frustum by - // transforming it with a -1 matrix. We do this by ensuring that - // the centroid is in front of all of the planes (actually, we only - // need to test the first plane). - if (_planes[0].dist_to_plane(_centroid) >= 0) { - // Oops! We're flipped! Rebuild the planes in the opposite - // direction. - _planes[0] = Planef(_points[0], _points[2], _points[3]); - _planes[1] = Planef(_points[0], _points[5], _points[1]); - _planes[2] = Planef(_points[1], _points[6], _points[2]); - _planes[3] = Planef(_points[2], _points[7], _points[3]); - _planes[4] = Planef(_points[3], _points[4], _points[0]); - _planes[5] = Planef(_points[4], _points[7], _points[6]); - - nassertv(_planes[0].dist_to_plane(_centroid) < 0); - - } else { - // No, a perfectly sane universe. - _planes[1] = Planef(_points[0], _points[1], _points[5]); - _planes[2] = Planef(_points[1], _points[2], _points[6]); - _planes[3] = Planef(_points[2], _points[3], _points[7]); - _planes[4] = Planef(_points[3], _points[0], _points[4]); - _planes[5] = Planef(_points[4], _points[6], _points[7]); - } -} - -void BoundingHexahedron:: -set_centroid() { - LPoint3f net = _points[0]; - for (int i = 1; i < num_points; i++) { - net += _points[i]; - } - _centroid = net / (float)num_points; -} diff --git a/panda/src/mathutil/boundingHexahedron.h b/panda/src/mathutil/boundingHexahedron.h deleted file mode 100644 index 88a695337f..0000000000 --- a/panda/src/mathutil/boundingHexahedron.h +++ /dev/null @@ -1,109 +0,0 @@ -// Filename: boundingHexahedron.h -// Created by: drose (03Oct99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef BOUNDINGHEXAHEDRON_H -#define BOUNDINGHEXAHEDRON_H - -#include - -#include "finiteBoundingVolume.h" -#include "frustum.h" -#include "plane.h" - -#include - - -/////////////////////////////////////////////////////////////////// -// Class : BoundingHexahedron -// Description : This defines a bounding convex hexahedron. It is -// typically used to represent a frustum, but may -// represent any enclosing convex hexahedron. -// -// This class does not support any of the around() or -// extend_by() functions, but all other functionality -// should be well-defined. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA BoundingHexahedron : public FiniteBoundingVolume { -public: - INLINE BoundingHexahedron(); - BoundingHexahedron(const Frustumf &frustum, bool is_ortho, - CoordinateSystem cs = CS_default); - virtual BoundingVolume *make_copy() const; - - virtual LPoint3f get_min() const; - virtual LPoint3f get_max() const; - - virtual LPoint3f get_approx_center() const; - virtual void xform(const LMatrix4f &mat); - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - - INLINE int get_num_points() const; - INLINE LPoint3f get_point(int n) const; - INLINE int get_num_planes() const; - INLINE Planef get_plane(int n) const; - -protected: - virtual bool extend_other(BoundingVolume *other) const; - virtual bool around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const; - virtual int contains_other(const BoundingVolume *other) const; - - - virtual bool extend_by_point(const LPoint3f &point); - virtual bool extend_by_sphere(const BoundingSphere *sphere); - virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron); - - virtual bool around_points(const LPoint3f *first, - const LPoint3f *last); - virtual bool around_spheres(const BoundingVolume **first, - const BoundingVolume **last); - virtual bool around_hexahedrons(const BoundingVolume **first, - const BoundingVolume **last); - - virtual int contains_point(const LPoint3f &point) const; - virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const; - virtual int contains_sphere(const BoundingSphere *sphere) const; - virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const; - -private: - void set_planes(); - void set_centroid(); - -private: - enum { - num_points = 8, - num_planes = 6 - }; - LPoint3f _points[num_points]; - Planef _planes[num_planes]; - LPoint3f _centroid; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - FiniteBoundingVolume::init_type(); - register_type(_type_handle, "BoundingHexahedron", - FiniteBoundingVolume::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class BoundingSphere; -}; - -#include "boundingHexahedron.I" - -#endif diff --git a/panda/src/mathutil/boundingLine.I b/panda/src/mathutil/boundingLine.I deleted file mode 100644 index 9ef228ecc9..0000000000 --- a/panda/src/mathutil/boundingLine.I +++ /dev/null @@ -1,33 +0,0 @@ -// Filename: boundingLine.I -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// - -INLINE BoundingLine:: -BoundingLine() { -} - -INLINE BoundingLine:: -BoundingLine(const LPoint3f &a, const LPoint3f &b) : - _origin(a), _vector(b - a) -{ - _vector.normalize(); - _flags = 0; - nassertd(!_origin.is_nan() && !_vector.is_nan()) { - _flags = F_empty; - } -} - -INLINE const LPoint3f &BoundingLine:: -get_point_a() const { - nassertr(!is_empty(), _origin); - nassertr(!is_infinite(), _origin); - return _origin; -} - -INLINE LPoint3f BoundingLine:: -get_point_b() const { - nassertr(!is_empty(), _origin); - nassertr(!is_infinite(), _origin); - return _origin + _vector; -} diff --git a/panda/src/mathutil/boundingLine.cxx b/panda/src/mathutil/boundingLine.cxx deleted file mode 100644 index ec60fe013b..0000000000 --- a/panda/src/mathutil/boundingLine.cxx +++ /dev/null @@ -1,114 +0,0 @@ -// Filename: boundingLine.cxx -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// - -#include "boundingLine.h" -#include "boundingSphere.h" -#include "config_mathutil.h" - -#include - -TypeHandle BoundingLine::_type_handle; - -BoundingVolume *BoundingLine:: -make_copy() const { - return new BoundingLine(*this); -} - -LPoint3f BoundingLine:: -get_approx_center() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - return (get_point_a() + get_point_b()) / 2.0; -} - -void BoundingLine:: -xform(const LMatrix4f &mat) { - nassertv(!mat.is_nan()); - - if (!is_empty() && !is_infinite()) { - _origin = _origin * mat; - _vector = _vector * mat; - _vector.normalize(); - } -} - -void BoundingLine:: -output(ostream &out) const { - if (is_empty()) { - out << "bline, empty"; - } else if (is_infinite()) { - out << "bline, infinite"; - } else { - out << "bline, (" << _origin << ") - (" << _origin + _vector << ")"; - } -} - -bool BoundingLine:: -extend_other(BoundingVolume *other) const { - return other->extend_by_line(this); -} - -bool BoundingLine:: -around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const { - return other->around_lines(first, last); -} - -int BoundingLine:: -contains_other(const BoundingVolume *other) const { - return other->contains_line(this); -} - - -bool BoundingLine:: -extend_by_line(const BoundingLine *line) { - nassertr(!line->is_empty() && !line->is_infinite(), false); - nassertr(!is_infinite(), false); - - if (is_empty()) { - _origin = line->_origin; - _vector = line->_vector; - _flags = 0; - } else { - _flags = F_infinite; - } - return true; -} - -int BoundingLine:: -contains_sphere(const BoundingSphere *sphere) const { - nassertr(!is_empty() && !is_infinite(), 0); - nassertr(!sphere->is_empty() && !sphere->is_infinite(), 0); - - float r = sphere->get_radius(); - - if (r * r >= sqr_dist_to_line(sphere->get_center())) { - return IF_possible | IF_some; - } else { - return IF_no_intersection; - } -} - -float BoundingLine:: -sqr_dist_to_line(const LPoint3f &point) const { - nassertr(!point.is_nan(), 0.0); - nassertr(!is_empty() && !is_infinite(), 0.0); - nassertr(!_vector.almost_equal(LVector3f(0.0, 0.0, 0.0)), 0.0); - - // The formula for the distance from a point to the line based on - // the quadratic equation. - - float A = dot(_vector, _vector); - nassertr(A != 0.0, 0.0); - LVector3f fc = _origin - point; - float B = 2.0 * dot(_vector, fc); - float fc_d2 = dot(fc, fc); - - float r2 = fc_d2 - B*B / 4.0*A; - - nassertr(!cnan(r2), 0.0); - return r2; -} diff --git a/panda/src/mathutil/boundingLine.h b/panda/src/mathutil/boundingLine.h deleted file mode 100644 index 46d409e3e5..0000000000 --- a/panda/src/mathutil/boundingLine.h +++ /dev/null @@ -1,81 +0,0 @@ -// Filename: boundingLine.h -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef BOUNDINGLINE_H -#define BOUNDINGLINE_H - -#include - -#include "geometricBoundingVolume.h" - -/////////////////////////////////////////////////////////////////// -// Class : BoundingLine -// Description : This funny bounding volume is an infinite line with -// no thickness and extending to infinity in both -// directions. -// -// Note that it *always* extends in both directions, -// despite the fact that you specify two points to the -// constructor. These are not endpoints, they are two -// arbitrary points on the line. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA BoundingLine : public GeometricBoundingVolume { -PUBLISHED: - INLINE BoundingLine(); - INLINE BoundingLine(const LPoint3f &a, const LPoint3f &b); - -public: - virtual BoundingVolume *make_copy() const; - - virtual LPoint3f get_approx_center() const; - virtual void xform(const LMatrix4f &mat); - - virtual void output(ostream &out) const; - -PUBLISHED: - INLINE const LPoint3f &get_point_a() const; - INLINE LPoint3f get_point_b() const; - -protected: - virtual bool extend_other(BoundingVolume *other) const; - virtual bool around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const; - virtual int contains_other(const BoundingVolume *other) const; - - virtual bool extend_by_line(const BoundingLine *line); - - virtual int contains_sphere(const BoundingSphere *sphere) const; - - float sqr_dist_to_line(const LPoint3f &point) const; - -private: - LPoint3f _origin; - LVector3f _vector; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeometricBoundingVolume::init_type(); - register_type(_type_handle, "BoundingLine", - GeometricBoundingVolume::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class BoundingSphere; -}; - -#include "boundingLine.I" - -#endif diff --git a/panda/src/mathutil/boundingSphere.I b/panda/src/mathutil/boundingSphere.I deleted file mode 100644 index 40a20580b5..0000000000 --- a/panda/src/mathutil/boundingSphere.I +++ /dev/null @@ -1,33 +0,0 @@ -// Filename: boundingSphere.I -// Created by: drose (02Oct99) -// -//////////////////////////////////////////////////////////////////// - -INLINE BoundingSphere:: -BoundingSphere() { -} - -INLINE BoundingSphere:: -BoundingSphere(const LPoint3f ¢er, float radius) : - _center(center), _radius(radius) -{ - _flags = 0; - nassertd(!_center.is_nan() && !cnan(_radius)) { - _flags = F_empty; - } -} - -INLINE const LPoint3f &BoundingSphere:: -get_center() const { - nassertr(!is_empty(), _center); - nassertr(!is_infinite(), _center); - return _center; -} - -INLINE float BoundingSphere:: -get_radius() const { - nassertr(!is_empty(), 0.0); - nassertr(!is_infinite(), 0.0); - return _radius; -} - diff --git a/panda/src/mathutil/boundingSphere.cxx b/panda/src/mathutil/boundingSphere.cxx deleted file mode 100644 index 7089cf57de..0000000000 --- a/panda/src/mathutil/boundingSphere.cxx +++ /dev/null @@ -1,455 +0,0 @@ -// Filename: boundingSphere.cxx -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -#include "boundingSphere.h" -#include "boundingHexahedron.h" -#include "boundingLine.h" -#include "config_mathutil.h" - -#include -#include - -TypeHandle BoundingSphere::_type_handle; - -BoundingVolume *BoundingSphere:: -make_copy() const { - return new BoundingSphere(*this); -} - -LPoint3f BoundingSphere:: -get_min() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - return LPoint3f(_center[0] - _radius, - _center[1] - _radius, - _center[2] - _radius); -} - -LPoint3f BoundingSphere:: -get_max() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - return LPoint3f(_center[0] + _radius, - _center[1] + _radius, - _center[2] + _radius); -} - -LPoint3f BoundingSphere:: -get_approx_center() const { - nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0)); - return get_center(); -} - -void BoundingSphere:: -xform(const LMatrix4f &mat) { - nassertv(!mat.is_nan()); - - if (!is_empty() && !is_infinite()) { - // First, determine the longest axis of the matrix, in case it - // contains a non-proportionate scale. - LVector3f x = mat.get_row3(0); - LVector3f y = mat.get_row3(1); - LVector3f z = mat.get_row3(2); - float xd = dot(x, x); - float yd = dot(y, y); - float zd = dot(z, z); - - float scale; - if (xd < yd) { - if (yd < zd) { - scale = sqrtf(zd); - } else { - scale = sqrtf(yd); - } - } else { - if (xd < zd) { - scale = sqrtf(zd); - } else { - scale = sqrtf(xd); - } - } - - // Transform the center - _center = _center * mat; - - // And the radius. - _radius *= scale; - } -} - -void BoundingSphere:: -output(ostream &out) const { - if (is_empty()) { - out << "bsphere, empty"; - } else if (is_infinite()) { - out << "bsphere, infinite"; - } else { - out << "bsphere, c (" << _center << "), r " << _radius; - } -} - -bool BoundingSphere:: -extend_other(BoundingVolume *other) const { - return other->extend_by_sphere(this); -} - -bool BoundingSphere:: -around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const { - return other->around_spheres(first, last); -} - -int BoundingSphere:: -contains_other(const BoundingVolume *other) const { - return other->contains_sphere(this); -} - - -bool BoundingSphere:: -extend_by_point(const LPoint3f &point) { - nassertr(!point.is_nan(), false); - - if (is_empty()) { - _center = point; - _radius = 0.0; - _flags = 0; - } else if (!is_infinite()) { - LVector3f v = point - _center; - float dist2 = dot(v, v); - if (dist2 > _radius * _radius) { - _radius = sqrtf(dist2); - } - } - return true; -} - -bool BoundingSphere:: -extend_by_sphere(const BoundingSphere *sphere) { - nassertr(!sphere->is_empty() && !sphere->is_infinite(), false); - nassertr(!is_infinite(), false); - - if (is_empty()) { - _center = sphere->_center; - _radius = sphere->_radius; - _flags = 0; - } else { - float dist = length(sphere->_center - _center); - - _radius = max(_radius, dist + sphere->_radius); - } - return true; -} - -bool BoundingSphere:: -extend_by_hexahedron(const BoundingHexahedron *hexahedron) { - return extend_by_finite(hexahedron); -} - -bool BoundingSphere:: -extend_by_finite(const FiniteBoundingVolume *volume) { - nassertr(!volume->is_empty(), false); - - LVector3f min1 = volume->get_min(); - LVector3f max1 = volume->get_max(); - - if (is_empty()) { - _center = (min1 + max1) * 0.5; - _radius = length(LVector3f(max1 - _center)); - _flags = 0; - } else { - LVector3f v = max1 - _center; - float dist2 = dot(v, v); - - if (dist2 > _radius * _radius) { - _radius = sqrtf(dist2); - } - } - - return true; -} - -bool BoundingSphere:: -around_points(const LPoint3f *first, const LPoint3f *last) { - nassertr(first != last, false); - - // First, get the minmax of all the points to construct a bounding - // box. - const LPoint3f *p = first; - -#ifndef NDEBUG - // Skip any NaN points. - int skipped_nan = 0; - while (p != last && (*p).is_nan()) { - ++p; - ++skipped_nan; - } - if (p == last) { - mathutil_cat.warning() - << "BoundingSphere around NaN\n"; - return false; - } -#endif - - LPoint3f min_box = *p; - LPoint3f max_box = *p; - ++p; - -#ifndef NDEBUG - // Skip more NaN points. - while (p != last && (*p).is_nan()) { - ++p; - ++skipped_nan; - } -#endif - - if (p == last) { - // Only one point; we have a radius of zero. This is not the same - // thing as an empty sphere, because our volume contains one - // point; an empty sphere contains no points. - _center = min_box; - _radius = 0.0; - - } else { - // More than one point; we have a nonzero radius. - while (p != last) { -#ifndef NDEBUG - // Skip more NaN points. - if ((*p).is_nan()) { - ++skipped_nan; - } else -#endif - { - min_box.set(min(min_box[0], (*p)[0]), - min(min_box[1], (*p)[1]), - min(min_box[2], (*p)[2])); - max_box.set(max(max_box[0], (*p)[0]), - max(max_box[1], (*p)[1]), - max(max_box[2], (*p)[2])); - } - ++p; - } - - // Now take the center of the bounding box as the center of the sphere. - _center = (min_box + max_box) / 2.0; - - // Now walk back through to get the max distance from center. - float max_dist2 = 0.0; - for (p = first; p != last; ++p) { - LVector3f v = (*p) - _center; - float dist2 = dot(v, v); - max_dist2 = max(max_dist2, dist2); - } - - _radius = sqrtf(max_dist2); - } - -#ifndef NDEBUG - if (skipped_nan != 0) { - mathutil_cat.warning() - << "BoundingSphere ignored " << skipped_nan << " NaN points of " - << (last - first) << " total.\n"; - } -#endif - - _flags = 0; - - return true; -} - -bool BoundingSphere:: -around_spheres(const BoundingVolume **first, - const BoundingVolume **last) { - return around_finite(first, last); -} - -bool BoundingSphere:: -around_hexahedrons(const BoundingVolume **first, - const BoundingVolume **last) { - return around_finite(first, last); -} - -bool BoundingSphere:: -around_finite(const BoundingVolume **first, - const BoundingVolume **last) { - nassertr(first != last, false); - - // We're given a set of bounding volumes, at least the first one of - // which is guaranteed to be finite and nonempty. Some others may - // not be. - - // First, get the minmax of all the points to construct a bounding - // box. - const BoundingVolume **p = first; - nassertr(!(*p)->is_empty() && !(*p)->is_infinite(), false); - nassertr((*p)->is_of_type(FiniteBoundingVolume::get_class_type()), false); - const FiniteBoundingVolume *vol = DCAST(FiniteBoundingVolume, *p); - LPoint3f min_box = vol->get_min(); - LPoint3f max_box = vol->get_max(); - - bool any_unknown = false; - - for (++p; p != last; ++p) { - nassertr(!(*p)->is_infinite(), false); - if (!(*p)->is_empty() && - (*p)->is_of_type(FiniteBoundingVolume::get_class_type())) { - const FiniteBoundingVolume *vol = DCAST(FiniteBoundingVolume, *p); - LPoint3f min1 = vol->get_min(); - LPoint3f max1 = vol->get_max(); - min_box.set(min(min_box[0], min1[0]), - min(min_box[1], min1[1]), - min(min_box[2], min1[2])); - max_box.set(max(max_box[0], max1[0]), - max(max_box[1], max1[1]), - max(max_box[2], max1[2])); - - if (!(*p)->is_of_type(BoundingSphere::get_class_type())) { - any_unknown = true; - } - } - } - - // Now take the center of the bounding box as the center of the sphere. - _center = (min_box + max_box) * 0.5; - - if (any_unknown) { - // If we have any volumes in the list that we don't know what to - // do with, we'll have to make the bounding sphere large enough to - // enclose the bounding box. Less than ideal, but too bad. - _radius = length(max_box - _center); - - } else { - // Otherwise, we do understand all the volumes in the list; make - // the sphere as tight as we can. - _radius = 0.0; - for (p = first; p != last; ++p) { - if (!(*p)->is_empty()) { - if ((*p)->is_of_type(BoundingSphere::get_class_type())) { - const BoundingSphere *sphere = DCAST(BoundingSphere, *p); - float dist = length(sphere->_center - _center); - _radius = max(_radius, dist + sphere->_radius); - } else { - // Shouldn't get here, unless we missed a type from above. - mathutil_cat.error() - << "Unexpected type in BoundingSphere::around_finite()\n"; - nassertr(false, false); - } - } - } - } - - _flags = 0; - return true; -} - -int BoundingSphere:: -contains_point(const LPoint3f &point) const { - nassertr(!point.is_nan(), IF_no_intersection); - - if (is_empty()) { - return IF_no_intersection; - - } else if (is_infinite()) { - return IF_possible | IF_some | IF_all; - - } else { - LVector3f v = point - _center; - float dist2 = dot(v, v); - return (dist2 <= _radius * _radius) ? - IF_possible | IF_some | IF_all : IF_no_intersection; - } -} - -int BoundingSphere:: -contains_lineseg(const LPoint3f &a, const LPoint3f &b) const { - nassertr(!a.is_nan() && !b.is_nan(), IF_no_intersection); - - if (a == b) { - return contains_point(a); - } - if (is_empty()) { - return IF_no_intersection; - - } else if (is_infinite()) { - return IF_possible | IF_some | IF_all; - - } else { - LPoint3f from = a; - LVector3f delta = b - a; - float t1, t2; - - // Solve the equation for the intersection of a line with a sphere - // using the quadratic equation. - float A = dot(delta, delta); - - nassertr(A != 0.0, 0); // Trivial line segment. - - LVector3f fc = from - _center; - float B = 2.0 * dot(delta, fc); - float C = dot(fc, fc) - _radius * _radius; - - float radical = B*B - 4.0*A*C; - - if (IS_NEARLY_ZERO(radical)) { - // Tangent. - t1 = t2 = -B / (2.0*A); - return (t1 >= 0.0 && t1 <= 1.0) ? - IF_possible | IF_some : IF_no_intersection; - } - - if (radical < 0.0) { - // No real roots: no intersection with the line. - return IF_no_intersection; - } - - float reciprocal_2A = 1.0f/(2.0*A); - float sqrt_radical = sqrtf(radical); - - t1 = ( -B - sqrt_radical ) * reciprocal_2A; - t2 = ( -B + sqrt_radical ) * reciprocal_2A; - - if (t1 >= 0.0 && t2 <= 1.0) { - return IF_possible | IF_some | IF_all; - } else if (t1 <= 1.0 && t2 >= 0.0) { - return IF_possible | IF_some; - } else { - return IF_no_intersection; - } - } -} - -int BoundingSphere:: -contains_sphere(const BoundingSphere *sphere) const { - nassertr(!is_empty() && !is_infinite(), 0); - nassertr(!sphere->is_empty() && !sphere->is_infinite(), 0); - - LVector3f v = sphere->_center - _center; - float dist2 = dot(v, v); - - if (_radius >= sphere->_radius && - dist2 <= (_radius - sphere->_radius) * (_radius - sphere->_radius)) { - // The other sphere is completely within this sphere. - return IF_possible | IF_some | IF_all; - - } else if (dist2 > (_radius + sphere->_radius) * (_radius + sphere->_radius)) { - // The other sphere is completely outside this sphere. - return IF_no_intersection; - - } else { - // The other sphere is partially within this sphere. - return IF_possible | IF_some; - } -} - -int BoundingSphere:: -contains_hexahedron(const BoundingHexahedron *hexahedron) const { - return hexahedron->contains_sphere(this) & ~IF_all; -} - -int BoundingSphere:: -contains_line(const BoundingLine *line) const { - return line->contains_sphere(this) & ~IF_all; -} diff --git a/panda/src/mathutil/boundingSphere.h b/panda/src/mathutil/boundingSphere.h deleted file mode 100644 index b9fe6be1b3..0000000000 --- a/panda/src/mathutil/boundingSphere.h +++ /dev/null @@ -1,94 +0,0 @@ -// Filename: boundingSphere.h -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef BOUNDINGSPHERE_H -#define BOUNDINGSPHERE_H - -#include - -#include "finiteBoundingVolume.h" - -/////////////////////////////////////////////////////////////////// -// Class : BoundingSphere -// Description : This defines a bounding sphere, consisting of a -// center and a radius. It is always a sphere, and -// never an ellipsoid or other quadric. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA BoundingSphere : public FiniteBoundingVolume { -PUBLISHED: - INLINE BoundingSphere(); - INLINE BoundingSphere(const LPoint3f ¢er, float radius); - -public: - virtual BoundingVolume *make_copy() const; - - virtual LPoint3f get_min() const; - virtual LPoint3f get_max() const; - - virtual LPoint3f get_approx_center() const; - virtual void xform(const LMatrix4f &mat); - - virtual void output(ostream &out) const; - -PUBLISHED: - INLINE const LPoint3f &get_center() const; - INLINE float get_radius() const; - -protected: - virtual bool extend_other(BoundingVolume *other) const; - virtual bool around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const; - virtual int contains_other(const BoundingVolume *other) const; - - - virtual bool extend_by_point(const LPoint3f &point); - virtual bool extend_by_sphere(const BoundingSphere *sphere); - virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron); - bool extend_by_finite(const FiniteBoundingVolume *volume); - - virtual bool around_points(const LPoint3f *first, - const LPoint3f *last); - virtual bool around_spheres(const BoundingVolume **first, - const BoundingVolume **last); - virtual bool around_hexahedrons(const BoundingVolume **first, - const BoundingVolume **last); - bool around_finite(const BoundingVolume **first, - const BoundingVolume **last); - - virtual int contains_point(const LPoint3f &point) const; - virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const; - virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const; - virtual int contains_sphere(const BoundingSphere *sphere) const; - virtual int contains_line(const BoundingLine *line) const; - -private: - LPoint3f _center; - float _radius; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - FiniteBoundingVolume::init_type(); - register_type(_type_handle, "BoundingSphere", - FiniteBoundingVolume::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class BoundingHexahedron; -}; - -#include "boundingSphere.I" - -#endif diff --git a/panda/src/mathutil/boundingVolume.I b/panda/src/mathutil/boundingVolume.I deleted file mode 100644 index 9f6a497184..0000000000 --- a/panda/src/mathutil/boundingVolume.I +++ /dev/null @@ -1,112 +0,0 @@ -// Filename: boundingVolume.I -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE BoundingVolume:: -BoundingVolume() { - _flags = F_empty; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::is_empty -// Access: Public -// Description: Any kind of volume might be empty. This is a -// degenerate volume that contains no points; it's not -// the same as, for instance, a sphere with radius zero, -// since that contains one point (the center). It -// intersects with no other volumes. -//////////////////////////////////////////////////////////////////// -INLINE bool BoundingVolume:: -is_empty() const { - return (_flags & F_empty) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::is_infinite -// Access: Public -// Description: The other side of the empty coin is an infinite -// volume. This is a degenerate state of a normally -// finite volume that contains all points. (Note that -// some kinds of infinite bounding volumes, like binary -// separating planes, do not contain all points and thus -// correctly return is_infinite() == false, even though -// they are technically infinite. This is a special -// case of the word 'infinite' meaning the volume covers -// all points in space.) -// -// It completely intersects with all other volumes -// except empty volumes. -//////////////////////////////////////////////////////////////////// -INLINE bool BoundingVolume:: -is_infinite() const { - return (_flags & F_infinite) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::set_infinite -// Access: Public -// Description: Marks the volume as infinite, even if it is normally -// finite. You can think of this as an infinite -// extend_by() operation. -//////////////////////////////////////////////////////////////////// -INLINE void BoundingVolume:: -set_infinite() { - _flags = F_infinite; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::extend_by -// Access: Public -// Description: Increases the size of the volume to include the given -// volume. -//////////////////////////////////////////////////////////////////// -INLINE bool BoundingVolume:: -extend_by(const BoundingVolume *vol) { - if (vol->is_infinite()) { - set_infinite(); - - } else if (!vol->is_empty()) { - // This is a double-dispatch. We call this virtual function on the - // volume we were given, which will in turn call the appropriate - // virtual function in our own class to perform the operation. - return vol->extend_other(this); - } - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::contains -// Access: Public -// Description: Returns the appropriate set of IntersectionFlags to -// indicate the amount of intersection with the -// indicated volume. -//////////////////////////////////////////////////////////////////// -INLINE int BoundingVolume:: -contains(const BoundingVolume *vol) const { - if (is_empty() || vol->is_empty()) { - return IF_no_intersection; - - } else if (is_infinite()) { - return IF_possible | IF_some | IF_all; - - } else if (vol->is_infinite()) { - return IF_possible | IF_some; - } - - // This is a double-dispatch. We call this virtual function on the - // volume we were given, which will in turn call the appropriate - // virtual function in our own class to perform the operation. - return vol->contains_other(this); -} - -INLINE ostream &operator << (ostream &out, const BoundingVolume &bound) { - bound.output(out); - return out; -} diff --git a/panda/src/mathutil/boundingVolume.cxx b/panda/src/mathutil/boundingVolume.cxx deleted file mode 100644 index a32f14acda..0000000000 --- a/panda/src/mathutil/boundingVolume.cxx +++ /dev/null @@ -1,191 +0,0 @@ -// Filename: boundingVolume.cxx -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -#include "boundingVolume.h" -#include "finiteBoundingVolume.h" - -#include - -TypeHandle BoundingVolume::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::around -// Access: Public -// Description: Resets the volume to enclose only the volumes -// indicated. Returns true if successful, false if the -// volume doesn't know how to do that or can't do that. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -around(const BoundingVolume **first, const BoundingVolume **last) { - _flags = F_empty; - - // Skip any empty volumes at the beginning of the list. We want to - // get to the first real volume. - while (first != last && (*first)->is_empty()) { - if ((*first)->is_infinite()) { - // If we go around an infinite volume, we're infinite too. - _flags = F_infinite; - return true; - } - ++first; - } - - bool okflag = true; - - if (first != last) { - // Check for more infinite bounding volumes in the list. - const BoundingVolume **bvi; - for (bvi = first; bvi != last; ++bvi) { - if ((*bvi)->is_infinite()) { - _flags = F_infinite; - return true; - } - } - - // This is a double-dispatch. We call this virtual function on - // the volume we were given, which will in turn call the - // appropriate virtual function in our own class to perform the - // operation. - if (!(*first)->around_other(this, first, last)) { - okflag = false; - } - } - - return okflag; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void BoundingVolume:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << *this << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::extend_by_sphere -// Access: Protected, Virtual -// Description: Double-dispatch support: called by extend_other() -// when the type we're extending by is known to be a -// sphere. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -extend_by_sphere(const BoundingSphere *) { - _flags = F_infinite; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::extend_by_hexahedron -// Access: Protected, Virtual -// Description: Double-dispatch support: called by extend_other() -// when the type we're extending by is known to be a -// hexahedron. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -extend_by_hexahedron(const BoundingHexahedron *) { - _flags = F_infinite; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::extend_by_line -// Access: Protected, Virtual -// Description: Double-dispatch support: called by extend_other() -// when the type we're extending by is known to be a -// line. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -extend_by_line(const BoundingLine *) { - _flags = F_infinite; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::around_spheres -// Access: Protected, Virtual -// Description: Double-dispatch support: called by around_other() -// when the type of the first element in the list is -// known to be a nonempty sphere. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -around_spheres(const BoundingVolume **, const BoundingVolume **) { - _flags = F_infinite; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::around_hexahedrons -// Access: Protected, Virtual -// Description: Double-dispatch support: called by around_other() -// when the type of the first element in the list is -// known to be a nonempty hexahedron. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -around_hexahedrons(const BoundingVolume **, const BoundingVolume **) { - _flags = F_infinite; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::around_lines -// Access: Protected, Virtual -// Description: Double-dispatch support: called by around_other() -// when the type of the first element in the list is -// known to be a nonempty line. -//////////////////////////////////////////////////////////////////// -bool BoundingVolume:: -around_lines(const BoundingVolume **, const BoundingVolume **) { - _flags = F_infinite; - if (is_of_type(FiniteBoundingVolume::get_class_type())) { - // If it's a FiniteBoundingVolume, we can't do any better than - // making it infinite. So we return true. - return true; - } - - // Otherwise, we might do better, and we require each class to - // define a function. If we get here, the function isn't defined, - // so we return false to indicate this. - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::contains_sphere -// Access: Protected, Virtual -// Description: Double-dispatch support: called by contains_other() -// when the type we're testing for intersection is known -// to be a sphere. -//////////////////////////////////////////////////////////////////// -int BoundingVolume:: -contains_sphere(const BoundingSphere *) const { - return IF_dont_understand; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::contains_hexahedron -// Access: Protected, Virtual -// Description: Double-dispatch support: called by contains_other() -// when the type we're testing for intersection is known -// to be a hexahedron. -//////////////////////////////////////////////////////////////////// -int BoundingVolume:: -contains_hexahedron(const BoundingHexahedron *) const { - return IF_dont_understand; -} - -//////////////////////////////////////////////////////////////////// -// Function: BoundingVolume::contains_line -// Access: Protected, Virtual -// Description: Double-dispatch support: called by contains_other() -// when the type we're testing for intersection is known -// to be a line. -//////////////////////////////////////////////////////////////////// -int BoundingVolume:: -contains_line(const BoundingLine *) const { - return IF_dont_understand; -} diff --git a/panda/src/mathutil/boundingVolume.h b/panda/src/mathutil/boundingVolume.h deleted file mode 100644 index 8291ac6d37..0000000000 --- a/panda/src/mathutil/boundingVolume.h +++ /dev/null @@ -1,147 +0,0 @@ -// Filename: boundingVolume.h -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef BOUNDINGVOLUME_H -#define BOUNDINGVOLUME_H - -#include - -#include -#include - -class BoundingSphere; -class BoundingHexahedron; -class BoundingLine; - - -/////////////////////////////////////////////////////////////////// -// Class : BoundingVolume -// Description : This is an abstract class for any volume in any sense -// which can be said to define the locality of reference -// of a node in a graph, along with all of its -// descendants. It is not necessarily a geometric -// volume (although see GeometricBoundingVolume); this -// is simply an abstract interface for bounds of any -// sort. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA BoundingVolume : public TypedReferenceCount { -PUBLISHED: - INLINE BoundingVolume(); - virtual BoundingVolume *make_copy() const=0; - - INLINE bool is_empty() const; - INLINE bool is_infinite() const; - - INLINE void set_infinite(); - - INLINE bool extend_by(const BoundingVolume *vol); - - // It might be nice to make these template member functions so we - // could have true STL-style first/last iterators, but that's - // impossible for virtual functions. - bool around(const BoundingVolume **first, - const BoundingVolume **last); - - // The contains() functions return the union of one or more of these - // bits. - enum IntersectionFlags { - // If no bits are set, it is known that there is no intersection. - IF_no_intersection = 0, - - // IF_possible is set if there might be an intersection. - IF_possible = 0x01, - - // IF_some is set if there is definitely an intersection. In this - // case, IF_possible will also be set. - IF_some = 0x02, - - // IF_all is set if the other bounding volume is known to be - // completely within this bounding volume: that is, there is no - // part of the other bounding volume that does not intersect this - // one. It does *not* indicate the inverse; it is possible that - // some part of this bounding volume does not intersect the other. - - // Also, the converse is not implied: if IF_all is not set, you - // simply don't know whether the other volume is completely - // contained within this one or not. - - // When IF_all is set, both IF_possible and IF_some will also be - // set. - IF_all = 0x04, - - // IF_dont_understand is set if the particular volume/volume - // intersection test has not been implemented. - IF_dont_understand = 0x08 - }; - - INLINE int contains(const BoundingVolume *vol) const; - - virtual void output(ostream &out) const=0; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - enum Flags { - F_empty = 0x01, - F_infinite = 0x02 - }; - int _flags; - -protected: - // The following functions support double-dispatch of virtual - // methods, so we can easily extend_by() various types of bounding - // volumes. - - // These functions are the first dispatch point. - virtual bool extend_other(BoundingVolume *other) const=0; - virtual bool around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const=0; - virtual int contains_other(const BoundingVolume *other) const=0; - - // These functions are the second dispatch point. They actually do - // the work. - virtual bool extend_by_sphere(const BoundingSphere *sphere); - virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron); - virtual bool extend_by_line(const BoundingLine *line); - - virtual bool around_spheres(const BoundingVolume **first, - const BoundingVolume **last); - virtual bool around_hexahedrons(const BoundingVolume **first, - const BoundingVolume **last); - virtual bool around_lines(const BoundingVolume **first, - const BoundingVolume **last); - - virtual int contains_sphere(const BoundingSphere *sphere) const; - virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const; - virtual int contains_line(const BoundingLine *line) const; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "BoundingVolume", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class BoundingSphere; - friend class BoundingHexahedron; - friend class BoundingLine; -}; - -INLINE ostream &operator << (ostream &out, const BoundingVolume &bound); - -#include "boundingVolume.I" - -#endif diff --git a/panda/src/mathutil/config_mathutil.cxx b/panda/src/mathutil/config_mathutil.cxx deleted file mode 100644 index 407a92178b..0000000000 --- a/panda/src/mathutil/config_mathutil.cxx +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: config_mathutil.cxx -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -#include "config_mathutil.h" -#include "boundingVolume.h" -#include "geometricBoundingVolume.h" -#include "finiteBoundingVolume.h" -#include "omniBoundingVolume.h" -#include "boundingSphere.h" -#include "boundingHexahedron.h" -#include "boundingLine.h" -#include - -Configure(config_mathutil); -NotifyCategoryDef(mathutil, ""); - -const double fft_offset = config_mathutil.GetDouble("fft-offset", 0.001); -const double fft_factor = config_mathutil.GetDouble("fft-factor", 0.1); -const double fft_exponent = config_mathutil.GetDouble("fft-exponent", 4); - -ConfigureFn(config_mathutil) { - BoundingHexahedron::init_type(); - BoundingSphere::init_type(); - BoundingVolume::init_type(); - FiniteBoundingVolume::init_type(); - GeometricBoundingVolume::init_type(); - OmniBoundingVolume::init_type(); - BoundingLine::init_type(); -} - diff --git a/panda/src/mathutil/config_mathutil.h b/panda/src/mathutil/config_mathutil.h deleted file mode 100644 index 80b4b77ebf..0000000000 --- a/panda/src/mathutil/config_mathutil.h +++ /dev/null @@ -1,20 +0,0 @@ -// Filename: config_mathutil.h -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_MATHUTIL_H -#define CONFIG_MATHUTIL_H - -#include -#include - -NotifyCategoryDecl(mathutil, EXPCL_PANDA, EXPTP_PANDA); - -extern const double fft_offset; -extern const double fft_factor; -extern const double fft_exponent; - -#endif - - diff --git a/panda/src/mathutil/fftCompressor.cxx b/panda/src/mathutil/fftCompressor.cxx deleted file mode 100644 index 0755ad5759..0000000000 --- a/panda/src/mathutil/fftCompressor.cxx +++ /dev/null @@ -1,849 +0,0 @@ -// Filename: fftCompressor.cxx -// Created by: drose (11Dec00) -// -//////////////////////////////////////////////////////////////////// - -#include "fftCompressor.h" -#include "config_mathutil.h" - -#include -#include -#include -#include - -#ifdef HAVE_FFTW - -#include - -// These FFTW support objects can only be defined if we actually have -// the FFTW library available. -static rfftw_plan get_real_compress_plan(int length); -static rfftw_plan get_real_decompress_plan(int length); - -typedef map RealPlans; -static RealPlans _real_compress_plans; -static RealPlans _real_decompress_plans; - -#endif - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::Constructor -// Access: Public -// Description: Constructs a new compressor object with default -// parameters. -//////////////////////////////////////////////////////////////////// -FFTCompressor:: -FFTCompressor() { - set_quality(-1); -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::is_compression_available -// Access: Public, Static -// Description: Returns true if the FFTW library is compiled in, so -// that this class is actually capable of doing useful -// compression/decompression work. Returns false -// otherwise, in which case any attempt to write a -// compressed stream will actually write an uncompressed -// stream, and any attempt to read a compressed stream -// will fail. -//////////////////////////////////////////////////////////////////// -bool FFTCompressor:: -is_compression_available() { -#ifndef HAVE_FFTW - return false; -#else - return true; -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::set_quality -// Access: Public -// Description: Sets the quality factor for the compression. This is -// an integer in the range 0 - 100 that roughly controls -// how aggressively the reals are compressed; lower -// numbers mean smaller output, and more data loss. -// -// There are a few special cases. Quality -1 means to -// use whatever individual parameters are set in the -// user's Configrc file, rather than the single quality -// dial. Quality 101 or higher means to generate -// lossless output (this is the default if libfftw is -// not available). Quality 102 writes all four -// components of quaternions to the output file, rather -// than just three, and quality 103 doesn't even convert -// hpr to quat. -//////////////////////////////////////////////////////////////////// -void FFTCompressor:: -set_quality(int quality) { -#ifndef HAVE_FFTW - // If we don't actually have FFTW, we can't really compress anything. - if (_quality <= 100) { - mathutil_cat.warning() - << "FFTW library is not available; generating uncompressed output.\n"; - } - _quality = 101; - -#else - _quality = quality; - - if (_quality < 0) { - // A negative quality indicates we should read the various - // parameters from individual config variables. - _fft_offset = fft_offset; - _fft_factor = fft_factor; - _fft_exponent = fft_exponent; - - } else if (_quality < 40) { - // 0 - 40 : - // fft-offset 1.0 - 0.001 - // fft-factor 1.0 - // fft-exponent 4.0 - - double t = (double)_quality / 40.0; - _fft_offset = interpolate(t, 1.0, 0.001); - _fft_factor = 1.0; - _fft_exponent = 4.0; - - } else if (_quality < 95) { - // 40 - 95: - // fft-offset 0.001 - // fft-factor 1.0 - 0.1 - // fft-exponent 4.0 - - double t = (double)(_quality - 40) / 55.0; - _fft_offset = 0.001; - _fft_factor = interpolate(t, 1.0, 0.1); - _fft_exponent = 4.0; - - } else { - // 95 - 100: - // fft-offset 0.001 - // fft-factor 0.1 - 0.0 - // fft-exponent 4.0 - - double t = (double)(_quality - 95) / 5.0; - _fft_offset = 0.001; - _fft_factor = interpolate(t, 0.1, 0.0); - _fft_exponent = 4.0; - } -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::get_quality -// Access: Public -// Description: Returns the quality number that was previously set -// via set_quality(). -//////////////////////////////////////////////////////////////////// -int FFTCompressor:: -get_quality() const { - return _quality; -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::write_header -// Access: Public -// Description: Writes the compression parameters to the indicated -// datagram. It is necessary to call this before -// writing anything else to the datagram, since these -// parameters will be necessary to correctly decompress -// the data later. -//////////////////////////////////////////////////////////////////// -void FFTCompressor:: -write_header(Datagram &datagram) { - datagram.add_int8(_quality); - if (_quality < 0) { - datagram.add_float64(_fft_offset); - datagram.add_float64(_fft_factor); - datagram.add_float64(_fft_exponent); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::write_reals -// Access: Public -// Description: Writes an array of floating-point numbers to the -// indicated datagram. -//////////////////////////////////////////////////////////////////// -void FFTCompressor:: -write_reals(Datagram &datagram, const float *array, int length) { - datagram.add_int32(length); - - if (_quality > 100) { - // Special case: lossless output. - for (int i = 0; i < length; i++) { - datagram.add_float32(array[i]); - } - return; - } - -#ifndef HAVE_FFTW - // If we don't have FFTW, we shouldn't get here. - nassertv(false); - -#else - - if (length == 0) { - // Special case: do nothing. - return; - } - - if (length == 1) { - // Special case: just write out the one number. - datagram.add_float32(array[0]); - return; - } - - // Normal case: FFT the array, and write that out. - double *data = (double *)alloca(length * sizeof(double)); - int i; - for (i = 0; i < length; i++) { - data[i] = array[i]; - } - - double *half_complex = (double *)alloca(length * sizeof(double)); - - rfftw_plan plan = get_real_compress_plan(length); - rfftw_one(plan, data, half_complex); - - // Now encode the numbers, run-length encoded by size, so we only - // write out the number of bits we need for each number. - - vector_double run; - RunWidth run_width = RW_invalid; - int num_written = 0; - - for (i = 0; i < length; i++) { - static const double max_range_32 = 2147483647.0; - static const double max_range_16 = 32767.0; - static const double max_range_8 = 127.0; - - double scale_factor = get_scale_factor(i, length); - double num = floor(half_complex[i] / scale_factor + 0.5); - - // How many bits do we need to encode this integer? - double a = fabs(num); - RunWidth num_width; - - if (a == 0.0) { - num_width = RW_0; - - } else if (a <= max_range_8) { - num_width = RW_8; - - } else if (a <= max_range_16) { - num_width = RW_16; - - } else if (a <= max_range_32) { - num_width = RW_32; - - } else { - num_width = RW_double; - } - - // A special case: if we're writing a string of one-byters and we - // come across a single intervening zero, don't interrupt the run - // just for that. - if (run_width == RW_8 && num_width == RW_0) { - if (i + 1 >= length || half_complex[i + 1] != 0.0) { - num_width = RW_8; - } - } - - if (num_width != run_width) { - // Now we need to flush the last run. - num_written += write_run(datagram, run_width, run); - run.clear(); - run_width = num_width; - } - - run.push_back(num); - } - - num_written += write_run(datagram, run_width, run); - nassertv(num_written == length); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::write_hprs -// Access: Public -// Description: Writes an array of HPR angles to the indicated -// datagram. -//////////////////////////////////////////////////////////////////// -void FFTCompressor:: -write_hprs(Datagram &datagram, const LVecBase3f *array, int length) { - if (_quality >= 103) { - // If quality level is at least 103, we don't even convert hpr to - // quat. - vector_float h, p, r; - for (int i = 0; i < length; i++) { - h.push_back(array[i][0]); - p.push_back(array[i][1]); - r.push_back(array[i][2]); - } - - write_reals(datagram, &h[0], length); - write_reals(datagram, &p[0], length); - write_reals(datagram, &r[0], length); - return; - } - - // First, convert the HPR's to quats. We expect quats to have - // better FFT consistency, and therefore compress better, even - // though they have an extra component. - - // However, because the quaternion will be normalized, we don't even - // have to write out all three components; any three can be used to - // determine the fourth (provided we ensure consistency of sign). - - vector_float qr, qi, qj, qk; - - for (int i = 0; i < length; i++) { - LMatrix3f mat; - compose_matrix(mat, LVecBase3f(1.0, 1.0, 1.0), array[i]); - - LOrientationf rot; - rot.set(mat); - rot.normalize(); - - if (rot.get_r() < 0) { - // Since rot == -rot, we can flip the quarternion if need be to - // keep the r component positive. This has two advantages. - // One, it makes it possible to infer r completely given i, j, - // and k (since we know it must be >= 0), and two, it helps - // protect against poor continuity caused by inadvertent - // flipping of the quarternion's sign between frames. - - // The choice of leaving r implicit rather than any of the other - // three seems to work the best in terms of guaranteeing - // continuity. - rot.set(-rot.get_r(), -rot.get_i(), -rot.get_j(), -rot.get_k()); - } - - // This is a debug severity, and not a warning or error, because - // (a) some small errors in hpr are usually acceptable, and (b) - // sometimes two different hpr trios actually represent the same - // rotation, e.g. (180, 0, -180) vs. (0, 0, 0). - if (mathutil_cat.is_debug()) { - LMatrix3f mat2; - rot.extract_to_matrix(mat2); - LVecBase3f scale, hpr; - bool success = decompose_matrix(mat2, scale, hpr); - nassertv(success); - if (!array[i].almost_equal(hpr, 0.001) || - !scale.almost_equal(LVecBase3f(1.0, 1.0, 1.0), 0.001)) { - mathutil_cat.debug() - << "Converted hpr to quaternion incorrectly!\n" - << " Source hpr: " << array[i] << "\n" - << " Quaternion: " << rot << "\n" - << " Which represents: hpr " << hpr << " scale " - << scale << "\n"; - } - } - - qr.push_back(rot.get_r()); - qi.push_back(rot.get_i()); - qj.push_back(rot.get_j()); - qk.push_back(rot.get_k()); - } - - // If quality is at least 102, we write all four quat components, - // instead of just the three. - if (_quality >= 102) { - write_reals(datagram, &qr[0], length); - } - write_reals(datagram, &qi[0], length); - write_reals(datagram, &qj[0], length); - write_reals(datagram, &qk[0], length); -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::read_header -// Access: Public -// Description: Reads the compression header that was written -// previously. This fills in the compression parameters -// necessary to correctly decompress the following data. -// -// Returns true if the header is read successfully, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool FFTCompressor:: -read_header(DatagramIterator &di) { - _quality = di.get_int8(); - - if (mathutil_cat.is_debug()) { - mathutil_cat.debug() - << "Found compressed data at quality level " << _quality << "\n"; - } - -#ifndef HAVE_FFTW - if (_quality <= 100) { - mathutil_cat.error() - << "FFTW library is not available; cannot read compressed data.\n"; - return false; - } -#endif - - set_quality(_quality); - - if (_quality < 0) { - _fft_offset = di.get_float64(); - _fft_factor = di.get_float64(); - _fft_exponent = di.get_float64(); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::read_reals -// Access: Public -// Description: Reads an array of floating-point numbers. The result -// is pushed onto the end of the indicated vector, which -// is not cleared first; it is the user's responsibility -// to ensure that the array is initially empty. Returns -// true if the data is read correctly, false if there is -// an error. -//////////////////////////////////////////////////////////////////// -bool FFTCompressor:: -read_reals(DatagramIterator &di, vector_float &array) { - int length = di.get_int32(); - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Reading real array of length " << length << "\n"; - } - - if (_quality > 100) { - // Special case: lossless output. - for (int i = 0; i < length; i++) { - array.push_back(di.get_float32()); - } - return true; - } - -#ifndef HAVE_FFTW - // If we don't have FFTW, we shouldn't get here. - return false; - -#else - - if (length == 0) { - // Special case: do nothing. - return true; - } - - if (length == 1) { - // Special case: just read in the one number. - array.push_back(di.get_float32()); - return true; - } - - // Normal case: read in the FFT array, and convert it back to - // (nearly) the original numbers. - vector_double half_complex; - half_complex.reserve(length); - int num_read = 0; - while (num_read < length) { - num_read += read_run(di, half_complex); - } - nassertr(num_read == length, false); - nassertr((int)half_complex.size() == length, false); - - int i; - for (i = 0; i < length; i++) { - half_complex[i] *= get_scale_factor(i, length); - } - - double *data = (double *)alloca(length * sizeof(double)); - rfftw_plan plan = get_real_decompress_plan(length); - rfftw_one(plan, &half_complex[0], data); - - double scale = 1.0 / (double)length; - array.reserve(array.size() + length); - for (i = 0; i < length; i++) { - array.push_back(data[i] * scale); - } - - return true; -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::read_hprs -// Access: Public -// Description: Reads an array of HPR angles. The result is pushed -// onto the end of the indicated vector, which is not -// cleared first; it is the user's responsibility to -// ensure that the array is initially empty. -//////////////////////////////////////////////////////////////////// -bool FFTCompressor:: -read_hprs(DatagramIterator &di, vector_LVecBase3f &array) { - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Reading HPRS\n"; - } - - if (_quality >= 103) { - // If quality level is at least 103, we don't even convert hpr to - // quat. - vector_float h, p, r; - bool okflag = true; - okflag = - read_reals(di, h) && - read_reals(di, p) && - read_reals(di, r); - - if (okflag) { - nassertr(h.size() == p.size() && p.size() == r.size(), false); - for (int i = 0; i < (int)h.size(); i++) { - array.push_back(LVecBase3f(h[i], p[i], r[i])); - } - } - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "HPRS read directly, okflag = " << (int)okflag << "\n"; - } - return okflag; - } - - vector_float qr, qi, qj, qk; - - bool okflag = true; - - if (_quality >= 102) { - okflag = read_reals(di, qr); - } - - okflag = - okflag && - read_reals(di, qi) && - read_reals(di, qj) && - read_reals(di, qk); - - if (okflag) { - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Decomposing HPRS, length = " << qi.size() << "\n"; - } - nassertr(qi.size() == qj.size() && qj.size() == qk.size(), false); - - array.reserve(array.size() + qi.size()); - for (int i = 0; i < (int)qi.size(); i++) { - LOrientationf rot; - - if (_quality >= 102) { - // If we have written out all four components, use them. - rot.set(qr[i], qi[i], qj[i], qj[i]); - - } else { - // Otherwise, infer the real component from the remaining - // three. - float qr2 = 1.0 - (qi[i] * qi[i] + qj[i] * qj[i] + qk[i] * qk[i]); - float qr1 = qr2 < 0.0 ? 0.0 : sqrtf(qr2); - rot.set(qr1, qi[i], qj[i], qk[i]); - } - - rot.normalize(); // Just for good measure. - - LMatrix3f mat; - rot.extract_to_matrix(mat); - LVecBase3f scale, hpr; - bool success = decompose_matrix(mat, scale, hpr); - nassertr(success, false); - - array.push_back(hpr); - } - } - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "HPRS read, okflag = " << (int)okflag << "\n"; - } - - return okflag; -} - - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::free_storage -// Access: Public, Static -// Description: Frees memory that has been allocated during past runs -// of the FFTCompressor. This is an optional call, but -// it may be made from time to time to empty the global -// cache that the compressor objects keep to facilitate -// fast compression/decompression. -//////////////////////////////////////////////////////////////////// -void FFTCompressor:: -free_storage() { -#ifdef HAVE_FFTW - RealPlans::iterator pi; - for (pi = _real_compress_plans.begin(); - pi != _real_compress_plans.end(); - ++pi) { - rfftw_destroy_plan((*pi).second); - } - _real_compress_plans.clear(); - - for (pi = _real_decompress_plans.begin(); - pi != _real_decompress_plans.end(); - ++pi) { - rfftw_destroy_plan((*pi).second); - } - _real_decompress_plans.clear(); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::write_run -// Access: Private -// Description: Writes a sequence of integers that all require the -// same number of bits. Returns the number of integers -// written, i.e. run.size(). -//////////////////////////////////////////////////////////////////// -int FFTCompressor:: -write_run(Datagram &datagram, FFTCompressor::RunWidth run_width, - const vector_double &run) { - if (run.empty()) { - return 0; - } - nassertr(run_width != RW_invalid, 0); - - if (run_width != RW_double) { - // If the width is anything other than RW_double, we write a - // single byte indicating the width and length of the upcoming - // run. - - if (run.size() <= RW_length_mask && - ((int)run_width | run.size()) != RW_double) { - // If there are enough bits remaining in the byte, use them to - // indicate the length of the run. We have to be a little - // careful, however, not to accidentally write a byte that looks - // like an RW_double flag. - datagram.add_uint8((int)run_width | run.size()); - - } else { - // Otherwise, write zero as the length, to indicate that we'll - // write the actual length in the following 16-bit word. - datagram.add_uint8(run_width); - - // Assuming, of course, that the length fits within 16 bits. - nassertr(run.size() < 65536, 0); - nassertr(run.size() != 0, 0); - - datagram.add_uint16(run.size()); - } - } - - // Now write the data itself. - vector_double::const_iterator ri; - switch (run_width) { - case RW_0: - // If it's a string of zeroes, we're done! - break; - - case RW_8: - for (ri = run.begin(); ri != run.end(); ++ri) { - datagram.add_int8((int)*ri); - } - break; - - case RW_16: - for (ri = run.begin(); ri != run.end(); ++ri) { - datagram.add_int16((int)*ri); - } - break; - - case RW_32: - for (ri = run.begin(); ri != run.end(); ++ri) { - datagram.add_int32((int)*ri); - } - break; - - case RW_double: - for (ri = run.begin(); ri != run.end(); ++ri) { - // In the case of RW_double, we only write the numbers one at a - // time, each time preceded by the RW_double flag. Hopefully - // this will happen only rarely. - datagram.add_int8((PN_int8)RW_double); - datagram.add_float64(*ri); - } - break; - - default: - break; - } - - return run.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::read_run -// Access: Private -// Description: Reads a sequence of integers that all require the -// same number of bits. Returns the number of integers -// read. It is the responsibility of the user to clear -// the vector before calling this function, or the -// numbers read will be appended to the end. -//////////////////////////////////////////////////////////////////// -int FFTCompressor:: -read_run(DatagramIterator &di, vector_double &run) { - PN_uint8 start = di.get_uint8(); - RunWidth run_width; - int length; - - if ((start & 0xff) == RW_double) { - // RW_double is a special case, and requires the whole byte. In - // this case, we don't encode a length, but assume it's only one. - run_width = RW_double; - length = 1; - - } else { - run_width = (RunWidth)(start & RW_width_mask); - length = start & RW_length_mask; - } - - if (length == 0) { - // If the length was zero, it means the actual length follows as a - // 16-bit word. - length = di.get_uint16(); - } - nassertr(length != 0, 0); - - run.reserve(run.size() + length); - - int i; - switch (run_width) { - case RW_0: - for (i = 0; i < length; i++) { - run.push_back(0.0); - } - break; - - case RW_8: - for (i = 0; i < length; i++) { - run.push_back((double)(int)di.get_int8()); - } - break; - - case RW_16: - for (i = 0; i < length; i++) { - run.push_back((double)(int)di.get_int16()); - } - break; - - case RW_32: - for (i = 0; i < length; i++) { - run.push_back((double)(int)di.get_int32()); - } - break; - - case RW_double: - for (i = 0; i < length; i++) { - run.push_back(di.get_float64()); - } - break; - - default: - break; - } - - return length; -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::get_scale_factor -// Access: Private -// Description: Returns the appropriate scaling for the given -// position within the halfcomplex array. -//////////////////////////////////////////////////////////////////// -double FFTCompressor:: -get_scale_factor(int i, int length) const { - int m = (length / 2) + 1; - int k = (i < m) ? i : length - i; - nassertr(k >= 0 && k < m, 1.0); - - return _fft_offset + - _fft_factor * pow((double)(m-1 - k) / (double)(m-1), _fft_exponent); -} - -//////////////////////////////////////////////////////////////////// -// Function: FFTCompressor::interpolate -// Access: Private, Static -// Description: Returns a number between a and b, inclusive, -// according to the value of t between 0 and 1, -// inclusive. -//////////////////////////////////////////////////////////////////// -double FFTCompressor:: -interpolate(double t, double a, double b) { - return a + t * (b - a); -} - - -#ifdef HAVE_FFTW - -//////////////////////////////////////////////////////////////////// -// Function: get_real_compress_plan -// Description: Returns a FFTW plan suitable for compressing a float -// array of the indicated length. -//////////////////////////////////////////////////////////////////// -static rfftw_plan -get_real_compress_plan(int length) { - RealPlans::iterator pi; - pi = _real_compress_plans.find(length); - if (pi != _real_compress_plans.end()) { - return (*pi).second; - } - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Creating compress plan for length " << length << ".\n"; - } - - rfftw_plan plan; - plan = rfftw_create_plan(length, FFTW_REAL_TO_COMPLEX, FFTW_ESTIMATE); - _real_compress_plans.insert(RealPlans::value_type(length, plan)); - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Got plan.\n"; - } - - return plan; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_real_decompress_plan -// Description: Returns a FFTW plan suitable for decompressing a float -// array of the indicated length. -//////////////////////////////////////////////////////////////////// -static rfftw_plan -get_real_decompress_plan(int length) { - RealPlans::iterator pi; - pi = _real_decompress_plans.find(length); - if (pi != _real_decompress_plans.end()) { - return (*pi).second; - } - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Creating decompress plan for length " << length << ".\n"; - } - - rfftw_plan plan; - plan = rfftw_create_plan(length, FFTW_COMPLEX_TO_REAL, FFTW_ESTIMATE); - _real_decompress_plans.insert(RealPlans::value_type(length, plan)); - - if (mathutil_cat.is_spam()) { - mathutil_cat.spam() - << "Got plan.\n"; - } - - return plan; -} - -#endif diff --git a/panda/src/mathutil/fftCompressor.h b/panda/src/mathutil/fftCompressor.h deleted file mode 100644 index e5e51f46ca..0000000000 --- a/panda/src/mathutil/fftCompressor.h +++ /dev/null @@ -1,83 +0,0 @@ -// Filename: fftCompressor.h -// Created by: drose (11Dec00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef FFTCOMPRESSOR_H -#define FFTCOMPRESSOR_H - -#include - -#include -#include -#include -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : FFTCompressor -// Description : This class manages a lossy compression and -// decompression of a stream of floating-point numbers -// to a datagram, based a fourier transform algorithm -// (similar in principle to JPEG compression). -// -// Actually, it doesn't do any real compression on its -// own; it just outputs a stream of integers that should -// compress much tighter via gzip than the original -// stream of floats would have. -// -// This class depends on the external FFTW library; -// without it, it will fall back on lossless output of -// the original data. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA FFTCompressor { -public: - FFTCompressor(); - - static bool is_compression_available(); - - void set_quality(int quality); - int get_quality() const; - - void write_header(Datagram &datagram); - void write_reals(Datagram &datagram, const float *array, int length); - void write_hprs(Datagram &datagram, const LVecBase3f *array, int length); - - bool read_header(DatagramIterator &di); - bool read_reals(DatagramIterator &di, vector_float &array); - bool read_hprs(DatagramIterator &di, vector_LVecBase3f &array); - - static void free_storage(); - -private: - enum RunWidth { - // We write a byte to the datagram at the beginning of each run to - // encode the width and length of the run. The width is indicated - // by the top two bits, while the length fits in the lower six, - // except RW_double, which is a special case. - RW_width_mask = 0xc0, - RW_length_mask = 0x3f, - RW_0 = 0x00, - RW_8 = 0x40, - RW_16 = 0x80, - RW_32 = 0xc0, - RW_double = 0xff, - RW_invalid = 0x01 - }; - - int write_run(Datagram &datagram, RunWidth run_width, - const vector_double &run); - int read_run(DatagramIterator &di, vector_double &run); - double get_scale_factor(int i, int length) const; - static double interpolate(double t, double a, double b); - - int _quality; - double _fft_offset; - double _fft_factor; - double _fft_exponent; -}; - -#endif - diff --git a/panda/src/mathutil/finiteBoundingVolume.cxx b/panda/src/mathutil/finiteBoundingVolume.cxx deleted file mode 100644 index 216096c741..0000000000 --- a/panda/src/mathutil/finiteBoundingVolume.cxx +++ /dev/null @@ -1,8 +0,0 @@ -// Filename: finiteBoundingVolume.cxx -// Created by: drose (02Oct99) -// -//////////////////////////////////////////////////////////////////// - -#include "finiteBoundingVolume.h" - -TypeHandle FiniteBoundingVolume::_type_handle; diff --git a/panda/src/mathutil/finiteBoundingVolume.h b/panda/src/mathutil/finiteBoundingVolume.h deleted file mode 100644 index 90c6ca8812..0000000000 --- a/panda/src/mathutil/finiteBoundingVolume.h +++ /dev/null @@ -1,63 +0,0 @@ -// Filename: finiteBoundingVolume.h -// Created by: drose (02Oct99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef FINITEBOUNDINGVOLUME_H -#define FINITEBOUNDINGVOLUME_H - -#include - -#include "geometricBoundingVolume.h" - - -/////////////////////////////////////////////////////////////////// -// Class : FiniteBoundingVolume -// Description : A special kind of GeometricBoundingVolume that is -// known to be finite. It is possible to query this -// kind of volume for its minimum and maximum extents. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA FiniteBoundingVolume : public GeometricBoundingVolume { -PUBLISHED: - virtual LPoint3f get_min() const=0; - virtual LPoint3f get_max() const=0; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeometricBoundingVolume::init_type(); - register_type(_type_handle, "FiniteBoundingVolume", - GeometricBoundingVolume::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#endif - - - - - - - - - - - - - - - - - - - diff --git a/panda/src/mathutil/frustum.N b/panda/src/mathutil/frustum.N deleted file mode 100644 index 40aeca57bf..0000000000 --- a/panda/src/mathutil/frustum.N +++ /dev/null @@ -1,2 +0,0 @@ -forcetype Frustum -forcetype Frustum diff --git a/panda/src/mathutil/frustum.h b/panda/src/mathutil/frustum.h deleted file mode 100644 index 122540c3db..0000000000 --- a/panda/src/mathutil/frustum.h +++ /dev/null @@ -1,65 +0,0 @@ -// Filename: frustum.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -#ifndef FRUSTUM_H -#define FRUSTUM_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Defines -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Class : Frustum -// Description : -//////////////////////////////////////////////////////////////////// -template -class EXPCL_PANDA Frustum { -PUBLISHED: - Frustum(); - - void make_ortho_2D(void); - void make_ortho_2D(P_numtype l, P_numtype r, P_numtype t, P_numtype b); - - void make_ortho(P_numtype fnear, P_numtype ffar); - void make_ortho(P_numtype fnear, P_numtype ffar, - P_numtype l, P_numtype r, P_numtype t, P_numtype b); - - void make_perspective_hfov(P_numtype xfov, P_numtype aspect, - P_numtype fnear, P_numtype ffar); - void make_perspective_vfov(P_numtype yfov, P_numtype aspect, - P_numtype fnear, P_numtype ffar); - void make_perspective(P_numtype xfov, P_numtype yfov, P_numtype fnear, - P_numtype ffar); - void get_perspective_params(P_numtype &yfov, P_numtype &aspect, - P_numtype &fnear, P_numtype &ffar) const; - void get_perspective_params(P_numtype &xfov, P_numtype &yfov, - P_numtype &aspect, P_numtype &fnear, - P_numtype &ffar) const; - -public: - LMatrix4 - get_perspective_projection_mat(CoordinateSystem cs = CS_default) const; - - LMatrix4 - get_ortho_projection_mat(CoordinateSystem cs = CS_default) const; - -public: - P_numtype _l, _r, _b, _t; - P_numtype _fnear, _ffar; -}; - -#include "frustum.I" - -typedef Frustum Frustumf; -typedef Frustum Frustumd; - -#endif diff --git a/panda/src/mathutil/frustum.I b/panda/src/mathutil/frustum_src.I similarity index 64% rename from panda/src/mathutil/frustum.I rename to panda/src/mathutil/frustum_src.I index 396f7f08f1..042934aae6 100644 --- a/panda/src/mathutil/frustum.I +++ b/panda/src/mathutil/frustum_src.I @@ -1,28 +1,15 @@ -// Filename: frustum.I +// Filename: frustum_src.I // Created by: mike (09Jan97) // //////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include "mathutil.h" -#include "config_mathutil.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Function: Constructor // Access: // Description: //////////////////////////////////////////////////////////////////// -template -Frustum:: -Frustum() { +INLINE FLOATNAME(Frustum):: +FLOATNAME(Frustum)() { _fnear = 1.4142; _ffar = 10.0; _l = -1; @@ -36,8 +23,7 @@ Frustum() { // Access: // Description: Sets up a two-dimensional orthographic frustum //////////////////////////////////////////////////////////////////// -template -void Frustum::make_ortho_2D(void) { +INLINE void FLOATNAME(Frustum)::make_ortho_2D(void) { make_ortho(-1, 1); } @@ -46,9 +32,8 @@ void Frustum::make_ortho_2D(void) { // Access: // Description: Sets up a two-dimensional orthographic frustum //////////////////////////////////////////////////////////////////// -template -void Frustum:: -make_ortho_2D(P_numtype l, P_numtype r, P_numtype t, P_numtype b) { +INLINE void FLOATNAME(Frustum):: +make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b) { make_ortho(-1, 1, l, r, t, b); } @@ -57,8 +42,7 @@ make_ortho_2D(P_numtype l, P_numtype r, P_numtype t, P_numtype b) { // Access: // Description: Behaves like gluOrtho //////////////////////////////////////////////////////////////////// -template -void Frustum::make_ortho(P_numtype fnear, P_numtype ffar) { +INLINE void FLOATNAME(Frustum)::make_ortho(FLOATTYPE fnear, FLOATTYPE ffar) { _fnear = fnear; _ffar = ffar; _l = -1; @@ -72,10 +56,9 @@ void Frustum::make_ortho(P_numtype fnear, P_numtype ffar) { // Access: // Description: Behaves like gluOrtho //////////////////////////////////////////////////////////////////// -template -void Frustum:: -make_ortho(P_numtype fnear, P_numtype ffar, P_numtype l, P_numtype r, - P_numtype t, P_numtype b) { +INLINE void FLOATNAME(Frustum):: +make_ortho(FLOATTYPE fnear, FLOATTYPE ffar, FLOATTYPE l, FLOATTYPE r, + FLOATTYPE t, FLOATTYPE b) { _fnear = fnear; _ffar = ffar; _l = l; @@ -106,10 +89,9 @@ make_ortho(P_numtype fnear, P_numtype ffar, P_numtype l, P_numtype r, // W yfov // //////////////////////////////////////////////////////////////////// -template -void Frustum:: -make_perspective_hfov(P_numtype hfov, P_numtype aspect, P_numtype fnear, - P_numtype ffar) { +INLINE void FLOATNAME(Frustum):: +make_perspective_hfov(FLOATTYPE hfov, FLOATTYPE aspect, FLOATTYPE fnear, + FLOATTYPE ffar) { _fnear = fnear; _ffar = ffar; _r = tan(deg_2_rad(hfov) * 0.5) * _fnear; @@ -118,10 +100,10 @@ make_perspective_hfov(P_numtype hfov, P_numtype aspect, P_numtype fnear, _b = -_t; } -template -void Frustum:: -make_perspective_vfov(P_numtype yfov, P_numtype aspect, P_numtype fnear, - P_numtype ffar) { + +INLINE void FLOATNAME(Frustum):: +make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, FLOATTYPE fnear, + FLOATTYPE ffar) { _fnear = fnear; _ffar = ffar; _t = tan(deg_2_rad(yfov) * 0.5) * _fnear; @@ -130,10 +112,10 @@ make_perspective_vfov(P_numtype yfov, P_numtype aspect, P_numtype fnear, _l = -_r; } -template -void Frustum:: -make_perspective(P_numtype xfov, P_numtype yfov, P_numtype fnear, - P_numtype ffar) { + +INLINE void FLOATNAME(Frustum):: +make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear, + FLOATTYPE ffar) { _fnear = fnear; _ffar = ffar; _t = tan(deg_2_rad(yfov) * 0.5) * _fnear; @@ -147,10 +129,9 @@ make_perspective(P_numtype xfov, P_numtype yfov, P_numtype fnear, // Access: // Description: //////////////////////////////////////////////////////////////////// -template -void Frustum:: -get_perspective_params(P_numtype& yfov, P_numtype& aspect, - P_numtype& fnear, P_numtype& ffar) const { +INLINE void FLOATNAME(Frustum):: +get_perspective_params(FLOATTYPE& yfov, FLOATTYPE& aspect, + FLOATTYPE& fnear, FLOATTYPE& ffar) const { yfov = rad_2_deg(atan(_t / _fnear)) * 2.0; aspect = _r / _t; fnear = _fnear; @@ -162,10 +143,9 @@ get_perspective_params(P_numtype& yfov, P_numtype& aspect, // Access: // Description: //////////////////////////////////////////////////////////////////// -template -void Frustum:: -get_perspective_params(P_numtype& xfov, P_numtype& yfov, P_numtype& aspect, - P_numtype& fnear, P_numtype& ffar) const { +INLINE void FLOATNAME(Frustum):: +get_perspective_params(FLOATTYPE& xfov, FLOATTYPE& yfov, FLOATTYPE& aspect, + FLOATTYPE& fnear, FLOATTYPE& ffar) const { xfov = rad_2_deg(atan(_r / _fnear)) * 2.0; get_perspective_params(yfov, aspect, fnear, ffar); } @@ -177,45 +157,44 @@ get_perspective_params(P_numtype& xfov, P_numtype& yfov, P_numtype& aspect, // perspective transform defined by the frustum, // accordinate to the indicated coordinate system. //////////////////////////////////////////////////////////////////// -template -LMatrix4 Frustum:: +INLINE FLOATNAME(LMatrix4) FLOATNAME(Frustum):: get_perspective_projection_mat(CoordinateSystem cs) const { if (cs == CS_default) { cs = default_coordinate_system; } - P_numtype a = (2.0 * _fnear) / (_r - _l); - P_numtype b = (_t + _b) / (_t - _b); - P_numtype c = (_ffar + _fnear) / (_ffar - _fnear); - P_numtype d = (_r + _l) / (_r - _l); - P_numtype e = (2.0 * _fnear) / (_t - _b); - P_numtype f = (-2.0 * _ffar * _fnear) / (_ffar - _fnear); + FLOATTYPE a = (2.0 * _fnear) / (_r - _l); + FLOATTYPE b = (_t + _b) / (_t - _b); + FLOATTYPE c = (_ffar + _fnear) / (_ffar - _fnear); + FLOATTYPE d = (_r + _l) / (_r - _l); + FLOATTYPE e = (2.0 * _fnear) / (_t - _b); + FLOATTYPE f = (-2.0 * _ffar * _fnear) / (_ffar - _fnear); switch (cs) { case CS_zup_right: - return LMatrix4( a, 0.0, 0.0, 0.0, + return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0, 0.0, -b, c, 1.0, d, e, 0.0, 0.0, 0.0, 0.0, f, 0.0); case CS_yup_right: - return LMatrix4( a, 0.0, 0.0, 0.0, + return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0, 0.0, e, 0.0, 0.0, d, b, -c,-1.0, 0.0, 0.0, f, 0.0); case CS_zup_left: - return LMatrix4::convert_mat(CS_zup_right, CS_zup_left) * + return FLOATNAME(LMatrix4)::convert_mat(CS_zup_right, CS_zup_left) * get_perspective_projection_mat(CS_zup_right); case CS_yup_left: - return LMatrix4::convert_mat(CS_yup_right, CS_yup_left) * + return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_yup_left) * get_perspective_projection_mat(CS_yup_right); default: mathutil_cat.error() << "Invalid coordinate system!\n"; - return LMatrix4::ident_mat(); + return FLOATNAME(LMatrix4)::ident_mat(); } } @@ -226,42 +205,41 @@ get_perspective_projection_mat(CoordinateSystem cs) const { // orthographic transform defined by the frustum, // accordinate to the indicated coordinate system. //////////////////////////////////////////////////////////////////// -template -LMatrix4 Frustum:: +INLINE FLOATNAME(LMatrix4) FLOATNAME(Frustum):: get_ortho_projection_mat(CoordinateSystem cs) const { if (cs == CS_default) { cs = default_coordinate_system; } - P_numtype a = 2.0 / (_r - _l); - P_numtype b = 2.0 / (_t - _b); - P_numtype c = 2.0 / (_ffar - _fnear); - P_numtype d = (_r + _l) / (_r - _l); - P_numtype e = (_t + _b) / (_t - _b); - P_numtype f = (_ffar + _fnear) / (_ffar - _fnear); + FLOATTYPE a = 2.0 / (_r - _l); + FLOATTYPE b = 2.0 / (_t - _b); + FLOATTYPE c = 2.0 / (_ffar - _fnear); + FLOATTYPE d = (_r + _l) / (_r - _l); + FLOATTYPE e = (_t + _b) / (_t - _b); + FLOATTYPE f = (_ffar + _fnear) / (_ffar - _fnear); switch (cs) { case CS_zup_right: - return LMatrix4::convert_mat(CS_yup_right, CS_zup_right) * + return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_zup_right) * get_ortho_projection_mat(CS_yup_right); case CS_yup_right: - return LMatrix4( a, 0.0, 0.0, 0.0, + return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, -c, 0.0, -d, -e, -f, 1.0); case CS_zup_left: - return LMatrix4::convert_mat(CS_zup_right, CS_zup_left) * + return FLOATNAME(LMatrix4)::convert_mat(CS_zup_right, CS_zup_left) * get_ortho_projection_mat(CS_zup_right); case CS_yup_left: - return LMatrix4::convert_mat(CS_yup_right, CS_yup_left) * + return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_yup_left) * get_ortho_projection_mat(CS_yup_right); default: mathutil_cat.error() << "Invalid coordinate system!\n"; - return LMatrix4::ident_mat(); + return FLOATNAME(LMatrix4)::ident_mat(); } } diff --git a/panda/src/mathutil/frustum_src.h b/panda/src/mathutil/frustum_src.h new file mode 100644 index 0000000000..074dfc30d2 --- /dev/null +++ b/panda/src/mathutil/frustum_src.h @@ -0,0 +1,45 @@ +// Filename: frustum_src.h +// Created by: mike (09Jan97) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Class : Frustum +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA FLOATNAME(Frustum) { +PUBLISHED: + INLINE FLOATNAME(Frustum)(); + + INLINE void make_ortho_2D(void); + INLINE void make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b); + + INLINE void make_ortho(FLOATTYPE fnear, FLOATTYPE ffar); + INLINE void make_ortho(FLOATTYPE fnear, FLOATTYPE ffar, + FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b); + + INLINE void make_perspective_hfov(FLOATTYPE xfov, FLOATTYPE aspect, + FLOATTYPE fnear, FLOATTYPE ffar); + INLINE void make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, + FLOATTYPE fnear, FLOATTYPE ffar); + INLINE void make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear, + FLOATTYPE ffar); + INLINE void get_perspective_params(FLOATTYPE &yfov, FLOATTYPE &aspect, + FLOATTYPE &fnear, FLOATTYPE &ffar) const; + INLINE void get_perspective_params(FLOATTYPE &xfov, FLOATTYPE &yfov, + FLOATTYPE &aspect, FLOATTYPE &fnear, + FLOATTYPE &ffar) const; + +public: + INLINE FLOATNAME(LMatrix4) + get_perspective_projection_mat(CoordinateSystem cs = CS_default) const; + + INLINE FLOATNAME(LMatrix4) + get_ortho_projection_mat(CoordinateSystem cs = CS_default) const; + +public: + FLOATTYPE _l, _r, _b, _t; + FLOATTYPE _fnear, _ffar; +}; + +#include "frustum_src.I" diff --git a/panda/src/mathutil/geometricBoundingVolume.I b/panda/src/mathutil/geometricBoundingVolume.I deleted file mode 100644 index 253c64d7e6..0000000000 --- a/panda/src/mathutil/geometricBoundingVolume.I +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: geometricBoundingVolume.I -// Created by: drose (07Oct99) -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeometricBoundingVolume:: -GeometricBoundingVolume() { -} - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::extend_by -// Access: Public -// Description: Increases the size of the volume to include the given -// volume. -//////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: -extend_by(const GeometricBoundingVolume *vol) { - return BoundingVolume::extend_by(vol); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::extend_by -// Access: Public -// Description: Increases the size of the volume to include the given -// point. -//////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: -extend_by(const LPoint3f &point) { - return extend_by_point(point); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::around -// Access: Public -// Description: Resets the volume to enclose only the volumes -// indicated. -//////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: -around(const GeometricBoundingVolume **first, - const GeometricBoundingVolume **last) { - return BoundingVolume::around((const BoundingVolume **)first, - (const BoundingVolume **)last); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::around -// Access: Public -// Description: Resets the volume to enclose only the points -// indicated. -//////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: -around(const LPoint3f *first, const LPoint3f *last) { - _flags = F_empty; - if (first != last) { - return around_points(first, last); - } - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::contains -// Access: Public -// Description: Returns the appropriate set of IntersectionFlags to -// indicate the amount of intersection with the -// indicated volume. -//////////////////////////////////////////////////////////////////// -INLINE int GeometricBoundingVolume:: -contains(const GeometricBoundingVolume *vol) const { - return BoundingVolume::contains(vol); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::contains -// Access: Public -// Description: Returns the appropriate set of IntersectionFlags to -// indicate the amount of intersection with the -// indicated point. -//////////////////////////////////////////////////////////////////// -INLINE int GeometricBoundingVolume:: -contains(const LPoint3f &point) const { - if (is_empty()) { - return IF_no_intersection; - } - - return contains_point(point); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeometricBoundingVolume::contains -// Access: Public -// Description: Returns the appropriate set of IntersectionFlags to -// indicate the amount of intersection with the -// indicated line segment. -//////////////////////////////////////////////////////////////////// -INLINE int GeometricBoundingVolume:: -contains(const LPoint3f &a, const LPoint3f &b) const { - if (is_empty()) { - return IF_no_intersection; - } - - return contains_lineseg(a, b); -} diff --git a/panda/src/mathutil/geometricBoundingVolume.cxx b/panda/src/mathutil/geometricBoundingVolume.cxx deleted file mode 100644 index f8275607a5..0000000000 --- a/panda/src/mathutil/geometricBoundingVolume.cxx +++ /dev/null @@ -1,30 +0,0 @@ -// Filename: geometricBoundingVolume.cxx -// Created by: drose (07Oct99) -// -//////////////////////////////////////////////////////////////////// - -#include "geometricBoundingVolume.h" - -TypeHandle GeometricBoundingVolume::_type_handle; - - -bool GeometricBoundingVolume:: -extend_by_point(const LPoint3f &) { - return false; -} - -bool GeometricBoundingVolume:: -around_points(const LPoint3f *, const LPoint3f *) { - _flags = F_empty; - return false; -} - -int GeometricBoundingVolume:: -contains_point(const LPoint3f &) const { - return IF_dont_understand; -} - -int GeometricBoundingVolume:: -contains_lineseg(const LPoint3f &, const LPoint3f &) const { - return IF_dont_understand; -} diff --git a/panda/src/mathutil/geometricBoundingVolume.h b/panda/src/mathutil/geometricBoundingVolume.h deleted file mode 100644 index 2e0a15780e..0000000000 --- a/panda/src/mathutil/geometricBoundingVolume.h +++ /dev/null @@ -1,76 +0,0 @@ -// Filename: geometricBoundingVolume.h -// Created by: drose (07Oct99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMETRICBOUNDINGVOLUME_H -#define GEOMETRICBOUNDINGVOLUME_H - -#include - -#include "boundingVolume.h" - -#include -#include - -/////////////////////////////////////////////////////////////////// -// Class : GeometricBoundingVolume -// Description : This is another abstract class, for a general class -// of bounding volumes that actually enclose points in -// 3-d space, such as BSP's and bounding spheres. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeometricBoundingVolume : public BoundingVolume { -public: - INLINE GeometricBoundingVolume(); - -PUBLISHED: - INLINE bool extend_by(const GeometricBoundingVolume *vol); - INLINE bool extend_by(const LPoint3f &point); - - // It might be nice to make these template member functions so we - // could have true STL-style first/last iterators, but that's - // impossible for virtual functions. - INLINE bool around(const GeometricBoundingVolume **first, - const GeometricBoundingVolume **last); - INLINE bool around(const LPoint3f *first, - const LPoint3f *last); - - INLINE int contains(const GeometricBoundingVolume *vol) const; - INLINE int contains(const LPoint3f &point) const; - INLINE int contains(const LPoint3f &a, const LPoint3f &b) const; - - virtual LPoint3f get_approx_center() const=0; - virtual void xform(const LMatrix4f &mat)=0; - -protected: - // Some virtual functions to implement fundamental bounding - // operations on points in 3-d space. - - virtual bool extend_by_point(const LPoint3f &point); - virtual bool around_points(const LPoint3f *first, - const LPoint3f *last); - virtual int contains_point(const LPoint3f &point) const; - virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - BoundingVolume::init_type(); - register_type(_type_handle, "GeometricBoundingVolume", - BoundingVolume::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "geometricBoundingVolume.I" - -#endif diff --git a/panda/src/mathutil/look_at.I b/panda/src/mathutil/look_at.I deleted file mode 100644 index 43ed0b67be..0000000000 --- a/panda/src/mathutil/look_at.I +++ /dev/null @@ -1,79 +0,0 @@ -// Filename: look_at.I -// Created by: drose (25Sep99) -// -//////////////////////////////////////////////////////////////////// - -INLINE void -heads_up(LMatrix3f &mat, const LVector3f &fwd, CoordinateSystem cs) { - heads_up(mat, fwd, LVector3f::up(cs), cs); -} - -INLINE void -look_at(LMatrix3f &mat, const LVector3f &fwd, CoordinateSystem cs) { - look_at(mat, fwd, LVector3f::up(cs), cs); -} - -INLINE void -heads_up(LMatrix4f &mat, const LVector3f &fwd, - const LVector3f &up, CoordinateSystem cs) { - LMatrix3f mat3; - heads_up(mat3, fwd, up, cs); - mat = LMatrix4f(mat3); -} - -INLINE void -look_at(LMatrix4f &mat, const LVector3f &fwd, - const LVector3f &up, CoordinateSystem cs) { - LMatrix3f mat3; - look_at(mat3, fwd, up, cs); - mat = LMatrix4f(mat3); -} - -INLINE void -heads_up(LMatrix4f &mat, const LVector3f &fwd, CoordinateSystem cs) { - heads_up(mat, fwd, LVector3f::up(cs), cs); -} - -INLINE void -look_at(LMatrix4f &mat, const LVector3f &fwd, CoordinateSystem cs) { - look_at(mat, fwd, LVector3f::up(cs), cs); -} - - - -INLINE void -heads_up(LMatrix3d &mat, const LVector3d &fwd, CoordinateSystem cs) { - heads_up(mat, fwd, LVector3d::up(cs), cs); -} - -INLINE void -look_at(LMatrix3d &mat, const LVector3d &fwd, CoordinateSystem cs) { - look_at(mat, fwd, LVector3d::up(cs), cs); -} - -INLINE void -heads_up(LMatrix4d &mat, const LVector3d &fwd, - const LVector3d &up, CoordinateSystem cs) { - LMatrix3d mat3; - heads_up(mat3, fwd, up, cs); - mat = LMatrix4d(mat3); -} - -INLINE void -look_at(LMatrix4d &mat, const LVector3d &fwd, - const LVector3d &up, CoordinateSystem cs) { - LMatrix3d mat3; - look_at(mat3, fwd, up, cs); - mat = LMatrix4d(mat3); -} - -INLINE void -heads_up(LMatrix4d &mat, const LVector3d &fwd, CoordinateSystem cs) { - heads_up(mat, fwd, LVector3d::up(cs), cs); -} - -INLINE void -look_at(LMatrix4d &mat, const LVector3d &fwd, CoordinateSystem cs) { - look_at(mat, fwd, LVector3d::up(cs), cs); -} - diff --git a/panda/src/mathutil/look_at.cxx b/panda/src/mathutil/look_at.cxx deleted file mode 100644 index ad21fe2450..0000000000 --- a/panda/src/mathutil/look_at.cxx +++ /dev/null @@ -1,342 +0,0 @@ -// Filename: lookAt.cxx -// Created by: drose (25Apr97) -// -//////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include "look_at.h" -#include - -template -INLINE LMatrix3 -make_xi_mat(const LVector2 &x) { - return LMatrix3(1, 0, 0, - 0, x[0], x[1], - 0, -x[1], x[0]); -} - -template -INLINE LMatrix3 -make_x_mat(const LVector2 &x) { - return LMatrix3(1, 0, 0, - 0, x[1], x[0], - 0, -x[0], x[1]); -} - -template -INLINE LMatrix3 -make_y_mat(const LVector2 &y) { - return LMatrix3(y[1], 0, -y[0], - 0, 1, 0, - y[0], 0, y[1]); -} - -template -INLINE LMatrix3 -make_z_mat(const LVector2 &z) { - return LMatrix3(z[1], -z[0], 0, - z[0], z[1], 0, - 0, 0, 1); -} - -//////////////////////////////////////////////////////////////////// -// Function: heads_up -// Description: Given two vectors defining a forward direction and an -// up vector, constructs the matrix that rotates things -// from the defined coordinate system to y-forward and -// z-up. The up vector will be rotated to z-up first, -// then the forward vector will be rotated as nearly to -// y-forward as possible. This will only have a -// different effect from look_at() if the forward and up -// vectors are not perpendicular. -//////////////////////////////////////////////////////////////////// -template -static void -_heads_up(LMatrix3 &mat, const LVector3 &fwd, - const LVector3 &up, CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - - if (cs == CS_zup_right || cs == CS_zup_left) { - // Z-up. - - // y is the projection of the up vector into the XZ plane. Its - // angle to the Z axis is the amount to rotate about the Y axis to - // bring the up vector into the YZ plane. - - LVector2 y(up[0], up[2]); - NumType d = dot(y, y); - if (d==0.0) { - y = LVector2(0.0, 1.0); - } else { - y /= csqrt(d); - } - - // x is the up vector rotated into the YZ plane. Its angle to the Z - // axis is the amount to rotate about the X axis to bring the up - // vector to the Z axis. - - LVector2 x(up[1], up[0]*y[0]+up[2]*y[1]); - d = dot(x, x); - if (d==0.0) { - x = LVector2(0.0, 1.0); - } else { - x /= csqrt(d); - } - - // Now apply both rotations to the forward vector. This will rotate - // the forward vector by the same amount we would have had to rotate - // the up vector to bring it to the Z axis. If the vectors were - // perpendicular, this will put the forward vector somewhere in the - // XY plane. - - // z is the projection of the newly rotated fwd vector into the XY - // plane. Its angle to the Y axis is the amount to rotate about the - // Z axis in order to bring the fwd vector to the Y axis. - LVector2 z(fwd[0]*y[1] - fwd[2]*y[0], - -fwd[0]*y[0]*x[0] + fwd[1]*x[1] - fwd[2]*y[1]*x[0]); - d = dot(z, z); - if (d==0.0) { - z = LVector2(0.0, 1.0); - } else { - z /= csqrt(d); - } - - // Now build the net rotation matrix. - if (cs == CS_zup_right) { - mat = - make_z_mat(z) * - make_x_mat(x) * - make_y_mat(y); - } else { // cs == CS_zup_left - mat = - make_z_mat(z) * - make_x_mat(-x) * - make_y_mat(-y); - } - } else { - // Y-up. - - // z is the projection of the forward vector into the XY plane. Its - // angle to the Y axis is the amount to rotate about the Z axis to - // bring the forward vector into the YZ plane. - - LVector2 z(up[0], up[1]); - NumType d = dot(z, z); - if (d==0.0) { - z = LVector2(0.0, 1.0); - } else { - z /= csqrt(d); - } - - // x is the forward vector rotated into the YZ plane. Its angle to - // the Y axis is the amount to rotate about the X axis to bring the - // forward vector to the Y axis. - - LVector2 x(up[0]*z[0] + up[1]*z[1], up[2]); - d = dot(x, x); - if (d==0.0) { - x = LVector2(1.0, 0.0); - } else { - x /= csqrt(d); - } - - // Now apply both rotations to the up vector. This will rotate - // the up vector by the same amount we would have had to rotate - // the forward vector to bring it to the Y axis. If the vectors were - // perpendicular, this will put the up vector somewhere in the - // XZ plane. - - // y is the projection of the newly rotated up vector into the XZ - // plane. Its angle to the Z axis is the amount to rotate about the - // Y axis in order to bring the up vector to the Z axis. - LVector2 y(fwd[0]*z[1] - fwd[1]*z[0], - -fwd[0]*x[1]*z[0] - fwd[1]*x[1]*z[1] + fwd[2]*x[0]); - d = dot(y, y); - if (d==0.0) { - y = LVector2(0.0, 1.0); - } else { - y /= csqrt(d); - } - - // Now build the net rotation matrix. - if (cs == CS_yup_right) { - mat = - make_y_mat(y) * - make_xi_mat(-x) * - make_z_mat(-z); - } else { // cs == CS_yup_left - mat = - make_y_mat(y) * - make_xi_mat(x) * - make_z_mat(z); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: look_at -// Description: Given two vectors defining a forward direction and an -// up vector, constructs the matrix that rotates things -// from the defined coordinate system to y-forward and -// z-up. The forward vector will be rotated to -// y-forward first, then the up vector will be rotated -// as nearly to z-up as possible. This will only have a -// different effect from heads_up() if the forward and -// up vectors are not perpendicular. -//////////////////////////////////////////////////////////////////// -template -static void -_look_at(LMatrix3 &mat, const LVector3 &fwd, - const LVector3 &up, CoordinateSystem cs) { - if (cs == CS_default) { - cs = default_coordinate_system; - } - - if (cs == CS_zup_right || cs == CS_zup_left) { - // Z-up. - - // z is the projection of the forward vector into the XY plane. Its - // angle to the Y axis is the amount to rotate about the Z axis to - // bring the forward vector into the YZ plane. - - LVector2 z(fwd[0], fwd[1]); - NumType d = dot(z, z); - if (d==0.0) { - z = LVector2(0.0, 1.0); - } else { - z /= csqrt(d); - } - - // x is the forward vector rotated into the YZ plane. Its angle to - // the Y axis is the amount to rotate about the X axis to bring the - // forward vector to the Y axis. - - LVector2 x(fwd[0]*z[0] + fwd[1]*z[1], fwd[2]); - d = dot(x, x); - if (d==0.0) { - x = LVector2(1.0, 0.0); - } else { - x /= csqrt(d); - } - - // Now apply both rotations to the up vector. This will rotate - // the up vector by the same amount we would have had to rotate - // the forward vector to bring it to the Y axis. If the vectors were - // perpendicular, this will put the up vector somewhere in the - // XZ plane. - - // y is the projection of the newly rotated up vector into the XZ - // plane. Its angle to the Z axis is the amount to rotate about the - // Y axis in order to bring the up vector to the Z axis. - LVector2 y(up[0]*z[1] - up[1]*z[0], - -up[0]*x[1]*z[0] - up[1]*x[1]*z[1] + up[2]*x[0]); - d = dot(y, y); - if (d==0.0) { - y = LVector2(0.0, 1.0); - } else { - y /= csqrt(d); - } - - // Now build the net rotation matrix. - if (cs == CS_zup_right) { - mat = - make_y_mat(y) * - make_xi_mat(x) * - make_z_mat(z); - } else { // cs == CS_zup_left - mat = - make_y_mat(-y) * - make_xi_mat(-x) * - make_z_mat(z); - } - } else { - // Y-up. - - // y is the projection of the up vector into the XZ plane. Its - // angle to the Z axis is the amount to rotate about the Y axis to - // bring the up vector into the YZ plane. - - LVector2 y(fwd[0], fwd[2]); - NumType d = dot(y, y); - if (d==0.0) { - y = LVector2(0.0, 1.0); - } else { - y /= csqrt(d); - } - - // x is the up vector rotated into the YZ plane. Its angle to the Z - // axis is the amount to rotate about the X axis to bring the up - // vector to the Z axis. - - LVector2 x(fwd[1], fwd[0]*y[0]+fwd[2]*y[1]); - d = dot(x, x); - if (d==0.0) { - x = LVector2(0.0, 1.0); - } else { - x /= csqrt(d); - } - - // Now apply both rotations to the forward vector. This will rotate - // the forward vector by the same amount we would have had to rotate - // the up vector to bring it to the Z axis. If the vectors were - // perpendicular, this will put the forward vector somewhere in the - // XY plane. - - // z is the projection of the newly rotated fwd vector into the XY - // plane. Its angle to the Y axis is the amount to rotate about the - // Z axis in order to bring the fwd vector to the Y axis. - LVector2 z(up[0]*y[1] - up[2]*y[0], - -up[0]*y[0]*x[0] + up[1]*x[1] - up[2]*y[1]*x[0]); - d = dot(z, z); - if (d==0.0) { - z = LVector2(0.0, 1.0); - } else { - z /= csqrt(d); - } - - // Now build the net rotation matrix. - if (cs == CS_yup_right) { - mat = - make_z_mat(z) * - make_x_mat(x) * - make_y_mat(-y); - } else { // cs == CS_yup_left - mat = - make_z_mat(-z) * - make_x_mat(-x) * - make_y_mat(-y); - } - } -} - -// The following functions are the non-template functions that are -// actually exported. - -void -heads_up(LMatrix3f &mat, const LVector3f &fwd, - const LVector3f &up, CoordinateSystem cs) { - _heads_up(mat, fwd, up, cs); -} - -void -look_at(LMatrix3f &mat, const LVector3f &fwd, - const LVector3f &up, CoordinateSystem cs) { - _look_at(mat, fwd, up, cs); -} - -void -heads_up(LMatrix3d &mat, const LVector3d &fwd, - const LVector3d &up, CoordinateSystem cs) { - _heads_up(mat, fwd, up, cs); -} - -void -look_at(LMatrix3d &mat, const LVector3d &fwd, - const LVector3d &up, CoordinateSystem cs) { - _look_at(mat, fwd, up, cs); -} diff --git a/panda/src/mathutil/look_at.h b/panda/src/mathutil/look_at.h deleted file mode 100644 index 819809731a..0000000000 --- a/panda/src/mathutil/look_at.h +++ /dev/null @@ -1,95 +0,0 @@ -// Filename: look_at.h -// Created by: drose (25Apr97) -// -//////////////////////////////////////////////////////////////////// - -#ifndef LOOKAT_H -#define LOOKAT_H - -//////////////////////////////////////////////////////////////////// -// Includes -/////////////////////////////////////////////////////////////////// -#include - -#include -#include - -// These functions return a matrix that rotates between a coordinate -// system defined with the given forward and up vectors, and the -// standard coordinate system with y-forward and z-up. They differ -// only in their behavior when the supplied forward and up vectors are -// not perpendicular; in this case, look_at will match the forward -// vector precisely, while heads_up will match the up vector -// precisely. - -// Since these functions only return a rotation matrix, the -// translation component is always zero. There are flavors of these -// functions that simply return the upper 3x3 part of the matrix, and -// flavors that return the whole 4x4 matrix with a zero bottom row. - -BEGIN_PUBLISH - -// Flavors for float-type arithmetic. - -EXPCL_PANDA void -heads_up(LMatrix3f &mat, const LVector3f &fwd, - const LVector3f &up = LVector3f::up(), - CoordinateSystem cs = CS_default); -EXPCL_PANDA void -look_at(LMatrix3f &mat, const LVector3f &fwd, - const LVector3f &up = LVector3f::up(), - CoordinateSystem cs = CS_default); - -INLINE void heads_up(LMatrix3f &mat, const LVector3f &fwd, - CoordinateSystem cs); -INLINE void look_at(LMatrix3f &mat, const LVector3f &fwd, - CoordinateSystem cs); - - -INLINE void heads_up(LMatrix4f &mat, const LVector3f &fwd, - const LVector3f &up = LVector3f::up(), - CoordinateSystem cs = CS_default); -INLINE void look_at(LMatrix4f &mat, const LVector3f &fwd, - const LVector3f &up = LVector3f::up(), - CoordinateSystem cs = CS_default); - -INLINE void heads_up(LMatrix4f &mat, const LVector3f &fwd, - CoordinateSystem cs); -INLINE void look_at(LMatrix4f &mat, const LVector3f &fwd, - CoordinateSystem cs); - - -// Flavors for double-type arithmetic. - -EXPCL_PANDA void -heads_up(LMatrix3d &mat, const LVector3d &fwd, - const LVector3d &up = LVector3d::up(), - CoordinateSystem cs = CS_default); -EXPCL_PANDA void -look_at(LMatrix3d &mat, const LVector3d &fwd, - const LVector3d &up = LVector3d::up(), - CoordinateSystem cs = CS_default); - -INLINE void heads_up(LMatrix3d &mat, const LVector3d &fwd, - CoordinateSystem cs); -INLINE void look_at(LMatrix3d &mat, const LVector3d &fwd, - CoordinateSystem cs); - - -INLINE void heads_up(LMatrix4d &mat, const LVector3d &fwd, - const LVector3d &up = LVector3d::up(), - CoordinateSystem cs = CS_default); -INLINE void look_at(LMatrix4d &mat, const LVector3d &fwd, - const LVector3d &up = LVector3d::up(), - CoordinateSystem cs = CS_default); - -INLINE void heads_up(LMatrix4d &mat, const LVector3d &fwd, - CoordinateSystem cs); -INLINE void look_at(LMatrix4d &mat, const LVector3d &fwd, - CoordinateSystem cs); - -END_PUBLISH - -#include "look_at.I" - -#endif diff --git a/panda/src/mathutil/look_at_src.I b/panda/src/mathutil/look_at_src.cxx similarity index 94% rename from panda/src/mathutil/look_at_src.I rename to panda/src/mathutil/look_at_src.cxx index 767fe9c6f8..321693715a 100644 --- a/panda/src/mathutil/look_at_src.I +++ b/panda/src/mathutil/look_at_src.cxx @@ -45,9 +45,13 @@ make_z_mat(const FLOATNAME(LVector2) &z) { // different effect from look_at() if the forward and up // vectors are not perpendicular. //////////////////////////////////////////////////////////////////// -static void -_heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, - const FLOATNAME(LVector3) &up, CoordinateSystem cs) { +void +heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, + const FLOATNAME(LVector3) &up, CoordinateSystem cs) { + if (cs == CS_default) { + cs = default_coordinate_system; + } + if (cs == CS_zup_right || cs == CS_zup_left) { // Z-up. @@ -56,7 +60,7 @@ _heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, // bring the up vector into the YZ plane. FLOATNAME(LVector2) y(up[0], up[2]); - FLOATTYPE1 d = dot(y, y); + FLOATTYPE d = dot(y, y); if (d==0.0) { y = FLOATNAME(LVector2)(0.0, 1.0); } else { @@ -113,7 +117,7 @@ _heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, // bring the forward vector into the YZ plane. FLOATNAME(LVector2) z(up[0], up[1]); - FLOATTYPE1 d = dot(z, z); + FLOATTYPE d = dot(z, z); if (d==0.0) { z = FLOATNAME(LVector2)(0.0, 1.0); } else { @@ -177,9 +181,9 @@ _heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, // different effect from heads_up() if the forward and // up vectors are not perpendicular. //////////////////////////////////////////////////////////////////// -static void -_look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, - const FLOATNAME(LVector3) &up, CoordinateSystem cs) { +void +look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, + const FLOATNAME(LVector3) &up, CoordinateSystem cs) { if (cs == CS_default) { cs = default_coordinate_system; } @@ -192,7 +196,7 @@ _look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, // bring the forward vector into the YZ plane. FLOATNAME(LVector2) z(fwd[0], fwd[1]); - FLOATTYPE1 d = dot(z, z); + FLOATTYPE d = dot(z, z); if (d==0.0) { z = FLOATNAME(LVector2)(0.0, 1.0); } else { @@ -249,7 +253,7 @@ _look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, // bring the up vector into the YZ plane. FLOATNAME(LVector2) y(fwd[0], fwd[2]); - FLOATTYPE1 d = dot(y, y); + FLOATTYPE d = dot(y, y); if (d==0.0) { y = FLOATNAME(LVector2)(0.0, 1.0); } else { @@ -300,20 +304,3 @@ _look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, } } } - -// The following functions are the non- -// actually exported. - -void -heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, - const FLOATNAME(LVector3) &up, CoordinateSystem cs) { - _heads_up(mat, fwd, up, cs); -} - -void -look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, - const FLOATNAME(LVector3) &up, CoordinateSystem cs) { - _look_at(mat, fwd, up, cs); -} - - diff --git a/panda/src/mathutil/look_at_src.h b/panda/src/mathutil/look_at_src.h new file mode 100644 index 0000000000..e0f325a7ff --- /dev/null +++ b/panda/src/mathutil/look_at_src.h @@ -0,0 +1,50 @@ +// Filename: look_at_src.h +// Created by: drose (25Sep99) +// +//////////////////////////////////////////////////////////////////// + +// These functions return a matrix that rotates between a coordinate +// system defined with the given forward and up vectors, and the +// standard coordinate system with y-forward and z-up. They differ +// only in their behavior when the supplied forward and up vectors are +// not perpendicular; in this case, look_at will match the forward +// vector precisely, while heads_up will match the up vector +// precisely. + +// Since these functions only return a rotation matrix, the +// translation component is always zero. There are flavors of these +// functions that simply return the upper 3x3 part of the matrix, and +// flavors that return the whole 4x4 matrix with a zero bottom row. + +BEGIN_PUBLISH + +EXPCL_PANDA void +heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, + const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), + CoordinateSystem cs = CS_default); +EXPCL_PANDA void +look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, + const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), + CoordinateSystem cs = CS_default); + +INLINE void heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, + CoordinateSystem cs); +INLINE void look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, + CoordinateSystem cs); + + +INLINE void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, + const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), + CoordinateSystem cs = CS_default); +INLINE void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, + const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), + CoordinateSystem cs = CS_default); + +INLINE void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, + CoordinateSystem cs); +INLINE void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, + CoordinateSystem cs); + +END_PUBLISH + +#include "look_at_src.I" diff --git a/panda/src/mathutil/mathHelpers.I b/panda/src/mathutil/mathHelpers.I deleted file mode 100644 index 2698113d06..0000000000 --- a/panda/src/mathutil/mathHelpers.I +++ /dev/null @@ -1,14 +0,0 @@ -// Filename: mathHelpers.I -// Created by: mike (25Apr97) -// -//////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include - -INLINE float distance(const LPoint3f &pos0, const LPoint3f &pos1) { - LVector3f v = pos0 - pos1; - return length(v); -} diff --git a/panda/src/mathutil/mathHelpers.h b/panda/src/mathutil/mathHelpers.h deleted file mode 100644 index a3607c7e4a..0000000000 --- a/panda/src/mathutil/mathHelpers.h +++ /dev/null @@ -1,24 +0,0 @@ -// Filename: mathHelpers.h -// Created by: mike (25Apr97) -// -//////////////////////////////////////////////////////////////////// - -#ifndef MATHHELPERS_H -#define MATHHELPERS_H - -//////////////////////////////////////////////////////////////////// -// Includes -/////////////////////////////////////////////////////////////////// -#include - -#include - -BEGIN_PUBLISH - -INLINE float distance(const LPoint3f &pos0, const LPoint3f &pos1); - -END_PUBLISH - -#include "mathHelpers.I" - -#endif diff --git a/panda/src/mathutil/mathutil.h b/panda/src/mathutil/mathutil.h deleted file mode 100644 index 1b26e8dd11..0000000000 --- a/panda/src/mathutil/mathutil.h +++ /dev/null @@ -1,23 +0,0 @@ -// Filename: mathutil.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -#ifndef MATHUTIL_H -#define MATHUTIL_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Functions -//////////////////////////////////////////////////////////////////// - -#define ABS(x) (((x)<0)?(-(x)):x) - -#endif diff --git a/panda/src/mathutil/omniBoundingVolume.I b/panda/src/mathutil/omniBoundingVolume.I deleted file mode 100644 index 2882be4f2d..0000000000 --- a/panda/src/mathutil/omniBoundingVolume.I +++ /dev/null @@ -1,14 +0,0 @@ -// Filename: omniBoundingVolume.I -// Created by: drose (22Jun00) -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE OmniBoundingVolume:: -OmniBoundingVolume() { - _flags = F_infinite; -} diff --git a/panda/src/mathutil/omniBoundingVolume.cxx b/panda/src/mathutil/omniBoundingVolume.cxx deleted file mode 100644 index c88ec2157e..0000000000 --- a/panda/src/mathutil/omniBoundingVolume.cxx +++ /dev/null @@ -1,187 +0,0 @@ -// Filename: omniBoundingVolume.cxx -// Created by: drose (22Jun00) -// -//////////////////////////////////////////////////////////////////// - -#include "omniBoundingVolume.h" -#include "boundingHexahedron.h" -#include "config_mathutil.h" - -#include - -TypeHandle OmniBoundingVolume::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -BoundingVolume *OmniBoundingVolume:: -make_copy() const { - return new OmniBoundingVolume(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::get_approx_center -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -LPoint3f OmniBoundingVolume:: -get_approx_center() const { - return LPoint3f(0.0, 0.0, 0.0); -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::xform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void OmniBoundingVolume:: -xform(const LMatrix4f &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void OmniBoundingVolume:: -output(ostream &out) const { - out << "omni"; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::extend_other -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -extend_other(BoundingVolume *other) const { - other->set_infinite(); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::around_other -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -around_other(BoundingVolume *other, - const BoundingVolume **, - const BoundingVolume **) const { - other->set_infinite(); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::contains_other -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int OmniBoundingVolume:: -contains_other(const BoundingVolume *) const { - return IF_possible | IF_some | IF_all; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::extend_by_point -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -extend_by_point(const LPoint3f &) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::extend_by_sphere -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -extend_by_sphere(const BoundingSphere *) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::extend_by_hexahedron -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -extend_by_hexahedron(const BoundingHexahedron *) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::around_points -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -around_points(const LPoint3f *, const LPoint3f *) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::around_spheres -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -around_spheres(const BoundingVolume **, - const BoundingVolume **) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::around_hexahedrons -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool OmniBoundingVolume:: -around_hexahedrons(const BoundingVolume **, - const BoundingVolume **) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::contains_point -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int OmniBoundingVolume:: -contains_point(const LPoint3f &) const { - return IF_possible | IF_some | IF_all; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::contains_lineseg -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int OmniBoundingVolume:: -contains_lineseg(const LPoint3f &, const LPoint3f &) const { - return IF_possible | IF_some | IF_all; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::contains_sphere -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int OmniBoundingVolume:: -contains_sphere(const BoundingSphere *) const { - return IF_possible | IF_some | IF_all; -} - -//////////////////////////////////////////////////////////////////// -// Function: OmniBoundingVolume::contains_hexahedron -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int OmniBoundingVolume:: -contains_hexahedron(const BoundingHexahedron *) const { - return IF_possible | IF_some | IF_all; -} diff --git a/panda/src/mathutil/omniBoundingVolume.h b/panda/src/mathutil/omniBoundingVolume.h deleted file mode 100644 index 6b41e15c82..0000000000 --- a/panda/src/mathutil/omniBoundingVolume.h +++ /dev/null @@ -1,76 +0,0 @@ -// Filename: omniBoundingVolume.h -// Created by: drose (22Jun00) -// -//////////////////////////////////////////////////////////////////// - -#ifndef OMNIBOUNDINGVOLUME_H -#define OMNIBOUNDINGVOLUME_H - -#include - -#include "geometricBoundingVolume.h" - -/////////////////////////////////////////////////////////////////// -// Class : OmniBoundingVolume -// Description : This is a special kind of GeometricBoundingVolume -// that fills all of space. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA OmniBoundingVolume : public GeometricBoundingVolume { -PUBLISHED: - INLINE OmniBoundingVolume(); - -public: - virtual BoundingVolume *make_copy() const; - - virtual LPoint3f get_approx_center() const; - virtual void xform(const LMatrix4f &mat); - - virtual void output(ostream &out) const; - -protected: - virtual bool extend_other(BoundingVolume *other) const; - virtual bool around_other(BoundingVolume *other, - const BoundingVolume **first, - const BoundingVolume **last) const; - virtual int contains_other(const BoundingVolume *other) const; - - - virtual bool extend_by_point(const LPoint3f &point); - virtual bool extend_by_sphere(const BoundingSphere *sphere); - virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron); - - virtual bool around_points(const LPoint3f *first, - const LPoint3f *last); - virtual bool around_spheres(const BoundingVolume **first, - const BoundingVolume **last); - virtual bool around_hexahedrons(const BoundingVolume **first, - const BoundingVolume **last); - - virtual int contains_point(const LPoint3f &point) const; - virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const; - virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const; - virtual int contains_sphere(const BoundingSphere *sphere) const; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeometricBoundingVolume::init_type(); - register_type(_type_handle, "OmniBoundingVolume", - GeometricBoundingVolume::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class BoundingHexahedron; -}; - -#include "omniBoundingVolume.I" - -#endif diff --git a/panda/src/mathutil/plane.N b/panda/src/mathutil/plane.N deleted file mode 100644 index 9b8394214f..0000000000 --- a/panda/src/mathutil/plane.N +++ /dev/null @@ -1,2 +0,0 @@ -forcetype Plane -forcetype Plane diff --git a/panda/src/mathutil/plane.cxx b/panda/src/mathutil/plane.cxx deleted file mode 100644 index e0a36c39f8..0000000000 --- a/panda/src/mathutil/plane.cxx +++ /dev/null @@ -1,14 +0,0 @@ -// Filename: plane.cxx -// Created by: drose (19May00) -// -//////////////////////////////////////////////////////////////////// - -#include "plane.h" - -// This tells GCC to explicitly instantiate the templates defined in -// plane.h and leave them here. -#ifdef __GNUC__ -#pragma implementation -#endif - - diff --git a/panda/src/mathutil/plane.h b/panda/src/mathutil/plane.h deleted file mode 100644 index 6c24966b16..0000000000 --- a/panda/src/mathutil/plane.h +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: plane.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -#ifndef PLANE_H -#define PLANE_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include - -#include -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Defines -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Class : Plane -// Description : -//////////////////////////////////////////////////////////////////// -template -class Plane { -PUBLISHED: - INLINE Plane(void); - INLINE Plane(const Plane ©); - INLINE Plane(const LPoint3 &a, const LPoint3 &b, - const LPoint3 &c); - INLINE Plane(const LVector3 &normal, - const LPoint3 &point); - - INLINE Plane& operator = (const Plane& copy); - - INLINE Plane operator * (const LMatrix3 &mat) const; - INLINE Plane operator * (const LMatrix4 &mat) const; - - - LMatrix4 - get_reflection_mat(void) const; - - INLINE LVector3 get_normal() const; - LPoint3 get_point() const; - INLINE NumType dist_to_plane(const LPoint3 &point) const; - INLINE bool intersects_line(LPoint3 &intersection_point, - const LPoint3 &p1, - const LPoint3 &p2) const; - INLINE bool intersects_line(NumType &t, - const LPoint3 &from, - const LVector3 &delta) const; - - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -public: - INLINE void write_datagram(Datagram &dest); - INLINE void read_datagram(DatagramIterator &source); - -public: - NumType _a, _b, _c, _d; -}; - -template -INLINE ostream &operator << (ostream &out, const Plane &p) { - p.output(out); - return out; -} - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, Plane) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, Plane) - -typedef Plane Planef; -typedef Plane Planed; - -#include "plane.I" - - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/mathutil/plane.I b/panda/src/mathutil/plane_src.I similarity index 60% rename from panda/src/mathutil/plane.I rename to panda/src/mathutil/plane_src.I index d51ef97ffc..6162e67d77 100644 --- a/panda/src/mathutil/plane.I +++ b/panda/src/mathutil/plane_src.I @@ -1,19 +1,7 @@ -// Filename: plane.I +// Filename: plane_src.I // Created by: mike (09Jan97) // //////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include "mathutil.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Function: Plane::Constructor @@ -22,9 +10,8 @@ // intersect the origin, perpendicular to the Z axis. // It's not clear how useful a default plane is. //////////////////////////////////////////////////////////////////// -template -INLINE Plane:: -Plane(void) { +INLINE FLOATNAME(Plane):: +FLOATNAME(Plane)(void) { _a = 0.0; _b = 0.0; _c = 1.0; @@ -36,9 +23,8 @@ Plane(void) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -template -INLINE Plane:: -Plane(const Plane ©) : +INLINE FLOATNAME(Plane):: +FLOATNAME(Plane)(const FLOATNAME(Plane) ©) : _a(copy._a), _b(copy._b), _c(copy._c), @@ -54,13 +40,12 @@ Plane(const Plane ©) : // viewed from the end of the normal vector, looking // down). //////////////////////////////////////////////////////////////////// -template -INLINE Plane:: -Plane(const LPoint3 &a, const LPoint3 &b, - const LPoint3 &c) { - LVector3 u = b - a; - LVector3 v = c - a; - LVector3 p = normalize(cross(u, v)); +INLINE FLOATNAME(Plane):: +FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b, + const FLOATNAME(LPoint3) &c) { + FLOATNAME(LVector3) u = b - a; + FLOATNAME(LVector3) v = c - a; + FLOATNAME(LVector3) p = normalize(cross(u, v)); _a = p[0]; _b = p[1]; @@ -74,10 +59,9 @@ Plane(const LPoint3 &a, const LPoint3 &b, // Description: Constructs a plane given a surface normal vector and // a point within the plane. //////////////////////////////////////////////////////////////////// -template -INLINE Plane:: -Plane(const LVector3 &normal, const LPoint3 &point) { - LVector3 p = normalize(normal); +INLINE FLOATNAME(Plane):: +FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, const FLOATNAME(LPoint3) &point) { + FLOATNAME(LVector3) p = normalize(normal); _a = p[0]; _b = p[1]; @@ -90,9 +74,8 @@ Plane(const LVector3 &normal, const LPoint3 &point) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -template -INLINE Plane& Plane:: -operator = (const Plane& p) { +INLINE FLOATNAME(Plane)& FLOATNAME(Plane):: +operator = (const FLOATNAME(Plane)& p) { _a = p._a; _b = p._b; _c = p._c; @@ -105,12 +88,11 @@ operator = (const Plane& p) { // Access: Public // Description: Transforms the plane by the indicated matrix. //////////////////////////////////////////////////////////////////// -template -INLINE Plane Plane:: -operator * (const LMatrix3 &mat) const { - LVector3 new_normal = get_normal() * mat; - LPoint3 new_point = get_point() * mat; - return Plane(new_normal, new_point); +INLINE FLOATNAME(Plane) FLOATNAME(Plane):: +operator * (const FLOATNAME(LMatrix3) &mat) const { + FLOATNAME(LVector3) new_normal = get_normal() * mat; + FLOATNAME(LPoint3) new_point = get_point() * mat; + return FLOATNAME(Plane)(new_normal, new_point); } //////////////////////////////////////////////////////////////////// @@ -118,34 +100,11 @@ operator * (const LMatrix3 &mat) const { // Access: Public // Description: Transforms the plane by the indicated matrix. //////////////////////////////////////////////////////////////////// -template -INLINE Plane Plane:: -operator * (const LMatrix4 &mat) const { - LVector3 new_normal = get_normal() * mat; - LPoint3 new_point = get_point() * mat; - return Plane(new_normal, new_point); -} - -//////////////////////////////////////////////////////////////////// -// Function: Plane::get_reflection_mat -// Access: Public -// Description: This computes a transform matrix that performs the -// perspective transform defined by the frustum, -// accordinate to the indicated coordinate system. -//////////////////////////////////////////////////////////////////// -template -LMatrix4 Plane:: -get_reflection_mat(void) const { - - NumType aa = _a * _a; NumType ab = _a * _b; NumType ac = _a * _c; - NumType ad = _a * _d; - NumType bb = _b * _b; NumType bc = _b * _c; NumType bd = _b * _d; - NumType cc = _c * _c; NumType cd = _c * _d; - - return LMatrix4( 1-2*aa, -2*ab, -2*ac, 0, - -2*ab, 1-2*bb, -2*bc, 0, - -2*ac, -2*bc, 1-2*cc, 0, - -2*ad, -2*bd, -2*cd, 1 ); +INLINE FLOATNAME(Plane) FLOATNAME(Plane):: +operator * (const FLOATNAME(LMatrix4) &mat) const { + FLOATNAME(LVector3) new_normal = get_normal() * mat; + FLOATNAME(LPoint3) new_point = get_point() * mat; + return FLOATNAME(Plane)(new_normal, new_point); } //////////////////////////////////////////////////////////////////// @@ -153,33 +112,9 @@ get_reflection_mat(void) const { // Access: Public // Description: Returns the surface normal of the plane. //////////////////////////////////////////////////////////////////// -template -INLINE LVector3 Plane:: +INLINE FLOATNAME(LVector3) FLOATNAME(Plane):: get_normal() const { - return LVector3(_a, _b, _c); -} - -//////////////////////////////////////////////////////////////////// -// Function: Plane::get_point -// Access: Public -// Description: Returns an arbitrary point in the plane. This can be -// used along with the normal returned by get_normal() -// to reconstruct the plane. -//////////////////////////////////////////////////////////////////// -template -LPoint3 Plane:: -get_point() const { - // Choose the denominator based on the largest axis in the normal. - if (cabs(_a) >= cabs(_b) && cabs(_a) >= cabs(_c)) { - nassertr(_a != 0.0, LPoint3(0.0, 0.0, 0.0)); - return LPoint3(-_d / _a, 0.0, 0.0); - } else if (cabs(_b) >= cabs(_c)) { - nassertr(_b != 0.0, LPoint3(0.0, 0.0, 0.0)); - return LPoint3(0.0, -_d / _b, 0.0); - } else { - nassertr(_c != 0.0, LPoint3(0.0, 0.0, 0.0)); - return LPoint3(0.0, 0.0, -_d / _c); - } + return FLOATNAME(LVector3)(_a, _b, _c); } //////////////////////////////////////////////////////////////////// @@ -192,9 +127,8 @@ get_point() const { // the plane (on the opposite side from the normal). // It's zero if the point is exactly in the plane. //////////////////////////////////////////////////////////////////// -template -INLINE NumType Plane:: -dist_to_plane(const LPoint3 &point) const { +INLINE FLOATTYPE FLOATNAME(Plane):: +dist_to_plane(const FLOATNAME(LPoint3) &point) const { return (_a * point[0] + _b * point[1] + _c * point[2] + _d); } @@ -208,12 +142,11 @@ dist_to_plane(const LPoint3 &point) const { // bearing on the intersection test. If true, sets // intersection_point to the point of intersection. //////////////////////////////////////////////////////////////////// -template -INLINE bool Plane:: -intersects_line(LPoint3 &intersection_point, - const LPoint3 &p1, - const LPoint3 &p2) const { - NumType t; +INLINE bool FLOATNAME(Plane):: +intersects_line(FLOATNAME(LPoint3) &intersection_point, + const FLOATNAME(LPoint3) &p1, + const FLOATNAME(LPoint3) &p2) const { + FLOATTYPE t; if (!intersects_line(t, p1, p2 - p1)) { return false; } @@ -238,12 +171,11 @@ intersects_line(LPoint3 &intersection_point, // point from, and t == 1.0 implies at point from + // delta, with other values of t accordingly. //////////////////////////////////////////////////////////////////// -template -INLINE bool Plane:: -intersects_line(NumType &t, - const LPoint3 &from, - const LVector3 &delta) const { - NumType denom = dot(get_normal(), delta); +INLINE bool FLOATNAME(Plane):: +intersects_line(FLOATTYPE &t, + const FLOATNAME(LPoint3) &from, + const FLOATNAME(LVector3) &delta) const { + FLOATTYPE denom = dot(get_normal(), delta); if (IS_NEARLY_ZERO(denom)) { return false; } @@ -257,8 +189,7 @@ intersects_line(NumType &t, // Access: Public // Description: //////////////////////////////////////////////////////////////////// -template -void Plane:: +INLINE void FLOATNAME(Plane):: output(ostream &out) const { out << "Plane(" << _a << " " << _b << " " << _c << " " << _d << ")"; } @@ -268,8 +199,7 @@ output(ostream &out) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -template -void Plane:: +INLINE void FLOATNAME(Plane):: write(ostream &out, int indent_level) const { indent(out, indent_level) << *this << "\n"; } @@ -279,8 +209,7 @@ write(ostream &out, int indent_level) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -template -void Plane:: +INLINE void FLOATNAME(Plane):: write_datagram(Datagram &dest) { dest.add_float32(_a); @@ -294,8 +223,7 @@ write_datagram(Datagram &dest) // Access: Public // Description: //////////////////////////////////////////////////////////////////// -template -void Plane:: +INLINE void FLOATNAME(Plane):: read_datagram(DatagramIterator &source) { _a = source.get_float32(); diff --git a/panda/src/mathutil/plane_src.cxx b/panda/src/mathutil/plane_src.cxx new file mode 100644 index 0000000000..a3051ed58d --- /dev/null +++ b/panda/src/mathutil/plane_src.cxx @@ -0,0 +1,47 @@ +// Filename: plane_src.cxx +// Created by: drose (03Apr01) +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: Plane::get_reflection_mat +// Access: Public +// Description: This computes a transform matrix that performs the +// perspective transform defined by the frustum, +// accordinate to the indicated coordinate system. +//////////////////////////////////////////////////////////////////// +FLOATNAME(LMatrix4) FLOATNAME(Plane):: +get_reflection_mat(void) const { + FLOATTYPE aa = _a * _a; FLOATTYPE ab = _a * _b; FLOATTYPE ac = _a * _c; + FLOATTYPE ad = _a * _d; + FLOATTYPE bb = _b * _b; FLOATTYPE bc = _b * _c; FLOATTYPE bd = _b * _d; + FLOATTYPE cc = _c * _c; FLOATTYPE cd = _c * _d; + + return FLOATNAME(LMatrix4)( 1-2*aa, -2*ab, -2*ac, 0, + -2*ab, 1-2*bb, -2*bc, 0, + -2*ac, -2*bc, 1-2*cc, 0, + -2*ad, -2*bd, -2*cd, 1 ); +} + +//////////////////////////////////////////////////////////////////// +// Function: Plane::get_point +// Access: Public +// Description: Returns an arbitrary point in the plane. This can be +// used along with the normal returned by get_normal() +// to reconstruct the plane. +//////////////////////////////////////////////////////////////////// +FLOATNAME(LPoint3) FLOATNAME(Plane):: +get_point() const { + // Choose the denominator based on the largest axis in the normal. + if (cabs(_a) >= cabs(_b) && cabs(_a) >= cabs(_c)) { + nassertr(_a != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0)); + return FLOATNAME(LPoint3)(-_d / _a, 0.0, 0.0); + } else if (cabs(_b) >= cabs(_c)) { + nassertr(_b != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0)); + return FLOATNAME(LPoint3)(0.0, -_d / _b, 0.0); + } else { + nassertr(_c != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0)); + return FLOATNAME(LPoint3)(0.0, 0.0, -_d / _c); + } +} diff --git a/panda/src/mathutil/plane_src.h b/panda/src/mathutil/plane_src.h new file mode 100644 index 0000000000..178d36f72b --- /dev/null +++ b/panda/src/mathutil/plane_src.h @@ -0,0 +1,53 @@ +// Filename: plane_src.h +// Created by: mike (09Jan97) +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Class : Plane +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA FLOATNAME(Plane) { +PUBLISHED: + INLINE FLOATNAME(Plane)(void); + INLINE FLOATNAME(Plane)(const FLOATNAME(Plane) ©); + INLINE FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b, + const FLOATNAME(LPoint3) &c); + INLINE FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, + const FLOATNAME(LPoint3) &point); + + INLINE FLOATNAME(Plane)& operator = (const FLOATNAME(Plane)& copy); + + INLINE FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix3) &mat) const; + INLINE FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix4) &mat) const; + + FLOATNAME(LMatrix4) get_reflection_mat(void) const; + + INLINE FLOATNAME(LVector3) get_normal() const; + FLOATNAME(LPoint3) get_point() const; + + INLINE FLOATTYPE dist_to_plane(const FLOATNAME(LPoint3) &point) const; + INLINE bool intersects_line(FLOATNAME(LPoint3) &intersection_point, + const FLOATNAME(LPoint3) &p1, + const FLOATNAME(LPoint3) &p2) const; + INLINE bool intersects_line(FLOATTYPE &t, + const FLOATNAME(LPoint3) &from, + const FLOATNAME(LVector3) &delta) const; + + INLINE void output(ostream &out) const; + INLINE void write(ostream &out, int indent_level = 0) const; + +public: + INLINE void write_datagram(Datagram &dest); + INLINE void read_datagram(DatagramIterator &source); + +public: + FLOATTYPE _a, _b, _c, _d; +}; + +INLINE ostream &operator << (ostream &out, const FLOATNAME(Plane) &p) { + p.output(out); + return out; +} + +#include "plane_src.I" diff --git a/panda/src/mathutil/rotate_to.cxx b/panda/src/mathutil/rotate_to.cxx deleted file mode 100644 index 917b2c3ee7..0000000000 --- a/panda/src/mathutil/rotate_to.cxx +++ /dev/null @@ -1,92 +0,0 @@ -// Filename: rotate_to.cxx -// Created by: drose (04Nov99) -// -//////////////////////////////////////////////////////////////////// - -#include -#include "rotate_to.h" -#include "luse.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Function: _rotate_to -// Description: Computes the matrix necessary to rotate vector a onto -// vector b. It is assumed that both vectors are -// normalized. -//////////////////////////////////////////////////////////////////// -template -static void -_rotate_to(LMatrix3 &mat, - const LVector3 &a, const LVector3 &b) { - NumType cos_theta = a.dot(b); - - LVector3 axis = a.cross(b); - NumType sin_theta = length(axis); - - // Check for collinear vectors - if (sin_theta < 0.0001) { - // The vectors are collinear. - - if (cos_theta < 0.0) { - // The vectors are opposite; choose an arbitrary axis - // perpendicular to a. - LVector3 absa(fabs(a[0]), fabs(a[1]), fabs(a[2])); - LVector3 lca(0., 0., 0.); - lca[absa[0]<=absa[1] ? absa[0]<=absa[2] ? 0 : 2 - : absa[1]<=absa[2] ? 1 : 2] = 1.0; - - axis = normalize(a.cross(lca)); - } else { - mat = LMatrix3::ident_mat(); - return; - } - - } else { - // The vectors are not collinear; determine the best axis. - axis /= sin_theta; - } - - NumType x = axis[0]; - NumType y = axis[1]; - NumType z = axis[2]; - - NumType t = 1.0 - cos_theta; - - mat(0, 0) = t * x * x + cos_theta; - mat(0, 1) = t * x * y + sin_theta * z; - mat(0, 2) = t * x * z - sin_theta * y; - - mat(1, 0) = t * y * x - sin_theta * z; - mat(1, 1) = t * y * y + cos_theta; - mat(1, 2) = t * y * z + sin_theta * x; - - mat(2, 0) = t * z * x + sin_theta * y; - mat(2, 1) = t * z * y - sin_theta * x; - mat(2, 2) = t * z * z + cos_theta; -} - - -void -rotate_to(LMatrix3f &mat, const LVector3f &a, const LVector3f &b) { - _rotate_to(mat, a, b); -} - -void -rotate_to(LMatrix3d &mat, const LVector3d &a, const LVector3d &b) { - _rotate_to(mat, a, b); -} - -void -rotate_to(LMatrix4f &mat, const LVector3f &a, const LVector3f &b) { - LMatrix3f m3; - _rotate_to(m3, a, b); - mat = LMatrix4f(m3); -} - -void -rotate_to(LMatrix4d &mat, const LVector3d &a, const LVector3d &b) { - LMatrix3d m3; - _rotate_to(m3, a, b); - mat = LMatrix4d(m3); -} diff --git a/panda/src/mathutil/rotate_to.h b/panda/src/mathutil/rotate_to.h deleted file mode 100644 index f60d665a2c..0000000000 --- a/panda/src/mathutil/rotate_to.h +++ /dev/null @@ -1,35 +0,0 @@ -// Filename: rotate_to.h -// Created by: drose (04Nov99) -// -//////////////////////////////////////////////////////////////////// - -#ifndef ROTATE_TO_H -#define ROTATE_TO_H - -//////////////////////////////////////////////////////////////////// -// -// rotate_to() -// -// This function computes a suitable rotation matrix to rotate vector -// a onto vector b. That is, it computes mat so that a * mat = b. -// The rotation axis is chosen to give the smallest possible rotation -// angle. -// -//////////////////////////////////////////////////////////////////// - -#include - -#include "lmatrix.h" -#include "luse.h" - -BEGIN_PUBLISH - -EXPCL_PANDA void rotate_to(LMatrix3f &mat, const LVector3f &a, const LVector3f &b); -EXPCL_PANDA void rotate_to(LMatrix3d &mat, const LVector3d &a, const LVector3d &b); - -EXPCL_PANDA void rotate_to(LMatrix4f &mat, const LVector3f &a, const LVector3f &b); -EXPCL_PANDA void rotate_to(LMatrix4d &mat, const LVector3d &a, const LVector3d &b); - -END_PUBLISH - -#endif diff --git a/panda/src/mathutil/rotate_to_src.I b/panda/src/mathutil/rotate_to_src.cxx similarity index 89% rename from panda/src/mathutil/rotate_to_src.I rename to panda/src/mathutil/rotate_to_src.cxx index 2487910982..f558174821 100644 --- a/panda/src/mathutil/rotate_to_src.I +++ b/panda/src/mathutil/rotate_to_src.cxx @@ -1,4 +1,4 @@ -// Filename: rotate_to.cxx +// Filename: rotate_to_src.cxx // Created by: drose (04Nov99) // //////////////////////////////////////////////////////////////////// @@ -9,14 +9,13 @@ // vector b. It is assumed that both vectors are // normalized. //////////////////////////////////////////////////////////////////// - static void _rotate_to(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) { - FLOATTYPE1 cos_theta = a.dot(b); + FLOATTYPE cos_theta = a.dot(b); FLOATNAME(LVector3) axis = a.cross(b); - FLOATTYPE1 sin_theta = length(axis); + FLOATTYPE sin_theta = length(axis); // Check for collinear vectors if (sin_theta < 0.0001) { @@ -41,11 +40,11 @@ _rotate_to(FLOATNAME(LMatrix3) &mat, axis /= sin_theta; } - FLOATTYPE1 x = axis[0]; - FLOATTYPE1 y = axis[1]; - FLOATTYPE1 z = axis[2]; + FLOATTYPE x = axis[0]; + FLOATTYPE y = axis[1]; + FLOATTYPE z = axis[2]; - FLOATTYPE1 t = 1.0 - cos_theta; + FLOATTYPE t = 1.0 - cos_theta; mat(0, 0) = t * x * x + cos_theta; mat(0, 1) = t * x * y + sin_theta * z; diff --git a/panda/src/mathutil/test_mathutil.cxx b/panda/src/mathutil/test_mathutil.cxx deleted file mode 100644 index 62896f1f59..0000000000 --- a/panda/src/mathutil/test_mathutil.cxx +++ /dev/null @@ -1,53 +0,0 @@ -// Filename: test_mathutil.cxx -// Created by: drose (16Mar00) -// -//////////////////////////////////////////////////////////////////// - -#include -#include "rotate_to.h" -#include "boundingLine.h" -#include "boundingSphere.h" - -int -main() { - /* - LVector3d a(1.0, 0.0, 0.0); - LVector3d b = normalize(LVector3d(0.5, 0.5, 0.0)); - - LMatrix3d rot; - rotate_to(rot, a, b); - - nout << "a = " << a << "\n" - << "b = " << b << "\n" - << "rot =\n"; - rot.write(nout, 2); - nout << "a * rot = " << a * rot << " length " << length(a * rot) << "\n" - << "a * invert(rot) = " << a * invert(rot) - << " length " << length(a * invert(rot)) << "\n" - << "b * rot = " << b * rot - << " length " << length(b * rot) << "\n" - << "b * invert(rot) = " << b * invert(rot) - << " length " << length(a * invert(rot)) << "\n"; - */ - - BoundingLine line(LPoint3f(0, 0, 1), LPoint3f(0, 0, 0)); - - BoundingSphere s1(LPoint3f(0, 0, 10), 1); - BoundingSphere s2(LPoint3f(10, 0, 10), 1); - BoundingSphere s3(LPoint3f(1, 0, 0), 1); - BoundingSphere s4(LPoint3f(-1, -1, -1), 1); - - line.contains(&s1); - line.contains(&s2); - line.contains(&s3); - line.contains(&s4); - - /* - s1.contains(LPoint3f(0, 0, 1), LPoint3f(0, 0, 0)); - s2.contains(LPoint3f(0, 0, 1), LPoint3f(0, 0, 0)); - s3.contains(LPoint3f(0, 0, 1), LPoint3f(0, 0, 0)); - s4.contains(LPoint3f(0, 0, 1), LPoint3f(0, 0, 0)); - */ - - return (0); -}