forked from bartvdbraak/blender
BGE patch 15044 approved: Edit Object Dynamics Actuator.
Add enable/disable dynamics actuator under the "Edit Object" category. The Enable/disable rigid body option is also availale but not implemented.
This commit is contained in:
parent
7ba2389932
commit
c353af4d3a
@ -462,6 +462,9 @@
|
||||
<File
|
||||
RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_AddObjectActuator.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_DynamicActuator.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_EndObjectActuator.cpp">
|
||||
</File>
|
||||
@ -686,6 +689,9 @@
|
||||
<File
|
||||
RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_AddObjectActuator.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_DynamicActuator.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\source\gameengine\Ketsji\KX_SCA_EndObjectActuator.h">
|
||||
</File>
|
||||
|
@ -81,7 +81,7 @@ typedef struct bEditObjectActuator {
|
||||
char name[32];
|
||||
float linVelocity[3]; /* initial lin. velocity on creation */
|
||||
short localflag; /* flag for the lin. vel: apply locally */
|
||||
short pad;
|
||||
short dyn_operation;
|
||||
} bEditObjectActuator;
|
||||
|
||||
typedef struct bSceneActuator {
|
||||
@ -360,10 +360,11 @@ typedef struct FreeCamera {
|
||||
/* editObjectActuator->type */
|
||||
#define ACT_EDOB_ADD_OBJECT 0
|
||||
#define ACT_EDOB_END_OBJECT 1
|
||||
#define ACT_EDOB_REPLACE_MESH 2
|
||||
#define ACT_EDOB_REPLACE_MESH 2
|
||||
#define ACT_EDOB_TRACK_TO 3
|
||||
#define ACT_EDOB_MAKE_CHILD 4
|
||||
#define ACT_EDOB_END_CHILD 5
|
||||
#define ACT_EDOB_DYNAMICS 4
|
||||
|
||||
|
||||
|
||||
/* editObjectActuator->flag */
|
||||
#define ACT_TRACK_3D 1
|
||||
|
@ -1940,8 +1940,15 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
|
||||
uiDefButI(block, NUM, 0, "Time:", xco+10+(width-20)/2, yco-44, (width-20)/2-40, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the tracking takes");
|
||||
uiDefButS(block, TOG, 0, "3D", xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
|
||||
}
|
||||
|
||||
str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3";
|
||||
else if(eoa->type==ACT_EDOB_DYNAMICS) {
|
||||
ysize= 48;
|
||||
glRects(xco, yco-ysize, xco+width, yco);
|
||||
uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
|
||||
|
||||
str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3";
|
||||
uiDefButS(block, MENU, B_REDR, str, xco+40, yco-44, (width-80), 19, &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
|
||||
}
|
||||
str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
|
||||
uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
|
||||
|
||||
yco-= ysize;
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "KX_SCA_EndObjectActuator.h"
|
||||
#include "KX_SCA_ReplaceMeshActuator.h"
|
||||
#include "KX_ParentActuator.h"
|
||||
#include "KX_SCA_DynamicActuator.h"
|
||||
|
||||
#include "KX_Scene.h"
|
||||
#include "KX_KetsjiEngine.h"
|
||||
@ -602,6 +603,15 @@ void BL_ConvertActuators(char* maggiename,
|
||||
blenderobject->upflag
|
||||
);
|
||||
baseact = tmptrackact;
|
||||
break;
|
||||
}
|
||||
case ACT_EDOB_DYNAMICS:
|
||||
{
|
||||
KX_SCA_DynamicActuator* tmpdynact
|
||||
= new KX_SCA_DynamicActuator(gameobj,
|
||||
editobact->dyn_operation
|
||||
);
|
||||
baseact = tmpdynact;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1283,17 +1283,7 @@ PyObject* KX_GameObject::PySuspendDynamics(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
if (m_bSuspendDynamics)
|
||||
{
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->SuspendDynamics();
|
||||
}
|
||||
m_bSuspendDynamics = true;
|
||||
|
||||
SuspendDynamics();
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@ -1303,18 +1293,7 @@ PyObject* KX_GameObject::PyRestoreDynamics(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
|
||||
if (!m_bSuspendDynamics)
|
||||
{
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->RestoreDynamics();
|
||||
}
|
||||
m_bSuspendDynamics = false;
|
||||
|
||||
RestoreDynamics();
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "GEN_HashedPtr.h"
|
||||
#include "KX_Scene.h"
|
||||
#include "KX_KetsjiEngine.h" /* for m_anim_framerate */
|
||||
|
||||
#include "KX_IPhysicsController.h" /* for suspend/resume */
|
||||
#define KX_OB_DYNAMIC 1
|
||||
|
||||
|
||||
@ -652,6 +652,32 @@ public:
|
||||
*/
|
||||
void Resume(void);
|
||||
|
||||
void SuspendDynamics(void) {
|
||||
if (m_bSuspendDynamics)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->SuspendDynamics();
|
||||
}
|
||||
m_bSuspendDynamics = true;
|
||||
}
|
||||
|
||||
void RestoreDynamics(void) {
|
||||
if (!m_bSuspendDynamics)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pPhysicsController1)
|
||||
{
|
||||
m_pPhysicsController1->RestoreDynamics();
|
||||
}
|
||||
m_bSuspendDynamics = false;
|
||||
}
|
||||
|
||||
KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
|
||||
/**
|
||||
* @section Python interface functions.
|
||||
|
206
source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
Normal file
206
source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
//
|
||||
// Adjust dynamics settins for this object
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// ***** BEGIN GPL LICENSE BLOCK *****
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software Foundation,
|
||||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
// All rights reserved.
|
||||
//
|
||||
// The Original Code is: all of this file.
|
||||
//
|
||||
// Contributor(s): none yet.
|
||||
//
|
||||
// ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
//
|
||||
// Previously existed as:
|
||||
|
||||
// \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
|
||||
|
||||
// Please look here for revision history.
|
||||
|
||||
#include "KX_SCA_DynamicActuator.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Python functions */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Integration hooks ------------------------------------------------------- */
|
||||
|
||||
PyTypeObject
|
||||
|
||||
KX_SCA_DynamicActuator::
|
||||
|
||||
Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"KX_SCA_DynamicActuator",
|
||||
sizeof(KX_SCA_DynamicActuator),
|
||||
0,
|
||||
PyDestructor,
|
||||
0,
|
||||
__getattr,
|
||||
__setattr,
|
||||
0,
|
||||
__repr,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
PyParentObject KX_SCA_DynamicActuator::Parents[] = {
|
||||
&KX_SCA_DynamicActuator::Type,
|
||||
&SCA_IActuator::Type,
|
||||
&SCA_ILogicBrick::Type,
|
||||
&CValue::Type,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
|
||||
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
|
||||
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
|
||||
|
||||
|
||||
PyObject* KX_SCA_DynamicActuator::_getattr(const STR_String& attr)
|
||||
{
|
||||
_getattr_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 1. setOperation */
|
||||
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation,
|
||||
"setOperation(operation?)\n"
|
||||
"\t - operation? : type of dynamic operation\n"
|
||||
"\t 0 = restore dynamics\n"
|
||||
"\t 1 = disable dynamics\n"
|
||||
"\t 2 = enable rigid body\n"
|
||||
"\t 3 = disable rigid body\n"
|
||||
"Change the dynamic status of the parent object.\n")
|
||||
{
|
||||
int dyn_operation;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &dyn_operation))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (dyn_operation <0 || dyn_operation>3) {
|
||||
PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
|
||||
return NULL;
|
||||
}
|
||||
m_dyn_operation= dyn_operation;
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
|
||||
"getOperation() -> integer\n"
|
||||
"Returns the operation type of this actuator.\n"
|
||||
)
|
||||
{
|
||||
return PyInt_FromLong((long)m_dyn_operation);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Native functions */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
|
||||
short dyn_operation,
|
||||
PyTypeObject* T) :
|
||||
|
||||
SCA_IActuator(gameobj, T),
|
||||
m_dyn_operation(dyn_operation)
|
||||
{
|
||||
} /* End of constructor */
|
||||
|
||||
|
||||
KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
|
||||
{
|
||||
// there's nothing to be done here, really....
|
||||
} /* end of destructor */
|
||||
|
||||
|
||||
|
||||
bool KX_SCA_DynamicActuator::Update()
|
||||
{
|
||||
// bool result = false; /*unused*/
|
||||
KX_GameObject *obj = (KX_GameObject*) GetParent();
|
||||
bool bNegativeEvent = IsNegativeEvent();
|
||||
KX_IPhysicsController* controller;
|
||||
RemoveAllEvents();
|
||||
|
||||
if (bNegativeEvent)
|
||||
return false; // do nothing on negative events
|
||||
|
||||
if (!obj)
|
||||
return false; // object not accessible, shouldnt happen
|
||||
controller = obj->GetPhysicsController();
|
||||
if (!controller)
|
||||
return false; // no physic object
|
||||
|
||||
switch (m_dyn_operation)
|
||||
{
|
||||
case 0:
|
||||
obj->RestoreDynamics();
|
||||
break;
|
||||
case 1:
|
||||
obj->SuspendDynamics();
|
||||
break;
|
||||
case 2:
|
||||
controller->setRigidBody(true);
|
||||
break;
|
||||
case 3:
|
||||
controller->setRigidBody(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CValue* KX_SCA_DynamicActuator::GetReplica()
|
||||
{
|
||||
KX_SCA_DynamicActuator* replica =
|
||||
new KX_SCA_DynamicActuator(*this);
|
||||
|
||||
if (replica == NULL)
|
||||
return NULL;
|
||||
|
||||
replica->ProcessReplica();
|
||||
|
||||
// this will copy properties and so on...
|
||||
CValue::AddDataToReplica(replica);
|
||||
|
||||
return replica;
|
||||
};
|
||||
|
||||
|
||||
/* eof */
|
76
source/gameengine/Ketsji/KX_SCA_DynamicActuator.h
Normal file
76
source/gameengine/Ketsji/KX_SCA_DynamicActuator.h
Normal file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Add object to the game world on action of this actuator
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// ***** BEGIN GPL LICENSE BLOCK *****
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software Foundation,
|
||||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
// All rights reserved.
|
||||
//
|
||||
// The Original Code is: all of this file.
|
||||
//
|
||||
// Contributor(s): Campbell Barton
|
||||
//
|
||||
// ***** END GPL LICENSE BLOCK *****
|
||||
//
|
||||
|
||||
#ifndef __KX_SCA_DYNAMICACTUATOR
|
||||
#define __KX_SCA_DYNAMICACTUATOR
|
||||
|
||||
#include "SCA_IActuator.h"
|
||||
#include "SCA_PropertyActuator.h"
|
||||
#include "SCA_LogicManager.h"
|
||||
|
||||
#include "KX_GameObject.h"
|
||||
#include "KX_IPhysicsController.h"
|
||||
|
||||
class KX_SCA_DynamicActuator : public SCA_IActuator
|
||||
{
|
||||
Py_Header;
|
||||
|
||||
// dynamics operation to apply to the game object
|
||||
short m_dyn_operation;
|
||||
public:
|
||||
KX_SCA_DynamicActuator(
|
||||
SCA_IObject* gameobj,
|
||||
short dyn_operation,
|
||||
PyTypeObject* T=&Type
|
||||
);
|
||||
|
||||
~KX_SCA_DynamicActuator(
|
||||
);
|
||||
|
||||
CValue*
|
||||
GetReplica(
|
||||
);
|
||||
|
||||
virtual bool
|
||||
Update();
|
||||
|
||||
virtual PyObject*
|
||||
_getattr(
|
||||
const STR_String& attr
|
||||
);
|
||||
|
||||
/* 1. setOperation */
|
||||
KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,setOperation);
|
||||
KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,getOperation);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user