BVB Source Codes

CRYENGINE Show ProceduralClipLookAround.cpp Source code

Return Download CRYENGINE: download ProceduralClipLookAround.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. //
  4. ////////////////////////////////////////////////////////////////////////////
  5.  
  6. #include "StdAfx.h"
  7.  
  8. #include "ICryMannequin.h"
  9.  
  10. #include <Mannequin/Serialization.h>
  11.  
  12. struct SLookAroundParams : public IProceduralParams
  13. {
  14.         SLookAroundParams()
  15.                 : smoothTime(1.0f)
  16.                 , scopeLayer(0)
  17.                 , yawMin(-1.0f)
  18.                 , yawMax(1.0f)
  19.                 , pitchMin(0.0f)
  20.                 , pitchMax(0.5f)
  21.                 , timeMin(1.0f)
  22.                 , timeMax(2.0f)
  23.         {
  24.         }
  25.  
  26.         virtual void Serialize(Serialization::IArchive& ar) override
  27.         {
  28.                 ar(Serialization::Decorators::AnimationName<SAnimRef>(animRef), "Animation", "Animation");
  29.                 ar(smoothTime, "SmoothTime", "Smooth Time");
  30.                 ar(Serialization::Decorators::Range<uint32>(scopeLayer, 0, 15), "ScopeLayer", "Scope Layer");
  31.                 ar(yawMin, "YawMin", "Yaw Min");
  32.                 ar(yawMax, "YawMax", "Yaw Max");
  33.                 ar(pitchMin, "PitchMin", "Pitch Max");
  34.                 ar(pitchMax, "PitchMax", "Pitch Max");
  35.                 ar(timeMin, "TimeMin", "Time Min");
  36.                 ar(timeMax, "TimeMax", "Time Max");
  37.         }
  38.  
  39.         virtual void GetExtraDebugInfo(StringWrapper& extraInfoOut) const override
  40.         {
  41.                 extraInfoOut = animRef.c_str();
  42.         }
  43.  
  44.         SAnimRef animRef;
  45.         float    smoothTime;
  46.         uint32   scopeLayer;
  47.         float    yawMin;
  48.         float    yawMax;
  49.         float    pitchMin;
  50.         float    pitchMax;
  51.         float    timeMin;
  52.         float    timeMax;
  53. };
  54.  
  55. class CProceduralClipLookAround : public TProceduralClip<SLookAroundParams>
  56. {
  57. public:
  58.         CProceduralClipLookAround()
  59.                 : m_lookAroundTime(0.f)
  60.                 , m_lookOffset(ZERO)
  61.         {
  62.         }
  63.  
  64.         virtual void OnEnter(float blendTime, float duration, const SLookAroundParams& params)
  65.         {
  66.                 const float smoothTime = params.smoothTime;
  67.                 const uint32 ikLayer = m_scope->GetBaseLayer() + params.scopeLayer;
  68.  
  69.                 UpdateLookTarget();
  70.                 Vec3 lookPos = m_entity->GetWorldPos();
  71.                 lookPos += m_entity->GetRotation() * (m_lookOffset * 10.0f);
  72.  
  73.                 if (!params.animRef.IsEmpty())
  74.                 {
  75.                         CryCharAnimationParams animParams;
  76.                         animParams.m_fTransTime = blendTime;
  77.                         animParams.m_nLayerID = ikLayer;
  78.                         animParams.m_nFlags = CA_LOOP_ANIMATION | CA_ALLOW_ANIM_RESTART;
  79.                         int animID = m_charInstance->GetIAnimationSet()->GetAnimIDByCRC(params.animRef.crc);
  80.                         m_charInstance->GetISkeletonAnim()->StartAnimationById(animID, animParams);
  81.                 }
  82.  
  83.                 IAnimationPoseBlenderDir* poseBlenderLook = m_charInstance->GetISkeletonPose()->GetIPoseBlenderLook();
  84.                 if (poseBlenderLook)
  85.                 {
  86.                         poseBlenderLook->SetState(true);
  87.                         poseBlenderLook->SetTarget(lookPos);
  88.                         poseBlenderLook->SetFadeoutAngle(DEG2RAD(180.0f));
  89.                         poseBlenderLook->SetPolarCoordinatesSmoothTimeSeconds(smoothTime);
  90.                         poseBlenderLook->SetLayer(ikLayer);
  91.                         poseBlenderLook->SetFadeInSpeed(blendTime);
  92.                 }
  93.         }
  94.  
  95.         virtual void OnExit(float blendTime)
  96.         {
  97.                 IAnimationPoseBlenderDir* poseBlenderLook = m_charInstance->GetISkeletonPose()->GetIPoseBlenderLook();
  98.                 if (poseBlenderLook)
  99.                 {
  100.                         poseBlenderLook->SetState(false);
  101.                         poseBlenderLook->SetFadeOutSpeed(blendTime);
  102.                 }
  103.         }
  104.  
  105.         virtual void Update(float timePassed)
  106.         {
  107.                 m_lookAroundTime -= timePassed;
  108.  
  109.                 if (m_lookAroundTime < 0.0f)
  110.                 {
  111.                         UpdateLookTarget();
  112.                 }
  113.  
  114.                 Vec3 lookPos = m_entity->GetWorldPos();
  115.                 lookPos += m_entity->GetRotation() * (m_lookOffset * 10.0f);
  116.  
  117.                 IAnimationPoseBlenderDir* pIPoseBlenderLook = m_charInstance->GetISkeletonPose()->GetIPoseBlenderLook();
  118.                 if (pIPoseBlenderLook)
  119.                 {
  120.                         pIPoseBlenderLook->SetState(true);
  121.                         pIPoseBlenderLook->SetTarget(lookPos);
  122.                         pIPoseBlenderLook->SetFadeoutAngle(DEG2RAD(180.0f));
  123.                 }
  124.         }
  125.  
  126.         void UpdateLookTarget()
  127.         {
  128.                 const SLookAroundParams& params = GetParams();
  129.  
  130.                 //--- TODO! Context use of random number generator!
  131.                 float yaw = cry_random(params.yawMin, params.yawMax);
  132.                 float pitch = cry_random(params.pitchMin, params.pitchMax);
  133.                 m_lookOffset.Set(sin_tpl(yaw), cos_tpl(yaw), 0.0f);
  134.                 m_lookAroundTime = cry_random(params.timeMin, params.timeMax);
  135.         }
  136.  
  137. public:
  138.         float m_lookAroundTime;
  139.         Vec3  m_lookOffset;
  140. };
  141.  
  142. REGISTER_PROCEDURAL_CLIP(CProceduralClipLookAround, "RandomLookAround");
  143.  
downloadProceduralClipLookAround.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top