cameraSpline.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. String mHitCommand;
  37. enum Type {
  38. NORMAL,
  39. POSITION_ONLY,
  40. KINK,
  41. NUM_TYPE_BITS = 2
  42. }mType;
  43. enum Path {
  44. LINEAR,
  45. SPLINE,
  46. NUM_PATH_BITS = 1
  47. }mPath;
  48. F32 mDistance;
  49. Knot *prev;
  50. Knot *next;
  51. Knot();
  52. Knot(const Knot &k);
  53. Knot(const Point3F &p, const QuatF &r, F32 s, Knot::Type type = NORMAL, Knot::Path path = SPLINE, String hitCommand = String::EmptyString);
  54. };
  55. CameraSpline();
  56. ~CameraSpline();
  57. bool isEmpty() { return (mFront == NULL); }
  58. S32 size() { return mSize; }
  59. Knot* remove(Knot *w);
  60. void removeAll();
  61. Knot* front() { return mFront; }
  62. Knot* back() { return (mFront == NULL) ? NULL : mFront->prev; }
  63. void push_back(Knot *w);
  64. void push_front(Knot *w) { push_back(w); mFront = w; mIsMapDirty = true; }
  65. Knot* getKnot(S32 i);
  66. Knot* next(Knot *k) { return (k && k->next == mFront) ? k : k->next; }
  67. Knot* prev(Knot *k) { return (k && k == mFront) ? k : k->prev; }
  68. F32 advanceTime(F32 t, S32 delta_ms);
  69. F32 advanceDist(F32 t, F32 meters);
  70. void value(F32 t, Knot *result, bool skip_rotation=false);
  71. F32 getDistance(F32 t);
  72. F32 getTime(F32 d);
  73. void renderTimeMap();
  74. private:
  75. Knot *mFront;
  76. S32 mSize;
  77. bool mIsMapDirty;
  78. struct TimeMap {
  79. F32 mTime;
  80. F32 mDistance;
  81. };
  82. Vector<TimeMap> mTimeMap;
  83. void buildTimeMap();
  84. };
  85. #endif