Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #pragma once
  2.  
  3. #ifndef SIMPLEFPSCONTOLLER_H
  4. #define SIMPLEFPSCONTOLLER_H
  5.  
  6. #include <AzCore/Component/Component.h>
  7. #include <AzCore/Component/EntityBus.h>
  8. #include <AzCore/Component/TickBus.h>
  9. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  10.  
  11. #include "..\..\..\Gems\Camera\Code\Source\CameraComponent.h"
  12.  
  13.  
  14. // EBUS
  15. #include <AzFramework/Entity/GameEntityContextBus.h>
  16. #include <AzFramework\Components\CameraBus.h>
  17.  
  18. namespace GameProject
  19. {
  20.     class SimpleFPSContoller:
  21.         public AZ::Component,
  22.         public AZ::EntityBus::MultiHandler,
  23.         public AZ::TickBus::Handler,
  24.         public AzFramework::InputChannelEventListener,
  25.         public AzFramework::GameEntityContextEventBus::Handler
  26.     {
  27.         enum InputMask : AZ::u8
  28.         {
  29.             eINPUT_NONE     = 0,
  30.             eINPUT_FORWARD  = 1,
  31.             eINPUT_BACK     = 1 << 1,
  32.             eINPUT_RIGHT    = 1 << 2,
  33.             eINPUT_LEFT     = 1 << 3,
  34.             eINPUT_UP       = 1 << 4,
  35.             eINPUT_DOWN     = 1 << 5,
  36.             eINPUT_MOUSE_X  = 1 << 6,
  37.             eINPUT_MOUSE_Y  = 1 << 7,
  38.         };
  39.  
  40.     public:
  41.         AZ_COMPONENT(SimpleFPSContoller, "{9F834A4E-3041-4626-A296-B1662AE82AC6}", AZ::Component);
  42.  
  43.         SimpleFPSContoller();
  44.         virtual ~SimpleFPSContoller();
  45.  
  46.         static void Reflect(AZ::ReflectContext* context);
  47.  
  48.         void Init() override;
  49.         void Activate() override;
  50.         void Deactivate() override;
  51.  
  52.         // AzFramework::InputChannelEventListener
  53.         bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
  54.  
  55.         // AZ::TickBus
  56.         void OnTick(float deltaTime, AZ::ScriptTimePoint time);
  57.  
  58.         //GameEntityContextEventBus
  59.         void OnGameEntitiesStarted() override;
  60.  
  61.         bool IsPointInView(AZ::Vector3 pos);
  62.    
  63.     private:
  64.         void OnMouseEvent(const AzFramework::InputChannel& inputChannel);
  65.         void OnKeyboardEvent(const AzFramework::InputChannel& inputChannel);
  66.         void DrawDebug();
  67.         void RayCastForward();
  68.         void RayCastForward2();
  69.         void GatherAroundHit();
  70.  
  71.         AZ::u8 m_MovementMasks = InputMask::eINPUT_NONE;
  72.         float m_yawChange = 0.0f;
  73.         float m_pitchChange = 0.0f;
  74.         float m_yaw = 0.0f;
  75.         float m_pitch = 0.0f;
  76.         float m_boost = 1.0f;
  77.  
  78.         AZ::Vector3     m_worldStartPosition;
  79.         AZ::Quaternion  m_worldStartRotation;
  80.  
  81.         float m_yawSaved = 0.0f;
  82.         float m_pitchSaved = 0.0f;
  83.  
  84.         AZ::Entity* childEntity = nullptr;
  85.  
  86.         //ratcast debug
  87.         AZ::Vector3     m_rayStartPosition = AZ::Vector3::CreateZero();
  88.         AZ::Vector3     m_rayEndPosition = AZ::Vector3::CreateZero();
  89.         AZ::Vector3     m_hitPosition = AZ::Vector3::CreateZero();
  90.         AZ::Vector3     m_hitNormal = AZ::Vector3::CreateZero();
  91.         AZ::EntityId    m_hitEntityId;
  92.         AZ::Entity*     m_hitEntity = nullptr;
  93.         AZStd::string   m_hitName;
  94.         float           m_gatherRadius = 2.0f;
  95.         AZ::Vector3     m_gatherPosition = AZ::Vector3::CreateZero();
  96.         AZStd::string   m_label;
  97.  
  98.         //Editor exposed properties
  99.         float m_yawRotationSpeed = 6;
  100.         float m_pitchRotationSpeed = 4;
  101.  
  102.  
  103.     };
  104. }
  105. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement