linearRandomForce.I 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Filename: linearRandomForce.I
  2. // Created by: charles (19Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function : random_unit_vector
  20. // Access : Protected
  21. // Description : generates a random unit vector
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE LVector3f LinearRandomForce::
  24. random_unit_vector(void) {
  25. float z, r, theta;
  26. z = 1.0f - (2.0f * bounded_rand());
  27. r = sqrtf(1.0f - (z * z));
  28. theta = 2.0f * 3.1415926f * bounded_rand();
  29. return LVector3f(r * cosf(theta), r * sinf(theta), z);
  30. }