BVB Source Codes

CRYENGINE Show ProceduralClipAimAround.cpp Source code

Return Download CRYENGINE: download ProceduralClipAimAround.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 SAimAroundParams : public IProceduralParams
  13. {
  14.         SAimAroundParams()
  15.                 : smoothTime(1.f)
  16.                 , scopeLayer(0)
  17.                 , yawMin(-1.f)
  18.                 , yawMax(1.f)
  19.                 , pitchMin(0.f)
  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");
  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 CProceduralClipAimAround : public TProceduralClip<SAimAroundParams>
  56. {
  57. public:
  58.         CProceduralClipAimAround();
  59.  
  60.         virtual void OnEnter(float blendTime, float duration, const SAimAroundParams& params)
  61.         {
  62.                 UpdateLookTarget();
  63.                 Vec3 lookPos = m_entity->GetWorldPos();
  64.                 lookPos += m_entity->GetRotation() * (m_lookOffset * 10.0f);
  65.  
  66.                 const float smoothTime = params.smoothTime;
  67.                 const uint32 ikLayer = m_scope->GetBaseLayer() + params.scopeLayer;
  68.                 if (!params.animRef.IsEmpty())
  69.                 {
  70.                         CryCharAnimationParams animParams;
  71.                         animParams.m_fTransTime = blendTime;
  72.                         animParams.m_nLayerID = ikLayer;
  73.                         animParams.m_nFlags = CA_LOOP_ANIMATION | CA_ALLOW_ANIM_RESTART;
  74.                         int animID = m_charInstance->GetIAnimationSet()->GetAnimIDByCRC(params.animRef.crc);
  75.                         m_charInstance->GetISkeletonAnim()->StartAnimationById(animID, animParams);
  76.                 }
  77.  
  78.                 IAnimationPoseBlenderDir* poseBlenderAim = m_charInstance->GetISkeletonPose()->GetIPoseBlenderAim();
  79.                 if (poseBlenderAim)
  80.                 {
  81.                         poseBlenderAim->SetState(true);
  82.                         poseBlenderAim->SetTarget(lookPos);
  83.                         poseBlenderAim->SetPolarCoordinatesSmoothTimeSeconds(smoothTime);
  84.                         poseBlenderAim->SetLayer(ikLayer);
  85.                         poseBlenderAim->SetFadeInSpeed(blendTime);
  86.                 }
  87.         }
  88.  
  89.         virtual void OnExit(float blendTime)
  90.         {
  91.                 IAnimationPoseBlenderDir* poseBlenderAim = m_charInstance->GetISkeletonPose()->GetIPoseBlenderAim();
  92.                 if (poseBlenderAim)
  93.                 {
  94.                         poseBlenderAim->SetState(false);
  95.                         poseBlenderAim->SetFadeOutSpeed(blendTime);
  96.                 }
  97.         }
  98.  
  99.         virtual void Update(float timePassed)
  100.         {
  101.                 m_lookAroundTime -= timePassed;
  102.  
  103.                 if (m_lookAroundTime < 0.0f)
  104.                 {
  105.                         UpdateLookTarget();
  106.                 }
  107.  
  108.                 Vec3 lookPos = m_entity->GetWorldPos();
  109.                 lookPos += m_entity->GetRotation() * (m_lookOffset * 10.0f);
  110.  
  111.                 IAnimationPoseBlenderDir* poseBlenderAim = m_charInstance->GetISkeletonPose()->GetIPoseBlenderAim();
  112.                 if (poseBlenderAim)
  113.                 {
  114.                         poseBlenderAim->SetState(true);
  115.                         poseBlenderAim->SetTarget(lookPos);
  116.                 }
  117.         }
  118.  
  119.         void UpdateLookTarget()
  120.         {
  121.                 const SAimAroundParams& params = GetParams();
  122.  
  123.                 //--- TODO! Context use of random number generator!
  124.                 float yaw = cry_random(params.yawMin, params.yawMax);
  125.                 float pitch = cry_random(params.pitchMin, params.pitchMax);
  126.                 m_lookOffset.Set(sin_tpl(yaw), cos_tpl(yaw), 0.0f);
  127.                 m_lookAroundTime = cry_random(params.timeMin, params.timeMax);
  128.         }
  129.  
  130. public:
  131.         float m_lookAroundTime;
  132.         Vec3  m_lookOffset;
  133. };
  134.  
  135. CProceduralClipAimAround::CProceduralClipAimAround()
  136.         : m_lookAroundTime(0)
  137.         , m_lookOffset(ZERO)
  138. {
  139. }
  140.  
  141. REGISTER_PROCEDURAL_CLIP(CProceduralClipAimAround, "RandomAimAround");
  142.  
downloadProceduralClipAimAround.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