diff engine/core/view/camera.cpp @ 407:f27880d4c08c

Moved getAngleBetween() form Camera to angles.h and updated it to not use the camera angle in it's calculation. Added camera rotation to the angle calculation for selecting the correct image by angles. Added a call to setRotation() to make sure that instance rotation is valid.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 29 Jan 2010 21:03:51 +0000
parents cfe2f6db4964
children 219b8036708c
line wrap: on
line diff
--- a/engine/core/view/camera.cpp	Fri Jan 29 19:52:14 2010 +0000
+++ b/engine/core/view/camera.cpp	Fri Jan 29 21:03:51 2010 +0000
@@ -39,6 +39,7 @@
 #include "model/structures/location.h"
 #include "util/log/logger.h"
 #include "util/math/fife_math.h"
+#include "util/math/angles.h"
 #include "util/time/timemanager.h"
 #include "video/renderbackend.h"
 #include "video/image.h"
@@ -526,13 +527,21 @@
 					angle = vc.facing_angle;
 				}
 
-				angle += instance->getRotation();
+				//generate angle based on camera rotation and instance rotation
+				angle = angle + m_rotation + instance->getRotation();
 
 				Image* image = NULL;
 				Action* action = instance->getCurrentAction();
 				if (action) {
 					FL_DBG(_log, "Instance has action");
-					int animation_id = action->getVisual<ActionVisual>()->getAnimationIndexByAngle(angle);
+					int animation_id = action->getVisual<ActionVisual>()->getAnimationIndexByAngle(vc.facing_angle + m_rotation);
+
+					int facing_angle;
+					if (vc.facing_angle < 0){
+						facing_angle = 360+vc.facing_angle; //make it a positive angle
+					}
+					instance->setRotation(facing_angle);  //update so the animation has correct rotation
+
 					Animation& animation = m_apool->getAnimation(animation_id);
 					unsigned int animtime = instance->getActionRuntime() % animation.getDuration();
 					image = animation.getFrameByTimestamp(animtime);