00001 // Filename: LOD.I 00002 // Created by: mike (09Jan97) 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 <math.h> 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: LODSwitch::Default Constructor 00023 // Access: Public 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 INLINE LODSwitch:: 00027 LODSwitch() { 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: LODSwitch::Constructor 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE LODSwitch:: 00036 LODSwitch(float in, float out) { 00037 set_range(in, out); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: LODSwitch::Copy Constructor 00042 // Access: Public 00043 // Description: 00044 //////////////////////////////////////////////////////////////////// 00045 INLINE LODSwitch:: 00046 LODSwitch(const LODSwitch ©) : 00047 _in(copy._in), 00048 _out(copy._out) 00049 { 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: LODSwitch::Copy Assignment Operator 00054 // Access: Public 00055 // Description: 00056 //////////////////////////////////////////////////////////////////// 00057 INLINE void LODSwitch:: 00058 operator = (const LODSwitch ©) { 00059 _in = copy._in; 00060 _out = copy._out; 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: LODSwitch::get_range 00065 // Access: Public 00066 // Description: 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE void LODSwitch:: 00069 get_range(float &in, float &out) const { 00070 in = get_in(); 00071 out = get_out(); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: LODSwitch::get_in 00076 // Access: Public 00077 // Description: 00078 //////////////////////////////////////////////////////////////////// 00079 INLINE float LODSwitch:: 00080 get_in() const { 00081 return sqrtf(_in); 00082 } 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function: LODSwitch::get_out 00086 // Access: Public 00087 // Description: 00088 //////////////////////////////////////////////////////////////////// 00089 INLINE float LODSwitch:: 00090 get_out() const { 00091 return sqrtf(_out); 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: LODSwitch::set_range 00096 // Access: Public 00097 // Description: 00098 //////////////////////////////////////////////////////////////////// 00099 INLINE void LODSwitch:: 00100 set_range(float in, float out) { 00101 // We actually store the square of the switching distances. This 00102 // makes the LOD computation a little simpler. 00103 _in = in * in; 00104 _out = out * out; 00105 } 00106 00107 //////////////////////////////////////////////////////////////////// 00108 // Function: LODSwitch::in_range 00109 // Access: Public 00110 // Description: Computes the distance between two points and returns 00111 // true if the result is within the range for the LOD. 00112 //////////////////////////////////////////////////////////////////// 00113 INLINE bool LODSwitch:: 00114 in_range(float dist_squared) const { 00115 return (dist_squared >= _out && dist_squared < _in); 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: LODSwitch::rescale 00120 // Access: Public 00121 // Description: Scales the switching distances by the square root of 00122 // the indicated factor. 00123 //////////////////////////////////////////////////////////////////// 00124 INLINE void LODSwitch:: 00125 rescale(float factor_squared) { 00126 _in *= factor_squared; 00127 _out *= factor_squared; 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: LODSwitch::operator == 00132 // Access: Public 00133 // Description: 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE bool LODSwitch:: 00136 operator == (const LODSwitch &) const { 00137 return true; 00138 } 00139 00140 //////////////////////////////////////////////////////////////////// 00141 // Function: LODSwitch::operator != 00142 // Access: Public 00143 // Description: 00144 //////////////////////////////////////////////////////////////////// 00145 INLINE bool LODSwitch:: 00146 operator != (const LODSwitch &) const { 00147 return false; 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: LODSwitch::operator < 00152 // Access: Public 00153 // Description: 00154 //////////////////////////////////////////////////////////////////// 00155 INLINE bool LODSwitch:: 00156 operator < (const LODSwitch &) const { 00157 return false; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: LODSwitch::write_datagram 00162 // Access: Public 00163 // Description: Writes the contents of the LODSwitch out to the 00164 // datagram, presumably in preparation to writing to a 00165 // Bam file. 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE void LODSwitch:: 00168 write_datagram(Datagram &destination) const { 00169 destination.add_float32(_in); 00170 destination.add_float32(_out); 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: LODSwitch::read_datagram 00175 // Access: Public 00176 // Description: Reads the contents of the LODSwitch from the 00177 // datagram, presumably in response to reading a Bam 00178 // file. 00179 //////////////////////////////////////////////////////////////////// 00180 INLINE void LODSwitch:: 00181 read_datagram(DatagramIterator &source) { 00182 _in = source.get_float32(); 00183 _out = source.get_float32(); 00184 }