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