Panda3D
physxMask.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physxMask.cxx
10  * @author enn0x
11  * @date 2009-10-21
12  */
13 
14 #include "physxMask.h"
15 
16 /**
17  * Returns a PhysxMask whose bits are all on.
18  */
20 all_on() {
21 
22  PhysxMask mask;
23  mask._mask = 0xffffffff;
24  return mask;
25 }
26 
27 /**
28  * Returns a PhysxMask whose bits are all off.
29  */
32 
33  PhysxMask mask;
34  mask._mask = 0x0000000;
35  return mask;
36 }
37 
38 /**
39  * Sets the nth bit on. Index must be in the range [0, 31].
40  */
41 void PhysxMask::
42 set_bit(unsigned int idx) {
43 
44  nassertv_always(idx >= 0 && idx <= 31);
45  _mask = _mask | (1 << idx);
46 }
47 
48 /**
49  * Sets the nth bit off. Index must be in the range [0, 31].
50  */
51 void PhysxMask::
52 clear_bit(unsigned int idx) {
53 
54  nassertv_always(idx >= 0 && idx <= 31);
55  _mask = _mask & ~(1 << idx);
56 }
57 
58 /**
59  * Returns true if the nth bit is set, false if it is cleared. Index must be
60  * in the range [0, 31].
61  */
62 bool PhysxMask::
63 get_bit(unsigned int idx) const {
64 
65  nassertr_always(idx >= 0 && idx <= 31, false);
66  return (_mask & (1 << idx)) ? true : false;
67 }
68 
69 /**
70  * Writes the PhysxMask out as a list of ones and zeros.
71  */
72 void PhysxMask::
73 output(std::ostream &out) const {
74 
75  std::string name;
76 
77  for (int i=0; i<32; i++) {
78  name += (_mask & (1 << i)) ? '1' : '0';
79  }
80 
81  out << "/" << name << "/";
82 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void output(std::ostream &out) const
Writes the PhysxMask out as a list of ones and zeros.
Definition: physxMask.cxx:73
void set_bit(unsigned int idx)
Sets the nth bit on.
Definition: physxMask.cxx:42
static PhysxMask all_on()
Returns a PhysxMask whose bits are all on.
Definition: physxMask.cxx:20
32-bit bitmask class.
Definition: physxMask.h:24
bool get_bit(unsigned int idx) const
Returns true if the nth bit is set, false if it is cleared.
Definition: physxMask.cxx:63
static PhysxMask all_off()
Returns a PhysxMask whose bits are all off.
Definition: physxMask.cxx:31
void clear_bit(unsigned int idx)
Sets the nth bit off.
Definition: physxMask.cxx:52