Panda3D
|
00001 // Filename: linearRandomForce.I 00002 // Created by: charles (19Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function : random_unit_vector 00017 // Access : Protected 00018 // Description : generates a random unit vector 00019 //////////////////////////////////////////////////////////////////// 00020 INLINE LVector3f LinearRandomForce:: 00021 random_unit_vector() { 00022 float z, r, theta; 00023 00024 z = 1.0f - (2.0f * bounded_rand()); 00025 r = sqrtf(1.0f - (z * z)); 00026 theta = 2.0f * 3.1415926f * bounded_rand(); 00027 00028 return LVector3f(r * cosf(theta), r * sinf(theta), z); 00029 } 00030