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
+2 -2
View File
@@ -141,8 +141,8 @@ class Boids2D : public sophia::Application {
cameraEntity.getComponent<sophia::TransformComponent>().position;
if (scrollLeft) cameraPosition.x -= scrollDistance;
if (scrollRight) cameraPosition.x += scrollDistance;
if (scrollUp) cameraPosition.y -= scrollDistance;
if (scrollDown) cameraPosition.y += scrollDistance;
if (scrollUp) cameraPosition.y += scrollDistance;
if (scrollDown) cameraPosition.y -= scrollDistance;
// One world unit per pixel, whatever size the viewport is.
cameraEntity.getComponent<sophia::CameraComponent>().ortho.height =
+3
View File
@@ -0,0 +1,3 @@
add_executable(cube main.cpp)
target_link_libraries(cube PRIVATE ${PROJECT_NAME})
+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)