From f486caddd2b15f587741deab5d9e037bc809982d Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 23 Oct 2022 01:27:20 -0700 Subject: [PATCH] Updated some docs, prepping for font. --- src/dawn/display/CMakeLists.txt | 1 + src/dawn/display/Transform.hpp | 88 +++++++++++++++++++++++++--- src/dawn/display/font/CMakeLists.txt | 10 ++++ src/dawn/display/font/Font.cpp | 8 +++ src/dawn/display/font/Font.hpp | 44 ++++++++++++++ 5 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 src/dawn/display/font/CMakeLists.txt create mode 100644 src/dawn/display/font/Font.cpp create mode 100644 src/dawn/display/font/Font.hpp diff --git a/src/dawn/display/CMakeLists.txt b/src/dawn/display/CMakeLists.txt index 95caaee1..e38df2d8 100644 --- a/src/dawn/display/CMakeLists.txt +++ b/src/dawn/display/CMakeLists.txt @@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME} ) # Subdirs +add_subdirectory(font) add_subdirectory(mesh) \ No newline at end of file diff --git a/src/dawn/display/Transform.hpp b/src/dawn/display/Transform.hpp index a8e0ad16..d8fda442 100644 --- a/src/dawn/display/Transform.hpp +++ b/src/dawn/display/Transform.hpp @@ -39,31 +39,105 @@ namespace Dawn { public: SceneItem &item; + /** + * Constructs a new transform instance. Currently I have bound transforms + * to their parent SceneItem, but in future I may allow them to become + * disconnected from each other, for example I really could use a special + * transform designed purely for UI elements, since they don't act like + * normal scene items, but for now Transforms and SceneItems are 1:1 + * + * @param item Item that this transform belongs to. + */ Transform(SceneItem &item); + /** + * Orients this transform to look at a given point in world space. + * + * @param position Position of the origin of this transform. + * @param look Position in world space this transform looks at. + */ void lookAt(glm::vec3 position, glm::vec3 look); void lookAt(glm::vec3 position, glm::vec3 look, glm::vec3 up); + /** + * Returns the local position (position relative to "my parent"). + * @return The 3D local position in parent-relative space. + */ glm::vec3 getLocalPosition(); + + /** + * Update / Set the local position of this transform relative to my parent + * @param position Position to set for the local transform. + */ void setLocalPosition(glm::vec3 position); + /** + * Retusn the scale of this item, relative to my parent. + * @return 3D Scale vector of this item in parent-relative space. + */ glm::vec3 getLocalScale(); - void setLocalScale(glm::vec3 scale); - - glm::quat getLocalRotation(); - void setLocalRotation(glm::quat rotation); - + /** + * Set the local scale of this item. + * @param scale Scale of this item, relative to its parent. + */ + void setLocalScale(glm::vec3 scale); + + /** + * Returns the local rotation for this transform. + * @return The local rotation (parent-relative). + */ + glm::quat getLocalRotation(); + + /** + * Set the local (parent-relative) rotation for this transform. + * @param rotation Rotation in parent relative space. + */ + void setLocalRotation(glm::quat rotation); + + /** + * Returns the transform matrix for this transform, in parent-relative + * space. + * @return The transform origin in parent-relative space. + */ glm::mat4 getLocalTransform(); + + /** + * Sets the local transform matrix for this transform. + * @param transform Local (parent-relative) transform to set. + */ void setLocalTransform(glm::mat4 transform); + /** + * Returns the transformation matrix for this transform, in world-space. + * @return The transform origin in world-space. + */ glm::mat4 getWorldTransform(); - void setWorldTransform(glm::mat4 transform); - + /** + * Updates the transform's world-space. + * @param transform Sets the transform position in world-space. + */ + void setWorldTransform(glm::mat4 transform); + + /** + * Updates the transform that this transform is a child of. Will also + * handle disconnecting any existing parent. + * + * @param p Parent that this transform is now a child of. + */ void setParent(Transform *p); + + /** + * Returns the parent transform of this transform, or nullptr if there is + * no parent for this transform. + * @return Pointer to the parent transform, or nullptr. + */ Transform * getParent(); + /** + * Dispose and clenaup this transform, also removes self from parent. + */ ~Transform(); }; } \ No newline at end of file diff --git a/src/dawn/display/font/CMakeLists.txt b/src/dawn/display/font/CMakeLists.txt new file mode 100644 index 00000000..841a5b48 --- /dev/null +++ b/src/dawn/display/font/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + Font.cpp +) \ No newline at end of file diff --git a/src/dawn/display/font/Font.cpp b/src/dawn/display/font/Font.cpp new file mode 100644 index 00000000..64ad528a --- /dev/null +++ b/src/dawn/display/font/Font.cpp @@ -0,0 +1,8 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Font.hpp" + +using namespace Dawn; \ No newline at end of file diff --git a/src/dawn/display/font/Font.hpp b/src/dawn/display/font/Font.hpp new file mode 100644 index 00000000..fb167403 --- /dev/null +++ b/src/dawn/display/font/Font.hpp @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "display/mesh/Mesh.hpp" +#include "display/Texture.hpp" + +namespace Dawn { + class FontMeasure { + public: + virtual float_t getWidth() = 0; + virtual float_t getHeight() = 0; + virtual int32_t getQuadsOnLine(int32_t line); + virtual int32_t getQuadIndexOnLine(int32_t line); + virtual int32_t getLineCount(); + virtual int32_t getQuadCount(); + }; + + class Font { + public: + Font(); + + virtual void init() = 0; + + virtual void buffer( + std::string text, + float_t fontSize, + float_t maxWidth, + Mesh &mesh, + FontMeasure &measure + ) = 0; + + virtual Texture & getTexture() = 0; + virtual void draw(Mesh &mesh, int32_t startCharacter, int32_t length) = 0; + virtual float_t getLineHeight(float_t fontSize) = 0; + virtual float_t getDefaultFontSize() = 0; + + virtual ~Font(); + }; +} \ No newline at end of file