~ | Better camera system + | Quad intersection test

This commit is contained in:
TheRedShip
2025-01-03 16:23:09 +01:00
parent f973d77654
commit d25db020bf
16 changed files with 135 additions and 1876 deletions

View File

@ -30,14 +30,17 @@ int main(int argc, char **argv)
Vertex vertices[3] = {{{-1.0f, -1.0f}, {0.0f, 0.0f}},{{3.0f, -1.0f}, {2.0f, 0.0f}},{{-1.0f, 3.0f}, {0.0f, 2.0f}}};
size_t size = sizeof(vertices) / sizeof(Vertex) / 3;
shader.setupVertexBuffer(vertices, size);
GLint max_gpu_size;
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
const std::vector<GPUObject> &gpu_data = scene.getGPUData();
std::cout << "Sending " << gpu_data.size() << " objects for "<< gpu_data.size() * sizeof(GPUObject) << " / " << max_gpu_size << " bytes" << std::endl;
while (!window.shouldClose())
{
glUseProgram(shader.getProgramCompute());
const std::vector<GPUObject> &gpu_data = scene.getGPUData();
// Update SSBO with latest object data
glBindBuffer(GL_SHADER_STORAGE_BUFFER, objectSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, gpu_data.size() * sizeof(GPUObject), gpu_data.data(), GL_DYNAMIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, objectSSBO);

View File

@ -38,14 +38,16 @@ void Camera::update_camera_vectors()
void Camera::update(float delta_time)
{
delta_time = std::min(delta_time, 0.1f);
_velocity += _acceleration * delta_time;
if (glm::length(_acceleration) < 0.1f)
_velocity *= (1.0f - _deceleration_rate * delta_time);
_velocity *= std::max(0.0f, 1.0f - _deceleration_rate * delta_time);
float speed = glm::length(_velocity);
if (speed > _maxSpeed)
_velocity = (_velocity / speed) * _maxSpeed;
_velocity = glm::normalize(_velocity) * _maxSpeed;
_position += _velocity * delta_time;
_acceleration = glm::vec3(0.0f);

View File

@ -90,6 +90,12 @@ void Scene::updateGPUData()
auto plane = static_cast<const Plane *>(obj);
gpu_obj.normal = plane->getNormal();
}
else if (obj->getType() == Object::Type::QUAD)
{
auto quad = static_cast<const Quad *>(obj);
gpu_obj.edge1 = quad->getEdge1();
gpu_obj.edge2 = quad->getEdge2();
}
_gpu_objects.push_back(gpu_obj);
}

View File

@ -25,6 +25,12 @@ SceneParser::SceneParser(Scene *scene) : _scene(scene)
try { return (new Plane(ss)); }
catch (const std::exception &e) { throw; }
};
object_parsers["qu"] = [](std::stringstream &ss) -> Object *
{
try { return (new Quad(ss)); }
catch (const std::exception &e) { throw; }
};
}
void SceneParser::parseMaterial(std::stringstream &line)