[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15486] trunk/blender: BGE logic patch: new "Add" mode for Ipo actuator, several corrections in state system.

Benoit Bolsee benoit.bolsee at online.be
Tue Jul 8 14:18:52 CEST 2008


Revision: 15486
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15486
Author:   ben2610
Date:     2008-07-08 14:18:43 +0200 (Tue, 08 Jul 2008)

Log Message:
-----------
BGE logic patch: new "Add" mode for Ipo actuator, several corrections in state system.

New Add mode for Ipo actuator
=============================
A new Add button, mutually exclusive with Force button, is available in
the Ipo actuator. When selected, it activates the Add mode that consists
in adding the Ipo curve to the current object situation in world
coordinates, or parent coordinates if the object has a parent. Scale Ipo
curves are multiplied instead of added to the object current scale.
If the local flag is selected, the Ipo curve is added (multiplied) in 
the object's local coordinates. 
Delta Ipo curves are handled identically to normal Ipo curve and there 
is no need to work with Delta Ipo curves provided that you make sure 
that the Ipo curve starts from origin. Origin means location 0 for 
Location Ipo curve, rotation 0 for Rotation Ipo curve and scale 1 for 
Scale Ipo curve.

The "current object situation" means the object's location, rotation 
and scale at the start of the Ipo curve. For Loop Stop and Loop End Ipo 
actuators, this means at the start of each loop. This initial state is
used as a base during the execution of the Ipo Curve but when the Ipo 
curve is restarted (later or immediately in case of Loop mode), the  
object current situation at that time is used as the new base.

For reference, here is the exact operation of the Add mode for each
type of Ipo curve (oLoc, oRot, oScale, oMat: object's loc/rot/scale
and orientation matrix at the start of the curve; iLoc, iRot, iScale,
iMat: Ipo curve loc/rot/scale and orientation matrix resulting from
the rotation).

Location
  Local=false: newLoc = oLoc+iLoc
  Local=true : newLoc = oLoc+oScale*(oMat*iLoc)
Rotation
  Local=false: newMat = iMat*oMat
  Local=true : newMat = oMat*iMat
Scale
  Local=false: newScale = oScale*iScale
  Local=true : newScale = oScale*iScale

Add+Local mode is very useful to have dynamic object executing complex
movement relative to their current location/orientation. Of cource, 
dynamics should be disabled during the execution of the curve.

Several corrections in state system
===================================
- Object initial state is taken into account when adding object
  dynamically
- Fix bug with link count when adding object dynamically
- Fix false on-off detection for Actuator sensor when actuator is
  trigged on negative event.
- Fix Parent actuator false activation on negative event
- Loop Ipo curve not restarting at correct frame when start frame is
  different from one.

Modified Paths:
--------------
    trunk/blender/projectfiles_vc7/blender/blenlib/BLI_blenlib.vcproj
    trunk/blender/source/blender/makesdna/DNA_actuator_types.h
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_IActuator.h
    trunk/blender/source/gameengine/GameLogic/SCA_IObject.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_IObject.h
    trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.h
    trunk/blender/source/gameengine/Ketsji/KX_IpoActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IpoActuator.h
    trunk/blender/source/gameengine/Ketsji/KX_ParentActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_Controller.h

Modified: trunk/blender/projectfiles_vc7/blender/blenlib/BLI_blenlib.vcproj
===================================================================
--- trunk/blender/projectfiles_vc7/blender/blenlib/BLI_blenlib.vcproj	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/projectfiles_vc7/blender/blenlib/BLI_blenlib.vcproj	2008-07-08 12:18:43 UTC (rev 15486)
@@ -359,6 +359,9 @@
 				RelativePath="..\..\..\source\blender\blenlib\intern\BLI_memarena.c">
 			</File>
 			<File
+				RelativePath="..\..\..\source\blender\blenlib\intern\BLI_mempool.c">
+			</File>
+			<File
 				RelativePath="..\..\..\source\blender\blenlib\intern\boxpack2d.c">
 			</File>
 			<File
@@ -474,6 +477,9 @@
 				RelativePath="..\..\..\source\blender\blenlib\BLI_memarena.h">
 			</File>
 			<File
+				RelativePath="..\..\..\source\blender\blenlib\BLI_mempool.h">
+			</File>
+			<File
 				RelativePath="..\..\..\source\blender\blenlib\intern\BLI_scanfill.h">
 			</File>
 			<File

