21 #include "hx3d/physics/2d/collision_matrix.hpp" 23 #include "hx3d/utils/log.hpp" 28 CollisionMatrix::CollisionMatrix() {
29 _currentCategory = 0x1;
33 if (_categories.find(name) != _categories.end()) {
34 Log.
Error(
"Physics2D: Category `%s` already exists !", name.c_str());
38 _categories[name] = _currentCategory;
40 _currentCategory <<= 0x1;
43 void CollisionMatrix::addOneMask(std::string name, std::string category) {
44 if (_categories.find(name) == _categories.end()) {
45 Log.
Error(
"Physics2D: Category `%s` does not exists !", name.c_str());
49 if (_categories.find(category) == _categories.end()) {
50 Log.
Error(
"Physics2D: Category `%s` does not exists !", category.c_str());
54 unsigned int mask = _masks[name];
55 unsigned int cat = _categories[name];
56 unsigned int otherCategory = _categories[category];
57 unsigned int otherMask = _masks[category];
59 mask |= otherCategory;
63 _masks[category] = otherMask;
67 if (_categories.find(category) == _categories.end()) {
68 Log.
Error(
"Physics2D: Category `%s` does not exists !", category.c_str());
72 return _categories[category];
76 if (_categories.find(category) == _categories.end()) {
77 Log.
Error(
"Physics2D: Category `%s` does not exists !", category.c_str());
81 return _masks[category];
unsigned int getCategory(std::string category)
Get a category bit from a name.
unsigned int getMask(std::string category)
Get a mask bit from a name.
void Error(const std::string fmt,...)
Write an error message.
static hx3d::LogImpl Log
Current log implementation.
void addCategory(std::string name)
Add a category.