Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_MouseActuator.cpp
- This file was moved from source/gameengine/Ketsji/KX_MouseActuator.cpp.
| Show All 14 Lines | |||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * Contributor(s): Geoffrey Gollmer, Jorge Bernal | * Contributor(s): Geoffrey Gollmer, Jorge Bernal | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| #include "KX_MouseActuator.h" | #include "SCA_MouseActuator.h" | ||||
| #include "KX_KetsjiEngine.h" | #include "KX_KetsjiEngine.h" | ||||
| #include "SCA_MouseManager.h" | #include "SCA_MouseManager.h" | ||||
| #include "SCA_IInputDevice.h" | #include "SCA_IInputDevice.h" | ||||
| #include "RAS_ICanvas.h" | #include "RAS_ICanvas.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "MT_Vector3.h" | #include "MT_Vector3.h" | ||||
| #include "MT_Scalar.h" | #include "MT_Scalar.h" | ||||
| #include "MT_assert.h" | #include "MT_assert.h" | ||||
| #include "limits.h" | #include "limits.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | ||||
| #include <config.h> | #include <config.h> | ||||
| #endif | #endif | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| KX_MouseActuator::KX_MouseActuator( | SCA_MouseActuator::SCA_MouseActuator(SCA_IObject* gameobj, | ||||
| SCA_IObject* gameobj, | |||||
| KX_KetsjiEngine* ketsjiEngine, | KX_KetsjiEngine* ketsjiEngine, | ||||
| SCA_MouseManager* eventmgr, | SCA_MouseManager* eventmgr, | ||||
| int acttype, | int acttype, | ||||
| bool visible, | bool visible, | ||||
| bool* use_axis, | bool* use_axis, | ||||
| float* threshold, | float* threshold, | ||||
| bool* reset, | bool* reset, | ||||
| int* object_axis, | int* object_axis, | ||||
| bool* local, | bool* local, | ||||
| float* sensitivity, | float* sensitivity, | ||||
| float* limit_x, | float* limit_x, | ||||
| float* limit_y | float* limit_y | ||||
| ): | ): | ||||
| SCA_IActuator(gameobj, KX_ACT_MOUSE), | SCA_IActuator(gameobj, SCA_ACT_MOUSE), | ||||
| m_ketsji(ketsjiEngine), | m_ketsji(ketsjiEngine), | ||||
| m_eventmgr(eventmgr), | m_eventmgr(eventmgr), | ||||
| m_type(acttype), | m_type(acttype), | ||||
| m_visible(visible), | m_visible(visible), | ||||
| m_use_axis_x(use_axis[0]), | m_use_axis_x(use_axis[0]), | ||||
| m_use_axis_y(use_axis[1]), | m_use_axis_y(use_axis[1]), | ||||
| m_reset_x(reset[0]), | m_reset_x(reset[0]), | ||||
| m_reset_y(reset[1]), | m_reset_y(reset[1]), | ||||
| Show All 11 Lines | ): | ||||
| m_object_axis[0] = object_axis[0]; | m_object_axis[0] = object_axis[0]; | ||||
| m_object_axis[1] = object_axis[1]; | m_object_axis[1] = object_axis[1]; | ||||
| m_sensitivity[0] = sensitivity[0]; | m_sensitivity[0] = sensitivity[0]; | ||||
| m_sensitivity[1] = sensitivity[1]; | m_sensitivity[1] = sensitivity[1]; | ||||
| m_angle[0] = 0.f; | m_angle[0] = 0.f; | ||||
| m_angle[1] = 0.f; | m_angle[1] = 0.f; | ||||
| } | } | ||||
| KX_MouseActuator::~KX_MouseActuator() | SCA_MouseActuator::~SCA_MouseActuator() | ||||
| { | { | ||||
| } | } | ||||
| bool KX_MouseActuator::Update() | bool SCA_MouseActuator::Update() | ||||
| { | { | ||||
| bool result = false; | bool result = false; | ||||
| bool bNegativeEvent = IsNegativeEvent(); | bool bNegativeEvent = IsNegativeEvent(); | ||||
| RemoveAllEvents(); | RemoveAllEvents(); | ||||
| if (bNegativeEvent) | if (bNegativeEvent) | ||||
| return false; // do nothing on negative events | return false; // do nothing on negative events | ||||
| ▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | case KX_ACT_MOUSE_LOOK: | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| bool KX_MouseActuator::isValid(KX_MouseActuator::KX_ACT_MOUSE_MODE mode) | bool SCA_MouseActuator::isValid(SCA_MouseActuator::KX_ACT_MOUSE_MODE mode) | ||||
| { | { | ||||
| return ((mode > KX_ACT_MOUSE_NODEF) && (mode < KX_ACT_MOUSE_MAX)); | return ((mode > KX_ACT_MOUSE_NODEF) && (mode < KX_ACT_MOUSE_MAX)); | ||||
| } | } | ||||
| CValue* KX_MouseActuator::GetReplica() | CValue* SCA_MouseActuator::GetReplica() | ||||
| { | { | ||||
| KX_MouseActuator* replica = new KX_MouseActuator(*this); | SCA_MouseActuator* replica = new SCA_MouseActuator(*this); | ||||
| replica->ProcessReplica(); | replica->ProcessReplica(); | ||||
| return replica; | return replica; | ||||
| } | } | ||||
| void KX_MouseActuator::ProcessReplica() | void SCA_MouseActuator::ProcessReplica() | ||||
| { | { | ||||
| SCA_IActuator::ProcessReplica(); | SCA_IActuator::ProcessReplica(); | ||||
| } | } | ||||
| void KX_MouseActuator::getMousePosition(float* pos) | void SCA_MouseActuator::getMousePosition(float* pos) | ||||
| { | { | ||||
| MT_assert(!m_mouse); | MT_assert(!m_mouse); | ||||
| const SCA_InputEvent & xevent = m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEX); | const SCA_InputEvent & xevent = m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEX); | ||||
| const SCA_InputEvent & yevent = m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEY); | const SCA_InputEvent & yevent = m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEY); | ||||
| pos[0] = m_canvas->GetMouseNormalizedX(xevent.m_eventval); | pos[0] = m_canvas->GetMouseNormalizedX(xevent.m_eventval); | ||||
| pos[1] = m_canvas->GetMouseNormalizedY(yevent.m_eventval); | pos[1] = m_canvas->GetMouseNormalizedY(yevent.m_eventval); | ||||
| } | } | ||||
| void KX_MouseActuator::setMousePosition(float fx, float fy) | void SCA_MouseActuator::setMousePosition(float fx, float fy) | ||||
| { | { | ||||
| int x, y; | int x, y; | ||||
| x = (int)(fx * m_canvas->GetWidth()); | x = (int)(fx * m_canvas->GetWidth()); | ||||
| y = (int)(fy * m_canvas->GetHeight()); | y = (int)(fy * m_canvas->GetHeight()); | ||||
| m_canvas->SetMousePosition(x, y); | m_canvas->SetMousePosition(x, y); | ||||
| } | } | ||||
| #ifndef DISABLE_PYTHON | #ifndef DISABLE_PYTHON | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject KX_MouseActuator::Type = { | PyTypeObject SCA_MouseActuator::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "KX_MouseActuator", | "SCA_MouseActuator", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_IActuator::Type, | &SCA_IActuator::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_MouseActuator::Methods[] = { | PyMethodDef SCA_MouseActuator::Methods[] = { | ||||
| {"reset", (PyCFunction) KX_MouseActuator::sPyReset, METH_NOARGS,"reset() : undo rotation caused by actuator\n"}, | {"reset", (PyCFunction) SCA_MouseActuator::sPyReset, METH_NOARGS,"reset() : undo rotation caused by actuator\n"}, | ||||
| {NULL,NULL} //Sentinel | {NULL,NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_MouseActuator::Attributes[] = { | PyAttributeDef SCA_MouseActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_BOOL_RW("visible", KX_MouseActuator, m_visible), | KX_PYATTRIBUTE_BOOL_RW("visible", SCA_MouseActuator, m_visible), | ||||
| KX_PYATTRIBUTE_BOOL_RW("use_axis_x", KX_MouseActuator, m_use_axis_x), | KX_PYATTRIBUTE_BOOL_RW("use_axis_x", SCA_MouseActuator, m_use_axis_x), | ||||
| KX_PYATTRIBUTE_BOOL_RW("use_axis_y", KX_MouseActuator, m_use_axis_y), | KX_PYATTRIBUTE_BOOL_RW("use_axis_y", SCA_MouseActuator, m_use_axis_y), | ||||
| KX_PYATTRIBUTE_FLOAT_ARRAY_RW("threshold", 0.0, 0.5, KX_MouseActuator, m_threshold, 2), | KX_PYATTRIBUTE_FLOAT_ARRAY_RW("threshold", 0.0, 0.5, SCA_MouseActuator, m_threshold, 2), | ||||
| KX_PYATTRIBUTE_BOOL_RW("reset_x", KX_MouseActuator, m_reset_x), | KX_PYATTRIBUTE_BOOL_RW("reset_x", SCA_MouseActuator, m_reset_x), | ||||
| KX_PYATTRIBUTE_BOOL_RW("reset_y", KX_MouseActuator, m_reset_y), | KX_PYATTRIBUTE_BOOL_RW("reset_y", SCA_MouseActuator, m_reset_y), | ||||
| KX_PYATTRIBUTE_INT_ARRAY_RW("object_axis", 0, 2, 1, KX_MouseActuator, m_object_axis, 2), | KX_PYATTRIBUTE_INT_ARRAY_RW("object_axis", SCA_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_X, SCA_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_Z, 1, SCA_MouseActuator, m_object_axis, 2), | ||||
| KX_PYATTRIBUTE_BOOL_RW("local_x", KX_MouseActuator, m_local_x), | KX_PYATTRIBUTE_BOOL_RW("local_x", SCA_MouseActuator, m_local_x), | ||||
| KX_PYATTRIBUTE_BOOL_RW("local_y", KX_MouseActuator, m_local_y), | KX_PYATTRIBUTE_BOOL_RW("local_y", SCA_MouseActuator, m_local_y), | ||||
| KX_PYATTRIBUTE_FLOAT_ARRAY_RW("sensitivity", -FLT_MAX, FLT_MAX, KX_MouseActuator, m_sensitivity, 2), | KX_PYATTRIBUTE_FLOAT_ARRAY_RW("sensitivity", -FLT_MAX, FLT_MAX, SCA_MouseActuator, m_sensitivity, 2), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("limit_x", KX_MouseActuator, pyattr_get_limit_x, pyattr_set_limit_x), | KX_PYATTRIBUTE_RW_FUNCTION("limit_x", SCA_MouseActuator, pyattr_get_limit_x, pyattr_set_limit_x), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("limit_y", KX_MouseActuator, pyattr_get_limit_y, pyattr_set_limit_y), | KX_PYATTRIBUTE_RW_FUNCTION("limit_y", SCA_MouseActuator, pyattr_get_limit_y, pyattr_set_limit_y), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("angle", KX_MouseActuator, pyattr_get_angle, pyattr_set_angle), | KX_PYATTRIBUTE_RW_FUNCTION("angle", SCA_MouseActuator, pyattr_get_angle, pyattr_set_angle), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| PyObject* KX_MouseActuator::pyattr_get_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject* SCA_MouseActuator::pyattr_get_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v); | SCA_MouseActuator* self = static_cast<SCA_MouseActuator*>(self_v); | ||||
| return Py_BuildValue("[f,f]", (self->m_limit_x[0] / M_PI * 180.0), (self->m_limit_x[1] / M_PI * 180.0)); | return Py_BuildValue("[f,f]", (self->m_limit_x[0] / M_PI * 180.0), (self->m_limit_x[1] / M_PI * 180.0)); | ||||
| } | } | ||||
| int KX_MouseActuator::pyattr_set_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_MouseActuator::pyattr_set_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| PyObject *item1, *item2; | PyObject *item1, *item2; | ||||
| KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v); | SCA_MouseActuator* self = static_cast<SCA_MouseActuator*>(self_v); | ||||
| if (!PyList_Check(value)) | if (!PyList_Check(value)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| if (PyList_Size(value) != 2) | if (PyList_Size(value) != 2) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| item1 = PyList_GetItem(value, 0); | item1 = PyList_GetItem(value, 0); | ||||
| item2 = PyList_GetItem(value, 1); | item2 = PyList_GetItem(value, 1); | ||||
| if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) { | if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) { | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| else { | else { | ||||
| self->m_limit_x[0] = (PyFloat_AsDouble(item1) * M_PI / 180.0); | self->m_limit_x[0] = (PyFloat_AsDouble(item1) * M_PI / 180.0); | ||||
| self->m_limit_x[1] = (PyFloat_AsDouble(item2) * M_PI / 180.0); | self->m_limit_x[1] = (PyFloat_AsDouble(item2) * M_PI / 180.0); | ||||
| } | } | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| PyObject* KX_MouseActuator::pyattr_get_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject* SCA_MouseActuator::pyattr_get_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v); | SCA_MouseActuator* self = static_cast<SCA_MouseActuator*>(self_v); | ||||
| return Py_BuildValue("[f,f]", (self->m_limit_y[0] / M_PI * 180.0), (self->m_limit_y[1] / M_PI * 180.0)); | return Py_BuildValue("[f,f]", (self->m_limit_y[0] / M_PI * 180.0), (self->m_limit_y[1] / M_PI * 180.0)); | ||||
| } | } | ||||
| int KX_MouseActuator::pyattr_set_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_MouseActuator::pyattr_set_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| PyObject *item1, *item2; | PyObject *item1, *item2; | ||||
| KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v); | SCA_MouseActuator* self = static_cast<SCA_MouseActuator*>(self_v); | ||||
| if (!PyList_Check(value)) | if (!PyList_Check(value)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| if (PyList_Size(value) != 2) | if (PyList_Size(value) != 2) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| item1 = PyList_GetItem(value, 0); | item1 = PyList_GetItem(value, 0); | ||||
| item2 = PyList_GetItem(value, 1); | item2 = PyList_GetItem(value, 1); | ||||
| if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) { | if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) { | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| else { | else { | ||||
| self->m_limit_y[0] = (PyFloat_AsDouble(item1) * M_PI / 180.0); | self->m_limit_y[0] = (PyFloat_AsDouble(item1) * M_PI / 180.0); | ||||
| self->m_limit_y[1] = (PyFloat_AsDouble(item2) * M_PI / 180.0); | self->m_limit_y[1] = (PyFloat_AsDouble(item2) * M_PI / 180.0); | ||||
| } | } | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| PyObject* KX_MouseActuator::pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject* SCA_MouseActuator::pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v); | SCA_MouseActuator* self = static_cast<SCA_MouseActuator*>(self_v); | ||||
| return Py_BuildValue("[f,f]", (self->m_angle[0] / M_PI * 180.0), (self->m_angle[1] / M_PI * 180.0)); | return Py_BuildValue("[f,f]", (self->m_angle[0] / M_PI * 180.0), (self->m_angle[1] / M_PI * 180.0)); | ||||
| } | } | ||||
| int KX_MouseActuator::pyattr_set_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_MouseActuator::pyattr_set_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| PyObject *item1, *item2; | PyObject *item1, *item2; | ||||
| KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v); | SCA_MouseActuator* self = static_cast<SCA_MouseActuator*>(self_v); | ||||
| if (!PyList_Check(value)) | if (!PyList_Check(value)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| if (PyList_Size(value) != 2) | if (PyList_Size(value) != 2) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| item1 = PyList_GetItem(value, 0); | item1 = PyList_GetItem(value, 0); | ||||
| item2 = PyList_GetItem(value, 1); | item2 = PyList_GetItem(value, 1); | ||||
| if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) { | if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) { | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| else { | else { | ||||
| self->m_angle[0] = (PyFloat_AsDouble(item1) * M_PI / 180.0); | self->m_angle[0] = (PyFloat_AsDouble(item1) * M_PI / 180.0); | ||||
| self->m_angle[1] = (PyFloat_AsDouble(item2) * M_PI / 180.0); | self->m_angle[1] = (PyFloat_AsDouble(item2) * M_PI / 180.0); | ||||
| } | } | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| PyObject* KX_MouseActuator::PyReset() | PyObject* SCA_MouseActuator::PyReset() | ||||
| { | { | ||||
| MT_Vector3 rotation; | MT_Vector3 rotation; | ||||
| KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent()); | KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent()); | ||||
| switch (m_object_axis[0]) { | switch (m_object_axis[0]) { | ||||
| case KX_ACT_MOUSE_OBJECT_AXIS_X: | case KX_ACT_MOUSE_OBJECT_AXIS_X: | ||||
| { | { | ||||
| rotation = MT_Vector3(-1.0 * m_angle[0], 0.0, 0.0); | rotation = MT_Vector3(-1.0 * m_angle[0], 0.0, 0.0); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines | |||||