/* model/collisionmesh.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_MODEL_COLLISIONMESH_H__ #define __INCLUDED_MODEL_COLLISIONMESH_H__ #include "math/mathlib.h" #include "model/fragment.h" #include "BulletCollision/CollisionShapes/btTriangleMesh.h" #include #include namespace model { /** * @brief a collection of triangles, representing the collision geometry of a model * A CollisionModel consists of a number of collisionmeshes. * */ class CollisionMesh { public: /// type definition for the collisionmesh registry typedef std::list Registry; CollisionMesh(); /// copy constructor CollisionMesh(const CollisionMesh &other); ~CollisionMesh(); /* ---- inspectors ----------------------------------------- */ /** * @brief the number of triangles in the collision mesh */ inline size_t size() const { return collisionmesh_size; } /** * @brief the bullet triangle mesh object */ inline btTriangleMesh *triangles() { return collisionmesh_triangles; } /** * @brief location of the mesh within the parent model * location() is a point in collision model coordinate space * that indicates the (0,0,0) location of this mesh. * The worldspawn mesh should have location (0,0,0) * */ inline const math::Vector3f &location() const { return collisionmesh_location; } /** * @brief transformation axis * For normal groups, this is the rotation matrix of the mesh * For rotating groups axis->forward() is the axis of the rotation. * For movers, axis->forward() is the axis of movement. * */ inline const math::Axis & axis() const { return collisionmesh_axis; } inline const math::Vector3f &movement() const { return collisionmesh_movement; } inline const float speed() const { return collisionmesh_speed; } inline const float distance() const { return collisionmesh_distance; } inline const float scale() const { return collisionmesh_scale; } inline const FragmentGroup::Type type() const { return collisionmesh_type; } /* ---- mutators ------------------------------------------- */ /** * @brief change the group type * */ inline void set_type(const FragmentGroup::Type type) { collisionmesh_type = type; } inline void set_location(const math::Vector3f &location) { collisionmesh_location.assign(location); } inline void set_axis(const math::Axis &axis) { collisionmesh_axis.assign(axis); } inline void set_movement(const math::Vector3f &movement) { collisionmesh_movement.assign(movement); } /** * @brief apply FragmentGroup parameters to the mesh * This method applies the fragmentgroups type, location, axis, movement, distance, speed and scale * to the collision mesh */ void set_params(const FragmentGroup &group); /** * @brief movement speed * For rotating meshes this is the number of degrees per second * For movers, this is the speed in units per second */ inline void set_speed(const float speed) { collisionmesh_speed = speed; } inline void set_distance(const float distance) { collisionmesh_distance = distance; } inline void set_scale(const float scale) { collisionmesh_scale = scale; } /** * @brief add a triangle to the collision mesh */ void add_triangle(const math::Vector3f & v0, const math::Vector3f & v1, const math::Vector3f & v2); private: /// the materials registry static Registry collisionmesh_registry; static bool collisionmesh_initialized; size_t collisionmesh_size; btTriangleMesh *collisionmesh_triangles; FragmentGroup::Type collisionmesh_type; math::Vector3f collisionmesh_location; math::Axis collisionmesh_axis; math::Vector3f collisionmesh_movement; float collisionmesh_speed; float collisionmesh_scale; float collisionmesh_distance; bool collisionmesh_owns_triangles; }; } // namespace model #endif // __INCLUDED_MODEL_COLLISIONMESH_H__