Dawn/src/dawnrpg/scene/HelloWorldScene.cpp
2024-11-26 19:38:35 -06:00

117 lines
3.8 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "scene/SceneList.hpp"
#include "component/SimpleComponent.hpp"
#include "component/display/Camera.hpp"
#include "component/display/material/SimpleTexturedMaterial.hpp"
#include "component/display/MeshRenderer.hpp"
#include "display/mesh/CubeMesh.hpp"
#include "display/mesh/SphereMesh.hpp"
#include "component/physics/CubeCollider.hpp"
#include "component/physics/SphereCollider.hpp"
using namespace Dawn;
void Dawn::helloWorldScene(Scene &s) {
auto cameraItem = s.createSceneItem();
auto camera = cameraItem->addComponent<Camera>();
cameraItem->lookAt({ 20, 20, 20 }, { 0, 0, 0 }, { 0, 1, 0 });
camera->clipFar = 99999.99f;
// Ground
{
// Create the scene item.
auto groundItem = s.createSceneItem();
groundItem->setLocalPosition(glm::vec3(0, 0, 0));
// Create a simple cube mesh.
auto groundMesh = std::make_shared<Mesh>();
groundMesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(groundMesh, glm::vec3(-15, -1, -15), glm::vec3(30, 2, 30), 0, 0);
// Add a renderer to the scene item.
auto groundMeshRenderer = groundItem->addComponent<MeshRenderer>();
groundMeshRenderer->mesh = groundMesh;
// Add a material to the scene item.
auto groundMaterial = groundItem->addComponent<SimpleTexturedMaterial>();
groundMaterial->setColor(COLOR_LIGHT_GREY);
// Add collider
auto groundCollider = groundItem->addComponent<CubeCollider>();
groundCollider->setColliderType(ColliderType::STATIC);
groundCollider->setShape(glm::vec3(15, 1, 15));
}
// Box
{
// Create the scene item.
auto cubeItem = s.createSceneItem();
cubeItem->setLocalPosition(glm::vec3(0, 10, 0));
// Create a simple cube mesh.
auto cubeMesh = std::make_shared<Mesh>();
cubeMesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(cubeMesh, glm::vec3(-1, -1, -1), glm::vec3(2, 2, 2), 0, 0);
// Add a renderer to the scene item.
auto cubeMeshRenderer = cubeItem->addComponent<MeshRenderer>();
cubeMeshRenderer->mesh = cubeMesh;
// Add a material to the scene item.
auto cubeMaterial = cubeItem->addComponent<SimpleTexturedMaterial>();
cubeMaterial->setColor(COLOR_MAGENTA);
// Add collider
auto cubeCollider = cubeItem->addComponent<CubeCollider>();
}
// Other Box
{
// Create the scene item.
auto cubeItem = s.createSceneItem();
cubeItem->setLocalPosition(glm::vec3(0.75f, 15, 0.1f));
// Create a simple cube mesh.
auto cubeMesh = std::make_shared<Mesh>();
cubeMesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(cubeMesh, glm::vec3(-1, -1, -1), glm::vec3(2, 2, 2), 0, 0);
// Add a renderer to the scene item.
auto cubeMeshRenderer = cubeItem->addComponent<MeshRenderer>();
cubeMeshRenderer->mesh = cubeMesh;
// Add a material to the scene item.
auto cubeMaterial = cubeItem->addComponent<SimpleTexturedMaterial>();
cubeMaterial->setColor(COLOR_MAGENTA);
// Add collider
auto cubeCollider = cubeItem->addComponent<CubeCollider>();
}
// Ball
{
// Create the scene item.
auto sphereItem = s.createSceneItem();
sphereItem->setLocalPosition(glm::vec3(-1.0f, 13, -0.6f));
// Create a simple cube mesh.
auto sphereMesh = std::make_shared<Mesh>();
SphereMesh::create(sphereMesh, 1.0f);
// Add a renderer to the scene item.
auto sphereMeshRenderer = sphereItem->addComponent<MeshRenderer>();
sphereMeshRenderer->mesh = sphereMesh;
// Add a material to the scene item.
auto sphereMaterial = sphereItem->addComponent<SimpleTexturedMaterial>();
sphereMaterial->setColor(COLOR_CYAN);
// Add collider
auto sphereCollider = sphereItem->addComponent<SphereCollider>();
}
}