feat: organized the create scene functions

This commit is contained in:
Sara 2024-09-19 15:44:28 +02:00
parent 8abee4ab20
commit 44859f2de0

View file

@ -8,31 +8,38 @@
#include "core/mesh_render_entity.h"
#include "utils/debug.h"
Scene *CreateInitialScene() {
Transformable transformable;
Transform transform;
SceneNode *root = CreateTransformNode();
// create a model with a camera attached as a child of the root of the scene
SceneNode *model_parent = CreateTransformNode();
SceneNodeAddChild(root, model_parent);
// create the rest of the scene with a mesh and a functionality node
SceneNodeAddChild(model_parent, CreateMeshRenderEntity("spacefighter"));
SceneNodeAddChild(model_parent, CreateTestObject());
transformable = TC_CAST(model_parent->entity, Transformable);
transform = transformable.tc->get_global_transform(transformable.data);
transform.translation.y += 10;
transformable.tc->set_global_transform(transformable.data, transform);
// create a camera attached to it's own transform node
SceneNode *camera_parent = CreateTransformNode(); // the parent
SceneNodeAddChild(model_parent, camera_parent); // attached to the model parent
//! Create camera node with a transformable parent.
SceneNode *CreateCameraScene() {
SceneNode *camera_parent = CreateTransformNode();
SceneNodeAddChild(camera_parent, CreateCameraNode());
// set camera parent offset
transformable = TC_CAST(camera_parent->entity, Transformable);
transform = transformable.tc->get_transform(transformable.data);
Transformable transformable = TC_CAST(camera_parent->entity, Transformable);
Transform transform = transformable.tc->get_transform(transformable.data);
transform.translation = (Vector3){3.f, 4.f, -10.f};
transform.rotation = QuaternionFromEuler(7.5f * DEG2RAD, 0.f, 0.f);
transformable.tc->set_transform(transformable.data, transform);
// create the camera and attach it to the dedicated transform node
SceneNodeAddChild(camera_parent, CreateCameraNode());
return camera_parent;
}
//! create a model with a camera attached as a child of the root of the scene.
SceneNode *CreateModelScene() {
SceneNode *model_parent = CreateTransformNode();
// create the rest of the scene with a mesh and a functionality node
SceneNodeAddChild(model_parent, CreateMeshRenderEntity("spacefighter"));
SceneNodeAddChild(model_parent, CreateTestObject());
// move the renderer's parent transform
Transformable transformable = TC_CAST(model_parent->entity, Transformable);
Transform transform = transformable.tc->get_global_transform(transformable.data);
transform.translation.y += 10;
transformable.tc->set_global_transform(transformable.data, transform);
return model_parent;
}
Scene *CreateInitialScene() {
SceneNode *root = CreateTransformNode();
SceneNode *model = CreateModelScene();
SceneNodeAddChild(root, model);
SceneNodeAddChild(model, CreateCameraScene());
return CreateScene(root);
}