cameraSpline.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _CAMERASPLINE_H_
  23. #define _CAMERASPLINE_H_
  24. #include "math/mMath.h"
  25. #include "core/util/tVector.h"
  26. //----------------------------------------------------------------------------
  27. class CameraSpline
  28. {
  29. public:
  30. struct Knot
  31. {
  32. public:
  33. Point3F mPosition;
  34. QuatF mRotation;
  35. F32 mSpeed; /// in meters per second
  36. enum Type {
  37. NORMAL,
  38. POSITION_ONLY,
  39. KINK,
  40. NUM_TYPE_BITS = 2
  41. }mType;
  42. enum Path {
  43. LINEAR,
  44. SPLINE,
  45. NUM_PATH_BITS = 1
  46. }mPath;
  47. F32 mDistance;
  48. Knot *prev;
  49. Knot *next;
  50. Knot() {};
  51. Knot(const Knot &k);
  52. Knot(const Point3F &p, const QuatF &r, F32 s, Knot::Type type = NORMAL, Knot::Path path = SPLINE);
  53. };
  54. CameraSpline();
  55. ~CameraSpline();
  56. bool isEmpty() { return (mFront == NULL); }
  57. S32 size() { return mSize; }
  58. Knot* remove(Knot *w);
  59. void removeAll();
  60. Knot* front() { return mFront; }
  61. Knot* back() { return (mFront == NULL) ? NULL : mFront->prev; }
  62. void push_back(Knot *w);
  63. void push_front(Knot *w) { push_back(w); mFront = w; mIsMapDirty = true; }
  64. Knot* getKnot(S32 i);
  65. Knot* next(Knot *k) { return (k->next == mFront) ? k : k->next; }
  66. Knot* prev(Knot *k) { return (k == mFront) ? k : k->prev; }
  67. F32 advanceTime(F32 t, S32 delta_ms);
  68. F32 advanceDist(F32 t, F32 meters);
  69. void value(F32 t, Knot *result, bool skip_rotation=false);
  70. F32 getDistance(F32 t);
  71. F32 getTime(F32 d);
  72. void renderTimeMap();
  73. private:
  74. Knot *mFront;
  75. S32 mSize;
  76. bool mIsMapDirty;
  77. struct TimeMap {
  78. F32 mTime;
  79. F32 mDistance;
  80. };
  81. Vector<TimeMap> mTimeMap;
  82. void buildTimeMap();
  83. };
  84. #endif