Modified: trunk/blender/source/blender/makesdna/DNA_actuator_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_actuator_types.h	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/blender/makesdna/DNA_actuator_types.h	2008-07-08 12:18:43 UTC (rev 15486)
@@ -339,8 +339,9 @@
 /* ipoactuator->flag */
 #define ACT_IPOFORCE        (1 << 0)
 #define ACT_IPOEND          (1 << 1)
-#define ACT_IPOFORCE_LOCAL  (1 << 2)
-#define ACT_IPOCHILD        (1 << 4)			
+#define ACT_IPOLOCAL		(1 << 2)
+#define ACT_IPOCHILD        (1 << 4)	
+#define ACT_IPOADD			(1 << 5)
 
 /* ipoactuator->flag for k2k */
 #define ACT_K2K_PREV		1

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/blender/src/buttons_logic.c	2008-07-08 12:18:43 UTC (rev 15486)
@@ -1581,6 +1581,18 @@
 	}
 }
 
+static void change_ipo_actuator(void *arg1_but, void *arg2_ia)
+{
+	bIpoActuator *ia = arg2_ia;
+	uiBut *but = arg1_but;
+
+	if (but->retval & ACT_IPOFORCE)
+		ia->flag &= ~ACT_IPOADD;
+	else if (but->retval & ACT_IPOADD)
+		ia->flag &= ~ACT_IPOFORCE;
+	but->retval = B_REDR;
+}
+
 void update_object_actuator_PID(void *act, void *arg)
 {
 	bObjectActuator *oa = act;
@@ -1799,42 +1811,49 @@
 			
 			str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
 			
-			uiDefButS(block, MENU, B_REDR, str,		xco+20, yco-24, width-40 - (width-40)/3, 19, &ia->type, 0, 0, 0, 0, "");
-			uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
-				"Child",	xco+20+0.666*(width-40), yco-24, (width-40)/3, 19, 
+			uiDefButS(block, MENU, B_REDR, str,		xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
+
+			but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
+				"Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
 				&ia->flag, 0, 0, 0, 0, 
-				"Add all children Objects as well");
+				"Convert Ipo to force. Force is applied in global or local coordinate according to Local flag"); 
+			uiButSetFunc(but, change_ipo_actuator, but, ia);
 
+			but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
+				"Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
+				&ia->flag, 0, 0, 0, 0, 
+				"Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
+			uiButSetFunc(but, change_ipo_actuator, but, ia);
+			
+			/* Only show the do-force-local toggle if force is requested */
+			if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
+				uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
+					"L", xco+width-30, yco-24, 20, 19, 
+					&ia->flag, 0, 0, 0, 0, 
+					"Let the ipo acts in local coordinates, used in Force and Add mode."); 
+			}
+
 			if(ia->type==ACT_IPO_FROM_PROP) {
 				uiDefBut(block, TEX, 0, 
-					"Prop: ",		xco+20, yco-44, width-40, 19, 
+					"Prop: ",		xco+10, yco-44, width-80, 19, 
 					ia->name, 0.0, 31.0, 0, 0, 
 					"Use this property to define the Ipo position");
 			}
 			else {
 				uiDefButI(block, NUM, 0, 
-					"Sta",		xco+20, yco-44, (width-100)/2, 19, 
+					"Sta",		xco+10, yco-44, (width-80)/2, 19, 
 					&ia->sta, 0.0, MAXFRAMEF, 0, 0, 
 					"Start frame, (subtract 1 to match blenders frame numbers)");
 				uiDefButI(block, NUM, 0, 
-					"End",		xco+18+(width-90)/2, yco-44, (width-100)/2, 19, 
+					"End",		xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
 					&ia->end, 0.0, MAXFRAMEF, 0, 0, 
 					"End frame, (subtract 1 to match blenders frame numbers)");
-				
-				uiDefButBitS(block, TOG, ACT_IPOFORCE, B_REDR, 
-					"Force", xco+width-78, yco-44, 43, 19, 
-					&ia->flag, 0, 0, 0, 0, 
-					"Convert Ipo to force"); 
-				
-				/* Only show the do-force-local toggle if force is requested */
-				if (ia->flag & ACT_IPOFORCE) {
-					uiDefButBitS(block, TOG, ACT_IPOFORCE_LOCAL, 0, 
-						"L", xco+width-35, yco-44, 15, 19, 
-						&ia->flag, 0, 0, 0, 0, 
-						"Let the force-ipo act in local coordinates."); 
-				}
-				
 			}
