Add new property-randomize command.
Set a random value for a numeric property Params: <property> - the name of the property to randomize <min> - the minimum allowed value <max> - the maximum allowed value
This commit is contained in:
parent
abf660ecef
commit
7543355d17
1 changed files with 20 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include STL_FSTREAM
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/math/sg_random.h>
|
||||
#include <simgear/misc/commands.hxx>
|
||||
#include <simgear/misc/props.hxx>
|
||||
#include <simgear/sg_inlines.h>
|
||||
|
@ -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 },
|
||||
|
|
Loading…
Add table
Reference in a new issue