Huge changes for 3d

This commit is contained in:
2026-09-30 18:53:16 -07:00
parent cd2e80cfca
commit b5b0eb9497
53 changed files with 1313 additions and 457 deletions
+50
View File
@@ -0,0 +1,50 @@
#include <glm/gtc/quaternion.hpp>
#include <sophia/application.hpp>
#include <sophia/components.hpp>
#include <sophia/entity.hpp>
#include <sophia/primitives.hpp>
#include <sophia/scene_view.hpp>
// A spinning cube seen through a perspective camera.
class Cube : public sophia::Application {
public:
Cube() : Application{{.width = 800, .height = 600, .name = "Cube"}} {
debugUI().showFrameStats(true);
}
void onCreate() override {
sophia::SceneHandle sceneHandle = scenes().create();
sophia::Scene& scene = scenes().get(sceneHandle);
sophia::Entity camera = scene.createCamera();
camera.getComponent<sophia::CameraComponent>().projection =
sophia::CameraComponent::Projection::Perspective;
camera.getComponent<sophia::TransformComponent>().position = {0.f, 0.f,
3.f};
// Unlit, so color each face by its normal to tell them apart.
sophia::MeshData data = sophia::primitives::cube();
for (sophia::MeshVertex& vertex : data.vertices) {
vertex.color = glm::vec4{vertex.normal * 0.5f + 0.5f, 1.f};
}
cube = scene.createEntity("Cube");
cube.addComponent<sophia::MeshComponent>(sophia::MeshComponent{
.handle = resources().create<sophia::Mesh>(data)});
sceneViews().create({
.scene = sceneHandle,
});
}
void onUpdate(const sophia::FrameInfo& frameInfo) override {
auto angle = static_cast<float>(frameInfo.elapsedTime);
cube.getComponent<sophia::TransformComponent>().rotation =
glm::angleAxis(angle, glm::normalize(glm::vec3{1.f, 1.f, 0.f}));
}
private:
sophia::Entity cube;
};
SOPHIA_MAIN(Cube)