Game Engine: Camera Lens Shift: support to change it during game
authorDalai Felinto <dfelinto@gmail.com>
Thu, 2 Jul 2015 16:47:27 +0000 (13:47 -0300)
committerDalai Felinto <dfelinto@gmail.com>
Thu, 2 Jul 2015 16:51:30 +0000 (13:51 -0300)
doc/python_api/rst/bge_types/bge.types.KX_Camera.rst
source/gameengine/Ketsji/KX_Camera.cpp
source/gameengine/Ketsji/KX_Camera.h

index 0baba5c33591475a05358ce3add5bf112049776f..ac5ab4b5fe5acddab1dcefc55ac1a8d92c5ed649 100644 (file)
@@ -51,6 +51,18 @@ base class --- :class:`KX_GameObject`
 
       :type: float
 
+   .. attribute:: shift_x
+
+      The camera's horizontal shift.
+
+      :type: float
+
+   .. attribute:: shift_y
+
+      The camera's vertical shift.
+
+      :type: float
+
    .. attribute:: perspective
 
       True if this camera has a perspective transform, False for an orthographic projection.
index 70bcf505f2e3c917dedbb318ef3c3cd64cb2d1a0..3b69d4005cdc62633e8b444f4984d5b760433421 100644 (file)
@@ -545,7 +545,9 @@ PyAttributeDef KX_Camera::Attributes[] = {
        KX_PYATTRIBUTE_RW_FUNCTION("ortho_scale",       KX_Camera,      pyattr_get_ortho_scale, pyattr_set_ortho_scale),
        KX_PYATTRIBUTE_RW_FUNCTION("near",      KX_Camera,      pyattr_get_near, pyattr_set_near),
        KX_PYATTRIBUTE_RW_FUNCTION("far",       KX_Camera,      pyattr_get_far,  pyattr_set_far),
-       
+       KX_PYATTRIBUTE_RW_FUNCTION("shift_x",   KX_Camera,      pyattr_get_shift_x, pyattr_set_shift_x),
+       KX_PYATTRIBUTE_RW_FUNCTION("shift_y",   KX_Camera,      pyattr_get_shift_y,  pyattr_set_shift_y),
+
        KX_PYATTRIBUTE_RW_FUNCTION("useViewport",       KX_Camera,      pyattr_get_use_viewport,  pyattr_set_use_viewport),
        
        KX_PYATTRIBUTE_RW_FUNCTION("projection_matrix", KX_Camera,      pyattr_get_projection_matrix, pyattr_set_projection_matrix),
@@ -862,6 +864,45 @@ int KX_Camera::pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, P
        return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject *KX_Camera::pyattr_get_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_Camera* self = static_cast<KX_Camera*>(self_v);
+       return PyFloat_FromDouble(self->m_camdata.m_shift_x);
+}
+
+int KX_Camera::pyattr_set_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+       KX_Camera* self = static_cast<KX_Camera*>(self_v);
+       float param = PyFloat_AsDouble(value);
+       if (param == -1) {
+               PyErr_SetString(PyExc_AttributeError, "camera.shift_x = float: KX_Camera, expected a float greater than zero");
+               return PY_SET_ATTR_FAIL;
+       }
+
+       self->m_camdata.m_shift_x = param;
+       self->m_set_projection_matrix = false;
+       return PY_SET_ATTR_SUCCESS;
+}
+
+PyObject *KX_Camera::pyattr_get_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_Camera* self = static_cast<KX_Camera*>(self_v);
+       return PyFloat_FromDouble(self->m_camdata.m_shift_y);
+}
+
+int KX_Camera::pyattr_set_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+       KX_Camera* self = static_cast<KX_Camera*>(self_v);
+       float param = PyFloat_AsDouble(value);
+       if (param == -1) {
+               PyErr_SetString(PyExc_AttributeError, "camera.shift_y = float: KX_Camera, expected a float greater than zero");
+               return PY_SET_ATTR_FAIL;
+       }
+
+       self->m_camdata.m_shift_y = param;
+       self->m_set_projection_matrix = false;
+       return PY_SET_ATTR_SUCCESS;
+}
 
 PyObject *KX_Camera::pyattr_get_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
index 41d0172f2cdc52c7c3d8dfe74ba1a7a651b8e261..991d8813a002357f5da030b8040f8ecb13c28414 100644 (file)
@@ -310,7 +310,11 @@ public:
        static int                      pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        static PyObject*        pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-       
+       static PyObject*        pyattr_get_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
        static PyObject*        pyattr_get_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);