00001 // Filename: test_math.cxx 00002 // Created by: drose (14Jan99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "luse.h" 00020 #include "lmatrix.h" 00021 #include "compose_matrix.h" 00022 00023 #include <notify.h> 00024 #include <stdlib.h> 00025 00026 void test() { 00027 LMatrix4f x = LMatrix4f::ident_mat(); 00028 LMatrix4f y = LMatrix4f::ident_mat(); 00029 00030 LMatrix4f z = x * y; 00031 } 00032 00033 int main(int argc, char *argv[]) { 00034 test(); 00035 00036 /* 00037 00038 LOrientationf orientation; // = LQuaternionf::ident_quat(); 00039 orientation.set(LMatrix4f::rotate_mat(-45.0f, LVector3f(0, 0, 1))); 00040 LRotationf rotation(LMatrix4f::rotate_mat(45.0f, LVector3f(0, 0, 1))); 00041 00042 nout << "Orientation: " << orientation << endl; 00043 nout << "Rotation: " << rotation << endl; 00044 00045 LQuaternionf composition = orientation * rotation; 00046 00047 nout << "Composition (o * r): " << composition << endl; 00048 composition.normalize(); 00049 nout << "Composition (after normalize): " << composition << endl; 00050 00051 LPoint3f p(1, 0, 0); 00052 LMatrix4f m = LMatrix4f::ident_mat(); 00053 00054 composition.extract_to_matrix(m); 00055 cout << "Rotation => Matrix: " << m << endl; 00056 cout << "Point: " << p << endl; 00057 cout << "Matrix * Point: " << m * p << endl; 00058 */ 00059 00060 /* 00061 LMatrix4d x = LMatrix4d::ident_mat(); 00062 LMatrix4d y = LMatrix4d::rotate_mat(90.0, LVector3d::up()); 00063 LMatrix4d a = LMatrix4d::translate_mat(10.0, 10.0, 0.0f); 00064 00065 nout << "x is " << x << "\ny is " << y << "\n" 00066 << "x * y is " << x * y << "\n" 00067 << "y * x is " << y * x << "\n" 00068 << "invert(x) is " << invert(x) << "\n" 00069 << "invert(y) is " << invert(y) << "\n" 00070 << "y * a is " << y * a << "\n" 00071 << "invert(y * a) is " << invert(y * a) << "\n" 00072 << "invert(invert(y * a)) is " << invert(invert(y * a)) << "\n" 00073 << "(y * a) * invert(y * a) is " << (y * a) * invert(y * a) << "\n" 00074 << "a * y is " << a * y << "\n" 00075 << "invert(a * y) is " << invert(a * y) << "\n" 00076 << "invert(invert(a * y)) is " << invert(invert(a * y)) << "\n"; 00077 00078 nout << "a is " << a << "\n" 00079 << "a * y is " << a * y << "\n" 00080 << "y * a is " << y * a << "\n"; 00081 00082 LVector3d r = LVector3d::right(); 00083 nout << "r is " << r << "\n" 00084 << "r * x is " << r * x << "\n" 00085 << "r * y is " << r * y << "\n" 00086 << "r * invert(y) is " << r * invert(y) << "\n" 00087 << "r * a is " << r * a << "\n"; 00088 00089 LPoint3d p(0.0f, 1.0f, 1.0f); 00090 nout << "p is " << p << "\n" 00091 << "p * x is " << p * x << "\n" 00092 << "p * y is " << p * y << "\n" 00093 << "p * invert(y) is " << p * invert(y) << "\n" 00094 << "p * a is " << p * a << "\n"; 00095 00096 LVecBase4d q(0.0f, 1.0f, 1.0f, 1.0f); 00097 nout << "q is " << q << "\n" 00098 << "q * x is " << q * x << "\n" 00099 << "q * y is " << q * y << "\n" 00100 << "q * invert(y) is " << q * invert(y) << "\n" 00101 << "q * a is " << q * a << "\n"; 00102 00103 Normald v1(0,0,1), v2(1,1,1); 00104 Vertexd p1(1,0,1), p2(1,2,3); 00105 Colorf c1(1,1,1,1), c2(0,0,0,0); 00106 00107 p2 = p2 - v1; 00108 00109 nout << "v1 = " << v1 00110 << "\nv2 = " << v2 00111 << "\np1 = " << p1 00112 << "\np2 = " << p2 00113 << "\nc1 = " << c1 00114 << "\n(c1 == c2) = " << (c1 == c2) 00115 << "\n"; 00116 00117 { 00118 LVecBase3f hpr(0.0f, 0.0f, 0.0f); 00119 LVecBase3f scale(1.0f, 1.0f, 1.0f); 00120 00121 if (argc > 3) { 00122 hpr.set(atof(argv[1]), atof(argv[2]), atof(argv[3])); 00123 } 00124 if (argc > 6) { 00125 scale.set(atof(argv[4]), atof(argv[5]), atof(argv[6])); 00126 } 00127 00128 cerr << "< hpr = " << hpr << " scale = " << scale << "\n"; 00129 LMatrix3f mat; 00130 compose_matrix(mat, scale, hpr); 00131 00132 if (decompose_matrix(mat, scale, hpr)) { 00133 nout << "> hpr = " << hpr << " scale = " << scale << "\n"; 00134 } else { 00135 nout << "Cannot decompose\n"; 00136 } 00137 } 00138 */ 00139 00140 /* 00141 for (int p = -90; p < 90; p += 10) { 00142 for (int x = -10; x < 10; x += 5) { 00143 LVecBase3f hpr(0, p, 0); 00144 LVecBase3f xyz(x, x, x); 00145 LVecBase3f scale(1, 1, 1); 00146 nout << "\n< hpr = " << hpr << " xyz = " << xyz << "\n"; 00147 LMatrix4f mat; 00148 compose_matrix(mat, scale, hpr, xyz); 00149 if (decompose_matrix(mat, scale, hpr, xyz)) { 00150 nout << "> hpr = " << hpr << " xyz = " << xyz << "\n"; 00151 } else { 00152 nout << "Cannot decompose\n"; 00153 } 00154 } 00155 } 00156 */ 00157 00158 return(0); 00159 } 00160