[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14074] trunk/blender: Delta Loc/Rot/ Scale Ipo curve are now supporting in the BGE with the following limitations :

Benoit Bolsee benoit.bolsee at online.be
Wed Mar 12 22:33:25 CET 2008


Revision: 14074
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14074
Author:   ben2610
Date:     2008-03-12 22:33:24 +0100 (Wed, 12 Mar 2008)

Log Message:
-----------
Delta Loc/Rot/Scale Ipo curve are now supporting in the BGE with the following limitations:

1. All Ipo channels are now independent. 
In Blender 2.45, all 3 Loc Ipo channels were automatically set
together. For example, having just a LocX Ipo channel was sufficient
to fix the X, Y and Z coordinates, with the Y and Z value taken
from the object original Y and Z location in Blender. The same
was true for the 3 Rot and the 3 Scale Ipo channels: the missing
channels were assumed to have constant value taken from the object
original orientation/scale in Blender.
With this patch, all Ipo channels are now independent. 
THIS WILL CREATE BACKWARD COMPATIBILITY PROBLEM if you omit to
define the 3 channels of a same type together in your Blend file:
the undefined Loc, Rot, Scale coordinates of the object will
be influenced by the parent/spawner Loc/Rot/Scale in case the
object is a child or dynamically created.

2. Delta Loc, Rot, Scale are now supported with the following
limitations:
- The delta Loc/Rot Ipo modify the object global (NOT local)
location/orientation
- The delta Scale change the object local scale
- The delta Ipo curves are relative to the object starting
Loc/Rot/Scale when the Ipo was first activated; after that, the
delta Ipo becomes global. This means that the object will return
to this initial Loc/Rot/Scale when you later restart the Ipo
curve, even if you had changed the object Loc/Rot/Scale in the
meantime. Of course this applies only to the specific Loc/Rot/Scale
coordinate that are defined in the Ipo channels as the channels
are now independent.

3. When the objects are converted from Blender to the BGE, the
delta Loc/Rot/Scale that might result from initial non-zero values
in delta Ipo Curves will be ignored. However, as soon as the
delta Ipo curve is activated, the non-zero values will be taken
into account and the object will jump to the same Loc/Rot/Scale
situation as in Blender. Note that delta Ipo curves with initial
non-zero values is bad practice; logically, a delta Ipo curver
should always start from 0.

4. If you define both a global and delta channel of the same
type (LocX and DLocX), the result will be a global channel equivalent
to the sum of the two channels (LocX+DLocX).

Modified Paths:
--------------
    trunk/blender/intern/moto/include/MT_Matrix3x3.h
    trunk/blender/source/gameengine/Converter/KX_IpoConvert.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.h

Modified: trunk/blender/intern/moto/include/MT_Matrix3x3.h
===================================================================
--- trunk/blender/intern/moto/include/MT_Matrix3x3.h	2008-03-12 21:31:17 UTC (rev 14073)
+++ trunk/blender/intern/moto/include/MT_Matrix3x3.h	2008-03-12 21:33:24 UTC (rev 14074)
@@ -147,6 +147,26 @@
 	       			 -sj,      cj * si,      cj * ci);
 	}
 
