planet
This commit is contained in:
@@ -21,14 +21,23 @@ void HydraPlanetQuadActor::InitialiseComponents()
|
||||
// _CreatePhysics();
|
||||
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
|
||||
_CreateRenderableComponent();
|
||||
}
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::DeferredInitialiseComponents()
|
||||
{
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::InitialiseQuad(float planet_diameter, float quad_dimension, uint32_t divisions, glm::vec3 origin)
|
||||
{
|
||||
m_divisions = divisions;
|
||||
m_planet_diameter = planet_diameter;
|
||||
m_origin = origin;
|
||||
m_quad_dimension = quad_dimension;
|
||||
_CreateMesh();
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::_CreatePosition()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
@@ -43,112 +52,84 @@ void HydraPlanetQuadActor::_CreateMesh()
|
||||
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||
|
||||
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
||||
|
||||
mesh->vertexes.resize(24);
|
||||
mesh->indexes.resize(36);
|
||||
|
||||
uint32_t vert_counts = m_divisions * m_divisions;
|
||||
uint32_t index_counts = ((m_divisions - 1) * (m_divisions -1)) * 6;
|
||||
mesh->vertexes.resize(vert_counts);
|
||||
mesh->indexes.resize(index_counts);
|
||||
|
||||
float scale_x = 10000.0f;
|
||||
float scale_y = 10000.0f;
|
||||
float scale_z = 10000.0f;
|
||||
|
||||
float min_x = -0.5f * scale_x;
|
||||
float min_y = -0.5f * scale_y;
|
||||
float min_z = -0.5f * scale_z;
|
||||
float min_x = -m_quad_dimension / 2.0f;
|
||||
float min_y = m_quad_dimension / 2.0f;
|
||||
float min_z = 0.0f;
|
||||
|
||||
float max_x = 0.5f * scale_x;
|
||||
float max_y = 0.5f * scale_y;
|
||||
float max_z = 0.5f * scale_z;
|
||||
float max_x = -m_quad_dimension / 2.0f;
|
||||
float max_y = m_quad_dimension / 2.0f;
|
||||
float max_z = 0.0f;
|
||||
|
||||
|
||||
float min_u = 100;
|
||||
float min_v = 100;
|
||||
|
||||
float max_u = 0;
|
||||
float max_v = 0;
|
||||
|
||||
// 1---2 5---6
|
||||
//| / | | / |
|
||||
// 0---3 4---7
|
||||
float xy_inc = m_quad_dimension / m_divisions;
|
||||
float uv_inc = -min_u / m_divisions;
|
||||
|
||||
// 1---2
|
||||
// | / |
|
||||
// 0---3
|
||||
HydraID actor_id = GetID();
|
||||
mesh->vertexes[0] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
float y = min_y;
|
||||
float x = min_x;
|
||||
float u = min_u;
|
||||
float v = min_v;
|
||||
|
||||
// Face 0
|
||||
mesh->indexes[0] = 0;
|
||||
mesh->indexes[1] = 1;
|
||||
mesh->indexes[2] = 2;
|
||||
uint32_t vert_idx =0;
|
||||
uint32_t index_idx = 0;
|
||||
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 ++)
|
||||
{
|
||||
//Create Vertex
|
||||
mesh->vertexes[vert_idx] = {x, y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
uint32_t ind0 = vert_idx + m_divisions;
|
||||
uint32_t ind1 = vert_idx;
|
||||
uint32_t ind2 = vert_idx + 1;
|
||||
uint32_t ind3 = vert_idx + m_divisions + 1;
|
||||
|
||||
mesh->indexes[3] = 0;
|
||||
mesh->indexes[4] = 2;
|
||||
mesh->indexes[5] = 3;
|
||||
mesh->indexes[index_idx + 0] = ind0;
|
||||
mesh->indexes[index_idx + 1] = ind1;
|
||||
mesh->indexes[index_idx + 2] = ind2;
|
||||
mesh->indexes[index_idx + 3] = ind0;
|
||||
mesh->indexes[index_idx + 4] = ind2;
|
||||
mesh->indexes[index_idx + 5] = ind3;
|
||||
|
||||
x += xy_inc;
|
||||
u += uv_inc;
|
||||
vert_idx++;
|
||||
index_idx ++;
|
||||
}
|
||||
//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[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[6] = 4;
|
||||
mesh->indexes[7] = 5;
|
||||
mesh->indexes[8] = 6;
|
||||
|
||||
mesh->indexes[9] = 4;
|
||||
mesh->indexes[10] = 6;
|
||||
mesh->indexes[11] = 7;
|
||||
|
||||
// Back Face
|
||||
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[12] = 8;
|
||||
mesh->indexes[13] = 9;
|
||||
mesh->indexes[14] = 10;
|
||||
|
||||
mesh->indexes[15] = 8;
|
||||
mesh->indexes[16] = 10;
|
||||
mesh->indexes[17] = 11;
|
||||
|
||||
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[18] = 12;
|
||||
mesh->indexes[19] = 13;
|
||||
mesh->indexes[20] = 14;
|
||||
|
||||
mesh->indexes[21] = 12;
|
||||
mesh->indexes[22] = 14;
|
||||
mesh->indexes[23] = 15;
|
||||
|
||||
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[24] = 16;
|
||||
mesh->indexes[25] = 17;
|
||||
mesh->indexes[26] = 18;
|
||||
|
||||
mesh->indexes[27] = 16;
|
||||
mesh->indexes[28] = 18;
|
||||
mesh->indexes[29] = 19;
|
||||
|
||||
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[30] = 20;
|
||||
mesh->indexes[31] = 21;
|
||||
mesh->indexes[32] = 22;
|
||||
|
||||
mesh->indexes[33] = 20;
|
||||
mesh->indexes[34] = 22;
|
||||
mesh->indexes[35] = 23;
|
||||
y += xy_inc;
|
||||
v += uv_inc;
|
||||
x = min_x;
|
||||
u = min_u;
|
||||
}
|
||||
//the last row
|
||||
for(uint32_t x_count = 0; x_count < m_divisions - 1; x_count ++)
|
||||
{
|
||||
mesh->vertexes[vert_idx] = {x, y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
x += xy_inc;
|
||||
u += uv_inc;
|
||||
vert_idx++;
|
||||
}
|
||||
|
||||
mesh_manager->CalculateNormals(mesh->mesh_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user