Panda3D
physxCapsule.cxx
1 // Filename: physxCapsule.cxx
2 // Created by: enn0x (31Oct09)
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 "physxCapsule.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxCapsule::get_radius
20 // Access: Published
21 // Description: Returns the capsule's radius.
22 ////////////////////////////////////////////////////////////////////
23 float PhysxCapsule::
24 get_radius() const {
25 
26  return _capsule.radius;
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: PhysxCapsule::set_radius
31 // Access: Published
32 // Description: Sets the capsule's radius.
33 ////////////////////////////////////////////////////////////////////
34 void PhysxCapsule::
35 set_radius(float radius) {
36 
37  _capsule.radius = radius;
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: PhysxCapsule::get_p0
42 // Access: Published
43 // Description: Returns the start point of the segment.
44 ////////////////////////////////////////////////////////////////////
46 get_p0() const {
47 
48  return PhysxManager::nxVec3_to_vec3(_capsule.p0);
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: PhysxCapsule::set_p0
53 // Access: Published
54 // Description: Sets the start point of the segment.
55 ////////////////////////////////////////////////////////////////////
56 void PhysxCapsule::
58 
59  nassertv(!p.is_nan());
60 
61  _capsule.p0 = PhysxManager::vec3_to_nxVec3(p);
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: PhysxCapsule::get_p1
66 // Access: Published
67 // Description: Returns the end point of the segment.
68 ////////////////////////////////////////////////////////////////////
70 get_p1() const {
71 
72  return PhysxManager::nxVec3_to_vec3(_capsule.p1);
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: PhysxCapsule::set_p1
77 // Access: Published
78 // Description: Sets the end point of the segment.
79 ////////////////////////////////////////////////////////////////////
80 void PhysxCapsule::
82 
83  nassertv(!p.is_nan());
84 
85  _capsule.p1 = PhysxManager::vec3_to_nxVec3(p);
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: PhysxCapsule::get_origin
90 // Access: Published
91 // Description: Returns the start point of the segment.
92 ////////////////////////////////////////////////////////////////////
94 get_origin() const {
95 
96  return PhysxManager::nxVec3_to_point3(_capsule.getOrigin());
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: PhysxCapsule::compute_direction
101 // Access: Published
102 // Description: Returns the direction vector from the segment's
103 // start point to it's end point.
104 ////////////////////////////////////////////////////////////////////
105 void PhysxCapsule::
107 
108  nassertv(!dir.is_nan());
109 
110  NxVec3 nDir = PhysxManager::point3_to_nxVec3(dir);
111  _capsule.computeDirection(nDir);
112  PhysxManager::update_point3_from_nxVec3(dir, nDir);
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: PhysxCapsule::compute_length
117 // Access: Published
118 // Description: Returns the distance from the segment's start point
119 // to it's end point.
120 ////////////////////////////////////////////////////////////////////
121 float PhysxCapsule::
122 compute_length() const {
123 
124  return _capsule.computeLength();
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: PhysxCapsule::compute_point
129 // Access: Published
130 // Description: Computes a point on the segment.
131 ////////////////////////////////////////////////////////////////////
132 void PhysxCapsule::
133 compute_point(LPoint3f &p, float t) const {
134 
135  nassertv(!p.is_nan());
136 
137  NxVec3 nP = PhysxManager::point3_to_nxVec3(p);
138  _capsule.computePoint(nP, t);
139  PhysxManager::update_point3_from_nxVec3(p, nP);
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: PhysxCapsule::compute_square_length
144 // Access: Published
145 // Description: Returns the square distance from the segment's
146 // start point to it's end point.
147 ////////////////////////////////////////////////////////////////////
148 float PhysxCapsule::
150 
151  return _capsule.computeSquareLength();
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: PhysxCapsule::set_origin_direction
156 // Access: Published
157 // Description: Setup this capsule from origin (start point) and
158 // direction vector.
159 ////////////////////////////////////////////////////////////////////
160 void PhysxCapsule::
161 set_origin_direction(const LPoint3f &origin, const LVector3f &direction) {
162 
163  nassertv(!origin.is_nan());
164  nassertv(!direction.is_nan());
165 
166  _capsule.setOriginDirection(PhysxManager::point3_to_nxVec3(origin),
167  PhysxManager::vec3_to_nxVec3(direction));
168 }
169 
void set_p0(LPoint3f p)
Sets the start point of the segment.
LPoint3f get_p1() const
Returns the end point of the segment.
void compute_direction(LPoint3f &dir) const
Returns the direction vector from the segment's start point to it's end point.
float get_radius() const
Returns the capsule's radius.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
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
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:464
void set_radius(float value)
Sets the capsule's radius.
void set_origin_direction(const LPoint3f &origin, const LVector3f &direction)
Setup this capsule from origin (start point) and direction vector.
void set_p1(LPoint3f p)
Sets the end point of the segment.
void compute_point(LPoint3f &p, float t) const
Computes a point on the segment.
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
float compute_length() const
Returns the distance from the segment's start point to it's end point.
LPoint3f get_p0() const
Returns the start point of the segment.
LPoint3f get_origin() const
Returns the start point of the segment.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
float compute_square_length() const
Returns the square distance from the segment's start point to it's end point.