Panda3D
 All Classes Functions Variables Enumerations
physxBoxShape.cxx
1 // Filename: physxBoxShape.cxx
2 // Created by: enn0x (16Sep09)
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 "physxBoxShape.h"
16 #include "physxBoxShapeDesc.h"
17 #include "physxManager.h"
18 
19 TypeHandle PhysxBoxShape::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: PhysxBoxShape::link
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void PhysxBoxShape::
27 link(NxShape *shapePtr) {
28 
29  _ptr = shapePtr->isBox();
30  _ptr->userData = this;
31  _error_type = ET_ok;
32 
33  set_name(shapePtr->getName());
34 
35  PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
36  actor->_shapes.add(this);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PhysxBoxShape::unlink
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 void PhysxBoxShape::
45 unlink() {
46 
47  _ptr->userData = NULL;
48  _error_type = ET_released;
49 
50  PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
51  actor->_shapes.remove(this);
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function : PhysxBoxShape::save_to_desc
56 // Access : Published
57 // Description : Saves the state of the shape object to a
58 // descriptor.
59 ////////////////////////////////////////////////////////////////////
60 void PhysxBoxShape::
61 save_to_desc(PhysxBoxShapeDesc &shapeDesc) const {
62 
63  nassertv(_error_type == ET_ok);
64  _ptr->saveToDesc(shapeDesc._desc);
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: PhysxBoxShape::set_dimensions
69 // Access: Published
70 // Description: Sets the box dimensions.
71 //
72 // The dimensions are the 'radii' of the box,
73 // meaning 1/2 extents in x dimension, 1/2 extents
74 // in y dimension, 1/2 extents in z dimension.
75 ////////////////////////////////////////////////////////////////////
76 void PhysxBoxShape::
78 
79  nassertv(_error_type == ET_ok);
80  _ptr->setDimensions(PhysxManager::vec3_to_nxVec3(vec));
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: PhysxBoxShape::get_dimensions
85 // Access: Published
86 // Description: Retrieves the dimensions of the box.
87 //
88 // The dimensions are the 'radii' of the box,
89 // meaning 1/2 extents in x dimension, 1/2 extents
90 // in y dimension, 1/2 extents in z dimension.
91 ////////////////////////////////////////////////////////////////////
93 get_dimensions() const {
94 
95  nassertr(_error_type == ET_ok, LVector3f::zero());
96  return PhysxManager::nxVec3_to_vec3(_ptr->getDimensions());
97 }
98 
void save_to_desc(PhysxBoxShapeDesc &shapeDesc) const
Saves the state of the shape object to a descriptor.
static const LVector3f & zero()
Returns a zero-length vector.
Definition: lvector3.h:269
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void set_dimensions(const LVector3f &dimensions)
Sets the box dimensions.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
Actors are the main simulation objects.
Definition: physxActor.h:48
Descriptor class for PhysxBoxShape.
void set_name(const char *name)
Sets a name string for this object.
Definition: physxShape.cxx:112
LVector3f get_dimensions() const
Retrieves the dimensions of the box.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85