From ed54bcf00babd58d4a439603b7b0fa9d6aa54f46 Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Thu, 6 Sep 2012 23:35:56 +0200 Subject: [PATCH] Changed: #1469 Computations for the new magic step --HG-- branch : gsoc2012-fabien --- .../camera_animation_steps_players.cpp | 76 +++++++++++-- .../position_or_entity_pos_resolver.cpp | 104 ++++++++++++++++-- .../position_or_entity_pos_resolver.h | 5 + 3 files changed, 168 insertions(+), 17 deletions(-) diff --git a/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp b/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp index fdb821288..93e7c9995 100644 --- a/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp +++ b/code/ryzom/client/src/camera_animation_manager/camera_animation_steps_players.cpp @@ -76,16 +76,78 @@ public: { TCameraAnimationOutputInfo camInfo; - /*// We don't change the position - camInfo.CamPos = currCamInfo.StartCamPos; + NLMISC::CVector targetPos = resolvePositionOrEntityPosition(PositionTarget, currCamInfo); - float ratio = currCamInfo.ElapsedTimeSinceStartStep / getDuration(); + ////////////////////////////////////////////////////////////////////////// + // Position + { + float ratio = 1.f; + if (PositionTransitionTime > 0.f) + ratio = currCamInfo.ElapsedTimeSinceStartStep / PositionTransitionTime; + if (ratio > 1.f) + ratio = 1.f; - // We compute the final look at direction - NLMISC::CVector finalDir = resolvePositionOrEntityPosition(LookAtPos) - camInfo.CamPos; + // We compute the current position between the starting position and the final position + NLMISC::CVector movementVector = targetPos - currCamInfo.StartCamPos; - // We get the current look at direction - camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir);*/ + // We substract the distance + float currDist = movementVector.norm(); + float substractRatio = 0.f; + if (currDist > 0.f) + substractRatio = (currDist - DistanceTo) / currDist; + if ((currDist - DistanceTo) < 0.f) + substractRatio = 0.f; + movementVector = movementVector * substractRatio; + + // We current position is computed using the ratio and the starting position + NLMISC::CVector offset = movementVector * ratio; + camInfo.CamPos = currCamInfo.StartCamPos + offset; + } + + ////////////////////////////////////////////////////////////////////////// + // Turn around + if (HasTurnAround) + { + // Now we compute the current angle between our position and the target's position + NLMISC::CVector2f currTopVector(camInfo.CamPos.x - targetPos.x, camInfo.CamPos.y - targetPos.y); + float distance2D = currTopVector.norm(); + currTopVector.normalize(); + + float angle = acosf(currTopVector.x); + if (currTopVector.y < 0) + angle *= -1.f; + + // We compute an angle to travail in function of the speed + float angleOffset = DT * TurnAroundSpeed; + + float newAngle = angle + angleOffset; + + // We compute the new position for this angle + NLMISC::CVector2f new2DPos(cosf(newAngle), sinf(newAngle)); + new2DPos = new2DPos * distance2D; + + // We integrate this new position in the world + NLMISC::CVector newDir(new2DPos.x, new2DPos.y, camInfo.CamPos.z - targetPos.z); + + camInfo.CamPos = targetPos + newDir; + } + + ////////////////////////////////////////////////////////////////////////// + // Look at target + { + float ratio = 1.f; + if (DirectionTransitionTime > 0.f) + ratio = currCamInfo.ElapsedTimeSinceStartStep / DirectionTransitionTime; + if (ratio > 1.f) + ratio = 1.f; + + // We compute the final look at direction + NLMISC::CVector finalDir = resolvePositionOrEntityTargetDir(LookAtTarget, currCamInfo, camInfo.CamPos); + + // We get the current look at direction + camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir); + } + ////////////////////////////////////////////////////////////////////////// return camInfo; } diff --git a/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.cpp b/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.cpp index 0a381b31e..9e7e50d02 100644 --- a/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.cpp +++ b/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.cpp @@ -19,7 +19,7 @@ #include "game_share/position_or_entity_type.h" #include "entities.h" -NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity) +NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo) { if (!posOrEntity.isValid()) { @@ -29,21 +29,105 @@ NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEn if (posOrEntity.isPosition()) return posOrEntity.getPosition(); + else if (posOrEntity.isPreviousPos()) + { + return currCamInfo.StartCamPos; + } + else if (posOrEntity.isReturnPos()) + { + return currCamInfo.AnimStartCamPos; + } + else if (posOrEntity.isEntityId()) + { + CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId()); + if (!entity) + { + nlwarning(" invalid entity with compressed id %d", posOrEntity.getEntityId()); + return NLMISC::CVector(); + } + else + { + NLMISC::CVector pos; + if (!entity->getHeadPos(pos)) + pos = entity->pos(); + + return pos; + } + } + return NLMISC::CVector(); +} - CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId()); - if (!entity) +NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity) +{ + if (!posOrEntity.isValid()) { - nlwarning(" invalid entity with compressed id %d", posOrEntity.getEntityId()); + nlwarning(" invalid position or entity"); return NLMISC::CVector(); } - else + + if (posOrEntity.isPosition()) + return posOrEntity.getPosition(); + else if (posOrEntity.isEntityId()) { - NLMISC::CVector pos; - if (!entity->getHeadPos(pos)) - pos = entity->pos(); - - return pos; + CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId()); + if (!entity) + { + nlwarning(" invalid entity with compressed id %d", posOrEntity.getEntityId()); + return NLMISC::CVector(); + } + else + { + NLMISC::CVector pos; + if (!entity->getHeadPos(pos)) + pos = entity->pos(); + + return pos; + } } return NLMISC::CVector(); } +NLMISC::CVector resolvePositionOrEntityTargetDir(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo, + const NLMISC::CVector& currCamPos) +{ + if (!posOrEntity.isValid()) + { + nlwarning(" invalid position or entity"); + return NLMISC::CVector(); + } + + if (posOrEntity.isPosition()) + { + NLMISC::CVector dir = posOrEntity.getPosition() - currCamPos; + dir.normalize(); + return dir; + } + else if (posOrEntity.isPreviousPos()) + { + return currCamInfo.StartCamLookAtDir; + } + else if (posOrEntity.isReturnPos()) + { + return currCamInfo.AnimStartCamLookAtDir; + } + else if (posOrEntity.isEntityId()) + { + CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId()); + if (!entity) + { + nlwarning(" invalid entity with compressed id %d", posOrEntity.getEntityId()); + return NLMISC::CVector(); + } + else + { + NLMISC::CVector pos; + if (!entity->getHeadPos(pos)) + pos = entity->pos(); + + NLMISC::CVector dir = pos - currCamPos; + dir.normalize(); + return dir; + } + } + return NLMISC::CVector(); +} diff --git a/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.h b/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.h index 600447763..5d4096742 100644 --- a/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.h +++ b/code/ryzom/client/src/camera_animation_manager/position_or_entity_pos_resolver.h @@ -21,11 +21,16 @@ #include "nel/misc/vector.h" #include "game_share/position_or_entity_type.h" #include "camera_animation_manager/position_or_entity_helper.h" +#include "camera_animation_manager/camera_animation_info.h" /// Function that returns the stored position if it contains a position /// Or the current entity's position if it contains an entity +NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo); NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity); +/// Functions that returns the stored look at target as a normalized direction vector +NLMISC::CVector resolvePositionOrEntityTargetDir(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo, + const NLMISC::CVector& currCamPos); #endif /* RY_POSITIONORENTITYPOSRESOLVER_H */