Panda3D
Loading...
Searching...
No Matches
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 */
20all_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 */
31all_off() {
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 */
42set_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 */
52clear_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 */
63get_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 */
73output(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}
32-bit bitmask class.
Definition physxMask.h:24
static PhysxMask all_on()
Returns a PhysxMask whose bits are all on.
Definition physxMask.cxx:20
static PhysxMask all_off()
Returns a PhysxMask whose bits are all off.
Definition physxMask.cxx:31
void set_bit(unsigned int idx)
Sets the nth bit on.
Definition physxMask.cxx:42
void output(std::ostream &out) const
Writes the PhysxMask out as a list of ones and zeros.
Definition physxMask.cxx:73
bool get_bit(unsigned int idx) const
Returns true if the nth bit is set, false if it is cleared.
Definition physxMask.cxx:63
void clear_bit(unsigned int idx)
Sets the nth bit off.
Definition physxMask.cxx:52
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.