Panda3D
bulletBoxShape.cxx
1 // Filename: bulletBoxShape.cxx
2 // Created by: enn0x (24Jan10)
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 "bulletBoxShape.h"
16 #include "bullet_utils.h"
17 
18 TypeHandle BulletBoxShape::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: BulletBoxShape::Constructor
22 // Access: Published
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 BulletBoxShape::
26 BulletBoxShape(const LVecBase3 &halfExtents) {
27 
28  btVector3 btHalfExtents = LVecBase3_to_btVector3(halfExtents);
29 
30  _shape = new btBoxShape(btHalfExtents);
31  _shape->setUserPointer(this);
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: BulletBoxShape::ptr
36 // Access: Public
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 btCollisionShape *BulletBoxShape::
40 ptr() const {
41 
42  return _shape;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: BulletBoxShape::get_half_extents_without_margin
47 // Access: Published
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 LVecBase3 BulletBoxShape::
51 get_half_extents_without_margin() const {
52 
53  return btVector3_to_LVecBase3(_shape->getHalfExtentsWithoutMargin());
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: BulletBoxShape::get_half_extents_with_margin
58 // Access: Published
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 LVecBase3 BulletBoxShape::
62 get_half_extents_with_margin() const {
63 
64  return btVector3_to_LVecBase3(_shape->getHalfExtentsWithMargin());
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: BulletBoxShape::make_from_solid
69 // Access: Public
70 // Description:
71 ////////////////////////////////////////////////////////////////////
72 BulletBoxShape *BulletBoxShape::
73 make_from_solid(const CollisionBox *solid) {
74 
75  LPoint3 p0 = solid->get_min();
76  LPoint3 p1 = solid->get_max();
77 
78  LVecBase3 extents(p1.get_x() - p0.get_x() / 2.0,
79  p1.get_y() - p0.get_y() / 2.0,
80  p1.get_z() - p0.get_z() / 2.0);
81 
82  return new BulletBoxShape(extents);
83 }
84 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
A cuboid collision volume or object.
Definition: collisionBox.h:30
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85