Player Indicator now working OK. Scaling depending on how far away you are makes the Indicator to hide players head behind it. Shields are making indicators to disappear.

This commit is contained in:
Teejoon
2016-02-17 17:58:01 +01:00
parent 4fd0108443
commit 5e3af7ac5d
5 changed files with 51 additions and 31 deletions
+34 -4
View File
@@ -67,16 +67,26 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
fillColor = (glm::vec4)fillComponent["Color"];
}
glm::mat4 modelMatrix = glm::mat4(1);
glm::mat4 modelMatrix;
bool isIndicator = false;
if (world->HasComponent(entity.ID, "Indicator") || entity.FirstParentWithComponent("Indicator").Valid())
{
EntityWrapper EntityWithIndicator;
if (world->HasComponent(entity.ID, "Indicator")) {
EntityWithIndicator = entity;
}
else {
EntityWithIndicator = entity.FirstParentWithComponent("Indicator");
}
auto indicator = EntityWithIndicator["Indicator"];
float minScale = (float)(double)indicator["MinScale"];
isIndicator = true;
glm::vec3 pos = Transform::AbsolutePosition(entity);
// Code for shcneking if sprite is inside or outside of screen
// Code for check if sprite is inside or outside of screen
//glm::vec4 projectedPos = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * glm::vec4(pos, 1.0f);
//projectedPos /= projectedPos.w;
//// Check if inside of outside of screen.
@@ -89,6 +99,13 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
glm::vec3 zAxis = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 normal = pos - m_Camera->Position();
//float distance = glm::length(normal);
//if (distance < minDistance) {
// pos = pos - glm::normalize(normal) * (distance - minDistance);
//} else if (distance > maxDistance) {
// pos = pos - glm::normalize(normal) * (distance - maxDistance);
//}
normal.y = 0;
normal = glm::normalize(normal);
glm::vec3 right = glm::cross(normal, zAxis);
@@ -97,21 +114,34 @@ void RenderSystem::fillSprites(std::list<std::shared_ptr<RenderJob>>& jobs, Worl
modelMatrix[0][0] = right.x;
modelMatrix[0][1] = right.y;
modelMatrix[0][2] = right.z;
modelMatrix[0][3] = 0.0f;
modelMatrix[1][0] = zAxis.x;
modelMatrix[1][1] = zAxis.y;
modelMatrix[1][2] = zAxis.z;
modelMatrix[1][3] = 0.0f;
modelMatrix[2][0] = normal.x;
modelMatrix[2][1] = normal.y;
modelMatrix[2][2] = normal.z;
modelMatrix[2][3] = 0.0f;
modelMatrix[3][0] = pos.x;
modelMatrix[3][1] = pos.y;
modelMatrix[3][2] = pos.z;
modelMatrix[3][3] = 1.0f;
modelMatrix = modelMatrix * glm::scale(Transform::AbsoluteScale(entity));
glm::mat4 tranformationMatrix = modelMatrix * glm::scale(Transform::AbsoluteScale(entity));
glm::vec4 tmp = tranformationMatrix * glm::vec4(glm::vec3(0.5, 0.5, 0), 1.0f);
glm::vec2 projectedTopRight = m_Camera->WorldToScreen(glm::vec3(tmp), m_Renderer->GetViewportSize());
tmp = tranformationMatrix * glm::vec4(glm::vec3(-0.5, -0.5, 0), 1.0f);
glm::vec2 projectedBottomLeft = m_Camera->WorldToScreen(glm::vec3(tmp), m_Renderer->GetViewportSize());
float diag = glm::length(projectedBottomLeft - projectedTopRight);
if (diag < minScale) {
tranformationMatrix = tranformationMatrix * glm::scale(glm::vec3(minScale / diag, minScale / diag, minScale / diag));
}
modelMatrix = tranformationMatrix;
} else {
modelMatrix = Transform::ModelMatrix(entity.ID, world);
}