Python methods for camera actuators (thanks snailrose)
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Wed, 29 Dec 2004 01:33:15 +0000 (01:33 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Wed, 29 Dec 2004 01:33:15 +0000 (01:33 +0000)
source/gameengine/Ketsji/KX_CameraActuator.cpp
source/gameengine/Ketsji/KX_CameraActuator.h
source/gameengine/PyDoc/KX_CameraActuator.py

index 4952c1050a78ebe17282a68ad7653fa6d2e6e3fa..328352b70a204e3d55138b89450e8eaa70a07877 100644 (file)
@@ -52,7 +52,7 @@ STR_String KX_CameraActuator::Y_AXIS_STRING = "y";
 
 KX_CameraActuator::KX_CameraActuator(
        SCA_IObject* gameobj, 
 
 KX_CameraActuator::KX_CameraActuator(
        SCA_IObject* gameobj, 
-       const CValue *obj,
+       CValue *obj,
        MT_Scalar hght,
        MT_Scalar minhght,
        MT_Scalar maxhght,
        MT_Scalar hght,
        MT_Scalar minhght,
        MT_Scalar maxhght,
@@ -66,7 +66,6 @@ KX_CameraActuator::KX_CameraActuator(
        m_maxHeight (maxhght),
        m_x (xytog)
 {
        m_maxHeight (maxhght),
        m_x (xytog)
 {
-       // nothing to do
 }
 
 KX_CameraActuator::~KX_CameraActuator()
 }
 
 KX_CameraActuator::~KX_CameraActuator()
@@ -359,12 +358,169 @@ PyParentObject KX_CameraActuator::Parents[] = {
 };
 
 PyMethodDef KX_CameraActuator::Methods[] = {
 };
 
 PyMethodDef KX_CameraActuator::Methods[] = {
+       {"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_VARARGS,       SetObject_doc},
+       {"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_NOARGS,        GetObject_doc},
+       {"setMin"       ,(PyCFunction) KX_CameraActuator::sPySetMin,    METH_VARARGS,   SetMin_doc},
+       {"getMin"       ,(PyCFunction) KX_CameraActuator::sPyGetMin,    METH_NOARGS,    GetMin_doc},
+       {"setMax"       ,(PyCFunction) KX_CameraActuator::sPySetMax,    METH_VARARGS,   SetMax_doc},
+       {"getMax"       ,(PyCFunction) KX_CameraActuator::sPyGetMax,    METH_NOARGS,    GetMax_doc},
+       {"setHeight",(PyCFunction) KX_CameraActuator::sPySetHeight,     METH_VARARGS,   SetHeight_doc},
+       {"getHeight",(PyCFunction) KX_CameraActuator::sPyGetHeight,     METH_NOARGS,    GetHeight_doc},
+       {"setXY"        ,(PyCFunction) KX_CameraActuator::sPySetXY,             METH_VARARGS,   SetXY_doc},
+       {"getXY"        ,(PyCFunction) KX_CameraActuator::sPyGetXY,     METH_VARARGS,   GetXY_doc},
        {NULL,NULL,NULL,NULL} //Sentinel
 };
 
 PyObject* KX_CameraActuator::_getattr(const STR_String& attr) {
        _getattr_up(SCA_IActuator);
 }
        {NULL,NULL,NULL,NULL} //Sentinel
 };
 
 PyObject* KX_CameraActuator::_getattr(const STR_String& attr) {
        _getattr_up(SCA_IActuator);
 }
+/* get obj  ---------------------------------------------------------- */
+char KX_CameraActuator::GetObject_doc[] = 
+"getObject\n"
+"\tReturns the object this sensor reacts to.\n";
+PyObject* KX_CameraActuator::PyGetObject(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       return PyString_FromString(m_ob->GetName());
+}
+/* set obj  ---------------------------------------------------------- */
+char KX_CameraActuator::SetObject_doc[] = 
+"setObject\n"
+"\tSets the object this sensor reacts to.\n";
+PyObject* KX_CameraActuator::PySetObject(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+    
+       PyObject* gameobj;
+       if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
+       {
+               m_ob = (CValue*)gameobj;
+               Py_Return;
+       }
+       PyErr_Clear();
+       
+       char* objectname;
+       if (PyArg_ParseTuple(args, "s", &objectname))
+       {
+               CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
+               if(object)
+               {
+                       m_ob = object;
+                       Py_Return;
+               }
+       }
+       
+       return NULL;
+}
 
 
+/* get min  ---------------------------------------------------------- */
+char KX_CameraActuator::GetMin_doc[] = 
+"getMin\n"
+"\tReturns the minimum value set in the Min: field.\n";
+PyObject* KX_CameraActuator::PyGetMin(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       return PyFloat_FromDouble(m_minHeight);
+}
+/* set min  ---------------------------------------------------------- */
+char KX_CameraActuator::SetMin_doc[] = 
+"setMin\n"
+"\tSets the minimum value.\n";
+PyObject* KX_CameraActuator::PySetMin(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       float min;
+       if(PyArg_ParseTuple(args,"f", &min))
+       {
+               m_minHeight = min;
+               Py_Return;
+       }
+       return NULL;
+}
+/* get min  ---------------------------------------------------------- */
+char KX_CameraActuator::GetMax_doc[] = 
+"getMax\n"
+"\tReturns the maximum value set in the Max: field.\n";
+PyObject* KX_CameraActuator::PyGetMax(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       return PyFloat_FromDouble(m_maxHeight);
+}
+/* set min  ---------------------------------------------------------- */
+char KX_CameraActuator::SetMax_doc[] = 
+"setMax\n"
+"\tSets the maximum value.\n";
+PyObject* KX_CameraActuator::PySetMax(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       float max;
+       if(PyArg_ParseTuple(args,"f", &max))
+       {
+               m_maxHeight = max;
+               Py_Return;
+       }
+       return NULL;
+}
+/* get height  ---------------------------------------------------------- */
+char KX_CameraActuator::GetHeight_doc[] = 
+"getHeight\n"
+"\tReturns the height value set in the height: field.\n";
+PyObject* KX_CameraActuator::PyGetHeight(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       return PyFloat_FromDouble(m_height);
+}
+/* set height  ---------------------------------------------------------- */
+char KX_CameraActuator::SetHeight_doc[] = 
+"setHeight\n"
+"\tSets the height value.\n";
+PyObject* KX_CameraActuator::PySetHeight(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       float height;
+       if(PyArg_ParseTuple(args,"f", &height))
+       {
+               m_height = height;
+               Py_Return;
+       }
+       return NULL;
+}
+/* set XY  ---------------------------------------------------------- */
+char KX_CameraActuator::SetXY_doc[] = 
+"setXY\n"
+"\tSets axis the camera tries to get behind.\n"
+"\t1=x, 0=y\n";
+PyObject* KX_CameraActuator::PySetXY(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       int value;
+       if(PyArg_ParseTuple(args,"i", &value))
+       {
+               m_x = value != 0;
+               Py_Return;
+       }
+       return NULL;
+}
+
+/* get XY -------------------------------------------------------------*/
+char KX_CameraActuator::GetXY_doc[] =
+"getXY\n"
+"\tGets the axis the camera tries to get behind.\n"
+"\tTrue = X, False = Y\n";
+PyObject* KX_CameraActuator::PyGetXY(PyObject* self,
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       return PyInt_FromLong(m_x);
+}
 
 /* eof */
 
 /* eof */
index 68bc91694e7dc4fb6d51dded68dd3ad942d2282f..27d8a77b28d4d788e614057d59b9630943cd56e3 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "SCA_IActuator.h"
 #include "MT_Scalar.h"
 
 #include "SCA_IActuator.h"
 #include "MT_Scalar.h"
+#include "SCA_LogicManager.h"
 
 /**
  * The camera actuator does a Robbie Muller prespective for you. This is a 
 
 /**
  * The camera actuator does a Robbie Muller prespective for you. This is a 
@@ -51,16 +52,23 @@ class KX_CameraActuator : public SCA_IActuator
        Py_Header;
 private :
        /** Object that will be tracked. */
        Py_Header;
 private :
        /** Object that will be tracked. */
-       const CValue *m_ob;
+       CValue *m_ob;
 
        /** height (float), */
 
        /** height (float), */
-       const MT_Scalar m_height;
+       //const MT_Scalar m_height;
+       /** min (float), */
+       //const MT_Scalar m_minHeight;
+       /** max (float), */
+       //const MT_Scalar m_maxHeight;
+       
+       /** height (float), */
+       MT_Scalar m_height;
        
        /** min (float), */
        
        /** min (float), */
-       const MT_Scalar m_minHeight;
+       MT_Scalar m_minHeight;
        
        /** max (float), */
        
        /** max (float), */
-       const MT_Scalar m_maxHeight;
+       MT_Scalar m_maxHeight;
        
        /** xy toggle (pick one): true == x, false == y */
        bool m_x;
        
        /** xy toggle (pick one): true == x, false == y */
        bool m_x;
@@ -81,7 +89,8 @@ private :
        KX_CameraActuator(
 
                SCA_IObject *gameobj,
        KX_CameraActuator(
 
                SCA_IObject *gameobj,
-               const CValue *ob,
+               //const CValue *ob,
+               CValue *ob,
                MT_Scalar hght,
                MT_Scalar minhght,
                MT_Scalar maxhght,
                MT_Scalar hght,
                MT_Scalar minhght,
                MT_Scalar maxhght,
@@ -111,8 +120,19 @@ private :
        /* --------------------------------------------------------------------- */
 
        virtual PyObject* _getattr(const STR_String& attr);
        /* --------------------------------------------------------------------- */
 
        virtual PyObject* _getattr(const STR_String& attr);
-
        
        
+       /* set object to look at */
+       KX_PYMETHOD_DOC(KX_CameraActuator,SetObject);
+       /* get current object  */
+       KX_PYMETHOD_DOC(KX_CameraActuator,GetObject);
+       KX_PYMETHOD_DOC(KX_CameraActuator,SetMin);
+       KX_PYMETHOD_DOC(KX_CameraActuator,GetMin);
+       KX_PYMETHOD_DOC(KX_CameraActuator,SetMax);
+       KX_PYMETHOD_DOC(KX_CameraActuator,GetMax);
+       KX_PYMETHOD_DOC(KX_CameraActuator,SetHeight);
+       KX_PYMETHOD_DOC(KX_CameraActuator,GetHeight);
+       KX_PYMETHOD_DOC(KX_CameraActuator,SetXY);
+       KX_PYMETHOD_DOC(KX_CameraActuator,GetXY);
 
 };
 
 
 };
 
index 236befdb1f6b882613afca8089767145cc15d8b3..032fc7338acac9e6a2c8fb54b01e220a1ef8cfc7 100644 (file)
@@ -6,6 +6,81 @@ class KX_CameraActuator(SCA_IActuator):
        """
        Applies changes to a camera.
        
        """
        Applies changes to a camera.
        
-       This actuator has no python methods.
+       @author: snail
        """
        """
+       def getObject():
+               """
+               Returns the name of the object this actuator tracks.
+               
+               rtype: string
+               """
+       
+       def setObject(target):
+               """
+               Sets the object this actuator tracks.
+               
+               @param target: the object to track.
+               @type target: string or L{KX_GameObject}
+               """
+       
+       def getMin():
+               """
+               Returns the minimum distance to target maintained by the actuator.
+               
+               @rtype: float
+               """
+       
+       def setMin(distance):
+               """
+               Sets the minimum distance to the target object maintained by the
+               actuator.
+               
+               @param distance: The minimum distance to maintain.
+               @type distance: float
+               """
+               
+       def getMax():
+               """
+               Gets the maximum distance to stay from the target object.
+               
+               @rtype: float
+               """
+       
+       def setMax(distance):
+               """
+               Sets the maximum distance to stay from the target object.
+               
+               @param distance: The maximum distance to maintain.
+               @type distance: float
+               """
+
+       def getHeight():
+               """
+               Returns the height to stay above the target object.
+               
+               @rtype: float
+               """
+       
+       def setHeight(height):
+               """
+               Sets the height to stay above the target object.
+               
+               @type height: float
+               @param height: The height to stay above the target object.
+               """
+       
+       def setXY(xaxis):
+               """
+               Sets the axis to get behind.
+               
+               @param xaxis: False to track Y axis, True to track X axis.
+               @type xaxis: boolean
+               """
 
 
+       def getXY():
+               """
+               Returns the axis this actuator is tracking.
+               
+               @return: True if tracking X axis, False if tracking Y axis.
+               @rtype: boolean
+               """