Blender  V2.59
SCA_2DFilterActuator.cpp
Go to the documentation of this file.
00001 /*
00002  * SCA_2DFilterActuator.cpp
00003  *
00004  * $Id: SCA_2DFilterActuator.cpp 37446 2011-06-13 11:36:25Z blendix $
00005  *
00006  * ***** BEGIN GPL LICENSE BLOCK *****
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  */
00025 
00031 #include <stddef.h>
00032 
00033 #include "SCA_IActuator.h"
00034 #include "SCA_2DFilterActuator.h"
00035 
00036 #include <iostream>
00037 
00038 SCA_2DFilterActuator::~SCA_2DFilterActuator()
00039 {
00040 }
00041 
00042 SCA_2DFilterActuator::SCA_2DFilterActuator(
00043         SCA_IObject *gameobj, 
00044         RAS_2DFilterManager::RAS_2DFILTER_MODE type,
00045                 short flag,
00046                 float float_arg,
00047                 int int_arg,
00048                 RAS_IRasterizer* rasterizer,
00049                 SCA_IScene* scene)
00050     : SCA_IActuator(gameobj, KX_ACT_2DFILTER),
00051      m_type(type),
00052          m_disableMotionBlur(flag),
00053          m_float_arg(float_arg),
00054          m_int_arg(int_arg),
00055          m_rasterizer(rasterizer),
00056          m_scene(scene)
00057 {
00058         m_gameobj = NULL;
00059         if(gameobj){
00060                 m_propNames = gameobj->GetPropertyNames();
00061                 m_gameobj = gameobj;
00062         }
00063 }
00064 
00065 
00066 CValue* SCA_2DFilterActuator::GetReplica()
00067 {
00068     SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this);
00069     replica->ProcessReplica();
00070     return replica;
00071 }
00072 
00073 
00074 bool SCA_2DFilterActuator::Update()
00075 {
00076         bool bNegativeEvent = IsNegativeEvent();
00077         RemoveAllEvents();
00078 
00079 
00080         if (bNegativeEvent)
00081                 return false; // do nothing on negative events
00082 
00083         if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR )
00084         {
00085                 if(!m_disableMotionBlur)
00086                         m_rasterizer->EnableMotionBlur(m_float_arg);
00087                 else
00088                         m_rasterizer->DisableMotionBlur();
00089 
00090                 return false;
00091         }
00092         else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
00093         {
00094                 m_scene->Update2DFilter(m_propNames, m_gameobj, m_type, m_int_arg, m_shaderText);
00095         }
00096         // once the filter is in place, no need to update it again => disable the actuator
00097     return false;
00098 }
00099 
00100 
00101 void SCA_2DFilterActuator::SetShaderText(const char *text)
00102 {
00103         m_shaderText = text;
00104 }
00105 
00106 #ifdef WITH_PYTHON
00107 
00108 /* ------------------------------------------------------------------------- */
00109 /* Python functions                                                          */
00110 /* ------------------------------------------------------------------------- */
00111 
00112 /* Integration hooks ------------------------------------------------------- */
00113 PyTypeObject SCA_2DFilterActuator::Type = {
00114         PyVarObject_HEAD_INIT(NULL, 0)
00115         "SCA_2DFilterActuator",
00116         sizeof(PyObjectPlus_Proxy),
00117         0,
00118         py_base_dealloc,
00119         0,
00120         0,
00121         0,
00122         0,
00123         py_base_repr,
00124         0,0,0,0,0,0,0,0,0,
00125         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00126         0,0,0,0,0,0,0,
00127         Methods,
00128         0,
00129         0,
00130         &SCA_IActuator::Type,
00131         0,0,0,0,0,0,
00132         py_base_new
00133 };
00134 
00135 PyMethodDef SCA_2DFilterActuator::Methods[] = {
00136         /* add python functions to deal with m_msg... */
00137     {NULL,NULL}
00138 };
00139 
00140 PyAttributeDef SCA_2DFilterActuator::Attributes[] = {
00141         KX_PYATTRIBUTE_STRING_RW("shaderText", 0, 64000, false, SCA_2DFilterActuator, m_shaderText),
00142         KX_PYATTRIBUTE_SHORT_RW("disableMotionBlur", 0, 1, true, SCA_2DFilterActuator, m_disableMotionBlur),
00143         KX_PYATTRIBUTE_ENUM_RW("mode",RAS_2DFilterManager::RAS_2DFILTER_ENABLED,RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS,false,SCA_2DFilterActuator,m_type),
00144         KX_PYATTRIBUTE_INT_RW("passNumber", 0, 100, true, SCA_2DFilterActuator, m_int_arg),
00145         KX_PYATTRIBUTE_FLOAT_RW("value", 0.0, 100.0, SCA_2DFilterActuator, m_float_arg),
00146         { NULL }        //Sentinel
00147 };
00148 
00149 #endif