00001 // Filename: builderMisc.cxx 00002 // Created by: drose (18Sep97) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "builderMisc.h" 00020 #include "builderTypes.h" 00021 00022 #include <luse.h> 00023 #include <stdlib.h> 00024 //////////////////////////////////////////////////////////////////// 00025 // Function: make_random_color 00026 // Description: Chooses a reasonable random color. 00027 //////////////////////////////////////////////////////////////////// 00028 void 00029 make_random_color(Colorf &color) { 00030 LVector3f rgb; 00031 float len; 00032 do { 00033 for (int i = 0; i < 3; i++) { 00034 rgb[i] = (double)rand() / (double)RAND_MAX; 00035 } 00036 len = length(rgb); 00037 00038 // Repeat until we have a color that's not too dark or too light. 00039 } while (len < .1 || len > 1.5); 00040 00041 #ifdef WIN32_VC 00042 color.set(rgb[0], rgb[1], rgb[2], 00043 0.25 + 0.75 * (double)rand() / (double)RAND_MAX); 00044 #else 00045 color.set(rgb[0], rgb[1], rgb[2], 00046 0.25 + 0.75 * (double)random() / (double)RAND_MAX); 00047 #endif 00048 } 00049