Merge remote-tracking branch 'origin/main' into SP3-2-Physics
This commit is contained in:
commit
015b443e4e
|
@ -120,8 +120,7 @@ namespace Sandbox
|
|||
auto& floorCollider = *SHComponentManager::GetComponent_s<SHColliderComponent>(floor);
|
||||
|
||||
floorRenderable.SetMesh(CUBE_MESH);
|
||||
floorRenderable.SetMaterial(customMat);
|
||||
floorRenderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
floorRenderable.SetMaterial(graphicsSystem->GetDefaultMaterialInstance());
|
||||
|
||||
floorTransform.SetWorldScale({ 7.5f, 0.5f, 7.5 });
|
||||
floorTransform.SetWorldPosition({ 0.0f, -3.0f, -5.0f });
|
||||
|
|
|
@ -200,7 +200,6 @@ namespace SHADE
|
|||
auto cubeFS = shaderModuleLibrary.GetBuiltInShaderModule("TestCube_FS");
|
||||
|
||||
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferSubpass);
|
||||
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::InitMiddleEnd(void) noexcept
|
||||
|
|
|
@ -144,6 +144,7 @@ namespace SHADE
|
|||
Handle<SHMaterialInstance> AddMaterialInstanceCopy(Handle<SHMaterialInstance> materialInst);
|
||||
void RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance);
|
||||
Handle<SHMaterial> GetDefaultMaterial() { return defaultMaterial; }
|
||||
Handle<SHMaterialInstance> GetDefaultMaterialInstance() { return AddOrGetBaseMaterialInstance(defaultMaterial); }
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Mesh Registration Functions */
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||
#include "SHGraphicsConstants.h"
|
||||
#include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/Vector/SHVec4.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -49,6 +51,22 @@ namespace SHADE
|
|||
// Reset all the properties to default values
|
||||
if (propMemory)
|
||||
memset(propMemory.get(), 0, propMemorySize);
|
||||
|
||||
// Initialize Vectors to all 1.0 by default
|
||||
const Handle<SHShaderBlockInterface> SHADER_INFO = GetShaderBlockInterface();
|
||||
for (int i = 0; i < SHADER_INFO->GetVariableCount(); ++i)
|
||||
{
|
||||
const auto& VAR = SHADER_INFO->GetVariable(i);
|
||||
switch (VAR->type)
|
||||
{
|
||||
case SHShaderBlockInterface::Variable::Type::VECTOR3:
|
||||
setPropertyUnsafe(VAR->offset, SHVec3::One);
|
||||
break;
|
||||
case SHShaderBlockInterface::Variable::Type::VECTOR4:
|
||||
setPropertyUnsafe(VAR->offset, SHVec4::One);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SHMaterial::ExportProperties(void* dest) const noexcept
|
||||
|
|
|
@ -75,6 +75,12 @@ namespace SHADE
|
|||
Handle<SHVkPipeline> pipeline;
|
||||
std::unique_ptr<char> propMemory;
|
||||
Byte propMemorySize = 0;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
inline void setPropertyUnsafe(uint32_t memOffset, const T& value); // SetProperty() but without checks
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Get offset and modify the memory directly
|
||||
T* dataPtr = propMemory.get() + PROP_INFO->offset;
|
||||
T* dataPtr = reinterpret_cast<T*>(propMemory.get() + PROP_INFO->offset);
|
||||
*dataPtr = value;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace SHADE
|
|||
if (memOffset + sizeof(T) > propMemorySize)
|
||||
throw std::invalid_argument("Attempted to set an invalid property!");
|
||||
// Set
|
||||
(*reinterpret_cast<T*>(propMemory.get() + memOffset)) = value;
|
||||
setPropertyUnsafe(memOffset, value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -58,7 +58,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Get offset and return the memory directly
|
||||
T* dataPtr = propMemory.get() + PROP_INFO->offset;
|
||||
T* dataPtr = reinterpret_cast<T*>(propMemory.get() + PROP_INFO->offset);
|
||||
return *dataPtr;
|
||||
}
|
||||
template<typename T>
|
||||
|
@ -81,4 +81,10 @@ namespace SHADE
|
|||
{
|
||||
return const_cast<const T&>(const_cast<SHMaterial*>(this)->GetProperty(memOffset));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SHMaterial::setPropertyUnsafe(uint32_t memOffset, const T& value)
|
||||
{
|
||||
(*reinterpret_cast<T*>(propMemory.get() + memOffset)) = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace SHADE
|
|||
|
||||
// Search Override Data for the property
|
||||
uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key);
|
||||
auto prop = std::find(overrideData.begin(), overrideData.end(), [&](const OverrideData& data)
|
||||
auto prop = std::find_if(overrideData.begin(), overrideData.end(), [&](const OverrideData& data)
|
||||
{
|
||||
return PROP_IDX == data.Index;
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ namespace SHADE
|
|||
throw std::invalid_argument("Attempted to get an property that was not set previously!");
|
||||
|
||||
// Get offset and return the memory directly
|
||||
T* dataPtr = dataStore.get() + prop->StoredDataOffset;
|
||||
T* dataPtr = reinterpret_cast<T*>(dataStore.get() + prop->StoredDataOffset);
|
||||
return *dataPtr;
|
||||
}
|
||||
template<typename T>
|
||||
|
|
|
@ -17,7 +17,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// Project Includes
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
#include "Math/SHMath.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -214,66 +214,4 @@ namespace SHADE
|
|||
SHLOG_ERROR("Image layouts are invalid. ");
|
||||
}
|
||||
}
|
||||
|
||||
vk::Format SHTextureLibrary::ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm:
|
||||
return vk::Format::eBc1RgbaUnormBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB:
|
||||
return vk::Format::eBc1RgbaSrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::BC5_SNorm:
|
||||
return isLinear ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_SNorm:
|
||||
return vk::Format::eR8G8B8A8Snorm;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb;
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm:
|
||||
case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm_SRGB:
|
||||
return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8Srgb;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported DDS format.");
|
||||
}
|
||||
|
||||
//switch (format)
|
||||
//{
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb;
|
||||
//
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb;
|
||||
//
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eBc1RgbaUnormBlock : vk::Format::eBc1RgbaSrgbBlock;
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock;
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm:
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB:
|
||||
// return (isLinear) ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock;
|
||||
|
||||
//case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm:
|
||||
// return (isLinear) ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock;
|
||||
//
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
// STL Includes
|
||||
#include <vector>
|
||||
// External Dependencies
|
||||
#include "tinyddsloader.h"
|
||||
// Project Includes
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
|
@ -169,6 +167,5 @@ namespace SHADE
|
|||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void preparePipelineBarriers(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::PipelineStageFlagBits& srcStage, vk::PipelineStageFlagBits& dstStage, std::vector<vk::ImageMemoryBarrier>& barriers);
|
||||
vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -195,6 +195,11 @@ namespace SHADE
|
|||
template<typename T>
|
||||
inline bool operator==(const Handle<T>& rhs) const noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
inline SHResourceLibraryBase* GetLibrary() const;
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -206,6 +211,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
friend class Handle;
|
||||
friend class Convert;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -96,6 +96,11 @@ namespace SHADE
|
|||
return id.Raw == rhs.id.Raw && library == static_cast<void*>(rhs.library);
|
||||
}
|
||||
|
||||
SHResourceLibraryBase* SHADE::Handle<void>::GetLibrary() const
|
||||
{
|
||||
return library;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ISelfHandle<T> - Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -70,13 +70,13 @@ namespace SHADE
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
SparseSet<T>::reference SparseSet<T>::at(index_type idx)
|
||||
typename SparseSet<T>::reference SparseSet<T>::at(index_type idx)
|
||||
{
|
||||
return const_cast<reference>(static_cast<const SparseSet<T>&>(*this).at(idx));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
SparseSet<T>::const_reference SparseSet<T>::at(index_type idx) const
|
||||
typename SparseSet<T>::const_reference SparseSet<T>::at(index_type idx) const
|
||||
{
|
||||
// Range Check
|
||||
if (idx >= sparseArray.size() || !contains(idx))
|
||||
|
@ -84,7 +84,7 @@ namespace SHADE
|
|||
return denseArray[sparseArray[idx]];
|
||||
}
|
||||
template<typename T>
|
||||
SparseSet<T>::size_type SparseSet<T>::size() const
|
||||
typename SparseSet<T>::size_type SparseSet<T>::size() const
|
||||
{
|
||||
return denseArray.size();
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace SHADE
|
|||
}
|
||||
template<typename T>
|
||||
template<typename ...Args>
|
||||
SparseSet<T>::reference SparseSet<T>::insert(index_type idx, Args && ...args)
|
||||
typename SparseSet<T>::reference SparseSet<T>::insert(index_type idx, Args && ...args)
|
||||
{
|
||||
// We need to resize the array
|
||||
if (idx >= sparseArray.size())
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/************************************************************************************//*!
|
||||
\file Material.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the implementation of the functions of the managed Material
|
||||
class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Material.hxx"
|
||||
// Standard Library
|
||||
#include <stdexcept>
|
||||
// Project Includes
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Macro Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
#define SET_PROP(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
const NATIVE_TYPE VAL = safe_cast<NATIVE_TYPE>(System::Convert::ChangeType(value, MANAGED_TYPE::typeid)); \
|
||||
NativeObject->SetProperty<NATIVE_TYPE>(PROP_NAME, VAL); \
|
||||
} \
|
||||
|
||||
#define SET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
const NATIVE_TYPE VAL = Convert::ToNative(safe_cast<MANAGED_TYPE>(System::Convert::ChangeType(value, MANAGED_TYPE::typeid))); \
|
||||
NativeObject->SetProperty<NATIVE_TYPE>(PROP_NAME, VAL); \
|
||||
} \
|
||||
|
||||
#define GET_PROP(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
return safe_cast<T>(NativeObject->GetProperty<NATIVE_TYPE>(PROP_NAME)); \
|
||||
} \
|
||||
|
||||
#define GET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \
|
||||
(T::typeid == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
return safe_cast<T>(Convert::ToCLI(NativeObject->GetProperty<NATIVE_TYPE>(PROP_NAME))); \
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Explicit Template Instantiation */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template ref class NativeAsset<SHMaterialInstance>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Material::Material(Handle<SHMaterialInstance> material)
|
||||
: NativeAsset<SHMaterialInstance>{ material }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Material Properties Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
generic<typename T>
|
||||
void Material::SetProperty(System::String^ name, T value)
|
||||
{
|
||||
if (!NativeObject)
|
||||
throw gcnew System::InvalidOperationException("Attempted to set property on an invalid material!");
|
||||
|
||||
// Call the correct one based on type
|
||||
const std::string PROP_NAME = Convert::ToNative(name);
|
||||
try
|
||||
{
|
||||
if SET_PROP (int, System::Int32)
|
||||
else if SET_PROP (int, System::Int64)
|
||||
else if SET_PROP (float, float)
|
||||
else if SET_PROP (double, double)
|
||||
else if SET_PROP_CONVERT(SHVec2, Vector2)
|
||||
else if SET_PROP_CONVERT(SHVec3, Vector3)
|
||||
// TODO: Vector4
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
throw gcnew System::ArgumentException("Attempted to modify an invalid property on a material.");
|
||||
}
|
||||
}
|
||||
|
||||
generic<typename T>
|
||||
T Material::GetProperty(System::String^ name)
|
||||
{
|
||||
if (!NativeObject)
|
||||
throw gcnew System::InvalidOperationException("[Material] Attempted to get property of an invalid material!");
|
||||
|
||||
// Call the correct one based on type
|
||||
const std::string PROP_NAME = Convert::ToNative(name);
|
||||
try
|
||||
{
|
||||
if GET_PROP (int, System::Int32)
|
||||
else if GET_PROP (int, System::Int64)
|
||||
else if GET_PROP (float, float)
|
||||
else if GET_PROP (double, double)
|
||||
else if GET_PROP_CONVERT(SHVec2, Vector2)
|
||||
else if GET_PROP_CONVERT(SHVec3, Vector3)
|
||||
// TODO: Vector4
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
throw gcnew System::ArgumentException("Attempted to retrieve a property on a material with an invalid type.");
|
||||
}
|
||||
|
||||
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/************************************************************************************//*!
|
||||
\file Material.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Mesh class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native MaterialInstance object containing material
|
||||
/// data that can be fed to Renderables for rendering.
|
||||
/// </summary>
|
||||
public ref class Material : public NativeAsset<SHMaterialInstance>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the Material
|
||||
/// </summary>
|
||||
/// <param name="material">Handle to the native material object.</param>
|
||||
Material(Handle<SHMaterialInstance> material);
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
// TODO: Change Shader
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Material Properties Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Set the value of a specific property.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of property to set.</typeparam>
|
||||
/// <param name="name">Name of the property to set.</param>
|
||||
/// <param name="value">Value to set te property to.</param>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If this Material object is invalid.
|
||||
/// </exception>
|
||||
/// <exception cref="System.ArgumentException">
|
||||
/// If the name or type was specified that does not match the material's shader's
|
||||
/// defined properties.
|
||||
/// </exception>
|
||||
generic<typename T>
|
||||
void SetProperty(System::String^ name, T value);
|
||||
/// <summary>
|
||||
/// Retrieves the value of a specified property on the material.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of property to get.</typeparam>
|
||||
/// <param name="name">Name of the property to get.</param>
|
||||
/// <returns>Value of that property on the material.</returns>
|
||||
/// <exception cref="System.InvalidOperationException">
|
||||
/// If this Material object is invalid.
|
||||
/// </exception>
|
||||
/// <exception cref="System.ArgumentException">
|
||||
/// If the name or type was specified that does not match the material's shader's
|
||||
/// defined properties.
|
||||
/// </exception>
|
||||
generic<typename T>
|
||||
T GetProperty(System::String^ name);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/************************************************************************************//*!
|
||||
\file Mesh.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the implementation of the functions of the managed Mesh class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Mesh.hxx"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Explicit Template Instantiation */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template ref class NativeAsset<SHMesh>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Mesh::Mesh(Handle<SHMesh> mesh)
|
||||
: NativeAsset<SHMesh> { mesh }
|
||||
{}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/************************************************************************************//*!
|
||||
\file Mesh.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Mesh class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
|
||||
// Project Includes
|
||||
#include "NativeAsset.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the native Mesh object containing vertex data that can
|
||||
/// be fed to Renderables for rendering.
|
||||
/// </summary>
|
||||
public ref class Mesh : public NativeAsset<SHMesh>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the Mesh
|
||||
/// </summary>
|
||||
/// <param name="mesh">Handle to the mesh object.</param>
|
||||
Mesh(Handle<SHMesh> mesh);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/************************************************************************************//*!
|
||||
\file NativeAsset.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the explicit template instantiation for some types of the
|
||||
templated managed NativeAsset class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
// Primary Include
|
||||
#include "NativeAsset.hxx"
|
||||
// Project Includes
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Explicit Tempalte Instantiations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/************************************************************************************//*!
|
||||
\file NativeAsset.h++
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of templated functions for the managed
|
||||
NativeAsset classes.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// Primary Include
|
||||
#include "NativeAsset.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename NativeAssetType>
|
||||
GenericHandle NativeAsset<NativeAssetType>::NativeObjectHandle::get()
|
||||
{
|
||||
return nativeObjHandle;
|
||||
}
|
||||
template <typename NativeAssetType>
|
||||
Handle<NativeAssetType> NativeAsset<NativeAssetType>::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return Handle<NativeAssetType>(Convert::ToNative(nativeObjHandle));
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<NativeAssetType>(); // Null handle
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename NativeAssetType>
|
||||
NativeAsset<NativeAssetType>::NativeAsset(Handle<NativeAssetType> nativeObj)
|
||||
: nativeObjHandle{ Convert::ToCLI(Handle<void>(nativeObj)) }
|
||||
{}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/************************************************************************************//*!
|
||||
\file NativeAsset.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the template definition of the managed class that represents
|
||||
native assets with a pointer to the corresponding native object.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2021 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Generalised template class for a managed representation of a native asset
|
||||
/// </summary>
|
||||
/// <typeparam name="NativeAssetType">
|
||||
/// The type of the asset's native representation.
|
||||
/// </typeparam>
|
||||
template<typename NativeAssetType>
|
||||
public ref class NativeAsset
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Generic handle for the native object
|
||||
/// </summary>
|
||||
property GenericHandle NativeObjectHandle
|
||||
{
|
||||
GenericHandle get();
|
||||
}
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<NativeAssetType> NativeObject
|
||||
{
|
||||
Handle<NativeAssetType> get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the native asset
|
||||
/// </summary>
|
||||
/// <param name="ptr">Native asset object.</param>
|
||||
NativeAsset(Handle<NativeAssetType> ptr);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
GenericHandle nativeObjHandle;
|
||||
};
|
||||
}
|
||||
|
||||
#include "NativeAsset.h++"
|
|
@ -27,7 +27,7 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Base interface for all Collider Shapes.
|
||||
/// </summary>
|
||||
public ref class CollisionShape
|
||||
public ref class CollisionShape abstract
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/************************************************************************************//*!
|
||||
\file Renderable.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the functions of the managed Renderable class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Renderable.hxx"
|
||||
#include "Assets/NativeAsset.hxx"
|
||||
#include "Utility/Convert.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Renderable::Renderable(Entity entity)
|
||||
: Component(entity)
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHADE::Mesh^ Renderable::Mesh::get()
|
||||
{
|
||||
return gcnew SHADE::Mesh(GetNativeComponent()->GetMesh());
|
||||
}
|
||||
void Renderable::Mesh::set(SHADE::Mesh^ value)
|
||||
{
|
||||
if (value == nullptr)
|
||||
{
|
||||
GetNativeComponent()->SetMesh(Handle<SHMesh>());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNativeComponent()->SetMesh(Handle<SHMesh>(Convert::ToNative(value->NativeObjectHandle)));
|
||||
}
|
||||
}
|
||||
SHADE::Material^ Renderable::Material::get()
|
||||
{
|
||||
return gcnew SHADE::Material(GetNativeComponent()->GetMaterial());
|
||||
}
|
||||
void Renderable::Material::set(SHADE::Material^ value)
|
||||
{
|
||||
if (value == nullptr)
|
||||
{
|
||||
GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>(Convert::ToNative(value->NativeObjectHandle)));
|
||||
}
|
||||
}
|
||||
System::Byte Renderable::LightLayer::get()
|
||||
{
|
||||
return GetNativeComponent()->GetLightLayer();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/************************************************************************************//*!
|
||||
\file Renderable.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Renderable class with the
|
||||
declaration of functions for working with it.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// Project Includes
|
||||
#include "Components/Component.hxx"
|
||||
#include "Math/Vector3.hxx"
|
||||
#include "Math/Quaternion.hxx"
|
||||
// External Dependencies
|
||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
#include "Assets/Mesh.hxx"
|
||||
#include "Assets/Material.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// CLR version of the SHADE Engine's SHRenderableComponent.
|
||||
/// </summary>
|
||||
public ref class Renderable : public Component<SHRenderable>
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs a Renderable Component that represents a native Renderable
|
||||
/// component tied to the specified Entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">Entity that this Component will be tied to.</param>
|
||||
Renderable(Entity entity);
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Mesh used to render this Renderable.
|
||||
/// </summary>
|
||||
property SHADE::Mesh^ Mesh
|
||||
{
|
||||
SHADE::Mesh^ get();
|
||||
void set(SHADE::Mesh^ value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Material used to render this Renderable.
|
||||
/// </summary>
|
||||
property SHADE::Material^ Material
|
||||
{
|
||||
SHADE::Material^ get();
|
||||
void set(SHADE::Material^ value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Material used to render this Renderable.
|
||||
/// </summary>
|
||||
property System::Byte LightLayer
|
||||
{
|
||||
System::Byte get();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/************************************************************************************//*!
|
||||
\file Renderable.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the functions of the managed Renderable class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
GenericHandle::GenericHandle(Handle<void> handle)
|
||||
: id { handle.GetId().Raw }
|
||||
, library { reinterpret_cast<void*>(handle.GetLibrary()) }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
System::UInt64 GenericHandle::Id::get()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
System::IntPtr GenericHandle::Library::get()
|
||||
{
|
||||
return library;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
GenericHandle::operator bool()
|
||||
{
|
||||
return library.ToPointer() != nullptr && id != System::UInt64::MaxValue;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/************************************************************************************//*!
|
||||
\file Handle.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed GenericHandle struct.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed version of the generic Handle<void>.
|
||||
/// </summary>
|
||||
public value struct GenericHandle
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs a GenericHandle for a native generic Handle<void>.
|
||||
/// </summary>
|
||||
/// <param name="handle">Handle to create a GenericHandle from.</param>
|
||||
explicit GenericHandle(Handle<void> handle);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// The internal ID of the handle.
|
||||
/// </summary>
|
||||
property System::UInt64 Id
|
||||
{
|
||||
System::UInt64 get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The library that the handle was issued by.
|
||||
/// </summary>
|
||||
property System::IntPtr Library
|
||||
{
|
||||
System::IntPtr get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Converts to true if this is a valid Handle.
|
||||
/// </summary>
|
||||
inline operator bool();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
System::UInt64 id;
|
||||
System::IntPtr library;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/************************************************************************************//*!
|
||||
\file Color.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 3, 2021
|
||||
\brief Contains the definition of the functions of the managed Color struct.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2021 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "Graphics/Color.hxx"
|
||||
// Standard Libraries
|
||||
#include <algorithm>
|
||||
// Project Includes
|
||||
#include "Math/Math.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Color::Color(float _red)
|
||||
: Color { _red, 0.0f, 0.0f, 1.0f }
|
||||
{}
|
||||
Color::Color(float _red, float _green)
|
||||
: Color { _red, _green, 0.0f, 1.0f }
|
||||
{}
|
||||
Color::Color(float _red, float _green, float _blue)
|
||||
: Color { _red, _green, _blue, 1.0f }
|
||||
{}
|
||||
Color::Color(float _red, float _green, float _blue, float _alpha)
|
||||
: r { _red }
|
||||
, g { _green }
|
||||
, b { _blue }
|
||||
, a { _alpha }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
bool Color::Equals(Object^ o)
|
||||
{
|
||||
try
|
||||
{
|
||||
Color col = safe_cast<Color>(o);
|
||||
return Equals(col);
|
||||
}
|
||||
catch (System::InvalidCastException^)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Object Overrides */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
bool Color::Equals(Color other)
|
||||
{
|
||||
return Math::CompareFloat(this->r, other.r)
|
||||
&&
|
||||
Math::CompareFloat(this->g, other.g)
|
||||
&&
|
||||
Math::CompareFloat(this->b, other.b)
|
||||
&&
|
||||
Math::CompareFloat(this->a, other.a);
|
||||
}
|
||||
int Color::GetHashCode()
|
||||
{
|
||||
const int HASH = 19;
|
||||
const int HASH2 = 23;
|
||||
const int HASH3 = 29;
|
||||
return r.GetHashCode() * HASH
|
||||
+ g.GetHashCode() * HASH2
|
||||
+ b.GetHashCode() * HASH3
|
||||
+ a.GetHashCode();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Color Color::Lerp(Color colA, Color colB, float t)
|
||||
{
|
||||
return LerpUnclamped(colA, colB, std::clamp(t, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
Color Color::LerpUnclamped(Color colA, Color colB, float t)
|
||||
{
|
||||
return colA + ((colB - colA) * t);
|
||||
}
|
||||
Color Color::operator+(Color lhs, Color rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r + rhs.r,
|
||||
lhs.g + rhs.g,
|
||||
lhs.b + rhs.b,
|
||||
lhs.a + rhs.a
|
||||
);
|
||||
}
|
||||
Color Color::operator-(Color lhs, Color rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r - rhs.r,
|
||||
lhs.g - rhs.g,
|
||||
lhs.b - rhs.b,
|
||||
lhs.a - rhs.a
|
||||
);
|
||||
}
|
||||
Color Color::operator*(Color lhs, Color rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r * rhs.r,
|
||||
lhs.g * rhs.g,
|
||||
lhs.b * rhs.b,
|
||||
lhs.a * rhs.a
|
||||
);
|
||||
}
|
||||
Color Color::operator*(Color lhs, float rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r * rhs,
|
||||
lhs.g * rhs,
|
||||
lhs.b * rhs,
|
||||
lhs.a * rhs
|
||||
);
|
||||
}
|
||||
Color Color::operator/(Color lhs, float rhs)
|
||||
{
|
||||
return Color
|
||||
(
|
||||
lhs.r / rhs,
|
||||
lhs.g / rhs,
|
||||
lhs.b / rhs,
|
||||
lhs.a / rhs
|
||||
);
|
||||
}
|
||||
bool Color::operator==(Color lhs, Color rhs)
|
||||
{
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
bool Color::operator!=(Color lhs, Color rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,287 @@
|
|||
/************************************************************************************//*!
|
||||
\file Color.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2022
|
||||
\brief Contains the definition of the managed Color struct with the
|
||||
declaration of functions for working with it.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// CLR version of the the SHADE Engine's Color struct which describes a Color
|
||||
/// encoded using floating point numbers that range from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
[System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)]
|
||||
public value struct Color : public System::IEquatable<Color>
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// A static class that contains a set of default Colors.
|
||||
/// </summary>
|
||||
ref class Defaults abstract sealed
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Pure black.
|
||||
/// </summary>
|
||||
static property Color Black
|
||||
{
|
||||
Color get() { return Color(0.0f, 0.0f, 0.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Light Gray, lighter than gray.
|
||||
/// </summary>
|
||||
static property Color LightGray
|
||||
{
|
||||
Color get() { return Color(0.827451f, 0.827451f, 0.827451f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gray, halfway between black and white.
|
||||
/// </summary>
|
||||
static property Color Gray
|
||||
{
|
||||
Color get() { return Color(0.5f, 0.5f, 0.5f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Dark Gray, darker than gray.
|
||||
/// </summary>
|
||||
static property Color DarkGray
|
||||
{
|
||||
Color get() { return Color(0.622f, 0.622f, 0.622f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure white.
|
||||
/// </summary>
|
||||
static property Color White
|
||||
{
|
||||
Color get() { return Color(1.0f, 1.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure red.
|
||||
/// </summary>
|
||||
static property Color Red
|
||||
{
|
||||
Color get() { return Color(1.0f, 0.0f, 0.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure green.
|
||||
/// </summary>
|
||||
static property Color Green
|
||||
{
|
||||
Color get() { return Color(0.0f, 1.0f, 0.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure blue.
|
||||
/// </summary>
|
||||
static property Color Blue
|
||||
{
|
||||
Color get() { return Color(0.0f, 0.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure cyan, mix of pure green and blue.
|
||||
/// </summary>
|
||||
static property Color Cyan
|
||||
{
|
||||
Color get() { return Color(0.0f, 1.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure magenta, mix of pure red and blue.
|
||||
/// </summary>
|
||||
static property Color Magenta
|
||||
{
|
||||
Color get() { return Color(1.0f, 0.0f, 1.0f); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Pure yellow, mix of pure red and green.
|
||||
/// </summary>
|
||||
static property Color Yellow
|
||||
{
|
||||
Color get() { return Color(1.0f, 1.0f, 0.0f); }
|
||||
}
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components with the
|
||||
/// green, blue and alpha component set to 1.0f.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
Color(float _red);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components with the
|
||||
/// blue and alpha component set to 1.0f.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
/// <param name="_green">Green component to set.</param>
|
||||
Color(float _red, float _green);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components with the
|
||||
/// alpha component set to 1.0f.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
/// <param name="_green">Green component to set.</param>
|
||||
/// <param name="_blue">Blue component to set.</param>
|
||||
Color(float _red, float _green, float _blue);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Color with the specified components.
|
||||
/// </summary>
|
||||
/// <param name="_red">Red component to set.</param>
|
||||
/// <param name="_green">Green component to set.</param>
|
||||
/// <param name="_blue">Blue component to set.</param>
|
||||
/// <param name="_alpha">Alpha component to set.</param>
|
||||
Color(float _red, float _green, float _blue, float _alpha);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Public Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Red component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float r;
|
||||
/// <summary>
|
||||
/// Green component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float g;
|
||||
/// <summary>
|
||||
/// Blue component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float b;
|
||||
/// <summary>
|
||||
/// Alpha component of the colour. Ranges from 0.0f to 1.0f.
|
||||
/// </summary>
|
||||
float a;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Compares equality with an object of the same type.
|
||||
/// </summary>
|
||||
/// <param name="other">The object to compare with.</param>
|
||||
/// <returns>True if both objects are the same.</returns>
|
||||
virtual bool Equals(Color other);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Object */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Compares equality with another unboxed object.
|
||||
/// </summary>
|
||||
/// <param name="o">The unboxed object to compare with.</param>
|
||||
/// <returns>True if both objects are the same.</returns>
|
||||
bool Equals(Object^ o) override;
|
||||
/// <summary>
|
||||
/// Gets a unique hash for this object.
|
||||
/// </summary>
|
||||
/// <returns>Unique hash for this object.</returns>
|
||||
int GetHashCode() override;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Static Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Linearly interpolates between two specified points.
|
||||
/// This is most commonly used to find a point some fraction of the way along a
|
||||
/// line between two endpoints.
|
||||
/// </summary>
|
||||
/// <param name="colA">The start Color, returned when t = 0.0.</param>
|
||||
/// <param name="colB">The end Color, returned when t = 1.0.</param>
|
||||
/// <param name="t">
|
||||
/// Value used to interpolate between a and b which is clamped to
|
||||
/// the range[0, 1].
|
||||
/// </param>
|
||||
/// <returns>The interpolated Vector3.</returns>
|
||||
static Color Lerp(Color colA, Color colB, float t);
|
||||
/// <summary>
|
||||
/// Linearly interpolates between two specified points.
|
||||
/// This is most commonly used to find a point some fraction of the way along a
|
||||
/// line between two endpoints.
|
||||
/// Unlike Lerp(), t is not clamped to a range at all.
|
||||
/// </summary>
|
||||
/// <param name="colA">The start Color, returned when t = 0.0.</param>
|
||||
/// <param name="colB">The end Color, returned when t = 1.0.</param>
|
||||
/// <param name="t">Value used to interpolate between a and b.</param>
|
||||
/// <returns>The interpolated Color.</returns>
|
||||
static Color LerpUnclamped(Color colA, Color colB, float t);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Adds two Colors together and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to add.</param>
|
||||
/// <param name="rhs">Another Color to add.</param>
|
||||
/// <returns>The result of lhs added to rhs</returns>
|
||||
static Color operator+(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Subtracts a Color from another Color and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to subtract from.</param>
|
||||
/// <param name="rhs">Another Color to subtract.</param>
|
||||
/// <returns>The result of rhs subtracted from lhs.</returns>
|
||||
static Color operator-(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Calculates the component-wise multiplication of two Colors and returns the
|
||||
/// result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to multiply with.</param>
|
||||
/// <param name="rhs">Another Color to multiply with.</param>
|
||||
/// <returns>The result of rhs subtracted from lhs.</returns>
|
||||
static Color operator*(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Calculates the multiplication of a Color with a scalar value and returns
|
||||
/// the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to multiply with.</param>
|
||||
/// <param name="rhs">Scalar to multiply with.</param>
|
||||
/// <returns>The result of the scalar multiplication.</returns>
|
||||
static Color operator*(Color lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Calculates the division of a Color with a scalar value and returns
|
||||
/// the result.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Scalar to divide with.</param>
|
||||
/// <param name="rhs">Color to divide with.</param>
|
||||
/// <returns>The result of the scalar division.</returns>
|
||||
static Color operator/(Color lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Checks if two Colors are approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to compare.</param>
|
||||
/// <param name="rhs">Another Color to compare.</param>
|
||||
/// <returns>
|
||||
/// True if all components are approximately equal within the default
|
||||
/// tolerance value.
|
||||
/// </returns>
|
||||
static bool operator==(Color lhs, Color rhs);
|
||||
/// <summary>
|
||||
/// Checks if two Colors are not approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Color to compare.</param>
|
||||
/// <param name="rhs">Another Color to compare.</param>
|
||||
/// <returns>
|
||||
/// True if all components are not approximately equal within the default
|
||||
/// tolerance value.
|
||||
/// </returns>
|
||||
static bool operator!=(Color lhs, Color rhs);
|
||||
};
|
||||
}
|
|
@ -54,4 +54,15 @@ namespace SHADE
|
|||
{
|
||||
return (value - a) / (b - a);
|
||||
}
|
||||
|
||||
bool Math::CompareFloat(float a, float b)
|
||||
{
|
||||
return CompareFloat(a, b, Epsilon);
|
||||
}
|
||||
|
||||
bool Math::CompareFloat(float a, float b, float tolerance)
|
||||
{
|
||||
return System::MathF::Abs(a - b) < tolerance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,12 +81,30 @@ namespace SHADE
|
|||
/// <returns>The interpolated float result between the two float values.</returns>
|
||||
static float LerpUnclamped(float a, float b, float t);
|
||||
/// <summary>
|
||||
/// Calculates the linear parameter t that produces the interpolant value within the range [a, b].
|
||||
/// Calculates the linear parameter t that produces the interpolant value within
|
||||
/// the range [a, b].
|
||||
/// </summary>
|
||||
/// <param name="a">Start value.</param>
|
||||
/// <param name="b">End value.</param>
|
||||
/// <param name="value">Value between start and end.</param>
|
||||
/// <returns>Percentage of value between start and end.</returns>
|
||||
static float InverseLerp(float a, float b, float value);
|
||||
/// <summary>
|
||||
/// Compares if two float values are close enough to be the same with a tolerance
|
||||
/// of Epsilon.
|
||||
/// </summary>
|
||||
/// <param name="a">One of the values to compare.</param>
|
||||
/// <param name="b">The other value to compare.</param>
|
||||
/// <returns>True if a and b are practically the same.</returns>
|
||||
static bool CompareFloat(float a, float b);
|
||||
/// <summary>
|
||||
/// Compares if two float values are close enough to be the same with the
|
||||
/// specified tolerance value.
|
||||
/// </summary>
|
||||
/// <param name="a">One of the values to compare.</param>
|
||||
/// <param name="b">The other value to compare.</param>
|
||||
/// <param name="tolerance">Tolerance for floating point comparison.</param>
|
||||
/// <returns>True if a and b are practically the same.</returns>
|
||||
static bool CompareFloat(float a, float b, float tolerance);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -84,4 +84,20 @@ namespace SHADE
|
|||
{
|
||||
return msclr::interop::marshal_as<System::String^>(str);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Handle Conversions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<void> Convert::ToNative(GenericHandle handle)
|
||||
{
|
||||
Handle<void> nativeHandle;
|
||||
nativeHandle.id.Raw = handle.Id;
|
||||
nativeHandle.library = reinterpret_cast<SHResourceLibraryBase*>(handle.Library.ToPointer());
|
||||
return nativeHandle;
|
||||
}
|
||||
|
||||
GenericHandle Convert::ToCLI(Handle<void> handle)
|
||||
{
|
||||
return GenericHandle(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/SHQuaternion.h"
|
||||
#include "Math/SHRay.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
// Project Includes
|
||||
#include "Engine/Entity.hxx"
|
||||
|
@ -27,6 +28,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Math/Vector3.hxx"
|
||||
#include "Math/Quaternion.hxx"
|
||||
#include "Math/Ray.hxx"
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -118,6 +120,23 @@ namespace SHADE
|
|||
/// <param name="str">The native std::string to convert from.</param>
|
||||
/// <returns>Managed copy of a native std::string.</returns>
|
||||
static System::String^ ToCLI(const std::string& str);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Handle Conversions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Converts from a managed GenericHandle to a Handle<void>.
|
||||
/// </summary>
|
||||
/// <param name="handle">GenericHandle to convert from.</param>
|
||||
/// <returns>Native generic Handle.</returns>
|
||||
static Handle<void> ToNative(GenericHandle handle);
|
||||
/// <summary>
|
||||
/// Converts from a native generic Handle<void> to a managed GenericHandle.
|
||||
/// </summary>
|
||||
/// <param name="handle">The native handle to convert.</param>
|
||||
/// <returns>Managed copy of the native Handle.</returns>
|
||||
static GenericHandle ToCLI(Handle<void> handle);
|
||||
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue