diff options
author | rtk0c <[email protected]> | 2023-10-19 22:50:07 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2025-08-16 11:31:16 -0700 |
commit | 297232d21594b138bb368a42b5b0d085ff9ed6aa (patch) | |
tree | 075d5407e1e12a9d35cbee6e4c20ad34e0765c42 /source/30-game/SceneThings.cpp | |
parent | d5cd34ff69f7fd134d5450696f298af1a864afbc (diff) |
The great renaming: switch to "module style"
Diffstat (limited to 'source/30-game/SceneThings.cpp')
-rw-r--r-- | source/30-game/SceneThings.cpp | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/source/30-game/SceneThings.cpp b/source/30-game/SceneThings.cpp deleted file mode 100644 index 3fa0436..0000000 --- a/source/30-game/SceneThings.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include "SceneThings.hpp" - -#include "CommonVertexIndex.hpp" -#include "Rect.hpp" - -#include <utility> - -SimpleGeometryObject::SimpleGeometryObject(GameWorld* world) - : GameObject(KD_SimpleGeometry, world) - , mRenderObject() - , mSize{ 1.0f, 1.0f, 1.0f } - , mXFaceColor(kXAxisColor) - , mYFaceColor(kYAxisColor) - , mZFaceColor(kZAxisColor) - , mNeedsRebuildMesh{ true } { - mRenderObject.SetMaterial(gDefaultMaterial.Get()); - mRenderObject.SetFormat(gVformatStandard.Get(), Tags::IT_16Bit); - mRenderObject.RebuildIfNecessary(); -} - -void SimpleGeometryObject::SetSize(glm::vec3 size) { - mSize = size; - mNeedsRebuildMesh = true; -} - -void SimpleGeometryObject::SetXFaceColor(RgbaColor color) { - mXFaceColor = color; - mNeedsRebuildMesh = true; -} - -void SimpleGeometryObject::SetYFaceColor(RgbaColor color) { - mYFaceColor = color; - mNeedsRebuildMesh = true; -} - -void SimpleGeometryObject::SetZFaceColor(RgbaColor color) { - mZFaceColor = color; - mNeedsRebuildMesh = true; -} - -std::span<const RenderObject> SimpleGeometryObject::GetRenderObjects() const { - using namespace Tags; - - if (mNeedsRebuildMesh) { - mNeedsRebuildMesh = false; - - Vertex_PTC vertices[4 /*vertices per face*/ * 6 /*faces*/]; - uint16_t indices[3 /*indices per triangle*/ * 2 /*triangles per face*/ * 6 /*faces*/]; - - auto extents = mSize / 2.0f; - - int faceGenVerticesIdx = 0; - int faceGenIndicesIdx = 0; - auto GenerateFace = [&](glm::vec3 faceCenter, glm::vec3 firstExtentVec, glm::vec3 secondExtentVec, RgbaColor color) { - // Generates (if viewing top down on the face): bottom left, top left, bottom right, top right - // (-1, -1) , (-1, 1) , (1, -1) , (1, 1) - // idx=0 , idx=1 , idx=2 , idx=3 - - // These are index offsets, see above comment - constexpr int kBottomLeft = 0; - constexpr int kTopLeft = 1; - constexpr int kBottomRight = 2; - constexpr int kTopRight = 3; - - int startVertIdx = faceGenVerticesIdx; - for (float firstDir : { -1, 1 }) { - for (float secondDir : { -1, 1 }) { - auto vertPos = faceCenter + firstExtentVec * firstDir + secondExtentVec * secondDir; - auto& vert = vertices[faceGenVerticesIdx]; - vert.x = vertPos.x; - vert.y = vertPos.y; - vert.z = vertPos.z; - vert.r = color.r; - vert.g = color.g; - vert.b = color.b; - vert.a = color.a; - faceGenVerticesIdx += 1; - } - } - - // Triangle #1 - indices[faceGenIndicesIdx++] = startVertIdx + kTopRight; - indices[faceGenIndicesIdx++] = startVertIdx + kTopLeft; - indices[faceGenIndicesIdx++] = startVertIdx + kBottomLeft; - // Triangle #2 - indices[faceGenIndicesIdx++] = startVertIdx + kTopRight; - indices[faceGenIndicesIdx++] = startVertIdx + kBottomLeft; - indices[faceGenIndicesIdx++] = startVertIdx + kBottomRight; - }; - for (int xDir : { -1, 1 }) { - float x = xDir * extents.x; - GenerateFace(glm::vec3(x, 0, 0), glm::vec3(0, 0, extents.z), glm::vec3(0, extents.y, 0), mXFaceColor); - } - for (int yDir : { -1, 1 }) { - float y = yDir * extents.y; - GenerateFace(glm::vec3(0, y, 0), glm::vec3(extents.x, 0, 0), glm::vec3(0, 0, extents.z), mYFaceColor); - } - for (int zDir : { -1, 1 }) { - float z = zDir * extents.z; - GenerateFace(glm::vec3(0, 0, z), glm::vec3(extents.x, 0, 0), glm::vec3(0, extents.y, 0), mZFaceColor); - } - - for (auto& vert : vertices) { - vert.u = 0.0f; - vert.v = 0.0f; - } - - mRenderObject.GetVertexBufferBindings().bindings[0]->Upload((const std::byte*)vertices, sizeof(vertices)); - mRenderObject.GetIndexBuffer()->Upload((const std::byte*)indices, IT_16Bit, std::size(indices)); - } - - return { &mRenderObject, 1 }; -} - -BuildingObject::BuildingObject(GameWorld* world) - : GameObject(KD_Building, world) { - mRenderObject.SetMaterial(gDefaultMaterial.Get()); - mRenderObject.SetFormat(gVformatStandard.Get(), Tags::IT_32Bit); - mRenderObject.RebuildIfNecessary(); -} - -// void BuildingObject::SetMeshMaterial(Material* material) { -// mMaterial.Attach(material); -// // TODO update render -// } - -// const Material* BuildingObject::GetMeshMaterial() const { -// return mMaterial.Get(); -// } - -// void BuildingObject::SetMesh(GpuMesh* mesh) { -// mMesh.Attach(mesh); -// // TODO update render -// } - -// const GpuMesh* BuildingObject::GetMesh() const { -// return mMesh.Get(); -// } - -std::span<const RenderObject> BuildingObject::GetRenderObjects() const { - return { &mRenderObject, 1 }; -} |