add test model

This commit is contained in:
MihailRis
2024-06-24 01:05:28 +03:00
parent ba458be334
commit 69ddcb7595
6 changed files with 81 additions and 27 deletions
+23 -13
View File
@@ -6,21 +6,26 @@
#include "../physics/PhysicsSolver.hpp"
#include "../graphics/render/ModelBatch.hpp"
#include "../graphics/core/Model.hpp"
#include "../maths/FrustumCulling.hpp"
#include <glm/ext/matrix_transform.hpp>
void Transform::refresh() {
combined = glm::mat4(1.0f);
combined = glm::translate(combined, pos);
combined = glm::scale(combined, size);
combined = combined * glm::mat4(rot);
}
Entities::Entities(Level* level) : level(level) {
auto entity = registry.create();
glm::vec3 pos(0.5f, 170, 0.5f);
glm::vec3 size(1);
registry.emplace<EntityId>(entity, 1);
registry.emplace<Transform>(entity, pos, size, glm::mat3(1.0f));
registry.emplace<Hitbox>(entity, pos, size/20.0f);
for (int i = 0; i < 1000; i++) {
auto entity = registry.create();
glm::vec3 pos(0.5f+rand()%50, 100+i, 0.5f+rand()%50);
glm::vec3 size(1);
registry.emplace<EntityId>(entity, 1);
registry.emplace<Transform>(entity, pos, size/4.0f, glm::mat3(1.0f));
registry.emplace<Hitbox>(entity, pos, size/2.0f);
}
}
void Entities::updatePhysics(float delta){
@@ -37,19 +42,24 @@ void Entities::updatePhysics(float delta){
true
);
transform.pos = hitbox.position;
transform.rot = glm::rotate(glm::mat4(transform.rot), delta, glm::vec3(0, 1, 0));
if (hitbox.grounded) {
hitbox.velocity.y = 10;
//hitbox.velocity.y = 10;
}
}
}
void Entities::render(Assets* assets, ModelBatch& batch) {
void Entities::render(Assets* assets, ModelBatch& batch, Frustum& frustum) {
auto view = registry.view<Transform>();
auto model = assets->get<model::Model>("dingus");
auto model = assets->get<model::Model>("cube");
for (auto [entity, transform] : view.each()) {
transform.refresh();
batch.pushMatrix(transform.combined);
batch.draw(model);
batch.popMatrix();
const auto& pos = transform.pos;
const auto& size = transform.size;
if (frustum.isBoxVisible(pos-size, pos+size)) {
transform.refresh();
batch.pushMatrix(transform.combined);
batch.draw(model);
batch.popMatrix();
}
}
}