Panda3D
 All Classes Functions Variables Enumerations
collisionRay.I
1 // Filename: collisionRay.I
2 // Created by: drose (22Jun00)
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: CollisionRay::Default Constructor
18 // Access: Public
19 // Description: Creates an invalid ray. This isn't terribly useful;
20 // it's expected that the user will subsequently adjust
21 // the ray via set_origin()/set_direction() or
22 // set_from_lens().
23 ////////////////////////////////////////////////////////////////////
24 INLINE CollisionRay::
26  _origin(LPoint3(0.0, 0.0, 0.0)),
27  _direction(LVector3(0.0, 0.0, 0.0))
28 {
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: CollisionRay::Constructor
33 // Access: Public
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 INLINE CollisionRay::
37 CollisionRay(const LPoint3 &origin, const LVector3 &direction) :
38  _origin(origin), _direction(direction)
39 {
40  nassertv(_direction != LPoint3::zero());
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: CollisionRay::Constructor
45 // Access: Public
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 INLINE CollisionRay::
49 CollisionRay(PN_stdfloat ox, PN_stdfloat oy, PN_stdfloat oz,
50  PN_stdfloat dx, PN_stdfloat dy, PN_stdfloat dz) :
51  _origin(ox, oy, oz), _direction(dx, dy, dz)
52 {
53  nassertv(_direction != LPoint3::zero());
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: CollisionRay::Copy Constructor
58 // Access: Public
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 INLINE CollisionRay::
62 CollisionRay(const CollisionRay &copy) :
63  CollisionSolid(copy),
64  _origin(copy._origin),
65  _direction(copy._direction)
66 {
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: CollisionRay::set_origin
71 // Access: Public
72 // Description:
73 ////////////////////////////////////////////////////////////////////
74 INLINE void CollisionRay::
75 set_origin(const LPoint3 &origin) {
76  _origin = origin;
77  mark_internal_bounds_stale();
78  mark_viz_stale();
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: CollisionRay::set_origin
83 // Access: Public
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 INLINE void CollisionRay::
87 set_origin(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
88  set_origin(LPoint3(x, y, z));
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: CollisionRay::get_origin
93 // Access: Public
94 // Description:
95 ////////////////////////////////////////////////////////////////////
96 INLINE const LPoint3 &CollisionRay::
97 get_origin() const {
98  return _origin;
99 }
100 
101 ////////////////////////////////////////////////////////////////////
102 // Function: CollisionRay::set_direction
103 // Access: Public
104 // Description:
105 ////////////////////////////////////////////////////////////////////
106 INLINE void CollisionRay::
107 set_direction(const LVector3 &direction) {
108  _direction = direction;
109  mark_internal_bounds_stale();
110  mark_viz_stale();
111  nassertv(_direction != LPoint3::zero());
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: CollisionRay::set_direction
116 // Access: Public
117 // Description:
118 ////////////////////////////////////////////////////////////////////
119 INLINE void CollisionRay::
120 set_direction(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
121  set_direction(LVector3(x, y, z));
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: CollisionRay::get_direction
126 // Access: Public
127 // Description:
128 ////////////////////////////////////////////////////////////////////
129 INLINE const LVector3 &CollisionRay::
130 get_direction() const {
131  return _direction;
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: CollisionRay::set_from_lens
136 // Access: Public
137 // Description: Accepts a LensNode and a 2-d point in the range
138 // [-1,1]. Sets the CollisionRay so that it begins at
139 // the LensNode's near plane and extends to
140 // infinity, making it suitable for picking objects from
141 // the screen given a camera and a mouse location.
142 ////////////////////////////////////////////////////////////////////
143 INLINE bool CollisionRay::
144 set_from_lens(LensNode *camera, PN_stdfloat px, PN_stdfloat py) {
145  return set_from_lens(camera, LPoint2(px, py));
146 }
An infinite ray, with a specific origin and direction.
Definition: collisionRay.h:31
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
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:258
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 set_from_lens(LensNode *camera, const LPoint2 &point)
Accepts a LensNode and a 2-d point in the range [-1,1].
This is a two-component point in space.
Definition: lpoint2.h:92
CollisionRay()
Creates an invalid ray.
Definition: collisionRay.I:25