Panda3D
collisionSegment.I
1 // Filename: collisionSegment.I
2 // Created by: drose (30Jan01)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: CollisionSegment::Default Constructor
18 // Access: Public
19 // Description: Creates an invalid segment. This isn't terribly useful;
20 // it's expected that the user will subsequently adjust
21 // the segment via set_origin()/set_direction() or
22 // set_from_lens().
23 ////////////////////////////////////////////////////////////////////
24 INLINE CollisionSegment::
26  _a(LPoint3(0.0, 0.0, 0.0)),
27  _b(LPoint3(0.0, 0.0, 0.0))
28 {
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: CollisionSegment::Constructor
33 // Access: Public
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 INLINE CollisionSegment::
37 CollisionSegment(const LPoint3 &a, const LPoint3 &b) :
38  _a(a), _b(b)
39 {
40  nassertv(_a != _b);
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: CollisionSegment::Constructor
45 // Access: Public
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 INLINE CollisionSegment::
49 CollisionSegment(PN_stdfloat ax, PN_stdfloat ay, PN_stdfloat az,
50  PN_stdfloat bx, PN_stdfloat by, PN_stdfloat bz) :
51  _a(ax, ay, az), _b(bx, by, bz)
52 {
53  nassertv(_a != _b);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: CollisionSegment::Copy Constructor
58 // Access: Public
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 INLINE CollisionSegment::
63  CollisionSolid(copy),
64  _a(copy._a),
65  _b(copy._b)
66 {
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: CollisionSegment::set_point_a
71 // Access: Public
72 // Description:
73 ////////////////////////////////////////////////////////////////////
74 INLINE void CollisionSegment::
75 set_point_a(const LPoint3 &a) {
76  _a = a;
77  mark_internal_bounds_stale();
78  mark_viz_stale();
79  // We don't assert here that a != b, on the assumption that you
80  // might be about to change both at once, and you'll probably start
81  // by changing a first.
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: CollisionSegment::set_point_a
86 // Access: Public
87 // Description:
88 ////////////////////////////////////////////////////////////////////
89 INLINE void CollisionSegment::
90 set_point_a(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
91  set_point_a(LPoint3(x, y, z));
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: CollisionSegment::get_point_a
96 // Access: Public
97 // Description:
98 ////////////////////////////////////////////////////////////////////
99 INLINE const LPoint3 &CollisionSegment::
100 get_point_a() const {
101  return _a;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: CollisionSegment::set_point_b
106 // Access: Public
107 // Description:
108 ////////////////////////////////////////////////////////////////////
109 INLINE void CollisionSegment::
110 set_point_b(const LPoint3 &b) {
111  _b = b;
112  mark_internal_bounds_stale();
113  mark_viz_stale();
114  nassertv(_a != _b);
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: CollisionSegment::set_point_b
119 // Access: Public
120 // Description:
121 ////////////////////////////////////////////////////////////////////
122 INLINE void CollisionSegment::
123 set_point_b(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
124  set_point_b(LPoint3(x, y, z));
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: CollisionSegment::get_point_b
129 // Access: Public
130 // Description:
131 ////////////////////////////////////////////////////////////////////
132 INLINE const LPoint3 &CollisionSegment::
133 get_point_b() const {
134  return _b;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: CollisionSegment::set_from_lens
139 // Access: Public
140 // Description: Accepts a LensNode and a 2-d point in the range
141 // [-1,1]. Sets the CollisionSegment so that it begins at
142 // the LensNode's near plane and extends to the
143 // far plane, making it suitable for picking objects
144 // from the screen given a camera and a mouse location.
145 ////////////////////////////////////////////////////////////////////
146 INLINE bool CollisionSegment::
147 set_from_lens(LensNode *camera, PN_stdfloat px, PN_stdfloat py) {
148  return set_from_lens(camera, LPoint2(px, py));
149 }
bool set_from_lens(LensNode *camera, const LPoint2 &point)
Accepts a LensNode and a 2-d point in the range [-1,1].
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
A node that contains a Lens.
Definition: lensNode.h:32
CollisionSegment()
Creates an invalid segment.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
A finite line segment, with two specific endpoints but no thickness.
This is a two-component point in space.
Definition: lpoint2.h:92