initial commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
#include "HydraPlayerActor.h"
|
||||
#include "HydraActorManager.h"
|
||||
#include "../HydraDefines.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/components/HydraPositionComponent.h"
|
||||
|
||||
|
||||
|
||||
void HydraPlayerActor::InitialiseComponents()
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
//HydraID entity_id = ecs->CreateEntity();
|
||||
HydraPositionComponent position_component;
|
||||
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
||||
}
|
||||
|
||||
void HydraPlayerActor::DeferredInitialiseComponents()
|
||||
{
|
||||
//_CreatePhysics();
|
||||
}
|
||||
void HydraPlayerActor::_CreatePhysics()
|
||||
{
|
||||
// HydraPhysicsComponent* physics_component = static_cast<HydraPhysicsComponent*>(GetEngine()->ComponentManager()->CreateComponent((uint32_t)HYDRA_COMPONENT_TYPE::PHYSICS, GetID()));
|
||||
|
||||
// physics_component->physics_definition.PhysicsType = HydraPhyicsType::Dynamic;
|
||||
// physics_component->physics_definition.PhysicsShape = HydraPhysicsShape::HydraBoxShape;
|
||||
// physics_component->physics_definition.Mass = 10.0f;
|
||||
// physics_component->physics_definition.ExtentX = 0.5f;
|
||||
// physics_component->physics_definition.ExtentY = 0.5f;
|
||||
// physics_component->physics_definition.ExtentZ = 0.5f;
|
||||
// physics_component->physics_definition.DynamicFriction = 0.5f;
|
||||
// physics_component->physics_definition.Restitution = 0.5f;
|
||||
// physics_component->physics_definition.Velocity = GetEngine()->ActorManager()->GetActorVelocity(GetID());
|
||||
|
||||
}
|
||||
void HydraPlayerActor::HandleInput(float delta_t)
|
||||
{
|
||||
glm::vec2 change = GetEngine()->MouseChange();
|
||||
|
||||
bool move_forward = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_W);
|
||||
bool move_backward = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_S);
|
||||
bool move_fast = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_LEFT_SHIFT);
|
||||
|
||||
bool move_left = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_A);
|
||||
bool move_right = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_D);
|
||||
|
||||
HydraRenderSettings render_settings = GetEngine()->RenderSettings();
|
||||
float scale = 0.2f;
|
||||
|
||||
float x_angle = (change.x / render_settings.DisplayWidth) * -500 * delta_t * scale;
|
||||
float y_angle = (change.y / render_settings.DisplayHeight) * -500 * delta_t * scale;
|
||||
|
||||
float extra_speed = 1.0f;
|
||||
float speed = 5.0f;
|
||||
|
||||
if (move_fast)
|
||||
{
|
||||
extra_speed = 150;
|
||||
}
|
||||
|
||||
GetEngine()->ActorManager()->RotateActor(GetID(), y_angle, x_angle, 0.0f);
|
||||
|
||||
glm::dvec3 pos_vec = GetEngine()->ActorManager()->GetActorPosition(GetID());
|
||||
glm::vec3 rot_vec = GetEngine()->ActorManager()->GetActorOrientation(GetID());
|
||||
|
||||
glm::mat4 rot = glm::mat4(1);
|
||||
|
||||
rot = glm::eulerAngleXYZ(rot_vec.x, rot_vec.y, rot_vec.z);
|
||||
|
||||
glm::dvec3 forward = m_forward * rot;
|
||||
glm::dvec3 right = m_right * rot;
|
||||
glm::dvec3 up = m_up * rot;
|
||||
|
||||
glm::dvec3 trans = glm::dvec3(0, 0, 0);
|
||||
|
||||
double distance = (double)(speed * extra_speed * delta_t);
|
||||
bool moved = false;
|
||||
if (move_forward)
|
||||
{
|
||||
trans = trans - (forward * distance);
|
||||
moved = true;
|
||||
}
|
||||
if (move_backward)
|
||||
{
|
||||
trans = trans + (forward * distance);
|
||||
moved = true;
|
||||
}
|
||||
|
||||
if (move_right)
|
||||
{
|
||||
trans = trans - (right * distance);
|
||||
moved = true;
|
||||
}
|
||||
|
||||
if (move_left)
|
||||
{
|
||||
trans = trans + (right * distance);
|
||||
moved = true;
|
||||
}
|
||||
if (moved)
|
||||
{
|
||||
GetEngine()->ActorManager()->TranslateActor(GetID(), -trans);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user