[Teleus-cvs] teleus/src/obj cube.cpp,1.8,1.9
Status: Inactive
Brought to you by:
spiffgq
|
From: <sp...@us...> - 2004-03-11 03:39:07
|
Update of /cvsroot/teleus/teleus/src/obj In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9439/src/obj Modified Files: cube.cpp Log Message: Removed randFloat(); replaced with math::Random class. We have a problem, though. The Random class uses /dev/urandom to randomly seed the generator. A new generator is created each time the method is called, so it needs a new seed each time. No problem. But if the platform has no /dev/urandom (*cough*windows*cough*), then Random falls back to the time() function. If Random uses the time() function, then all of the randomly generated cubes will be identical. 2000 identical cubes. The optimal solution would be to replace the time() call with an equivalent to /dev/urandom. If that is impossible, then we will have to replace the Random class in Cube::getRandomCube() with a static instance that is only seeded once. Index: cube.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/cube.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** cube.cpp 25 Feb 2004 02:23:26 -0000 1.8 --- cube.cpp 11 Mar 2004 03:20:42 -0000 1.9 *************** *** 29,32 **** --- 29,33 ---- #include "math/vector.hpp" #include "math/physics.hpp" + #include "math/random.hpp" #include "debug.hpp" *************** *** 116,119 **** --- 117,122 ---- Cube * Cube::getRandomCube (){ + math::Random rand; + gfx::Color3f color; math::Vector3d dimensions; *************** *** 130,150 **** color = gfx::Color3f( ! math::randFloat (0.0f, 1.0f), ! math::randFloat (0.0f, 1.0f), ! math::randFloat (0.0f, 1.0f)); ! dimensions.x = math::randFloat (10.0f, 100.0f); ! dimensions.y = math::randFloat (10.0f, 100.0f); ! dimensions.z = math::randFloat (10.0f, 100.0f); const double MAX_POSITION = 4000.0f; ! position.x = math::randFloat (-MAX_POSITION, MAX_POSITION); ! position.y = math::randFloat (-MAX_POSITION, MAX_POSITION); ! position.z = math::randFloat (-MAX_POSITION, MAX_POSITION); ! orientation.x = math::randFloat (0.0f, 360.0f); ! orientation.y = math::randFloat (0.0f, 360.0f); ! orientation.z = math::randFloat (0.0f, 360.0f); ! angle = math::randFloat (0.0f, 360.0f); #if 0 --- 133,153 ---- color = gfx::Color3f( ! rand.floatNumber (0.0f, 1.0f), ! rand.floatNumber (0.0f, 1.0f), ! rand.floatNumber (0.0f, 1.0f)); ! dimensions.x = rand.floatNumber (10.0f, 100.0f); ! dimensions.y = rand.floatNumber (10.0f, 100.0f); ! dimensions.z = rand.floatNumber (10.0f, 100.0f); const double MAX_POSITION = 4000.0f; ! position.x = rand.floatNumber (-MAX_POSITION, MAX_POSITION); ! position.y = rand.floatNumber (-MAX_POSITION, MAX_POSITION); ! position.z = rand.floatNumber (-MAX_POSITION, MAX_POSITION); ! orientation.x = rand.floatNumber (0.0f, 360.0f); ! orientation.y = rand.floatNumber (0.0f, 360.0f); ! orientation.z = rand.floatNumber (0.0f, 360.0f); ! angle = rand.floatNumber (0.0f, 360.0f); #if 0 *************** *** 153,164 **** velocity.z = 0.0; //math::randFloat(0.0f, 100.0f); #else ! velocity.x = math::randFloat(0.0f, 100.0f); ! velocity.y = math::randFloat(0.0f, 100.0f); ! velocity.z = math::randFloat(0.0f, 100.0f); #endif ! rotVel.x = math::randFloat (0.0f, 1.0f); ! rotVel.y = math::randFloat (0.0f, 1.0f); ! rotVel.z = math::randFloat (0.0f, 1.0f); mass = (dimensions.x * dimensions.y * dimensions.z) / 10.0f; --- 156,167 ---- velocity.z = 0.0; //math::randFloat(0.0f, 100.0f); #else ! velocity.x = rand.floatNumber (0.0f, 100.0f); ! velocity.y = rand.floatNumber (0.0f, 100.0f); ! velocity.z = rand.floatNumber (0.0f, 100.0f); #endif ! rotVel.x = rand.floatNumber (0.0f, 1.0f); ! rotVel.y = rand.floatNumber (0.0f, 1.0f); ! rotVel.z = rand.floatNumber (0.0f, 1.0f); mass = (dimensions.x * dimensions.y * dimensions.z) / 10.0f; |