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