Panda3D
collisionRay.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file collisionRay.I
10  * @author drose
11  * @date 2000-06-22
12  */
13 
14 /**
15  * Creates an invalid ray. This isn't terribly useful; it's expected that the
16  * user will subsequently adjust the ray via set_origin()/set_direction() or
17  * set_from_lens().
18  */
19 INLINE CollisionRay::
21  _origin(LPoint3(0.0, 0.0, 0.0)),
22  _direction(LVector3(0.0, 0.0, 0.0))
23 {
24 }
25 
26 /**
27  *
28  */
29 INLINE CollisionRay::
30 CollisionRay(const LPoint3 &origin, const LVector3 &direction) :
31  _origin(origin), _direction(direction)
32 {
33  nassertv(_direction != LPoint3::zero());
34 }
35 
36 /**
37  *
38  */
39 INLINE CollisionRay::
40 CollisionRay(PN_stdfloat ox, PN_stdfloat oy, PN_stdfloat oz,
41  PN_stdfloat dx, PN_stdfloat dy, PN_stdfloat dz) :
42  _origin(ox, oy, oz), _direction(dx, dy, dz)
43 {
44  nassertv(_direction != LPoint3::zero());
45 }
46 
47 /**
48  *
49  */
50 INLINE CollisionRay::
51 CollisionRay(const CollisionRay &copy) :
52  CollisionSolid(copy),
53  _origin(copy._origin),
54  _direction(copy._direction)
55 {
56 }
57 
58 /**
59  *
60  */
61 INLINE void CollisionRay::
62 set_origin(const LPoint3 &origin) {
63  _origin = origin;
64  mark_internal_bounds_stale();
65  mark_viz_stale();
66 }
67 
68 /**
69  *
70  */
71 INLINE void CollisionRay::
72 set_origin(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
73  set_origin(LPoint3(x, y, z));
74 }
75 
76 /**
77  *
78  */
79 INLINE const LPoint3 &CollisionRay::
80 get_origin() const {
81  return _origin;
82 }
83 
84 /**
85  *
86  */
87 INLINE void CollisionRay::
88 set_direction(const LVector3 &direction) {
89  _direction = direction;
90  mark_internal_bounds_stale();
91  mark_viz_stale();
92  nassertv(_direction != LPoint3::zero());
93 }
94 
95 /**
96  *
97  */
98 INLINE void CollisionRay::
99 set_direction(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
100  set_direction(LVector3(x, y, z));
101 }
102 
103 /**
104  *
105  */
106 INLINE const LVector3 &CollisionRay::
107 get_direction() const {
108  return _direction;
109 }
110 
111 /**
112  * Accepts a LensNode and a 2-d point in the range [-1,1]. Sets the
113  * CollisionRay so that it begins at the LensNode's near plane and extends to
114  * infinity, making it suitable for picking objects from the screen given a
115  * camera and a mouse location.
116  */
117 INLINE bool CollisionRay::
118 set_from_lens(LensNode *camera, PN_stdfloat px, PN_stdfloat py) {
119  return set_from_lens(camera, LPoint2(px, py));
120 }
An infinite ray, with a specific origin and direction.
Definition: collisionRay.h:27
The abstract base class for all things that can collide with other things in the world,...
A node that contains a Lens.
Definition: lensNode.h:29
bool set_from_lens(LensNode *camera, const LPoint2 &point)
Accepts a LensNode and a 2-d point in the range [-1,1].
CollisionRay()
Creates an invalid ray.
Definition: collisionRay.I:20