From dd3f9cff91be36c48d24a3d6124727ea83234a1c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 14 Jul 2010 20:52:04 +0000 Subject: patch from Goran Milovanovic for the BGE python api. camera.ortho_scale (use when in ortho mode only) (own previous commit incorrectly removed thumb metadata from new imbuf) --- source/blender/imbuf/intern/thumbs_blend.c | 2 +- source/gameengine/Ketsji/KX_Camera.cpp | 21 +++++++++++++++++++++ source/gameengine/Ketsji/KX_Camera.h | 2 ++ source/gameengine/PyDoc/bge.types.rst | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index 2b55e87546a..7f1c903e9de 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -121,7 +121,7 @@ static ImBuf *loadblend_thumb(gzFile gzfile) return NULL; /* finally malloc and read the data */ - img= IMB_allocImBuf(x, y, 32, IB_rect, 0); + img= IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata, 0); if(gzread(gzfile, img->rect, len) != len) { IMB_freeImBuf(img); diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index bba3b2219ed..82786456589 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -499,6 +499,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("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), @@ -728,6 +729,26 @@ int KX_Camera::pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, 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(self_v); + return PyFloat_FromDouble(self->m_camdata.m_scale); +} + +int KX_Camera::pyattr_set_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_Camera* self= static_cast(self_v); + float param = PyFloat_AsDouble(value); + if (param == -1) { + PyErr_SetString(PyExc_AttributeError, "camera.scale = float: KX_Camera, expected a float greater then zero"); + return PY_SET_ATTR_FAIL; + } + + self->m_camdata.m_scale= param; + self->m_set_projection_matrix = false; + return PY_SET_ATTR_SUCCESS; +} + PyObject* KX_Camera::pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_Camera* self= static_cast(self_v); diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index e209f0461b9..406ee1d0764 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -289,6 +289,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_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); 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); diff --git a/source/gameengine/PyDoc/bge.types.rst b/source/gameengine/PyDoc/bge.types.rst index 935d3e7e00e..e0ace6ad85b 100644 --- a/source/gameengine/PyDoc/bge.types.rst +++ b/source/gameengine/PyDoc/bge.types.rst @@ -4185,6 +4185,12 @@ Game Engine bge.types Module :type: float + .. attribute:: ortho_scale + + The camera's view scale when in orthographic mode. + + :type: float + .. attribute:: near The camera's near clip distance. -- cgit v1.2.3