Panda3D
|
00001 // Filename: physxGroupsMask.cxx 00002 // Created by: enn0x (21Oct09) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "physxGroupsMask.h" 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function: PhysxGroupsMask::all_on 00019 // Access: Published 00020 // Description: Returns a PhysxGroupsMask whose bits are all on. 00021 //////////////////////////////////////////////////////////////////// 00022 PhysxGroupsMask PhysxGroupsMask:: 00023 all_on() { 00024 00025 PhysxGroupsMask mask; 00026 mask._mask.bits0 = 0xffffffff; 00027 mask._mask.bits1 = 0xffffffff; 00028 mask._mask.bits2 = 0xffffffff; 00029 mask._mask.bits3 = 0xffffffff; 00030 return mask; 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: PhysxGroupsMask::all_off 00035 // Access: Published 00036 // Description: Returns a PhysxGroupsMask whose bits are all off. 00037 //////////////////////////////////////////////////////////////////// 00038 PhysxGroupsMask PhysxGroupsMask:: 00039 all_off() { 00040 00041 PhysxGroupsMask mask; 00042 00043 mask._mask.bits0 = 0x0000000; 00044 mask._mask.bits1 = 0x0000000; 00045 mask._mask.bits2 = 0x0000000; 00046 mask._mask.bits3 = 0x0000000; 00047 00048 return mask; 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PhysxGroupsMask::set_bit 00053 // Access: Published 00054 // Description: Sets the nth bit on. 00055 // Index must be in the range [0, 127]. 00056 //////////////////////////////////////////////////////////////////// 00057 void PhysxGroupsMask:: 00058 set_bit(unsigned int idx) { 00059 00060 nassertv_always(idx >= 0 && idx <= 127); 00061 00062 NxU32 bits = 1 << (idx % 32); 00063 00064 if (idx < 32) { 00065 _mask.bits0 |= bits; 00066 } 00067 else if (idx < 64) { 00068 _mask.bits1 |= bits; 00069 } 00070 else if (idx < 96) { 00071 _mask.bits2 |= bits; 00072 } 00073 else { 00074 _mask.bits3 |= bits; 00075 } 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: PhysxGroupsMask::clear_bit 00080 // Access: Published 00081 // Description: Sets the nth bit off. 00082 // Index must be in the range [0, 127]. 00083 //////////////////////////////////////////////////////////////////// 00084 void PhysxGroupsMask:: 00085 clear_bit(unsigned int idx) { 00086 00087 nassertv_always(idx >= 0 && idx <= 127); 00088 00089 NxU32 bits = 1 << (idx % 32); 00090 00091 if (idx < 32) { 00092 _mask.bits0 = _mask.bits0 & ~bits; 00093 } 00094 else if (idx < 64) { 00095 _mask.bits1 = _mask.bits1 & ~bits; 00096 } 00097 else if (idx < 96) { 00098 _mask.bits2 = _mask.bits2 & ~bits; 00099 } 00100 else { 00101 _mask.bits3 = _mask.bits3 & ~bits; 00102 } 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: PhysxGroupsMask::get_bit 00107 // Access: Published 00108 // Description: Returns true if the nth bit is set, false if it is 00109 // cleared. 00110 // Index must be in the range [0, 127]. 00111 //////////////////////////////////////////////////////////////////// 00112 bool PhysxGroupsMask:: 00113 get_bit(unsigned int idx) const { 00114 00115 nassertr_always(idx >= 0 && idx <= 127, false); 00116 00117 NxU32 bits = 1 << (idx % 32); 00118 00119 if (idx < 32) { 00120 return (_mask.bits0 & bits) ? true : false; 00121 } 00122 else if (idx < 64) { 00123 return (_mask.bits1 & bits) ? true : false; 00124 } 00125 else if (idx < 96) { 00126 return (_mask.bits2 & bits) ? true : false; 00127 } 00128 else { 00129 return (_mask.bits3 & bits) ? true : false; 00130 } 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: PhysxGroupsMask::output 00135 // Access: Published 00136 // Description: Writes the PhysxGroupsMask out as a list of ones and 00137 // zeros. 00138 //////////////////////////////////////////////////////////////////// 00139 void PhysxGroupsMask:: 00140 output(ostream &out) const { 00141 00142 string name0; 00143 string name1; 00144 string name2; 00145 string name3; 00146 00147 for (int i=0; i<32; i++) { 00148 name0 += (_mask.bits0 & (1 << i)) ? '1' : '0'; 00149 name1 += (_mask.bits1 & (1 << i)) ? '1' : '0'; 00150 name2 += (_mask.bits2 & (1 << i)) ? '1' : '0'; 00151 name3 += (_mask.bits3 & (1 << i)) ? '1' : '0'; 00152 } 00153 00154 out << "/" << name0 << "-" << name1 << "-" << name2 << "-" << name3 << "/"; 00155 } 00156