Panda3D

physxMask.cxx

00001 // Filename: physxMask32.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 "physxMask.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: PhysxMask::all_on
00019 //       Access: Published
00020 //  Description: Returns a PhysxMask whose bits are all on.
00021 ////////////////////////////////////////////////////////////////////
00022 PhysxMask PhysxMask::
00023 all_on() {
00024 
00025   PhysxMask mask;
00026   mask._mask = 0xffffffff;
00027   return mask;
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: PhysxMask::all_off
00032 //       Access: Published
00033 //  Description: Returns a PhysxMask whose bits are all off.
00034 ////////////////////////////////////////////////////////////////////
00035 PhysxMask PhysxMask::
00036 all_off() {
00037 
00038   PhysxMask mask;
00039   mask._mask = 0x0000000;
00040   return mask;
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: PhysxMask::set_bit
00045 //       Access: Published
00046 //  Description: Sets the nth bit on.
00047 //               Index must be in the range [0, 31].
00048 ////////////////////////////////////////////////////////////////////
00049 void PhysxMask::
00050 set_bit(unsigned int idx) {
00051 
00052   nassertv_always(idx >= 0 && idx <= 31);
00053   _mask = _mask | (1 << idx);
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: PhysxMask::clear_bit
00058 //       Access: Published
00059 //  Description: Sets the nth bit off.
00060 //               Index must be in the range [0, 31].
00061 ////////////////////////////////////////////////////////////////////
00062 void PhysxMask::
00063 clear_bit(unsigned int idx) {
00064 
00065   nassertv_always(idx >= 0 && idx <= 31);
00066   _mask = _mask & ~(1 << idx);
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: PhysxMask::get_bit
00071 //       Access: Published
00072 //  Description: Returns true if the nth bit is set, false if it is
00073 //               cleared.
00074 //               Index must be in the range [0, 31].
00075 ////////////////////////////////////////////////////////////////////
00076 bool PhysxMask::
00077 get_bit(unsigned int idx) const {
00078 
00079   nassertr_always(idx >= 0 && idx <= 31, false);
00080   return (_mask & (1 << idx)) ? true : false;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: PhysxMask::output
00085 //       Access: Published
00086 //  Description: Writes the PhysxMask out as a list of ones and
00087 //               zeros.
00088 ////////////////////////////////////////////////////////////////////
00089 void PhysxMask::
00090 output(ostream &out) const {
00091 
00092   string name;
00093 
00094   for (int i=0; i<32; i++) {
00095     name += (_mask & (1 << i)) ? '1' : '0';
00096   }
00097 
00098   out << "/" << name << "/";
00099 }
00100 
 All Classes Functions Variables Enumerations