+	void getEuler(MT_Scalar& yaw, MT_Scalar& pitch, MT_Scalar& roll) const
+		{			
+			if (m_el[2][0] != -1.0 && m_el[2][0] != 1.0) {
+				pitch = MT_Scalar(-asin(m_el[2][0]));
+				yaw = MT_Scalar(atan2(m_el[2][1] / cos(pitch), m_el[2][2] / cos(pitch)));
+				roll = MT_Scalar(atan2(m_el[1][0] / cos(pitch), m_el[0][0] / cos(pitch)));				
+			}
+			else {
+				roll = MT_Scalar(0);
+				if (m_el[2][0] == -1.0) {
+					pitch = MT_PI / 2.0;
+					yaw = MT_Scalar(atan2(m_el[0][1], m_el[0][2]));
+				}
+				else {
+					pitch = - MT_PI / 2.0;
+					yaw = MT_Scalar(atan2(m_el[0][1], m_el[0][2]));
+				}
+			}
+		}
+
     void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z) {
         m_el[0][0] *= x; m_el[0][1] *= y; m_el[0][2] *= z;
         m_el[1][0] *= x; m_el[1][1] *= y; m_el[1][2] *= z;

Modified: trunk/blender/source/gameengine/Converter/KX_IpoConvert.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_IpoConvert.cpp	2008-03-12 21:31:17 UTC (rev 14073)
+++ trunk/blender/source/gameengine/Converter/KX_IpoConvert.cpp	2008-03-12 21:33:24 UTC (rev 14074)
@@ -100,9 +100,9 @@
 
 		ipocontr->GetIPOTransform().SetPosition(
 			MT_Point3(
-			blenderobject->loc[0]+blenderobject->dloc[0],
-			blenderobject->loc[1]+blenderobject->dloc[1],
-			blenderobject->loc[2]+blenderobject->dloc[2]
+			blenderobject->loc[0]/*+blenderobject->dloc[0]*/,
+			blenderobject->loc[1]/*+blenderobject->dloc[1]*/,
+			blenderobject->loc[2]/*+blenderobject->dloc[2]*/
 			)
 		);
 		ipocontr->GetIPOTransform().SetEulerAngles(
@@ -134,7 +134,7 @@
 					&(ipocontr->GetIPOTransform().GetPosition()[0]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyPosition(true);
+			ipocontr->SetIPOChannelActive(OB_LOC_X, true);
 	
 		}
 		
@@ -145,7 +145,7 @@
 					&(ipocontr->GetIPOTransform().GetPosition()[1]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyPosition(true);
+			ipocontr->SetIPOChannelActive(OB_LOC_Y, true);
 		}
 		
 		ipo = ipoList->GetScalarInterpolator(OB_LOC_Z);
@@ -155,7 +155,7 @@
 					&(ipocontr->GetIPOTransform().GetPosition()[2]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyPosition(true);
+			ipocontr->SetIPOChannelActive(OB_LOC_Z, true);
 		}
 		
 		// Master the art of cut & paste programming...
@@ -167,7 +167,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaPosition()[0]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyPosition(true);
+			ipocontr->SetIPOChannelActive(OB_DLOC_X, true);
 		}
 		
 		ipo = ipoList->GetScalarInterpolator(OB_DLOC_Y);
@@ -177,7 +177,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaPosition()[1]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyPosition(true);
+			ipocontr->SetIPOChannelActive(OB_DLOC_Y, true);
 		}
 		
 		ipo = ipoList->GetScalarInterpolator(OB_DLOC_Z);
@@ -187,7 +187,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaPosition()[2]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyPosition(true);
+			ipocontr->SetIPOChannelActive(OB_DLOC_Z, true);
 		}
 		
 		// Explore the finesse of reuse and slight modification
