00001 // Filename: plane_src.cxx 00002 // Created by: drose (03Apr01) 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 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: Plane::get_reflection_mat 00022 // Access: Public 00023 // Description: This computes a transform matrix that performs the 00024 // perspective transform defined by the frustum, 00025 // accordinate to the indicated coordinate system. 00026 //////////////////////////////////////////////////////////////////// 00027 FLOATNAME(LMatrix4) FLOATNAME(Plane):: 00028 get_reflection_mat(void) const { 00029 FLOATTYPE aa = _a * _a; FLOATTYPE ab = _a * _b; FLOATTYPE ac = _a * _c; 00030 FLOATTYPE ad = _a * _d; 00031 FLOATTYPE bb = _b * _b; FLOATTYPE bc = _b * _c; FLOATTYPE bd = _b * _d; 00032 FLOATTYPE cc = _c * _c; FLOATTYPE cd = _c * _d; 00033 00034 return FLOATNAME(LMatrix4)( 1-2*aa, -2*ab, -2*ac, 0, 00035 -2*ab, 1-2*bb, -2*bc, 0, 00036 -2*ac, -2*bc, 1-2*cc, 0, 00037 -2*ad, -2*bd, -2*cd, 1 ); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: Plane::get_point 00042 // Access: Public 00043 // Description: Returns an arbitrary point in the plane. This can be 00044 // used along with the normal returned by get_normal() 00045 // to reconstruct the plane. 00046 //////////////////////////////////////////////////////////////////// 00047 FLOATNAME(LPoint3) FLOATNAME(Plane):: 00048 get_point() const { 00049 // Choose the denominator based on the largest axis in the normal. 00050 if (cabs(_a) >= cabs(_b) && cabs(_a) >= cabs(_c)) { 00051 nassertr(_a != 0.0f, FLOATNAME(LPoint3)(0.0f, 0.0f, 0.0f)); 00052 return FLOATNAME(LPoint3)(-_d / _a, 0.0f, 0.0f); 00053 } else if (cabs(_b) >= cabs(_c)) { 00054 nassertr(_b != 0.0f, FLOATNAME(LPoint3)(0.0f, 0.0f, 0.0f)); 00055 return FLOATNAME(LPoint3)(0.0f, -_d / _b, 0.0f); 00056 } else { 00057 nassertr(_c != 0.0f, FLOATNAME(LPoint3)(0.0f, 0.0f, 0.0f)); 00058 return FLOATNAME(LPoint3)(0.0f, 0.0f, -_d / _c); 00059 } 00060 }