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
This commit is contained in:
Thomas Szepe 2015-03-23 21:40:11 +01:00
parent 2affbb437b
commit d07c666a0e
9 changed files with 133 additions and 10 deletions

View File

@ -87,6 +87,19 @@ Constants
Right eye being used during stereoscopic rendering.
.. data:: KX_MIST_QUADRATIC
Type of quadratic attenuation used to fade mist.
.. data:: KX_MIST_LINEAR
Type of linear attenuation used to fade mist.
.. data:: KX_MIST_INV_QUADRATIC
Type of inverse quadratic attenuation used to fade mist.
*********
Functions
*********
@ -165,18 +178,25 @@ Functions
:type rgba: list [r, g, b, a]
.. function:: setAmbientColor(rgb)
Sets the color of ambient light.
:type rgb: list [r, g, b]
.. function:: setMistColor(rgb)
Sets the mist color.
:type rgb: list [r, g, b]
.. function:: setAmbientColor(rgb)
Sets the color of ambient light.
:type rgb: list [r, g, b]
.. function:: setMistType(mode)
Sets the mist attenuation type.
:type mode: KX_MIST_QUADRATIC, KX_MIST_LINEAR, KX_MIST_INV_QUADRATIC
.. function:: setMistStart(start)
@ -193,9 +213,16 @@ Functions
:type end: float
.. function:: setMistIntensity(intensity)
Sets the mist intensity value.
:type start: float
.. function:: disableMist()
Disables mist.
.. note:: Deprecated use setUseMist().

View File

@ -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;

View File

@ -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);

View File

@ -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()

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);