add test model
This commit is contained in:
parent
ba458be334
commit
69ddcb7595
46
res/content/base/models/cube.obj
Normal file
46
res/content/base/models/cube.obj
Normal file
@ -0,0 +1,46 @@
|
||||
# Blender v2.79 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib cube.mtl
|
||||
o Cube
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.500000
|
||||
v 0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
vn 1.0000 0.0000 0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn 0.0000 0.0000 -1.0000
|
||||
usemtl blocks/stone
|
||||
s off
|
||||
f 1/1/1 2/2/1 3/3/1 4/4/1
|
||||
f 5/5/2 8/6/2 7/7/2 6/8/2
|
||||
f 1/1/3 5/9/3 6/10/3 2/11/3
|
||||
f 2/12/4 6/13/4 7/7/4 3/14/4
|
||||
f 3/15/5 7/16/5 8/17/5 4/4/5
|
||||
f 5/5/6 1/18/6 4/19/6 8/20/6
|
||||
@ -2,5 +2,8 @@
|
||||
"sounds": [
|
||||
"blocks/door_open",
|
||||
"blocks/door_close"
|
||||
],
|
||||
"models": [
|
||||
"cube"
|
||||
]
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ void WorldRenderer::renderLevel(
|
||||
drawChunks(level->chunks.get(), camera, shader);
|
||||
|
||||
shader->uniformMatrix("u_model", glm::mat4(1.0f));
|
||||
level->entities->render(assets, *modelBatch);
|
||||
level->entities->render(assets, *modelBatch, *frustumCulling);
|
||||
modelBatch->render();
|
||||
|
||||
skybox->unbind();
|
||||
|
||||
@ -3,8 +3,7 @@
|
||||
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
class Frustum
|
||||
{
|
||||
class Frustum {
|
||||
public:
|
||||
Frustum() {};
|
||||
|
||||
@ -12,8 +11,7 @@ public:
|
||||
bool isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp) const;
|
||||
|
||||
private:
|
||||
enum Planes
|
||||
{
|
||||
enum Planes {
|
||||
Left = 0,
|
||||
Right,
|
||||
Bottom,
|
||||
@ -25,8 +23,7 @@ private:
|
||||
};
|
||||
|
||||
template<Planes i, Planes j>
|
||||
struct ij2k
|
||||
{
|
||||
struct ij2k {
|
||||
enum { k = i * (9 - i) / 2 + j - 1 };
|
||||
};
|
||||
|
||||
@ -37,8 +34,7 @@ private:
|
||||
glm::vec3 m_points[8];
|
||||
};
|
||||
|
||||
inline void Frustum::update(glm::mat4 m)
|
||||
{
|
||||
inline void Frustum::update(glm::mat4 m) {
|
||||
m = glm::transpose(m);
|
||||
m_planes[Left] = m[3] + m[0];
|
||||
m_planes[Right] = m[3] - m[0];
|
||||
@ -78,8 +74,7 @@ inline void Frustum::update(glm::mat4 m)
|
||||
|
||||
inline bool Frustum::isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp) const {
|
||||
// check box outside/inside of frustum
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
for (int i = 0; i < Count; i++) {
|
||||
if ((glm::dot(m_planes[i], glm::vec4(minp.x, minp.y, minp.z, 1.0f)) < 0.0) &&
|
||||
(glm::dot(m_planes[i], glm::vec4(maxp.x, minp.y, minp.z, 1.0f)) < 0.0) &&
|
||||
(glm::dot(m_planes[i], glm::vec4(minp.x, maxp.y, minp.z, 1.0f)) < 0.0) &&
|
||||
@ -106,8 +101,7 @@ inline bool Frustum::isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp)
|
||||
}
|
||||
|
||||
template<Frustum::Planes a, Frustum::Planes b, Frustum::Planes c>
|
||||
inline glm::vec3 Frustum::intersection(const glm::vec3* crosses) const
|
||||
{
|
||||
inline glm::vec3 Frustum::intersection(const glm::vec3* crosses) const {
|
||||
float D = glm::dot(glm::vec3(m_planes[a]), crosses[ij2k<b, c>::k]);
|
||||
glm::vec3 res = glm::mat3(crosses[ij2k<b, c>::k], -crosses[ij2k<a, c>::k], crosses[ij2k<a, b>::k]) *
|
||||
glm::vec3(m_planes[a].w, m_planes[b].w, m_planes[c].w);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ struct Transform {
|
||||
class Level;
|
||||
class Assets;
|
||||
class ModelBatch;
|
||||
class Frustum;
|
||||
|
||||
class Entity {
|
||||
entt::registry& registry;
|
||||
@ -51,7 +52,7 @@ class Entities {
|
||||
public:
|
||||
Entities(Level* level);
|
||||
void updatePhysics(float delta);
|
||||
void render(Assets* assets, ModelBatch& batch);
|
||||
void render(Assets* assets, ModelBatch& batch, Frustum& frustum);
|
||||
};
|
||||
|
||||
#endif // OBJECTS_ENTITIES_HPP_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user