Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stokes <kupomail@gmail.com>2013-08-07 09:24:47 +0400
committerDaniel Stokes <kupomail@gmail.com>2013-08-07 09:24:47 +0400
commit29c8e4512c2deda8e37f503f30c5a89f20e21a45 (patch)
tree2971a06ddecf8c831f09dd3499441d3fd75807cf
parentf5c66a3676da2141b240896ad701689f83f5a143 (diff)
Adding a fov attribute to KX_Camera. This attribute converts the field of view value and uses it to set lens.
-rw-r--r--doc/python_api/rst/bge_types/bge.types.KX_Camera.rst6
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp30
-rw-r--r--source/gameengine/Ketsji/KX_Camera.h2
3 files changed, 38 insertions, 0 deletions
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_Camera.rst b/doc/python_api/rst/bge_types/bge.types.KX_Camera.rst
index baf60ec0c97..0baba5c3359 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_Camera.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_Camera.rst
@@ -27,6 +27,12 @@ base class --- :class:`KX_GameObject`
:type: float
+ .. attribute:: fov
+
+ The camera's field of view value.
+
+ :type: float
+
.. attribute:: ortho_scale
The camera's view scale when in orthographic mode.
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
index 0cd06a7b6eb..73ebf89bea3 100644
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ b/source/gameengine/Ketsji/KX_Camera.cpp
@@ -521,6 +521,7 @@ PyAttributeDef KX_Camera::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("perspective", KX_Camera, pyattr_get_perspective, pyattr_set_perspective),
KX_PYATTRIBUTE_RW_FUNCTION("lens", KX_Camera, pyattr_get_lens, pyattr_set_lens),
+ KX_PYATTRIBUTE_RW_FUNCTION("fov", KX_Camera, pyattr_get_fov, pyattr_set_fov),
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),
@@ -752,6 +753,35 @@ int KX_Camera::pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef,
return PY_SET_ATTR_SUCCESS;
}
+PyObject *KX_Camera::pyattr_get_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_Camera* self = static_cast<KX_Camera*>(self_v);
+
+ float lens = self->m_camdata.m_lens;
+ float width = self->m_camdata.m_sensor_x;
+ float fov = 2.0 * atan(0.5 * width / lens);
+
+ return PyFloat_FromDouble(fov * MT_DEGS_PER_RAD);
+}
+
+int KX_Camera::pyattr_set_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_Camera* self = static_cast<KX_Camera*>(self_v);
+ float fov = PyFloat_AsDouble(value);
+ if (fov <= 0.0) {
+ PyErr_SetString(PyExc_AttributeError, "camera.fov = float: KX_Camera, expected a float greater then zero");
+ return PY_SET_ATTR_FAIL;
+ }
+
+ fov *= MT_RADS_PER_DEG;
+ float width = self->m_camdata.m_sensor_x;
+ float lens = width / (2.0 * tan(0.5 * fov));
+
+ self->m_camdata.m_lens= lens;
+ self->m_set_projection_matrix = false;
+ return PY_SET_ATTR_SUCCESS;
+}
+
PyObject *KX_Camera::pyattr_get_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_Camera* self = static_cast<KX_Camera*>(self_v);
diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h
index f615fefc223..454c4a54ec1 100644
--- a/source/gameengine/Ketsji/KX_Camera.h
+++ b/source/gameengine/Ketsji/KX_Camera.h
@@ -298,6 +298,8 @@ public:
static PyObject* pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject* pyattr_get_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);