~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_CameraActuator.cpp

Tags: upstream-2.40
ImportĀ upstreamĀ versionĀ 2.40

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
 * KX_CameraActuator.cpp
3
3
 *
4
 
 * $Id: KX_CameraActuator.cpp,v 1.7 2004/11/22 10:19:19 kester Exp $
 
4
 * $Id: KX_CameraActuator.cpp,v 1.9 2005/03/09 19:45:59 lukep Exp $
5
5
 *
6
6
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
7
7
 *
52
52
 
53
53
KX_CameraActuator::KX_CameraActuator(
54
54
        SCA_IObject* gameobj, 
55
 
        const CValue *obj,
 
55
        CValue *obj,
56
56
        MT_Scalar hght,
57
57
        MT_Scalar minhght,
58
58
        MT_Scalar maxhght,
66
66
        m_maxHeight (maxhght),
67
67
        m_x (xytog)
68
68
{
69
 
        // nothing to do
70
69
}
71
70
 
72
71
KX_CameraActuator::~KX_CameraActuator()
90
89
 
91
90
/* three functions copied from blender arith... don't know if there's an equivalent */
92
91
 
93
 
float Normalise(float *n)
 
92
static float Kx_Normalise(float *n)
94
93
{
95
94
        float d;
96
95
        
109
108
        return d;
110
109
}
111
110
 
112
 
void Crossf(float *c, float *a, float *b)
 
111
static void Kx_Crossf(float *c, float *a, float *b)
113
112
{
114
113
        c[0] = a[1] * b[2] - a[2] * b[1];
115
114
        c[1] = a[2] * b[0] - a[0] * b[2];
117
116
}
118
117
 
119
118
 
120
 
void VecUpMat3(float *vec, float mat[][3], short axis)
 
119
static void Kx_VecUpMat3(float *vec, float mat[][3], short axis)
121
120
{
122
121
 
123
122
        // Construct a camera matrix s.t. the specified axis
159
158
        mat[coz][0]= vec[0];
160
159
        mat[coz][1]= vec[1];
161
160
        mat[coz][2]= vec[2];
162
 
        Normalise((float *)mat[coz]);
 
161
        Kx_Normalise((float *)mat[coz]);
163
162
        
164
163
        inp= mat[coz][2];
165
164
        mat[coy][0]= - inp*mat[coz][0];
166
165
        mat[coy][1]= - inp*mat[coz][1];
167
166
        mat[coy][2]= 1.0 - inp*mat[coz][2];
168
167
 
169
 
        Normalise((float *)mat[coy]);
 
168
        Kx_Normalise((float *)mat[coy]);
170
169
        
171
 
        Crossf(mat[cox], mat[coy], mat[coz]);
 
170
        Kx_Crossf(mat[cox], mat[coy], mat[coz]);
172
171
        
173
172
}
174
173
 
294
293
        rc[0]= (lookat[0]-from[0]);
295
294
        rc[1]= (lookat[1]-from[1]);
296
295
        rc[2]= (lookat[2]-from[2]);
297
 
        VecUpMat3(rc, mat, 3);  /* y up Track -z */
 
296
        Kx_VecUpMat3(rc, mat, 3);       /* y up Track -z */
298
297
        
299
298
 
300
299
 
359
358
};
360
359
 
