Changed: #1469 Computations for the new magic step

--HG--
branch : gsoc2012-fabien
hg/feature/gsoc2012-fabien
Fabien_HENON 13 years ago
parent c21fbc5a9f
commit ed54bcf00b

@ -76,16 +76,78 @@ public:
{ {
TCameraAnimationOutputInfo camInfo; TCameraAnimationOutputInfo camInfo;
/*// We don't change the position NLMISC::CVector targetPos = resolvePositionOrEntityPosition(PositionTarget, currCamInfo);
camInfo.CamPos = currCamInfo.StartCamPos;
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 current position between the starting position and the final position
NLMISC::CVector movementVector = targetPos - currCamInfo.StartCamPos;
// 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 // We compute the final look at direction
NLMISC::CVector finalDir = resolvePositionOrEntityPosition(LookAtPos) - camInfo.CamPos; NLMISC::CVector finalDir = resolvePositionOrEntityTargetDir(LookAtTarget, currCamInfo, camInfo.CamPos);
// We get the current look at direction // We get the current look at direction
camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir);*/ camInfo.CamLookAtDir = computeCurrentLookAtDir(ratio, currCamInfo.StartCamLookAtDir, finalDir);
}
//////////////////////////////////////////////////////////////////////////
return camInfo; return camInfo;
} }

@ -19,7 +19,7 @@
#include "game_share/position_or_entity_type.h" #include "game_share/position_or_entity_type.h"
#include "entities.h" #include "entities.h"
NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity) NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo)
{ {
if (!posOrEntity.isValid()) if (!posOrEntity.isValid())
{ {
@ -29,7 +29,46 @@ NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEn
if (posOrEntity.isPosition()) if (posOrEntity.isPosition())
return posOrEntity.getPosition(); 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("<resolvePositionOrEntityPosition> 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 resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEntity)
{
if (!posOrEntity.isValid())
{
nlwarning("<resolvePositionOrEntityPosition> invalid position or entity");
return NLMISC::CVector();
}
if (posOrEntity.isPosition())
return posOrEntity.getPosition();
else if (posOrEntity.isEntityId())
{
CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId()); CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(posOrEntity.getEntityId());
if (!entity) if (!entity)
{ {
@ -44,6 +83,51 @@ NLMISC::CVector resolvePositionOrEntityPosition(const CPositionOrEntity& posOrEn
return pos; return pos;
} }
}
return NLMISC::CVector(); return NLMISC::CVector();
} }
NLMISC::CVector resolvePositionOrEntityTargetDir(const CPositionOrEntity& posOrEntity, const TCameraAnimationInputInfo& currCamInfo,
const NLMISC::CVector& currCamPos)
{
if (!posOrEntity.isValid())
{
nlwarning("<resolvePositionOrEntityPosition> 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("<resolvePositionOrEntityPosition> 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();
}

@ -21,11 +21,16 @@
#include "nel/misc/vector.h" #include "nel/misc/vector.h"
#include "game_share/position_or_entity_type.h" #include "game_share/position_or_entity_type.h"
#include "camera_animation_manager/position_or_entity_helper.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 /// Function that returns the stored position if it contains a position
/// Or the current entity's position if it contains an entity /// 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); 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 */ #endif /* RY_POSITIONORENTITYPOSRESOLVER_H */

Loading…
Cancel
Save