diff options
author | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-05-30 15:09:46 +0400 |
---|---|---|
committer | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-05-30 15:09:46 +0400 |
commit | d38329b5aa6be472ea49c3a52b61875a772a6c9a (patch) | |
tree | 8f8ebf5a0438725b6d5398f1cb5d1f3c028ce668 /source/gameengine/Ketsji/KX_Light.cpp | |
parent | b97c77df2bafd7add01ea9dc8bfcad1e82714559 (diff) |
Added Python module for Lights.
Added attributes to the vertex class.
Diffstat (limited to 'source/gameengine/Ketsji/KX_Light.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_Light.cpp | 175 |
1 files changed, 173 insertions, 2 deletions
diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 658f45a49b0..9be4256f58f 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -41,13 +41,16 @@ #include "KX_Light.h" #include "RAS_IRenderTools.h" +#include "KX_PyMath.h" + KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks, class RAS_IRenderTools* rendertools, - const RAS_LightObject& lightobj + const RAS_LightObject& lightobj, + PyTypeObject* T ) : - KX_GameObject(sgReplicationInfo,callbacks), + KX_GameObject(sgReplicationInfo,callbacks,T), m_rendertools(rendertools) { m_lightobj = lightobj; @@ -77,3 +80,171 @@ CValue* KX_LightObject::GetReplica() m_rendertools->AddLight(&replica->m_lightobj); return replica; } + +PyObject* KX_LightObject::_getattr(const STR_String& attr) +{ + if (attr == "layer") + return PyInt_FromLong(m_lightobj.m_layer); + + if (attr == "energy") + return PyFloat_FromDouble(m_lightobj.m_energy); + + if (attr == "distance") + return PyFloat_FromDouble(m_lightobj.m_distance); + + if (attr == "colour" || attr == "color") + return Py_BuildValue("[fff]", m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue); + + if (attr == "lin_attenuation") + return PyFloat_FromDouble(m_lightobj.m_att1); + + if (attr == "spotsize") + return PyFloat_FromDouble(m_lightobj.m_spotsize); + + if (attr == "spotblend") + return PyFloat_FromDouble(m_lightobj.m_spotblend); + + if (attr == "SPOT") + return PyInt_FromLong(RAS_LightObject::LIGHT_SPOT); + + if (attr == "SUN") + return PyInt_FromLong(RAS_LightObject::LIGHT_SUN); + + if (attr == "NORMAL") + return PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL); + + if (attr == "type") + return PyInt_FromLong(m_lightobj.m_type); + + _getattr_up(KX_GameObject); +} + +int KX_LightObject::_setattr(const STR_String& attr, PyObject *pyvalue) +{ + if (attr == "SPOT" || attr == "SUN" || attr == "NORMAL") + { + PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr.ReadPtr()); + return 1; + } + + if (PyInt_Check(pyvalue)) + { + int value = PyInt_AsLong(pyvalue); + if (attr == "layer") + { + m_lightobj.m_layer = value; + return 0; + } + + if (attr == "type") + { + if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL) + m_lightobj.m_type = (RAS_LightObject::LightType) value; + return 0; + } + } + + if (PyFloat_Check(pyvalue)) + { + float value = PyFloat_AsDouble(pyvalue); + if (attr == "energy") + { + m_lightobj.m_energy = value; + return 0; + } + + if (attr == "distance") + { + m_lightobj.m_distance = value; + return 0; + } + + if (attr == "lin_attenuation") + { + m_lightobj.m_att1 = value; + return 0; + } + + if (attr == "spotsize") + { + m_lightobj.m_spotsize = value; + return 0; + } + + if (attr == "spotblend") + { + m_lightobj.m_spotblend = value; + return 0; + } + } + + if (PySequence_Check(pyvalue)) + { + if (attr == "colour" || attr == "color") + { + MT_Vector3 colour(MT_Vector3FromPyList(pyvalue)); + m_lightobj.m_red = colour[0]; + m_lightobj.m_green = colour[1]; + m_lightobj.m_blue = colour[2]; + return 0; + } + } + + return KX_GameObject::_setattr(attr, pyvalue); +} + +PyMethodDef KX_LightObject::Methods[] = { + {NULL,NULL} //Sentinel +}; + +char KX_LightObject::doc[] = "Module KX_LightObject\n\n" +"Constants:\n" +"\tSPOT\n" +"\tSUN\n" +"\tNORMAL\n" +"Attributes:\n" +"\ttype -> SPOT, SUN or NORMAL\n" +"\t\tThe type of light.\n" +"\tlayer -> integer bit field.\n" +"\t\tThe layers this light applies to.\n" +"\tenergy -> float.\n" +"\t\tThe brightness of the light.\n" +"\tdistance -> float.\n" +"\t\tThe effect radius of the light.\n" +"\tcolour -> list [r, g, b].\n" +"\tcolor -> list [r, g, b].\n" +"\t\tThe colour of the light.\n" +"\tlin_attenuation -> float.\n" +"\t\tThe attenuation factor for the light.\n" +"\tspotsize -> float.\n" +"\t\tThe size of the spot.\n" +"\tspotblend -> float.\n" +"\t\tThe blend? of the spot.\n"; + +PyTypeObject KX_LightObject::Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "KX_LightObject", + sizeof(KX_LightObject), + 0, + PyDestructor, + 0, + __getattr, + __setattr, + 0, //&MyPyCompare, + __repr, + 0, //&cvalue_as_number, + 0, + 0, + 0, + 0, 0, 0, 0, 0, 0, + doc +}; + +PyParentObject KX_LightObject::Parents[] = { + &KX_LightObject::Type, + &KX_GameObject::Type, + &SCA_IObject::Type, + &CValue::Type, + NULL +}; |