trackerData.I 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Filename: trackerData.I
  2. // Created by: jason (04Aug00)
  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. // Function: TrackerData::Default Constructor
  16. // Access: Public
  17. // Description:
  18. ////////////////////////////////////////////////////////////////////
  19. INLINE TrackerData::
  20. TrackerData() :
  21. _flags(0)
  22. {
  23. }
  24. ////////////////////////////////////////////////////////////////////
  25. // Function: TrackerData::Copy Constructor
  26. // Access: Public
  27. // Description:
  28. ////////////////////////////////////////////////////////////////////
  29. INLINE TrackerData::
  30. TrackerData(const TrackerData &copy) {
  31. (*this) = copy;
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: TrackerData::clear
  35. // Access: Public
  36. // Description: Removes all data from the structure.
  37. ////////////////////////////////////////////////////////////////////
  38. INLINE void TrackerData::
  39. clear() {
  40. _flags = 0;
  41. }
  42. ////////////////////////////////////////////////////////////////////
  43. // Function: TrackerData::set_time
  44. // Access: Public
  45. // Description: Indicates the time at which the position information
  46. // (pos and orient) are effective. This is a time
  47. // elapsed in seconds since some undefined epoch; it may
  48. // or may not correspond to the clock time indicated in
  49. // the global ClockObject.
  50. ////////////////////////////////////////////////////////////////////
  51. INLINE void TrackerData::
  52. set_time(double time) {
  53. _time = time;
  54. _flags |= F_has_time;
  55. }
  56. ////////////////////////////////////////////////////////////////////
  57. // Function: TrackerData::has_time
  58. // Access: Public
  59. // Description: Returns true if the position information time is
  60. // available. See set_time().
  61. ////////////////////////////////////////////////////////////////////
  62. INLINE bool TrackerData::
  63. has_time() const {
  64. return (_flags & F_has_time) != 0;
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: TrackerData::get_time
  68. // Access: Public
  69. // Description: Returns the time at which the position information
  70. // (pos and orient) are effective. It is an error to
  71. // call this if has_time() does not return true. See
  72. // set_time().
  73. ////////////////////////////////////////////////////////////////////
  74. INLINE double TrackerData::
  75. get_time() const {
  76. nassertr(has_time(), 0.0);
  77. return _time;
  78. }
  79. ////////////////////////////////////////////////////////////////////
  80. // Function: TrackerData::set_pos
  81. // Access: Public
  82. // Description: Indicates the current position of the tracker sensor
  83. // in space. The coordinate system of this position is
  84. // defined by the tracker.
  85. ////////////////////////////////////////////////////////////////////
  86. INLINE void TrackerData::
  87. set_pos(const LPoint3f &pos) {
  88. _pos = pos;
  89. _flags |= F_has_pos;
  90. }
  91. ////////////////////////////////////////////////////////////////////
  92. // Function: TrackerData::has_pos
  93. // Access: Public
  94. // Description: Returns true if the current position is available.
  95. // See set_pos().
  96. ////////////////////////////////////////////////////////////////////
  97. INLINE bool TrackerData::
  98. has_pos() const {
  99. return (_flags & F_has_pos) != 0;
  100. }
  101. ////////////////////////////////////////////////////////////////////
  102. // Function: TrackerData::get_pos
  103. // Access: Public
  104. // Description: Returns the current position of the tracker. It is
  105. // legal to call this if has_pos() returns false; in
  106. // this case, the position will always be (0, 0, 0).
  107. ////////////////////////////////////////////////////////////////////
  108. INLINE const LPoint3f &TrackerData::
  109. get_pos() const {
  110. if (has_pos()) {
  111. return _pos;
  112. } else {
  113. static LPoint3f zero(0.0, 0.0, 0.0);
  114. return zero;
  115. }
  116. }
  117. ////////////////////////////////////////////////////////////////////
  118. // Function: TrackerData::set_orient
  119. // Access: Public
  120. // Description: Indicates the current orientation of the tracker
  121. // sensor in space. The coordinate system of this
  122. // orientation is defined by the tracker, but should be
  123. // the same coordinate system as that reflected by
  124. // set_pos().
  125. ////////////////////////////////////////////////////////////////////
  126. INLINE void TrackerData::
  127. set_orient(const LOrientationf &orient) {
  128. _orient = orient;
  129. _flags |= F_has_orient;
  130. }
  131. ////////////////////////////////////////////////////////////////////
  132. // Function: TrackerData::has_orient
  133. // Access: Public
  134. // Description: Returns true if the current orientation is available.
  135. // See set_orient().
  136. ////////////////////////////////////////////////////////////////////
  137. INLINE bool TrackerData::
  138. has_orient() const {
  139. return (_flags & F_has_orient) != 0;
  140. }
  141. ////////////////////////////////////////////////////////////////////
  142. // Function: TrackerData::get_orient
  143. // Access: Public
  144. // Description: Returns the current orientation of the tracker. It
  145. // is legal to call this if has_orient() returns false;
  146. // in this case, the result is always the identity
  147. // orientation.
  148. ////////////////////////////////////////////////////////////////////
  149. INLINE const LOrientationf &TrackerData::
  150. get_orient() const {
  151. if (has_orient()) {
  152. return _orient;
  153. } else {
  154. static LOrientationf ident = LOrientationf::ident_quat();
  155. return ident;
  156. }
  157. }
  158. ////////////////////////////////////////////////////////////////////
  159. // Function: TrackerData::set_dt
  160. // Access: Public
  161. // Description: Indicates the amount of elapsed time over which which
  162. // the information (pos and orient) were computed. This
  163. // only makes sense if the information represents
  164. // velocity or acceleration, rather than position. This
  165. // is an elapsed time in seconds.
  166. ////////////////////////////////////////////////////////////////////
  167. INLINE void TrackerData::
  168. set_dt(double dt) {
  169. _dt = dt;
  170. _flags |= F_has_dt;
  171. }
  172. ////////////////////////////////////////////////////////////////////
  173. // Function: TrackerData::has_dt
  174. // Access: Public
  175. // Description: Returns true if the computed elapsed time is
  176. // available. See set_dt().
  177. ////////////////////////////////////////////////////////////////////
  178. INLINE bool TrackerData::
  179. has_dt() const {
  180. return (_flags & F_has_dt) != 0;
  181. }
  182. ////////////////////////////////////////////////////////////////////
  183. // Function: TrackerData::get_dt
  184. // Access: Public
  185. // Description: Returns the amount of elapsed time over which the
  186. // information (pos and orient) were computed. It
  187. // is an error to call this if has_dt() does not return
  188. // true. See set_dt().
  189. ////////////////////////////////////////////////////////////////////
  190. INLINE double TrackerData::
  191. get_dt() const {
  192. nassertr(has_dt(), 0.0);
  193. return _dt;
  194. }