From 782f0b63829a2c257a6e2942c49882f7fe04c33c Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Wed, 11 Jan 2012 07:27:39 +0000 Subject: bge camera actuator: -X and -Y axis The camera actuator only allows to look the object from its front face. Given that Blender takes -Y as the default forward orientation, the current functionality doesn't let a camera to track an actor from behind. This patch allows for -X and -Y axis tracking. This way a camera over the shoulders of a character is possible (without resorting to rotate the mesh/armature original orientation. - patch reviewed by Campbell Barton, thanks --- source/blender/blenkernel/intern/sca.c | 2 +- source/blender/blenloader/intern/readfile.c | 18 +++++- source/blender/makesdna/DNA_actuator_types.h | 4 -- source/blender/makesrna/intern/rna_actuator.c | 8 ++- .../gameengine/Converter/KX_ConvertActuators.cpp | 2 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 67 +++++++++++++++------- source/gameengine/Ketsji/KX_CameraActuator.h | 6 +- 7 files changed, 74 insertions(+), 33 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index f7eda6bd9b3..92dfe90eec1 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -428,7 +428,7 @@ void init_actuator(bActuator *act) case ACT_CAMERA: act->data= MEM_callocN(sizeof(bCameraActuator), "camact"); ca = act->data; - ca->axis = ACT_CAMERA_X; + ca->axis = OB_POSX; ca->damping = 1.0/32.0; break; case ACT_EDIT_OBJECT: diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index bb5682f4ebd..1f45be6848d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -12941,7 +12941,23 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* put compatibility code here until next subversion bump */ { - + { + /* convert Camera Actuator values to defines */ + Object *ob; + bActuator *act; + for(ob = main->object.first; ob; ob= ob->id.next) { + for(act= ob->actuators.first; act; act= act->next) { + if (act->type == ACT_CAMERA) { + bCameraActuator *ba= act->data; + + if(ba->axis==(float) 'x') ba->axis=OB_POSX; + else if (ba->axis==(float)'y') ba->axis=OB_POSY; + /* don't do an if/else to avoid imediate subversion bump*/ +// ba->axis=((ba->axis == (float) 'x')?OB_POSX_X:OB_POSY); + } + } + } + } } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h index a4280a6e463..076910ade1f 100644 --- a/source/blender/makesdna/DNA_actuator_types.h +++ b/source/blender/makesdna/DNA_actuator_types.h @@ -520,10 +520,6 @@ typedef struct bActuator { #define ACT_STATE_REMOVE 2 #define ACT_STATE_CHANGE 3 -/* cameraactuator->axis */ -#define ACT_CAMERA_X (float)'x' -#define ACT_CAMERA_Y (float)'y' - /* steeringactuator->type */ #define ACT_STEERING_SEEK 0 #define ACT_STEERING_FLEE 1 diff --git a/source/blender/makesrna/intern/rna_actuator.c b/source/blender/makesrna/intern/rna_actuator.c index 612c34d1c92..6098e885df5 100644 --- a/source/blender/makesrna/intern/rna_actuator.c +++ b/source/blender/makesrna/intern/rna_actuator.c @@ -867,8 +867,10 @@ static void rna_def_camera_actuator(BlenderRNA *brna) PropertyRNA *prop; static EnumPropertyItem prop_axis_items[] ={ - {ACT_CAMERA_X, "X", 0, "X", "Camera tries to get behind the X axis"}, - {ACT_CAMERA_Y, "Y", 0, "Y", "Camera tries to get behind the Y axis"}, + {OB_POSX, "POS_X", 0, "+X", "Camera tries to get behind the X axis"}, + {OB_POSY, "POS_Y", 0, "+Y", "Camera tries to get behind the Y axis"}, + {OB_NEGX, "NEG_X", 0, "-X", "Camera tries to get behind the -X axis"}, + {OB_NEGY, "NEG_Y", 0, "-Y", "Camera tries to get behind the -Y axis"}, {0, NULL, 0, NULL, NULL}}; srna= RNA_def_struct(brna, "CameraActuator", "Actuator"); @@ -905,7 +907,7 @@ static void rna_def_camera_actuator(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Damping", "Strength of the constraint that drives the camera behind the target"); RNA_def_property_update(prop, NC_LOGIC, NULL); - /* x/y */ + /* +x/+y/-x/-y */ prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "axis"); RNA_def_property_enum_items(prop, prop_axis_items); diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index f4b173763d3..be14400f33a 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -300,7 +300,7 @@ void BL_ConvertActuators(const char* maggiename, camact->height, camact->min, camact->max, - camact->axis=='x', + camact->axis, camact->damping); baseact = tmpcamact; } diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index d4aae68dafb..cd0aff0a87b 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -53,7 +53,7 @@ KX_CameraActuator::KX_CameraActuator( float hght, float minhght, float maxhght, - bool xytog, + short axis, float damping ): SCA_IActuator(gameobj, KX_ACT_CAMERA), @@ -61,7 +61,7 @@ KX_CameraActuator::KX_CameraActuator( m_height (hght), m_minHeight (minhght), m_maxHeight (maxhght), - m_x (xytog), + m_axis(axis), m_damping (damping) { if (m_ob) @@ -264,23 +264,50 @@ bool KX_CameraActuator::Update(double curtime, bool frame) /* C4: camera behind actor */ - if (m_x) { - fp1[0] = actormat[0][0]; - fp1[1] = actormat[1][0]; - fp1[2] = actormat[2][0]; - - fp2[0] = frommat[0][0]; - fp2[1] = frommat[1][0]; - fp2[2] = frommat[2][0]; - } - else { - fp1[0] = actormat[0][1]; - fp1[1] = actormat[1][1]; - fp1[2] = actormat[2][1]; - - fp2[0] = frommat[0][1]; - fp2[1] = frommat[1][1]; - fp2[2] = frommat[2][1]; + switch (m_axis) { + case OB_POSX: + /* X */ + fp1[0] = actormat[0][0]; + fp1[1] = actormat[1][0]; + fp1[2] = actormat[2][0]; + + fp2[0] = frommat[0][0]; + fp2[1] = frommat[1][0]; + fp2[2] = frommat[2][0]; + break; + case OB_POSY: + /* Y */ + fp1[0] = actormat[0][1]; + fp1[1] = actormat[1][1]; + fp1[2] = actormat[2][1]; + + fp2[0] = frommat[0][1]; + fp2[1] = frommat[1][1]; + fp2[2] = frommat[2][1]; + break; + case OB_NEGX: + /* -X */ + fp1[0] = -actormat[0][0]; + fp1[1] = -actormat[1][0]; + fp1[2] = -actormat[2][0]; + + fp2[0] = frommat[0][0]; + fp2[1] = frommat[1][0]; + fp2[2] = frommat[2][0]; + break; + case OB_NEGY: + /* -Y */ + fp1[0] = -actormat[0][1]; + fp1[1] = -actormat[1][1]; + fp1[2] = -actormat[2][1]; + + fp2[0] = frommat[0][1]; + fp2[1] = frommat[1][1]; + fp2[2] = frommat[2][1]; + break; + default: + assert(0); + break; } inp= fp1[0]*fp2[0] + fp1[1]*fp2[1] + fp1[2]*fp2[2]; @@ -389,7 +416,7 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { KX_PYATTRIBUTE_FLOAT_RW("min",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_minHeight), KX_PYATTRIBUTE_FLOAT_RW("max",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_maxHeight), KX_PYATTRIBUTE_FLOAT_RW("height",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_height), - KX_PYATTRIBUTE_BOOL_RW("useXY",KX_CameraActuator,m_x), + KX_PYATTRIBUTE_SHORT_RW("axis", 0, 3, true, KX_CameraActuator,m_axis), KX_PYATTRIBUTE_RW_FUNCTION("object", KX_CameraActuator, pyattr_get_object, pyattr_set_object), KX_PYATTRIBUTE_FLOAT_RW("damping",0.f,10.f,KX_CameraActuator,m_damping), {NULL} diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index a6344ae380a..1cae676fe3f 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -70,8 +70,8 @@ private : /** max (float), */ float m_maxHeight; - /** xy toggle (pick one): true == x, false == y */ - bool m_x; + /** axis the camera tries to get behind: +x/+y/-x/-y */ + short m_axis; /** damping (float), */ float m_damping; @@ -97,7 +97,7 @@ private : float hght, float minhght, float maxhght, - bool xytog, + short axis, float damping ); -- cgit v1.2.3