From 7543355d1768215bdd241972d9be579f20c52b10 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 4 Apr 2003 22:38:35 +0000 Subject: [PATCH] Add new property-randomize command. Set a random value for a numeric property Params: - the name of the property to randomize - the minimum allowed value - the maximum allowed value --- src/Main/fg_commands.cxx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 8218dfa3d..cda99467a 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -9,6 +9,7 @@ #include STL_FSTREAM #include +#include #include #include #include @@ -684,6 +685,24 @@ do_property_cycle (const SGPropertyNode * arg) } +/** + * Built-in command: randomize a numeric property value. + * + * property: the name of the property value to randomize. + * min: the minimum allowed value. + * max: the maximum allowed value. + */ +static bool +do_property_randomize (const SGPropertyNode * arg) +{ + SGPropertyNode * prop = get_prop(arg); + double min = arg->getDoubleValue("min", DBL_MIN); + double max = arg->getDoubleValue("max", DBL_MAX); + prop->setDoubleValue(sg_random() * (max - min) + min); + std::cerr << "Random value is " << prop->getDoubleValue() << std::endl; +} + + /** * Built-in command: Show an XML-configured dialog. * @@ -840,6 +859,7 @@ static struct { { "property-swap", do_property_swap }, { "property-scale", do_property_scale }, { "property-cycle", do_property_cycle }, + { "property-randomize", do_property_randomize }, { "dialog-show", do_dialog_show }, { "dialog-close", do_dialog_close }, { "dialog-show", do_dialog_show }, -- 2.39.5