361
360
PyMethodDef KX_CameraActuator::Methods[] = {
 
361
        {"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_VARARGS,       SetObject_doc},
 
362
        {"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_NOARGS,        GetObject_doc},
 
363
        {"setMin"       ,(PyCFunction) KX_CameraActuator::sPySetMin,    METH_VARARGS,   SetMin_doc},
 
364
        {"getMin"       ,(PyCFunction) KX_CameraActuator::sPyGetMin,    METH_NOARGS,    GetMin_doc},
 
365
        {"setMax"       ,(PyCFunction) KX_CameraActuator::sPySetMax,    METH_VARARGS,   SetMax_doc},
 
366
        {"getMax"       ,(PyCFunction) KX_CameraActuator::sPyGetMax,    METH_NOARGS,    GetMax_doc},
 
367
        {"setHeight",(PyCFunction) KX_CameraActuator::sPySetHeight,     METH_VARARGS,   SetHeight_doc},
 
368
        {"getHeight",(PyCFunction) KX_CameraActuator::sPyGetHeight,     METH_NOARGS,    GetHeight_doc},
 
369
        {"setXY"        ,(PyCFunction) KX_CameraActuator::sPySetXY,             METH_VARARGS,   SetXY_doc},
 
370
        {"getXY"        ,(PyCFunction) KX_CameraActuator::sPyGetXY,     METH_VARARGS,   GetXY_doc},
362
371
        {NULL,NULL,NULL,NULL} //Sentinel
363
372
};
364
373
 
365
374
PyObject* KX_CameraActuator::_getattr(const STR_String& attr) {
366
375
        _getattr_up(SCA_IActuator);
367
376
}
368
 
 
 
377
/* get obj  ---------------------------------------------------------- */
 
378
char KX_CameraActuator::GetObject_doc[] = 
 
379
"getObject\n"
 
380
"\tReturns the object this sensor reacts to.\n";
 
381
PyObject* KX_CameraActuator::PyGetObject(PyObject* self, 
 
382
                                                                                PyObject* args, 
 
383
                                                                                PyObject* kwds)
 
384
{
 
385
        return PyString_FromString(m_ob->GetName());
 
386
}
 
387
/* set obj  ---------------------------------------------------------- */
 
388
char KX_CameraActuator::SetObject_doc[] = 
 
389
"setObject\n"
 
390
"\tSets the object this sensor reacts to.\n";
 
391
PyObject* KX_CameraActuator::PySetObject(PyObject* self, 
 
392
                                                                                PyObject* args, 
 
393
                                                                                PyObject* kwds)
 
394
{
 
395
    
 
396
        PyObject* gameobj;
 
397
        if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
 
398
        {
 
399
                m_ob = (CValue*)gameobj;
 
400
                Py_Return;
 
401
        }
 
402
        PyErr_Clear();
 
403
        
 
404
        char* objectname;
 
405
        if (PyArg_ParseTuple(args, "s", &objectname))
 
406
        {
 
407
                CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
 
408
                if(object)
 
409
                {
 
410
                        m_ob = object;
 
411
                        Py_Return;
 
412
                }
 
413
        }
 
414
        
 
415
        return NULL;
 
416
}
 
417
 
 
418
/* get min  ---------------------------------------------------------- */
 
419
char KX_CameraActuator::GetMin_doc[] = 
 
420
"getMin\n"
 
421
"\tReturns the minimum value set in the Min: field.\n";
 
422
PyObject* KX_CameraActuator::PyGetMin(PyObject* self, 
 
423
                                                                                PyObject* args, 
 
424
                                                                                PyObject* kwds)
 
425
{
 
426
        return PyFloat_FromDouble(m_minHeight);
 
427
}
 
428
/* set min  ---------------------------------------------------------- */
 
429
char KX_CameraActuator::SetMin_doc[] = 
 
430
"setMin\n"
 
431
"\tSets the minimum value.\n";
 
432
PyObject* KX_CameraActuator::PySetMin(PyObject* self, 
 
433
                                                                                PyObject* args, 
 
434
                                                                                PyObject* kwds)
 
435
{
 
436
        float min;
 
437
        if(PyArg_ParseTuple(args,"f", &min))
 
438
        {
 
439
                m_minHeight = min;
 
440
                Py_Return;
 
441
        }
 
442
        return NULL;
 
443
}
 
444
/* get min  ---------------------------------------------------------- */
 
445
char KX_CameraActuator::GetMax_doc[] = 
 
446
"getMax\n"
 
447
"\tReturns the maximum value set in the Max: field.\n";
 
448
PyObject* KX_CameraActuator::PyGetMax(PyObject* self, 
 
449
                                                                                PyObject* args, 
 
450
                                                                                PyObject* kwds)
 
451
{
 
452
        return PyFloat_FromDouble(m_maxHeight);
 
453
}
 
454
/* set min  ---------------------------------------------------------- */
 
455
char KX_CameraActuator::SetMax_doc[] = 
 
456
"setMax\n"
 
457
"\tSets the maximum value.\n";
 
458
PyObject* KX_CameraActuator::PySetMax(PyObject* self, 
 
459
                                                                                PyObject* args, 
 
460
                                                                                PyObject* kwds)
 
461
{
 
462
        float max;
 
463
        if(PyArg_ParseTuple(args,"f", &max))
 
464
        {
 
465
                m_maxHeight = max;
 
466
                Py_Return;
 
467
        }
 
468
        return NULL;
 
469
}
 
470
/* get height  ---------------------------------------------------------- */
 
471
char KX_CameraActuator::GetHeight_doc[] = 
 
472
"getHeight\n"
 
473
"\tReturns the height value set in the height: field.\n";
 
474
PyObject* KX_CameraActuator::PyGetHeight(PyObject* self, 
 
475
                                                                                PyObject* args, 
 
476
                                                                                PyObject* kwds)
 
477
{
 
478
        return PyFloat_FromDouble(m_height);
 
479
}
 
480
/* set height  ---------------------------------------------------------- */
 
481
char KX_CameraActuator::SetHeight_doc[] = 
 
482
"setHeight\n"
 
483
"\tSets the height value.\n";
 
484
PyObject* KX_CameraActuator::PySetHeight(PyObject* self, 
 
485
                                                                                PyObject* args, 
 
486
                                                                                PyObject* kwds)
 
487
{
 
488
        float height;
 
489
        if(PyArg_ParseTuple(args,"f", &height))
 
490
        {
 
491
                m_height = height;
 
492
                Py_Return;
 
493
        }
 
494
        return NULL;
 
495
}
 
496
/* set XY  ---------------------------------------------------------- */
 
497
char KX_CameraActuator::SetXY_doc[] = 
 
498
"setXY\n"
 
499
"\tSets axis the camera tries to get behind.\n"
 
500
"\t1=x, 0=y\n";
 
501
PyObject* KX_CameraActuator::PySetXY(PyObject* self, 
 
502
                                                                                PyObject* args, 
 
503
                                                                                PyObject* kwds)
 
504
{
 
505
        int value;
 
506
        if(PyArg_ParseTuple(args,"i", &value))
 
507
        {
 
508
                m_x = value != 0;
 
509
                Py_Return;
 
510
        }
 
511
        return NULL;
 
512
}
 
513
 
 
514
/* get XY -------------------------------------------------------------*/
 
515
char KX_CameraActuator::GetXY_doc[] =
 
516
"getXY\n"
 
517
"\tGets the axis the camera tries to get behind.\n"
 
518
"\tTrue = X, False = Y\n";
 
519
PyObject* KX_CameraActuator::PyGetXY(PyObject* self,
 
520
                                                                                PyObject* args, 
 
521
                                                                                PyObject* kwds)
 
522
{
 
523
        return PyInt_FromLong(m_x);
 
524
}
369
525
 
370
526
/* eof */