Initial commit.
This commit is contained in:
parent
496a29c08c
commit
a2456a46f5
@ -1,2 +1,4 @@
|
||||
# ReflexToQ3
|
||||
Converter to convert reflex maps into quake-style .map format.
|
||||
|
||||
Usage run from commandline: ReflexToQ3.exe [input].map [output].map
|
||||
|
22
ReflexToQ3.sln
Normal file
22
ReflexToQ3.sln
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.31101.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReflexToQ3", "ReflexToQ3\ReflexToQ3.vcxproj", "{56AE2665-4191-464C-A2D8-80E60D44CE17}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{56AE2665-4191-464C-A2D8-80E60D44CE17}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{56AE2665-4191-464C-A2D8-80E60D44CE17}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{56AE2665-4191-464C-A2D8-80E60D44CE17}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{56AE2665-4191-464C-A2D8-80E60D44CE17}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
90
ReflexToQ3/ReflexToQ3.vcxproj
Normal file
90
ReflexToQ3/ReflexToQ3.vcxproj
Normal file
@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" 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>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{56AE2665-4191-464C-A2D8-80E60D44CE17}</ProjectGuid>
|
||||
<RootNamespace>ReflexToQ3</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</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>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ckmath\ckmath.h" />
|
||||
<ClInclude Include="ckmath\ckmath_constants.h" />
|
||||
<ClInclude Include="ckmath\ckmath_geometry.h" />
|
||||
<ClInclude Include="ckmath\ckmath_matrix.h" />
|
||||
<ClInclude Include="ckmath\ckmath_quaternion.h" />
|
||||
<ClInclude Include="ckmath\ckmath_scalar.h" />
|
||||
<ClInclude Include="ckmath\ckmath_types.h" />
|
||||
<ClInclude Include="ckmath\ckmath_vector.h" />
|
||||
<ClInclude Include="libraries.h" />
|
||||
<ClInclude Include="mapparser.h" />
|
||||
<ClInclude Include="worldspawn.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ckmath\ckmath_geometry.cpp" />
|
||||
<ClCompile Include="ckmath\ckmath_matrix.cpp" />
|
||||
<ClCompile Include="ckmath\ckmath_quaternion.cpp" />
|
||||
<ClCompile Include="ckmath\ckmath_vector.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="mapparser.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
75
ReflexToQ3/ReflexToQ3.vcxproj.filters
Normal file
75
ReflexToQ3/ReflexToQ3.vcxproj.filters
Normal file
@ -0,0 +1,75 @@
|
||||
<?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;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;hm;inl;inc;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>
|
||||
<Filter Include="ckmath">
|
||||
<UniqueIdentifier>{b02e339e-6cfc-4b44-bf71-2d5fb97b9424}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="worldspawn.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libraries.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_constants.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_geometry.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_matrix.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_quaternion.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_scalar.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_types.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ckmath\ckmath_vector.h">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="mapparser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ckmath\ckmath_geometry.cpp">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ckmath\ckmath_matrix.cpp">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ckmath\ckmath_quaternion.cpp">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ckmath\ckmath_vector.cpp">
|
||||
<Filter>ckmath</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mapparser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
20
ReflexToQ3/ckmath/ckmath.h
Normal file
20
ReflexToQ3/ckmath/ckmath.h
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_H__
|
||||
#define __MATH_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_constants.h"
|
||||
#include "ckmath_types.h"
|
||||
#include "ckmath_geometry.h"
|
||||
#include "ckmath_vector.h"
|
||||
#include "ckmath_scalar.h"
|
||||
#include "ckmath_matrix.h"
|
||||
#include "ckmath_quaternion.h"
|
||||
|
||||
#endif
|
17
ReflexToQ3/ckmath/ckmath_constants.h
Normal file
17
ReflexToQ3/ckmath/ckmath_constants.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_CONSTANTS_H__
|
||||
#define __MATH_CONSTANTS_H__
|
||||
|
||||
// Math
|
||||
static const double s_kdTau = 6.2831853071795864769252867665590057683943387987502116;
|
||||
static const double s_kdPi = 3.1415926535897932384626433832795028841971693993751058;
|
||||
static const float s_kfTau = static_cast<const float>(s_kdTau);
|
||||
static const float s_kfPi = static_cast<const float>(s_kdPi);
|
||||
|
||||
#endif
|
121
ReflexToQ3/ckmath/ckmath_geometry.cpp
Normal file
121
ReflexToQ3/ckmath/ckmath_geometry.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_scalar.h"
|
||||
#include "ckmath_vector.h"
|
||||
#include "ckmath_geometry.h"
|
||||
|
||||
const bool IsIntersection(const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC)
|
||||
{
|
||||
const TVector3d kNAxNB = CrossProduct(TVector3d(), _krA.m_Normal, _krB.m_Normal);
|
||||
return(Magnitude(DotProduct(kNAxNB, _krC.m_Normal)) > 0.0);
|
||||
}
|
||||
|
||||
const bool IsIntersection(const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC)
|
||||
{
|
||||
const TVector3f kNAxNB = CrossProduct(TVector3f(), _krA.m_Normal, _krB.m_Normal);
|
||||
return(Magnitude(DotProduct(kNAxNB, _krC.m_Normal)) > 0.0f);
|
||||
}
|
||||
|
||||
const TVector3d& GetIntersection( TVector3d& _rResult,
|
||||
const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC)
|
||||
{
|
||||
const TVector3d kNBxNC = CrossProduct(TVector3d(), _krB.m_Normal, _krC.m_Normal);
|
||||
const TVector3d kNCxNA = CrossProduct(TVector3d(), _krC.m_Normal, _krA.m_Normal);
|
||||
const TVector3d kNAxNB = CrossProduct(TVector3d(), _krA.m_Normal, _krB.m_Normal);
|
||||
|
||||
const double kdDistanceA = DotProduct(_krA.m_Normal, _krA.m_Point);
|
||||
const double kdDistanceB = DotProduct(_krB.m_Normal, _krB.m_Point);
|
||||
const double kdDistanceC = DotProduct(_krC.m_Normal, _krC.m_Point);
|
||||
|
||||
const TVector3d kDA_NBxNC = ScalarMultiply(TVector3d(), kNBxNC, kdDistanceA);
|
||||
const TVector3d kDB_NCxNA = ScalarMultiply(TVector3d(), kNCxNA, kdDistanceB);
|
||||
const TVector3d kDC_NAxNB = ScalarMultiply(TVector3d(), kNAxNB, kdDistanceC);
|
||||
|
||||
const double kdDenom = DotProduct(kNAxNB, _krC.m_Normal);
|
||||
|
||||
const TVector3d kNumer = Add(TVector3d(), Add(TVector3d(), kDA_NBxNC, kDB_NCxNA), kDC_NAxNB);
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, (1.0 / kdDenom));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& GetIntersection( TVector3f& _rResult,
|
||||
const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC)
|
||||
{
|
||||
const TVector3f kNBxNC = CrossProduct(TVector3f(), _krB.m_Normal, _krC.m_Normal);
|
||||
const TVector3f kNCxNA = CrossProduct(TVector3f(), _krC.m_Normal, _krA.m_Normal);
|
||||
const TVector3f kNAxNB = CrossProduct(TVector3f(), _krA.m_Normal, _krB.m_Normal);
|
||||
|
||||
const float kfDistanceA = DotProduct(_krA.m_Normal, _krA.m_Point);
|
||||
const float kfDistanceB = DotProduct(_krB.m_Normal, _krB.m_Point);
|
||||
const float kfDistanceC = DotProduct(_krC.m_Normal, _krC.m_Point);
|
||||
|
||||
const TVector3f kDA_NBxNC = ScalarMultiply(TVector3f(), kNBxNC, kfDistanceA);
|
||||
const TVector3f kDB_NCxNA = ScalarMultiply(TVector3f(), kNCxNA, kfDistanceB);
|
||||
const TVector3f kDC_NAxNB = ScalarMultiply(TVector3f(), kNAxNB, kfDistanceC);
|
||||
|
||||
const float kfDenom = DotProduct(kNAxNB, _krC.m_Normal);
|
||||
|
||||
const TVector3f kNumer = Add(TVector3f(), Add(TVector3f(), kDA_NBxNC, kDB_NCxNA), kDC_NAxNB);
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, (1.0f / kfDenom));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& GetPolygonNormal(TVector3d& _rResult, const TVector3d* _kpVertices, const size_t _kVertexCount)
|
||||
{
|
||||
_rResult = ZeroVector(TVector3d());
|
||||
|
||||
for(size_t i = 0; i < _kVertexCount; ++i)
|
||||
{
|
||||
const size_t kIndexA = ((_kVertexCount-1)+i)%_kVertexCount;
|
||||
const size_t kIndexB = i;
|
||||
|
||||
const TVector3d& krA = _kpVertices[kIndexA];
|
||||
const TVector3d& krB = _kpVertices[kIndexB];
|
||||
|
||||
const TVector3d kCrossProduct = CrossProduct(TVector3d(), krA, krB);
|
||||
|
||||
_rResult = Add(_rResult, _rResult, kCrossProduct);
|
||||
}
|
||||
|
||||
_rResult = Normalize(_rResult, _rResult);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& GetPolygonNormal(TVector3f& _rResult, const TVector3f* _kpVertices, const size_t _kVertexCount)
|
||||
{
|
||||
_rResult = ZeroVector(TVector3f());
|
||||
|
||||
for(size_t i = 0; i < _kVertexCount; ++i)
|
||||
{
|
||||
const size_t kIndexA = ((_kVertexCount-1)+i)%_kVertexCount;
|
||||
const size_t kIndexB = i;
|
||||
|
||||
const TVector3f& krA = _kpVertices[kIndexA];
|
||||
const TVector3f& krB = _kpVertices[kIndexB];
|
||||
|
||||
const TVector3f kCrossProduct = CrossProduct(TVector3f(), krA, krB);
|
||||
|
||||
_rResult = Add(_rResult, _rResult, kCrossProduct);
|
||||
}
|
||||
|
||||
_rResult = Normalize(_rResult, _rResult);
|
||||
|
||||
return(_rResult);
|
||||
}
|
42
ReflexToQ3/ckmath/ckmath_geometry.h
Normal file
42
ReflexToQ3/ckmath/ckmath_geometry.h
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_GEOMETRY_H__
|
||||
#define __MATH_GEOMETRY_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
|
||||
const bool IsIntersection( const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC);
|
||||
|
||||
const bool IsIntersection( const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC);
|
||||
|
||||
const TVector3d& GetIntersection( TVector3d& _rResult,
|
||||
const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC);
|
||||
|
||||
const TVector3f& GetIntersection( TVector3f& _rResult,
|
||||
const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC);
|
||||
|
||||
const TVector3d& GetPolygonNormal( TVector3d& _rResult,
|
||||
const TVector3d* _kpVertices,
|
||||
const size_t _kVertexCount);
|
||||
|
||||
const TVector3f& GetPolygonNormal( TVector3f& _rResult,
|
||||
const TVector3f* _kpVertices,
|
||||
const size_t _kVertexCount);
|
||||
|
||||
|
||||
#endif
|
2123
ReflexToQ3/ckmath/ckmath_matrix.cpp
Normal file
2123
ReflexToQ3/ckmath/ckmath_matrix.cpp
Normal file
File diff suppressed because it is too large
Load Diff
410
ReflexToQ3/ckmath/ckmath_matrix.h
Normal file
410
ReflexToQ3/ckmath/ckmath_matrix.h
Normal file
@ -0,0 +1,410 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_MATRIX_H__
|
||||
#define __MATH_MATRIX_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
//
|
||||
// Matrix 4
|
||||
//
|
||||
|
||||
const bool Equal(const TMatrix4d& _krA, const TMatrix4d& _krB, const double _kdEpsilon);
|
||||
|
||||
const bool Equal(const TMatrix4f& _krA, const TMatrix4f& _krB, const float _kfEpsilon);
|
||||
|
||||
const TMatrix4d& ZeroMatrix(TMatrix4d& _rResult);
|
||||
|
||||
const TMatrix4f& ZeroMatrix(TMatrix4f& _rResult);
|
||||
|
||||
const TMatrix4d& IdentityMatrix(TMatrix4d& _rResult);
|
||||
|
||||
const TMatrix4f& IdentityMatrix(TMatrix4f& _rResult);
|
||||
|
||||
const TMatrix4d& Multiply( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krA,
|
||||
const TMatrix4d& _krB);
|
||||
|
||||
const TMatrix4f& Multiply( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krA,
|
||||
const TMatrix4f& _krB);
|
||||
|
||||
const TMatrix4d& ScalarMultiply(TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix,
|
||||
const double _kdScalar);
|
||||
|
||||
const TMatrix4f& ScalarMultiply(TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix,
|
||||
const float _kfScalar);
|
||||
|
||||
const TVector4d& VectorMultiply(TVector4d& _rResult,
|
||||
const TMatrix4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& VectorMultiply(TVector4f& _rResult,
|
||||
const TMatrix4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TMatrix4d& Add( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krA,
|
||||
const TMatrix4d& _krB);
|
||||
|
||||
const TMatrix4f& Add( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krA,
|
||||
const TMatrix4f& _krB);
|
||||
|
||||
const TMatrix4d& Transpose( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& Transpose( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const double GetElement(const TMatrix4d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float GetElement(const TMatrix4f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix4d& SetElement( TMatrix4d& _rResult,
|
||||
const double _kdValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix4f& SetElement( TMatrix4f& _rResult,
|
||||
const float _kfValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix3d& Submatrix( TMatrix3d& _rResult,
|
||||
const TMatrix4d& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const TMatrix3f& Submatrix( TMatrix3f& _rResult,
|
||||
const TMatrix4f& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const double FirstMinor(const TMatrix4d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float FirstMinor( const TMatrix4f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix4d& MatrixOfMinors(TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& MatrixOfMinors(TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const TMatrix4d& MatrixOfCofactors( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& MatrixOfCofactors( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const double Determinant(const TMatrix4d& _krMatrix);
|
||||
|
||||
const float Determinant(const TMatrix4f& _krMatrix);
|
||||
|
||||
const TMatrix4d& Inverse( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& Inverse( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const TMatrix4d& TranslationMatrix( TMatrix4d& _rResult,
|
||||
const TVector3d& _krVector);
|
||||
|
||||
const TMatrix4f& TranslationMatrix( TMatrix4f& _rResult,
|
||||
const TVector3f& _krVector);
|
||||
|
||||
const TMatrix4d& ScalingMatrix( TMatrix4d& _rResult,
|
||||
const double _kdX,
|
||||
const double _kdY,
|
||||
const double _kdZ);
|
||||
|
||||
const TMatrix4f& ScalingMatrix( TMatrix4f& _rResult,
|
||||
const float _kfX,
|
||||
const float _kfY,
|
||||
const float _kfZ);
|
||||
|
||||
const TMatrix4d& TransformationMatrix( TMatrix4d& _rResult,
|
||||
const TVector3d& _krBasisX,
|
||||
const TVector3d& _krBasisY,
|
||||
const TVector3d& _krBasisZ,
|
||||
const TVector3d& _krTranslation);
|
||||
|
||||
const TMatrix4f& TransformationMatrix( TMatrix4f& _rResult,
|
||||
const TVector3f& _krBasisX,
|
||||
const TVector3f& _krBasisY,
|
||||
const TVector3f& _krBasisZ,
|
||||
const TVector3f& _krTranslation);
|
||||
|
||||
const TMatrix4d& RotationMatrix( TMatrix4d& _rResult,
|
||||
const TVector4d& _krQuaternion);
|
||||
|
||||
const TMatrix4f& RotationMatrix( TMatrix4f& _rResult,
|
||||
const TVector4f& _krQuaternion);
|
||||
|
||||
const TMatrix4d& AxisRotationXMatrix(TMatrix4d& _rResult,
|
||||
const double _kdAngle);
|
||||
|
||||
const TMatrix4f& AxisRotationXMatrix(TMatrix4f& _rResult,
|
||||
const float _kfAngle);
|
||||
|
||||
const TMatrix4d& AxisRotationYMatrix(TMatrix4d& _rResult,
|
||||
const double _kdAngle);
|
||||
|
||||
const TMatrix4f& AxisRotationYMatrix(TMatrix4f& _rResult,
|
||||
const float _kfAngle);
|
||||
|
||||
const TMatrix4d& AxisRotationZMatrix(TMatrix4d& _rResult,
|
||||
const double _kdAngle);
|
||||
|
||||
const TMatrix4f& AxisRotationZMatrix(TMatrix4f& _rResult,
|
||||
const float _kfAngle);
|
||||
|
||||
const TMatrix4d& PerspectiveMatrix( TMatrix4d& _rResult,
|
||||
const double _kdLeft, const double _kdRight,
|
||||
const double _kdBottom, const double _kdTop,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& PerspectiveMatrix( TMatrix4f& _rResult,
|
||||
const float _kfLeft, const float _kfRight,
|
||||
const float _kfBottom, const float _kfTop,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
const TMatrix4d& PerspectiveMatrix( TMatrix4d& _rResult,
|
||||
const double _kdFovX, const double _kdFovY,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& PerspectiveMatrix( TMatrix4f& _rResult,
|
||||
const float _kfFovX, const float _kfFovY,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
const TMatrix4d& OrthographicMatrix(TMatrix4d& _rResult,
|
||||
const double _kdLeft, const double _kdRight,
|
||||
const double _kdBottom, const double _kdTop,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& OrthographicMatrix(TMatrix4f& _rResult,
|
||||
const float _kfLeft, const float _kfRight,
|
||||
const float _kfBottom, const float _kfTop,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
const TMatrix4d& OrthographicMatrix(TMatrix4d& _rResult,
|
||||
const double _kdWidth, const double _kdHeight,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& OrthographicMatrix(TMatrix4f& _rResult,
|
||||
const float _kfWidth, const float _kfHeight,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
//
|
||||
// Matrix 3
|
||||
//
|
||||
|
||||
const bool Equal(const TMatrix3d& _krA, const TMatrix3d& _krB, const double _kdEpsilon);
|
||||
|
||||
const bool Equal(const TMatrix3f& _krA, const TMatrix3f& _krB, const float _kfEpsilon);
|
||||
|
||||
const TMatrix3d& ZeroMatrix(TMatrix3d& _rResult);
|
||||
|
||||
const TMatrix3f& ZeroMatrix(TMatrix3f& _rResult);
|
||||
|
||||
const TMatrix3d& IdentityMatrix(TMatrix3d& _rResult);
|
||||
|
||||
const TMatrix3f& IdentityMatrix(TMatrix3f& _rResult);
|
||||
|
||||
const TMatrix3d& Multiply( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krA,
|
||||
const TMatrix3d& _krB);
|
||||
|
||||
const TMatrix3f& Multiply( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krA,
|
||||
const TMatrix3f& _krB);
|
||||
|
||||
const TMatrix3d& ScalarMultiply(TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix,
|
||||
const double _kdScalar);
|
||||
|
||||
const TMatrix3f& ScalarMultiply(TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix,
|
||||
const float _kfScalar);
|
||||
|
||||
const TVector3d& VectorMultiply(TVector3d& _rResult,
|
||||
const TMatrix3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& VectorMultiply(TVector3f& _rResult,
|
||||
const TMatrix3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TMatrix3d& Add( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krA,
|
||||
const TMatrix3d& _krB);
|
||||
|
||||
const TMatrix3f& Add( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krA,
|
||||
const TMatrix3f& _krB);
|
||||
|
||||
const TMatrix3d& Transpose( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& Transpose( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
const double GetElement(const TMatrix3d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float GetElement(const TMatrix3f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix3d& SetElement( TMatrix3d& _rResult,
|
||||
const double _kdValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix3f& SetElement( TMatrix3f& _rResult,
|
||||
const float _kfValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix2d& Submatrix( TMatrix2d& _rResult,
|
||||
const TMatrix3d& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const TMatrix2f& Submatrix( TMatrix2f& _rResult,
|
||||
const TMatrix3f& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const double Determinant(const TMatrix3d& _krMatrix);
|
||||
|
||||
const float Determinant(const TMatrix3f& _krMatrix);
|
||||
|
||||
const double FirstMinor(const TMatrix3d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float FirstMinor( const TMatrix3f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix3d& MatrixOfMinors(TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& MatrixOfMinors(TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
const TMatrix3d& MatrixOfCofactors( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& MatrixOfCofactors( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
const TMatrix3d& Inverse( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& Inverse( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
//
|
||||
// Matrix 2
|
||||
//
|
||||
|
||||
const bool Equal(const TMatrix2d& _krA, const TMatrix2d& _krB, const double _kdEpsilon);
|
||||
|
||||
const bool Equal(const TMatrix2f& _krA, const TMatrix2f& _krB, const float _kfEpsilon);
|
||||
|
||||
const TMatrix2d& ZeroMatrix(TMatrix2d& _rResult);
|
||||
|
||||
const TMatrix2f& ZeroMatrix(TMatrix2f& _rResult);
|
||||
|
||||
const TMatrix2d& IdentityMatrix(TMatrix2d& _rResult);
|
||||
|
||||
const TMatrix2f& IdentityMatrix(TMatrix2f& _rResult);
|
||||
|
||||
const TMatrix2d& Multiply( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krA,
|
||||
const TMatrix2d& _krB);
|
||||
|
||||
const TMatrix2f& Multiply( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krA,
|
||||
const TMatrix2f& _krB);
|
||||
|
||||
const TMatrix2d& ScalarMultiply(TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krMatrix,
|
||||
const double _kdScalar);
|
||||
|
||||
const TMatrix2f& ScalarMultiply(TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krMatrix,
|
||||
const float _kfScalar);
|
||||
|
||||
const TVector2d& VectorMultiply(TVector2d& _rResult,
|
||||
const TMatrix2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& VectorMultiply(TVector2f& _rResult,
|
||||
const TMatrix2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TMatrix2d& Add( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krA,
|
||||
const TMatrix2d& _krB);
|
||||
|
||||
const TMatrix2f& Add( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krA,
|
||||
const TMatrix2f& _krB);
|
||||
|
||||
const TMatrix2d& Transpose( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krMatrix);
|
||||
|
||||
const TMatrix2f& Transpose( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krMatrix);
|
||||
|
||||
const double GetElement(const TMatrix2d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float GetElement(const TMatrix2f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix2d& SetElement( TMatrix2d& _rResult,
|
||||
const double _kdValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix2f& SetElement( TMatrix2f& _rResult,
|
||||
const float _kfValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix2d& Inverse( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krMatrix);
|
||||
|
||||
const TMatrix2f& Inverse( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krMatrix);
|
||||
|
||||
const double Determinant(const TMatrix2d& _krMatrix);
|
||||
|
||||
const float Determinant(const TMatrix2f& _krMatrix);
|
||||
|
||||
|
||||
|
||||
#endif
|
236
ReflexToQ3/ckmath/ckmath_quaternion.cpp
Normal file
236
ReflexToQ3/ckmath/ckmath_quaternion.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_quaternion.h"
|
||||
#include "ckmath_scalar.h"
|
||||
#include "ckmath_vector.h"
|
||||
|
||||
|
||||
//
|
||||
// Quaternion
|
||||
//
|
||||
|
||||
const TVector4d& IdentityQuaternion(TVector4d& _rResult)
|
||||
{
|
||||
_rResult.m_dW = 1.0;
|
||||
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
_rResult.m_dZ = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& IdentityQuaternion(TVector4f& _rResult)
|
||||
{
|
||||
_rResult.m_fW = 1.0f;
|
||||
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
_rResult.m_fZ = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& ConjugateQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion)
|
||||
{
|
||||
_rResult.m_dW = _krQuaternion.m_dW;
|
||||
|
||||
_rResult.m_dX = -_krQuaternion.m_dX;
|
||||
_rResult.m_dY = -_krQuaternion.m_dY;
|
||||
_rResult.m_dZ = -_krQuaternion.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& ConjugateQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion)
|
||||
{
|
||||
_rResult.m_fW = _krQuaternion.m_fW;
|
||||
|
||||
_rResult.m_fX = -_krQuaternion.m_fX;
|
||||
_rResult.m_fY = -_krQuaternion.m_fY;
|
||||
_rResult.m_fZ = -_krQuaternion.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& InverseQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply(_rResult,
|
||||
ConjugateQuaternion(TVector4d(), _krQuaternion),
|
||||
(1.0 / Square(QuaternionMagnitude(_krQuaternion))));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& InverseQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply(_rResult,
|
||||
ConjugateQuaternion(TVector4f(), _krQuaternion),
|
||||
(1.0f / Square(QuaternionMagnitude(_krQuaternion))));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& UnitQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply( _rResult,
|
||||
_krQuaternion,
|
||||
(1.0 / QuaternionMagnitude(_krQuaternion)));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& UnitQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply( _rResult,
|
||||
_krQuaternion,
|
||||
(1.0f / QuaternionMagnitude(_krQuaternion)));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& AxisAngleQuaternion(TVector4d& _rResult, const TVector3d& _krAxis, const double _kdAngle)
|
||||
{
|
||||
_rResult.m_dW = Cosine(_kdAngle / 2.0);
|
||||
|
||||
_rResult.m_dX = _krAxis.m_dX * Sine(_kdAngle / 2.0);
|
||||
_rResult.m_dY = _krAxis.m_dY * Sine(_kdAngle / 2.0);
|
||||
_rResult.m_dZ = _krAxis.m_dZ * Sine(_kdAngle / 2.0);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& AxisAngleQuaternion(TVector4f& _rResult, const TVector3f& _krAxis, const float _kfAngle)
|
||||
{
|
||||
_rResult.m_fW = Cosine(_kfAngle / 2.0f);
|
||||
|
||||
_rResult.m_fX = _krAxis.m_fX * Sine(_kfAngle / 2.0f);
|
||||
_rResult.m_fY = _krAxis.m_fY * Sine(_kfAngle / 2.0f);
|
||||
_rResult.m_fZ = _krAxis.m_fZ * Sine(_kfAngle / 2.0f);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double QuaternionMagnitude(const TVector4d& _krQuaternion)
|
||||
{
|
||||
return(SquareRoot(QuaternionProduct(TVector4d(),
|
||||
ConjugateQuaternion( TVector4d(),
|
||||
_krQuaternion),
|
||||
_krQuaternion).m_dW));
|
||||
}
|
||||
|
||||
const float QuaternionMagnitude(const TVector4f& _krQuaternion)
|
||||
{
|
||||
return(SquareRoot(QuaternionProduct(TVector4f(),
|
||||
ConjugateQuaternion( TVector4f(),
|
||||
_krQuaternion),
|
||||
_krQuaternion).m_fW));
|
||||
}
|
||||
|
||||
const TVector4d& QuaternionProduct(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB)
|
||||
{
|
||||
_rResult.m_dW = (_krA.m_dW * _krB.m_dW) - (_krA.m_dX * _krB.m_dX) - (_krA.m_dY * _krB.m_dY) - (_krA.m_dZ * _krB.m_dZ);
|
||||
_rResult.m_dX = (_krA.m_dW * _krB.m_dX) + (_krA.m_dX * _krB.m_dW) + (_krA.m_dY * _krB.m_dZ) - (_krA.m_dZ * _krB.m_dY);
|
||||
_rResult.m_dY = (_krA.m_dW * _krB.m_dY) - (_krA.m_dX * _krB.m_dZ) + (_krA.m_dY * _krB.m_dW) + (_krA.m_dZ * _krB.m_dX);
|
||||
_rResult.m_dZ = (_krA.m_dW * _krB.m_dZ) + (_krA.m_dX * _krB.m_dY) - (_krA.m_dY * _krB.m_dX) + (_krA.m_dZ * _krB.m_dW);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& QuaternionProduct(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB)
|
||||
{
|
||||
_rResult.m_fW = (_krA.m_fW * _krB.m_fW) - (_krA.m_fX * _krB.m_fX) - (_krA.m_fY * _krB.m_fY) - (_krA.m_fZ * _krB.m_fZ);
|
||||
_rResult.m_fX = (_krA.m_fW * _krB.m_fX) + (_krA.m_fX * _krB.m_fW) + (_krA.m_fY * _krB.m_fZ) - (_krA.m_fZ * _krB.m_fY);
|
||||
_rResult.m_fY = (_krA.m_fW * _krB.m_fY) - (_krA.m_fX * _krB.m_fZ) + (_krA.m_fY * _krB.m_fW) + (_krA.m_fZ * _krB.m_fX);
|
||||
_rResult.m_fZ = (_krA.m_fW * _krB.m_fZ) + (_krA.m_fX * _krB.m_fY) - (_krA.m_fY * _krB.m_fX) + (_krA.m_fZ * _krB.m_fW);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& QuaternionRotate(TVector3d& _rResult, const TVector3d& _krVector, const TVector4d& _krQuaternion)
|
||||
{
|
||||
const TVector4d kVecAsQuat{_krVector.m_dX, _krVector.m_dY, _krVector.m_dZ, 0.0};
|
||||
|
||||
const TVector4d kResultAsQuat = QuaternionProduct(TVector4d(),
|
||||
QuaternionProduct(TVector4d(), _krQuaternion, kVecAsQuat),
|
||||
ConjugateQuaternion(TVector4d(), _krQuaternion));
|
||||
|
||||
_rResult.m_dX = kResultAsQuat.m_dX;
|
||||
_rResult.m_dY = kResultAsQuat.m_dY;
|
||||
_rResult.m_dZ = kResultAsQuat.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& QuaternionRotate(TVector3f& _rResult, const TVector3f& _krVector, const TVector4f& _krQuaternion)
|
||||
{
|
||||
const TVector4f kVecAsQuat{_krVector.m_fX, _krVector.m_fY, _krVector.m_fZ, 0.0f};
|
||||
|
||||
const TVector4f kResultAsQuat = QuaternionProduct(TVector4f(),
|
||||
QuaternionProduct(TVector4f(), _krQuaternion, kVecAsQuat),
|
||||
ConjugateQuaternion(TVector4f(), _krQuaternion));
|
||||
|
||||
_rResult.m_fX = kResultAsQuat.m_fX;
|
||||
_rResult.m_fY = kResultAsQuat.m_fY;
|
||||
_rResult.m_fZ = kResultAsQuat.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& Slerp(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB, const double _kdT)
|
||||
{
|
||||
const double kdCosOmega = DotProduct(_krA, _krB);
|
||||
|
||||
double dK0, dK1;
|
||||
if(Magnitude(kdCosOmega) == 1.0) // Avoid divide by zero using lerp
|
||||
{
|
||||
dK0 = 1.0 - _kdT;
|
||||
dK1 = _kdT;
|
||||
}
|
||||
else
|
||||
{
|
||||
const double kdSinOmega = SquareRoot(1.0 - Square(kdCosOmega));
|
||||
const double kdOmega = ArcTan2(kdSinOmega, kdCosOmega);
|
||||
|
||||
dK0 = Sine((1.0 - _kdT) * kdOmega) * (1.0 / kdSinOmega);
|
||||
dK1 = Sine(_kdT * kdOmega) * (1.0 / kdSinOmega);
|
||||
}
|
||||
|
||||
_rResult.m_dW = (_krA.m_dW * dK0) + (_krB.m_dW * dK1);
|
||||
_rResult.m_dX = (_krA.m_dX * dK0) + (_krB.m_dX * dK1);
|
||||
_rResult.m_dY = (_krA.m_dY * dK0) + (_krB.m_dY * dK1);
|
||||
_rResult.m_dZ = (_krA.m_dZ * dK0) + (_krB.m_dZ * dK1);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Slerp(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB, const float _kfT)
|
||||
{
|
||||
const float kfCosOmega = DotProduct(_krA, _krB);
|
||||
|
||||
float fK0, fK1;
|
||||
if(Magnitude(kfCosOmega) == 1.0f) // Avoid divide by zero using lerp
|
||||
{
|
||||
fK0 = 1.0f - _kfT;
|
||||
fK1 = _kfT;
|
||||
}
|
||||
else
|
||||
{
|
||||
const float kfSinOmega = SquareRoot(1.0f - Square(kfCosOmega));
|
||||
const float kfOmega = ArcTan2(kfSinOmega, kfCosOmega);
|
||||
|
||||
fK0 = Sine((1.0f - _kfT) * kfOmega) * (1.0f / kfSinOmega);
|
||||
fK1 = Sine(_kfT * kfOmega) * (1.0f / kfSinOmega);
|
||||
}
|
||||
|
||||
_rResult.m_fW = (_krA.m_fW * fK0) + (_krB.m_fW * fK1);
|
||||
_rResult.m_fX = (_krA.m_fX * fK0) + (_krB.m_fX * fK1);
|
||||
_rResult.m_fY = (_krA.m_fY * fK0) + (_krB.m_fY * fK1);
|
||||
_rResult.m_fZ = (_krA.m_fZ * fK0) + (_krB.m_fZ * fK1);
|
||||
|
||||
return(_rResult);
|
||||
}
|
53
ReflexToQ3/ckmath/ckmath_quaternion.h
Normal file
53
ReflexToQ3/ckmath/ckmath_quaternion.h
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_QUATERNION_H__
|
||||
#define __MATH_QUATERNION_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
// Quaternion Function Prototypes
|
||||
|
||||
const TVector4d& IdentityQuaternion(TVector4d& _rResult);
|
||||
|
||||
const TVector4f& IdentityQuaternion(TVector4f& _rResult);
|
||||
|
||||
const TVector4d& ConjugateQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector4f& ConjugateQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& InverseQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector4f& InverseQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& UnitQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector4f& UnitQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& AxisAngleQuaternion(TVector4d& _rResult, const TVector3d& _krAxis, const double _kdAngle);
|
||||
|
||||
const TVector4f& AxisAngleQuaternion(TVector4f& _rResult, const TVector3f& _krAxis, const float _kfAngle);
|
||||
|
||||
const double QuaternionMagnitude(const TVector4d& _krQuaternion);
|
||||
|
||||
const float QuaternionMagnitude(const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& QuaternionProduct(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB);
|
||||
|
||||
const TVector4f& QuaternionProduct(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB);
|
||||
|
||||
const TVector3d& QuaternionRotate(TVector3d& _rResult, const TVector3d& _krVector, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector3f& QuaternionRotate(TVector3f& _rResult, const TVector3f& _krVector, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& Slerp(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB, const double _kdT);
|
||||
|
||||
const TVector4f& Slerp(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB, const float _kfT);
|
||||
|
||||
|
||||
#endif
|
109
ReflexToQ3/ckmath/ckmath_scalar.h
Normal file
109
ReflexToQ3/ckmath/ckmath_scalar.h
Normal file
@ -0,0 +1,109 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_SCALAR_H__
|
||||
#define __MATH_SCALAR_H__
|
||||
|
||||
// Library Includes
|
||||
#include <cmath>
|
||||
|
||||
// Scalar Function Prototypes
|
||||
|
||||
// double
|
||||
inline const double Square(const double _kdScalar)
|
||||
{
|
||||
return(_kdScalar * _kdScalar);
|
||||
}
|
||||
|
||||
inline const double Magnitude(const double _kdScalar)
|
||||
{
|
||||
return(abs(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double SquareRoot(const double _kdScalar)
|
||||
{
|
||||
return(sqrt(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double ArcCos(const double _kdScalar)
|
||||
{
|
||||
return(acos(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double ArcTan(const double _kdScalar)
|
||||
{
|
||||
return(atan(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double ArcTan2(const double _kdX, const double _kdY)
|
||||
{
|
||||
return(atan2(_kdX, _kdY));
|
||||
}
|
||||
|
||||
inline const double Sine(const double _kdScalar)
|
||||
{
|
||||
return(sin(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double Cosine(const double _kdScalar)
|
||||
{
|
||||
return(cos(_kdScalar));
|
||||
}
|
||||
|
||||
inline const bool Equal(const double _kdA, const double _kdB, const double _kdEpsilon)
|
||||
{
|
||||
return((Magnitude(_kdA - _kdB) < _kdEpsilon));
|
||||
}
|
||||
|
||||
// float
|
||||
inline const float Square(const float _kfScalar)
|
||||
{
|
||||
return(_kfScalar * _kfScalar);
|
||||
}
|
||||
|
||||
inline const float Magnitude(const float _kfScalar)
|
||||
{
|
||||
return(fabsf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float SquareRoot(const float _kfScalar)
|
||||
{
|
||||
return(sqrtf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float ArcCos(const float _kfScalar)
|
||||
{
|
||||
return(acosf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float ArcTan(const float _kfScalar)
|
||||
{
|
||||
return(atanf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float ArcTan2(const float _kfX, const float _kfY)
|
||||
{
|
||||
return(atan2f(_kfX, _kfY));
|
||||
}
|
||||
|
||||
inline const float Sine(const float _kfScalar)
|
||||
{
|
||||
return(sinf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float Cosine(const float _kfScalar)
|
||||
{
|
||||
return(cosf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const bool Equal(const float _kfA, const float _kfB, const float _kfEpsilon)
|
||||
{
|
||||
return((Magnitude(_kfA - _kfB) < _kfEpsilon));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
306
ReflexToQ3/ckmath/ckmath_types.h
Normal file
306
ReflexToQ3/ckmath/ckmath_types.h
Normal file
@ -0,0 +1,306 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_TYPES_H__
|
||||
#define __MATH_TYPES_H__
|
||||
|
||||
//
|
||||
//
|
||||
// Struct Prototypes
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Vector
|
||||
//
|
||||
struct TVector4d
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
double m_dZ;
|
||||
double m_dW;
|
||||
};
|
||||
|
||||
struct TVector4f
|
||||
{
|
||||
float m_fX;
|
||||
float m_fY;
|
||||
float m_fZ;
|
||||
float m_fW;
|
||||
};
|
||||
|
||||
struct TVector3d
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
double m_dZ;
|
||||
};
|
||||
|
||||
struct TVector3f
|
||||
{
|
||||
float m_fX;
|
||||
float m_fY;
|
||||
float m_fZ;
|
||||
};
|
||||
|
||||
struct TVector2d
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
};
|
||||
|
||||
struct TVector2f
|
||||
{
|
||||
float m_fX;
|
||||
float m_fY;
|
||||
};
|
||||
|
||||
//
|
||||
// Matrix
|
||||
//
|
||||
struct TMatrix4d
|
||||
{
|
||||
double m_d11, m_d12, m_d13, m_d14;
|
||||
double m_d21, m_d22, m_d23, m_d24;
|
||||
double m_d31, m_d32, m_d33, m_d34;
|
||||
double m_d41, m_d42, m_d43, m_d44;
|
||||
};
|
||||
|
||||
struct TMatrix4f
|
||||
{
|
||||
float m_f11, m_f12, m_f13, m_f14;
|
||||
float m_f21, m_f22, m_f23, m_f24;
|
||||
float m_f31, m_f32, m_f33, m_f34;
|
||||
float m_f41, m_f42, m_f43, m_f44;
|
||||
};
|
||||
|
||||
struct TMatrix3d
|
||||
{
|
||||
double m_d11, m_d12, m_d13;
|
||||
double m_d21, m_d22, m_d23;
|
||||
double m_d31, m_d32, m_d33;
|
||||
};
|
||||
|
||||
struct TMatrix3f
|
||||
{
|
||||
float m_f11, m_f12, m_f13;
|
||||
float m_f21, m_f22, m_f23;
|
||||
float m_f31, m_f32, m_f33;
|
||||
};
|
||||
|
||||
struct TMatrix2d
|
||||
{
|
||||
double m_d11, m_d12;
|
||||
double m_d21, m_d22;
|
||||
};
|
||||
|
||||
struct TMatrix2f
|
||||
{
|
||||
float m_f11, m_f12;
|
||||
float m_f21, m_f22;
|
||||
};
|
||||
|
||||
//
|
||||
// Plane
|
||||
//
|
||||
struct TPlane3d
|
||||
{
|
||||
TVector3d m_Point;
|
||||
TVector3d m_Normal;
|
||||
};
|
||||
|
||||
struct TPlane3f
|
||||
{
|
||||
TVector3f m_Point;
|
||||
TVector3f m_Normal;
|
||||
|
||||
};
|
||||
|
||||
struct TPlane2d
|
||||
{
|
||||
TVector2d m_Point;
|
||||
TVector2d m_Normal;
|
||||
};
|
||||
|
||||
struct TPlane2f
|
||||
{
|
||||
TVector2f m_Point;
|
||||
TVector2f m_Normal;
|
||||
};
|
||||
|
||||
//
|
||||
// Triangle
|
||||
//
|
||||
struct TTriangle3d
|
||||
{
|
||||
TVector3d m_A;
|
||||
TVector3d m_B;
|
||||
TVector3d m_C;
|
||||
};
|
||||
|
||||
struct TTriangle3f
|
||||
{
|
||||
TVector3f m_A;
|
||||
TVector3f m_B;
|
||||
TVector3f m_C;
|
||||
};
|
||||
|
||||
struct TTriangle2d
|
||||
{
|
||||
TVector2d m_A;
|
||||
TVector2d m_B;
|
||||
TVector2d m_C;
|
||||
};
|
||||
|
||||
struct TTriangle2f
|
||||
{
|
||||
TVector2f m_A;
|
||||
TVector2f m_B;
|
||||
TVector2f m_C;
|
||||
};
|
||||
|
||||
//
|
||||
// Line
|
||||
//
|
||||
struct TLine3d
|
||||
{
|
||||
TVector3d m_A;
|
||||
TVector3d m_B;
|
||||
};
|
||||
|
||||
struct TLine3f
|
||||
{
|
||||
TVector3f m_A;
|
||||
TVector3f m_B;
|
||||
};
|
||||
|
||||
struct TLine2d
|
||||
{
|
||||
TVector2d m_A;
|
||||
TVector2d m_B;
|
||||
};
|
||||
|
||||
struct TLine2f
|
||||
{
|
||||
TVector2f m_A;
|
||||
TVector2f m_B;
|
||||
};
|
||||
|
||||
//
|
||||
// Ray
|
||||
//
|
||||
struct TRay3d
|
||||
{
|
||||
TVector3d m_Start;
|
||||
TVector3d m_Direction;
|
||||
};
|
||||
|
||||
struct TRay3f
|
||||
{
|
||||
TVector3f m_Start;
|
||||
TVector3f m_Direction;
|
||||
};
|
||||
|
||||
struct TRay2d
|
||||
{
|
||||
TVector2d m_Start;
|
||||
TVector2d m_Direction;
|
||||
};
|
||||
|
||||
struct TRay2f
|
||||
{
|
||||
TVector2f m_Start;
|
||||
TVector2f m_Direction;
|
||||
};
|
||||
|
||||
//
|
||||
// Sphere
|
||||
//
|
||||
struct TSphere3d
|
||||
{
|
||||
TVector3d m_Center;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TSphere3f
|
||||
{
|
||||
TVector3f m_Center;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
//
|
||||
// Circle
|
||||
//
|
||||
struct TCircle2d
|
||||
{
|
||||
TVector2d m_Center;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TCircle2f
|
||||
{
|
||||
TVector2f m_Center;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
//
|
||||
// Capsule
|
||||
//
|
||||
struct TCapsule3d
|
||||
{
|
||||
TLine3d m_Line;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TCapsule3f
|
||||
{
|
||||
TLine3f m_Line;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
struct TCapsule2d
|
||||
{
|
||||
TLine2d m_Line;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TCapsule2f
|
||||
{
|
||||
TLine2f m_Line;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
//
|
||||
// AABB
|
||||
//
|
||||
struct TAABB3d
|
||||
{
|
||||
TVector3d m_MinPoint;
|
||||
TVector3d m_MaxPoint;
|
||||
};
|
||||
|
||||
struct TAABB3f
|
||||
{
|
||||
TVector3f m_MinPoint;
|
||||
TVector3f m_MaxPoint;
|
||||
};
|
||||
|
||||
struct TAABB2d
|
||||
{
|
||||
TVector2d m_MinPoint;
|
||||
TVector2d m_MaxPoint;
|
||||
};
|
||||
|
||||
struct TAABB2f
|
||||
{
|
||||
TVector2f m_MinPoint;
|
||||
TVector2f m_MaxPoint;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
708
ReflexToQ3/ckmath/ckmath_vector.cpp
Normal file
708
ReflexToQ3/ckmath/ckmath_vector.cpp
Normal file
@ -0,0 +1,708 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_vector.h"
|
||||
#include "ckmath_scalar.h"
|
||||
|
||||
|
||||
//
|
||||
// Vector 4
|
||||
//
|
||||
|
||||
const TVector4d& ZeroVector(TVector4d& _rResult)
|
||||
{
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
_rResult.m_dZ = 0.0;
|
||||
_rResult.m_dW = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& ZeroVector(TVector4f& _rResult)
|
||||
{
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
_rResult.m_fZ = 0.0f;
|
||||
_rResult.m_fW = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector4d& _krA,
|
||||
const TVector4d& _krB,
|
||||
const double _kdEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_dX - _krB.m_dX) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dY - _krB.m_dY) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dZ - _krB.m_dZ) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dW - _krB.m_dW) < _kdEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector4f& _krA,
|
||||
const TVector4f& _krB,
|
||||
const float _kfEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_fX - _krB.m_fX) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fY - _krB.m_fY) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fZ - _krB.m_fZ) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fW - _krB.m_fW) < _kfEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const TVector4d& Add( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX + _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY + _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ + _krB.m_dZ;
|
||||
_rResult.m_dW = _krA.m_dW + _krB.m_dW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Add( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX + _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY + _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ + _krB.m_fZ;
|
||||
_rResult.m_fW = _krA.m_fW + _krB.m_fW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& Subtract(TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX - _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY - _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ - _krB.m_dZ;
|
||||
_rResult.m_dW = _krA.m_dW - _krB.m_dW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Subtract(TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX - _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY - _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ - _krB.m_fZ;
|
||||
_rResult.m_fW = _krA.m_fW - _krB.m_fW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& ScalarMultiply( TVector4d& _rResult,
|
||||
const TVector4d& _krV,
|
||||
const double _kdS)
|
||||
{
|
||||
_rResult.m_dX = _krV.m_dX * _kdS;
|
||||
_rResult.m_dY = _krV.m_dY * _kdS;
|
||||
_rResult.m_dZ = _krV.m_dZ * _kdS;
|
||||
_rResult.m_dW = _krV.m_dW * _kdS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& ScalarMultiply( TVector4f& _rResult,
|
||||
const TVector4f& _krV,
|
||||
const float _kfS)
|
||||
{
|
||||
_rResult.m_fX = _krV.m_fX * _kfS;
|
||||
_rResult.m_fY = _krV.m_fY * _kfS;
|
||||
_rResult.m_fZ = _krV.m_fZ * _kfS;
|
||||
_rResult.m_fW = _krV.m_fW * _kfS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double VectorMagnitude(const TVector4d& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_dX)
|
||||
+ Square(_krV.m_dY)
|
||||
+ Square(_krV.m_dZ)
|
||||
+ Square(_krV.m_dW)));
|
||||
}
|
||||
|
||||
const float VectorMagnitude(const TVector4f& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_fX)
|
||||
+ Square(_krV.m_fY)
|
||||
+ Square(_krV.m_fZ)
|
||||
+ Square(_krV.m_fW)));
|
||||
}
|
||||
|
||||
const double DotProduct( const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdResult = ( (_krA.m_dX * _krB.m_dX)
|
||||
+ (_krA.m_dY * _krB.m_dY)
|
||||
+ (_krA.m_dZ * _krB.m_dZ)
|
||||
+ (_krA.m_dW * _krB.m_dW));
|
||||
|
||||
return(kdResult);
|
||||
}
|
||||
|
||||
const float DotProduct( const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfResult = ( (_krA.m_fX * _krB.m_fX)
|
||||
+ (_krA.m_fY * _krB.m_fY)
|
||||
+ (_krA.m_fZ * _krB.m_fZ)
|
||||
+ (_krA.m_fW * _krB.m_fW));
|
||||
|
||||
return(kfResult);
|
||||
}
|
||||
|
||||
const TVector4d& Normalize( TVector4d& _rResult,
|
||||
const TVector4d& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0 / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Normalize( TVector4f& _rResult,
|
||||
const TVector4f& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0f / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& Projection( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector4d kNumer = ScalarMultiply(TVector4d(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kdDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Projection( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector4f kNumer = ScalarMultiply(TVector4f(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kfDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double AngleBetween(const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kdAngle);
|
||||
}
|
||||
|
||||
const float AngleBetween( const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kfAngle);
|
||||
}
|
||||
|
||||
const double Distance(const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdDistance = VectorMagnitude(Subtract(TVector4d(), _krA, _krB));
|
||||
|
||||
return(kdDistance);
|
||||
}
|
||||
|
||||
const float Distance( const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfDistance = VectorMagnitude(Subtract(TVector4f(), _krA, _krB));
|
||||
|
||||
return(kfDistance);
|
||||
}
|
||||
|
||||
//
|
||||
// Vector 3
|
||||
//
|
||||
|
||||
const TVector3d& ZeroVector(TVector3d& _rResult)
|
||||
{
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
_rResult.m_dZ = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& ZeroVector(TVector3f& _rResult)
|
||||
{
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
_rResult.m_fZ = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const double _kdEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_dX - _krB.m_dX) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dY - _krB.m_dY) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dZ - _krB.m_dZ) < _kdEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const float _kfEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_fX - _krB.m_fX) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fY - _krB.m_fY) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fZ - _krB.m_fZ) < _kfEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const TVector3d& Add( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX + _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY + _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ + _krB.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Add( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX + _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY + _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ + _krB.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& Subtract(TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX - _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY - _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ - _krB.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Subtract(TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX - _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY - _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ - _krB.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& ScalarMultiply( TVector3d& _rResult,
|
||||
const TVector3d& _krV,
|
||||
const double _kdS)
|
||||
{
|
||||
_rResult.m_dX = _krV.m_dX * _kdS;
|
||||
_rResult.m_dY = _krV.m_dY * _kdS;
|
||||
_rResult.m_dZ = _krV.m_dZ * _kdS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& ScalarMultiply( TVector3f& _rResult,
|
||||
const TVector3f& _krV,
|
||||
const float _kfS)
|
||||
{
|
||||
_rResult.m_fX = _krV.m_fX * _kfS;
|
||||
_rResult.m_fY = _krV.m_fY * _kfS;
|
||||
_rResult.m_fZ = _krV.m_fZ * _kfS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double VectorMagnitude(const TVector3d& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_dX)
|
||||
+ Square(_krV.m_dY)
|
||||
+ Square(_krV.m_dZ)));
|
||||
}
|
||||
|
||||
const float VectorMagnitude(const TVector3f& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_fX)
|
||||
+ Square(_krV.m_fY)
|
||||
+ Square(_krV.m_fZ)));
|
||||
}
|
||||
|
||||
const double DotProduct( const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
return( (_krA.m_dX * _krB.m_dX)
|
||||
+ (_krA.m_dY * _krB.m_dY)
|
||||
+ (_krA.m_dZ * _krB.m_dZ));
|
||||
}
|
||||
|
||||
const float DotProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
return( (_krA.m_fX * _krB.m_fX)
|
||||
+ (_krA.m_fY * _krB.m_fY)
|
||||
+ (_krA.m_fZ * _krB.m_fZ));
|
||||
}
|
||||
|
||||
const TVector3d& CrossProduct(TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
_rResult.m_dX = (_krA.m_dY * _krB.m_dZ) - ( _krA.m_dZ * _krB.m_dY);
|
||||
_rResult.m_dY = (_krA.m_dZ * _krB.m_dX) - ( _krA.m_dX * _krB.m_dZ);
|
||||
_rResult.m_dZ = (_krA.m_dX * _krB.m_dY) - ( _krA.m_dY * _krB.m_dX);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& CrossProduct(TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
_rResult.m_fX = (_krA.m_fY * _krB.m_fZ) - ( _krA.m_fZ * _krB.m_fY);
|
||||
_rResult.m_fY = (_krA.m_fZ * _krB.m_fX) - ( _krA.m_fX * _krB.m_fZ);
|
||||
_rResult.m_fZ = (_krA.m_fX * _krB.m_fY) - ( _krA.m_fY * _krB.m_fX);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& Normalize( TVector3d& _rResult,
|
||||
const TVector3d& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0 / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Normalize( TVector3f& _rResult,
|
||||
const TVector3f& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0f / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& Projection( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
const double kdDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector3d kNumer = ScalarMultiply(TVector3d(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kdDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Projection( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
const float kfDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector3f kNumer = ScalarMultiply(TVector3f(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kfDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double AngleBetween(const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
const double kdAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kdAngle);
|
||||
}
|
||||
|
||||
const float AngleBetween( const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
const float kfAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kfAngle);
|
||||
}
|
||||
|
||||
const double Distance(const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
const double kdDistance = VectorMagnitude(Subtract(TVector3d(), _krA, _krB));
|
||||
|
||||
return(kdDistance);
|
||||
}
|
||||
|
||||
const float Distance( const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
const float kfDistance = VectorMagnitude(Subtract(TVector3f(), _krA, _krB));
|
||||
|
||||
return(kfDistance);
|
||||
}
|
||||
|
||||
const double ScalarTripleProduct( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC)
|
||||
{
|
||||
return(DotProduct(_krA, CrossProduct(TVector3d(), _krB, _krC)));
|
||||
}
|
||||
|
||||
const float ScalarTripleProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC)
|
||||
{
|
||||
return(DotProduct(_krA, CrossProduct(TVector3f(), _krB, _krC)));
|
||||
}
|
||||
|
||||
const TVector3d& VectorTripleProduct( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC)
|
||||
{
|
||||
return(CrossProduct(_rResult, _krA, CrossProduct(TVector3d(), _krB, _krC)));
|
||||
}
|
||||
|
||||
const TVector3f& VectorTripleProduct( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC)
|
||||
{
|
||||
return(CrossProduct(_rResult, _krA, CrossProduct(TVector3f(), _krB, _krC)));
|
||||
}
|
||||
|
||||
//
|
||||
// Vector 2
|
||||
//
|
||||
|
||||
const TVector2d& ZeroVector(TVector2d& _rResult)
|
||||
{
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& ZeroVector(TVector2f& _rResult)
|
||||
{
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector2d& _krA,
|
||||
const TVector2d& _krB,
|
||||
const double _kdEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_dX - _krB.m_dX) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dY - _krB.m_dY) < _kdEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector2f& _krA,
|
||||
const TVector2f& _krB,
|
||||
const float _kfEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_fX - _krB.m_fX) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fY - _krB.m_fY) < _kfEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const TVector2d& Add( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX + _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY + _krB.m_dY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Add( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX + _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY + _krB.m_fY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2d& Subtract(TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX - _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY - _krB.m_dY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Subtract(TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX - _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY - _krB.m_fY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2d& ScalarMultiply( TVector2d& _rResult,
|
||||
const TVector2d& _krV,
|
||||
const double _kdS)
|
||||
{
|
||||
_rResult.m_dX = _krV.m_dX * _kdS;
|
||||
_rResult.m_dY = _krV.m_dY * _kdS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& ScalarMultiply( TVector2f& _rResult,
|
||||
const TVector2f& _krV,
|
||||
const float _kfS)
|
||||
{
|
||||
_rResult.m_fX = _krV.m_fX * _kfS;
|
||||
_rResult.m_fY = _krV.m_fY * _kfS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double VectorMagnitude(const TVector2d& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_dX)
|
||||
+ Square(_krV.m_dY)));
|
||||
}
|
||||
|
||||
const float VectorMagnitude(const TVector2f& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_fX)
|
||||
+ Square(_krV.m_fY)));
|
||||
}
|
||||
|
||||
const double DotProduct( const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
return( (_krA.m_dX * _krB.m_dX)
|
||||
+ (_krA.m_dY * _krB.m_dY));
|
||||
}
|
||||
|
||||
const float DotProduct( const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
return( (_krA.m_fX * _krB.m_fX)
|
||||
+ (_krA.m_fY * _krB.m_fY));
|
||||
}
|
||||
|
||||
const TVector2d& Normalize( TVector2d& _rResult,
|
||||
const TVector2d& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0 / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Normalize( TVector2f& _rResult,
|
||||
const TVector2f& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0f / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2d& Projection( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
const double kdDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector2d kNumer = ScalarMultiply(TVector2d(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kdDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Projection( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
const float kfDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector2f kNumer = ScalarMultiply(TVector2f(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kfDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double AngleBetween(const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
const double kdAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kdAngle);
|
||||
}
|
||||
|
||||
const float AngleBetween( const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
const float kfAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kfAngle);
|
||||
}
|
||||
|
||||
const double Distance(const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
const double kdDistance = VectorMagnitude(Subtract(TVector2d(), _krA, _krB));
|
||||
|
||||
return(kdDistance);
|
||||
}
|
||||
|
||||
const float Distance( const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
const float kfDistance = VectorMagnitude(Subtract(TVector2f(), _krA, _krB));
|
||||
|
||||
return(kfDistance);
|
||||
}
|
272
ReflexToQ3/ckmath/ckmath_vector.h
Normal file
272
ReflexToQ3/ckmath/ckmath_vector.h
Normal file
@ -0,0 +1,272 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_VECTOR_H__
|
||||
#define __MATH_VECTOR_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
// Vector Function Prototypes
|
||||
|
||||
|
||||
//
|
||||
// Vector 4
|
||||
//
|
||||
|
||||
const TVector4d& ZeroVector(TVector4d& _rResult);
|
||||
|
||||
const TVector4f& ZeroVector(TVector4f& _rResult);
|
||||
|
||||
const bool Equal( const TVector4d& _krA,
|
||||
const TVector4d& _krB,
|
||||
const double _kdEpsilon);
|
||||
|
||||
const bool Equal( const TVector4f& _krA,
|
||||
const TVector4f& _krB,
|
||||
const float _kfEpsilon);
|
||||
|
||||
const TVector4d& Add( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& Add( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TVector4d& Subtract( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& Subtract( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TVector4d& ScalarMultiply(TVector4d& _rResult,
|
||||
const TVector4d& _krV,
|
||||
const double _kdS);
|
||||
|
||||
const TVector4f& ScalarMultiply(TVector4f& _rResult,
|
||||
const TVector4f& _krV,
|
||||
const float _kfS);
|
||||
|
||||
const double VectorMagnitude(const TVector4d& _krV);
|
||||
|
||||
const float VectorMagnitude(const TVector4f& _krV);
|
||||
|
||||
const double DotProduct(const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const float DotProduct( const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TVector4d& Normalize( TVector4d& _rResult,
|
||||
const TVector4d& _krV);
|
||||
|
||||
const TVector4f& Normalize( TVector4f& _rResult,
|
||||
const TVector4f& _krV);
|
||||
|
||||
const TVector4d& Projection(TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& Projection(TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const double AngleBetween( const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const float AngleBetween( const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const double Distance( const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const float Distance( const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
//
|
||||
// Vector 3
|
||||
//
|
||||
|
||||
const TVector3d& ZeroVector(TVector3d& _rResult);
|
||||
|
||||
const TVector3f& ZeroVector(TVector3f& _rResult);
|
||||
|
||||
const bool Equal( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const double _kdEpsilon);
|
||||
|
||||
const bool Equal( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const float _kfEpsilon);
|
||||
|
||||
const TVector3d& Add( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& Add( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& Subtract( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& Subtract( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& ScalarMultiply(TVector3d& _rResult,
|
||||
const TVector3d& _krV,
|
||||
const double _kdS);
|
||||
|
||||
const TVector3f& ScalarMultiply(TVector3f& _rResult,
|
||||
const TVector3f& _krV,
|
||||
const float _kfS);
|
||||
|
||||
const double VectorMagnitude(const TVector3d& _krV);
|
||||
|
||||
const float VectorMagnitude(const TVector3f& _krV);
|
||||
|
||||
const double DotProduct(const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const float DotProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& CrossProduct( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& CrossProduct( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& Normalize( TVector3d& _rResult,
|
||||
const TVector3d& _krV);
|
||||
|
||||
const TVector3f& Normalize( TVector3f& _rResult,
|
||||
const TVector3f& _krV);
|
||||
|
||||
const TVector3d& Projection(TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& Projection(TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const double AngleBetween( const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const float AngleBetween( const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const double Distance( const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const float Distance( const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const double ScalarTripleProduct( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC);
|
||||
|
||||
const float ScalarTripleProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC);
|
||||
|
||||
const TVector3d& VectorTripleProduct( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC);
|
||||
|
||||
const TVector3f& VectorTripleProduct( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC);
|
||||
|
||||
//
|
||||
// Vector 2
|
||||
//
|
||||
|
||||
const TVector2d& ZeroVector(TVector2d& _rResult);
|
||||
|
||||
const TVector2f& ZeroVector(TVector2f& _rResult);
|
||||
|
||||
const bool Equal( const TVector2d& _krA,
|
||||
const TVector2d& _krB,
|
||||
const double _kdEpsilon);
|
||||
|
||||
const bool Equal( const TVector2f& _krA,
|
||||
const TVector2f& _krB,
|
||||
const float _kfEpsilon);
|
||||
|
||||
const TVector2d& Add( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& Add( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TVector2d& Subtract( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& Subtract( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TVector2d& ScalarMultiply(TVector2d& _rResult,
|
||||
const TVector2d& _krV,
|
||||
const double _kdS);
|
||||
|
||||
const TVector2f& ScalarMultiply(TVector2f& _rResult,
|
||||
const TVector2f& _krV,
|
||||
const float _kfS);
|
||||
|
||||
const double VectorMagnitude(const TVector2d& _krV);
|
||||
|
||||
const float VectorMagnitude(const TVector2f& _krV);
|
||||
|
||||
const double DotProduct(const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const float DotProduct( const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TVector2d& Normalize( TVector2d& _rResult,
|
||||
const TVector2d& _krV);
|
||||
|
||||
const TVector2f& Normalize( TVector2f& _rResult,
|
||||
const TVector2f& _krV);
|
||||
|
||||
const TVector2d& Projection(TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& Projection(TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const double AngleBetween( const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const float AngleBetween( const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const double Distance( const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const float Distance( const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
|
||||
#endif
|
37
ReflexToQ3/libraries.h
Normal file
37
ReflexToQ3/libraries.h
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __LIBRARIES_H__
|
||||
#define __LIBRARIES_H__
|
||||
|
||||
// Visual Leak Detector
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
//#include <vld.h>
|
||||
#endif
|
||||
|
||||
// Platform Libraries
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
// Chronokun Libraries
|
||||
#include "ckmath/ckmath.h"
|
||||
|
||||
// C++ Libraries
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
|
||||
#endif
|
121
ReflexToQ3/main.cpp
Normal file
121
ReflexToQ3/main.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
// Libraries Include
|
||||
#include "libraries.h"
|
||||
// Local Includes
|
||||
#include "mapparser.h"
|
||||
|
||||
// Structs
|
||||
struct TPlanePoints
|
||||
{
|
||||
TVector3f m_A;
|
||||
TVector3f m_B;
|
||||
TVector3f m_C;
|
||||
};
|
||||
|
||||
TPlanePoints GetPlanePoints(const TVector3f* _kpPoints, const size_t _kNumPoints)
|
||||
{
|
||||
TPlanePoints PlanePoints;
|
||||
|
||||
// Find Normal
|
||||
const TVector3f kNormal = GetPolygonNormal(TVector3f(), _kpPoints, _kNumPoints);
|
||||
|
||||
// Find center point
|
||||
TVector3f Temp{0.0f, 0.0f, 0.0f};
|
||||
for(size_t i = 0; i < _kNumPoints; ++i)
|
||||
{
|
||||
Temp = Add(Temp, Temp, _kpPoints[i]);
|
||||
}
|
||||
const TVector3f kCenter = ScalarMultiply(TVector3f(), Temp, (1.0f / (float)_kNumPoints));
|
||||
|
||||
// Find Tangent
|
||||
const TVector3f kTangent = Normalize(TVector3f(), Subtract(TVector3f(), _kpPoints[1], _kpPoints[0]));
|
||||
|
||||
// Find BiTangent
|
||||
const TVector3f kBiTangent = Normalize(TVector3f(), CrossProduct(TVector3f(), kNormal, kTangent));
|
||||
|
||||
PlanePoints.m_A = Add(TVector3f(), kCenter, kBiTangent);
|
||||
PlanePoints.m_B = kCenter;
|
||||
PlanePoints.m_C = Add(TVector3f(), kCenter, kTangent);
|
||||
|
||||
return(PlanePoints);
|
||||
}
|
||||
|
||||
std::vector<TPlanePoints> GetBrushPlanes(const TBrush& _krBrush)
|
||||
{
|
||||
std::vector<TPlanePoints> Planes;
|
||||
for(const TFace& krFace : _krBrush.m_Faces)
|
||||
{
|
||||
std::vector<TVector3f> Verts(krFace.m_Indices.size());
|
||||
for(size_t i = 0; i < krFace.m_Indices.size(); ++i)
|
||||
{
|
||||
Verts[i] = _krBrush.m_Vertices[krFace.m_Indices[i]];
|
||||
}
|
||||
Planes.push_back(GetPlanePoints(Verts.data(), Verts.size()));
|
||||
}
|
||||
|
||||
return(Planes);
|
||||
}
|
||||
|
||||
std::string GetBrushString(const TBrush& _krBrush)
|
||||
{
|
||||
std::vector<TPlanePoints> Planes = GetBrushPlanes(_krBrush);
|
||||
std::stringstream ssOutput;
|
||||
|
||||
if(Planes.size())
|
||||
{
|
||||
ssOutput << "{" << std::endl;
|
||||
for(const TPlanePoints& krPlane : Planes)
|
||||
{
|
||||
ssOutput << "( " << krPlane.m_A.m_fX << " " << krPlane.m_A.m_fZ << " " << krPlane.m_A.m_fY << " ) ";
|
||||
ssOutput << "( " << krPlane.m_B.m_fX << " " << krPlane.m_B.m_fZ << " " << krPlane.m_B.m_fY << " ) ";
|
||||
ssOutput << "( " << krPlane.m_C.m_fX << " " << krPlane.m_C.m_fZ << " " << krPlane.m_C.m_fY << " ) ";
|
||||
ssOutput << "common/caulk 0 0 0 0.500000 0.500000 0 4 0" << std::endl;
|
||||
}
|
||||
ssOutput << "}" << std::endl;
|
||||
}
|
||||
|
||||
return(ssOutput.str());
|
||||
}
|
||||
|
||||
int main(const int _kiArgC, const char** _kppcArgv)
|
||||
{
|
||||
// Check we have correct number of parameters
|
||||
if(_kiArgC < 3)
|
||||
{
|
||||
return(3);
|
||||
}
|
||||
|
||||
CMapParser Parser;
|
||||
|
||||
const bool kbSuccess = Parser.LoadMap(_kppcArgv[1]);
|
||||
if(!kbSuccess)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Open output file
|
||||
std::ofstream OutFile;
|
||||
OutFile.open(_kppcArgv[2]);
|
||||
if(!OutFile.is_open())
|
||||
{
|
||||
return(2);
|
||||
}
|
||||
|
||||
OutFile << "{" << std::endl
|
||||
<< "\"classname\" \"worldspawn\"" << std::endl;
|
||||
|
||||
for(const TBrush& krBrush : Parser.m_WorldSpawn.m_Brushes)
|
||||
{
|
||||
OutFile << GetBrushString(krBrush);
|
||||
}
|
||||
|
||||
OutFile << "}" << std::endl;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
233
ReflexToQ3/mapparser.cpp
Normal file
233
ReflexToQ3/mapparser.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
// Libraries Include
|
||||
#include "libraries.h"
|
||||
// This Include
|
||||
#include "mapparser.h"
|
||||
|
||||
const bool CMapParser::LoadMap(const char* _kpcFileName)
|
||||
{
|
||||
std::ifstream InFile;
|
||||
EParserState eState = PARSERSTATE_UNKNOWN;
|
||||
|
||||
InFile.open(_kpcFileName, std::ios::in);
|
||||
if(InFile.is_open())
|
||||
{
|
||||
std::string Line;
|
||||
bool bAdvance = true;
|
||||
bool bGoing = true;
|
||||
while(bGoing)
|
||||
{
|
||||
if(bAdvance)
|
||||
{
|
||||
if(!std::getline(InFile, Line))
|
||||
{
|
||||
bGoing = false;
|
||||
}
|
||||
}
|
||||
bAdvance = true;
|
||||
if(eState == PARSERSTATE_UNKNOWN)
|
||||
{
|
||||
if(strcmp(Line.c_str(), "entity") == 0)
|
||||
{
|
||||
eState = PARSERSTATE_ENTITY;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if(eState == PARSERSTATE_ENTITY)
|
||||
{
|
||||
eState = this->ParseEntity(Line);
|
||||
}
|
||||
else if(eState == PARSERSTATE_WORLDSPAWN)
|
||||
{
|
||||
eState = this->ParseWorldSpawn(Line);
|
||||
}
|
||||
else if(eState == PARSERSTATE_BRUSH)
|
||||
{
|
||||
eState = this->ParseBrush(Line);
|
||||
//bAdvance = false;
|
||||
}
|
||||
else if(eState == PARSERSTATE_VERTEX)
|
||||
{
|
||||
eState = this->ParseVertex(Line);
|
||||
if(eState != PARSERSTATE_VERTEX)
|
||||
{
|
||||
bAdvance = false;
|
||||
}
|
||||
}
|
||||
else if(eState == PARSERSTATE_FACE)
|
||||
{
|
||||
eState = this->ParseFace(Line);
|
||||
if(eState != PARSERSTATE_FACE)
|
||||
{
|
||||
bAdvance = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
InFile.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
EParserState CMapParser::ParseEntity(const std::string _Line)
|
||||
{
|
||||
const size_t kszLineSize = 256;
|
||||
char pcLine[kszLineSize];
|
||||
const char* kpcDelim = " ";
|
||||
char* pcToken;
|
||||
char* pcContext;
|
||||
|
||||
strcpy_s(pcLine, _Line.c_str());
|
||||
pcToken = strtok_s(pcLine, kpcDelim, &pcContext);
|
||||
|
||||
while(pcToken != nullptr)
|
||||
{
|
||||
if(strcmp(pcToken, "\ttype") == 0)
|
||||
{
|
||||
pcToken = strtok_s(nullptr, kpcDelim, &pcContext);
|
||||
if(strcmp(pcToken, "WorldSpawn") == 0)
|
||||
{
|
||||
return(PARSERSTATE_WORLDSPAWN);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(PARSERSTATE_UNKNOWN);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return(PARSERSTATE_ENTITY);
|
||||
}
|
||||
}
|
||||
return(PARSERSTATE_UNKNOWN);
|
||||
}
|
||||
|
||||
EParserState CMapParser::ParseWorldSpawn(const std::string _Line)
|
||||
{
|
||||
if(strcmp(_Line.c_str(), "brush") == 0)
|
||||
{
|
||||
this->m_WorldSpawn.m_Brushes.push_back(TBrush());
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
return(PARSERSTATE_WORLDSPAWN);
|
||||
}
|
||||
|
||||
EParserState CMapParser::ParseBrush(const std::string _Line)
|
||||
{
|
||||
if(strcmp(_Line.c_str(), "brush") == 0)
|
||||
{
|
||||
this->m_WorldSpawn.m_Brushes.push_back(TBrush());
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
if(strcmp(_Line.c_str(), "\tvertices") == 0)
|
||||
{
|
||||
return(PARSERSTATE_VERTEX);
|
||||
}
|
||||
else if(strcmp(_Line.c_str(), "\tfaces") == 0)
|
||||
{
|
||||
return(PARSERSTATE_FACE);
|
||||
}
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
|
||||
EParserState CMapParser::ParseVertex(const std::string _Line)
|
||||
{
|
||||
const size_t kszLineSize = 256;
|
||||
char pcLine[kszLineSize];
|
||||
const char* kpcDelim = " \t";
|
||||
char* pcToken;
|
||||
char* pcContext;
|
||||
|
||||
strcpy_s(pcLine, _Line.c_str());
|
||||
pcToken = strtok_s(pcLine, kpcDelim, &pcContext);
|
||||
|
||||
TVector3f Vert;
|
||||
int iTokenNum = 0;
|
||||
while(pcToken != nullptr)
|
||||
{
|
||||
if(std::isdigit(pcToken[0], std::locale()) || pcToken[0] == '-')
|
||||
{
|
||||
double dValue = std::stod(pcToken);
|
||||
if(iTokenNum == 0)
|
||||
{
|
||||
Vert.m_fX = (float)dValue;
|
||||
}
|
||||
else if(iTokenNum == 1)
|
||||
{
|
||||
Vert.m_fY = (float)dValue;
|
||||
}
|
||||
else if(iTokenNum == 2)
|
||||
{
|
||||
Vert.m_fZ = (float)dValue;
|
||||
}
|
||||
iTokenNum++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
|
||||
pcToken = strtok_s(nullptr, kpcDelim, &pcContext);
|
||||
}
|
||||
|
||||
this->m_WorldSpawn.m_Brushes[this->m_WorldSpawn.m_Brushes.size()-1].m_Vertices.push_back(Vert);
|
||||
return(PARSERSTATE_VERTEX);
|
||||
}
|
||||
|
||||
EParserState CMapParser::ParseFace(const std::string _Line)
|
||||
{
|
||||
const size_t kszLineSize = 256;
|
||||
char pcLine[kszLineSize];
|
||||
const char* kpcDelim = " \t";
|
||||
char* pcToken;
|
||||
char* pcContext;
|
||||
|
||||
strcpy_s(pcLine, _Line.c_str());
|
||||
pcToken = strtok_s(pcLine, kpcDelim, &pcContext);
|
||||
|
||||
int iTokenNum = 0;
|
||||
|
||||
std::vector<int> Indices;
|
||||
while(pcToken != nullptr)
|
||||
{
|
||||
if(iTokenNum < 5)
|
||||
{
|
||||
if(std::isdigit(pcToken[0], std::locale()) || pcToken[0] == '-')
|
||||
{
|
||||
double dValue = std::stod(pcToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
}
|
||||
else if(iTokenNum < 9)
|
||||
{
|
||||
if(std::isdigit(pcToken[0], std::locale()) || pcToken[0] == '-')
|
||||
{
|
||||
int iValue = std::stoi(pcToken);
|
||||
Indices.push_back(iValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(PARSERSTATE_BRUSH);
|
||||
}
|
||||
}
|
||||
|
||||
iTokenNum++;
|
||||
pcToken = strtok_s(nullptr, kpcDelim, &pcContext);
|
||||
}
|
||||
|
||||
TFace Face;
|
||||
Face.m_Indices = Indices;
|
||||
this->m_WorldSpawn.m_Brushes[this->m_WorldSpawn.m_Brushes.size()-1].m_Faces.push_back(Face);
|
||||
return(PARSERSTATE_FACE);
|
||||
}
|
44
ReflexToQ3/mapparser.h
Normal file
44
ReflexToQ3/mapparser.h
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MAPPARSER_H__
|
||||
#define __MAPPARSER_H__
|
||||
|
||||
// Includes
|
||||
#include "worldspawn.h"
|
||||
|
||||
// enums
|
||||
enum EParserState
|
||||
{
|
||||
PARSERSTATE_UNKNOWN,
|
||||
PARSERSTATE_ENTITY,
|
||||
PARSERSTATE_WORLDSPAWN,
|
||||
PARSERSTATE_BRUSH,
|
||||
PARSERSTATE_VERTEX,
|
||||
PARSERSTATE_FACE
|
||||
};
|
||||
|
||||
class CMapParser
|
||||
{
|
||||
// Variables
|
||||
public:
|
||||
TWorldSpawn m_WorldSpawn;
|
||||
|
||||
// Functions
|
||||
public:
|
||||
const bool LoadMap(const char* _kpcFileName);
|
||||
|
||||
protected:
|
||||
EParserState ParseEntity(const std::string _Line);
|
||||
EParserState ParseWorldSpawn(const std::string _Line);
|
||||
EParserState ParseBrush(const std::string _Line);
|
||||
EParserState ParseVertex(const std::string _Line);
|
||||
EParserState ParseFace(const std::string _Line);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
34
ReflexToQ3/worldspawn.h
Normal file
34
ReflexToQ3/worldspawn.h
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __WORLDSPAWN_H__
|
||||
#define __WORLDSPAWN_H__
|
||||
|
||||
struct TFace
|
||||
{
|
||||
float m_fXOffset;
|
||||
float m_fYOffset;
|
||||
float m_fXScale;
|
||||
float m_fYScale;
|
||||
float m_fRotation;
|
||||
std::vector<int> m_Indices;
|
||||
std::string m_Material;
|
||||
};
|
||||
|
||||
struct TBrush
|
||||
{
|
||||
std::vector<TVector3f> m_Vertices;
|
||||
std::vector<TFace> m_Faces;
|
||||
|
||||
};
|
||||
|
||||
struct TWorldSpawn
|
||||
{
|
||||
std::vector<TBrush> m_Brushes;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user