+			uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
+				"Child",	xco+10+(width-80), yco-44, 60, 19, 
+				&ia->flag, 0, 0, 0, 0, 
+				"Update IPO on all children Objects as well");
+
 			yco-= ysize;
 			break;
 		}

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2008-07-08 12:18:43 UTC (rev 15486)
@@ -2331,7 +2331,8 @@
 	{
 		KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
 		struct Object* blenderobj = converter->FindBlenderObject(gameobj);
-		gameobj->SetState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state);
+		gameobj->SetInitState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state);
+		gameobj->ResetState();
 	}
 
 #endif //CONVERT_LOGIC

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp	2008-07-08 12:18:43 UTC (rev 15486)
@@ -233,7 +233,8 @@
 				STR_String propname = ( ipoact->name ? ipoact->name : "");
 				// first bit?
 				bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
-				bool force_local = (ipoact->flag & ACT_IPOFORCE_LOCAL);
+				bool local = (ipoact->flag & ACT_IPOLOCAL);
+				bool ipo_add = (ipoact->flag & ACT_IPOADD);
 				
 				KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
 					gameobj,
@@ -244,8 +245,8 @@
 					ipoact->type + 1, // + 1, because Blender starts to count at zero,
 					// Ketsji at 1, because zero is reserved for "NoDef"
 					ipo_as_force,
-					force_local
-					);
+					ipo_add,
+					local);
 				baseact = tmpbaseact;
 				break;
 			}

Modified: trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp	2008-07-08 12:18:43 UTC (rev 15486)
@@ -111,7 +111,7 @@
 {
 	if (m_actuator)
 	{
-		m_midresult = m_actuator->IsActive();
+		m_midresult = m_actuator->IsActive() && !m_actuator->IsNegativeEvent();
 	}
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_IActuator.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_IActuator.h	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/gameengine/GameLogic/SCA_IActuator.h	2008-07-08 12:18:43 UTC (rev 15486)
@@ -87,6 +87,7 @@
 	bool IsNegativeEvent() const;
 	virtual ~SCA_IActuator();
 
+	void ClrLink() { m_links=0; }
 	void IncLink() { m_links++; }
 	void DecLink();
 	bool IsNoLink() const { return !m_links; }

Modified: trunk/blender/source/gameengine/GameLogic/SCA_IObject.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_IObject.cpp	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/gameengine/GameLogic/SCA_IObject.cpp	2008-07-08 12:18:43 UTC (rev 15486)
@@ -40,7 +40,7 @@
 
 MT_Point3 SCA_IObject::m_sDummy=MT_Point3(0,0,0);
 
-SCA_IObject::SCA_IObject(PyTypeObject* T): m_state(0), CValue(T)
+SCA_IObject::SCA_IObject(PyTypeObject* T): m_initState(0), m_state(0), CValue(T)
 {
 	m_suspended = false;
 }
@@ -164,7 +164,9 @@
 	{
 		SCA_IActuator* newactuator = (SCA_IActuator*) (*ita)->GetReplica();
 		newactuator->ReParent(this);
+		// actuators are initially not connected to any controller
 		newactuator->SetActive(false);
+		newactuator->ClrLink();
 		oldactuators[act++] = newactuator;
 	}
 
@@ -175,6 +177,7 @@
 	{
 		SCA_IController* newcontroller = (SCA_IController*)(*itc)->GetReplica();
 		newcontroller->ReParent(this);
+		newcontroller->SetActive(false);
 		oldcontrollers[con++]=newcontroller;
 
 	}
@@ -186,6 +189,9 @@
 	{
 		SCA_ISensor* newsensor = (SCA_ISensor*)(*its)->GetReplica();
 		newsensor->ReParent(this);
+		newsensor->SetActive(false);
+		// sensors are initially not connected to any controller
+		newsensor->ClrLink();
 		oldsensors[sen++] = newsensor;
 	}
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_IObject.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_IObject.h	2008-07-08 11:47:22 UTC (rev 15485)
+++ trunk/blender/source/gameengine/GameLogic/SCA_IObject.h	2008-07-08 12:18:43 UTC (rev 15486)
@@ -69,6 +69,11 @@
 	bool m_suspended;
 
 	/**
+	 * init state of object (used when object is created)
+	 */
+	unsigned int			m_initState;
+
+	/**
 	 * current state = bit mask of state that are active
 	 */
 	unsigned int			m_state;
@@ -118,6 +123,16 @@
 	void Resume(void);
 
 	/**
+	 * Set init state
+	 */
+	void SetInitState(unsigned int initState) { m_initState = initState; }
+
+	/**
+	 * initialize the state when object is created
+	 */
+	void ResetState(void) { SetState(m_initState); }
+
+	/**
 	 * Set the object state
 	 */
 	void SetState(unsigned int state);


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list