WIP, debugging code added, still not working.
This commit is contained in:
@@ -25,6 +25,19 @@ RenderSystem::~RenderSystem()
|
||||
|
||||
bool RenderSystem::OnSetCamera(Events::SetCamera& e)
|
||||
{
|
||||
//Right now, lets set the camera to cull away stuff if it is connected to a player.
|
||||
//TODO: This won't work with spectators, or death anim.
|
||||
if (e.CameraEntity.FirstParentWithComponent("Player").Valid()) {
|
||||
m_FrustumCamPtr = &m_Camera;
|
||||
LOG_INFO("Setting frustum to new camera.");
|
||||
} else if (e.CameraEntity != m_CurrentCamera) {
|
||||
//If the camera has no parents, i.e. a free camera,
|
||||
//then we cull from the last camera, so we can see if the culling works.
|
||||
//Copy the camera into the last frustum camera, without allocating new memory.
|
||||
new ((void*)m_LastCullCamera) Camera(*m_Camera);
|
||||
m_FrustumCamPtr = &m_LastCullCamera;
|
||||
LOG_INFO("New camera, frustum remains at old camera.");
|
||||
}
|
||||
ComponentWrapper cTransform = e.CameraEntity["Transform"];
|
||||
ComponentWrapper cCamera = e.CameraEntity["Camera"];
|
||||
m_Camera->SetFOV((double)cCamera["FOV"]);
|
||||
@@ -33,17 +46,6 @@ bool RenderSystem::OnSetCamera(Events::SetCamera& e)
|
||||
m_Camera->SetPosition(cTransform["Position"]);
|
||||
m_Camera->SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
|
||||
m_CurrentCamera = e.CameraEntity;
|
||||
//Right now, lets set the camera to cull away stuff if it is connected to anything.
|
||||
//TODO: This won't work with spectators, or death anim.
|
||||
if (m_CurrentCamera.Parent().Valid()) {
|
||||
//Copy the camera into the last frustum camera, without allocating new memory.
|
||||
new ((void*)m_LastCullCamera) Camera(*m_Camera);
|
||||
m_FrustumCamPtr = &m_Camera;
|
||||
} else {
|
||||
//If the camera has no parents, i.e. a free camera,
|
||||
//then we cull from the last camera, so we can see if the culling works.
|
||||
m_FrustumCamPtr = &m_LastCullCamera;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,26 +58,45 @@ bool RenderSystem::isChildOfCurrentCamera(EntityWrapper entity)
|
||||
return entity == m_CurrentCamera || entity.IsChildOf(m_CurrentCamera);
|
||||
}
|
||||
|
||||
float frustrumTODO = 0.f;
|
||||
|
||||
void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs, std::list<std::shared_ptr<RenderJob>>& transparentJobs)
|
||||
{
|
||||
if (!frustumEntity.Valid() && m_World->GetComponentPools().size() > 0) {
|
||||
frustumEntity = EntityWrapper(m_World, m_World->CreateEntity());
|
||||
m_World->AttachComponent(frustumEntity.ID, "Transform");
|
||||
m_World->AttachComponent(frustumEntity.ID, "Model");
|
||||
frustumEntity["Model"]["Resource"] = "Models/Core/UnitCube.mesh";
|
||||
}
|
||||
|
||||
std::vector<EntityAABB> seenEntities;
|
||||
//m_Octree->ObjectsInFrustum((*m_FrustumCamPtr)->ProjectionMatrix() * (*m_FrustumCamPtr)->ViewMatrix(), seenEntities);
|
||||
//m_Octree->ObjectsInFrustum((*m_FrustumCamPtr)->ViewMatrix() * (*m_FrustumCamPtr)->ProjectionMatrix(), seenEntities);
|
||||
|
||||
glm::mat4x4 viewProj = (*m_FrustumCamPtr)->ViewMatrix() * (*m_FrustumCamPtr)->ProjectionMatrix();
|
||||
glm::mat4x4 viewProj = (*m_FrustumCamPtr)->ProjectionMatrix() * (*m_FrustumCamPtr)->ViewMatrix();
|
||||
OctSpace::Frustum frustum;
|
||||
//Order: Right, left, top, bottom, far, near.
|
||||
int sign = 1;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
int sign = 2 * (i % 2) - 1;
|
||||
sign = -sign;
|
||||
int index = i / 2;
|
||||
OctSpace::Plane& plane = frustum.planes[i];
|
||||
plane.normal.x = viewProj[0].w + sign * viewProj[0][index];
|
||||
plane.normal.y = viewProj[1].w + sign * viewProj[1][index];
|
||||
plane.normal.z = viewProj[2].w + sign * viewProj[2][index];
|
||||
plane.distance = viewProj[3].w + sign * viewProj[3][index];
|
||||
float divByNormalLength = 1.0f / glm::length(plane.normal);
|
||||
plane.normal *= divByNormalLength;
|
||||
plane.distance *= divByNormalLength;
|
||||
OctSpace::Plane& plane = frustum.Planes[i];
|
||||
plane.Normal.x = viewProj[0].w + sign * viewProj[0][index];
|
||||
plane.Normal.y = viewProj[1].w + sign * viewProj[1][index];
|
||||
plane.Normal.z = viewProj[2].w + sign * viewProj[2][index];
|
||||
plane.Distance = viewProj[3].w + sign * viewProj[3][index];
|
||||
float divByNormalLength = 1.0f / glm::length(plane.Normal);
|
||||
plane.Normal *= divByNormalLength;
|
||||
plane.Distance *= divByNormalLength;
|
||||
}
|
||||
if (frustumEntity.Valid()) {
|
||||
int planeI = 0;
|
||||
glm::vec3 pos = (*m_FrustumCamPtr)->Position() + frustrumTODO * (*m_FrustumCamPtr)->Forward();
|
||||
float dist = glm::dot(frustum.Planes[planeI].Normal, pos) + frustum.Planes[planeI].Distance;
|
||||
frustumEntity["Transform"]["Position"] = pos - dist * frustum.Planes[planeI].Normal;
|
||||
frustumEntity["Transform"]["Scale"] = glm::vec3(0.15f);
|
||||
}
|
||||
if (++frustrumTODO > 75) {
|
||||
frustrumTODO = 0.f;
|
||||
}
|
||||
|
||||
//for (auto& seenEntity : seenEntities) {
|
||||
@@ -109,11 +130,11 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
|
||||
|
||||
if (entity.HasComponent("AABB")) {
|
||||
OctSpace::Frustum::Output o = frustum.VsAABB(*Collision::EntityAbsoluteAABB(entity));
|
||||
if (o == OctSpace::Frustum::Outside) {
|
||||
continue;
|
||||
if (o == OctSpace::Frustum::Outside && entity != frustumEntity) {
|
||||
resource = "Models/Core/UnitRaptor.mesh";
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
} else if (entity != frustumEntity){
|
||||
resource = "Models/Core/Error.mesh";
|
||||
}
|
||||
|
||||
Model* model;
|
||||
|
||||
Reference in New Issue
Block a user