diff options
author | Thomas Szepe <HG1_public@gmx.net> | 2015-03-23 23:40:11 +0300 |
---|---|---|
committer | Thomas Szepe <HG1_public@gmx.net> | 2015-03-23 23:40:11 +0300 |
commit | d07c666a0e542517914dad580d1b3f4787525852 (patch) | |
tree | 4f9c2c5999817acaca97351e72e71f3f19cb7652 /source/gameengine | |
parent | 2affbb437bd3cbf3e1a502bd65a5eefb64a92b9b (diff) |
BGE: Add setMistType and setMistIntensity API.
This patch adds the missing setMistType() and setMistIntensity() to the API
Reviewers: campbellbarton, brecht, moguri
Reviewed By: campbellbarton, brecht, moguri
Subscribers: campbellbarton, dingto
Differential Revision: https://developer.blender.org/D149
Diffstat (limited to 'source/gameengine')
8 files changed, 100 insertions, 4 deletions
diff --git a/source/gameengine/Converter/BlenderWorldInfo.cpp b/source/gameengine/Converter/BlenderWorldInfo.cpp index 28e42c1cc63..5f476949616 100644 --- a/source/gameengine/Converter/BlenderWorldInfo.cpp +++ b/source/gameengine/Converter/BlenderWorldInfo.cpp @@ -70,8 +70,10 @@ BlenderWorldInfo::BlenderWorldInfo(struct Scene *blenderscene, struct World *ble if (blenderworld) { m_hasworld = true; m_hasmist = ((blenderworld->mode) & WO_MIST ? true : false); + m_misttype = blenderworld->mistype; m_miststart = blenderworld->miststa; m_mistdistance = blenderworld->mistdist; + m_mistintensity = blenderworld->misi; copy_v3_v3(m_mistcolor, &blenderworld->horr); copy_v3_v3(m_backgroundcolor, &blenderworld->horr); copy_v3_v3(m_ambientcolor, &blenderworld->ambr); @@ -131,6 +133,11 @@ float BlenderWorldInfo::getAmbientColorBlue() return m_ambientcolor[2]; } +short BlenderWorldInfo::getMistType() +{ + return m_misttype; +} + float BlenderWorldInfo::getMistStart() { return m_miststart; @@ -141,6 +148,11 @@ float BlenderWorldInfo::getMistDistance() return m_mistdistance; } +float BlenderWorldInfo::getMistIntensity() +{ + return m_mistintensity; +} + float BlenderWorldInfo::getMistColorRed() { return m_mistcolor[0]; @@ -163,6 +175,11 @@ void BlenderWorldInfo::setBackColor(float r, float g, float b) m_backgroundcolor[2] = b; } +void BlenderWorldInfo::setMistType(short type) +{ + m_misttype = type; +} + void BlenderWorldInfo::setUseMist(bool enable) { m_hasmist = enable; @@ -178,6 +195,10 @@ void BlenderWorldInfo::setMistDistance(float d) m_mistdistance = d; } +void BlenderWorldInfo::setMistIntensity(float intensity) +{ + m_mistintensity = intensity; +} void BlenderWorldInfo::setMistColor(float r, float g, float b) { m_mistcolor[0] = r; diff --git a/source/gameengine/Converter/BlenderWorldInfo.h b/source/gameengine/Converter/BlenderWorldInfo.h index 6c67681c3bc..4184d428808 100644 --- a/source/gameengine/Converter/BlenderWorldInfo.h +++ b/source/gameengine/Converter/BlenderWorldInfo.h @@ -40,8 +40,10 @@ class BlenderWorldInfo : public KX_WorldInfo float m_backgroundcolor[3]; bool m_hasmist; + short m_misttype; float m_miststart; float m_mistdistance; + float m_mistintensity; float m_mistcolor[3]; float m_ambientcolor[3]; @@ -60,16 +62,20 @@ public: float getAmbientColorGreen(); float getAmbientColorBlue(); + short getMistType(); float getMistStart(); float getMistDistance(); + float getMistIntensity(); float getMistColorRed(); float getMistColorGreen(); float getMistColorBlue(); void setBackColor(float r, float g, float b); void setUseMist(bool enable); + void setMistType(short type); void setMistStart(float d); void setMistDistance(float d); + void setMistIntensity(float intensity); void setMistColor(float r, float g, float b); void setAmbientColor(float r, float g, float b); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 44b667e15e0..8c6cb2b32d4 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -996,8 +996,10 @@ void KX_KetsjiEngine::SetWorldSettings(KX_WorldInfo* wi) if (wi->hasMist()) { m_rasterizer->SetFog( + wi->getMistType(), wi->getMistStart(), wi->getMistDistance(), + wi->getMistIntensity(), wi->getMistColorRed(), wi->getMistColorGreen(), wi->getMistColorBlue() diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index e0af3283f44..8fd38db4a2a 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1091,6 +1091,29 @@ static PyObject *gPySetUseMist(PyObject *, PyObject *args) Py_RETURN_NONE; } +static PyObject *gPySetMistType(PyObject *, PyObject *args) +{ + short type; + + if (!PyArg_ParseTuple(args,"i:setMistType",&type)) + return NULL; + + if (type < 0 || type > 2) { + PyErr_SetString(PyExc_ValueError, "Rasterizer.setMistType(int): Mist type is not known"); + return NULL; + } + + KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo(); + if (!wi->hasWorld()) { + PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistType(int), World not available"); + return NULL; + } + + wi->setMistType(type); + + Py_RETURN_NONE; +} + static PyObject *gPySetMistStart(PyObject *, PyObject *args) { float miststart; @@ -1125,6 +1148,24 @@ static PyObject *gPySetMistEnd(PyObject *, PyObject *args) Py_RETURN_NONE; } +static PyObject *gPySetMistIntensity(PyObject *, PyObject *args) +{ + + float intensity; + if (!PyArg_ParseTuple(args,"f:setMistIntensity",&intensity)) + return NULL; + + KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo(); + if (!wi->hasWorld()) { + PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistIntensity(float), World not available"); + return NULL; + } + + wi->setMistIntensity(intensity); + + Py_RETURN_NONE; +} + static PyObject *gPySetAmbientColor(PyObject *, PyObject *value) { MT_Vector3 vec; @@ -1522,8 +1563,10 @@ static struct PyMethodDef rasterizer_methods[] = { {"disableMist",(PyCFunction)gPyDisableMist,METH_NOARGS,"turn off mist"}, {"setUseMist",(PyCFunction)gPySetUseMist,METH_VARARGS,"enable or disable mist"}, {"setMistColor",(PyCFunction)gPySetMistColor,METH_O,"set Mist Color (rgb)"}, + {"setMistType",(PyCFunction)gPySetMistType,METH_VARARGS,"set mist type (short type)"}, {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start"}, {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End"}, + {"setMistIntensity",(PyCFunction)gPySetMistIntensity,METH_VARARGS,"set mist intensity (float intensity)"}, {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"}, {"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_NOARGS,"disable motion blur"}, @@ -2370,6 +2413,11 @@ PyMODINIT_FUNC initRasterizerPythonBinding() KX_MACRO_addTypesToDict(d, LEFT_EYE, RAS_IRasterizer::RAS_STEREO_LEFTEYE); KX_MACRO_addTypesToDict(d, RIGHT_EYE, RAS_IRasterizer::RAS_STEREO_RIGHTEYE); + /* KX_WorldInfo mist types */ + KX_MACRO_addTypesToDict(d, KX_MIST_QUADRATIC, KX_WorldInfo::KX_MIST_QUADRATIC); + KX_MACRO_addTypesToDict(d, KX_MIST_LINEAR, KX_WorldInfo::KX_MIST_LINEAR); + KX_MACRO_addTypesToDict(d, KX_MIST_INV_QUADRATIC, KX_WorldInfo::KX_MIST_INV_QUADRATIC); + // XXXX Add constants here // Check for errors diff --git a/source/gameengine/Ketsji/KX_WorldInfo.h b/source/gameengine/Ketsji/KX_WorldInfo.h index 251ba95f43a..f90a4ff6b6d 100644 --- a/source/gameengine/Ketsji/KX_WorldInfo.h +++ b/source/gameengine/Ketsji/KX_WorldInfo.h @@ -43,6 +43,15 @@ class MT_CmMatrix4x4; class KX_WorldInfo { public: + /** + * Mist options + */ + enum MistType { + KX_MIST_QUADRATIC, + KX_MIST_LINEAR, + KX_MIST_INV_QUADRATIC, + }; + KX_WorldInfo() {} virtual ~KX_WorldInfo(); @@ -51,8 +60,10 @@ public: virtual float getBackColorRed() = 0; virtual float getBackColorGreen() = 0; virtual float getBackColorBlue() = 0; + virtual short getMistType() = 0; virtual float getMistStart() = 0; virtual float getMistDistance() = 0; + virtual float getMistIntensity() = 0; virtual float getMistColorRed() = 0; virtual float getMistColorGreen() = 0; virtual float getMistColorBlue() = 0; @@ -62,8 +73,10 @@ public: virtual float getAmbientColorBlue() = 0; virtual void setUseMist(bool enable) = 0; + virtual void setMistType(short) = 0; virtual void setMistStart(float) = 0; virtual void setMistDistance(float) = 0; + virtual void setMistIntensity(float) = 0; virtual void setMistColor(float, float, float) = 0; virtual void setBackColor(float, float, float) = 0; virtual void setAmbientColor(float,float,float) = 0; diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 6f5273f035f..22ffcd48739 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -297,7 +297,7 @@ public: /** * Fog */ - virtual void SetFog(float start, float dist, float r, float g, float b) = 0; + virtual void SetFog(short type, float start, float dist, float intensity, float r, float g, float b) = 0; virtual void SetFogColor(float r, float g,float b) = 0; virtual void SetFogStart(float start) = 0; virtual void SetFogEnd(float end) = 0; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 14a184bbe7f..9269640afa3 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -247,14 +247,18 @@ void RAS_OpenGLRasterizer::SetFogEnd(float fogend) -void RAS_OpenGLRasterizer::SetFog(float start, +void RAS_OpenGLRasterizer::SetFog(short type, + float start, float dist, + float intensity, float r, float g, float b) { + m_fogtype = type; m_fogstart = start; m_fogdist = dist; + m_fogintensity = intensity; m_fogr = r; m_fogg = g; m_fogb = b; @@ -279,7 +283,7 @@ void RAS_OpenGLRasterizer::DisplayFog() { float params[4] = {m_fogr, m_fogg, m_fogb, 1.0f}; glFogi(GL_FOG_MODE, GL_LINEAR); - glFogf(GL_FOG_DENSITY, 0.1f); + glFogf(GL_FOG_DENSITY, m_fogintensity / 10.0f); glFogf(GL_FOG_START, m_fogstart); glFogf(GL_FOG_END, m_fogstart + m_fogdist); glFogfv(GL_FOG_COLOR, params); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 042243230b3..48023f9786c 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -80,8 +80,10 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer /* fogging vars */ bool m_fogenabled; + short m_fogtype; float m_fogstart; float m_fogdist; + float m_fogintensity; float m_fogr; float m_fogg; float m_fogb; @@ -198,7 +200,7 @@ public: virtual const MT_Point3& GetCameraPosition(); virtual bool GetCameraOrtho(); - virtual void SetFog(float start, float dist, float r, float g, float b); + virtual void SetFog(short type, float start, float dist, float intensity, float r, float g, float b); virtual void SetFogColor(float r, float g, float b); virtual void SetFogStart(float fogstart); virtual void SetFogEnd(float fogend); |