aboutsummaryrefslogtreecommitdiff
path: root/Client
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-02 11:41:42 +0800
committerchai <chaifix@163.com>2021-12-02 11:41:42 +0800
commit7a798253441a8bd499d36bd8153b92ab08de8a9f (patch)
tree32e4ee995534a4a8cd7c2e0b530ff02c45217e8f /Client
parentbcc11176480f403ab294de24d61bab993ce2fdfd (diff)
*fixed
Diffstat (limited to 'Client')
-rw-r--r--Client/Project/VisualStudio/PND.sln11
-rw-r--r--Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj3
-rw-r--r--Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj.filters3
-rw-r--r--Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj129
-rw-r--r--Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.filters22
-rw-r--r--Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.user4
-rw-r--r--Client/Source/Phy2DLite/Arbiter.cpp25
-rw-r--r--Client/Source/Phy2DLite/Arbiter.h3
-rw-r--r--Client/Source/Phy2DLite/Body.cpp45
-rw-r--r--Client/Source/Phy2DLite/Collide.cpp33
-rw-r--r--Client/Source/Phy2DLite/Constants.h19
-rw-r--r--Client/Source/Phy2DLite/Joint.cpp15
-rw-r--r--Client/Source/Phy2DLite/Math.cpp0
-rw-r--r--Client/Source/Phy2DLite/World.cpp12
-rw-r--r--Client/Source/float2fixed/main.cpp17
15 files changed, 275 insertions, 66 deletions
diff --git a/Client/Project/VisualStudio/PND.sln b/Client/Project/VisualStudio/PND.sln
index 66ce8a7..2293ffb 100644
--- a/Client/Project/VisualStudio/PND.sln
+++ b/Client/Project/VisualStudio/PND.sln
@@ -25,6 +25,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MeshBuilder", "MeshBuilder\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UIEditor", "UIEditor\UIEditor.vcxproj", "{F19BE44F-AF92-49E2-A43B-BF0348FAD139}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "float2fixed", "float2fixed\float2fixed.vcxproj", "{88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -105,6 +107,14 @@ Global
{F19BE44F-AF92-49E2-A43B-BF0348FAD139}.Release|x64.Build.0 = Release|x64
{F19BE44F-AF92-49E2-A43B-BF0348FAD139}.Release|x86.ActiveCfg = Release|Win32
{F19BE44F-AF92-49E2-A43B-BF0348FAD139}.Release|x86.Build.0 = Release|Win32
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Debug|x64.ActiveCfg = Debug|x64
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Debug|x64.Build.0 = Debug|x64
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Debug|x86.ActiveCfg = Debug|Win32
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Debug|x86.Build.0 = Debug|Win32
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Release|x64.ActiveCfg = Release|x64
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Release|x64.Build.0 = Release|x64
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Release|x86.ActiveCfg = Release|Win32
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -117,6 +127,7 @@ Global
{648C7FE7-9EF4-4D6D-8701-93F1821EB758} = {69D9F6A1-FE05-4A58-B87C-E62A6C69BE8F}
{EB023CB6-1559-46FB-8C43-B4B20482DDFE} = {69D9F6A1-FE05-4A58-B87C-E62A6C69BE8F}
{F19BE44F-AF92-49E2-A43B-BF0348FAD139} = {69D9F6A1-FE05-4A58-B87C-E62A6C69BE8F}
+ {88E2113C-BC15-4D54-8D09-5DBFB3A47C6D} = {845A763B-9CD8-4795-A3C4-D83146B3550C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3501AE41-C1E5-4131-9AB2-0DCBD10D9E3F}
diff --git a/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj b/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj
index 633276d..61da1c4 100644
--- a/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj
+++ b/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj
@@ -141,7 +141,6 @@
<ClCompile Include="..\..\..\Source\Phy2DLite\Body.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Collide.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Joint.cpp" />
- <ClCompile Include="..\..\..\Source\Phy2DLite\Math.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Tests\test_math.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Tests\test.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\World.cpp" />
@@ -165,6 +164,7 @@
<ItemGroup>
<ClInclude Include="..\..\..\Source\Phy2DLite\Arbiter.h" />
<ClInclude Include="..\..\..\Source\Phy2DLite\Body.h" />
+ <ClInclude Include="..\..\..\Source\Phy2DLite\Constants.h" />
<ClInclude Include="..\..\..\Source\Phy2DLite\Joint.h" />
<ClInclude Include="..\..\..\Source\Phy2DLite\Math.h" />
<ClInclude Include="..\..\..\Source\Phy2DLite\Phy2D.h" />
@@ -193,6 +193,7 @@
<ClInclude Include="..\..\..\ThirdParty\libfixmath\libfixmath\uint32.h" />
</ItemGroup>
<ItemGroup>
+ <Text Include="..\..\..\Source\Phy2DLite\README.txt" />
<Text Include="..\..\..\ThirdParty\libfixmath\libfixmath\code_style.txt" />
</ItemGroup>
<ItemGroup>
diff --git a/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj.filters b/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj.filters
index bfba900..104e093 100644
--- a/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj.filters
+++ b/Client/Project/VisualStudio/Phy2Dlite/Phy2Dlite.vcxproj.filters
@@ -5,7 +5,6 @@
<ClCompile Include="..\..\..\Source\Phy2DLite\Body.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Collide.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Joint.cpp" />
- <ClCompile Include="..\..\..\Source\Phy2DLite\Math.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\World.cpp" />
<ClCompile Include="..\..\..\Source\Phy2DLite\Tests\test_math.cpp">
<Filter>Tests</Filter>
@@ -133,6 +132,7 @@
<ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\math.hpp">
<Filter>Libs\fpm</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Source\Phy2DLite\Constants.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="Tests">
@@ -158,6 +158,7 @@
<Text Include="..\..\..\ThirdParty\libfixmath\libfixmath\code_style.txt">
<Filter>Libs\libfixmath</Filter>
</Text>
+ <Text Include="..\..\..\Source\Phy2DLite\README.txt" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\ThirdParty\libfixmath\libfixmath\libfixmath.cbp">
diff --git a/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj b/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj
new file mode 100644
index 0000000..bbf150d
--- /dev/null
+++ b/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.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>
+ <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>15.0</VCProjectVersion>
+ <ProjectGuid>{88E2113C-BC15-4D54-8D09-5DBFB3A47C6D}</ProjectGuid>
+ <RootNamespace>float2fixed</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.17763.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>v141</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</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 />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\..\ThirdParty</AdditionalIncludeDirectories>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\Source\float2fixed\main.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\fixed.hpp" />
+ <ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\ios.hpp" />
+ <ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\math.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.filters b/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.filters
new file mode 100644
index 0000000..9f7de50
--- /dev/null
+++ b/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.filters
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <ClCompile Include="..\..\..\Source\float2fixed\main.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="fpm">
+ <UniqueIdentifier>{70a2b92b-c209-4cc2-aade-3ebd3ffc7184}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\fixed.hpp">
+ <Filter>fpm</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\ios.hpp">
+ <Filter>fpm</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\ThirdParty\fpm\include\fpm\math.hpp">
+ <Filter>fpm</Filter>
+ </ClInclude>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.user b/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.user
new file mode 100644
index 0000000..6e2aec7
--- /dev/null
+++ b/Client/Project/VisualStudio/float2fixed/float2fixed.vcxproj.user
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup />
+</Project> \ No newline at end of file
diff --git a/Client/Source/Phy2DLite/Arbiter.cpp b/Client/Source/Phy2DLite/Arbiter.cpp
index 4163154..567e6f7 100644
--- a/Client/Source/Phy2DLite/Arbiter.cpp
+++ b/Client/Source/Phy2DLite/Arbiter.cpp
@@ -2,6 +2,7 @@
#include "World.h"
#include "Body.h"
#include "Joint.h"
+#include "Constants.h"
using namespace Phy2D;
@@ -54,9 +55,9 @@ void Arbiter::Update(Contact* newContacts, int numNewContacts)
}
else
{
- c->Pn = 0.0f;
- c->Pt = 0.0f;
- c->Pnb = 0.0f;
+ c->Pn = _0;
+ c->Pt = _0;
+ c->Pnb = _0;
}
}
else
@@ -74,8 +75,8 @@ void Arbiter::Update(Contact* newContacts, int numNewContacts)
void Arbiter::PreStep(number inv_dt)
{
- const number k_allowedPenetration = 0.01f;
- number k_biasFactor = World::positionCorrection ? 0.2f : 0.0f;
+ const number k_allowedPenetration = _0_01;
+ number k_biasFactor = World::positionCorrection ? _0_2 : _0;
for (int i = 0; i < numContacts; ++i)
{
@@ -89,16 +90,16 @@ void Arbiter::PreStep(number inv_dt)
number rn2 = Dot(r2, c->normal);
number kNormal = body1->invMass + body2->invMass;
kNormal += body1->invI * (Dot(r1, r1) - rn1 * rn1) + body2->invI * (Dot(r2, r2) - rn2 * rn2);
- c->massNormal = (number) 1.0f / kNormal;
+ c->massNormal = (number)_1 / kNormal;
- Vec2 tangent = Cross(c->normal, 1.0f);
+ Vec2 tangent = Cross(c->normal, _1);
number rt1 = Dot(r1, tangent);
number rt2 = Dot(r2, tangent);
number kTangent = body1->invMass + body2->invMass;
kTangent += body1->invI * (Dot(r1, r1) - rt1 * rt1) + body2->invI * (Dot(r2, r2) - rt2 * rt2);
- c->massTangent = (number) 1.0f / kTangent;
+ c->massTangent = (number)_1 / kTangent;
- c->bias = -k_biasFactor * inv_dt * Min(0.0f, c->separation + k_allowedPenetration);
+ c->bias = -k_biasFactor * inv_dt * Min(_0, c->separation + k_allowedPenetration);
if (World::accumulateImpulses)
{
@@ -137,12 +138,12 @@ void Arbiter::ApplyImpulse()
{
// Clamp the accumulated impulse
number Pn0 = c->Pn;
- c->Pn = Max(Pn0 + dPn, 0.0f);
+ c->Pn = Max(Pn0 + dPn, _0);
dPn = c->Pn - Pn0;
}
else
{
- dPn = Max(dPn, 0.0f);
+ dPn = Max(dPn, _0);
}
// Apply contact impulse
@@ -157,7 +158,7 @@ void Arbiter::ApplyImpulse()
// Relative velocity at contact
dv = b2->velocity + Cross(b2->angularVelocity, c->r2) - b1->velocity - Cross(b1->angularVelocity, c->r1);
- Vec2 tangent = Cross(c->normal, 1.0f);
+ Vec2 tangent = Cross(c->normal, _1);
number vt = Dot(dv, tangent);
number dPt = c->massTangent * (-vt);
diff --git a/Client/Source/Phy2DLite/Arbiter.h b/Client/Source/Phy2DLite/Arbiter.h
index 2232210..167978f 100644
--- a/Client/Source/Phy2DLite/Arbiter.h
+++ b/Client/Source/Phy2DLite/Arbiter.h
@@ -1,6 +1,7 @@
#pragma once
#include "Math.h"
+#include "Constants.h"
namespace Phy2D
{
@@ -21,7 +22,7 @@ namespace Phy2D
struct Contact
{
- Contact() : Pn(0.0f), Pt(0.0f), Pnb(0.0f) {}
+ Contact() : Pn(_0), Pt(_0), Pnb(_0) {}
Vec2 position;
Vec2 normal;
diff --git a/Client/Source/Phy2DLite/Body.cpp b/Client/Source/Phy2DLite/Body.cpp
index 1d896fd..993c3f8 100644
--- a/Client/Source/Phy2DLite/Body.cpp
+++ b/Client/Source/Phy2DLite/Body.cpp
@@ -1,47 +1,48 @@
#include "Body.h"
+#include "Constants.h"
using namespace Phy2D;
Body::Body()
{
- position.Set(0.0f, 0.0f);
- rotation = 0.0f;
- velocity.Set(0.0f, 0.0f);
- angularVelocity = 0.0f;
- force.Set(0.0f, 0.0f);
- torque = 0.0f;
- friction = 0.2f;
+ position.Set(_0, _0);
+ rotation = _0;
+ velocity.Set(_0, _0);
+ angularVelocity = _0;
+ force.Set(_0, _0);
+ torque = _0;
+ friction = _0_2;
- width.Set(1.0f, 1.0f);
+ width.Set(_1, _1);
mass = NUMBER_MAX;
- invMass = 0.0f;
+ invMass = _0;
I = NUMBER_MAX;
- invI = 0.0f;
+ invI = _0;
}
void Body::Set(const Vec2& w, number m)
{
- position.Set(0.0f, 0.0f);
- rotation = 0.0f;
- velocity.Set(0.0f, 0.0f);
- angularVelocity = 0.0f;
- force.Set(0.0f, 0.0f);
- torque = 0.0f;
- friction = 0.2f;
+ position.Set(_0, _0);
+ rotation = _0;
+ velocity.Set(_0, _0);
+ angularVelocity = _0;
+ force.Set(_0, _0);
+ torque = _0;
+ friction = _0_2;
width = w;
mass = m;
if (mass < NUMBER_MAX)
{
- invMass = (number)1.0f / mass;
- I = mass * (width.x * width.x + width.y * width.y) / 12.0f;
- invI = (number)1.0f / I;
+ invMass = (number)_1 / mass;
+ I = mass * (width.x * width.x + width.y * width.y) / _12;
+ invI = (number)_1 / I;
}
else
{
- invMass = 0.0f;
+ invMass = _0;
I = NUMBER_MAX;
- invI = 0.0f;
+ invI = _0;
}
}
diff --git a/Client/Source/Phy2DLite/Collide.cpp b/Client/Source/Phy2DLite/Collide.cpp
index 6849c0e..116a72e 100644
--- a/Client/Source/Phy2DLite/Collide.cpp
+++ b/Client/Source/Phy2DLite/Collide.cpp
@@ -2,6 +2,7 @@
#include "Body.h"
#include "World.h"
#include "Joint.h"
+#include "Constants.h"
using namespace Phy2D;
@@ -58,16 +59,16 @@ int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
number distance1 = Dot(normal, vIn[1].v) - offset;
// If the points are behind the plane
- if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
- if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
+ if (distance0 <= _0) vOut[numOut++] = vIn[0];
+ if (distance1 <= _0) vOut[numOut++] = vIn[1];
// If the points are on different sides of the plane
- if (distance0 * distance1 < 0.0f)
+ if (distance0 * distance1 < _0)
{
// Find intersection point of edge and plane
number interp = distance0 / (distance0 - distance1);
vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);
- if (distance0 > 0.0f)
+ if (distance0 > _0)
{
vOut[numOut].fp = vIn[0].fp;
vOut[numOut].fp.e.inEdge1 = clipEdge;
@@ -96,7 +97,7 @@ static void ComputeIncidentEdge(ClipVertex c[2], const Vec2& h, const Vec2& pos,
if (nAbs.x > nAbs.y)
{
- if (Sign(n.x) > 0.0f)
+ if (Sign(n.x) > _0)
{
c[0].v.Set(h.x, -h.y);
c[0].fp.e.inEdge2 = EDGE3;
@@ -119,7 +120,7 @@ static void ComputeIncidentEdge(ClipVertex c[2], const Vec2& h, const Vec2& pos,
}
else
{
- if (Sign(n.y) > 0.0f)
+ if (Sign(n.y) > _0)
{
c[0].v.Set(h.x, h.y);
c[0].fp.e.inEdge2 = EDGE4;
@@ -152,8 +153,8 @@ namespace Phy2D
int Collide(Contact* contacts, Body* bodyA, Body* bodyB)
{
// Setup
- Vec2 hA = 0.5f * bodyA->width;
- Vec2 hB = 0.5f * bodyB->width;
+ Vec2 hA = _0_5 * bodyA->width;
+ Vec2 hB = _0_5 * bodyB->width;
Vec2 posA = bodyA->position;
Vec2 posB = bodyB->position;
@@ -173,12 +174,12 @@ namespace Phy2D
// Box A faces
Vec2 faceA = Abs(dA) - hA - absC * hB;
- if (faceA.x > 0.0f || faceA.y > 0.0f)
+ if (faceA.x > _0 || faceA.y > _0)
return 0;
// Box B faces
Vec2 faceB = Abs(dB) - absCT * hA - hB;
- if (faceB.x > 0.0f || faceB.y > 0.0f)
+ if (faceB.x > _0 || faceB.y > _0)
return 0;
// Find best axis
@@ -189,16 +190,16 @@ namespace Phy2D
// Box A faces
axis = FACE_A_X;
separation = faceA.x;
- normal = dA.x > 0.0f ? RotA.col1 : -RotA.col1;
+ normal = dA.x > _0 ? RotA.col1 : -RotA.col1;
- const number relativeTol = 0.95f;
- const number absoluteTol = 0.01f;
+ const number relativeTol = _0_95;
+ const number absoluteTol = _0_01;
if (faceA.y > relativeTol * separation + absoluteTol * hA.y)
{
axis = FACE_A_Y;
separation = faceA.y;
- normal = dA.y > 0.0f ? RotA.col2 : -RotA.col2;
+ normal = dA.y > _0 ? RotA.col2 : -RotA.col2;
}
// Box B faces
@@ -206,14 +207,14 @@ namespace Phy2D
{
axis = FACE_B_X;
separation = faceB.x;
- normal = dB.x > 0.0f ? RotB.col1 : -RotB.col1;
+ normal = dB.x > _0 ? RotB.col1 : -RotB.col1;
}
if (faceB.y > relativeTol * separation + absoluteTol * hB.y)
{
axis = FACE_B_Y;
separation = faceB.y;
- normal = dB.y > 0.0f ? RotB.col2 : -RotB.col2;
+ normal = dB.y > _0 ? RotB.col2 : -RotB.col2;
}
// Setup clipping plane data based on the separating axis
diff --git a/Client/Source/Phy2DLite/Constants.h b/Client/Source/Phy2DLite/Constants.h
new file mode 100644
index 0000000..aa50e8c
--- /dev/null
+++ b/Client/Source/Phy2DLite/Constants.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Settings.h"
+
+namespace Phy2D
+{
+#if NUMBER_ALIAS == NUMBER_FPM
+#define CONSTANT(name, value) static number name = number::from_raw_value(value)
+
+ CONSTANT(_1, 65536);
+ CONSTANT(_0, 0);
+ CONSTANT(_0_01, 655);
+ CONSTANT(_0_2, 13107);
+ CONSTANT(_0_5, 32768);
+ CONSTANT(_0_95, 62259);
+ CONSTANT(_12, 786432);
+
+#endif
+} \ No newline at end of file
diff --git a/Client/Source/Phy2DLite/Joint.cpp b/Client/Source/Phy2DLite/Joint.cpp
index 95f7c64..71375d0 100644
--- a/Client/Source/Phy2DLite/Joint.cpp
+++ b/Client/Source/Phy2DLite/Joint.cpp
@@ -1,6 +1,7 @@
#include "Joint.h"
#include "Body.h"
#include "World.h"
+#include "Constants.h"
using namespace Phy2D;
@@ -17,10 +18,10 @@ void Joint::Set(Body* b1, Body* b2, const Vec2& anchor)
localAnchor1 = Rot1T * (anchor - body1->position);
localAnchor2 = Rot2T * (anchor - body2->position);
- P.Set(0.0f, 0.0f);
+ P.Set(_0, _0);
- softness = 0.0f;
- biasFactor = 0.2f;
+ softness = _0;
+ biasFactor = _0_2;
}
void Joint::PreStep(number inv_dt)
@@ -37,8 +38,8 @@ void Joint::PreStep(number inv_dt)
// = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
// [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x]
Mat22 K1;
- K1.col1.x = body1->invMass + body2->invMass; K1.col2.x = 0.0f;
- K1.col1.y = 0.0f; K1.col2.y = body1->invMass + body2->invMass;
+ K1.col1.x = body1->invMass + body2->invMass; K1.col2.x = _0;
+ K1.col1.y = _0; K1.col2.y = body1->invMass + body2->invMass;
Mat22 K2;
K2.col1.x = body1->invI * r1.y * r1.y; K2.col2.x = -body1->invI * r1.x * r1.y;
@@ -64,7 +65,7 @@ void Joint::PreStep(number inv_dt)
}
else
{
- bias.Set(0.0f, 0.0f);
+ bias.Set(_0, _0);
}
if (World::warmStarting)
@@ -78,7 +79,7 @@ void Joint::PreStep(number inv_dt)
}
else
{
- P.Set(0.0f, 0.0f);
+ P.Set(_0, _0);
}
}
diff --git a/Client/Source/Phy2DLite/Math.cpp b/Client/Source/Phy2DLite/Math.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Client/Source/Phy2DLite/Math.cpp
+++ /dev/null
diff --git a/Client/Source/Phy2DLite/World.cpp b/Client/Source/Phy2DLite/World.cpp
index 4f48b69..8852f1f 100644
--- a/Client/Source/Phy2DLite/World.cpp
+++ b/Client/Source/Phy2DLite/World.cpp
@@ -2,10 +2,10 @@
#include "Body.h"
#include "Joint.h"
#include "Arbiter.h"
+#include "Constants.h"
using namespace Phy2D;
-
using std::vector;
using std::map;
using std::pair;
@@ -45,7 +45,7 @@ void World::BroadPhase()
{
Body* bj = bodies[j];
- if (bi->invMass == 0.0f && bj->invMass == 0.0f)
+ if (bi->invMass == _0 && bj->invMass == _0)
continue;
Arbiter newArb(bi, bj);
@@ -73,7 +73,7 @@ void World::BroadPhase()
void World::Step(number dt)
{
- number inv_dt = dt > 0.0f ? (number)1.0f / dt : (number)0.0f;
+ number inv_dt = dt > _0 ? _1 / dt : _0;
// Determine overlapping bodies and update contact points.
BroadPhase();
@@ -83,7 +83,7 @@ void World::Step(number dt)
{
Body* b = bodies[i];
- if (b->invMass == 0.0f)
+ if (b->invMass == _0)
continue;
b->velocity += dt * (gravity + b->invMass * b->force);
@@ -123,7 +123,7 @@ void World::Step(number dt)
b->position += dt * b->velocity;
b->rotation += dt * b->angularVelocity;
- b->force.Set(0.0f, 0.0f);
- b->torque = 0.0f;
+ b->force.Set(_0, _0);
+ b->torque = _0;
}
}
diff --git a/Client/Source/float2fixed/main.cpp b/Client/Source/float2fixed/main.cpp
new file mode 100644
index 0000000..5c4fa40
--- /dev/null
+++ b/Client/Source/float2fixed/main.cpp
@@ -0,0 +1,17 @@
+#include "fpm/include/fpm/fixed.hpp"
+#include "fpm/include/fpm/ios.hpp"
+#include <iostream>
+
+using namespace std;
+
+typedef fpm::fixed_16_16 fixed16;
+
+int main()
+{
+ fixed16 n = 0.95f;
+ cout << n.raw_value();
+
+ getchar();
+
+ return 0;
+} \ No newline at end of file