Quads
This commit is contained in:
@@ -62,7 +62,7 @@ bool HydraGame::Initialise()
|
|||||||
|
|
||||||
m_player_actor_id = GetEngine()->ActorManager()->CreateActor<HydraPlayerActor>();
|
m_player_actor_id = GetEngine()->ActorManager()->CreateActor<HydraPlayerActor>();
|
||||||
GetEngine()->ActorManager()->InitialiseActor(m_player_actor_id);
|
GetEngine()->ActorManager()->InitialiseActor(m_player_actor_id);
|
||||||
GetEngine()->ActorManager()->SetPosition(m_player_actor_id, glm::dvec3(0, 2, 10000));
|
GetEngine()->ActorManager()->SetPosition(m_player_actor_id, glm::dvec3(0, 0, 1100));
|
||||||
|
|
||||||
GetEngine()->PossessPlayer(m_player_actor_id);
|
GetEngine()->PossessPlayer(m_player_actor_id);
|
||||||
GetEngine()->Camera()->AttachToActor(m_player_actor_id);
|
GetEngine()->Camera()->AttachToActor(m_player_actor_id);
|
||||||
|
|||||||
@@ -561,6 +561,7 @@ void main()
|
|||||||
float ao = 1;
|
float ao = 1;
|
||||||
vec3 ambient = vec3(0.05) * diffuse.xyz * ao;
|
vec3 ambient = vec3(0.05) * diffuse.xyz * ao;
|
||||||
vec3 Lo = ambient;
|
vec3 Lo = ambient;
|
||||||
|
|
||||||
if(metal_rough[0] > 0)
|
if(metal_rough[0] > 0)
|
||||||
{
|
{
|
||||||
uFragColor = vec4(diffuse.xyz * metal_rough[0], diffuse.a);
|
uFragColor = vec4(diffuse.xyz * metal_rough[0], diffuse.a);
|
||||||
@@ -655,7 +656,7 @@ void main()
|
|||||||
uFragColor = vec4(output_color, 1.0);
|
uFragColor = vec4(output_color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//uFragColor = vec4(normal,1);
|
||||||
// float light = dot(lights[0].light_direction, normal);
|
// float light = dot(lights[0].light_direction, normal);
|
||||||
|
|
||||||
// uFragColor = vec4(diffuse.xyz * light,1);
|
// uFragColor = vec4(diffuse.xyz * light,1);
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ void HydraPlanetActor::_CreateQuads()
|
|||||||
{
|
{
|
||||||
m_quads[0] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
m_quads[0] = GetEngine()->ActorManager()->CreateActor<HydraPlanetQuadActor>();
|
||||||
HydraPlanetQuadActor* quad0 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[0]));
|
HydraPlanetQuadActor* quad0 = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(m_quads[0]));
|
||||||
quad0->InitialiseQuad(10000.0f, 10000.0f, 100, glm::vec3(0,0,0));
|
quad0->InitialiseQuad(1000.0f, 1000.0f, 4, glm::vec3(0,0,0));
|
||||||
GetEngine()->ActorManager()->InitialiseActor(m_quads[0]);
|
GetEngine()->ActorManager()->InitialiseActor(m_quads[0]);
|
||||||
GetEngine()->ActorManager()->SetPosition(m_quads[0], glm::dvec3(-5000, -5000 , 5000));
|
GetEngine()->ActorManager()->SetPosition(m_quads[0], glm::dvec3(0, 0 , 0));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,32 +52,29 @@ void HydraPlanetQuadActor::_CreateMesh()
|
|||||||
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||||
|
|
||||||
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
||||||
|
|
||||||
uint32_t vert_counts = m_divisions * m_divisions;
|
uint32_t vert_counts = m_divisions * m_divisions;
|
||||||
uint32_t index_counts = ((m_divisions - 1) * (m_divisions -1)) * 6;
|
uint32_t index_counts = ((m_divisions - 1) * (m_divisions -1)) * 6;
|
||||||
mesh->vertexes.resize(vert_counts);
|
mesh->vertexes.resize(vert_counts);
|
||||||
mesh->indexes.resize(index_counts);
|
mesh->indexes.resize(index_counts);
|
||||||
|
|
||||||
float scale_x = 10000.0f;
|
|
||||||
float scale_y = 10000.0f;
|
|
||||||
float scale_z = 10000.0f;
|
|
||||||
|
|
||||||
float min_x = -m_quad_dimension / 2.0f;
|
float min_x = -m_quad_dimension / 2.0f;
|
||||||
float min_y = m_quad_dimension / 2.0f;
|
float min_y = -m_quad_dimension / 2.0f;
|
||||||
float min_z = 0.0f;
|
float min_z = 0.0f;
|
||||||
|
|
||||||
float max_x = -m_quad_dimension / 2.0f;
|
float max_x = m_quad_dimension / 2.0f;
|
||||||
float max_y = m_quad_dimension / 2.0f;
|
float max_y = m_quad_dimension / 2.0f;
|
||||||
float max_z = 0.0f;
|
float max_z = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
float min_u = 100;
|
float min_u = 0;
|
||||||
float min_v = 100;
|
float min_v = 1;
|
||||||
|
|
||||||
float max_u = 0;
|
float max_u = 1;
|
||||||
float max_v = 0;
|
float max_v = 0;
|
||||||
|
|
||||||
float xy_inc = m_quad_dimension / m_divisions;
|
float xy_inc = m_quad_dimension / m_divisions;
|
||||||
float uv_inc = -min_u / m_divisions;
|
float u_inc = max_u / (m_divisions-1);
|
||||||
|
float v_inc = -min_v / (m_divisions-1);
|
||||||
|
|
||||||
// 1---2
|
// 1---2
|
||||||
// | / |
|
// | / |
|
||||||
@@ -89,45 +86,48 @@ void HydraPlanetQuadActor::_CreateMesh()
|
|||||||
float u = min_u;
|
float u = min_u;
|
||||||
float v = min_v;
|
float v = min_v;
|
||||||
|
|
||||||
uint32_t vert_idx =0;
|
uint32_t vert_idx = 0;
|
||||||
uint32_t index_idx = 0;
|
uint32_t index_idx = 0;
|
||||||
|
|
||||||
for(uint32_t y_count = 0; y_count < m_divisions - 1; y_count ++)
|
for(uint32_t y_count = 0; y_count < m_divisions - 1; y_count ++)
|
||||||
{
|
{
|
||||||
for(uint32_t x_count = 0; x_count < m_divisions - 1; x_count ++)
|
for(uint32_t x_count = 0; x_count < m_divisions - 1; x_count ++)
|
||||||
{
|
{
|
||||||
//Create Vertex
|
//Create Vertex
|
||||||
mesh->vertexes[vert_idx] = {x, y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
mesh->vertexes[vert_idx] = {x, y, min_z, u, v, actor_id, mat_comp.material_id, 0};
|
||||||
uint32_t ind0 = vert_idx + m_divisions;
|
uint32_t ind0 = vert_idx;
|
||||||
uint32_t ind1 = vert_idx;
|
uint32_t ind1 = vert_idx + m_divisions;
|
||||||
uint32_t ind2 = vert_idx + 1;
|
uint32_t ind2 = vert_idx + m_divisions + 1;
|
||||||
uint32_t ind3 = vert_idx + m_divisions + 1;
|
uint32_t ind3 = vert_idx + 1;
|
||||||
|
|
||||||
mesh->indexes[index_idx + 0] = ind0;
|
mesh->indexes[index_idx + 0] = ind0;
|
||||||
mesh->indexes[index_idx + 1] = ind1;
|
mesh->indexes[index_idx + 1] = ind2;
|
||||||
mesh->indexes[index_idx + 2] = ind2;
|
mesh->indexes[index_idx + 2] = ind1;
|
||||||
mesh->indexes[index_idx + 3] = ind0;
|
mesh->indexes[index_idx + 3] = ind0;
|
||||||
mesh->indexes[index_idx + 4] = ind2;
|
mesh->indexes[index_idx + 4] = ind3;
|
||||||
mesh->indexes[index_idx + 5] = ind3;
|
mesh->indexes[index_idx + 5] = ind2;
|
||||||
|
|
||||||
x += xy_inc;
|
x += xy_inc;
|
||||||
u += uv_inc;
|
u += u_inc;
|
||||||
vert_idx++;
|
vert_idx++;
|
||||||
index_idx ++;
|
index_idx += 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the end vert but no indexes
|
//Add the end vert but no indexes
|
||||||
mesh->vertexes[vert_idx] = {x, y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
mesh->vertexes[vert_idx] = {x, y, min_z, u, v, actor_id, mat_comp.material_id, 0};
|
||||||
|
vert_idx++;
|
||||||
y += xy_inc;
|
y += xy_inc;
|
||||||
v += uv_inc;
|
v += v_inc;
|
||||||
x = min_x;
|
x = min_x;
|
||||||
u = min_u;
|
u = min_u;
|
||||||
|
|
||||||
}
|
}
|
||||||
//the last row
|
//the last row
|
||||||
for(uint32_t x_count = 0; x_count < m_divisions - 1; x_count ++)
|
for(uint32_t x_count = 0; x_count < m_divisions; x_count ++)
|
||||||
{
|
{
|
||||||
mesh->vertexes[vert_idx] = {x, y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
mesh->vertexes[vert_idx] = {x, y, min_z, u, v, actor_id, mat_comp.material_id, 0};
|
||||||
x += xy_inc;
|
x += xy_inc;
|
||||||
u += uv_inc;
|
u += u_inc;
|
||||||
vert_idx++;
|
vert_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ void HydraMeshManager::DeleteMesh(HydraID mesh_id)
|
|||||||
|
|
||||||
void HydraMeshManager::CalculateNormals(HydraID mesh_id)
|
void HydraMeshManager::CalculateNormals(HydraID mesh_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
HydraMesh mesh = m_meshes[mesh_id];
|
HydraMesh mesh = m_meshes[mesh_id];
|
||||||
for (int i = 0; i < mesh.indexes.size(); i += 3)
|
for (int i = 0; i < mesh.indexes.size(); i += 3)
|
||||||
{
|
{
|
||||||
@@ -65,9 +64,14 @@ void HydraMeshManager::CalculateNormals(HydraID mesh_id)
|
|||||||
uint32_t idx1 = mesh.indexes[i+1];
|
uint32_t idx1 = mesh.indexes[i+1];
|
||||||
uint32_t idx2 = mesh.indexes[i+2];
|
uint32_t idx2 = mesh.indexes[i+2];
|
||||||
|
|
||||||
glm::vec3 vec0 = glm::normalize(glm::vec3(mesh.vertexes[idx0].position[0], mesh.vertexes[idx0].position[1], mesh.vertexes[idx0].position[2]));
|
glm::vec3 vec0 = glm::vec3(mesh.vertexes[idx0].position[0], mesh.vertexes[idx0].position[1], mesh.vertexes[idx0].position[2]);
|
||||||
glm::vec3 vec1 = glm::normalize(glm::vec3(mesh.vertexes[idx1].position[0], mesh.vertexes[idx1].position[1], mesh.vertexes[idx1].position[2]));
|
glm::vec3 vec1 = glm::vec3(mesh.vertexes[idx1].position[0], mesh.vertexes[idx1].position[1], mesh.vertexes[idx1].position[2]);
|
||||||
glm::vec3 vec2 = glm::normalize(glm::vec3(mesh.vertexes[idx2].position[0], mesh.vertexes[idx2].position[1], mesh.vertexes[idx2].position[2]));
|
glm::vec3 vec2 = glm::vec3(mesh.vertexes[idx2].position[0], mesh.vertexes[idx2].position[1], mesh.vertexes[idx2].position[2]);
|
||||||
|
|
||||||
|
vec1= vec1 - vec0;
|
||||||
|
vec2 = vec2 - vec0;
|
||||||
|
vec0 = glm::vec3(0,0,0);
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 normal = glm::triangleNormal(vec0, vec1, vec2);
|
glm::vec3 normal = glm::triangleNormal(vec0, vec1, vec2);
|
||||||
|
|
||||||
@@ -82,25 +86,6 @@ void HydraMeshManager::CalculateNormals(HydraID mesh_id)
|
|||||||
m_meshes[mesh_id].vertexes[idx2].normal[0] = normal[0];
|
m_meshes[mesh_id].vertexes[idx2].normal[0] = normal[0];
|
||||||
m_meshes[mesh_id].vertexes[idx2].normal[1] = normal[1];
|
m_meshes[mesh_id].vertexes[idx2].normal[1] = normal[1];
|
||||||
m_meshes[mesh_id].vertexes[idx2].normal[2] = normal[2];
|
m_meshes[mesh_id].vertexes[idx2].normal[2] = normal[2];
|
||||||
// glm::vec3 vec0 = glm::vec3(mesh.vertexes[mesh.indexes[i]], mesh.vertexes[mesh.indexes[i] + 1], mesh.vertexes[mesh.indexes[i] + 2]);
|
|
||||||
// glm::vec3 vec1 = glm::vec3(Vertexes[Indexes[i+1]], Vertexes[Indexes[i+1] + 1], Vertexes[Indexes[i+1] + 2]);
|
|
||||||
// glm::vec3 vec2 = glm::vec3(Vertexes[Indexes[i+2]], Vertexes[Indexes[i+2] + 1], Vertexes[Indexes[i+2] + 2]);
|
|
||||||
|
|
||||||
// glm::vec3 normal = glm::triangleNormal(vec0, vec1, vec2);
|
|
||||||
|
|
||||||
// Normals[Indexes[i]] = normal.x;
|
|
||||||
// Normals[Indexes[i]+1] = normal.y;
|
|
||||||
// Normals[Indexes[i]+2] = normal.z;
|
|
||||||
|
|
||||||
// Normals[Indexes[i+1]] = normal.x;
|
|
||||||
// Normals[Indexes[i+1] + 1] = normal.y;
|
|
||||||
// Normals[Indexes[i+1] + 2] = normal.z;
|
|
||||||
|
|
||||||
// Normals[Indexes[i + 2]] = normal.x;
|
|
||||||
// Normals[Indexes[i + 2] + 1] = normal.y;
|
|
||||||
// Normals[Indexes[i + 2] + 2] = normal.z;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -2,11 +2,11 @@
|
|||||||
Pos=60,60
|
Pos=60,60
|
||||||
Size=400,400
|
Size=400,400
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
LastUsed=20260903
|
LastUsed=20260904
|
||||||
|
|
||||||
[Window][Hello, world!]
|
[Window][Hello, world!]
|
||||||
Pos=60,60
|
Pos=60,60
|
||||||
Size=338,157
|
Size=338,157
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
LastUsed=20260903
|
LastUsed=20260904
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user