comparison 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
comparison
equal deleted inserted replaced
406:b50dd16543b2 407:f27880d4c08c
37 #include "model/structures/instancetree.h" 37 #include "model/structures/instancetree.h"
38 #include "model/structures/instance.h" 38 #include "model/structures/instance.h"
39 #include "model/structures/location.h" 39 #include "model/structures/location.h"
40 #include "util/log/logger.h" 40 #include "util/log/logger.h"
41 #include "util/math/fife_math.h" 41 #include "util/math/fife_math.h"
42 #include "util/math/angles.h"
42 #include "util/time/timemanager.h" 43 #include "util/time/timemanager.h"
43 #include "video/renderbackend.h" 44 #include "video/renderbackend.h"
44 #include "video/image.h" 45 #include "video/image.h"
45 #include "video/imagepool.h" 46 #include "video/imagepool.h"
46 #include "video/animation.h" 47 #include "video/animation.h"
524 drawpt = toScreenCoordinates( instance->getLocationRef().getMapCoordinates() ); 525 drawpt = toScreenCoordinates( instance->getLocationRef().getMapCoordinates() );
525 vc.facing_angle = getAngleBetween(instance->getLocationRef(), instance->getFacingLocation()); 526 vc.facing_angle = getAngleBetween(instance->getLocationRef(), instance->getFacingLocation());
526 angle = vc.facing_angle; 527 angle = vc.facing_angle;
527 } 528 }
528 529
529 angle += instance->getRotation(); 530 //generate angle based on camera rotation and instance rotation
531 angle = angle + m_rotation + instance->getRotation();
530 532
531 Image* image = NULL; 533 Image* image = NULL;
532 Action* action = instance->getCurrentAction(); 534 Action* action = instance->getCurrentAction();
533 if (action) { 535 if (action) {
534 FL_DBG(_log, "Instance has action"); 536 FL_DBG(_log, "Instance has action");
535 int animation_id = action->getVisual<ActionVisual>()->getAnimationIndexByAngle(angle); 537 int animation_id = action->getVisual<ActionVisual>()->getAnimationIndexByAngle(vc.facing_angle + m_rotation);
538
539 int facing_angle;
540 if (vc.facing_angle < 0){
541 facing_angle = 360+vc.facing_angle; //make it a positive angle
542 }
543 instance->setRotation(facing_angle); //update so the animation has correct rotation
544
536 Animation& animation = m_apool->getAnimation(animation_id); 545 Animation& animation = m_apool->getAnimation(animation_id);
537 unsigned int animtime = instance->getActionRuntime() % animation.getDuration(); 546 unsigned int animtime = instance->getActionRuntime() % animation.getDuration();
538 image = animation.getFrameByTimestamp(animtime); 547 image = animation.getFrameByTimestamp(animtime);
539 } else { 548 } else {
540 FL_DBG(_log, "No action"); 549 FL_DBG(_log, "No action");