Add interface for C# light class and modified Color to match Unity's interface

This commit is contained in:
Kah Wei 2022-11-08 20:18:50 +08:00
parent 80ab010b4b
commit 715699b63b
6 changed files with 308 additions and 89 deletions

View File

@ -0,0 +1,79 @@
/************************************************************************************//*!
\file Light.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 8, 2022
\brief Contains the definition of the functions of the managed Light 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 "Light.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
Light::Light(Entity entity)
: Component(entity)
{}
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
Vector3 Light::Position::get()
{
return Convert::ToCLI(GetNativeComponent()->GetPosition());
}
void Light::Position::set(Vector3 value)
{
GetNativeComponent()->SetPosition(Convert::ToNative(value));
}
Light::Type Light::LightType::get()
{
return static_cast<Type>(GetNativeComponent()->GetType());
}
void Light::LightType::set(Light::Type value)
{
GetNativeComponent()->SetType(static_cast<SH_LIGHT_TYPE>(value));
}
Vector3 Light::Direction::get()
{
return Convert::ToCLI(GetNativeComponent()->GetDirection());
}
void Light::Direction::set(Vector3 value)
{
GetNativeComponent()->SetDirection(Convert::ToNative(value));
}
Color Light::Color::get()
{
return Convert::ToCLI(SHColour(GetNativeComponent()->GetColor()));
}
void Light::Color::set(SHADE::Color value)
{
GetNativeComponent()->SetColor(Convert::ToNative(value));
}
System::UInt32 Light::CullingMask::get()
{
return GetNativeComponent()->GetCullingMask();
}
void Light::CullingMask::set(System::UInt32 value)
{
GetNativeComponent()->SetCullingMask(value);
}
float Light::Strength::get()
{
return GetNativeComponent()->GetStrength();
}
void Light::Strength::set(float value)
{
GetNativeComponent()->SetStrength(value);
}
}

View File

@ -0,0 +1,125 @@
/************************************************************************************//*!
\file Light.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 8, 2022
\brief Contains the definition of the managed Light 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"
// External Dependencies
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
namespace SHADE
{
/// <summary>
/// CLR version of the SHADE Engine's SHLightComponent.
/// </summary>
public ref class Light : public Component<SHLightComponent>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructs a Light Component that represents a native Light component tied to
/// the specified Entity.
/// </summary>
/// <param name="entity">Entity that this Component will be tied to.</param>
Light(Entity entity);
public:
/*-----------------------------------------------------------------------------*/
/* Constants */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Supported types of the Light Component.
/// </summary>
enum class Type
{
/// <summary>
/// Light applied uniformly across the scene at a specified direction.
/// </summary>
Directional,
/// <summary>
/// Light that originates from a certain point in all directions.
/// Not implemented yet.
/// </summary>
Point,
/// <summary>
/// Light that originates from a certain point within a angle.
/// Not implemented yet.
/// </summary>
Spot,
/// <summary>
/// Light applied to all objects. Has no source point.
/// </summary>
Ambient
};
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Position of the light. Only works for Point Light (unimplemented).
/// </summary>
[System::ObsoleteAttribute("Not implemented yet.", true)]
property Vector3 Position
{
Vector3 get();
void set(Vector3 val);
}
/// <summary>
/// Type of lighting that this Light component will apply onto the scene.
/// </summary>
property Type LightType
{
Type get();
void set(Type val);
}
/// <summary>
/// Direction of the light. Only applicable for Directional Lights.
/// </summary>
property Vector3 Direction
{
Vector3 get();
void set(Vector3 val);
}
/// <summary>
/// Colour of the Light.
/// </summary>
property SHADE::Color Color
{
SHADE::Color get();
void set(SHADE::Color val);
}
/// <summary>
/// Culling mask that is used to control what types of Materials would be
/// affected by this Light.
/// </summary>
property System::UInt32 CullingMask
{
System::UInt32 get();
void set(System::UInt32 val);
}
/// <summary>
/// Intensity of the Light
/// </summary>
property float Strength
{
float get();
void set(float val);
}
};
}

View File

@ -22,8 +22,8 @@ of DigiPen Institute of Technology is prohibited.
// External Dependencies
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Math/Transform/SHTransformComponent.h"
#include "Physics\Components\SHColliderComponent.h"
#include "Physics\Components\SHRigidBodyComponent.h"
#include "Physics/Components/SHColliderComponent.h"
#include "Physics/Components/SHRigidBodyComponent.h"
#include "Scene/SHSceneManager.h"
#include "Scene/SHSceneGraph.h"
#include "Tools/SHLog.h"
@ -31,10 +31,11 @@ of DigiPen Institute of Technology is prohibited.
#include "Utility/Convert.hxx"
#include "Utility/Debug.hxx"
#include "Components/Transform.hxx"
#include "Components\RigidBody.hxx"
#include "Components\Collider.hxx"
#include "Components/RigidBody.hxx"
#include "Components/Collider.hxx"
#include "Components/Camera.hxx"
#include "Components/CameraArm.hxx"
#include "Components/Light.hxx"
namespace SHADE
{
@ -252,6 +253,7 @@ namespace SHADE
componentMap.Add(createComponentSet<SHRigidBodyComponent, RigidBody>());
componentMap.Add(createComponentSet<SHCameraComponent, Camera>());
componentMap.Add(createComponentSet<SHCameraArmComponent, CameraArm>());
componentMap.Add(createComponentSet<SHLightComponent, Light>());
}
/*---------------------------------------------------------------------------------*/

View File

@ -25,17 +25,8 @@ namespace SHADE
{
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>
@ -113,7 +104,6 @@ namespace SHADE
{
Color get() { return Color(1.0f, 1.0f, 0.0f); }
}
};
/*-----------------------------------------------------------------------------*/
/* Constructors */

View File

@ -72,6 +72,16 @@ namespace SHADE
return Ray(ToCLI(vec.position), ToCLI(vec.direction));
}
SHColour Convert::ToNative(Color col)
{
return SHColour(col.r, col.g, col.b, col.a);
}
Color Convert::ToCLI(const SHColour& vec)
{
return Color(vec.x, vec.y, vec.z, vec.w);
}
/*---------------------------------------------------------------------------------*/
/* String Conversions */
/*---------------------------------------------------------------------------------*/

View File

@ -29,6 +29,8 @@ of DigiPen Institute of Technology is prohibited.
#include "Math/Quaternion.hxx"
#include "Math/Ray.hxx"
#include "Engine/GenericHandle.hxx"
#include "Math/SHColour.h"
#include "Graphics/Color.hxx"
namespace SHADE
{
@ -104,6 +106,17 @@ namespace SHADE
/// <param name="vec">The native Vector2 to convert from.</param>
/// <returns>Managed copy of a native Vector2.</returns>
static Ray ToCLI(const SHRay& vec);
/// Converts from a managed Color to a native Colour.
/// </summary>
/// <param name="vec">The managed Color to convert from.</param>
/// <returns>Native copy of a managed Color.</returns>
static SHColour ToNative(Color col);
/// <summary>
/// Converts from a native Colour to a managed Color.
/// </summary>
/// <param name="vec">The native Colour to convert from.</param>
/// <returns>Managed copy of a native Colour.</returns>
static Color ToCLI(const SHColour& vec);
/*-----------------------------------------------------------------------------*/
/* String Conversions */