@@ -199,7 +199,7 @@
 					&(ipocontr->GetIPOTransform().GetEulerAngles()[0]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyOrientation(true);
+			ipocontr->SetIPOChannelActive(OB_ROT_X, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_ROT_Y);
 		if (ipo) {
@@ -208,7 +208,7 @@
 					&(ipocontr->GetIPOTransform().GetEulerAngles()[1]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyOrientation(true);
+			ipocontr->SetIPOChannelActive(OB_ROT_Y, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_ROT_Z);
 		if (ipo) {
@@ -217,7 +217,7 @@
 					&(ipocontr->GetIPOTransform().GetEulerAngles()[2]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyOrientation(true);
+			ipocontr->SetIPOChannelActive(OB_ROT_Z, true);
 		}
 
 		// Hmmm, the need for a macro comes to mind... 
@@ -229,7 +229,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[0]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyOrientation(true);
+			ipocontr->SetIPOChannelActive(OB_DROT_X, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_DROT_Y);
 		if (ipo) {
@@ -238,7 +238,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[1]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyOrientation(true);
+			ipocontr->SetIPOChannelActive(OB_DROT_Y, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_DROT_Z);
 		if (ipo) {
@@ -247,7 +247,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[2]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyOrientation(true);
+			ipocontr->SetIPOChannelActive(OB_DROT_Z, true);
 		}
 
 		// Hang on, almost there... 
@@ -259,7 +259,7 @@
 					&(ipocontr->GetIPOTransform().GetScaling()[0]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyScaling(true);
+			ipocontr->SetIPOChannelActive(OB_SIZE_X, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_SIZE_Y);
 		if (ipo) {
@@ -268,7 +268,7 @@
 					&(ipocontr->GetIPOTransform().GetScaling()[1]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyScaling(true);
+			ipocontr->SetIPOChannelActive(OB_SIZE_Y, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_SIZE_Z);
 		if (ipo) {
@@ -277,7 +277,7 @@
 					&(ipocontr->GetIPOTransform().GetScaling()[2]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyScaling(true);
+			ipocontr->SetIPOChannelActive(OB_SIZE_Z, true);
 		}
 
 		// The last few... 
@@ -289,7 +289,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaScaling()[0]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyScaling(true);
+			ipocontr->SetIPOChannelActive(OB_DSIZE_X, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_DSIZE_Y);
 		if (ipo) {
@@ -298,7 +298,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaScaling()[1]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyScaling(true);
+			ipocontr->SetIPOChannelActive(OB_DSIZE_Y, true);
 		}
 		ipo = ipoList->GetScalarInterpolator(OB_DSIZE_Z);
 		if (ipo) {
@@ -307,7 +307,7 @@
 					&(ipocontr->GetIPOTransform().GetDeltaScaling()[2]),
 					ipo);
 			ipocontr->AddInterpolator(interpolator);
-			ipocontr->SetModifyScaling(true);
+			ipocontr->SetIPOChannelActive(OB_DSIZE_Z, true);
 		}
 		
 		{

Modified: trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.cpp	2008-03-12 21:31:17 UTC (rev 14073)
+++ trunk/blender/source/gameengine/Ketsji/KX_IPO_SGController.cpp	2008-03-12 21:33:24 UTC (rev 14074)
@@ -51,20 +51,21 @@
 #include "KX_ScalarInterpolator.h"
 #include "KX_GameObject.h"
 #include "KX_IPhysicsController.h"
+#include "DNA_ipo_types.h"
+#include "BLI_arithb.h"
 
 // All objects should start on frame 1! Will we ever need an object to 
 // start on another frame, the 1.0 should change.
 KX_IpoSGController::KX_IpoSGController() 
-: m_modify_position(false),
-  m_modify_orientation(false),
-  m_modify_scaling(false),
-  m_ipo_as_force(false),
+: m_ipo_as_force(false),
   m_force_ipo_acts_local(false),
   m_modified(true),
+  m_ipo_start_initialized(false),
   m_ipotime(1.0)
 {
 	m_game_object = NULL;
-
+	for (int i=0; i < KX_MAX_IPO_CHANNELS; i++)
+		m_ipo_channels_active[i] = false;
 }
 
 
@@ -115,21 +116,60 @@
 		}
 		
 		SG_Spatial* ob = (SG_Spatial*)m_pObject;
-		
-		if (m_modify_position) {
-			if (m_ipo_as_force) {
-				
-				if (m_game_object && ob) {
+
+		//initialization on the first frame of the IPO
+		if (! m_ipo_start_initialized && currentTime > 0.0) {
+			m_ipo_start_point = ob->GetLocalPosition();
+			m_ipo_start_orient = ob->GetLocalOrientation();
+			m_ipo_start_scale = ob->GetLocalScale();
+			m_ipo_start_initialized = true;
+		}
+
+		//modifies position?
+		if (m_ipo_channels_active[OB_LOC_X] || m_ipo_channels_active[OB_LOC_Y] || m_ipo_channels_active[OB_LOC_Z] || m_ipo_channels_active[OB_DLOC_X] || m_ipo_channels_active[OB_DLOC_Y] || m_ipo_channels_active[OB_DLOC_Z])
+		{
+			if (m_ipo_as_force == true) 
+			{
+				if (m_game_object && ob) 
+				{
 					m_game_object->GetPhysicsController()->ApplyForce(m_force_ipo_acts_local ?
 						ob->GetWorldOrientation() * m_ipo_xform.GetPosition() :
 						m_ipo_xform.GetPosition(), false);
 				}
-
-			} else {
-				ob->SetLocalPosition(m_ipo_xform.GetPosition());
+			} 
+			else
+			{
+				//by default, leave object as it stands
+				MT_Point3 newPosition = ob->GetLocalPosition();
+				//apply separate IPO channels if there is any data in them
+				//Loc and dLoc act by themselves or are additive
+				//LocX and dLocX
+				if (m_ipo_channels_active[OB_LOC_X]) {
+					newPosition[0] = (m_ipo_channels_active[OB_DLOC_X] ? m_ipo_xform.GetPosition()[0] + m_ipo_xform.GetDeltaPosition()[0] : m_ipo_xform.GetPosition()[0]);
+				}
+				else if (m_ipo_channels_active[OB_DLOC_X] && m_ipo_start_initialized) {
+					newPosition[0] = (m_ipo_start_point[0] + m_ipo_xform.GetDeltaPosition()[0]);
+				}
+				//LocY and dLocY
+				if (m_ipo_channels_active[OB_LOC_Y]) {
+					newPosition[1] = (m_ipo_channels_active[OB_DLOC_Y] ? m_ipo_xform.GetPosition()[1] + m_ipo_xform.GetDeltaPosition()[1] : m_ipo_xform.GetPosition()[1]);
+				}
+				else if (m_ipo_channels_active[OB_DLOC_Y] && m_ipo_start_initialized) {
+					newPosition[1] = (m_ipo_start_point[1] + m_ipo_xform.GetDeltaPosition()[1]);
+				}
+				//LocZ and dLocZ
+				if (m_ipo_channels_active[OB_LOC_Z]) {
+					newPosition[2] = (m_ipo_channels_active[OB_DLOC_Z] ? m_ipo_xform.GetPosition()[2] + m_ipo_xform.GetDeltaPosition()[2] : m_ipo_xform.GetPosition()[2]);
+				}
+				else if (m_ipo_channels_active[OB_DLOC_Z] && m_ipo_start_initialized) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list