Panda3D
 All Classes Functions Variables Enumerations
physxActorDesc.cxx
1 // Filename: physxActorDesc.cxx
2 // Created by: enn0x (05Sep09)
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 "physxActorDesc.h"
16 #include "physxBodyDesc.h"
17 #include "physxManager.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: PhysxActorDesc::add_shape
21 // Access: Published
22 // Description: Adds a shape to the list of collision shapes
23 // composing this actor.
24 ////////////////////////////////////////////////////////////////////
27 
28  _desc.shapes.push_back(desc.ptr());
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PhysxActorDesc::set_name
33 // Access: Published
34 // Description: Sets the optional debug name for the actor.
35 ////////////////////////////////////////////////////////////////////
37 set_name(const char *name) {
38 
39  _name = name ? name : "";
40  _desc.name = _name.c_str();
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: PhysxActorDesc::set_density
45 // Access: Published
46 // Description: Set the density used during mass/intertia
47 // computation. This value is used if the actor's
48 // shapes do not have a mass asigned.
49 ////////////////////////////////////////////////////////////////////
51 set_density(float density) {
52 
53  _desc.density = density;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: PhysxActorDesc::set_global_pos
58 // Access: Published
59 // Description: Set the position of the actor in global space.
60 ////////////////////////////////////////////////////////////////////
62 set_global_pos(const LPoint3f &pos) {
63 
64  _desc.globalPose.t = PhysxManager::point3_to_nxVec3(pos);
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: PhysxActorDesc::set_global_mat
69 // Access: Published
70 // Description: Set the position and orientation of the actor
71 // in global space. Scaling and shear arenot
72 // supported, even if the matrix contains a scale or
73 // shear.
74 ////////////////////////////////////////////////////////////////////
77 
78  _desc.globalPose = PhysxManager::mat4_to_nxMat34(mat);
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: PhysxActorDesc::set_global_hpr
83 // Access: Published
84 // Description: Sets the orientation of the actor in global space
85 // by providing angles for heading, pitch and roll.
86 ////////////////////////////////////////////////////////////////////
88 set_global_hpr(float h, float p, float r) {
89 
90  LQuaternionf q;
91  LMatrix3f rot;
92  NxMat34 m;
93 
94  q.set_hpr(LVector3f(h, p, r));
95  q.extract_to_matrix(rot);
96 
97  _desc.globalPose.M = PhysxManager::mat3_to_nxMat33(rot);
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: PhysxActorDesc::set_body
102 // Access: Published
103 // Description: Sets the body descriptor for this actor. The actor
104 // will be dynmaic if a body descriptor is set, and
105 // static if no body descriptor is set.
106 ////////////////////////////////////////////////////////////////////
107 void PhysxActorDesc::
109 
110  _desc.body = &(desc._desc);
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: PhysxActorDesc::get_body
115 // Access: Published
116 // Description: Gets the body descriptor for this actor.
117 ////////////////////////////////////////////////////////////////////
119 get_body() const {
120  assert(false /* Not implemented */);
121 
122  //PhysxBodyDesc value;
123  //value._desc = *(_desc.body);
124  //return value;
125  return PhysxBodyDesc();
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: PhysxActorDesc::get_name
130 // Access: Published
131 // Description: Returns the optional debug name for this actor.
132 ////////////////////////////////////////////////////////////////////
133 const char *PhysxActorDesc::
134 get_name() const {
135 
136  return _desc.name;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: PhysxActorDesc::get_density
141 // Access: Published
142 // Description: Returns the actor's density.
143 ////////////////////////////////////////////////////////////////////
144 float PhysxActorDesc::
145 get_density() const {
146 
147  return _desc.density;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: PhysxActorDesc::get_global_pos
152 // Access: Published
153 // Description: Returns the actor's position in global space.
154 ////////////////////////////////////////////////////////////////////
156 get_global_pos() const {
157 
158  return PhysxManager::nxVec3_to_point3(_desc.globalPose.t);
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: PhysxActorDesc::get_global_mat
163 // Access: Published
164 // Description: Returns the actor's transform in global space.
165 ////////////////////////////////////////////////////////////////////
167 get_global_mat() const {
168 
169  return PhysxManager::nxMat34_to_mat4(_desc.globalPose);
170 }
171 
const char * get_name() const
Returns the optional debug name for this actor.
PhysxBodyDesc get_body() const
Gets the body descriptor for this actor.
LMatrix4f get_global_mat() const
Returns the actor's transform in global space.
float get_density() const
Returns the actor's density.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
void set_global_pos(const LPoint3f &pos)
Set the position of the actor in global space.
void extract_to_matrix(LMatrix3f &m) const
Based on the quat lib from VRPN.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
void set_global_hpr(float h, float p, float r)
Sets the orientation of the actor in global space by providing angles for heading, pitch and roll.
void add_shape(PhysxShapeDesc &desc)
Adds a shape to the list of collision shapes composing this actor.
LPoint3f get_global_pos() const
Returns the actor's position in global space.
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:145
void set_density(float density)
Set the density used during mass/intertia computation.
void set_body(PhysxBodyDesc &desc)
Sets the body descriptor for this actor.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
Definition: physxManager.I:169
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
Abstract base class for shape descriptors.
This is the base quaternion class.
Definition: lquaternion.h:96
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
Descriptor for the optional rigid body dynamic state of PhysxActor.
Definition: physxBodyDesc.h:29
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
Definition: physxManager.I:158
void set_name(const char *name)
Sets the optional debug name for the actor.
void set_global_mat(const LMatrix4f &mat)
Set the position and orientation of the actor in global space.