Merge branch 'main' of https://github.com/scorpioblood/PhanesEngine
This commit is contained in:
commit
13cecc8f97
407
.gitignore
vendored
407
.gitignore
vendored
@ -1,7 +1,404 @@
|
||||
# Directories
|
||||
.vs/
|
||||
bin/
|
||||
bin-int/
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
#Files
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||
*.vbp
|
||||
|
||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||
*.dsw
|
||||
*.dsp
|
||||
|
||||
# Visual Studio 6 technical files
|
||||
*.ncb
|
||||
*.aps
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# Visual Studio History (VSHistory) files
|
||||
.vshistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
# Exclude other vs files
|
||||
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.filters
|
@ -1,148 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{246c9c0b-21bd-4c7e-b6b7-7dec3ba5e59f}</ProjectGuid>
|
||||
<RootNamespace>DevPlayground</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)bin\$(Configuration)-$(Platform)\$(Projectname)\</OutDir>
|
||||
<IntDir>$(SolutionDir)bin-int\$(Configuration)-$(Platform)\$(Projectname)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>P_WIN_BUILD;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)PhanesEngine\src\Runtime;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>$(SolutionDir)bin\$(Configuration)-$(Platform)\PhanesEngine\PhanesEngine.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>P_WIN_BUILD;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)PhanesEngine\src\Runtime;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PhanesEngine\PhanesEngine.vcxproj">
|
||||
<Project>{a884925e-3ec8-48b0-92e5-99ab92647465}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="DevPlayground.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="DevPlayground.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
30
Engine/src/Runtime/Core/Core.h
Normal file
30
Engine/src/Runtime/Core/Core.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#ifdef P_WIN_BUILD
|
||||
|
||||
#ifdef P_DEBUG
|
||||
|
||||
#define P_DEBUGBREAK DebugBreak();
|
||||
|
||||
#else
|
||||
|
||||
#define P_DEBUGBREAK
|
||||
|
||||
#endif // P_DEBUG
|
||||
|
||||
#define FORCEINLINE __forceinline
|
||||
|
||||
#elif defined(P_UNIX_BUILD)
|
||||
|
||||
#error Only Windows is supported at the moment.
|
||||
|
||||
#elif defined(P_ARM_BUILD)
|
||||
|
||||
#error Only Windows is supported at the moment.
|
||||
|
||||
#else
|
||||
|
||||
#error The target system must be defined. (See https://github.com/scorpioblood/PhanesEngine for more information)
|
||||
|
||||
#endif // P_WIN_BUILD
|
41
Engine/src/Runtime/Core/Include.h
Normal file
41
Engine/src/Runtime/Core/Include.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef P_USE_NAMESPACES
|
||||
|
||||
using namespace Phanes::Core::Math::Literals;
|
||||
|
||||
// Starting point
|
||||
namespace PApp = Phanes::Core::Application;
|
||||
|
||||
|
||||
// Math
|
||||
namespace PMath = Phanes::Core::Math;
|
||||
namespace PMathInternal = Phanes::Core::Math::Internal;
|
||||
|
||||
|
||||
// OSAL
|
||||
namespace PTypes = Phanes::Core::Types
|
||||
|
||||
#endif
|
||||
|
||||
// --- Starting point ------------------------------
|
||||
|
||||
#include "Core/public/StartingPoint/StartingPoint.h"
|
||||
#include "Core/public/StartingPoint/EntryPoint.h"
|
||||
|
||||
// --- Math ----------------------------------------
|
||||
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathTypeConversion.h"
|
||||
#include "Core/public/Math/MathUnitConversion.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
#include "Core/public/Math/Vector2.h"
|
||||
#include "Core/public/Math/Vector3.h"
|
||||
|
||||
#include "Core/public/Math/IntVector2.h"
|
||||
#include "Core/public/Math/IntVector3.h"
|
||||
|
||||
// --- OSAL ----------------------------------------
|
||||
|
||||
#include "Core/public/OSAL/PlatformTypes.h"
|
22
Engine/src/Runtime/Core/private/Math/IntPoint.cpp
Normal file
22
Engine/src/Runtime/Core/private/Math/IntPoint.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/IntPoint.h"
|
||||
|
||||
|
||||
|
||||
// ----- TIntPoint2 ------------------------------------------
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Phanes::Core::Math::Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2)
|
||||
{
|
||||
return Magnitude(p2 - p1);
|
||||
}
|
||||
|
||||
// ----- TIntPoint3 ------------------------------------------
|
||||
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Phanes::Core::Math::Distance(const TIntPoint3<T>& p1, const TIntPoint3<T>& p2)
|
||||
{
|
||||
return Magnitude(p2 - p1);
|
||||
}
|
461
Engine/src/Runtime/Core/private/Math/IntVector2.cpp
Normal file
461
Engine/src/Runtime/Core/private/Math/IntVector2.cpp
Normal file
@ -0,0 +1,461 @@
|
||||
// ============================== //
|
||||
// TIntVector2 implementation //
|
||||
// ============================== //
|
||||
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/IntVector2.h"
|
||||
|
||||
#include "Core/public/Math/IntPoint.h"
|
||||
|
||||
//#include "Math/Matrix2.h"
|
||||
//#include "Math/Matrix2.h"
|
||||
//#include "Math/Vector3.h"
|
||||
//#include "Math/Vector4.h"
|
||||
//#include "Math/IntVector2.h"
|
||||
//#include "Math/IntVector3.h"
|
||||
//#include "Math/IntVector4.h"
|
||||
|
||||
|
||||
// ============================ //
|
||||
// TIntVector2 constructors //
|
||||
// ============================ //
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const T x, const T y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const T* comp)
|
||||
{
|
||||
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (IntVector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components.");
|
||||
memcpy(this->comp, comp, sizeof(T) * 2);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntPoint2<T>& start, const TIntPoint2<T>& end)
|
||||
{
|
||||
this->x = end.x - start.x;
|
||||
this->y = end.y - start.y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector3<T>& v)
|
||||
{
|
||||
this->x = v.x;
|
||||
this->y = v.y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector2<T>& v)
|
||||
{
|
||||
memcpy(this->comp, comp, sizeof(T) * 2);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T>::TIntVector2(TIntVector2<T>&& v)
|
||||
{
|
||||
this->comp = v.comp;
|
||||
v.comp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
// ========================= //
|
||||
// TIntVector2 operators //
|
||||
// ========================= //
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, T s)
|
||||
{
|
||||
v1.x += s;
|
||||
v1.y += s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
v1.x += v2.x;
|
||||
v1.y += v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, T s)
|
||||
{
|
||||
v1.x -= s;
|
||||
v1.y -= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
v1.x -= v2.x;
|
||||
v1.y -= v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*=(TIntVector2<T>& v1, T s)
|
||||
{
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*(const TIntVector2<T>& v1, T s)
|
||||
{
|
||||
return TIntVector2<T>(v1.x * s, v1.y * s);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
inline Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*(T s, const TIntVector2<T>& v1)
|
||||
{
|
||||
return v1 * s;
|
||||
}
|
||||
|
||||
template<IntType T, IntType Rt>
|
||||
Rt Phanes::Core::Math::operator* (const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+(const TIntVector2<T>& v1, T s)
|
||||
{
|
||||
return TIntVector2<T>(v1.x + s, v1.y + s);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return TIntVector2<T>(v1.x + v2.x, v1.y + v2.y);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-(const TIntVector2<T>& v1, T s)
|
||||
{
|
||||
return TIntVector2<T>(v1.x - s, v1.y - s);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return TIntVector2<T>(v1.x - v2.x, v1.y - v2.y);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
void Phanes::Core::Math::operator-(TIntVector2<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::operator== (const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::operator!=(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC);
|
||||
}
|
||||
|
||||
template<IntType T, IntType Rt>
|
||||
Rt Phanes::Core::Math::Magnitude(const TIntVector2<T>& v1)
|
||||
{
|
||||
return sqrtf(v1.x * v1.x + v1.y * v1.y);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::SqrMagnitude(const TIntVector2<T>& v1)
|
||||
{
|
||||
return v1.x * v1.x + v1.y * v1.y;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTruncV(TIntVector2<T>& v1, T s)
|
||||
{
|
||||
Rt _s = (Rt)1.0 / s;
|
||||
|
||||
v1.x = trunc(v1.x * s);
|
||||
v1.y = trunc(v1.y * s);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Phanes::Core::Math::Angle(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2));
|
||||
}
|
||||
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Phanes::Core::Math::CosineAngle(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return (v1 * v2) / Magnitude(v1) * Magnitude(v2);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVectorV(TIntVector2<T>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) ? 1 : -1;
|
||||
v1.y = (v1.y > 0) ? 1 : -1;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::DotP(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::MaxV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
|
||||
v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::MinV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
|
||||
v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicularV(TIntVector2<T>& v1)
|
||||
{
|
||||
T x = v1.x;
|
||||
v1.x = v1.y;
|
||||
v1.y = -v1.x;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TIntVector2<T>& v1)
|
||||
{
|
||||
T x = v1.x;
|
||||
v1.x = -v1.y;
|
||||
v1.y = v1.x;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::ScaleV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
v1.x *= v2.x;
|
||||
v1.y *= v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
v1 = v2;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, T x, T y)
|
||||
{
|
||||
v1.x = x;
|
||||
v1.y = y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::NegateV(TIntVector2<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
inline bool Phanes::Core::Math::IsNormalized(const TIntVector2<T>& v1)
|
||||
{
|
||||
return (SqrMagnitude(v1));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
inline bool Phanes::Core::Math::IsPerpendicular(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) = 0);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
inline bool Phanes::Core::Math::IsParallel(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) = 1);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
inline bool Phanes::Core::Math::IsCoincident(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) > 1);
|
||||
}
|
||||
|
||||
//
|
||||
//Phanes::Core::Math::Matrix2 Phanes::Core::Math::OuterProduct(const TIntVector2& v1, const TIntVector2& v2)
|
||||
//{
|
||||
// return Matrix2(
|
||||
// v1.x * v2.x, v1.x * v2.y,
|
||||
// v1.y * v2.x, v1.y * v2.y
|
||||
// );
|
||||
//}
|
||||
|
||||
// ================================================================= //
|
||||
// TIntVector2 static function implementation with return values //
|
||||
// ================================================================= //
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Reflect(const TIntVector2<T>& v1, const TVector2<Rt>& normal)
|
||||
{
|
||||
return TVector2<Rt>(v1 - (2 * (v1 * normal) * normal));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Scale(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return TIntVector2<T>(v1.x * v2.x, v1.y * v2.y);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::CompInverse(const TIntVector2<T>& v1)
|
||||
{
|
||||
return TVector2<T>(1.0f / v1.x, 1.0f / v1.y);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Negate(const TIntVector2<T>& v1)
|
||||
{
|
||||
return TIntVector2<T>(-v1.x, -v1.y);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicular(const TIntVector2<T>& v1)
|
||||
{
|
||||
return TIntVector2<T>(v1.y, -v1.x);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicular(const TIntVector2<T>& v1)
|
||||
{
|
||||
return TIntVector2<T>(-v1.y, v1.x);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Min(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return TIntVector2<T>(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Max(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
|
||||
{
|
||||
return TIntVector2<T>(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y));
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Normalize(const TIntVector2<T>& v1)
|
||||
{
|
||||
float vecNorm = Magnitude(v1);
|
||||
return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::UnsafeNormalize(const TIntVector2<T>& v1)
|
||||
{
|
||||
return TVector2(v1 / Magnitude(v1));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVector(const TIntVector2<T>& v1)
|
||||
{
|
||||
return TIntVector2<T>((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::BindToSquare(const TIntVector2<T>& v1, T radius)
|
||||
{
|
||||
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
|
||||
return v1 * k;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::ClampToSquare(const TIntVector2<T>& v1, T radius)
|
||||
{
|
||||
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
|
||||
float k = (prime > radius) ? abs(radius / prime) : 1.0f;
|
||||
|
||||
return TVector2(v1 * k);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Lerp(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t)
|
||||
{
|
||||
t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0);
|
||||
|
||||
return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::LerpUnclamped(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t)
|
||||
{
|
||||
return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Rotate(const TIntVector2<T>& v1, Rt angle)
|
||||
{
|
||||
float sinAngle = sin(angle);
|
||||
float cosAngle = cos(angle);
|
||||
|
||||
return TVector2<Rt>((Rt)v1.x * cosAngle - (Rt)v1.y * sinAngle, (Rt)v1.y * cosAngle + (Rt)v1.x * sinAngle);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::ClockwiseRotate(const TIntVector2<T>& v1, Rt angle)
|
||||
{
|
||||
return Rotate(v1, -angle);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTrunc(const TIntVector2<T>& v1, T s)
|
||||
{
|
||||
Rt _s = (Rt)1.0 / s;
|
||||
return TIntVector2<T>(trunc(v1.x * _s), trunc(v1.y * _s));
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::DivideFloat(const TIntVector2<T>& v1, T s)
|
||||
{
|
||||
Rt _s = (Rt)1.0 / s;
|
||||
return TIntVector2<T>((Rt)v1.x * _s, (Rt)v1.y * _s);
|
||||
}
|
516
Engine/src/Runtime/Core/private/Math/IntVector3.cpp
Normal file
516
Engine/src/Runtime/Core/private/Math/IntVector3.cpp
Normal file
@ -0,0 +1,516 @@
|
||||
// ============================== //
|
||||
// TIntVector2 implementation //
|
||||
// ============================== //
|
||||
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/IntVector3.h"
|
||||
|
||||
#include "Core/public/Math/IntPoint.h"
|
||||
#include "Core/public/Math/Plane.h"
|
||||
|
||||
|
||||
template<IntType T>
|
||||
inline Phanes::Core::Math::TIntVector3<T>::TIntVector3(const T x, const T y, const T z)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T>::TIntVector3(const T* comp)
|
||||
{
|
||||
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (IntVector3.cpp): Setting 3D vector coordinates by an array, comp must have a size of at least 3 components.");
|
||||
memcpy(this->comp, comp, sizeof(T) * 3);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T>::TIntVector3(const TIntVector2<T>& v)
|
||||
{
|
||||
this->x = v.x;
|
||||
this->y = v.y;
|
||||
this->z = (T)0;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T>::TIntVector3(const TIntPoint3<T>& start, const TIntPoint3<T>& end)
|
||||
{
|
||||
this->x = end.x - start.x;
|
||||
this->y = end.y - start.y;
|
||||
this->z = end.z - start.z;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T>::TIntVector3(const TIntVector3<T>& v)
|
||||
{
|
||||
memcpy(this->comp, comp, sizeof(T) * 3);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T>::TIntVector3(TIntVector3<T>&& v)
|
||||
{
|
||||
this->comp = v.comp;
|
||||
v.comp = nullptr;
|
||||
}
|
||||
|
||||
// ========================= //
|
||||
// TIntVector3 operators //
|
||||
// ========================= //
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator+=(TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x += s;
|
||||
v1.y += s;
|
||||
v1.z += s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator+=(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x += v2.x;
|
||||
v1.y += v2.y;
|
||||
v1.z += v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator-=(TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x -= s;
|
||||
v1.y -= s;
|
||||
v1.z -= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator-=(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x -= v2.x;
|
||||
v1.y -= v2.y;
|
||||
v1.z -= v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator*=(TIntVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
v1.z *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator*(const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
return TIntVector3<T>(v1.x * s.v1.y * s, v1.z * s);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator*(T s, const TIntVector3<T>& v1)
|
||||
{
|
||||
return v1 * s;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::operator*(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator+(const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
return TIntVector3<T>(v1.x + s.v1.y + s, v1.z + s);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator+(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator-(const TIntVector3<T>& v1, T s)
|
||||
{
|
||||
return TIntVector3<T>(v1.x - s.v1.y - s, v1.z - s);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator-(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::operator-(TIntVector3<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
v1.z = -v1.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::operator==(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v2.x) < P_FLT_INAC && abs(v1.y - v2.y) < P_FLT_INAC && abs(v1.z - v2.z) < P_FLT_INAC);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::operator!=(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v2.x) > P_FLT_INAC || abs(v1.y - v2.y) > P_FLT_INAC || abs(v1.z - v2.z) > P_FLT_INAC);
|
||||
}
|
||||
|
||||
// ======================================= //
|
||||
// TIntVector3 function implementation //
|
||||
// ======================================= //
|
||||
|
||||
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Phanes::Core::Math::Magnitude(const TIntVector3<T>& v1)
|
||||
{
|
||||
return sqrt(DotP(v1, v1));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::SqrMagnitude(const TIntVector3<T>& v1)
|
||||
{
|
||||
return DotP(v1, v1);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Phanes::Core::Math::Angle(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2)));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::DotP(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::VectorTriple(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
{
|
||||
return CrossP(CrossP(v1, v2), v3);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::SignVector(const TIntVector3<T>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) - (v1.x < 0);
|
||||
v1.y = (v1.y > 0) - (v1.y < 0);
|
||||
v1.z = (v1.z > 0) - (v1.z < 0);
|
||||
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::Equals(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold);
|
||||
}
|
||||
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::CrossPV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
float x = v1.x;
|
||||
float y = v1.y;
|
||||
float z = v1.z;
|
||||
|
||||
v1.x = (y * v2.z) - (z * v2.y);
|
||||
v1.y = (z * v2.x) - (x * v2.z);
|
||||
v1.z = (x * v2.y) - (y * v2.x);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::MaxV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x = Max(v1.x, v2.x);
|
||||
v1.y = Max(v1.y, v2.y);
|
||||
v1.z = Max(v1.z, v2.z);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::MinV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x = Min(v1.x, v2.x);
|
||||
v1.y = Min(v1.y, v2.y);
|
||||
v1.z = Min(v1.z, v2.z);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::NegateV(TIntVector3<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
v1.z = -v1.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::ScaleV(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1.x *= v2.x;
|
||||
v1.y *= v2.y;
|
||||
v1.z *= v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::Set(TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
v1 = v2;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::Set(TIntVector3<T>& v1, T x, T y, T z)
|
||||
{
|
||||
v1.x = x;
|
||||
v1.y = y;
|
||||
v1.z = z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::SignVectorV(TIntVector3<T>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) ? 1 : 0;
|
||||
v1.y = (v1.y > 0) ? 1 : 0;
|
||||
v1.z = (v1.z > 0) ? 1 : 0;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::ScalarTriple(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
{
|
||||
return CrossP(v1, v2) * v3;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
T Phanes::Core::Math::CosineAngle(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return (v1 * v2) / (Magnitude(v1) * Magnitude(v2));
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::VectorTripleV(TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3)
|
||||
{
|
||||
CrossPV(CrossPV(v1, v2), v3);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::IsPerpendicular(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) < threshold);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::IsParallel(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) > threshold);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::IsCoincident(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (DotP(v1, v2) > threshold);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::IsNormalized(const TIntVector3<T>& v1, T threshold)
|
||||
{
|
||||
return (SqrMagnitude(v1) < threshold);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
bool Phanes::Core::Math::IsCoplanar(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3, T threshold)
|
||||
{
|
||||
return (ScalarTriple(v1, v2, v3) < threshold);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =============== //
|
||||
// With Return //
|
||||
// =============== //
|
||||
|
||||
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::Normalize(const TIntVector3<T>& v1)
|
||||
{
|
||||
float vecNorm = Magnitude(v1);
|
||||
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::UnsafeNormalize(const TIntVector3<T>& v1)
|
||||
{
|
||||
return v1 / Magnitude(v1);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::Reflect(const TIntVector3<T>& v1, const TVector3<Rt>& normal)
|
||||
{
|
||||
return v1 - (2 * (v1 * normal) * normal);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::PerspectiveDivide(const TIntVector3<T>& v1)
|
||||
{
|
||||
float _z = (T)1.0 / v1.z;
|
||||
return TIntVector3<T>(v1.x * _z, v1.y * _z, (T)0.0);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::CrossP(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>((v1.y * v2.z) - (v1.z * v2.y),
|
||||
(v1.z * v2.x) - (v1.x * v2.z),
|
||||
(v1.x * v2.y) - (v1.y * v2.x));
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::Lerp(const TIntVector3<T>& start, const TIntVector3<T>& dest, Rt t)
|
||||
{
|
||||
t = Clamp(t, (Rt)0.0, (Rt), 1.0);
|
||||
return ((Rt)1.0 - t) * start + t * dest;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::LerpUnclamped(const TIntVector3<T>& start, const TIntVector3<T>& dest, Rt t)
|
||||
{
|
||||
return (1 - t) * start + t * dest;
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::Max(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>((v1.x > v2.x) ? v1.x : v2.x,
|
||||
(v1.y > v2.y) ? v1.y : v2.y,
|
||||
(v1.z > v2.z) ? v1.z : v2.z);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::Min(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>((v1.x < v2.x) ? v1.x : v2.x,
|
||||
(v1.y < v2.y) ? v1.y : v2.y,
|
||||
(v1.z < v2.z) ? v1.z : v2.z);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::Negate(const TIntVector3<T>& v1)
|
||||
{
|
||||
return TIntVector3<T>(-v1.x, -v1.y, -v1.z);
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
Phanes::Core::Math::TIntVector3<T> Phanes::Core::Math::Scale(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return TIntVector3<T>(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::ClampMagnitude(const TIntVector3<T>& v1, T min, T max)
|
||||
{
|
||||
Rt magnitude = Magnitude(v1);
|
||||
|
||||
const TVector3<Rt> unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T);
|
||||
|
||||
Clamp(magnitude, min, max);
|
||||
|
||||
return unitVec * magnitude;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::ScaleToMagnitude(const TIntVector3<T>& v1, T magnitude)
|
||||
{
|
||||
NormalizeV(v1) *= magnitude;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::CompInverse(const TIntVector3<T>& v1)
|
||||
{
|
||||
return TIntVector3<T>((Rt)1.0 / v1.x, (Rt)1.0 / v1.y, (Rt)1.0 / v1.z);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::ReflectFromPlane(const TIntVector3<T>& v1, const TPlane<Rt>& plane)
|
||||
{
|
||||
return Reflect(v1, plane.normal);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::ReflectFromPlane(const TIntVector3<T>& v1, const TVector3<Rt>& normal)
|
||||
{
|
||||
return Reflect(v1, normal);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::RotateAroundAxis(const TIntVector3<T>& v1, const TVector3<Rt>& axisNormal, Rt angle)
|
||||
{
|
||||
T sinAngle = sin(angle);
|
||||
T cosAngle = cos(angle);
|
||||
|
||||
return ((Rt)1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::Project(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) / DotP(v2, v2)) * v2;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::Reject(const TIntVector3<T>& v1, const TIntVector3<T>& v2)
|
||||
{
|
||||
return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2;
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::ProjectOntoPlane(const TIntVector3<T>& v1, const TVector3<Rt>& normal)
|
||||
{
|
||||
return Reject(v1, normal);
|
||||
}
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Phanes::Core::Math::TVector3<Rt> Phanes::Core::Math::ProjectOntoPlane(const TIntVector3<T>& v1, const TPlane<Rt>& plane)
|
||||
{
|
||||
return Reject(v1, plane.normal);
|
||||
}
|
57
Engine/src/Runtime/Core/private/Math/MathCommon.cpp
Normal file
57
Engine/src/Runtime/Core/private/Math/MathCommon.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
|
||||
#include "Core/public/OSAL/PlatformTypes.h"
|
||||
|
||||
// NOTE: oneline if statments are much faster than the max / min algorithm or expanded if's (64.519 ms per 1 000 000 operations)
|
||||
|
||||
template<typename T>
|
||||
T Phanes::Core::Math::Clamp(T value, T low, T high)
|
||||
{
|
||||
if (value < low) value = low;
|
||||
if (value > high) value = high;
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Phanes::Core::Math::Max(T x, T y)
|
||||
{
|
||||
return (x > y) ? x : y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Phanes::Core::Math::Min(T x, T y)
|
||||
{
|
||||
return (x < y) ? x : y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Phanes::Core::Math::Swap(T& x, T& y)
|
||||
{
|
||||
float z = x;
|
||||
x = y;
|
||||
y = z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Phanes::Core::Math::Equals(T x, T y, T threshold)
|
||||
{
|
||||
if (abs(x - y) < threshold) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
float Phanes::Core::Math::FastInvSqrt(T n)
|
||||
{
|
||||
Phanes::Core::Types::int32 i = * ( int * ) &n;
|
||||
float x2 = n * 0.5f;
|
||||
|
||||
i = 0x5f3759df - (i >> 1);
|
||||
n = * ( float * ) &i;
|
||||
n = n * (1.5f - (x2 * n * n));
|
||||
|
||||
return n;
|
||||
}
|
48
Engine/src/Runtime/Core/private/Math/MathTypeConversion.cpp
Normal file
48
Engine/src/Runtime/Core/private/Math/MathTypeConversion.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "PhanesEnginePCH.h"
|
||||
#include "Core/public/Math/MathTypeConversion.h"
|
||||
|
||||
// ============ //
|
||||
// ToString //
|
||||
// ============ //
|
||||
|
||||
template<RealType T>
|
||||
std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector2<T>& v) {
|
||||
return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")";
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
std::string Phanes::Core::Math::ToString(const TIntVector2<T>& v)
|
||||
{
|
||||
return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")";
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector3<T>& v) {
|
||||
return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ")";
|
||||
}
|
||||
|
||||
template<IntType T>
|
||||
std::string Phanes::Core::Math::ToString(const TIntVector3<T>& v)
|
||||
{
|
||||
std::to_string(3);
|
||||
|
||||
return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ")";
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//std::string Phanes::Core::Math::ToString(const Vector4& v)
|
||||
//{
|
||||
// return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ", " + std::to_string(v.w) + ")";
|
||||
//}
|
||||
//
|
||||
//template<typename T>
|
||||
//std::string Phanes::Core::Math::ToString(const Matrix2& v)
|
||||
//{
|
||||
// return std::to_string(v(0,0)) + " | " + std::to_string(v(0,1)) + "\n" + std::to_string(v(1,0)) + " | " + std::to_string(v(1,1));
|
||||
//}
|
||||
//
|
||||
//template<typename T>
|
||||
//std::string Phanes::Core::Math::ToString(const Matrix3& v)
|
||||
//{
|
||||
// return std::to_string(v(0, 0)) + " | " + std::to_string(v(0, 1)) + " | " + std::to_string(v(0, 2)) + "\n" + std::to_string(v(1, 0)) + " | " + std::to_string(v(1, 1)) + " | " + std::to_string(v(1, 2)) + "\n" + std::to_string(v(2, 0)) + " | " + std::to_string(v(2, 1)) + " | " + std::to_string(v(2, 2));
|
||||
//}
|
39
Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp
Normal file
39
Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/MathUnitConversion.h"
|
||||
|
||||
template<RealType T>
|
||||
inline T Phanes::Core::Math::UnitConversion::DegToRad(T deg)
|
||||
{
|
||||
return deg * P_PI_180_FLT;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline T Phanes::Core::Math::UnitConversion::RadToDeg(T rad)
|
||||
{
|
||||
return rad * P_180_PI_FLT;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline T Phanes::Core::Math::UnitConversion::DegToGradian(T deg)
|
||||
{
|
||||
return deg * 1.111111f;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline T Phanes::Core::Math::UnitConversion::GradianToDeg(T g)
|
||||
{
|
||||
return g * 0.9f;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline T Phanes::Core::Math::UnitConversion::RadToGradian(T rad)
|
||||
{
|
||||
return rad * 200 / P_PI_FLT;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline T Phanes::Core::Math::UnitConversion::GradianToRad(T g)
|
||||
{
|
||||
return g * P_PI_FLT / 200;
|
||||
}
|
237
Engine/src/Runtime/Core/private/Math/Matrix2.cpp
Normal file
237
Engine/src/Runtime/Core/private/Math/Matrix2.cpp
Normal file
@ -0,0 +1,237 @@
|
||||
// =========================== //
|
||||
// Matrix2D implementation //
|
||||
// =========================== //
|
||||
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Matrix2.h"
|
||||
|
||||
#pragma warning(disable : 4172)
|
||||
|
||||
// ================================= //
|
||||
// Class Methods for easy access //
|
||||
// ================================= //
|
||||
|
||||
float& phanes::core::math::coretypes::Matrix2::operator()(int n, int m)
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
const float& phanes::core::math::coretypes::Matrix2::operator()(int n, int m) const
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector2& phanes::core::math::coretypes::Matrix2::operator[](int m)
|
||||
{
|
||||
return (*reinterpret_cast<Vector2*>(this->fields[m]));
|
||||
}
|
||||
|
||||
const phanes::core::math::coretypes::Vector2& phanes::core::math::coretypes::Matrix2::operator[](int m) const
|
||||
{
|
||||
return (*reinterpret_cast<const Vector2*>(this->fields[m]));
|
||||
}
|
||||
|
||||
|
||||
// ================= //
|
||||
// Constructors //
|
||||
// ================= //
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::createMatrix(float fields[2][2])
|
||||
{
|
||||
Matrix2 a;
|
||||
std::copy(&fields[0][0], &fields[2][2], &a.fields[0][0]);
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::createMatrix(float f00, float f01, float f10, float f11)
|
||||
{
|
||||
Matrix2 a;
|
||||
a.fields[0][0] = f00; a.fields[1][0] = f01;
|
||||
a.fields[0][1] = f10; a.fields[1][1] = f11;
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::createMatrix(const Vector2& a, const Vector2& b)
|
||||
{
|
||||
Matrix2 m;
|
||||
m.fields[0][0] = a.x; m.fields[1][0] = b.x;
|
||||
m.fields[0][1] = a.y; m.fields[1][1] = b.y;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// ============= //
|
||||
// Operators //
|
||||
// ============= //
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix2& a, float s)
|
||||
{
|
||||
a[0] += s;
|
||||
a[1] += s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
a[0] += b[0];
|
||||
a[1] += b[1];
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix2& a, float s)
|
||||
{
|
||||
a[0] -= s;
|
||||
a[1] -= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
a[0] -= b[0];
|
||||
a[1] -= b[1];
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix2& a, float s)
|
||||
{
|
||||
a[0] *= s;
|
||||
a[1] *= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
Matrix2 c = a;
|
||||
|
||||
a(0, 0) = c(0, 0) * b(0, 0) + c(0, 1) * b(1, 0);
|
||||
a(0, 1) = c(0, 0) * b(0, 1) + c(0, 1) * b(1, 1);
|
||||
|
||||
a(1, 0) = c(1, 0) * b(0, 0) + c(1, 1) * b(1, 0);
|
||||
a(1, 1) = c(1, 0) * b(0, 1) + c(1, 1) * b(1, 1);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::operator+(const Matrix2& a, float s)
|
||||
{
|
||||
Matrix2 m;
|
||||
m[0] = a[0] + s;
|
||||
m[1] = a[1] + s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::operator+(const Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
Matrix2 m;
|
||||
m[0] = a[0] + b[0];
|
||||
m[1] = a[1] + b[1];
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::operator-(const Matrix2& a, float s)
|
||||
{
|
||||
Matrix2 m;
|
||||
m[0] = a[0] - s;
|
||||
m[1] = a[1] - s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::operator-(const Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
Matrix2 m;
|
||||
m[0] = a[0] - b[0];
|
||||
m[1] = a[1] - b[1];
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::operator*(const Matrix2& a, float s)
|
||||
{
|
||||
Matrix2 m;
|
||||
m[0] = a[0] * s;
|
||||
m[1] = a[1] * s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::operator*(const Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
Matrix2 m;
|
||||
|
||||
m(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0);
|
||||
m(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1);
|
||||
m(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0);
|
||||
m(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector2 phanes::core::math::coretypes::operator*(const Matrix2& a, const Vector2& v)
|
||||
{
|
||||
Vector2 b = createVector(
|
||||
a(0, 0) * v.x + a(0, 1) * v.y,
|
||||
a(1, 0) * v.x + a(1, 1) * v.y
|
||||
);
|
||||
return b;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Matrix2& a, const Matrix2& b)
|
||||
{
|
||||
if (a[0] == b[0] && a[1] == b[1]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float phanes::core::math::coretypes::determinant(const Matrix2& a)
|
||||
{
|
||||
return (a(0, 0) * a(1, 1)) - (a(0, 1) * a(1, 0));
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::inverseNR(Matrix2& a)
|
||||
{
|
||||
float& ref = a(0, 0);
|
||||
float b = ref;
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
a(0, 0) = a(1, 1);
|
||||
a(0, 1) = -a(0, 1);
|
||||
a(1, 0) = -a(1, 0);
|
||||
a(1, 1) = b;
|
||||
|
||||
a *= _1_det;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::transposeNR(Matrix2& a)
|
||||
{
|
||||
swap(a(0, 1), a(1, 0));
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::inverse(Matrix2& a)
|
||||
{
|
||||
Matrix2 m;
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
m(0, 0) = a(1, 1);
|
||||
m(0, 1) = -a(0, 1);
|
||||
m(1, 0) = -a(1, 0);
|
||||
m(1, 1) = a(0, 0);
|
||||
|
||||
m *= _1_det;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix2 phanes::core::math::coretypes::transpose(const Matrix2& a)
|
||||
{
|
||||
Matrix2 c;
|
||||
c(0, 0) = a(0, 0);
|
||||
c(1, 0) = a(0, 1);
|
||||
c(0, 1) = a(1, 0);
|
||||
c(1, 1) = a(1, 1);
|
||||
return c;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::isIndentityMatrix(const Matrix2& a)
|
||||
{
|
||||
|
||||
if (a == phanes::core::math::coretypes::createMatrix(1, 0, 0, 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
303
Engine/src/Runtime/Core/private/Math/Matrix3.cpp
Normal file
303
Engine/src/Runtime/Core/private/Math/Matrix3.cpp
Normal file
@ -0,0 +1,303 @@
|
||||
// ========================== //
|
||||
// Matrix3 implementation //
|
||||
// ========================== //
|
||||
|
||||
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Matrix3.h"
|
||||
|
||||
// ================================= //
|
||||
// Class Methods for easy access //
|
||||
// ================================= //
|
||||
|
||||
float& phanes::core::math::coretypes::Matrix3::operator()(int n, int m)
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector3& phanes::core::math::coretypes::Matrix3::operator[](int m)
|
||||
{
|
||||
return (*reinterpret_cast<Vector3*>(this->fields[m]));
|
||||
}
|
||||
|
||||
const float& phanes::core::math::coretypes::Matrix3::operator()(int n, int m) const
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
const phanes::core::math::coretypes::Vector3& phanes::core::math::coretypes::Matrix3::operator[](int m) const
|
||||
{
|
||||
return (*reinterpret_cast<const Vector3*>(this->fields[m]));
|
||||
}
|
||||
|
||||
|
||||
// ================= //
|
||||
// Constructors //
|
||||
// ================= //
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(float fields[3][3])
|
||||
{
|
||||
Matrix3 a;
|
||||
std::copy(&fields[0][0], &fields[3][3], &a.fields[0][0]);
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(float f00, float f01, float f02, float f10, float f11, float f12, float f20, float f21, float f22)
|
||||
{
|
||||
Matrix3 a;
|
||||
a.fields[0][0] = f00; a.fields[1][0] = f01; a.fields[2][0] = f02;
|
||||
a.fields[0][1] = f10; a.fields[1][1] = f11; a.fields[2][1] = f12;
|
||||
a.fields[0][2] = f20; a.fields[1][2] = f21; a.fields[2][2] = f22;
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(const Vector3& a, const Vector3& b, const Vector3& c)
|
||||
{
|
||||
Matrix3 m;
|
||||
m.fields[0][0] = a.x; m.fields[1][0] = b.x; m.fields[2][0] = c.x;
|
||||
m.fields[0][1] = a.y; m.fields[1][1] = b.y; m.fields[2][1] = c.y;
|
||||
m.fields[0][2] = a.z; m.fields[1][2] = b.z; m.fields[2][2] = c.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// ============= //
|
||||
// Operators //
|
||||
// ============= //
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix3& a, float s)
|
||||
{
|
||||
a[0] += s;
|
||||
a[1] += s;
|
||||
a[2] += s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
a[0] += b[0];
|
||||
a[1] += b[1];
|
||||
a[2] += b[2];
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix3& a, float s)
|
||||
{
|
||||
a[0] -= s;
|
||||
a[1] -= s;
|
||||
a[2] -= s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
a[0] -= b[0];
|
||||
a[1] -= b[1];
|
||||
a[2] -= b[2];
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix3& a, float s)
|
||||
{
|
||||
a[0] *= s;
|
||||
a[1] *= s;
|
||||
a[2] *= s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 c = a;
|
||||
a(0, 0) = c(0, 0) * b(0, 0) + c(0, 1) * b(1, 0) + c(0, 2) * b(2, 0);
|
||||
a(0, 1) = c(0, 0) * b(0, 1) + c(0, 1) * b(1, 1) + c(0, 2) * b(2, 1);
|
||||
a(0, 2) = c(0, 0) * b(0, 2) + c(0, 1) * b(1, 2) + c(0, 2) * b(2, 2);
|
||||
|
||||
a(1, 0) = c(1, 0) * b(0, 0) + c(1, 1) * b(1, 0) + c(1, 2) * b(2, 0);
|
||||
a(1, 1) = c(1, 0) * b(0, 1) + c(1, 1) * b(1, 1) + c(1, 2) * b(2, 1);
|
||||
a(1, 2) = c(1, 0) * b(0, 2) + c(1, 1) * b(1, 2) + c(1, 2) * b(2, 2);
|
||||
|
||||
a(2, 0) = c(2, 0) * b(0, 0) + c(2, 1) * b(1, 0) + c(2, 2) * b(2, 0);
|
||||
a(2, 1) = c(2, 0) * b(0, 1) + c(2, 1) * b(1, 1) + c(2, 2) * b(2, 1);
|
||||
a(2, 2) = c(2, 0) * b(0, 2) + c(2, 1) * b(1, 2) + c(2, 2) * b(2, 2);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator+(const Matrix3& a, float s)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] + s;
|
||||
m[1] = a[1] + s;
|
||||
m[2] = a[2] + s;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator+(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] + b[0];
|
||||
m[1] = a[1] + b[1];
|
||||
m[2] = a[2] + b[2];
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator-(const Matrix3& a, float s)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] - s;
|
||||
m[1] = a[1] - s;
|
||||
m[2] = a[2] - s;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator-(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] - b[0];
|
||||
m[1] = a[1] - b[1];
|
||||
m[2] = a[2] - b[2];
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator*(const Matrix3& a, float s)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] * s;
|
||||
m[1] = a[1] * s;
|
||||
m[2] = a[2] * s;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator*(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 m;
|
||||
|
||||
m(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0) + a(0, 2) * b(2, 0);
|
||||
m(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1) + a(0, 2) * b(2, 1);
|
||||
m(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2) * b(2, 2);
|
||||
|
||||
m(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0) + a(1, 2) * b(2, 0);
|
||||
m(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1) + a(1, 2) * b(2, 1);
|
||||
m(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2) * b(2, 2);
|
||||
|
||||
m(2, 0) = a(2, 0) * b(0, 0) + a(2, 1) * b(1, 0) + a(2, 2) * b(2, 0);
|
||||
m(2, 1) = a(2, 0) * b(0, 1) + a(2, 1) * b(1, 1) + a(2, 2) * b(2, 1);
|
||||
m(2, 2) = a(2, 0) * b(0, 2) + a(2, 1) * b(1, 2) + a(2, 2) * b(2, 2);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector3 phanes::core::math::coretypes::operator*(const Matrix3& a, const Vector3& v)
|
||||
{
|
||||
Vector3 b = createVector(
|
||||
a(0, 0) * v.x + a(0, 1) * v.y + a(0, 2) * v.z,
|
||||
a(1, 0) * v.x + a(1, 1) * v.y + a(1, 2) * v.z,
|
||||
a(2, 0) * v.x + a(2, 1) * v.y + a(2, 2) * v.z
|
||||
);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// =============================== //
|
||||
// Matrix function definition //
|
||||
// =============================== //
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::determinant(const Matrix3& a)
|
||||
{
|
||||
return (a(0, 0) * (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1))
|
||||
-a(0, 1) * (a(1, 0) * a(2, 2) - a(1, 2) * a(2, 0))
|
||||
+a(0, 2) * (a(1, 0) * a(2, 1) - a(1, 1) * a(2, 0)));
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::inverseNR(Matrix3& a)
|
||||
{
|
||||
const Vector3& v0 = a[0];
|
||||
const Vector3& v1 = a[1];
|
||||
const Vector3& v2 = a[2];
|
||||
|
||||
Vector3 r0 = crossP(v1, v2);
|
||||
Vector3 r1 = crossP(v2, v0);
|
||||
Vector3 r2 = crossP(v0, v1);
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
a = createMatrix(
|
||||
r0.x, r0.y, r0.z,
|
||||
r1.x, r1.y, r1.z,
|
||||
r2.x, r2.y, r2.z
|
||||
);
|
||||
|
||||
a *= _1_det;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::transposeNR(Matrix3& a)
|
||||
{
|
||||
swap(a(0, 1), a(1, 0));
|
||||
swap(a(0, 2), a(2, 0));
|
||||
swap(a(1, 2), a(2, 1));
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::inverse(Matrix3& a)
|
||||
{
|
||||
const Vector3& v0 = a[0];
|
||||
const Vector3& v1 = a[1];
|
||||
const Vector3& v2 = a[2];
|
||||
|
||||
Vector3 r0 = crossP(v1, v2);
|
||||
Vector3 r1 = crossP(v2, v0);
|
||||
Vector3 r2 = crossP(v0, v1);
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
Matrix3 m = createMatrix(
|
||||
r0.x, r0.y, r0.z,
|
||||
r1.x, r1.y, r1.z,
|
||||
r2.x, r2.y, r2.z
|
||||
);
|
||||
|
||||
m *= _1_det;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::transpose(const Matrix3& a)
|
||||
{
|
||||
Matrix3 m = createMatrix(
|
||||
a(0, 0), a(1, 0), a(2, 0),
|
||||
a(0, 1), a(1, 1), a(2, 1),
|
||||
a(0, 2), a(1, 2), a(2, 2)
|
||||
);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
bool phanes::core::math::coretypes::isIndentityMatrix(const Matrix3& a)
|
||||
{
|
||||
if (a == phanes::core::math::coretypes::createMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
347
Engine/src/Runtime/Core/private/Math/Matrix4.cpp
Normal file
347
Engine/src/Runtime/Core/private/Math/Matrix4.cpp
Normal file
@ -0,0 +1,347 @@
|
||||
// ========================== //
|
||||
// Matrix4 implementation //
|
||||
// ========================== //
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Matrix4.h"
|
||||
|
||||
#include "Math/Vector3.h"
|
||||
|
||||
|
||||
// ================================= //
|
||||
// Class Methods for easy access //
|
||||
// ================================= //
|
||||
|
||||
float& phanes::core::math::coretypes::Matrix4::operator()(int n, int m)
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4& phanes::core::math::coretypes::Matrix4::operator[](int m)
|
||||
{
|
||||
return (*reinterpret_cast<Vector4*>(this->fields[m]));
|
||||
}
|
||||
|
||||
const float& phanes::core::math::coretypes::Matrix4::operator()(int n, int m) const
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
const phanes::core::math::coretypes::Vector4& phanes::core::math::coretypes::Matrix4::operator[](int m) const
|
||||
{
|
||||
return (*reinterpret_cast<const Vector4*>(this->fields[m]));
|
||||
}
|
||||
|
||||
|
||||
// ================= //
|
||||
// Constructors //
|
||||
// ================= //
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::createMatrix(float fields[4][4])
|
||||
{
|
||||
Matrix4 a;
|
||||
std::copy(&fields[0][0], &fields[4][4], &a.fields[0][0]);
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::createMatrix(float f00, float f01, float f02, float f03, float f10, float f11, float f12, float f13, float f20, float f21, float f22, float f23, float f30, float f31, float f32, float f33)
|
||||
{
|
||||
Matrix4 a;
|
||||
a.fields[0][0] = f00; a.fields[1][0] = f01; a.fields[2][0] = f02; a.fields[3][0] = f03;
|
||||
a.fields[0][1] = f10; a.fields[1][1] = f11; a.fields[2][1] = f12; a.fields[3][1] = f13;
|
||||
a.fields[0][2] = f20; a.fields[1][2] = f21; a.fields[2][2] = f22; a.fields[3][2] = f23;
|
||||
a.fields[0][3] = f30; a.fields[1][3] = f31; a.fields[2][3] = f32; a.fields[3][3] = f33;
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::createMatrix(const Vector4& a, const Vector4& b, const Vector4& c, const Vector4& d)
|
||||
{
|
||||
Matrix4 m;
|
||||
m.fields[0][0] = a.x; m.fields[1][0] = b.x; m.fields[2][0] = c.x; m.fields[3][0] = d.x;
|
||||
m.fields[0][1] = a.y; m.fields[1][1] = b.y; m.fields[2][1] = c.y; m.fields[3][1] = d.y;
|
||||
m.fields[0][2] = a.z; m.fields[1][2] = b.z; m.fields[2][2] = c.z; m.fields[3][2] = d.z;
|
||||
m.fields[0][3] = a.w; m.fields[1][3] = b.w; m.fields[2][3] = c.w; m.fields[3][3] = d.w;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// ============= //
|
||||
// Operators //
|
||||
// ============= //
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix4& a, float s)
|
||||
{
|
||||
a[0] += s;
|
||||
a[1] += s;
|
||||
a[2] += s;
|
||||
a[3] += s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
a[0] += b[0];
|
||||
a[1] += b[1];
|
||||
a[2] += b[2];
|
||||
a[3] += b[3];
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix4& a, float s)
|
||||
{
|
||||
a[0] -= s;
|
||||
a[1] -= s;
|
||||
a[2] -= s;
|
||||
a[3] -= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
a[0] -= b[0];
|
||||
a[1] -= b[1];
|
||||
a[2] -= b[2];
|
||||
a[3] -= b[3];
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix4& a, float s)
|
||||
{
|
||||
a[0] *= s;
|
||||
a[1] *= s;
|
||||
a[2] *= s;
|
||||
a[3] *= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 c = a;
|
||||
|
||||
a(0, 0) = c(0, 0) * b(0, 0) + c(0, 1) * b(1, 0) + c(0, 2) * b(2, 0) + c(0, 3) * b(3, 0);
|
||||
a(0, 1) = c(0, 0) * b(0, 1) + c(0, 1) * b(1, 1) + c(0, 2) * b(2, 1) + c(0, 3) * b(3, 1);
|
||||
a(0, 2) = c(0, 0) * b(0, 2) + c(0, 1) * b(1, 2) + c(0, 2) * b(2, 2) + c(0, 3) * b(3, 2);
|
||||
a(0, 3) = c(0, 0) * b(0, 3) + c(0, 1) * b(1, 3) + c(0, 2) * b(2, 3) + c(0, 3) * b(3, 3);
|
||||
|
||||
a(1, 0) = c(1, 0) * b(0, 0) + c(1, 1) * b(1, 0) + c(1, 2) * b(2, 0) + c(1, 3) * b(3, 0);
|
||||
a(1, 1) = c(1, 0) * b(0, 1) + c(1, 1) * b(1, 1) + c(1, 2) * b(2, 1) + c(1, 3) * b(3, 1);
|
||||
a(1, 2) = c(1, 0) * b(0, 2) + c(1, 1) * b(1, 2) + c(1, 2) * b(2, 2) + c(1, 3) * b(3, 2);
|
||||
a(1, 3) = c(1, 0) * b(0, 3) + c(1, 1) * b(1, 3) + c(1, 2) * b(2, 3) + c(1, 3) * b(3, 3);
|
||||
|
||||
a(2, 0) = c(2, 0) * b(0, 0) + c(2, 1) * b(1, 0) + c(2, 2) * b(2, 0) + c(2, 3) * b(3, 0);
|
||||
a(2, 1) = c(2, 0) * b(0, 1) + c(2, 1) * b(1, 1) + c(2, 2) * b(2, 1) + c(2, 3) * b(3, 1);
|
||||
a(2, 2) = c(2, 0) * b(0, 2) + c(2, 1) * b(1, 2) + c(2, 2) * b(2, 2) + c(2, 3) * b(3, 2);
|
||||
a(2, 3) = c(2, 0) * b(0, 3) + c(2, 1) * b(1, 3) + c(2, 2) * b(2, 3) + c(2, 3) * b(3, 3);
|
||||
|
||||
a(3, 0) = c(3, 0) * b(0, 0) + c(3, 1) * b(1, 0) + c(3, 2) * b(2, 0) + c(3, 3) * b(3, 0);
|
||||
a(3, 1) = c(3, 0) * b(0, 1) + c(3, 1) * b(1, 1) + c(3, 2) * b(2, 1) + c(3, 3) * b(3, 1);
|
||||
a(3, 2) = c(3, 0) * b(0, 2) + c(3, 1) * b(1, 2) + c(3, 2) * b(2, 2) + c(3, 3) * b(3, 2);
|
||||
a(3, 3) = c(3, 0) * b(0, 3) + c(3, 1) * b(1, 3) + c(3, 2) * b(2, 3) + c(3, 3) * b(3, 3);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator+(const Matrix4& a, float s)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] + s;
|
||||
m[1] = a[1] + s;
|
||||
m[2] = a[2] + s;
|
||||
m[3] = a[3] + s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator+(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] + b[0];
|
||||
m[1] = a[1] + b[1];
|
||||
m[2] = a[2] + b[2];
|
||||
m[3] = a[3] + b[3];
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator-(const Matrix4& a, float s)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] - s;
|
||||
m[1] = a[1] - s;
|
||||
m[2] = a[2] - s;
|
||||
m[3] = a[3] - s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator-(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] - b[0];
|
||||
m[1] = a[1] - b[1];
|
||||
m[2] = a[2] - b[2];
|
||||
m[3] = a[3] - b[3];
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator*(const Matrix4& a, float s)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] * s;
|
||||
m[1] = a[1] * s;
|
||||
m[2] = a[2] * s;
|
||||
m[3] = a[3] * s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator*(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 m;
|
||||
|
||||
m(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0) + a(0, 2) * b(2, 0) + a(0, 3) * b(3, 0);
|
||||
m(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1) + a(0, 2) * b(2, 1) + a(0, 3) * b(3, 1);
|
||||
m(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2) * b(2, 2) + a(0, 3) * b(3, 2);
|
||||
m(0, 3) = a(0, 0) * b(0, 3) + a(0, 1) * b(1, 3) + a(0, 2) * b(2, 3) + a(0, 3) * b(3, 3);
|
||||
|
||||
m(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0) + a(1, 2) * b(2, 0) + a(1, 3) * b(3, 0);
|
||||
m(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1) + a(1, 2) * b(2, 1) + a(1, 3) * b(3, 1);
|
||||
m(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2) * b(2, 2) + a(1, 3) * b(3, 2);
|
||||
m(1, 3) = a(1, 0) * b(0, 3) + a(1, 1) * b(1, 3) + a(1, 2) * b(2, 3) + a(1, 3) * b(3, 3);
|
||||
|
||||
m(2, 0) = a(2, 0) * b(0, 0) + a(2, 1) * b(1, 0) + a(2, 2) * b(2, 0) + a(2, 3) * b(3, 0);
|
||||
m(2, 1) = a(2, 0) * b(0, 1) + a(2, 1) * b(1, 1) + a(2, 2) * b(2, 1) + a(2, 3) * b(3, 1);
|
||||
m(2, 2) = a(2, 0) * b(0, 2) + a(2, 1) * b(1, 2) + a(2, 2) * b(2, 2) + a(2, 3) * b(3, 2);
|
||||
m(2, 3) = a(2, 0) * b(0, 3) + a(2, 1) * b(1, 3) + a(2, 2) * b(2, 3) + a(2, 3) * b(3, 3);
|
||||
|
||||
m(3, 0) = a(3, 0) * b(0, 0) + a(3, 1) * b(1, 0) + a(3, 2) * b(2, 0) + a(3, 3) * b(3, 0);
|
||||
m(3, 1) = a(3, 0) * b(0, 1) + a(3, 1) * b(1, 1) + a(3, 2) * b(2, 1) + a(3, 3) * b(3, 1);
|
||||
m(3, 2) = a(3, 0) * b(0, 2) + a(3, 1) * b(1, 2) + a(3, 2) * b(2, 2) + a(3, 3) * b(3, 2);
|
||||
m(3, 3) = a(3, 0) * b(0, 3) + a(3, 1) * b(1, 3) + a(3, 2) * b(2, 3) + a(3, 3) * b(3, 3);
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator*(const Matrix4& a, const Vector4& v)
|
||||
{
|
||||
Vector4 b = createVector(
|
||||
a(0, 0) * v.x + a(0, 1) * v.y + a(0, 2) * v.z + a(0, 3) * v.w,
|
||||
a(1, 0) * v.x + a(1, 1) * v.y + a(1, 2) * v.z + a(1, 3) * v.w,
|
||||
a(2, 0) * v.x + a(2, 1) * v.y + a(2, 2) * v.z + a(2, 3) * v.w,
|
||||
a(3, 0) * v.x + a(3, 1) * v.y + a(3, 2) * v.z + a(3, 3) * v.w
|
||||
);
|
||||
return b;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// =============================== //
|
||||
// Matrix function definition //
|
||||
// =============================== //
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::determinant(const Matrix4& a)
|
||||
{
|
||||
Vector3 v0 = reinterpret_cast<const Vector3&>(a[0]);
|
||||
Vector3 v1 = reinterpret_cast<const Vector3&>(a[1]);
|
||||
Vector3 v2 = reinterpret_cast<const Vector3&>(a[2]);
|
||||
Vector3 v3 = reinterpret_cast<const Vector3&>(a[3]);
|
||||
|
||||
Vector3 s = crossP(v0, v1);
|
||||
Vector3 t = crossP(v2, v3);
|
||||
Vector3 u = a(3, 1) * v0 + a(3, 0) * v1;
|
||||
Vector3 v = a(3, 3) * v2 + a(3, 2) * v3;
|
||||
|
||||
return s * v + t * u;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::inverseNR(Matrix4& a)
|
||||
{
|
||||
Vector3 v0 = reinterpret_cast<const Vector3&>(a[0]);
|
||||
Vector3 v1 = reinterpret_cast<const Vector3&>(a[1]);
|
||||
Vector3 v2 = reinterpret_cast<const Vector3&>(a[2]);
|
||||
Vector3 v3 = reinterpret_cast<const Vector3&>(a[3]);
|
||||
|
||||
Vector3 s = crossP(v0, v1);
|
||||
Vector3 t = crossP(v2, v3);
|
||||
Vector3 u = a(3, 1) * v0 + a(3, 0) * v1;
|
||||
Vector3 v = a(3, 3) * v2 + a(3, 2) * v3;
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
Vector3 r0 = crossP(v1, v) + t * a(3, 1);
|
||||
Vector3 r1 = crossP(v, v0) - t * a(3, 0);
|
||||
Vector3 r2 = crossP(v3, u) + s * a(3, 3);
|
||||
Vector3 r3 = crossP(u, v2) - s * a(3, 2);
|
||||
|
||||
a = createMatrix(
|
||||
r0.x, r0.y, r0.z, -dotP(v1, t),
|
||||
r1.x, r1.y, r1.z, -dotP(v0, t),
|
||||
r2.x, r2.y, r2.z, -dotP(v3, s),
|
||||
r3.x, r3.y, r3.z, -dotP(v2, s)
|
||||
);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::transposeNR(Matrix4& a)
|
||||
{
|
||||
swap(a(0, 1), a(1, 0));
|
||||
swap(a(0, 2), a(2, 0));
|
||||
swap(a(0, 3), a(3, 0));
|
||||
|
||||
swap(a(1, 2), a(2, 1));
|
||||
swap(a(1, 3), a(3, 1));
|
||||
|
||||
swap(a(2, 3), a(3, 2));
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::inverse(Matrix4& a)
|
||||
{
|
||||
Vector3 v0 = reinterpret_cast<const Vector3&>(a[0]);
|
||||
Vector3 v1 = reinterpret_cast<const Vector3&>(a[1]);
|
||||
Vector3 v2 = reinterpret_cast<const Vector3&>(a[2]);
|
||||
Vector3 v3 = reinterpret_cast<const Vector3&>(a[3]);
|
||||
|
||||
Vector3 s = crossP(v0, v1);
|
||||
Vector3 t = crossP(v2, v3);
|
||||
Vector3 u = a(3, 1) * v0 + a(3, 0) * v1;
|
||||
Vector3 v = a(3, 3) * v2 + a(3, 2) * v3;
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
Vector3 r0 = crossP(v1, v) + t * a(3, 1);
|
||||
Vector3 r1 = crossP(v, v0) - t * a(3, 0);
|
||||
Vector3 r2 = crossP(v3, u) + s * a(3, 3);
|
||||
Vector3 r3 = crossP(u, v2) - s * a(3, 2);
|
||||
|
||||
Matrix4 m = createMatrix(
|
||||
r0.x, r0.y, r0.z, -dotP(v1, t),
|
||||
r1.x, r1.y, r1.z, -dotP(v0, t),
|
||||
r2.x, r2.y, r2.z, -dotP(v3, s),
|
||||
r3.x, r3.y, r3.z, -dotP(v2, s)
|
||||
);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::transpose(const Matrix4& a)
|
||||
{
|
||||
Matrix4 m = a;
|
||||
|
||||
swap(m(0, 1), m(1, 0));
|
||||
swap(m(0, 2), m(2, 0));
|
||||
swap(m(0, 3), m(3, 0));
|
||||
|
||||
swap(m(1, 2), m(2, 1));
|
||||
swap(m(1, 3), m(3, 1));
|
||||
|
||||
swap(m(2, 3), m(3, 2));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::isIndentityMatrix(const Matrix4& a)
|
||||
{
|
||||
if (a == phanes::core::math::coretypes::createMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
34
Engine/src/Runtime/Core/private/Math/Point.cpp
Normal file
34
Engine/src/Runtime/Core/private/Math/Point.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/Point.h"
|
||||
|
||||
#include "Core/public/Math/Vector2.h"
|
||||
#include "Core/public/Math/Vector3.h"
|
||||
// #include "Core/public/Math/Vector4.h"
|
||||
|
||||
|
||||
// ----- TPoint2 ------------------------------------------
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::Distance(const TPoint2<T>& p1, const TPoint2<T>& p2)
|
||||
{
|
||||
return Magnitude(p2 - p1);
|
||||
}
|
||||
|
||||
|
||||
// ----- TPoint3 ------------------------------------------
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::Distance(const TPoint3<T>& p1, const TPoint3<T>& p2)
|
||||
{
|
||||
return Magnitude(p2 - p1);
|
||||
}
|
||||
|
||||
|
||||
// ----- TPoint4 ------------------------------------------
|
||||
|
||||
//template<RealType T>
|
||||
//T Phanes::Core::Math::Distance(const TPoint4<T>& p1, const TPoint4<T>& p2)
|
||||
//{
|
||||
// return Magnitude(TVector3<T>(p1, p2));
|
||||
//}
|
570
Engine/src/Runtime/Core/private/Math/Vector2.cpp
Normal file
570
Engine/src/Runtime/Core/private/Math/Vector2.cpp
Normal file
@ -0,0 +1,570 @@
|
||||
// =========================== //
|
||||
// TVector2 implementation //
|
||||
// =========================== //
|
||||
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/Vector2.h"
|
||||
|
||||
#include "Core/public/Math/Point.h"
|
||||
|
||||
//#include "Math/Matrix2.h"
|
||||
//#include "Math/Matrix2.h"
|
||||
//#include "Math/Vector3.h"
|
||||
//#include "Math/Vector4.h"
|
||||
//#include "Math/IntVector2.h"
|
||||
//#include "Math/IntVector3.h"
|
||||
//#include "Math/IntVector4.h"
|
||||
|
||||
|
||||
// ========================= //
|
||||
// TVector2 constructors //
|
||||
// ========================= //
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T>::TVector2(const Real x, const Real y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T>::TVector2(const Real* comp)
|
||||
{
|
||||
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components.");
|
||||
memcpy(this->comp, comp, sizeof(T) * 2);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T>::TVector2(const TPoint2<Real>& start, const TPoint2<Real>& end)
|
||||
{
|
||||
this->x = end.x - start.x;
|
||||
this->y = end.y - start.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T>::TVector2(const TVector3<Real>& v)
|
||||
{
|
||||
this->x = v.x;
|
||||
this->y = v.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T>::TVector2(const TVector2<Real>& v)
|
||||
{
|
||||
memcpy(this->comp, comp, sizeof(T) * 2);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T>::TVector2(TVector2<Real>&& v)
|
||||
{
|
||||
this->comp = v.comp;
|
||||
v.comp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Phanes::Core::Math::TVector2::TVector2(const Vector3& v)
|
||||
//{
|
||||
// std::copy(v.components, v.components + 2, this->components);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Phanes::Core::Math::TVector2::TVector2(const Vector4& v)
|
||||
//{
|
||||
// std::copy(v.components, v.components + 2, this->components);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Phanes::Core::Math::TVector2::TVector2(const IntVector2& v)
|
||||
//{
|
||||
// std::copy(v.components, v.components + 2, this->components);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Phanes::Core::Math::TVector2::TVector2(const IntVector3& v)
|
||||
//{
|
||||
// std::copy(v.components, v.components + 2, this->components);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Phanes::Core::Math::TVector2::TVector2(const IntVector4& v)
|
||||
//{
|
||||
// std::copy(v.components, v.components + 2, this->components);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Phanes::Core::Math::TVector2::TVector2(const Point2& v)
|
||||
//{
|
||||
// std::copy(v.components, v.components + 2, this->components);
|
||||
//}
|
||||
|
||||
// ====================== //
|
||||
// TVector2 operators //
|
||||
// ====================== //
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, T s)
|
||||
{
|
||||
v1.x += s;
|
||||
v1.y += s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
v1.x += v2.x;
|
||||
v1.y += v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, T s)
|
||||
{
|
||||
v1.x -= s;
|
||||
v1.y -= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
v1.x -= v2.x;
|
||||
v1.y -= v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*=(TVector2<T>& v1, T s)
|
||||
{
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/=(TVector2<T>& v1, T s)
|
||||
{
|
||||
s = 1.0f / s;
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*(const TVector2<T>& v1, T s)
|
||||
{
|
||||
return TVector2<T>(v1.x * s, v1.y * s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(const TVector2<T>& v1, T s)
|
||||
{
|
||||
s = 1.0f / s;
|
||||
return TVector2<T>(v1.x * s, v1.y * s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*(T s, const TVector2<T>& v1)
|
||||
{
|
||||
return v1 * s;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(T s, const TVector2<T>& v1)
|
||||
{
|
||||
s = 1.0f / s;
|
||||
return v1 * s;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::operator* (const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+(const TVector2<T>& v1, T s)
|
||||
{
|
||||
return TVector2<T>(v1.x + s, v1.y + s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return TVector2<T>(v1.x + v2.x, v1.y + v2.y);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-(const TVector2<T>& v1, T s)
|
||||
{
|
||||
return TVector2<T>(v1.x - s, v1.y - s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return TVector2<T>(v1.x - v2.x, v1.y - v2.y);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
void Phanes::Core::Math::operator-(TVector2<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::operator== (const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::operator!=(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::Magnitude(const TVector2<T>& v1)
|
||||
{
|
||||
return sqrtf(v1.x * v1.x + v1.y * v1.y);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::SqrMagnitude(const TVector2<T>& v1)
|
||||
{
|
||||
return v1.x * v1.x + v1.y * v1.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NormalizeV(TVector2<T>& v1)
|
||||
{
|
||||
float vecNorm = Magnitude(v1);
|
||||
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalizeV(TVector2<T>& v1)
|
||||
{
|
||||
v1 /= Magnitude(v1);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::Angle(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2));
|
||||
}
|
||||
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::CosineAngle(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return (v1 * v2) / Magnitude(v1) * Magnitude(v2);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVectorV(TVector2<T>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) ? 1 : -1;
|
||||
v1.y = (v1.y > 0) ? 1 : -1;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::BindToSquareV(TVector2<T>& v1, T radius)
|
||||
{
|
||||
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
|
||||
v1 *= k;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClampToSquareV(TVector2<T>& v1, T radius)
|
||||
{
|
||||
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
|
||||
float k = (prime > radius) ? abs(radius / prime) : 1.0f;
|
||||
v1 *= k;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::DotP(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::MaxV(TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
|
||||
v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::MinV(TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
|
||||
v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicularV(TVector2<T>& v1)
|
||||
{
|
||||
T x = v1.x;
|
||||
v1.x = v1.y;
|
||||
v1.y = -v1.x;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TVector2<T>& v1)
|
||||
{
|
||||
T x = v1.x;
|
||||
v1.x = -v1.y;
|
||||
v1.y = v1.x;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ScaleV(TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
v1.x *= v2.x;
|
||||
v1.y *= v2.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverseV(TVector2<T>& v1)
|
||||
{
|
||||
v1.x = 1.0f / v1.x;
|
||||
v1.y = 1.0f / v1.y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ReflectV(TVector2<T>& v1, const TVector2<T>& normal)
|
||||
{
|
||||
Set(v1, v1 - (2 * (v1 * normal) * normal));
|
||||
|
||||
return v1;
|
||||
}
|
||||
template<RealType T>
|
||||
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
v1 = v2;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, T x, T y)
|
||||
{
|
||||
v1.x = x;
|
||||
v1.y = y;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::RotateV(TVector2<T>& v1, T angle)
|
||||
{
|
||||
float sinAngle = sin(angle);
|
||||
float cosAngle = cos(angle);
|
||||
|
||||
Set(v1,
|
||||
v1.x * cosAngle - v1.y * sinAngle,
|
||||
v1.y * cosAngle + v1.x * sinAngle
|
||||
);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClockwiseRotateV(TVector2<T>& v1, T angle)
|
||||
{
|
||||
RotateV(v1, -angle);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NegateV(TVector2<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline bool Phanes::Core::Math::IsNormalized(const TVector2<T>& v1, T threshold)
|
||||
{
|
||||
return (SqrMagnitude(v1) < threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline bool Phanes::Core::Math::IsPerpendicular(const TVector2<T>& v1, const TVector2<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) < threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline bool Phanes::Core::Math::IsParallel(const TVector2<T>& v1, const TVector2<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(DotP(v1,v2)) > threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
inline bool Phanes::Core::Math::IsCoincident(const TVector2<T>& v1, const TVector2<T>& v2, T threshold)
|
||||
{
|
||||
return (DotP(v1, v2) > threshold);
|
||||
}
|
||||
|
||||
//
|
||||
//Phanes::Core::Math::Matrix2 Phanes::Core::Math::OuterProduct(const TVector2& v1, const TVector2& v2)
|
||||
//{
|
||||
// return Matrix2(
|
||||
// v1.x * v2.x, v1.x * v2.y,
|
||||
// v1.y * v2.x, v1.y * v2.y
|
||||
// );
|
||||
//}
|
||||
|
||||
// ============================================================== //
|
||||
// TVector2 static function implementation with return values //
|
||||
// ============================================================== //
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Reflect(const TVector2<T>& v1, const TVector2<T>& normal)
|
||||
{
|
||||
return TVector2<T>(v1 - (2 * (v1 * normal) * normal));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Scale(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return TVector2<T>(v1.x * v2.x, v1.y * v2.y);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverse(const TVector2<T>& v1)
|
||||
{
|
||||
return TVector2<T>(1.0f / v1.x, 1.0f / v1.y);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Negate(const TVector2<T>& v1)
|
||||
{
|
||||
return TVector2<T>(-v1.x, -v1.y);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicular(const TVector2<T>& v1)
|
||||
{
|
||||
return TVector2<T>(v1.y, -v1.x);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicular(const TVector2<T>& v1)
|
||||
{
|
||||
return TVector2<T>(-v1.y, v1.x);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Min(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return TVector2<T>(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Max(const TVector2<T>& v1, const TVector2<T>& v2)
|
||||
{
|
||||
return TVector2<T>(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Normalize(const TVector2<T>& v1)
|
||||
{
|
||||
float vecNorm = Magnitude(v1);
|
||||
return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalize(const TVector2<T>& v1)
|
||||
{
|
||||
return (v1 / Magnitude(v1));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVector(const TVector2<T>& v1)
|
||||
{
|
||||
return TVector2<T>((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::BindToSquare(const TVector2<T>& v1, T radius)
|
||||
{
|
||||
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
|
||||
return v1 * k;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClampToSquare(const TVector2<T>& v1, T radius)
|
||||
{
|
||||
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
|
||||
float k = (prime > radius) ? abs(radius / prime) : 1.0f;
|
||||
|
||||
return v1 * k;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Lerp(const TVector2<T>& startVec, const TVector2<T>& destVec, T t)
|
||||
{
|
||||
t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0);
|
||||
|
||||
return (t * destVec) + ((1 - t) * startVec);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::LerpUnclamped(const TVector2<T>& startVec, const TVector2<T>& destVec, T t)
|
||||
{
|
||||
return (t * destVec) + ((1 - t) * startVec);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Rotate(const TVector2<T>& v1, T angle)
|
||||
{
|
||||
float sinAngle = sin(angle);
|
||||
float cosAngle = cos(angle);
|
||||
|
||||
return TVector2<T>(v1.x * cosAngle - v1.y * sinAngle,
|
||||
v1.y * cosAngle + v1.x * sinAngle);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClockwiseRotate(const TVector2<T>& v1, T angle)
|
||||
{
|
||||
return Rotate(v1, -angle);
|
||||
}
|
669
Engine/src/Runtime/Core/private/Math/Vector3.cpp
Normal file
669
Engine/src/Runtime/Core/private/Math/Vector3.cpp
Normal file
@ -0,0 +1,669 @@
|
||||
// =========================== //
|
||||
// TVector3 implementation //
|
||||
// =========================== //
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include "Core/public/Math/Vector3.h"
|
||||
|
||||
#include "Core/public/Math/Point.h"
|
||||
#include "Core/public/Math/Plane.h"
|
||||
|
||||
template<RealType T>
|
||||
inline Phanes::Core::Math::TVector3<T>::TVector3(const Real x, const Real y, const Real z)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T>::TVector3(const Real* comp)
|
||||
{
|
||||
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector3.cpp): Setting 3D vector coordinates by an array, comp must have a size of at least 3 components.");
|
||||
memcpy(this->comp, comp, sizeof(T) * 3);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T>::TVector3(const TPoint3<T>& start, const TPoint3<T>& end)
|
||||
{
|
||||
this->x = end.x - start.x;
|
||||
this->y = end.y - start.y;
|
||||
this->z = end.z - start.z;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T>::TVector3(const TVector3<Real>& v)
|
||||
{
|
||||
memcpy(this->comp, comp, sizeof(T) * 3);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T>::TVector3(TVector3<Real>&& v)
|
||||
{
|
||||
this->comp = v.comp;
|
||||
v.comp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ====================== //
|
||||
// TVector3 operators //
|
||||
// ====================== //
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x += s;
|
||||
v1.y += s;
|
||||
v1.z += s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
v1.x += v2.x;
|
||||
v1.y += v2.y;
|
||||
v1.z += v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x -= s;
|
||||
v1.y -= s;
|
||||
v1.z -= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
v1.x -= v2.x;
|
||||
v1.y -= v2.y;
|
||||
v1.z -= v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*=(TVector3<T>& v1, T s)
|
||||
{
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
v1.z *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/=(TVector3<T>& v1, T s)
|
||||
{
|
||||
s = (T)1.0 / s;
|
||||
v1.x *= s;
|
||||
v1.y *= s;
|
||||
v1.z *= s;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(const TVector3<T>& v1, T s)
|
||||
{
|
||||
return TVector3<T>(v1.x * s. v1.y * s, v1.z * s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(const TVector3<T>& v1, T s)
|
||||
{
|
||||
s = (T)1.0 / s;
|
||||
return TVector3<T>(v1.x * s.v1.y * s, v1.z * s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(T s, const TVector3<T>& v1)
|
||||
{
|
||||
return v1 * s;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(T s, const TVector3<T>& v1)
|
||||
{
|
||||
return v1 / s;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::operator*(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+(const TVector3<T>& v1, T s)
|
||||
{
|
||||
return TVector3<T>(v1.x + s.v1.y + s, v1.z + s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return TVector3<T>(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(const TVector3<T>& v1, T s)
|
||||
{
|
||||
return TVector3<T>(v1.x - s.v1.y - s, v1.z - s);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return TVector3<T>(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(TVector3<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
v1.z = -v1.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::operator==(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v2.x) < P_FLT_INAC && abs(v1.y - v2.y) < P_FLT_INAC && abs(v1.z - v2.z) < P_FLT_INAC);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::operator!=(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return (abs(v1.x - v2.x) > P_FLT_INAC || abs(v1.y - v2.y) > P_FLT_INAC || abs(v1.z - v2.z) > P_FLT_INAC);
|
||||
}
|
||||
|
||||
// ==================================== //
|
||||
// TVector3 function implementation //
|
||||
// ==================================== //
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::Magnitude(const TVector3<T>& v1)
|
||||
{
|
||||
return sqrt(DotP(v1, v1));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::SqrMagnitude(const TVector3<T>& v1)
|
||||
{
|
||||
return DotP(v1, v1);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::SqrLength(const TVector3<T>& v1)
|
||||
{
|
||||
return SqrMagnitude(v1);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NormalizeV(TVector3<T>& v1)
|
||||
{
|
||||
float vecNorm = Magnitude(v1);
|
||||
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalizeV(TVector3<T>& v1)
|
||||
{
|
||||
v1 /= Magnitude(v1);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectV(TVector3<T>& v1, const TVector3<T>& normal)
|
||||
{
|
||||
Set(v1, v1 - (2 * (v1 * normal) * normal));
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::Angle(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2)));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::DotP(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
void Phanes::Core::Math::Orthogonalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3)
|
||||
{
|
||||
Set(v2, Reject(v2, v1));
|
||||
Set(v3, Reject(Reject(v3, v1), v2));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
void Phanes::Core::Math::OrthoNormalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3)
|
||||
{
|
||||
Set(v2, Reject(v2, v1));
|
||||
Set(v3, Reject(Reject(v3, v1), v2));
|
||||
|
||||
NormalizeV(v1);
|
||||
NormalizeV(v2);
|
||||
NormalizeV(v3);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleToMagnitude(const TVector3<T>& v1, T magnitude)
|
||||
{
|
||||
NormalizeV(v1) *= magnitude;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverse(const TVector3<T>& v1)
|
||||
{
|
||||
return TVector3<T>((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlane(const TVector3<T>& v1, const TPlane<T>& plane)
|
||||
{
|
||||
return Reflect(v1, plane.normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlane(const TVector3<T>& v1, const TVector3<T>& normal)
|
||||
{
|
||||
return Reflect(v1, normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxis(const TVector3<T>& v1, const TVector3<T>& axisNormal, T angle)
|
||||
{
|
||||
T sinAngle = sin(angle);
|
||||
T cosAngle = cos(angle);
|
||||
|
||||
return (1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::VectorTriple(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3)
|
||||
{
|
||||
return CrossP(CrossP(v1, v2), v3);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Project(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return (DotP(v1, v2) / DotP(v2, v2)) * v2;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Reject(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlane(const TVector3<T>& v1, const TVector3<T>& normal)
|
||||
{
|
||||
return Reject(v1, normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlane(const TVector3<T>& v1, const TPlane<T>& plane)
|
||||
{
|
||||
return Reject(v1, plane.normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVector(const TVector3<T>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) - (v1.x < 0);
|
||||
v1.y = (v1.y > 0) - (v1.y < 0);
|
||||
v1.z = (v1.z > 0) - (v1.z < 0);
|
||||
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::Equals(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivideV(TVector3<T>& v1)
|
||||
{
|
||||
float _z = (T)1.0 / v1.z;
|
||||
v1.x *= _z;
|
||||
v1.y *= _z;
|
||||
v1.z = (T)0.0;
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossPV(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
float x = v1.x;
|
||||
float y = v1.y;
|
||||
float z = v1.z;
|
||||
|
||||
v1.x = (y * v2.z) - (z * v2.y);
|
||||
v1.y = (z * v2.x) - (x * v2.z);
|
||||
v1.z = (x * v2.y) - (y * v2.x);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MaxV(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
v1.x = Max(v1.x, v2.x);
|
||||
v1.y = Max(v1.y, v2.y);
|
||||
v1.z = Max(v1.z, v2.z);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MinV(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
v1.x = Min(v1.x, v2.x);
|
||||
v1.y = Min(v1.y, v2.y);
|
||||
v1.z = Min(v1.z, v2.z);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NegateV(TVector3<T>& v1)
|
||||
{
|
||||
v1.x = -v1.x;
|
||||
v1.y = -v1.y;
|
||||
v1.z = -v1.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleV(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
v1.x *= v2.x;
|
||||
v1.y *= v2.y;
|
||||
v1.z *= v2.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectV(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
float x = (v1 * v2) / (v2 * v2);
|
||||
v1 = x * v2;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RejectV(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
float x = (v1 * v2) / (v2 * v2);
|
||||
v1 -= x * v2;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlaneV(TVector3<T>& v1, const TVector3<T>& normal)
|
||||
{
|
||||
return RejectV(v1, normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlaneV(TVector3<T>& v1, const TPlane<T>& plane)
|
||||
{
|
||||
return RejectV(v1, plane.normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
v1 = v2;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, T x, T y, T z)
|
||||
{
|
||||
v1.x = x;
|
||||
v1.y = y;
|
||||
v1.z = z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ClampMagnitudeV(TVector3<T>& v1, T min, T max)
|
||||
{
|
||||
T magnitude = Magnitude(v1);
|
||||
|
||||
v1 = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T);
|
||||
|
||||
Clamp(magnitude, min, max);
|
||||
|
||||
v1 *= magnitude;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverseV(TVector3<T>& v1)
|
||||
{
|
||||
v1.x = 1.0f / v1.x;
|
||||
v1.y = 1.0f / v1.y;
|
||||
v1.z = 1.0f / v1.z;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlaneV(TVector3<T>& v1, const TPlane<T>& plane)
|
||||
{
|
||||
return ReflectV(v1, plane.normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlaneV(TVector3<T>& v1, const TVector3<T>& normal)
|
||||
{
|
||||
return ReflectV(v1, normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxisV(TVector3<T>& v1, const TVector3<T>& axisNormal, T angle)
|
||||
{
|
||||
T sinAngle = sin(angle);
|
||||
T cosAngle = cos(angle);
|
||||
|
||||
v1 = ((T)1.0 - cosAngle) * DotP(axisNormal, v1) * axisNormal + cosAngle * v1 + sinAngle * CrossP(axisNormal, v1);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleToMagnitudeV(TVector3<T>& v1, T magnitude)
|
||||
{
|
||||
NormalizeV(v1) *= magnitude;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVectorV(TVector3<T>& v1)
|
||||
{
|
||||
v1.x = (v1.x > 0) ? 1 : 0;
|
||||
v1.y = (v1.y > 0) ? 1 : 0;
|
||||
v1.z = (v1.z > 0) ? 1 : 0;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::ScalarTriple(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3)
|
||||
{
|
||||
return CrossP(v1, v2) * v3;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
T Phanes::Core::Math::CosineAngle(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return (v1 * v2) / (Magnitude(v1) * Magnitude(v2));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::VectorTripleV(TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3)
|
||||
{
|
||||
CrossPV(CrossPV(v1, v2), v3);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::IsPerpendicular(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) < threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::IsParallel(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (abs(DotP(v1, v2)) > threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::IsCoincident(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
|
||||
{
|
||||
return (DotP(v1, v2) > threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::IsNormalized(const TVector3<T>& v1, T threshold)
|
||||
{
|
||||
return (SqrMagnitude(v1) < threshold);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
bool Phanes::Core::Math::IsCoplanar(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3, T threshold)
|
||||
{
|
||||
return (ScalarTriple(v1, v2, v3) < threshold);
|
||||
}
|
||||
|
||||
|
||||
// ================ //
|
||||
// With return: //
|
||||
// ================ //
|
||||
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Normalize(const TVector3<T>& v1)
|
||||
{
|
||||
float vecNorm = Magnitude(v1);
|
||||
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalize(const TVector3<T>& v1)
|
||||
{
|
||||
return v1 / Magnitude(v1);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Reflect(const TVector3<T>& v1, const TVector3<T>& normal)
|
||||
{
|
||||
return v1 - (2 * (v1 * normal) * normal);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivide(const TVector3<T>& v1)
|
||||
{
|
||||
float _z = (T)1.0 / v1.z;
|
||||
return TVector3<T>(v1.x * _z, v1.y * _z, (T)0.0);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossP(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return TVector3<T>((v1.y * v2.z) - (v1.z * v2.y),
|
||||
(v1.z * v2.x) - (v1.x * v2.z),
|
||||
(v1.x * v2.y) - (v1.y * v2.x));
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Lerp(const TVector3<T>& start, const TVector3<T>& dest, T t)
|
||||
{
|
||||
t = Clamp(t, (T)0.0, (T), 1.0);
|
||||
return (1 - t) * start + t * dest;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::LerpUnclamped(const TVector3<T>& start, const TVector3<T>& dest, T t)
|
||||
{
|
||||
return (1 - t) * start + t * dest;
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Max(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return TVector3<T>((v1.x > v2.x) ? v1.x : v2.x,
|
||||
(v1.y > v2.y) ? v1.y : v2.y,
|
||||
(v1.z > v2.z) ? v1.z : v2.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Min(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return TVector3<T>((v1.x < v2.x) ? v1.x : v2.x,
|
||||
(v1.y < v2.y) ? v1.y : v2.y,
|
||||
(v1.z < v2.z) ? v1.z : v2.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Negate(const TVector3<T>& v1)
|
||||
{
|
||||
return TVector3<T>(-v1.x, -v1.y, -v1.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Scale(const TVector3<T>& v1, const TVector3<T>& v2)
|
||||
{
|
||||
return TVector3<T>(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
}
|
||||
|
||||
template<RealType T>
|
||||
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ClampMagnitude(const TVector3<T>& v1, T min, T max)
|
||||
{
|
||||
T magnitude = Magnitude(v1);
|
||||
|
||||
const TVector3<T> unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T);
|
||||
|
||||
Clamp(magnitude, min, max);
|
||||
|
||||
return unitVec * magnitude;
|
||||
}
|
||||
|
388
Engine/src/Runtime/Core/private/Math/Vector4.cpp
Normal file
388
Engine/src/Runtime/Core/private/Math/Vector4.cpp
Normal file
@ -0,0 +1,388 @@
|
||||
// ========================== //
|
||||
// Vector4 implementation //
|
||||
// ========================== //
|
||||
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Vector4.h"
|
||||
|
||||
#include "Math/Vector3.h"
|
||||
#include "Math/Vector2.h"
|
||||
|
||||
|
||||
// ===================== //
|
||||
// Vector4 operators //
|
||||
// ===================== //
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::createVector(float x, float y, float z, float w)
|
||||
{
|
||||
Vector4 _new{};
|
||||
_new.x = x;
|
||||
_new.y = y;
|
||||
_new.z = z;
|
||||
_new.w = w;
|
||||
return _new;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Vector4& a, float s)
|
||||
{
|
||||
a.x += s;
|
||||
a.y += s;
|
||||
a.z += s;
|
||||
a.w += s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+= (phanes::core::math::coretypes::Vector4& a, const phanes::core::math::coretypes::Vector4& b) {
|
||||
a.x += b.x;
|
||||
a.y += b.y;
|
||||
a.z += b.z;
|
||||
a.w += b.w;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Vector4& a, float s)
|
||||
{
|
||||
a.x -= s;
|
||||
a.y -= s;
|
||||
a.z -= s;
|
||||
a.w -= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-= (phanes::core::math::coretypes::Vector4& a, const phanes::core::math::coretypes::Vector4& b) {
|
||||
a.x -= b.x;
|
||||
a.y -= b.y;
|
||||
a.z -= b.z;
|
||||
a.w -= b.w;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator*= (phanes::core::math::coretypes::Vector4& a, float s) {
|
||||
a.x *= s;
|
||||
a.y *= s;
|
||||
a.z *= s;
|
||||
a.w *= s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator/= (phanes::core::math::coretypes::Vector4& a, float s) {
|
||||
s = 1.0f / s;
|
||||
a.x *= s;
|
||||
a.y *= s;
|
||||
a.z *= s;
|
||||
a.w *= s;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator*(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator*(float s, const Vector4& a)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator/(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
s = 1.0f / s;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator/(float s, const Vector4& a)
|
||||
{
|
||||
Vector4 v;
|
||||
s = 1.0f / s;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::operator*(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator+(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x + s;
|
||||
v.y = a.y + s;
|
||||
v.z = a.z + s;
|
||||
v.w = a.w + s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator+(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x + b.x;
|
||||
v.y = a.y + b.y;
|
||||
v.z = a.z + b.z;
|
||||
v.w = a.w + b.w;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator-(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x - s;
|
||||
v.y = a.y - s;
|
||||
v.z = a.z - s;
|
||||
v.w = a.w - s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator-(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x - b.x;
|
||||
v.y = a.y - b.y;
|
||||
v.z = a.z - b.z;
|
||||
v.w = a.w - b.w;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator-(Vector4& a)
|
||||
{
|
||||
a.x = -a.x;
|
||||
a.y = -a.y;
|
||||
a.z = -a.z;
|
||||
a.w = -a.w;
|
||||
}
|
||||
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
if (abs(a.x - b.x) <= P_FLT_INAC and abs(a.y - b.y) <= P_FLT_INAC and abs(a.z - b.z) <= P_FLT_INAC and abs(a.w - b.w) <= P_FLT_INAC)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ====================================== //
|
||||
// Vector4 function implementation //
|
||||
// ====================================== //
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::magnitude(const Vector4& a)
|
||||
{
|
||||
return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
|
||||
}
|
||||
|
||||
float phanes::core::math::coretypes::sqrMagnitude(const Vector4& a)
|
||||
{
|
||||
return a.x * a.x + a.y * a.y + a.z * a.z;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::normalizeNR(Vector4& a)
|
||||
{
|
||||
a /= sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
}
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::angle(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return acosf(dotP(a, b) / (magnitude(a) * magnitude(b)));
|
||||
}
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::dotP(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::orthogonolize(Vector4& a, Vector4& b, Vector4& c)
|
||||
{
|
||||
Set(b, b - project(b, a));
|
||||
Set(c, c - project(c, a) - project(c, b));
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::orthoNormalize(Vector4& a, Vector4& b, Vector4& c)
|
||||
{
|
||||
Set(b, b - project(b, a));
|
||||
Set(c, c - project(c, a) - project(c, b));
|
||||
|
||||
a /= sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
b /= sqrtf(b.x * b.x + b.y * b.y + b.z * b.z);
|
||||
c /= sqrtf(c.x * c.x + c.y * c.y + c.z * c.z);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::scaleToMagnitude(Vector4& a, float size)
|
||||
{
|
||||
a /= sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
a *= size;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::equals(const Vector4& a, const Vector4& b, float threshold)
|
||||
{
|
||||
if (abs(a.x - b.x) <= threshold and abs(a.y - b.y) <= threshold and abs(a.z - b.z) <= threshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::perpspectiveDivideNR(Vector4& a)
|
||||
{
|
||||
float _z = 1.0f / a.z;
|
||||
a.x *= _z;
|
||||
a.y *= _z;
|
||||
a.z = 0.0f;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::maxNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x = phanes::core::math::max(a.x, b.x);
|
||||
a.y = phanes::core::math::max(a.y, b.y);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::minNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x = phanes::core::math::min(a.x, b.x);
|
||||
a.y = phanes::core::math::min(a.y, b.y);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::scaleNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
a.z *= b.z;
|
||||
}
|
||||
|
||||
// projects vector a onto vector b
|
||||
void phanes::core::math::coretypes::projectNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
float x = (a * b) / (b * b);
|
||||
a.x = x * b.x;
|
||||
a.y = x * b.y;
|
||||
a.z = x * b.z;
|
||||
}
|
||||
|
||||
// rejects vector a from vector b
|
||||
void phanes::core::math::coretypes::rejectNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
float x = ((a * b) / (b * b));
|
||||
a.x -= x * b.x;
|
||||
a.y -= x * b.y;
|
||||
a.z -= x * b.z;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::Set(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x = b.x;
|
||||
a.y = b.y;
|
||||
a.z = b.z;
|
||||
}
|
||||
|
||||
|
||||
// WITH RETURN: //
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::perpspectiveDivide(const Vector4& a)
|
||||
{
|
||||
float _z = 1.0f / a.z;
|
||||
return createVector(a.x * _z, a.y * _z, a.z * _z, 0.0f);
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::lerp(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
t = phanes::core::math::clamp(t, .0f, 1.0f);
|
||||
return a * (1 - t) + t * b;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::lerpUnclamped(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
return a * (1 - t) + t * b;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::slerp(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
t = phanes::core::math::clamp(t, 0.0f, 1.0f);
|
||||
Vector4 _a = normalize(a);
|
||||
Vector4 _b = normalize(b);
|
||||
float _angle = angle(_a, _b);
|
||||
return (((sinf(1.0f - t) * _angle) / sinf(_angle)) * _a) + ((sinf(t * _angle) / sinf(_angle)) * _b);
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::slerpUnclamped(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
Vector4 _a = normalize(a);
|
||||
Vector4 _b = normalize(b);
|
||||
float _angle = angle(_a, _b);
|
||||
return (((sinf(1.0f - t) * _angle) / sinf(_angle)) * _a) + ((sinf(t * _angle) / sinf(_angle)) * _b);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::max(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 _new{};
|
||||
_new.x = phanes::core::math::max(a.x, b.x);
|
||||
_new.y = phanes::core::math::max(a.y, b.y);
|
||||
_new.z = phanes::core::math::max(a.z, b.z);
|
||||
return _new;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::min(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 _new{};
|
||||
_new.x = phanes::core::math::min(a.x, b.x);
|
||||
_new.y = phanes::core::math::min(a.y, b.y);
|
||||
_new.z = phanes::core::math::min(a.z, b.z);
|
||||
return _new;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::scale(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return createVector(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::project(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return ((a * b) / (b * b)) * b;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::reject(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return a - ((a * b) / (b * b)) * b;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::normalize(const Vector4& a)
|
||||
{
|
||||
return a / sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "StartingPoint/StartingPoint.h"
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "Core/public/StartingPoint/StartingPoint.h"
|
||||
|
||||
Phanes::Core::Application::PhanesGame::PhanesGame()
|
||||
{
|
156
Engine/src/Runtime/Core/public/Math/IntPoint.h
Normal file
156
Engine/src/Runtime/Core/public/Math/IntPoint.h
Normal file
@ -0,0 +1,156 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
#include "Core/public/Math/IntVector2.h"
|
||||
#include "Core/public/Math/IntVector3.h"
|
||||
// #include "Core/public/Math/IntVector4.h"
|
||||
|
||||
#ifndef P_DEBUG
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* General annonation: The Point is the same as a vector. The type exists, to ensure a
|
||||
* easy differentiation between the two.
|
||||
*/
|
||||
|
||||
#ifndef INTPOINT_H
|
||||
#define INTPOINT_H
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* A 2D Point with components x and y with integer precision.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
struct TIntPoint2 : public TIntVector2<T> {
|
||||
|
||||
using TIntVector2<T>::TIntVector2;
|
||||
|
||||
/**
|
||||
* Creates IntPoint2 from IntPoint3's xy
|
||||
*
|
||||
* @param a IntPoint3 one
|
||||
*/
|
||||
|
||||
TIntPoint2(const TIntPoint3<T>& a)
|
||||
{
|
||||
this->x = a.x;
|
||||
this->y = a.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates IntPoint2 from IntPoint4's xy
|
||||
*
|
||||
* @param a IntPoint4 one
|
||||
*/
|
||||
|
||||
//TIntPoint2(const TIntPoint4<T>& a)
|
||||
//{
|
||||
// this->x = a.x;
|
||||
// this->y = a.y;
|
||||
|
||||
//}
|
||||
};
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* A 3D Point with components x and y with integer precision.
|
||||
*/
|
||||
|
||||
|
||||
template<IntType T>
|
||||
struct TIntPoint3 : public TIntVector3<T> {
|
||||
|
||||
using TIntVector3<T>::TIntVector3;
|
||||
|
||||
/**
|
||||
* Creates IntPoint3 from IntPoint2's xy and zero
|
||||
*
|
||||
* @param a IntPoint2 one
|
||||
*/
|
||||
|
||||
TIntPoint3(const TIntPoint2<T>& a)
|
||||
{
|
||||
this->x = a.x;
|
||||
this->y = a.y;
|
||||
this->z = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates IntPoint3 from IntPoint4's xyz
|
||||
*
|
||||
* @param a IntPoint4 one
|
||||
*/
|
||||
|
||||
//TIntPoint3(const TIntPoint4<T>& a)
|
||||
//{
|
||||
// this->components[0] = a.components[0];
|
||||
// this->components[1] = a.components[1];
|
||||
// this->components[2] = a.components[2];
|
||||
//}
|
||||
};
|
||||
|
||||
template<IntType T, RealType Rt>
|
||||
Rt Distance(const TIntPoint3<T>& p1, const TIntPoint3<T>& p2);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* A 4D Point with components x and y with integer precision.
|
||||
*/
|
||||
|
||||
|
||||
//template<typename T>
|
||||
//struct TIntPoint4 : public TIntVector4<T> {
|
||||
// static_assert(std::is_integral_v(T), "T must be an integer type.");
|
||||
|
||||
// using IntVector4<T>::IntVector4;
|
||||
|
||||
// /**
|
||||
// * Creates IntPoint4 from IntPoint2's xy and the last two zero
|
||||
// *
|
||||
// * @param a IntPoint2 one
|
||||
// */
|
||||
|
||||
// PHANES_CORE_API IntPoint4(const IntPoint2<T>& a)
|
||||
// {
|
||||
// this->components[0] = a.components[0];
|
||||
// this->components[1] = a.components[1];
|
||||
// this->components[2] = 0;
|
||||
// this->components[3] = 0;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Creates IntPoint4 from IntPoint3's xyz and zero
|
||||
// *
|
||||
// * @param a IntPoint3 one
|
||||
// */
|
||||
|
||||
// PHANES_CORE_API IntPoint4(const IntPoint3<T>& a)
|
||||
// {
|
||||
// this->components[0] = a.components[0];
|
||||
// this->components[1] = a.components[1];
|
||||
// this->components[2] = a.components[2];
|
||||
// this->components[3] = 0;
|
||||
// }
|
||||
//};
|
||||
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
#endif // !INTPOINT_H
|
872
Engine/src/Runtime/Core/public/Math/IntVector2.h
Normal file
872
Engine/src/Runtime/Core/public/Math/IntVector2.h
Normal file
@ -0,0 +1,872 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/Core.h"
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
#ifndef P_DEBUG
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Note: Some function are deleted, because, their unusable with int types, except very specific cases.
|
||||
* To keep the library verbose, these functions are explicitly marked as deleted.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INTVECTOR2_H
|
||||
#define INTVECTOR2_H
|
||||
|
||||
#define PIntZeroVector2(type) TIntVector2<##type>(0,0)
|
||||
#define PIntVectorSouth2(type) TIntVector2<##type>(0,-1)
|
||||
#define PIntVectorNorth2(type) TIntVector2<##type>(0,1)
|
||||
#define PIntVectorEast2(type) TIntVector2<##type>(1,0)
|
||||
#define PIntVectorWest2(type) TIntVector2<##type>(-1,0)
|
||||
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* A 2D Vector with components x and y with integer precision.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
struct TIntVector2 {
|
||||
|
||||
static_assert(std::is_integral_v<T>, "T must be an integer type.");
|
||||
|
||||
public:
|
||||
|
||||
// Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa.
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
/** X component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
* @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T x;
|
||||
|
||||
/** Y component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T y;
|
||||
};
|
||||
|
||||
/** Components array holding the data
|
||||
*
|
||||
* @ref [FIELD]x
|
||||
* @ref [FIELD]y
|
||||
*
|
||||
* @note Components are split into x and y. Access and manipulation is possible by these variables.
|
||||
*/
|
||||
|
||||
T comp[2];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor without initialization
|
||||
*/
|
||||
|
||||
TIntVector2() = default;
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
|
||||
TIntVector2(const TIntVector2<T>& v);
|
||||
|
||||
/**
|
||||
* Move constructor
|
||||
*/
|
||||
|
||||
TIntVector2(TIntVector2<T>&& v);
|
||||
|
||||
/**
|
||||
* Convert other type of vector
|
||||
*/
|
||||
|
||||
template<IntType OtherIntType>
|
||||
explicit TIntVector2(const TIntVector2<OtherIntType>& v) : x((T)v.x), y((T)v.y) {};
|
||||
|
||||
template<RealType Real>
|
||||
explicit TIntVector2(const TVector2<Real>& v) : x((T)v.x), y((T)v.y) {};
|
||||
|
||||
/**
|
||||
* Construct Vector from xy components.
|
||||
*
|
||||
* @param x X component
|
||||
* @param y Y component
|
||||
*/
|
||||
|
||||
TIntVector2(const T x, const T y);
|
||||
|
||||
/**
|
||||
* Construct Vector from two component array.
|
||||
*
|
||||
* @param comp Array of components
|
||||
*/
|
||||
|
||||
TIntVector2(const T* comp);
|
||||
|
||||
/**
|
||||
* Construct Vector from 3D integer Vector's xy.
|
||||
*
|
||||
* @param v 3D IntVector to copy from
|
||||
*/
|
||||
|
||||
TIntVector2(const TIntVector3<T>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 4D integer Vector's xy.
|
||||
*
|
||||
* @param v 4D IntVector to copy from
|
||||
*/
|
||||
|
||||
//TIntVector2(const TIntVector4<IntType>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 2D Point's xy.
|
||||
*
|
||||
* @param v 2D Point to copy from
|
||||
*/
|
||||
|
||||
//TIntVector2(const TIntPoint2<IntType>& v);
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a vector pointing from start to end.
|
||||
*
|
||||
* @param(start) Startingpoint
|
||||
* @param(end) Endpoint
|
||||
*/
|
||||
|
||||
TIntVector2(const TIntPoint2<T>& start, const TIntPoint2<T>& end);
|
||||
};
|
||||
|
||||
// ======================== //
|
||||
// IntVector2 operators //
|
||||
// ======================== //
|
||||
|
||||
|
||||
/**
|
||||
* Addition operation on same TIntVector2<T> (this) by a floating point value.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(s) Floating point to add
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator+= (TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Addition operation on same TIntVector2<T> (this) by a another TIntVector2<T>.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(v2) Vector to add
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator+= (TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Substraction operation on same TIntVector2<T> (this) by a floating point.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(v2) Floating point to substract
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator-= (TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Substraction operation on same TIntVector2<T> (this) by a another TIntVector2<T>.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(v2) Vector to substract
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator-= (TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Multiplication of TIntVector2<T> (this) with a floating point.
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to multiply with
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator*= (TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Devision of Vector (this) by floating point.
|
||||
*
|
||||
* @param(v1) Vector to divide with
|
||||
* @param(s Floating point to divide with
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator/= (TIntVector2<T>& v1, T s) = delete;
|
||||
|
||||
/**
|
||||
* Scale of Vector by floating point. (> Creates a new TIntVector2<T>)
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to multiply with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator* (const TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Division of Vector by floating point. (> Creates another TIntVector2<T>)
|
||||
*
|
||||
* @see [FUNC]DivideFloat
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to divide with
|
||||
*
|
||||
* @return Result Vector
|
||||
* @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator/ (const TIntVector2<T>& v1, T s) = delete;
|
||||
|
||||
/**
|
||||
* Scale of Vector by floating point. (> Creates a new TIntVector2<T>)
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to multiply with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector2<T> operator* (T s, const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.)
|
||||
*
|
||||
* @see [FUNC]DivideFloat
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to divide with
|
||||
*
|
||||
* @return Result Vector
|
||||
*
|
||||
* @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector2<T> operator/ (T s, const TIntVector2<T>& v1) = delete;
|
||||
|
||||
/**
|
||||
* Dot product between two Vectors.
|
||||
*
|
||||
* @see [FUNC]DotP
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @result Dot product
|
||||
*/
|
||||
|
||||
template<IntType T, IntType Rt = float>
|
||||
Rt operator* (const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise addition of Vector with floating point.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(s Floating point to add
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator+ (const TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Componentwise addition of Vector with floating point.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(s Floating point to add
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator+ (const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise substraction of Vector with floating point.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(s Floating point to substract
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator- (const TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Componentwise substraction of Vector with Vector.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(s Floating point to substract
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> operator- (const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Negate Vector.
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
void operator- (TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Compare Vector for equality.
|
||||
*
|
||||
* @see [FUNC]Equals
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*
|
||||
* @return true if equal, false if inequal
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
bool operator== (const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
|
||||
/**
|
||||
* Compare Vector for inequality.
|
||||
*
|
||||
* @see [FUNC]Equals
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*
|
||||
* @return true if inequal, false if equal
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
bool operator!= (const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
// ============================================== //
|
||||
// IntVector2 static function implementation //
|
||||
// ============================================== //
|
||||
|
||||
/**
|
||||
* Magnitude of Vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @return Size of Vector
|
||||
*/
|
||||
|
||||
template<IntType T, IntType Rt = float>
|
||||
Rt Magnitude(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* @see [FUNC]Magnitude
|
||||
*/
|
||||
template<IntType T, IntType Rt = float>
|
||||
FORCEINLINE Rt Length(const TIntVector2<T>& v1) { return Magnitude(v1); };
|
||||
|
||||
/**
|
||||
* Square of magnitude of Vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @return Magnitude without calculating square root
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T SqrMagnitude(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* @see [FUNC]SqrMagnitude
|
||||
*/
|
||||
template<IntType T>
|
||||
FORCEINLINE T SqrLength(const TIntVector2<T>& v1) { return SqrMagnitude(v1); };
|
||||
|
||||
|
||||
/**
|
||||
* Divide vector and truncate result.
|
||||
*
|
||||
* @param(v1) Vector to divide
|
||||
* @param(s) Number to divide with
|
||||
*
|
||||
* @note Rt is the type of the reciprocal of s.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TIntVector2<T> DivideTruncV(TIntVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Angle between to Vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
Rt Angle(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Cosine of angle between to Vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
Rt CosineAngle(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Returns signs of components in vector: -1 / +1 / 0.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> SignVectorV(TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Dot product of two Vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T DotP(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates Vector, with component wise largest values.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> MaxV(TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates Vector, with component wise smallest values.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> MinV(TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets perpendicular Vector to v1.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> GetPerpendicularV(TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets perpendicular Vector to v1.
|
||||
*
|
||||
* @reg [FUNC]PerpendicularV
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> GetReversePerpendicularV(TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Component wise multiplication of Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> ScaleV(TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Copies one Vector two another
|
||||
*
|
||||
* @param(v1) Vector to copy to
|
||||
* @param(v2) Vector to copy
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> Set(TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Sets components of a vector.
|
||||
*
|
||||
* @param(v1) Vector to copy to
|
||||
* @param(v2) Vector to copy
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> Set(TIntVector2<T>& v1, T x, T y);
|
||||
|
||||
|
||||
/**
|
||||
* Negates Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> NegateV(TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Tests if vector is a unity vector.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return true if unit vector, false if not
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsNormalized(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are perpendicular to each other.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return true if perpendicular, false if not
|
||||
*
|
||||
* @note Requires v1 and v2 to be normal vectors.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsPerpendicular(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are parallel to each other. (Angle is close to zero.)
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return true if parallel, false if not
|
||||
*
|
||||
* @note Requires v1 and v2 to be normal vectors.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsParallel(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are coincident. (Are parallel and point in the same direction.)
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return true if coincident, false if not
|
||||
*
|
||||
* @note Requires v1 and v2 to be normal vectors.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsCoincident(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets outer product of to vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Resulting matrix
|
||||
*/
|
||||
|
||||
//template<IntType T>
|
||||
//Matrix2<T> OuterProduct(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
|
||||
// ============================================================= //
|
||||
// IntVector2 static function implementation with return values //
|
||||
// ============================================================= //
|
||||
|
||||
|
||||
/**
|
||||
* Reflects a vector on a normal
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(normal) Normal of surface
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> Reflect(const TIntVector2<T>& v1, const TVector2<Rt>& normal);
|
||||
|
||||
/**
|
||||
* Scales a vector component wise
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> Scale(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise inverse of a vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Componentwise inverted, floating point vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> CompInverse(const TIntVector2<T>& v1);
|
||||
|
||||
|
||||
/**
|
||||
* Negates Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Componentwise inverted vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> Negate(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets the perpendicular vector of v1
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Perpendicular vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> GetPerpendicular(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets reverse of the perpendicular vector of v1
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Reversed perpendicular vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> GetReversePerpendicular(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the component wise minimals of both vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Minimal vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> Min(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the component wise maxima of both vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Maximal vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> Max(const TIntVector2<T>& v1, const TIntVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates a normalized instance of the vector
|
||||
*
|
||||
* @param(v1) Vector to normalize
|
||||
*
|
||||
* @return Unit vector
|
||||
* @note Returns floating point vector.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> Normalize(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Creates a normalized instance of the vector
|
||||
*
|
||||
* @param(v1) Vector to normalize
|
||||
*
|
||||
* @return Unit vector
|
||||
* @note Does not test for zero vector
|
||||
* @note Returns floating point vector.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> UnsafeNormalize(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Returns signs of components in vector: -1 / +1 / 0.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Vector with signs as components
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector2<T> SignVector(const TIntVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Binds a vector to a square with a radius
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(radius) Radius of square (=> Distance from middle to center of each site.)
|
||||
*
|
||||
* @return Bound, floating point vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> BindToSquare(const TIntVector2<T>& v1, T radius);
|
||||
|
||||
/**
|
||||
* Clamps a vector to a square with a radius
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(radius) Radius of square (=> Distance from middle to center of each site.)
|
||||
*
|
||||
* @return Clamped, floating point vector. If the length of the vector fits the square, then the vector is returned.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> ClampToSquare(const TIntVector2<T>& v1, T radius);
|
||||
|
||||
/**
|
||||
* Interpolates between to vectors.
|
||||
*
|
||||
* @param(startVec) Start vector (t = 0)
|
||||
* @param(destVec) Destination vector (t = 1)
|
||||
* @param(t) Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is clamped between 0 - 1.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> Lerp(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t);
|
||||
|
||||
/**
|
||||
* Interpolates between to vectors.
|
||||
*
|
||||
* @param(startVec) Start vector (t = 0)
|
||||
* @param(destVec) Destination vector (t = 1)
|
||||
* @param(t) Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is not clamped. Make shure t is between 0.0f and 1.0f
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> LerpUnclamped(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t);
|
||||
|
||||
/**
|
||||
* Anti-clockwise vector rotation.
|
||||
*
|
||||
* @param(v1) Vector to rotate
|
||||
* @param(angle) Angle to rotate
|
||||
*
|
||||
* @return Rotated vector
|
||||
*
|
||||
* @note Angle is not clamped
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> Rotate(const TIntVector2<T>& v1, Rt angle);
|
||||
|
||||
/**
|
||||
* Clockwise vector rotation.
|
||||
*
|
||||
* @param(v1) Vector to rotate
|
||||
*
|
||||
* @return Rotated vector
|
||||
*
|
||||
* @note Angle is not clamped
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
FORCEINLINE TVector2<Rt> ClockwiseRotate(const TIntVector2<T>& v1, Rt angle);
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(s) Vector two
|
||||
*
|
||||
* @note Truncates result instead of rounding
|
||||
* @note Rt is the type of the reciprocal of s.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TIntVector2<T> DivideTrunc(const TIntVector2<T>& v1, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(s) Vector two
|
||||
*
|
||||
* @return Floating point vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector2<Rt> DivideFloat(const TIntVector2<T>& v1, T s);
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
#endif // !INTVECTOR2_H
|
||||
|
966
Engine/src/Runtime/Core/public/Math/IntVector3.h
Normal file
966
Engine/src/Runtime/Core/public/Math/IntVector3.h
Normal file
@ -0,0 +1,966 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
#include "Core/public/Math/Vector3.h"
|
||||
|
||||
#ifndef P_DEBUG
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef INTVECTOR3_H
|
||||
#define INTVECTOR3_H
|
||||
|
||||
#define PIntZeroVector3(type) TIntVector3<##type>(0,0,0)
|
||||
#define PIntVectorForward3(type) TIntVector3<##type>(1,0,0)
|
||||
#define PIntVectorBackward3(type) TIntVector3<##type>(-1,0,0)
|
||||
#define PIntVectorEast3(type) TIntVector3<##type>(0,1,0)
|
||||
#define PIntVectorWest3(type) TIntVector3<##type>(0,-1,0)
|
||||
#define PIntVectorUp3(type) TIntVector3<##type>(0,0,1)
|
||||
#define PIntVectorDown3(type) TIntVector3<##type>(0,0,-1)
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* A 3D Vector with components x, y and z with integer precision.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
struct TIntVector3 {
|
||||
|
||||
public:
|
||||
|
||||
// Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa.
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
/** X component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
* @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T x;
|
||||
|
||||
/** Y component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T y;
|
||||
|
||||
/** Z component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note Z does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T z;
|
||||
};
|
||||
|
||||
/** Components array holding the data
|
||||
*
|
||||
* @ref [FIELD]x
|
||||
* @ref [FIELD]y
|
||||
* @ref [FIELD]z
|
||||
*
|
||||
* @note Components are split into x, y and z. Access and manipulation is possible by these variables.
|
||||
*/
|
||||
|
||||
T comp[3];
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor without initialization
|
||||
*/
|
||||
|
||||
TIntVector3() = default;
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
|
||||
TIntVector3(const TIntVector3<T>& v);
|
||||
|
||||
/**
|
||||
* Move constructor
|
||||
*/
|
||||
|
||||
TIntVector3(TIntVector3<T>&& v);
|
||||
|
||||
/**
|
||||
* Convert other type of vector
|
||||
*/
|
||||
|
||||
template<IntType OtherIntType>
|
||||
explicit TIntVector3(const TIntVector3<OtherIntType>& v) : x((T)v.x), y((T)v.y) {};
|
||||
|
||||
template<RealType Real>
|
||||
explicit TIntVector3(const TVector3<Real>& v) : x((T)v.x), y((T)v.y) {};
|
||||
|
||||
/**
|
||||
* Construct Vector from xy components.
|
||||
*
|
||||
* @param x X component
|
||||
* @param y Y component
|
||||
* @param z Z component
|
||||
*/
|
||||
|
||||
TIntVector3(const T x, const T y, const T z);
|
||||
|
||||
/**
|
||||
* Construct Vector from two component array.
|
||||
*
|
||||
* @param comp Array of components
|
||||
*/
|
||||
|
||||
TIntVector3(const T* comp);
|
||||
|
||||
/**
|
||||
* Construct Vector from 3D integer Vector's xy.
|
||||
*
|
||||
* @param v 3D IntVector to copy from
|
||||
*/
|
||||
|
||||
TIntVector3(const TIntVector2<T>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 4D integer Vector's xy.
|
||||
*
|
||||
* @param v 4D IntVector to copy from
|
||||
*/
|
||||
|
||||
//TIntVector2(const TIntVector4<IntType>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 2D Point's xy.
|
||||
*
|
||||
* @param v 2D Point to copy from
|
||||
*/
|
||||
|
||||
//TIntVector2(const TIntPoint2<IntType>& v);
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a vector pointing from start to end.
|
||||
*
|
||||
* @param(start) Startingpoint
|
||||
* @param(end) Endpoint
|
||||
*/
|
||||
|
||||
TIntVector3(const TIntPoint3<T>& start, const TIntPoint3<T>& end);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ======================== //
|
||||
// IntVector3 operators //
|
||||
// ======================== //
|
||||
|
||||
|
||||
/**
|
||||
* Coponentwise addition of floating point to 3D vector
|
||||
*
|
||||
* @param(v1) vector to add to
|
||||
* @param(s) floating point to add
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator+= (TIntVector3<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise addition of 3D vector to 3D vector
|
||||
*
|
||||
* @param(v1) vector to add to
|
||||
* @param(v2) vector to add
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator+= (TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of floating point of 3D vector
|
||||
*
|
||||
* @param(v1) vector to substract from
|
||||
* @param(s) floating point to substract
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator-= (TIntVector3<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of 3D vector to 3D vector
|
||||
*
|
||||
* @param(v1) vector to substract from
|
||||
* @param(v2) vector to substract with
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator-= (TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Dot product between two 3D Vectors
|
||||
*
|
||||
* @param(v1) vector one
|
||||
* @param(s) floating point
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator*= (TIntVector3<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise multiplication of 3D Vectors with floating point
|
||||
*
|
||||
* @param(v1) vector one
|
||||
* @param(s) floating point
|
||||
*
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator* (const TIntVector3<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise multiplication of 3D Vectors with floating point
|
||||
*
|
||||
* @param(s) floating point
|
||||
* @param(v2) vector
|
||||
*
|
||||
* @return Resultion vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline TIntVector3<T> operator* (T s, const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Dot product between two 3D Vectors
|
||||
*
|
||||
* @param(v1) vector one
|
||||
* @param(v2) vector two
|
||||
*
|
||||
* @return Dot product of Vectors
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T operator* (const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Coponentwise addition of floating point to 3D vector
|
||||
*
|
||||
* @param(v1) vector to add to
|
||||
* @param(s) floating point to add
|
||||
*
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator+ (const TIntVector3<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise addition of 3D vector to 3D vector
|
||||
*
|
||||
* @param(v1) vector to add to
|
||||
* @param(v2) vector to add
|
||||
*
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator+ (const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of floating point of 3D vector
|
||||
*
|
||||
* @param(v1) vector to substract from
|
||||
* @param(s) floating point to substract
|
||||
*
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator- (const TIntVector3<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Coponentwise substraction of floating point of 3D vector
|
||||
*
|
||||
* @param(v1) vector to substract from
|
||||
* @param(v2) vector to substract with
|
||||
*
|
||||
* @return Resulting vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator- (const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Negates vector
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> operator- (TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Tests two 3D vectors for equality.
|
||||
*
|
||||
* @ref [FUNC]Equals
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return True if equal, false if not.
|
||||
*
|
||||
* @note Uses [MACRO]P_FLT_INAC
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool operator== (const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Tests two 3D vectors for inequality.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return True if inequal, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool operator!= (const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
// ============================================== //
|
||||
// IntVector3 static function implementation //
|
||||
// ============================================== //
|
||||
|
||||
/**
|
||||
* Gets magnitude of vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @return Magnitude of vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
inline Rt Magnitude(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* @see [FUNC]Magnitude
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
FORCEINLINE T Length(const TIntVector3<T>& v1) { return Magnitude(v1); };
|
||||
|
||||
/**
|
||||
* Gets square magnitude of vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @return Square magnitude of vector
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline T SqrMagnitude(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* @see SqrMagnitude
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
FORCEINLINE T SqrLength(const TIntVector3<T>& v1) { return SqrMagnitude(v1); };
|
||||
|
||||
/**
|
||||
* Gets angle between two vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Angle between vectors
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
Rt Angle(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Dot product of two vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Dot product of vectors
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T DotP(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Returns signs of components in vector: -1 / +1 / 0.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Vector with signs a components.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> SignVector(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Tests two vectors for equality.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(threshold) Allowed T inaccuracy.
|
||||
*
|
||||
* @return True if equal, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool Equals(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Calculates the cross product between two vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note result is stored in v1.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> CrossPV(TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets the componentwise max of both vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note result is stored in v1.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> MaxV(TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets the componentwise min of both vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note result is stored in v1.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> MinV(TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets reversed vector.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note result is stored in v1.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> NegateV(TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Performes componentwise multiplication of two vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note result is stored in v1.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> ScaleV(TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Copies v1 vector
|
||||
*
|
||||
* @param(v1) Vector to copy to
|
||||
* @param(v2) Vector to copy
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Set(TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Sets vector.
|
||||
*
|
||||
* @param(v1) Vector to copy to
|
||||
* @param(x) X component
|
||||
* @param(y) Y component
|
||||
* @param(z) Z component
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Set(TIntVector3<T>& v1, T x, T y, T z);
|
||||
|
||||
/**
|
||||
* Returns signs of components in vector: -1 / +1 / 0.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> SignVectorV(TIntVector3<T>& v1);
|
||||
|
||||
|
||||
/**
|
||||
* Gets scalar triple product ((v1 x v2) * v3). (Volume of parallelepiped.)
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(v3) Vector three
|
||||
*
|
||||
* @return Vector triple product
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T ScalarTriple(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3);
|
||||
|
||||
/**
|
||||
* Gets the cosine of the angle between to vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Cosine of angle between vectors.
|
||||
* @note Simply omits acos of angle.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
T CosineAngle(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets vector triple product ((v1 x v2) x v3).
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(v3) Vector three
|
||||
*
|
||||
* @note result is stored in v1
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> VectorTripleV(TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3);
|
||||
|
||||
/**
|
||||
* Tests whether two vectors are perpendicular.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(threshold) Allowed T inaccuracy
|
||||
*
|
||||
* @return True if perpendicular, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsPerpendicular(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests whether two vectors are parallel.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f)
|
||||
*
|
||||
* @return True if parallel, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsParallel(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold = 1.0f - P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests whether two vectors are coincident (Parallel and point in same direction).
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f)
|
||||
*
|
||||
* @return True if coincident, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsCoincident(const TIntVector3<T>& v1, const TIntVector3<T>& v2, T threshold = 1.0f - P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests whether v1 vectors is v1 unit vector.
|
||||
*
|
||||
* @param(v1) Vector
|
||||
* @param(threshold) Allowed T inaccuracy
|
||||
*
|
||||
* @return True if unit vector, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsNormalized(const TIntVector3<T>& v1, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests if three vectors are coplanar
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(v3) Vector three
|
||||
* @param(threshold) Allowed T inaccuracy
|
||||
*
|
||||
* @return True if coplanar, false if not.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
inline bool IsCoplanar(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3, T threshold = P_FLT_INAC);
|
||||
|
||||
|
||||
/**
|
||||
* Gets outer product of to vectors.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Resulting matrix
|
||||
*/
|
||||
|
||||
//template<IntType T>
|
||||
//Matrix3<T> OuterProduct(const IntVector3<T>& a, const IntVector3<T>& b);
|
||||
|
||||
|
||||
// ================================================================ //
|
||||
// IntVector3 static function implementation with return values //
|
||||
// ================================================================ //
|
||||
|
||||
/**
|
||||
* Normalized vector
|
||||
*
|
||||
* @param(v1) vector to normalize
|
||||
*
|
||||
* @return Normalized vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> Normalize(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Normalizes vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @note Does not test for zero vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> UnsafeNormalize(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Reflects a vector on a surface
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(normal) Normal of surface
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> Reflect(const TIntVector3<T>& v1, const TVector3<Rt>& normal);
|
||||
|
||||
|
||||
/**
|
||||
* Performes perspective divide on vector.
|
||||
*
|
||||
* @param(v1) vector to perspective divide
|
||||
*
|
||||
* @return Perspective divided vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> PerspectiveDivide(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets cross product between two vectors.
|
||||
*
|
||||
* @param(v1) vector one
|
||||
* @param(v2) vector two
|
||||
*
|
||||
* @return Cross product of v1 and v2
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> CrossP(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Linearly interpolates between two vectors.
|
||||
*
|
||||
* @param(start) Starting vector
|
||||
* @param(dest) Destination vector
|
||||
* @param(t) 0.0 to 1.0 interpolation value
|
||||
*
|
||||
* @return Cross product of v1 and v2
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> Lerp(const TIntVector3<T>& start, const TIntVector3<T>& dest, Rt t);
|
||||
|
||||
/**
|
||||
* Linearly interpolates between two vectors.
|
||||
*
|
||||
* @param(v1) Starting vector
|
||||
* @param(dest) Destination vector
|
||||
* @param(t) 0.0 to 1.0 interpolation value
|
||||
*
|
||||
* @return Cross product of v1 and v2
|
||||
* @note Does not clamp t between 0.0 and 1.0.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> LerpUnclamped(const TIntVector3<T>& start, const TIntVector3<T>& dest, Rt t);
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the componentwise max of both vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Vector of componentwise max
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Max(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the componentwise min of both vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Vector of componentwise min
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Min(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets reversed vector.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note result is stored in v1.
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Negate(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Multiplies vector componentwise.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Vector with componentwise products
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> Scale(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Clamps vector to a range of magnitudes.
|
||||
*
|
||||
* @param(v1) Vector to clamp
|
||||
* @param(min) Min magnitude
|
||||
* @param(max) Max magnitude
|
||||
*
|
||||
* @return Clamped vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> ClampMagnitude(const TIntVector3<T>& v1, T min, T max);
|
||||
|
||||
/**
|
||||
* Binds vector into cube.
|
||||
*
|
||||
* @param(v1) Vector to clamp
|
||||
* @param(cubeRadius) Radius of the cube
|
||||
*
|
||||
* @result Vector clamped in cube.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> BoundToCube(const TIntVector3<T> v1, T cubeRadius) {};
|
||||
|
||||
/**
|
||||
* Clamps vector into cube.
|
||||
*
|
||||
* @param(v1) Vector to clamp
|
||||
* @param(cubeRadius) Radius of the cube
|
||||
*
|
||||
* @result Vector clamped in cube.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> ClampToCube(const TIntVector3<T> v1, T cubeRadius) {};
|
||||
|
||||
/**
|
||||
* Scales vector two specific magnitude.
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @note It's faster to use operator* or operator*= for naturaly normalized vectors.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> ScaleToMagnitude(const TIntVector3<T>& v1, T magnitude);
|
||||
|
||||
/**
|
||||
* Clamps vector into cube.
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @result Vector with inverted components.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> CompInverse(const TIntVector3<T>& v1);
|
||||
|
||||
/**
|
||||
* Reflect by plane
|
||||
*
|
||||
* @param(v1) Vector to mirror
|
||||
* @param(plane) Plane to mirror on
|
||||
*
|
||||
* @return Mirrored vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
FORCEINLINE TVector3<Rt> ReflectFromPlane(const TIntVector3<T>& v1, const TPlane<Rt>& plane);
|
||||
|
||||
/**
|
||||
* Reflect by plane
|
||||
*
|
||||
* @param(v1) Vector to mirror
|
||||
* @param(plane) Normal of plane
|
||||
*
|
||||
* @return Mirrored vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
FORCEINLINE TVector3<Rt> ReflectFromPlane(const TIntVector3<T>& v1, const TVector3<Rt>& normal);
|
||||
|
||||
/**
|
||||
* Rotates vector around axis
|
||||
*
|
||||
* @param(v1) Vector to mirror
|
||||
* @param(axisNormal) Axis to rotate around
|
||||
*
|
||||
* @return Rotated vector
|
||||
* @note Calculates vector rotation with Rodrigues-Rotation
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> RotateAroundAxis(const TIntVector3<T>& v1, const TVector3<Rt>& axisNormal, Rt angle);
|
||||
|
||||
/**
|
||||
* Gets vector triple product ((v1 x v2) x v3).
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(v3) Vector three
|
||||
*
|
||||
* @return Vector triple product
|
||||
*/
|
||||
|
||||
template<IntType T>
|
||||
TIntVector3<T> VectorTriple(const TIntVector3<T>& v1, const TIntVector3<T>& v2, const TIntVector3<T>& v3);
|
||||
|
||||
/**
|
||||
* Projects vector v1 onto v2
|
||||
*
|
||||
* @param(v1) Vector to project
|
||||
* @param(v2) Vector to project on
|
||||
*
|
||||
* @return Projected vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> Project(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Rejects vector v1 from v2
|
||||
*
|
||||
* @param(v1) Vector to reject
|
||||
* @param(v2) Vector to reject from
|
||||
*
|
||||
* @return Rejected vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> Reject(const TIntVector3<T>& v1, const TIntVector3<T>& v2);
|
||||
|
||||
/**
|
||||
* Projects vector onto plane
|
||||
*
|
||||
* @param(v1) Vector to reject
|
||||
* @param(normal) Normal of the plane
|
||||
*
|
||||
* @return Projected vector
|
||||
* @note Simply rejects the vector from normal
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
FORCEINLINE TVector3<Rt> ProjectOntoPlane(const TIntVector3<T>& v1, const TVector3<Rt>& normal);
|
||||
|
||||
/**
|
||||
* Projects vector onto plane
|
||||
*
|
||||
* @param(v1) Vector to reject
|
||||
* @param(normal) Plane
|
||||
*
|
||||
* @return Projected vector
|
||||
* @note Simply rejects the vector from normal
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
FORCEINLINE TVector3<Rt> ProjectOntoPlane(const TIntVector3<T>& v1, const TPlane<Rt>& plane);
|
||||
|
||||
/**
|
||||
* Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation.
|
||||
*
|
||||
* @param(v1) Starting vector
|
||||
* @param(v2) Destination vector
|
||||
* @param(t) 0.0 to 1.0 interpolation value
|
||||
*
|
||||
* @return Interpolated unit vector
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> Slerp(const TIntVector3<T>& v1, const TIntVector3<T>& v2, Rt t) {};
|
||||
|
||||
/**
|
||||
* Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation.
|
||||
*
|
||||
* @param(v1) Starting vector
|
||||
* @param(v2) Destination vector
|
||||
* @param(t) 0.0 to 1.0 interpolation value
|
||||
*
|
||||
* @return Interpolated unit vector.
|
||||
* @note Does not clamp s between 0.0 and 1.0.
|
||||
*/
|
||||
|
||||
template<IntType T, RealType Rt = float>
|
||||
TVector3<Rt> SlerpUnclamped(const TIntVector3<T>& v1, const TIntVector3<T>& v2, Rt t) {};
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
#endif // !INTVECTOR3_H
|
||||
|
941
Engine/src/Runtime/Core/public/Math/IntVector4.h
Normal file
941
Engine/src/Runtime/Core/public/Math/IntVector4.h
Normal file
@ -0,0 +1,941 @@
|
||||
#pragma once
|
||||
|
||||
#include "Misc/BoilerplateHeader.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/MathCommon.h"
|
||||
#include "Math/MathAbstractTypes.h"
|
||||
#include "Math/MathFwd.h"
|
||||
|
||||
|
||||
#ifndef P_DEBUG
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef INTVECTOR4_H
|
||||
#define INTVECTOR4_H
|
||||
|
||||
namespace phanes::core::math::coretypes {
|
||||
|
||||
/**
|
||||
* A 4D Vector with components x, y, z and w with integer precision.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
struct IntVector4 {
|
||||
|
||||
static_assert(std::is_integral_v(T), "T must be an integer type.");
|
||||
|
||||
public:
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
|
||||
/** X component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T x = &components[1];
|
||||
|
||||
/** Y component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T y = &components[1];
|
||||
|
||||
/** Z component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note z does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T z = &components[2];
|
||||
|
||||
/** W component of Vector
|
||||
*
|
||||
* @ref [FIELD]components
|
||||
*
|
||||
* @note w does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
T w = &components[3];
|
||||
|
||||
};
|
||||
|
||||
/** Components array holding the data
|
||||
*
|
||||
* @ref [FIELD]x
|
||||
* @ref [FIELD]y
|
||||
* @ref [FIELD]z
|
||||
* @ref [FIELD]w
|
||||
*
|
||||
* @note Components are split into x, y, z and w. Access and manipulation is possible by these variables.
|
||||
*/
|
||||
|
||||
T components[4];
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor without initialization
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4() = default;
|
||||
|
||||
|
||||
/**
|
||||
* Construct Vector from xy components.
|
||||
*
|
||||
* @param x X component
|
||||
* @param y Y component
|
||||
* @param z Z component
|
||||
* @param w W component
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const T x, const T y, const T z, const T w);
|
||||
|
||||
/**
|
||||
* Construct Vector from two component array.
|
||||
*
|
||||
* @param comp Array of components
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const T comp[4]);
|
||||
|
||||
/**
|
||||
* Construct Vector from 2D Vector's xy and the last two zero.
|
||||
*
|
||||
* @param v 2D IntVector to copy from
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const Vector2<T>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 3D Vector's xyz and zero.
|
||||
*
|
||||
* @param v 3D Vector to copy from
|
||||
*/
|
||||
|
||||
|
||||
PHANES_CORE_API IntVector4(const Vector3<T>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 4D Vector's xyzw.
|
||||
*
|
||||
* @param v 4D Vector to copy from
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const Vector4<T>& v);
|
||||
|
||||
|
||||
/**
|
||||
* Construct Vector from 2D integer Vector's xy and the last two zero.
|
||||
*
|
||||
* @param v 3D IntVector to copy from
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const IntVector2<T>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 4D integer Vector's xyz and zero.
|
||||
*
|
||||
* @param v 4D IntVector to copy from
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const IntVector3<T>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 3D Point's xyzw.
|
||||
*
|
||||
* @param v 3D Point to copy from
|
||||
*/
|
||||
|
||||
PHANES_CORE_API IntVector4(const IntPoint4<T>& v);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
// List of IntVector4 for DoP and ECS
|
||||
|
||||
// List of 4D Vectors using int
|
||||
using IntVector4List = std::vector <IntVector4<int>>;
|
||||
|
||||
|
||||
|
||||
// ======================== //
|
||||
// IntVector4 operators //
|
||||
// ======================== //
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Addition operation on same IntVector4 (this) by a integer value.
|
||||
*
|
||||
* @param a Vector to add to
|
||||
* @param s integer to add
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator+= (IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Addition operation on same IntVector4 (this) by a another IntVector4.
|
||||
*
|
||||
* @param a Vector to add to
|
||||
* @param b Vector to add
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator+= (IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Substraction operation on same IntVector4 (this) by a integer.
|
||||
*
|
||||
* @param a Vector to substract from
|
||||
* @param b integer to substract
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator-= (IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Substraction operation on same IntVector4 (this) by a another IntVector4.
|
||||
*
|
||||
* @param a Vector to substract from
|
||||
* @param b Vector to substract
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator-= (IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Multiplication of IntVector4 (this) with a integer. (Scale)
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to multiply with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator*= (IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Devision of Vector (this) by integer.
|
||||
*
|
||||
* @ref [FUNC]DivideTruncV
|
||||
* @ref [FUNC]DivideFloatV
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to divide with
|
||||
*
|
||||
* @note Rounds components
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator/= (IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise divison of Vector (this) by another vector
|
||||
*
|
||||
* @ref [FUNC]DivideTruncV
|
||||
* @ref [FUNC]DivideFloatV
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param b Vector to divide with
|
||||
*
|
||||
* @note Rounds components
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator/= (IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Scale of Vector by integer. (> Creates a new IntVector4)
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to multiply with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator* (const IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Scale of Vector by integer. (> Creates a new IntVector4)
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to multiply with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator* (T s, const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Dot product between two Vectors.
|
||||
*
|
||||
* @ref [FUNC]DotP
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @result Dot product
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API T operator* (const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Division of Vector by integer. (> Creates another IntVector4)
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to divide with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator/ (const IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Division of Vector by integer. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.)
|
||||
*
|
||||
* @ref [FUNC]DivideTrunc
|
||||
* @ref [FUNC]DivideFloat
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to divide with
|
||||
*
|
||||
* @note Rounds components
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator/ (T s, const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise division of Vector (> For convenience not arithmethicaly correct. Works like overloaded counterpart.)
|
||||
*
|
||||
* @ref [FUNC]DivideTrunc
|
||||
* @ref [FUNC]DivideFloat
|
||||
*
|
||||
* @param a Vector to multiply with
|
||||
* @param s integer to divide with
|
||||
*
|
||||
* @note Rounds components
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator/ (const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise addition of Vector with integer.
|
||||
*
|
||||
* @param a Vector to add to
|
||||
* @param s integer to add
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator+ (const IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise addition of Vector with integer.
|
||||
*
|
||||
* @param a Vector to add to
|
||||
* @param s integer to add
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator+ (const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise substraction of Vector with integer.
|
||||
*
|
||||
* @param a Vector to substract from
|
||||
* @param s integer to substract
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator- (const IntVector4<T>& a, T s);
|
||||
|
||||
/**
|
||||
* Componentwise substraction of Vector with Vector.
|
||||
*
|
||||
* @param a Vector to substract from
|
||||
* @param s integer to substract
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> operator- (const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Negate Vector.
|
||||
*
|
||||
* @param a Vector to negate
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API void operator- (IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Compare Vector for equality.
|
||||
*
|
||||
* @ref [FUNC]Equals
|
||||
*
|
||||
* @param a Vector to negate
|
||||
*
|
||||
* @return true if equal, false if inequal
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API bool operator== (const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Compare Vector for inequality.
|
||||
*
|
||||
* @ref [FUNC]Equals
|
||||
*
|
||||
* @param a Vector to negate
|
||||
*
|
||||
* @return true if inequal, false if equal
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API bool operator!= (const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
// ============================================== //
|
||||
// IntVector4 static function implementation //
|
||||
// ============================================== //
|
||||
|
||||
/**
|
||||
* Magnitude of Vector
|
||||
*
|
||||
* @param a Vector
|
||||
*
|
||||
* @return Size of Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API T Magnitude(const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Square of magnitude of Vector
|
||||
*
|
||||
* @param a Vector
|
||||
*
|
||||
* @return Magnitude without calculating square root
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API T SqrMagnitude(const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Normalize Vector
|
||||
*
|
||||
* @param a Vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void NormalizeV(IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Angle between to Vectors
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API T Angle(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Dot product of two Vectors
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API T DotP(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Creates Vector, with component wise largest values.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void MaxV(IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Creates Vector, with component wise smallest values.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void MinV(IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Gets perpendicular Vector to a.
|
||||
*
|
||||
* @reg NO_RETURN(ReversePerpendicular)
|
||||
*
|
||||
* @param a Vector one
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void PerpendicularV(IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Gets perpendicular Vector to a.
|
||||
*
|
||||
* @reg NO_RETURN(Perpendicular)
|
||||
*
|
||||
* @param a Vector one
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void ReversePerpendicularV(IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise multiplication of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void ScaleV(IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Truncates result instead of rounding
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void DivideTruncV(IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Truncates result instead of rounding
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void DivideTruncV(IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise inversion of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void CompInverseV(IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Reflect Vector by normal vector.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Stores new Vector to a
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void ReflectV(IntVector4<T>& a, const IntVector4<T>& normal);
|
||||
|
||||
|
||||
/**
|
||||
* Copies one Vector two another
|
||||
*
|
||||
* @param a Vector to copy to
|
||||
* @param b Vector to copy
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void Set(IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Sets components of a vector.
|
||||
*
|
||||
* @param a Vector to copy to
|
||||
* @param b Vector to copy
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API void Set(IntVector4<T>& a, T x, T y, T z, T w);
|
||||
|
||||
|
||||
/**
|
||||
* Tests if vector is a unity vector.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param threshold Threshold to one
|
||||
*
|
||||
* @return true if unit vector, false if not
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API bool IsNormalized(const IntVector4<T>& a, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are perpendicular to each other.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
* @param threshold Threshold
|
||||
*
|
||||
* @return true if perpendicular, false if not
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API bool IsPerpendicular(const IntVector4<T>& a, const IntVector4<T>& b, T threshold = P_FLT_INAC);
|
||||
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are parallel to each other. (Angle is close to zero.)
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
* @param threshold Threshold
|
||||
*
|
||||
* @return true if parallel, false if not
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API bool IsParallel(const IntVector4<T>& a, const IntVector4<T>& b, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are coincident. (Are parallel and point in the same direction.)
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
* @param threshold Threshold
|
||||
*
|
||||
* @return true if coincident, false if not
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API bool IsCoincident(const IntVector4<T>& a, const IntVector4<T>& b, T threshold = P_FLT_INAC);
|
||||
|
||||
|
||||
/**
|
||||
* Gets outer product of to vectors.
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Resulting matrix
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API Matrix2<T> OuterProduct(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
// ================================================================ //
|
||||
// IntVector4 static function implementation with return values //
|
||||
// ================================================================ //
|
||||
|
||||
|
||||
/**
|
||||
* Reflects a vector on a normal
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param normal Normal vector
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Reflect(const IntVector4<T>& a, const IntVector4<T>& normal);
|
||||
|
||||
|
||||
/**
|
||||
* Scales a vector component wise
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Scale(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Truncates result instead of rounding
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> DivideTrunc(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @note Truncates result instead of rounding
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> DivideTrunc(const IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Floating point vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API Vector2<T> DivideFloat(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Component wise division of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Floating point vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API Vector2<T> DivideFloat(const IntVector4<T>& a, T s);
|
||||
|
||||
|
||||
/**
|
||||
* Componentwise inverse of Vector
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> CompInverse(const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the perpendicular vector of a
|
||||
*
|
||||
* @param a Vector one
|
||||
*
|
||||
* @return Perpendicular vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Perpendicular(const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Gets reverse of the perpendicular vector of a
|
||||
*
|
||||
* @param a Vector one
|
||||
*
|
||||
* @return Reversed perpendicular vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> ReversePerpendicular(const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the component wise minimals of both vectors
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Minimal vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Min(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the component wise maxima of both vectors
|
||||
*
|
||||
* @param a Vector one
|
||||
* @param b Vector two
|
||||
*
|
||||
* @return Maximal vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Max(const IntVector4<T>& a, const IntVector4<T>& b);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a normalized instance of the vector
|
||||
*
|
||||
* @param a Vector to normalize
|
||||
*
|
||||
* @return Unit vector
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Normalize(const IntVector4<T>& a);
|
||||
|
||||
|
||||
/**
|
||||
* Interpolates between to vectors.
|
||||
*
|
||||
* @param a Start value (t = 0)
|
||||
* @param b End value (t = 1)
|
||||
* @param t Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is clamped between 0 - 1.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> Lerp(const IntVector4<T>& a, const IntVector4<T>& b, T t);
|
||||
|
||||
|
||||
/**
|
||||
* Interpolates between to vectors.
|
||||
*
|
||||
* @param a Start value (t = 0)
|
||||
* @param b End value (t = 1)
|
||||
* @param t Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is not clamped.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
INLINE PHANES_CORE_API IntVector4<T> LerpUnclamped(const IntVector4<T>& a, const IntVector4<T>& b, T t);
|
||||
|
||||
|
||||
/**
|
||||
* Spherical interpolation between two vectors.
|
||||
*
|
||||
* @param a Start value (t = 0)
|
||||
* @param b End value (t = 1)
|
||||
* @param t Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is clamped between 0 - 1.
|
||||
* @note Quaternion are more efficient and should be used if possible.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> Slerp(const IntVector4<T>& a, const IntVector4<T>& b, T t);
|
||||
|
||||
|
||||
/**
|
||||
* Spherical interpolation between two vectors.
|
||||
*
|
||||
* @param a Start value (t = 0)
|
||||
* @param b End value (t = 1)
|
||||
* @param t Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is clamped between 0 - 1.
|
||||
* @note Quaternion are more efficient and should be used if possible.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
PHANES_CORE_API IntVector4<T> SlerpUnclamped(const IntVector4<T>& a, const IntVector4<T>& b, T t);
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
#endif // !INTVECTOR3_H
|
||||
|
29
Engine/src/Runtime/Core/public/Math/MathAbstractTypes.h
Normal file
29
Engine/src/Runtime/Core/public/Math/MathAbstractTypes.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef ABSTRACT_TYPES_H
|
||||
#define ABSTRACT_TYPES_H
|
||||
|
||||
namespace Phanes::Core::Math::Internal {
|
||||
|
||||
template <typename T, unsigned int D = 3>
|
||||
struct AVector {
|
||||
public:
|
||||
|
||||
/**
|
||||
* List of n components of the vector
|
||||
*/
|
||||
|
||||
T comp[D];
|
||||
|
||||
};
|
||||
|
||||
template <typename T, unsigned int n = 3, unsigned int m = 3>
|
||||
struct AMatrix {
|
||||
public:
|
||||
T fields[n][m];
|
||||
|
||||
};
|
||||
|
||||
}; // Phanes::Core::Math::abstract::coretypes
|
||||
|
||||
#endif // !ABSTRACT_TYPES_H
|
98
Engine/src/Runtime/Core/public/Math/MathCommon.h
Normal file
98
Engine/src/Runtime/Core/public/Math/MathCommon.h
Normal file
@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#define P_FLT_INAC_LARGE 0.0001f // large float inaccuracy (1*10^-4);
|
||||
#define P_FLT_INAC 0.00001f // float inaccuracy (1*10^-5);
|
||||
#define P_FLT_INAC_SMALL 0.000001f // small float inaccuracy (1*10^-6);
|
||||
|
||||
#define P_180_PI 57.29577951308232 // (double) 180°/pi;
|
||||
#define P_180_PI_FLT 57.29577951308232f // (float) 180°/pi;
|
||||
|
||||
#define P_PI_180 0.0174532925199432 // double pi/180°
|
||||
#define P_PI_180_FLT 0.0174532925199432f // (float) pi/180°
|
||||
|
||||
#define P_PI 3.1415926535897932 // PI
|
||||
#define P_PI_FLT 3.1415926535897932f // PI
|
||||
|
||||
|
||||
#include "Core/Core.h"
|
||||
|
||||
#ifndef MATH_COMMON_H
|
||||
#define MATH_COMMON_H
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* Clamps a value between minimum and maximum
|
||||
*
|
||||
* @param value Value to clamp
|
||||
* @param low Minimum
|
||||
* @param high Maximum
|
||||
*
|
||||
* @return Minimum, if value is to small / Maximum, if value is to large / value, if value is in range.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T Clamp(T value, T low, T high);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the larger of two values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*
|
||||
* @return Larger value
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
inline T Max(T x, T y);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the smaller of two values
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*
|
||||
* @return Smaller value
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
inline T Min(T x, T y);
|
||||
|
||||
/**
|
||||
* Swaps the values of two variables
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
inline void Swap(T& x, T& y);
|
||||
|
||||
/**
|
||||
* Test two numbers for equality
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
template<typename T>
|
||||
bool Equals(T x, T y, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Calculates the reciprocal of the square root of n using the algorithm of A Quake III
|
||||
*
|
||||
* @param n Number to calculate
|
||||
*
|
||||
* @return Inverse square root of n
|
||||
*
|
||||
* @note a simple 1.0f / sqrtf(x) is faster than this algorithm. Use for research purpose only.
|
||||
*/
|
||||
|
||||
|
||||
template<typename T>
|
||||
float FastInvSqrt(T n);
|
||||
|
||||
|
||||
} // phanes
|
||||
|
||||
#endif // !MATH_COMMON_H
|
103
Engine/src/Runtime/Core/public/Math/MathFwd.h
Normal file
103
Engine/src/Runtime/Core/public/Math/MathFwd.h
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/Core.h"
|
||||
|
||||
#include "Core/public/OSAL/PlatformTypes.h"
|
||||
|
||||
#ifndef MATH_FWD_H
|
||||
#define MATH_FWD_H
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
/**
|
||||
* Includes forward declarations, as well as certain useful typedefs.
|
||||
*
|
||||
* @ref OSAL/PlatformTypes.h
|
||||
*/
|
||||
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* Template forward declarations.
|
||||
*/
|
||||
|
||||
template<RealType T> struct TColor;
|
||||
template<RealType T> struct TLinearColor;
|
||||
template<RealType T> struct TVector2;
|
||||
template<RealType T> struct TVector3;
|
||||
template<RealType T> struct TVector4;
|
||||
template<RealType T> struct TRay;
|
||||
template<RealType T> struct TPlane;
|
||||
template<RealType T> struct TMatrix2;
|
||||
template<RealType T> struct TMatrix3;
|
||||
template<RealType T> struct TMatrix4;
|
||||
template<RealType T> struct TQuaternion;
|
||||
template<RealType T> struct TTransform;
|
||||
template<RealType T> struct TPoint2;
|
||||
template<RealType T> struct TPoint3;
|
||||
template<RealType T> struct TPoint4;
|
||||
template<IntType T> struct TIntVector2;
|
||||
template<IntType T> struct TIntVector3;
|
||||
template<IntType T> struct TIntVector4;
|
||||
template<IntType T> struct TIntPoint2;
|
||||
template<IntType T> struct TIntPoint3;
|
||||
template<IntType T> struct TIntPoint4;
|
||||
|
||||
/**
|
||||
* Specific instantiation of forward declarations.
|
||||
*/
|
||||
|
||||
// TVector2
|
||||
typedef TVector2<float> Vector2;
|
||||
typedef TVector2<double> Vector2d;
|
||||
|
||||
typedef std::vector<Vector2> Vector2List;
|
||||
typedef std::vector<Vector2d> Vector2Listd;
|
||||
|
||||
// TVector3
|
||||
typedef TVector3<float> Vector3;
|
||||
typedef TVector3<double> Vector3d;
|
||||
|
||||
typedef std::vector<Vector3> Vector3List;
|
||||
typedef std::vector<Vector3d> Vector3Listd;
|
||||
|
||||
|
||||
|
||||
// TIntVector2
|
||||
typedef TIntVector2<int> IntVector2;
|
||||
typedef TIntVector2<long> IntVector2l;
|
||||
|
||||
typedef std::vector<IntVector2> IntVector2List;
|
||||
typedef std::vector<IntVector2l> IntVector2Listl;
|
||||
|
||||
// TIntVector3
|
||||
typedef TIntVector3<int> IntVector3;
|
||||
typedef TIntVector3<long> IntVector3l;
|
||||
|
||||
typedef std::vector<IntVector3> IntVector3List;
|
||||
typedef std::vector<IntVector3l> IntVector3Listl;
|
||||
|
||||
|
||||
|
||||
// TMatrix2
|
||||
typedef TMatrix2<float> Matrix2;
|
||||
typedef TMatrix2<double> Matrix2d;
|
||||
|
||||
typedef std::vector<Matrix2> Matrix2List;
|
||||
typedef std::vector<Matrix2d> Matrix2Listd;
|
||||
|
||||
} // Phanes::Core::Math::coretypes
|
||||
|
||||
namespace Phanes::Core::Math::Internal
|
||||
{
|
||||
|
||||
// Internal types
|
||||
|
||||
template <typename T, unsigned int D> struct AVector;
|
||||
|
||||
template <typename T, unsigned int n, unsigned int> struct AMatrix;
|
||||
}
|
||||
|
||||
|
||||
#endif // !MATH_FWD_H
|
77
Engine/src/Runtime/Core/public/Math/MathTypeConversion.h
Normal file
77
Engine/src/Runtime/Core/public/Math/MathTypeConversion.h
Normal file
@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
// ============================================= //
|
||||
// Function to convert types into each other //
|
||||
// //
|
||||
// @ref [FILE]MathUnitConversion //
|
||||
// ============================================= //
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/Vector2.h"
|
||||
#include "Core/public/Math/Vector3.h"
|
||||
//#include "Core/public/Math/Vector4.h"
|
||||
//#include "Core/public/Math/Matrix2.h"
|
||||
//#include "Core/public/Math/Matrix3.h"
|
||||
#include "Core/public/Math/IntVector2.h"
|
||||
#include "Core/public/Math/IntVector3.h"
|
||||
|
||||
#ifndef MATH_TYPE_CONVERSION_H
|
||||
#define MATH_TYPE_CONVERSION_H
|
||||
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
// =================================================== //
|
||||
// std::to_string wrapper //
|
||||
// //
|
||||
// This is, to make using ToString more general //
|
||||
// and allow usage of one function instead of two, //
|
||||
// for converting a mathmatical type to a string. //
|
||||
// =================================================== //
|
||||
|
||||
FORCEINLINE std::string ToString(long long val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(double val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(float val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(int val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(long val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(long double val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(unsigned long long val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(unsigned int val) { return std::to_string(val); };
|
||||
|
||||
FORCEINLINE std::string ToString(unsigned long val) { return std::to_string(val); };
|
||||
|
||||
// ============ //
|
||||
// ToString //
|
||||
// ============ //
|
||||
|
||||
template<RealType T>
|
||||
std::string ToString(const TVector2<T>& v);
|
||||
|
||||
template<IntType T>
|
||||
std::string ToString(const TIntVector2<T>& v);
|
||||
|
||||
template<RealType T>
|
||||
std::string ToString(const TVector3<T>& v);
|
||||
|
||||
template<IntType T>
|
||||
std::string ToString(const TIntVector3<T>& v);
|
||||
|
||||
//std::string toString(const Vector4& v);
|
||||
|
||||
//std::string toString(const Matrix2& v);
|
||||
|
||||
//std::string toString(const Matrix3& v);
|
||||
|
||||
}
|
||||
|
||||
#endif // !MATH_TYPE_CONVERSION_H
|
121
Engine/src/Runtime/Core/public/Math/MathUnitConversion.h
Normal file
121
Engine/src/Runtime/Core/public/Math/MathUnitConversion.h
Normal file
@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
// ======================================= //
|
||||
// Contains functions to convert units //
|
||||
// ======================================= //
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
|
||||
namespace Phanes::Core::Math::UnitConversion
|
||||
{
|
||||
|
||||
/**
|
||||
* Converts degrees to radians.
|
||||
*
|
||||
* @param(deg) Angle in degress (°)
|
||||
*
|
||||
* @return Angle in radians
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline T DegToRad(T deg);
|
||||
|
||||
/**
|
||||
* Converts radians to degrees.
|
||||
*
|
||||
* @param(rad) Angle in radians (rad)
|
||||
*
|
||||
* @return Angle in degrees
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline T RadToDeg(T rad);
|
||||
|
||||
/**
|
||||
* Converts degrees to gradian.
|
||||
*
|
||||
* @param(deg) Angle in degress (°)
|
||||
*
|
||||
* @return Angle in gradian
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline T DegToGradian(T deg);
|
||||
|
||||
/**
|
||||
* Converts gradian to degrees.
|
||||
*
|
||||
* @param(rad) Angle in gradians (g)
|
||||
*
|
||||
* @return Angle in degrees
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline T GradianToDeg(T g);
|
||||
|
||||
/**
|
||||
* Converts radians to gradians.
|
||||
*
|
||||
* @param(deg) Angle in radians (rad)
|
||||
*
|
||||
* @return Angle in gradians
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline T RadToGradian(T rad);
|
||||
|
||||
/**
|
||||
* Converts gradian to radians.
|
||||
*
|
||||
* @param(rad) Angle in gradians (g)
|
||||
*
|
||||
* @return Angle in radians
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline T GradianToRad(T g);
|
||||
|
||||
} // phanes::core::math::typeconversion
|
||||
|
||||
|
||||
namespace Phanes::Core::Math::UnitLiterals
|
||||
{
|
||||
// ============================================== //
|
||||
// unit conversion with user-defined literals //
|
||||
// ============================================== //
|
||||
|
||||
/**
|
||||
* Convert deg to rad.
|
||||
*
|
||||
* @param(_x) Angle in degress
|
||||
*/
|
||||
|
||||
double operator ""_deg(long double _x)
|
||||
{
|
||||
return _x * P_PI_180_FLT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert rad to rad.
|
||||
*
|
||||
* @param(_x) Angle in degress
|
||||
*/
|
||||
|
||||
double operator ""_rad(long double _x)
|
||||
{
|
||||
return _x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gradian to rad.
|
||||
*
|
||||
* @param(_x) Angle in degress
|
||||
*/
|
||||
|
||||
double operator ""_g(long double _x)
|
||||
{
|
||||
return _x * P_PI_FLT / 200;
|
||||
}
|
||||
}
|
154
Engine/src/Runtime/Core/public/Math/Matrix2.h
Normal file
154
Engine/src/Runtime/Core/public/Math/Matrix2.h
Normal file
@ -0,0 +1,154 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/Core.h"
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/Vector2.h"
|
||||
|
||||
#ifndef MATRIX2_H
|
||||
#define MATRIX2_H
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
// 2x2 Matrix defined in column-major order.
|
||||
// Accessed by M[Row][Col].
|
||||
|
||||
template<RealType T>
|
||||
struct alignas(4) TMatrix2
|
||||
{
|
||||
public:
|
||||
|
||||
alignas(4) T m[2][2];
|
||||
|
||||
public:
|
||||
|
||||
TMatrix2() = default;
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
|
||||
TMatrix2(const TMatrix2<T>& m);
|
||||
|
||||
/**
|
||||
* Move constructor.
|
||||
*/
|
||||
|
||||
TMatrix2(TMatrix2<T>&& m);
|
||||
|
||||
/**
|
||||
* Construct Matrix from 2d array.
|
||||
*
|
||||
* @param(fields) 2D Array with column major order.
|
||||
*/
|
||||
|
||||
TMatrix2(T fields[2][2]);
|
||||
|
||||
/**
|
||||
* Construct Matrix from parameters.
|
||||
*
|
||||
* @param(n00) M[0][0]
|
||||
* @param(n10) M[1][0]
|
||||
* @param(n01) M[0][1]
|
||||
* @param(n11) M[1][1]
|
||||
*
|
||||
* @note nXY = n[Row][Col]
|
||||
*/
|
||||
|
||||
TMatrix2(T n00, T n10, T n01, T n11);
|
||||
|
||||
/**
|
||||
* Construct Matrix from two 2d vector columns.
|
||||
*
|
||||
* @param(v1) Column zero
|
||||
* @param(v2) Column one
|
||||
*/
|
||||
|
||||
TMatrix2(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
public:
|
||||
|
||||
FORCEINLINE T& operator() (int n, int m);
|
||||
FORCEINLINE TVector2<T>& operator[] (int m);
|
||||
|
||||
FORCEINLINE const T& operator() (int n, int m) const;
|
||||
FORCEINLINE const TVector2<T>& operator[] (int m) const;
|
||||
};
|
||||
|
||||
// ==================== //
|
||||
// Matrix2 operator //
|
||||
// ==================== //
|
||||
|
||||
template<RealType T>
|
||||
void operator+= (TMatrix2<T>& m1, T s);
|
||||
|
||||
template<RealType T>
|
||||
void operator+= (TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
template<RealType T>
|
||||
void operator-= (TMatrix2<T>& m1, T s);
|
||||
|
||||
template<RealType T>
|
||||
void operator-= (TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
template<RealType T>
|
||||
void operator*= (TMatrix2<T>& m1, T s);
|
||||
|
||||
template<RealType T>
|
||||
void operator*= (TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> operator+ (const TMatrix2<T>& m1, T s);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> operator+ (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> operator- (const TMatrix2<T>& m1, T s);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> operator- (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> operator* (const TMatrix2<T>& m1, T s);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> operator* (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator* (const TMatrix2<T>& m1, const TVector2<T>& v);
|
||||
|
||||
template<RealType T>
|
||||
bool operator== (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
|
||||
|
||||
|
||||
// =============================== //
|
||||
// Matrix function definition //
|
||||
// =============================== //
|
||||
|
||||
template<RealType T>
|
||||
T Determinant(const Matrix2& m1);
|
||||
|
||||
template<RealType T>
|
||||
void InverseV(TMatrix2<T>& m1);
|
||||
|
||||
template<RealType T>
|
||||
void TransposeV(TMatrix2<T>& m1);
|
||||
|
||||
// =============== //
|
||||
// WITH RETURN //
|
||||
// =============== //
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> Inverse(TMatrix2<T>& m1);
|
||||
|
||||
template<RealType T>
|
||||
TMatrix2<T> Transpose(const TMatrix2<T>& m1);
|
||||
|
||||
template<RealType T>
|
||||
bool IsIndentityMatrix(const TMatrix2<T>& m1, T threshold = P_FLT_INAC);
|
||||
|
||||
} // Phanes::Core::Math
|
||||
|
||||
|
||||
#endif // !MATRIX2_H
|
105
Engine/src/Runtime/Core/public/Math/Matrix3.h
Normal file
105
Engine/src/Runtime/Core/public/Math/Matrix3.h
Normal file
@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include "Misc/BoilerplateHeader.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/MathAbstractTypes.h"
|
||||
#include "Math/Vector3.h"
|
||||
|
||||
#ifndef MATRIX3_H
|
||||
#define MATRIX3_H
|
||||
|
||||
namespace phanes {
|
||||
|
||||
namespace core {
|
||||
|
||||
namespace math {
|
||||
|
||||
namespace coretypes {
|
||||
|
||||
// 3x3 Matrix defined in column-major order.
|
||||
|
||||
struct Matrix3 : public phanes::core::math::abstract::coretypes::AMatrix<float, 3, 3>
|
||||
{
|
||||
public:
|
||||
|
||||
FORCEINLINE PHANES_CORE_API float& operator() (int n, int m);
|
||||
FORCEINLINE PHANES_CORE_API Vector3& operator[] (int m);
|
||||
|
||||
FORCEINLINE PHANES_CORE_API const float& operator() (int n, int m) const;
|
||||
FORCEINLINE PHANES_CORE_API const Vector3& operator[] (int m) const;
|
||||
|
||||
};
|
||||
|
||||
// List of Matrices for DoP and ECS
|
||||
typedef std::vector<Matrix3> Matrix3List;
|
||||
|
||||
// Matrix3 constructor
|
||||
PHANES_CORE_API Matrix3 createMatrix(float fields[3][3]);
|
||||
|
||||
PHANES_CORE_API Matrix3 createMatrix(float f00, float f01, float f02,
|
||||
float f10, float f11, float f12,
|
||||
float f20, float f21, float f22);
|
||||
|
||||
PHANES_CORE_API Matrix3 createMatrix(const Vector3& a, const Vector3& b, const Vector3& c);
|
||||
|
||||
|
||||
// ==================== //
|
||||
// Matrix3 operator //
|
||||
// ==================== //
|
||||
|
||||
PHANES_CORE_API void operator+= (Matrix3& a, float s);
|
||||
PHANES_CORE_API void operator+= (Matrix3& a, const Matrix3& b);
|
||||
|
||||
PHANES_CORE_API void operator-= (Matrix3& a, float s);
|
||||
PHANES_CORE_API void operator-= (Matrix3& a, const Matrix3& b);
|
||||
|
||||
PHANES_CORE_API void operator*= (Matrix3& a, float s);
|
||||
PHANES_CORE_API void operator*= (Matrix3& a, const Matrix3& b);
|
||||
|
||||
PHANES_CORE_API Matrix3 operator+ (const Matrix3& a, float s);
|
||||
PHANES_CORE_API Matrix3 operator+ (const Matrix3& a, const Matrix3& b);
|
||||
|
||||
PHANES_CORE_API Matrix3 operator- (const Matrix3& a, float s);
|
||||
PHANES_CORE_API Matrix3 operator- (const Matrix3& a, const Matrix3& b);
|
||||
|
||||
PHANES_CORE_API Matrix3 operator* (const Matrix3& a, float s);
|
||||
PHANES_CORE_API Matrix3 operator* (const Matrix3& a, const Matrix3& b);
|
||||
PHANES_CORE_API Vector3 operator* (const Matrix3& a, const Vector3& v);
|
||||
|
||||
PHANES_CORE_API bool operator== (const Matrix3& a, const Matrix3& b);
|
||||
|
||||
|
||||
|
||||
// =============================== //
|
||||
// Matrix function definition //
|
||||
// =============================== //
|
||||
|
||||
PHANES_CORE_API float determinant(const Matrix3& a);
|
||||
|
||||
|
||||
PHANES_CORE_API void inverseNR(Matrix3& a);
|
||||
|
||||
PHANES_CORE_API void transposeNR(Matrix3& a);
|
||||
|
||||
|
||||
// =============== //
|
||||
// WITH RETURN //
|
||||
// =============== //
|
||||
|
||||
PHANES_CORE_API Matrix3 inverse(Matrix3& a);
|
||||
|
||||
PHANES_CORE_API Matrix3 transpose(const Matrix3& a);
|
||||
|
||||
PHANES_CORE_API bool isIndentityMatrix(const Matrix3& a);
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
} // phanes::core::math
|
||||
|
||||
} // phanes::core
|
||||
|
||||
} // phanes
|
||||
|
||||
|
||||
#endif // !MATRIX3_H
|
103
Engine/src/Runtime/Core/public/Math/Matrix4.h
Normal file
103
Engine/src/Runtime/Core/public/Math/Matrix4.h
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include "Misc/BoilerplateHeader.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/MathAbstractTypes.h"
|
||||
#include "Math/Vector4.h"
|
||||
|
||||
#ifndef MATRIX4_H
|
||||
#define MATRIX4_H
|
||||
|
||||
namespace phanes {
|
||||
|
||||
namespace core {
|
||||
|
||||
namespace math {
|
||||
|
||||
namespace coretypes {
|
||||
|
||||
// 4x4 Matrix defined in column-major order.
|
||||
|
||||
struct Matrix4 : public phanes::core::math::abstract::coretypes::AMatrix<float, 4, 4>
|
||||
{
|
||||
public:
|
||||
|
||||
FORCEINLINE PHANES_CORE_API float& operator() (int n, int m);
|
||||
FORCEINLINE PHANES_CORE_API Vector4& operator[] (int m);
|
||||
|
||||
FORCEINLINE PHANES_CORE_API const float& operator() (int n, int m) const;
|
||||
FORCEINLINE PHANES_CORE_API const Vector4& operator[] (int m) const;
|
||||
};
|
||||
|
||||
// List of Matrices for DoP and ECS
|
||||
typedef std::vector<Matrix4> Matrix4List;
|
||||
|
||||
// Matrix4 constructor
|
||||
PHANES_CORE_API Matrix4 createMatrix(float fields[4][4]);
|
||||
|
||||
PHANES_CORE_API Matrix4 createMatrix(float f00, float f01, float f02, float f03,
|
||||
float f10, float f11, float f12, float f13,
|
||||
float f20, float f21, float f22, float f23,
|
||||
float f30, float f31, float f32, float f33
|
||||
);
|
||||
|
||||
PHANES_CORE_API Matrix4 createMatrix(const Vector4& a, const Vector4& b, const Vector4& c, const Vector4& d);
|
||||
|
||||
// ==================== //
|
||||
// Matrix4 operator //
|
||||
// ==================== //
|
||||
|
||||
PHANES_CORE_API void operator+= (Matrix4& a, float s);
|
||||
PHANES_CORE_API void operator+= (Matrix4& a, const Matrix4& b);
|
||||
|
||||
PHANES_CORE_API void operator-= (Matrix4& a, float s);
|
||||
PHANES_CORE_API void operator-= (Matrix4& a, const Matrix4& b);
|
||||
|
||||
PHANES_CORE_API void operator*= (Matrix4& a, float s);
|
||||
PHANES_CORE_API void operator*= (Matrix4& a, const Matrix4& b);
|
||||
|
||||
PHANES_CORE_API Matrix4 operator+ (const Matrix4& a, float s);
|
||||
PHANES_CORE_API Matrix4 operator+ (const Matrix4& a, const Matrix4& b);
|
||||
|
||||
PHANES_CORE_API Matrix4 operator- (const Matrix4& a, float s);
|
||||
PHANES_CORE_API Matrix4 operator- (const Matrix4& a, const Matrix4& b);
|
||||
|
||||
PHANES_CORE_API Matrix4 operator* (const Matrix4& a, float s);
|
||||
PHANES_CORE_API Matrix4 operator* (const Matrix4& a, const Matrix4& b);
|
||||
PHANES_CORE_API Vector4 operator* (const Matrix4& a, const Vector4& v);
|
||||
|
||||
PHANES_CORE_API bool operator== (const Matrix4& a, const Matrix4& b);
|
||||
|
||||
|
||||
// ================================ //
|
||||
// Matrix4 function definition //
|
||||
// ================================ //
|
||||
|
||||
PHANES_CORE_API float determinant(const Matrix4& a);
|
||||
|
||||
PHANES_CORE_API void inverseNR(Matrix4& a);
|
||||
|
||||
PHANES_CORE_API void transposeNR(Matrix4& a);
|
||||
|
||||
// =============== //
|
||||
// WITH RETURN //
|
||||
// =============== //
|
||||
|
||||
PHANES_CORE_API Matrix4 inverse(Matrix4& a);
|
||||
|
||||
PHANES_CORE_API Matrix4 transpose(const Matrix4& a);
|
||||
|
||||
PHANES_CORE_API bool isIndentityMatrix(const Matrix4& a);
|
||||
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
} // phanes::core::math
|
||||
|
||||
} // phanes::core
|
||||
|
||||
} // phanes
|
||||
|
||||
|
||||
#endif // !MATRIX4_H
|
21
Engine/src/Runtime/Core/public/Math/Plane.h
Normal file
21
Engine/src/Runtime/Core/public/Math/Plane.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/Vector3.h"
|
||||
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
// Plane in 3D space, defined as: P: ax + by + cz = d;
|
||||
|
||||
template<RealType T>
|
||||
struct TPlane
|
||||
{
|
||||
public:
|
||||
TVector3<T> normal;
|
||||
T d;
|
||||
};
|
||||
|
||||
} // Phanes::Core::Math
|
184
Engine/src/Runtime/Core/public/Math/Point.h
Normal file
184
Engine/src/Runtime/Core/public/Math/Point.h
Normal file
@ -0,0 +1,184 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
#ifndef P_DEBUG
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The Point is the same as a vector. The type exists, to ensure
|
||||
* differentiation between the two types.
|
||||
*/
|
||||
|
||||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* A 2D Point with components x and y with float precision.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
struct TPoint2 : public TVector2<T> {
|
||||
static_assert(std::is_floating_point_v<T>, "T must be a floating point");
|
||||
|
||||
using TVector2<T>::TVector2;
|
||||
|
||||
using Real = T;
|
||||
|
||||
/**
|
||||
* Creates Point2 from Point3's xy
|
||||
*
|
||||
* @param a Point3 one
|
||||
*/
|
||||
|
||||
TPoint2(const TPoint3<T>& p)
|
||||
{
|
||||
this->x = p.x;
|
||||
this->y = p.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Point2 from Point4's xy
|
||||
*
|
||||
* @param a Point4 one
|
||||
*/
|
||||
|
||||
TPoint2(const TPoint4<T>& p)
|
||||
{
|
||||
this->x = p.x;
|
||||
this->y = p.y;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates distance between two points.
|
||||
*
|
||||
* @param(p1) Point one
|
||||
* @param(p2) Point two
|
||||
*
|
||||
* @return Distance between two points.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T Distance(const TPoint2<T>& p1, const TPoint2<T>& p2);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* A 3D Point with components x and y with float precision.
|
||||
*/
|
||||
|
||||
|
||||
template<RealType T>
|
||||
struct TPoint3 : public TVector3<T> {
|
||||
static_assert(std::is_floating_point_v(T), "T must be a floating point");
|
||||
|
||||
using TVector3<T>::TVector3;
|
||||
|
||||
using Real = T;
|
||||
|
||||
/**
|
||||
* Creates Point3 from Point2's xy and zero
|
||||
*
|
||||
* @param a Point2 one
|
||||
*/
|
||||
|
||||
TPoint3(const TPoint2<T>& p)
|
||||
{
|
||||
this->x = p.x;
|
||||
this->y = p.y;
|
||||
this->z = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Point3 from Point4's xyz
|
||||
*
|
||||
* @param a Point4 one
|
||||
*/
|
||||
|
||||
TPoint3(const TPoint4<T>& p)
|
||||
{
|
||||
this->x = p.x;
|
||||
this->y = p.y;
|
||||
this->z = p.z;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates distance between two points.
|
||||
*
|
||||
* @param(p1) Point one
|
||||
* @param(p2) Point two
|
||||
*
|
||||
* @return Distance between two points.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T Distance(const TPoint3<T>& p1, const TPoint3<T>& p2);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* A 4D Point with components x and y with float precision.
|
||||
*/
|
||||
|
||||
|
||||
//template<RealType T>
|
||||
//struct TPoint4 : public TVector4<T> {
|
||||
// static_assert(std::is_floating_point_v(T), "T must be a floating point");
|
||||
|
||||
// using TVector4<T>::TVector4;
|
||||
|
||||
// /**
|
||||
// * Creates Point4 from Point2's xy and the last two zero
|
||||
// *
|
||||
// * @param a Point2 one
|
||||
// */
|
||||
|
||||
// TPoint4(const TPoint2<T>& p)
|
||||
// {
|
||||
// this->x = p.x;
|
||||
// this->y = p.y;
|
||||
// this->z = 0;
|
||||
// this->w = 0;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Creates Point4 from Point3's xyz and zero
|
||||
// *
|
||||
// * @param a Point3 one
|
||||
// */
|
||||
|
||||
// TPoint4(const TPoint3<T>& p)
|
||||
// {
|
||||
// this->x = p.x;
|
||||
// this->y = p.y;
|
||||
// this->z = p.z;
|
||||
// this->w = 0;
|
||||
// }
|
||||
//};
|
||||
|
||||
///**
|
||||
// * Calculates distance between two points.
|
||||
// *
|
||||
// * @param(p1) Point one
|
||||
// * @param(p2) Point two
|
||||
// *
|
||||
// * @return Distance between two points.
|
||||
// */
|
||||
|
||||
//template<RealType T>
|
||||
//T Distance(const TPoint4<T>& p1, const TPoint4<T>& p2);
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
#endif // !POINT_H
|
12
Engine/src/Runtime/Core/public/Math/README.md
Normal file
12
Engine/src/Runtime/Core/public/Math/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# PhanesCore
|
||||
|
||||
## Math
|
||||
|
||||
### Description
|
||||
|
||||
Math lib.
|
||||
|
||||
|
||||
### Notes
|
||||
|
||||
- Normals are called normals for a reason.
|
934
Engine/src/Runtime/Core/public/Math/Vector2.h
Normal file
934
Engine/src/Runtime/Core/public/Math/Vector2.h
Normal file
@ -0,0 +1,934 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core/Core.h"
|
||||
#include "Core/public/Misc/Boilerplate.h"
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
#ifndef P_DEBUG
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
#ifndef VECTOR2_H
|
||||
#define VECTOR2_H
|
||||
|
||||
#define PZeroVector2(type) TVector2<##type>(0,0)
|
||||
#define PVectorSouth2(type) TVector2<##type>(0,-1)
|
||||
#define PVectorNorth2(type) TVector2<##type>(0,1)
|
||||
#define PVectorEast2(type) TVector2<##type>(1,0)
|
||||
#define PVectorWest2(type) TVector2<##type>(-1,0)
|
||||
|
||||
|
||||
namespace Phanes::Core::Math {
|
||||
|
||||
/**
|
||||
* A 2D Vector with components x and y with floating point precision.
|
||||
*/
|
||||
|
||||
|
||||
template<RealType T>
|
||||
struct TVector2 {
|
||||
|
||||
public:
|
||||
|
||||
using Real = T;
|
||||
|
||||
// Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa.
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
/** X component of Vector
|
||||
*
|
||||
* @see [FIELD]components
|
||||
* @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
Real x;
|
||||
|
||||
/** Y component of Vector
|
||||
*
|
||||
* @see [FIELD]components
|
||||
*
|
||||
* @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
|
||||
*/
|
||||
Real y;
|
||||
};
|
||||
|
||||
/** Components array holding the data
|
||||
*
|
||||
* @see [FIELD]x
|
||||
* @see [FIELD]y
|
||||
*
|
||||
* @note Components are split into x and y. Access and manipulation is possible by these variables.
|
||||
*/
|
||||
|
||||
Real comp[2];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor without initialization
|
||||
*/
|
||||
|
||||
TVector2() = default;
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
|
||||
TVector2(const TVector2<Real>& v);
|
||||
|
||||
/**
|
||||
* Move constructor
|
||||
*/
|
||||
|
||||
TVector2(TVector2<Real>&& v);
|
||||
|
||||
/**
|
||||
* Convert other type of vector
|
||||
*/
|
||||
|
||||
template<RealType FloatType>
|
||||
explicit TVector2(const TVector2<FloatType>& v) : x((T)v.x), y((T)v.y) {};
|
||||
|
||||
|
||||
template<IntType OtherIntType>
|
||||
explicit TVector2(const TIntVector2<OtherIntType>& v) : x((T)v.x), y((T)v.y) {};
|
||||
|
||||
/**
|
||||
* Construct Vector from xy components.
|
||||
*
|
||||
* @param(x) X component
|
||||
* @param(y) Y component
|
||||
*/
|
||||
|
||||
TVector2(const Real x, const Real y);
|
||||
|
||||
/**
|
||||
* Construct Vector from two component array.
|
||||
*
|
||||
* @param(comp) Array of components
|
||||
*/
|
||||
|
||||
explicit TVector2(const Real* comp);
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a vector pointing from start to end.
|
||||
*
|
||||
* @param(start) Startingpoint
|
||||
* @param(end) Endpoint
|
||||
*/
|
||||
|
||||
TVector2(const TPoint2<Real>& start, const TPoint2<Real>& end);
|
||||
|
||||
/**
|
||||
* Construct Vector from 3D Vector's xy.
|
||||
*
|
||||
* @param(v) 3D Vector to copy from
|
||||
*/
|
||||
|
||||
explicit TVector2(const TVector3<Real>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 4D Vector's xy.
|
||||
*
|
||||
* @param(v) 4D Vector to copy from
|
||||
*/
|
||||
|
||||
//TVector2(const TVector4<Real>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 2D integer Vector's xy.
|
||||
*
|
||||
* @param(v) 2D IntVector to copy from
|
||||
*/
|
||||
|
||||
//TVector2(const TIntVector2<Real>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 3D integer Vector's xy.
|
||||
*
|
||||
* @param(v) 3D IntVector to copy from
|
||||
*/
|
||||
|
||||
//TVector2(const TIntVector3<Real>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 4D integer Vector's xy.
|
||||
*
|
||||
* @param(v) 4D IntVector to copy from
|
||||
*/
|
||||
|
||||
//TVector2(const TIntVector4<Real>& v);
|
||||
|
||||
/**
|
||||
* Construct Vector from 2D Point's xy.
|
||||
*
|
||||
* @param(v) 2D Point to copy from
|
||||
*/
|
||||
|
||||
//TVector2(const TPoint2<Real>& v);
|
||||
|
||||
|
||||
};
|
||||
|
||||
// ====================== //
|
||||
// TVector2 operators //
|
||||
// ====================== //
|
||||
|
||||
/**
|
||||
* Addition operation on same TVector2<T> (this) by a floating point value.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(s) Floating point to add
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator+= (TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Addition operation on same TVector2<T> (this) by a another TVector2<T>.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(v2) Vector to add
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator+= (TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Substraction operation on same TVector2<T> (this) by a floating point.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(v2) Floating point to substract
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator-= (TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Substraction operation on same TVector2<T> (this) by a another TVector2<T>.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(v2) Vector to substract
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator-= (TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Multiplication of TVector2<T> (this) with a floating point.
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to multiply with
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator*= (TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Devision of Vector (this) by floating point.
|
||||
*
|
||||
* @param(v1) Vector to divide with
|
||||
* @param(s Floating point to divide with
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator/= (TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Scale of Vector by floating point. (> Creates a new TVector2<T>)
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to multiply with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator* (const TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Division of Vector by floating point. (> Creates another TVector2<T>)
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to divide with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator/ (const TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Scale of Vector by floating point. (> Creates a new TVector2<T>)
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to multiply with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline TVector2<T> operator* (T s, const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.)
|
||||
*
|
||||
* @param(v1) Vector to multiply with
|
||||
* @param(s Floating point to divide with
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline TVector2<T> operator/ (T s, const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Dot product between two Vectors.
|
||||
*
|
||||
* @see [FUNC]DotP
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @result Dot product
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T operator* (const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise addition of Vector with floating point.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(s Floating point to add
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator+ (const TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Componentwise addition of Vector with floating point.
|
||||
*
|
||||
* @param(v1) Vector to add to
|
||||
* @param(s Floating point to add
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator+ (const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise substraction of Vector with floating point.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(s Floating point to substract
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator- (const TVector2<T>& v1, T s);
|
||||
|
||||
/**
|
||||
* Componentwise substraction of Vector with Vector.
|
||||
*
|
||||
* @param(v1) Vector to substract from
|
||||
* @param(s Floating point to substract
|
||||
*
|
||||
* @return Result Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> operator- (const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Negate Vector.
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
void operator- (TVector2<T>& v1);
|
||||
|
||||
|
||||
/**
|
||||
* Compare Vector for equality.
|
||||
*
|
||||
* @see [FUNC]Equals
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*
|
||||
* @return true if equal, false if inequal
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
bool operator== (const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
|
||||
/**
|
||||
* Compare Vector for inequality.
|
||||
*
|
||||
* @see [FUNC]Equals
|
||||
*
|
||||
* @param(v1) Vector to negate
|
||||
*
|
||||
* @return true if inequal, false if equal
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
bool operator!= (const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
|
||||
// ============================================ //
|
||||
// TVector2 static function implementation //
|
||||
// ============================================ //
|
||||
|
||||
/**
|
||||
* Magnitude of Vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @return Size of Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T Magnitude(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* @see [FUNC]Magnitude
|
||||
*/
|
||||
template<RealType T>
|
||||
FORCEINLINE T Length(const TVector2<T>& v1) { return Magnitude(v1); };
|
||||
|
||||
/**
|
||||
* Square of magnitude of Vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @return Magnitude without calculating square root
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T SqrMagnitude(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* @see [FUNC]SqrMagnitude
|
||||
*/
|
||||
template<RealType T>
|
||||
FORCEINLINE T SqrLength(const TVector2<T>& v1) { return SqrMagnitude(v1); };
|
||||
|
||||
/**
|
||||
* Normalize Vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> NormalizeV(TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Normalize Vector
|
||||
*
|
||||
* @param(v1) Vector
|
||||
*
|
||||
* @note Does not look for zero vector.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> UnsafeNormalizeV(TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Angle between to Vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T Angle(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Cosine of angle between to Vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T CosineAngle(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Returns signs of components in vector: -1 / +1 / 0.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> SignVectorV(TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Binds a vector to a square with a radius
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(radius) Radius of square (=> Distance from middle to center of each site.)
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> BindToSquareV(TVector2<T>& v1, T radius);
|
||||
|
||||
/**
|
||||
* Clamps a vector to a square with a radius
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(radius) Radius of square (=> Distance from middle to center of each site.)
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> ClampToSquareV(TVector2<T>& v1, T radius);
|
||||
|
||||
/**
|
||||
* Dot product of two Vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
T DotP(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates Vector, with component wise largest values.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> MaxV (TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates Vector, with component wise smallest values.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> MinV (TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Gets perpendicular Vector to v1.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> GetPerpendicularV (TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets perpendicular Vector to v1.
|
||||
*
|
||||
* @reg [FUNC]PerpendicularV
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> GetReversePerpendicularV (TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Component wise multiplication of Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> ScaleV(TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise inverse of Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> CompInverseV(TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Reflect Vector by normal vector.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(normal) Normal of surface
|
||||
*
|
||||
* @note Stores new Vector to v1
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> ReflectV (TVector2<T>& v1, const TVector2<T>& normal);
|
||||
|
||||
/**
|
||||
* Copies one Vector two another
|
||||
*
|
||||
* @param(v1) Vector to copy to
|
||||
* @param(v2) Vector to copy
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Set(TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Sets components of a vector.
|
||||
*
|
||||
* @param(v1) Vector to copy to
|
||||
* @param(v2) Vector to copy
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Set(TVector2<T>& v1, T x, T y);
|
||||
|
||||
/**
|
||||
* Anti-clockwise vector rotation.
|
||||
*
|
||||
* @param(v1) Vector to rotate
|
||||
*
|
||||
* @note Angle is not clamped
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> RotateV(TVector2<T>& v1, T angle);
|
||||
|
||||
|
||||
/**
|
||||
* Clockwise vector rotation.
|
||||
*
|
||||
* @param(v1) Vector to rotate
|
||||
*
|
||||
* @note Angle is not clamped
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
FORCEINLINE TVector2<T> ClockwiseRotateV(TVector2<T>& v1, T angle);
|
||||
|
||||
/**
|
||||
* Negates Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> NegateV(TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Tests if vector is a unity vector.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(threshold) Threshold to zero
|
||||
*
|
||||
* @return true if unit vector, false if not
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline bool IsNormalized(const TVector2<T>& v1, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are perpendicular to each other.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(threshold) Threshold to zero
|
||||
*
|
||||
* @return true if perpendicular, false if not
|
||||
*
|
||||
* @note Requires v1 and v2 to be normal vectors.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline bool IsPerpendicular(const TVector2<T>& v1, const TVector2<T>& v2, T threshold = P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are parallel to each other. (Angle is close to zero.)
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(t) threshold Threshold from one (e.g. 0.98f)
|
||||
*
|
||||
* @return true if parallel, false if not
|
||||
*
|
||||
* @note Requires v1 and v2 to be normal vectors.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline bool IsParallel(const TVector2<T>& v1, const TVector2<T>& v2, T threshold = 1.0f - P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Tests if 2 vectors are coincident. (Are parallel and point in the same direction.)
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
* @param(threshold) from one (e.g. 0.98f)
|
||||
*
|
||||
* @return true if coincident, false if not
|
||||
*
|
||||
* @note Requires v1 and v2 to be normal vectors.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
inline bool IsCoincident(const TVector2<T>& v1, const TVector2<T>& v2, T threshold = 1.0f - P_FLT_INAC);
|
||||
|
||||
/**
|
||||
* Gets outer product of to vectors.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Resulting matrix
|
||||
*/
|
||||
|
||||
//
|
||||
//Matrix2 OuterProduct(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
|
||||
// ============================================================== //
|
||||
// TVector2 static function implementation with return values //
|
||||
// ============================================================== //
|
||||
|
||||
|
||||
/**
|
||||
* Reflects a vector on a normal
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(normal) Normal of surface
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Reflect(const TVector2<T>& v1, const TVector2<T>& normal);
|
||||
|
||||
/**
|
||||
* Scales a vector component wise
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Reflected vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Scale(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Componentwise inverse of a vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Componentwise inverted vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> CompInverse(const TVector2<T>& v1);
|
||||
|
||||
|
||||
/**
|
||||
* Negates Vector
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Componentwise inverted vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Negate(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets the perpendicular vector of v1
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Perpendicular vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> GetPerpendicular(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Gets reverse of the perpendicular vector of v1
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Reversed perpendicular vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> GetReversePerpendicular(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the component wise minimals of both vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Minimal vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Min(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates a new Vector by the component wise maxima of both vectors
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(v2) Vector two
|
||||
*
|
||||
* @return Maximal vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Max(const TVector2<T>& v1, const TVector2<T>& v2);
|
||||
|
||||
/**
|
||||
* Creates a normalized instance of the vector
|
||||
*
|
||||
* @param(v1) Vector to normalize
|
||||
*
|
||||
* @return Unit vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Normalize(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Creates a normalized instance of the vector
|
||||
*
|
||||
* @param(v1) Vector to normalize
|
||||
*
|
||||
* @return Unit vector
|
||||
* @note Does not test for zero vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> UnsafeNormalize(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Returns signs of components in vector: -1 / +1 / 0.
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
*
|
||||
* @return Vector with signs as components
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> SignVector(const TVector2<T>& v1);
|
||||
|
||||
/**
|
||||
* Binds a vector to a square with a radius
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(radius) Radius of square (=> Distance from middle to center of each site.)
|
||||
*
|
||||
* @return Bound vector
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> BindToSquare(const TVector2<T>& v1, T radius);
|
||||
|
||||
/**
|
||||
* Clamps a vector to a square with a radius
|
||||
*
|
||||
* @param(v1) Vector one
|
||||
* @param(radius) Radius of square (=> Distance from middle to center of each site.)
|
||||
*
|
||||
* @return Clamped vector. If the length of the vector fits the square, then the vector is returned.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> ClampToSquare(const TVector2<T>& v1, T radius);
|
||||
|
||||
/**
|
||||
* Interpolates between to vectors.
|
||||
*
|
||||
* @param(startVec) Start vector (t = 0)
|
||||
* @param(destVec) Destination vector (t = 1)
|
||||
* @param(t) Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is clamped between 0 - 1.
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Lerp(const TVector2<T>& startVec, const TVector2<T>& destVec, T t);
|
||||
|
||||
/**
|
||||
* Interpolates between to vectors.
|
||||
*
|
||||
* @param(startVec) Start vector (t = 0)
|
||||
* @param(destVec) Destination vector (t = 1)
|
||||
* @param(t) Interpolation value
|
||||
*
|
||||
* @return Interpolated vector
|
||||
*
|
||||
* @note Interpolation is not clamped. Make shure t is between 0.0f and 1.0f
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> LerpUnclamped(const TVector2<T>& startVec, const TVector2<T>& destVec, T t);
|
||||
|
||||
/**
|
||||
* Anti-clockwise vector rotation.
|
||||
*
|
||||
* @param(v1) Vector to rotate
|
||||
* @param(angle) Angle to rotate
|
||||
*
|
||||
* @return Rotated vector
|
||||
*
|
||||
* @note Angle is not clamped
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> Rotate(const TVector2<T>& v1, T angle);
|
||||
|
||||
/**
|
||||
* Clockwise vector rotation.
|
||||
*
|
||||
* @param(v1) Vector to rotate
|
||||
*
|
||||
* @return Rotated vector
|
||||
*
|
||||
* @note Angle is not clamped
|
||||
*/
|
||||
|
||||
template<RealType T>
|
||||
TVector2<T> ClockwiseRotate(const TVector2<T>& v1, T angle);
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
#endif // !VECTOR2_H
|
1191
Engine/src/Runtime/Core/public/Math/Vector3.h
Normal file
1191
Engine/src/Runtime/Core/public/Math/Vector3.h
Normal file
File diff suppressed because it is too large
Load Diff
155
Engine/src/Runtime/Core/public/Math/Vector4.h
Normal file
155
Engine/src/Runtime/Core/public/Math/Vector4.h
Normal file
@ -0,0 +1,155 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Core/public/Math/MathCommon.h"
|
||||
#include "Core/public/Math/MathAbstractTypes.h"
|
||||
#include "Core/public/Math/MathFwd.h"
|
||||
|
||||
#pragma warning(disable : 4244)
|
||||
|
||||
#ifdef P_USE_MATH_CONSTANTS
|
||||
|
||||
|
||||
#endif // P_USE_MATH_CONSTANTS
|
||||
|
||||
#ifndef VECTOR4_H
|
||||
#define VECTOR4_H
|
||||
|
||||
|
||||
namespace phanes {
|
||||
|
||||
namespace core {
|
||||
|
||||
namespace math {
|
||||
|
||||
namespace coretypes {
|
||||
|
||||
// Basis 4D Vector (x, y, z, w)
|
||||
|
||||
template<typename T>
|
||||
struct Vector4 {
|
||||
public:
|
||||
float x, y, z, w;
|
||||
};
|
||||
|
||||
// List of Vector3 for DoP and ECS
|
||||
typedef std::vector<Vector4<T>> Vector4List;
|
||||
|
||||
|
||||
Vector4 createVector(float x, float y, float z, float w);
|
||||
|
||||
|
||||
// ===================== //
|
||||
// Vector4 operators //
|
||||
// ===================== //
|
||||
|
||||
void operator+= (Vector4& a, float s);
|
||||
void operator+= (Vector4& a, const Vector4& b);
|
||||
|
||||
void operator-= (Vector4& a, float s);
|
||||
void operator-= (Vector4& a, const Vector4& b);
|
||||
|
||||
void operator*= (Vector4& a, float s);
|
||||
|
||||
void operator/= (Vector4& a, float s);
|
||||
|
||||
Vector4 operator* (const Vector4& a, float s);
|
||||
|
||||
Vector4 operator/ (const Vector4& a, float s);
|
||||
|
||||
Vector4 operator* (float s, const Vector4& a);
|
||||
|
||||
Vector4 operator/ (float s, const Vector4& a);
|
||||
|
||||
// Vector4 dot-product
|
||||
float operator* (const Vector4& a, const Vector4& b);
|
||||
|
||||
Vector4 operator+ (const Vector4& a, float s);
|
||||
Vector4 operator+ (const Vector4& a, const Vector4& b);
|
||||
|
||||
Vector4 operator- (const Vector4& a, float s);
|
||||
Vector4 operator- (const Vector4& a, const Vector4& b);
|
||||
|
||||
void operator- (Vector4& a);
|
||||
|
||||
bool operator== (const Vector4& a, const Vector4& b);
|
||||
|
||||
|
||||
// ==================================== //
|
||||
// Vector4 function implementation //
|
||||
// ==================================== //
|
||||
|
||||
float magnitude(const Vector4& a);
|
||||
|
||||
float sqrMagnitude(const Vector4& a);
|
||||
|
||||
void normalizeNR(Vector4& a);
|
||||
|
||||
float angle(const Vector4& a, const Vector4& b);
|
||||
|
||||
// dot product between two FVector3. Does the same as operator*
|
||||
float dotP(const Vector4& a, const Vector4& b);
|
||||
|
||||
void scaleToMagnitude(Vector4& a, float magnitude);
|
||||
|
||||
bool equals(const Vector4& a, const Vector4& b, float threshold);
|
||||
|
||||
void Set(Vector4& a, const Vector4& b);
|
||||
|
||||
void perpspectiveDivideNR(Vector4& a);
|
||||
|
||||
void maxNR(Vector4& a, const Vector4& b);
|
||||
|
||||
void minNR(Vector4& a, const Vector4& b);
|
||||
|
||||
void scaleNR(Vector4& a, const Vector4& b);
|
||||
|
||||
void orthogonolize(Vector4& a, Vector4& b, Vector4& c);
|
||||
|
||||
void orthoNormalize(Vector4& a, Vector4& b, Vector4& c);
|
||||
|
||||
// projects vector a onto vector b
|
||||
void projectNR(Vector4& a, const Vector4& b);
|
||||
|
||||
// rejects vector a from vector b
|
||||
void rejectNR(Vector4& a, const Vector4& b);
|
||||
|
||||
|
||||
// ============ //
|
||||
// WITH RETURN: //
|
||||
// ============ //
|
||||
|
||||
Vector4 lerp(const Vector4& a, const Vector4& b, float t);
|
||||
|
||||
Vector4 lerpUnclamped(const Vector4& a, const Vector4& b, float t);
|
||||
|
||||
Vector4 slerp(const Vector4& a, const Vector4& b, float t);
|
||||
|
||||
Vector4 slerpUnclamped(const Vector4& a, const Vector4& b, float t);
|
||||
|
||||
Vector4 max(const Vector4& a, const Vector4& b);
|
||||
|
||||
Vector4 min(const Vector4& a, const Vector4& b);
|
||||
|
||||
Vector4 scale(const Vector4& a, const Vector4& b);
|
||||
|
||||
Vector4 perpspectiveDivide(const Vector4& a);
|
||||
|
||||
Vector4 normalize(const Vector4& a);
|
||||
|
||||
// projects vector a onto vector b
|
||||
Vector4 project(const Vector4& a, const Vector4& b);
|
||||
|
||||
// rejects vector a from vector b
|
||||
Vector4 reject(const Vector4& a, const Vector4& b);
|
||||
|
||||
} // phanes::core::math::coretypes
|
||||
|
||||
} // phanes::core::math
|
||||
|
||||
} // phanes::core
|
||||
|
||||
} // phanes
|
||||
|
||||
|
||||
#endif // !VECTOR4_H
|
11
Engine/src/Runtime/Core/public/Misc/Boilerplate.h
Normal file
11
Engine/src/Runtime/Core/public/Misc/Boilerplate.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
// Typenames with RealType constrain have to be floating point numbers.
|
||||
template<typename T>
|
||||
concept RealType = std::is_floating_point_v<T>;
|
||||
|
||||
// Typenames with IntType constrain have to be integer number.
|
||||
template<typename T>
|
||||
concept IntType = std::is_integral_v<T>;
|
112
Engine/src/Runtime/Core/public/OSAL/PlatformTypes.h
Normal file
112
Engine/src/Runtime/Core/public/OSAL/PlatformTypes.h
Normal file
@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
||||
|
||||
// ============================================= //
|
||||
// Turn os specific types into global types. //
|
||||
// ============================================= //
|
||||
|
||||
|
||||
// TODO: include int128
|
||||
|
||||
namespace Phanes::Core::Types
|
||||
{
|
||||
|
||||
#ifdef P_WIN_BUILD
|
||||
|
||||
// MSCV++ specific types
|
||||
|
||||
typedef FLOAT128 float128;
|
||||
|
||||
//#elif P_UNIX_BUILD
|
||||
//
|
||||
// // GCC specific types
|
||||
//
|
||||
// typedef __float128 float128;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Specific types size
|
||||
//
|
||||
// 8-Bit integer
|
||||
typedef int8_t int8;
|
||||
|
||||
// 16-Bit integer
|
||||
typedef int16_t int16;
|
||||
|
||||
// 32-Bit integer
|
||||
typedef int32_t int32;
|
||||
|
||||
// 64-Bit integer
|
||||
typedef int64_t int64;
|
||||
|
||||
// 8-Bit unsigned integer
|
||||
typedef uint8_t uint8;
|
||||
|
||||
// 16-Bit unsigned integer
|
||||
typedef uint16_t uint16;
|
||||
|
||||
// 32-Bit unsigned integer
|
||||
typedef uint32_t uint32;
|
||||
|
||||
// 64-Bit unsigned integer
|
||||
typedef uint64_t uint64;
|
||||
|
||||
|
||||
|
||||
// At least N bit types
|
||||
//
|
||||
// At least 8-Bit integer
|
||||
typedef int_least8_t lint8;
|
||||
|
||||
// At least 16-Bit integer
|
||||
typedef int_least16_t lint16;
|
||||
|
||||
// At least 32-Bit integer
|
||||
typedef int_least32_t lint32;
|
||||
|
||||
// At least 64-Bit integer
|
||||
typedef int_least64_t lint64;
|
||||
|
||||
// At least 8-Bit integer
|
||||
typedef uint_least8_t ulint8;
|
||||
|
||||
// At least 16-Bit integer
|
||||
typedef uint_least16_t ulint16;
|
||||
|
||||
// At least 32-Bit integer
|
||||
typedef uint_least32_t ulint32;
|
||||
|
||||
// At least 64-Bit integer
|
||||
typedef uint_least64_t ulint64;
|
||||
|
||||
|
||||
|
||||
// Fast N bit types
|
||||
//
|
||||
// Fast 8-bit integer
|
||||
typedef int_fast8_t fint8;
|
||||
|
||||
// At least 16-Bit integer
|
||||
typedef int_fast16_t fint16;
|
||||
|
||||
// At least 32-Bit integer
|
||||
typedef int_fast32_t fint32;
|
||||
|
||||
// At least 64-Bit integer
|
||||
typedef int_fast64_t fint64;
|
||||
|
||||
// At least 8-Bit integer
|
||||
typedef uint_fast8_t ufint8;
|
||||
|
||||
// At least 16-Bit integer
|
||||
typedef uint_fast16_t ufint16;
|
||||
|
||||
// At least 32-Bit integer
|
||||
typedef uint_fast32_t ufint32;
|
||||
|
||||
// At least 64-Bit integer
|
||||
typedef uint_fast64_t ufint64;
|
||||
|
||||
}
|
14
Engine/src/Runtime/Core/public/OSAL/README.md
Normal file
14
Engine/src/Runtime/Core/public/OSAL/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# PhanesCore
|
||||
## Operating System Abstraction Layer (OSAL)
|
||||
|
||||
### Descritpion
|
||||
|
||||
Contains abstraction necessary for cross platform compatability. Including but not limited to specific datatypes.
|
||||
|
||||
### Note
|
||||
|
||||
- The PhanesEngine will have no console support in the near future.
|
||||
|
||||
- Testing will only happen for Windows. GCC compatability will be partitally included, but by far not fully. Though support is planed for future versions.
|
||||
|
||||
- Minimum SSE4.1 is required. To run the engine.
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
// Entry point for Phanes game
|
||||
|
||||
|
||||
#ifdef P_WIN_BUILD
|
||||
|
||||
extern Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreatePhanesGame();
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace Phanes::Core::Application
|
||||
{
|
||||
class PHANES_CORE_API PhanesGame
|
||||
class PhanesGame
|
||||
{
|
||||
|
||||
public:
|
5
Engine/src/Runtime/Phanes.h
Normal file
5
Engine/src/Runtime/Phanes.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// --- Core -------------------
|
||||
|
||||
#include "Core/Include.h"
|
3
Engine/src/Runtime/PhanesEnginePCH.cpp
Normal file
3
Engine/src/Runtime/PhanesEnginePCH.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
// Cpp file for PCH, because Visual Studio
|
||||
|
||||
#include "PhanesEnginePCH.h"
|
28
Engine/src/Runtime/PhanesEnginePCH.h
Normal file
28
Engine/src/Runtime/PhanesEnginePCH.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
// Contains precompiled headers used throught PhanesEngine //
|
||||
#define NOMAXMIN
|
||||
|
||||
#ifndef PHANES_CORE_PCH_H
|
||||
|
||||
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <concepts>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
#ifdef P_WIN_BUILD
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // !PHANES_CORE_PCH_H
|
||||
|
201
LICENSE
201
LICENSE
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -1,41 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34701.34
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PhanesEngine", "PhanesEngine\PhanesEngine.vcxproj", "{A884925E-3EC8-48B0-92E5-99AB92647465}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DevPlayground", "DevPlayground\DevPlayground.vcxproj", "{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Debug|x64.Build.0 = Debug|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Debug|x86.Build.0 = Debug|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Release|x64.ActiveCfg = Release|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Release|x64.Build.0 = Release|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Release|x86.ActiveCfg = Release|x64
|
||||
{A884925E-3EC8-48B0-92E5-99AB92647465}.Release|x86.Build.0 = Release|x64
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Debug|x64.Build.0 = Debug|x64
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Release|x64.ActiveCfg = Release|x64
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Release|x64.Build.0 = Release|x64
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{246C9C0B-21BD-4C7E-B6B7-7DEC3BA5E59F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {468677CF-4EE2-4D98-AB83-D82EB75CA916}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -1,94 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{a884925e-3ec8-48b0-92e5-99ab92647465}</ProjectGuid>
|
||||
<RootNamespace>PhanesEngine</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)bin\$(Configuration)-$(Platform)\$(Projectname)\</OutDir>
|
||||
<IntDir>$(SolutionDir)bin-int\$(Configuration)-$(Platform)\$(Projectname)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>P_WIN_BUILD;P_DLL_EXPORT;P_DEBUG;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)$(ProjectName)\src\Runtime\;$(SolutionDir)$(ProjectName)\src\Runtime\Core\public\</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>P_WIN_BUILD;P_DLL_EXPORT;P_RELEASE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)$(ProjectName)\src\Runtime\;$(SolutionDir)$(ProjectName)\src\Runtime\Core\public\</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Runtime\Core\public\StartingPoint\EntryPoint.h" />
|
||||
<ClInclude Include="src\Runtime\PhanesEngine.h" />
|
||||
<ClInclude Include="src\Runtime\Core\Core.h" />
|
||||
<ClInclude Include="src\Runtime\Core\public\StartingPoint\StartingPoint.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Runtime\Core\private\Math\Vector2.cpp" />
|
||||
<ClCompile Include="src\Runtime\Core\private\StartingPoint\StartingPoint.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Runtime\PhanesEngine.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Runtime\Core\Core.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Runtime\Core\public\StartingPoint\StartingPoint.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Runtime\Core\public\StartingPoint\EntryPoint.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Runtime\Core\private\Math\Vector2.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Runtime\Core\private\StartingPoint\StartingPoint.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef P_WIN_BUILD
|
||||
|
||||
#ifdef P_DLL_EXPORT
|
||||
|
||||
#define PHANES_CORE_API __declspec(dllexport)
|
||||
|
||||
#else
|
||||
|
||||
#define PHANES_CORE_API __declspec(dllimport)
|
||||
|
||||
#endif // P_DLL_EXPORT
|
||||
|
||||
#else
|
||||
|
||||
#error Only Windows is supported at the moment.
|
||||
|
||||
#endif // P_WIN_BUILD
|
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
// ---- Core library -----------------------------
|
||||
|
||||
#include "Core/public/StartingPoint/StartingPoint.h"
|
||||
#include "Core/public/StartingPoint/EntryPoint.h"
|
@ -1,11 +1,10 @@
|
||||
#include <Phanes.h>
|
||||
|
||||
#include <PhanesEngine.h>
|
||||
|
||||
using namespace Phanes::Core::Math;
|
||||
|
||||
class DevPlayground : public Phanes::Core::Application::PhanesGame {};
|
||||
|
||||
|
||||
|
||||
Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreatePhanesGame()
|
||||
{
|
||||
return new DevPlayground();
|
12
Tests/TestProject/Main.cpp
Normal file
12
Tests/TestProject/Main.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "Core/public/Math/Vector2.h"
|
||||
|
||||
namespace PMath = Phanes::Core::Math;
|
||||
|
||||
int main()
|
||||
{
|
||||
float t = 2;
|
||||
PMath::Clamp(t, 2.0f, 4.0f);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
BIN
bin-int/Debug-x64/Engine/CodeAnalysisResultManifest.txt
Normal file
BIN
bin-int/Debug-x64/Engine/CodeAnalysisResultManifest.txt
Normal file
Binary file not shown.
7
bin-int/Debug-x64/Engine/PhanesEngine.lib.recipe
Normal file
7
bin-int/Debug-x64/Engine/PhanesEngine.lib.recipe
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<ProjectOutputs />
|
||||
<ContentFiles />
|
||||
<SatelliteDlls />
|
||||
<NonRecipeFileRefs />
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user