Added a plane to the shadowed scene.
Also fixed multiple batches failing from vector resizing. Now using a list as the back end for batched scenes.
This commit is contained in:
parent
ab86354833
commit
d196e42522
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
@ -19,7 +21,9 @@ namespace charcoal
|
||||
return m_batches.back();
|
||||
}
|
||||
|
||||
std::vector<BatchType> m_batches;
|
||||
// Since the intention is to access the batches through the returned references,
|
||||
// it is better to store them in a list.
|
||||
std::list<BatchType> m_batches;
|
||||
};
|
||||
}
|
||||
}
|
@ -29,17 +29,19 @@ namespace charcoal
|
||||
}
|
||||
|
||||
template <typename VertexType, typename IndexType>
|
||||
Mesh<VertexType, IndexType>* gen_plane_p(const DrawMode& draw_mode, float width, float depth)
|
||||
Mesh<VertexType, IndexType>* gen_plane_pn(const DrawMode& draw_mode, float width, float depth)
|
||||
{
|
||||
Mesh<VertexType, IndexType>* mesh;
|
||||
|
||||
float x = width / 2.0f;
|
||||
float z = depth / 2.0f;
|
||||
|
||||
Position pos0(-x, 0.0f, z);
|
||||
Position pos0(-x, 0.0f, z);
|
||||
Position pos1(-x, 0.0f, -z);
|
||||
Position pos2( x, 0.0f, z);
|
||||
Position pos3( x, 0.0f, -z);
|
||||
Position pos2(x, 0.0f, z);
|
||||
Position pos3(x, 0.0f, -z);
|
||||
|
||||
Normal normal(0.0f, 1.0f, 0.0f);
|
||||
|
||||
switch (draw_mode)
|
||||
{
|
||||
@ -49,6 +51,10 @@ namespace charcoal
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 0;
|
||||
mesh->indices[1] = 1;
|
||||
mesh->indices[2] = 2;
|
||||
@ -60,6 +66,10 @@ namespace charcoal
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 0;
|
||||
mesh->indices[1] = 1;
|
||||
mesh->indices[2] = 3;
|
||||
@ -72,6 +82,10 @@ namespace charcoal
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 0;
|
||||
mesh->indices[1] = 1;
|
||||
mesh->indices[2] = 3;
|
||||
@ -83,6 +97,10 @@ namespace charcoal
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 0;
|
||||
mesh->indices[1] = 1;
|
||||
mesh->indices[2] = 1;
|
||||
@ -93,12 +111,30 @@ namespace charcoal
|
||||
mesh->indices[7] = 0;
|
||||
break;
|
||||
case DrawMode::DRAW_TRIANGLE_STRIP:
|
||||
mesh = MeshFactory<VertexType, IndexType>::create_mesh(4, 4);
|
||||
mesh->vertices[0].set_position(pos0);
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 1;
|
||||
mesh->indices[1] = 3;
|
||||
mesh->indices[2] = 0;
|
||||
mesh->indices[3] = 2;
|
||||
break;
|
||||
case DrawMode::DRAW_TRIANGLE_FAN:
|
||||
mesh = MeshFactory<VertexType, IndexType>::create_mesh(4, 4);
|
||||
mesh->vertices[0].set_position(pos0);
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 0;
|
||||
mesh->indices[1] = 1;
|
||||
mesh->indices[2] = 3;
|
||||
@ -110,11 +146,15 @@ namespace charcoal
|
||||
mesh->vertices[1].set_position(pos1);
|
||||
mesh->vertices[2].set_position(pos2);
|
||||
mesh->vertices[3].set_position(pos3);
|
||||
mesh->indices[0] = 0;
|
||||
mesh->indices[1] = 1;
|
||||
mesh->indices[2] = 3;
|
||||
mesh->indices[3] = 3;
|
||||
mesh->indices[4] = 1;
|
||||
mesh->vertices[0].set_normal(normal);
|
||||
mesh->vertices[1].set_normal(normal);
|
||||
mesh->vertices[2].set_normal(normal);
|
||||
mesh->vertices[3].set_normal(normal);
|
||||
mesh->indices[0] = 1;
|
||||
mesh->indices[1] = 3;
|
||||
mesh->indices[2] = 0;
|
||||
mesh->indices[3] = 0;
|
||||
mesh->indices[4] = 3;
|
||||
mesh->indices[5] = 2;
|
||||
break;
|
||||
case DrawMode::DRAW_LINE_STRIP_ADJACENCY:
|
||||
@ -123,7 +163,7 @@ namespace charcoal
|
||||
case DrawMode::DRAW_TRIANGLES_ADJACENCY:
|
||||
case DrawMode::DRAW_PATCHES:
|
||||
default:
|
||||
throw EXCEPTION("Unable to gen_plane_p for current draw mode: " + std::string(draw_mode));
|
||||
throw EXCEPTION("Unable to gen_plane_p for current draw mode: " + std::to_string(draw_mode));
|
||||
}
|
||||
|
||||
return mesh;
|
||||
|
@ -6,14 +6,21 @@
|
||||
|
||||
MyBuiltinLitShadowedScene::MyBuiltinLitShadowedScene(Application& application)
|
||||
: litshadowed::Scene(application),
|
||||
m_shape(
|
||||
m_cube(
|
||||
meshgenerator::set_material<litshadowed::Vertex, litshadowed::Index>(
|
||||
meshgenerator::gen_cube_pn<litshadowed::Vertex, litshadowed::Index>(DRAW_TRIANGLES, 2.0f, 2.0f, 2.0f),
|
||||
Material(1.0f, 1.0f, 0.2f, 1.0f)
|
||||
), DrawMode::DRAW_TRIANGLES
|
||||
),
|
||||
m_plane(
|
||||
meshgenerator::set_material<litshadowed::Vertex, litshadowed::Index>(
|
||||
meshgenerator::gen_plane_pn<litshadowed::Vertex, litshadowed::Index>(DRAW_TRIANGLES, 4.0f, 4.0f),
|
||||
Material(1.0f, 1.0f, 0.2f, 1.0f)
|
||||
), DrawMode::DRAW_TRIANGLES
|
||||
),
|
||||
m_camera((float)TAU_1_4, (float)m_screen_size.x / m_screen_size.y, 1.0f, 10.0f, vec3(0.0f, 0.0f, -5.0f)),
|
||||
m_batch(add_batch(&m_shape, 1))
|
||||
m_cube_batch(add_batch(&m_cube, 1)),
|
||||
m_plane_batch(add_batch(&m_plane, 1))
|
||||
{
|
||||
add_prerenderable(&m_camera);
|
||||
set_camera(&m_camera);
|
||||
@ -45,7 +52,7 @@ void MyBuiltinLitShadowedScene::update(float delta_time, clock_t clock)
|
||||
radians = (float)TAU * c / intervals;
|
||||
|
||||
{
|
||||
Poseable& pose = m_batch.get_pose(0);
|
||||
Poseable& pose = m_cube_batch.get_pose(0);
|
||||
pose.rotate(glm::normalize(vec3(1.0f, 1.0f, 0.0f)), (float)TAU_1_8 * delta_time);
|
||||
pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f));
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ public:
|
||||
|
||||
void update(float delta_time, clock_t clock) override;
|
||||
private:
|
||||
litshadowed::Renderable m_shape;
|
||||
litshadowed::Renderable m_cube;
|
||||
litshadowed::Renderable m_plane;
|
||||
builtin::Camera3D m_camera;
|
||||
litshadowed::Batch& m_batch;
|
||||
litshadowed::Batch& m_cube_batch;
|
||||
litshadowed::Batch& m_plane_batch;
|
||||
};
|
Loading…
Reference in New Issue
Block a user