Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Mass.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Hel
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Mass
  9. * License : No use w/o permission (C) 2003 Mongoose
  10. * Comments: This is the class that has the mass - oh yass
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History -------------------------------------------------
  17. *
  18. * 2003.06.02:
  19. * Mongoose - Created, based on algorithms from Erkin Tunca
  20. =================================================================*/
  21. #include "Mass.h"
  22. ////////////////////////////////////////////////////////////
  23. // Constructors
  24. ////////////////////////////////////////////////////////////
  25. Mass::Mass()
  26. {
  27. mMass = 0.0;
  28. }
  29. Mass::Mass(vec_t mass)
  30. {
  31. mMass = mass;
  32. }
  33. Mass::Mass(vec_t mass, const Vector3d &position, const Vector3d &velocity)
  34. {
  35. mMass = mass;
  36. mPos = position;
  37. mVelocity = velocity;
  38. }
  39. Mass::~Mass()
  40. {
  41. }
  42. ////////////////////////////////////////////////////////////
  43. // Public Accessors
  44. ////////////////////////////////////////////////////////////
  45. ////////////////////////////////////////////////////////////
  46. // Public Mutators
  47. ////////////////////////////////////////////////////////////
  48. void Mass::applyForce(Vector3d force)
  49. {
  50. mForce += force;
  51. }
  52. void Mass::rest()
  53. {
  54. mForce = Vector3d(0, 0, 0);
  55. }
  56. void Mass::simulate(vec_t timeDelta)
  57. {
  58. // The Euler Method, hhmmm... for now
  59. // Update velocity
  60. mVelocity += (mForce / mMass) * timeDelta;
  61. // Update position, position = velocity * time delta
  62. mPos += mVelocity * timeDelta;
  63. }
  64. ////////////////////////////////////////////////////////////
  65. // Private Accessors
  66. ////////////////////////////////////////////////////////////
  67. ////////////////////////////////////////////////////////////
  68. // Private Mutators
  69. ////////////////////////////////////////////////////////////
  70. ////////////////////////////////////////////////////////////
  71. // Unit Test code
  72. ////////////////////////////////////////////////////////////
  73. #ifdef UNIT_TEST_MASS
  74. int runMassUnitTest(int argc, char *argv[])
  75. {
  76. Mass test;
  77. return 0;
  78. }
  79. int main(int argc, char *argv[])
  80. {
  81. printf("[Mass class test]\n");
  82. runMassUnitTest(argc, argv);
  83. return 0;
  84. }
  85. #endif