, cam()
, world()
, interface(world)
+, test_controller(MakeTestEntity(world))
, running(false) {
GLContext::EnableVSync();
glClearColor(0.0, 0.0, 0.0, 1.0);
}
+Entity &Application::MakeTestEntity(World &world) {
+ Entity &e = world.AddEntity();
+ e.Position({ 0.0f, 0.0f, 0.0f });
+ e.SetShape(world.BlockTypes()[1]->shape, { 1.0f, 1.0f, 0.0f });
+ e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
+ return e;
+}
+
void Application::RunN(size_t n) {
Uint32 last = SDL_GetTicks();
void Application::Update(int dt) {
interface.Update(dt);
+ test_controller.Update(dt);
world.Update(dt);
}
#define BLANK_APP_HPP_
#include "camera.hpp"
+#include "controller.hpp"
#include "init.hpp"
#include "interface.hpp"
#include "shader.hpp"
void Update(int dt);
void Render();
+ static Entity &MakeTestEntity(World &);
+
private:
InitSDL init_sdl;
InitIMG init_img;
World world;
Interface interface;
+ RandomWalk test_controller;
+
bool running;
};
entity.Velocity(glm::rotateY(velocity, yaw));
}
+
+RandomWalk::RandomWalk(Entity &e)
+: entity(e)
+, time_left(0) {
+
+}
+
+
+void RandomWalk::Update(int dt) {
+ time_left -= dt;
+ if (time_left > 0) return;
+ time_left += 2500 + (rand() % 5000);
+
+ constexpr float move_vel = 0.0005f;
+
+ glm::vec3 new_vel = entity.Velocity();
+
+ switch (rand() % 9) {
+ case 0:
+ new_vel.x = -move_vel;
+ break;
+ case 1:
+ new_vel.x = 0.0f;
+ break;
+ case 2:
+ new_vel.x = move_vel;
+ break;
+ case 3:
+ new_vel.y = -move_vel;
+ break;
+ case 4:
+ new_vel.y = 0.0f;
+ break;
+ case 5:
+ new_vel.y = move_vel;
+ break;
+ case 6:
+ new_vel.z = -move_vel;
+ break;
+ case 7:
+ new_vel.z = 0.0f;
+ break;
+ case 8:
+ new_vel.z = move_vel;
+ break;
+ }
+
+ entity.Velocity(new_vel);
+}
+
}
};
+
+class RandomWalk {
+
+public:
+ explicit RandomWalk(Entity &);
+
+ void Update(int dt);
+
+private:
+ Entity &entity;
+
+ int time_left;
+
+};
+
}
#endif
#include "entity.hpp"
-#include "chunk.hpp"
+#include "geometry.hpp"
+#include "shape.hpp"
#include <cmath>
#include <glm/gtx/transform.hpp>
}
-void Entity::SetShape(Shape *s, const glm::vec3 &color) {
+void Entity::SetShape(const Shape *s, const glm::vec3 &color) {
shape = s;
model_buffer.Clear();
shape->Vertices(model_buffer.vertices, model_buffer.normals, model_buffer.indices);
#include "block.hpp"
#include "chunk.hpp"
-#include "geometry.hpp"
#include "model.hpp"
-#include "shape.hpp"
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
namespace blank {
+class Ray;
class Shape;
class Entity {
bool HasShape() const { return shape; }
const Shape *GetShape() const { return shape; }
- void SetShape(Shape *, const glm::vec3 &color);
+ void SetShape(const Shape *, const glm::vec3 &color);
void SetShapeless();
const glm::vec3 &Velocity() const { return velocity; }
void Draw();
private:
- Shape *shape;
+ const Shape *shape;
Model model;
glm::vec3 velocity;
player = &AddEntity();
player->Position({ 4.0f, 4.0f, 4.0f });
- Entity &test_entity = AddEntity();
- test_entity.Position({ 0.0f, 0.0f, 0.0f });
- test_entity.SetShape(&blockShape, { 1.0f, 1.0f, 0.0f });
- test_entity.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
-
chunks.Generate({ -4, -4, -4 }, { 5, 5, 5});
}