feat: add sphere scene with fixed cube-to-sphere mapping
Added scenes/sphere.{hpp,cpp} using the cube-to-sphere
approach from nrz.cpp, but with corrected math: vertices
are simply normalized to project onto the unit sphere
(the original used a broken formula with p=50.0 as an
exponent).
The sphere uses indexed geometry with position, normal,
and UV attributes, plus a simple diffuse lighting shader.
Press 1/2 to switch between cube and sphere scenes.
Updated .gitignore to exclude generated PNG screenshots.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include "cbt/scene.hpp"
|
||||
#include "cbt/opengl/buffer.hpp"
|
||||
#include "cbt/opengl/shader.hpp"
|
||||
#include "cbt/opengl/vao.hpp"
|
||||
|
||||
namespace cbt::scenes {
|
||||
|
||||
class sphere final : public scene {
|
||||
public:
|
||||
sphere();
|
||||
auto init() -> bool override;
|
||||
auto update(float delta_time) -> void override;
|
||||
auto render() -> void override;
|
||||
|
||||
private:
|
||||
opengl::shader m_prog;
|
||||
opengl::buffer m_vbo;
|
||||
opengl::buffer m_ebo{opengl::buffer_type::index};
|
||||
opengl::vao m_vao;
|
||||
|
||||
GLint m_loc_proj = -1;
|
||||
GLint m_loc_view = -1;
|
||||
GLint m_loc_model = -1;
|
||||
|
||||
GLsizei m_index_count = 0;
|
||||
|
||||
std::chrono::steady_clock::time_point m_start;
|
||||
|
||||
auto build_mesh() -> void;
|
||||
auto build_shader() -> bool;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user