Compare commits

...

8 Commits

8 changed files with 26 additions and 23 deletions
@@ -19,6 +19,7 @@ public:
virtual const glm::vec3 Rotation() const { return m_Rotation; } virtual const glm::vec3 Rotation() const { return m_Rotation; }
virtual bool Jumping() const { return m_Jumping; } virtual bool Jumping() const { return m_Jumping; }
virtual bool Crouching() const { return m_Crouching; } virtual bool Crouching() const { return m_Crouching; }
virtual bool CrouchingLastFrame() const { return m_CrouchingLastFrame; }
virtual bool DoubleJumping() const { return m_DoubleJumping; } virtual bool DoubleJumping() const { return m_DoubleJumping; }
virtual void SetDoubleJumping(bool isDoubleJumping) { virtual void SetDoubleJumping(bool isDoubleJumping) {
m_DoubleJumping = isDoubleJumping; m_DoubleJumping = isDoubleJumping;
@@ -44,6 +45,7 @@ protected:
bool m_Jumping = false; bool m_Jumping = false;
bool m_DoubleJumping = false; bool m_DoubleJumping = false;
bool m_Crouching = false; bool m_Crouching = false;
bool m_CrouchingLastFrame = false;
//assault dash membervariables - needed to calculate the doubletap- and dashlogic //assault dash membervariables - needed to calculate the doubletap- and dashlogic
double m_AssaultDashDoubleTapDeltaTime = 0.0; double m_AssaultDashDoubleTapDeltaTime = 0.0;
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable), //i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
@@ -82,6 +84,7 @@ void FirstPersonInputController<EventContext>::Reset()
{ {
m_Rotation = glm::vec3(0.f, 0.f, 0.f); m_Rotation = glm::vec3(0.f, 0.f, 0.f);
m_Jumping = false; m_Jumping = false;
m_CrouchingLastFrame = m_Crouching;
} }
template <typename EventContext> template <typename EventContext>
+1
View File
@@ -470,6 +470,7 @@ bool AABBvsTriangle(const AABB& box,
} }
glm::vec3 cornerResolution = (1+t) * diagonal; glm::vec3 cornerResolution = (1+t) * diagonal;
cornerResolution = glm::dot(cornerResolution, triNormal) * triNormal;
//Overwrite the smallest resolution if cornerResolution is smaller. //Overwrite the smallest resolution if cornerResolution is smaller.
float lenSq = glm::length2(cornerResolution); float lenSq = glm::length2(cornerResolution);
if (lenSq < resolveShortest.DistanceSq) { if (lenSq < resolveShortest.DistanceSq) {
+1 -2
View File
@@ -88,12 +88,11 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity); glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"]; glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end();
bool isOnGround = (bool)cPhysics["IsOnGround"]; bool isOnGround = (bool)cPhysics["IsOnGround"];
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector. //Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; (glm::vec3&)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity); boxA = *Collision::EntityAbsoluteAABB(entity);
cPhysics["Velocity"] = inOutVelocity; cPhysics["Velocity"] = inOutVelocity;
if (isOnGround) { if (isOnGround) {
+6 -6
View File
@@ -24,7 +24,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
while (entity != EntityID_Invalid) { while (entity != EntityID_Invalid) {
ComponentWrapper transform = world->GetComponent(entity, "Transform"); ComponentWrapper transform = world->GetComponent(entity, "Transform");
EntityID parent = world->GetParent(entity); EntityID parent = world->GetParent(entity);
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]; position += Transform::AbsoluteScale(world, parent) * (Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]);
entity = parent; entity = parent;
} }
@@ -89,12 +89,12 @@ glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
{ {
return AbsoluteTransformation(EntityWrapper(world, entity)); return AbsoluteTransformation(EntityWrapper(world, entity));
glm::vec3 position = Transform::AbsolutePosition(world, entity); //glm::vec3 position = Transform::AbsolutePosition(world, entity);
glm::quat orientation = Transform::AbsoluteOrientation(world, entity); //glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
glm::vec3 scale = Transform::AbsoluteScale(world, entity); //glm::vec3 scale = Transform::AbsoluteScale(world, entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); //glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
return modelMatrix; //return modelMatrix;
} }
glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix) glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
+1 -1
View File
@@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer,
{ {
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera); EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera);
auto resolution = Rectangle::Rectangle(1280, 720); auto resolution = Rectangle::Rectangle(1280, 720);
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f); m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.001f, 500.f);
} }
void EditorRenderSystem::Update(double dt) void EditorRenderSystem::Update(double dt)
+9 -2
View File
@@ -204,14 +204,21 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
if (m_CurrentSelection.Valid()) { if (m_CurrentSelection.Valid()) {
if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) { if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) {
glm::quat parentOrientation; glm::quat parentOrientation;
glm::vec3 parentScale(1.f);
EntityWrapper parent = m_CurrentSelection.Parent(); EntityWrapper parent = m_CurrentSelection.Parent();
if (parent.Valid()) { if (parent.Valid()) {
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent)); parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
parentScale = Transform::AbsoluteScale(parent);
} }
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation; (glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation / parentScale;
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) { } else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
glm::vec3 parentScale(1.f);
EntityWrapper parent = m_CurrentSelection.Parent();
if (parent.Valid()) {
parentScale = Transform::AbsoluteScale(parent);
}
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]); glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
glm::vec3 localTranslation = selectionOri * e.Translation; glm::vec3 localTranslation = selectionOri * e.Translation / parentScale;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation; (glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
} }
m_EditorGUI->SetDirty(m_CurrentSelection); m_EditorGUI->SetDirty(m_CurrentSelection);
@@ -264,6 +264,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
size = glm::vec3(1.f, 1.f, 1.f); size = glm::vec3(1.f, 1.f, 1.f);
} else { } else {
size = glm::vec3(1.f, 1.6f, 1.f); size = glm::vec3(1.f, 1.6f, 1.f);
if (controller->CrouchingLastFrame() && isOnGround) {
// The collision should resolve this anyway, but
// this is more reliable, since the box gets larger.
((glm::vec3&)cTransform["Position"]).y += 0.3f;
}
} }
} }
-12
View File
@@ -208,18 +208,6 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
m_EventBroker->Publish(lock); m_EventBroker->Publish(lock);
} }
// HACK: Set the player model color to team color
EntityWrapper playerModel = e.Player.FirstChildByName("PlayerModel");
if (playerModel.Valid() && e.Player.HasComponent("Team")) {
ComponentWrapper cTeam = e.Player["Team"];
ComponentWrapper cModel = playerModel["Model"];
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Red")) {
cModel["Color"] = glm::vec3(1.f, 0.f, 0.f);
} else if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Blue")) {
cModel["Color"] = glm::vec3(0.f, 0.25f, 1.f);
}
}
return true; return true;
} }