~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/SCA_RandomActuator.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
 
1
/*
2
2
 * Set random/camera stuff
3
3
 *
4
 
 * $Id: SCA_RandomActuator.cpp 28254 2010-04-18 10:28:37Z campbellbarton $
5
4
 *
6
5
 * ***** BEGIN GPL LICENSE BLOCK *****
7
6
 *
29
28
 * ***** END GPL LICENSE BLOCK *****
30
29
 */
31
30
 
 
31
/** \file gameengine/GameLogic/SCA_RandomActuator.cpp
 
32
 *  \ingroup gamelogic
 
33
 */
 
34
 
 
35
 
 
36
#include <stddef.h>
 
37
 
32
38
#include "BoolValue.h"
33
39
#include "IntValue.h"
34
40
#include "FloatValue.h"
145
151
                /* If x_1, x_2, ... is a sequence of random numbers with uniform     */
146
152
                /* distribution between zero and one, k is the first integer for     */
147
153
                /* which the product x_1*x_2*...*x_k < exp(-\lamba).                 */
148
 
                float a = 0.0, b = 0.0;
 
154
                float a, b;
149
155
                int res = 0;
150
156
                /* The - sign is important here! The number to test for, a, must be  */
151
157
                /* between 0 and 1.                                                  */
200
206
                          sensible values. The termination condition states two 
201
207
                          things: 
202
208
                          1. s >= 0 is not allowed: to prevent the distro from 
203
 
                             getting a bias towards high values. This is a small 
 
209
                                 getting a bias towards high values. This is a small
204
210
                                 correction, really, and might also be left out.
205
211
                          2. s == 0 is not allowed: to prevent a division by zero
206
 
                             when renormalising the drawn value to the desired 
 
212
                                 when renormalising the drawn value to the desired
207
213
                                 distribution shape. As a side effect, the distro will
208
214
                                 never yield the exact mean. 
209
215
                          I am not sure whether this is consistent, since the error 
260
266
        return false;
261
267
}
262
268
 
263
 
void SCA_RandomActuator::enforceConstraints() {
 
269
void SCA_RandomActuator::enforceConstraints()
 
270
{
264
271
        /* The constraints that are checked here are the ones fundamental to     */
265
272
        /* the various distributions. Limitations of the algorithms are checked  */
266
273
        /* elsewhere (or they should be... ).                                    */
305
312
        }
306
313
}
307
314
 
308
 
#ifndef DISABLE_PYTHON
 
315
#ifdef WITH_PYTHON
309
316
 
310
317
/* ------------------------------------------------------------------------- */
311
318
/* Python functions                                                          */
354
361
        KX_PYATTRIBUTE_FLOAT_RO("para1",SCA_RandomActuator,m_parameter1),
355
362
        KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2),
356
363
        KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution),
357
 
        KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,100,false,SCA_RandomActuator,m_propname,CheckProperty),
 
364
        KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_RandomActuator,m_propname,CheckProperty),
358
365
        KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed),
359
366
        { NULL }        //Sentinel
360
367
};      
385
392
"\tSet this generator to produce a constant boolean value.\n") 
386
393
{
387
394
        int paraArg;
388
 
        if(!PyArg_ParseTuple(args, "i:setBoolConst", &paraArg)) {
 
395
        if (!PyArg_ParseTuple(args, "i:setBoolConst", &paraArg)) {
389
396
                return NULL;
390
397
        }
391
398
        
397
404
/* 12. setBoolUniform, */
398
405
KX_PYMETHODDEF_DOC_NOARGS(SCA_RandomActuator, setBoolUniform,
399
406
"setBoolUniform()\n"
400
 
"\tSet this generator to produce true and false, each with 50%% chance of occuring\n") 
 
407
"\tSet this generator to produce true and false, each with 50%% chance of occurring\n") 
401
408
{
402
409
        /* no args */
403
410
        m_distribution = KX_RANDOMACT_BOOL_UNIFORM;
411
418
"\tReturn false value * 100%% of the time.\n")
412
419
{
413
420
        float paraArg;
414
 
        if(!PyArg_ParseTuple(args, "f:setBoolBernouilli", &paraArg)) {
 
421
        if (!PyArg_ParseTuple(args, "f:setBoolBernouilli", &paraArg)) {
415
422
                return NULL;
416
423
        }
417
424
        
427
434
"\tAlways return value\n") 
428
435
{
429
436
        int paraArg;
430
 
        if(!PyArg_ParseTuple(args, "i:setIntConst", &paraArg)) {
 
437
        if (!PyArg_ParseTuple(args, "i:setIntConst", &paraArg)) {
431
438
                return NULL;
432
439
        }
433
440
        
445
452
"\tupper_bound. The boundaries are included.\n")
446
453
{
447
454
        int paraArg1, paraArg2;
448
 
        if(!PyArg_ParseTuple(args, "ii:setIntUniform", &paraArg1, &paraArg2)) {
 
455
        if (!PyArg_ParseTuple(args, "ii:setIntUniform", &paraArg1, &paraArg2)) {
449
456
                return NULL;
450
457
        }
451
458
        
464
471
"\tnumber of tries needed to achieve succes.\n")
465
472
{
466
473
        float paraArg;
467
 
        if(!PyArg_ParseTuple(args, "f:setIntPoisson", &paraArg)) {
 
474
        if (!PyArg_ParseTuple(args, "f:setIntPoisson", &paraArg)) {
468
475
                return NULL;
469
476
        }
470
477
        
480
487
"\tAlways return value\n")
481
488
{
482
489
        float paraArg;
483
 
        if(!PyArg_ParseTuple(args, "f:setFloatConst", &paraArg)) {
 
490
        if (!PyArg_ParseTuple(args, "f:setFloatConst", &paraArg)) {
484
491
                return NULL;
485
492
        }
486
493
        
498
505
"\tupper_bound.\n")
499
506
{
500
507
        float paraArg1, paraArg2;
501
 
        if(!PyArg_ParseTuple(args, "ff:setFloatUniform", &paraArg1, &paraArg2)) {
 
508
        if (!PyArg_ParseTuple(args, "ff:setFloatUniform", &paraArg1, &paraArg2)) {
502
509
                return NULL;
503
510
        }
504
511
        
517
524
"\tdeviation from the mean is characterized by standard_deviation.\n")
518
525
{
519
526
        float paraArg1, paraArg2;
520
 
        if(!PyArg_ParseTuple(args, "ff:setFloatNormal", &paraArg1, &paraArg2)) {
 
527
        if (!PyArg_ParseTuple(args, "ff:setFloatNormal", &paraArg1, &paraArg2)) {
521
528
                return NULL;
522
529
        }
523
530
        
535
542
"\tis characterized by half_life.\n")
536
543
{
537
544
        float paraArg;
538
 
        if(!PyArg_ParseTuple(args, "f:setFloatNegativeExponential", &paraArg)) {
 
545
        if (!PyArg_ParseTuple(args, "f:setFloatNegativeExponential", &paraArg)) {
539
546
                return NULL;
540
547
        }
541
548