diff --git a/Bin/Script/PLACEHOLDER b/Bin/Script/PLACEHOLDER
deleted file mode 100644
index e69de29b..00000000
diff --git a/Bin/Settings/ServerInit.ini b/Bin/Settings/ServerInit.ini
deleted file mode 100644
index a3b8f420..00000000
--- a/Bin/Settings/ServerInit.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-port 15151
-clients 200
\ No newline at end of file
diff --git a/Bin/Settings/serversearchpath.ini b/Bin/Settings/serversearchpath.ini
deleted file mode 100644
index 6dc44cff..00000000
--- a/Bin/Settings/serversearchpath.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-ServerInit ..\Settings\ServerInit.ini
-More a
-more b
-more c
\ No newline at end of file
diff --git a/Code/DanBias.sln b/Code/DanBias.sln
index 5e8f837e..4dedaaa2 100644
--- a/Code/DanBias.sln
+++ b/Code/DanBias.sln
@@ -39,10 +39,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameP
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Game\DanBiasServerLauncher\DanBiasServerLauncher.vcxproj", "{060B1890-CBF3-4808-BA99-A4776222093B}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Physics lab", "Physics lab\Physics lab.vcxproj", "{5128BD77-6472-4C4A-BE6F-724AD0E589C2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameServer", "Game\GameServer\GameServer.vcxproj", "{143BD516-20A1-4890-A3E4-F8BFD02220E7}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@@ -257,18 +259,18 @@ Global
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|Win32.Build.0 = Release|Win32
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.ActiveCfg = Release|x64
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.Build.0 = Release|x64
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Mixed Platforms.Build.0 = Debug|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Win32.ActiveCfg = Debug|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Win32.Build.0 = Debug|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|x64.ActiveCfg = Debug|x64
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|x64.Build.0 = Debug|x64
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Mixed Platforms.ActiveCfg = Release|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Mixed Platforms.Build.0 = Release|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.ActiveCfg = Release|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.Build.0 = Release|Win32
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.ActiveCfg = Release|x64
+ {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.Build.0 = Release|x64
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -281,6 +283,18 @@ Global
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Release|Win32.Build.0 = Release|Win32
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Release|x64.ActiveCfg = Release|x64
{143BD516-20A1-4890-A3E4-F8BFD02220E7}.Release|x64.Build.0 = Release|x64
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -295,7 +309,7 @@ Global
{8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{060B1890-CBF3-4808-BA99-A4776222093B} = {20720CA7-795C-45AD-A302-9383A6DD503A}
- {666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{143BD516-20A1-4890-A3E4-F8BFD02220E7} = {20720CA7-795C-45AD-A302-9383A6DD503A}
+ {666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A}
EndGlobalSection
EndGlobal
diff --git a/Code/Dokumentation/LevelLoader.uxf b/Code/Dokumentation/LevelLoader.uxf
new file mode 100644
index 00000000..723857bb
--- /dev/null
+++ b/Code/Dokumentation/LevelLoader.uxf
@@ -0,0 +1,277 @@
+
+
+ 8
+
+ com.umlet.element.Package
+
+ 552
+ 320
+ 584
+ 368
+
+ LevelLoader
+
+
+
+ com.umlet.element.Class
+
+ 440
+ 88
+ 128
+ 40
+
+ GameLogic
+<<Erik>>
+
+
+
+ com.umlet.element.Relation
+
+ 768
+ 472
+ 136
+ 104
+
+ lt=<<<<-
+ 120;24;120;88;24;88
+
+
+ com.umlet.element.Class
+
+ 560
+ 544
+ 232
+ 136
+
+ <<Interface>>
+Parser
+--
+Functions:
+vector<struct> Parse();
+-
+Privates:
+enum headerType;
+const int FileHeaderSize;
+const int FileVersion;
+
+
+
+
+ com.umlet.element.Class
+
+ 624
+ 208
+ 80
+ 24
+
+ LevelLoader
+
+
+
+
+ com.umlet.element.Relation
+
+ 640
+ 208
+ 40
+ 168
+
+ lt=<<.
+ 24;24;24;152
+
+
+ com.umlet.element.Relation
+
+ 384
+ 176
+ 256
+ 56
+
+ lt=->>>>
+m1=1..1
+m2=1..1
+<Knows about
+ 240;40;24;40
+
+
+ com.umlet.element.Package
+
+ 248
+ 320
+ 248
+ 160
+
+ Defines
+
+
+
+ com.umlet.element.Class
+
+ 800
+ 360
+ 208
+ 136
+
+ <<Interface>>
+Loader
+--
+Functions:
+wchar* LoadFile(string fileName);
+Model* LoadModel(string modelName);
+Model* LoadModel(int modelID);
+-
+Privates:
+
+
+
+ com.umlet.element.Class
+
+ 328
+ 208
+ 80
+ 24
+
+ Defines
+
+
+
+ com.umlet.element.Class
+
+ 256
+ 360
+ 232
+ 104
+
+ Defines.h
+<<Header file>>
+--
+Enum ObjectType(static, dynamic, specials);
+.
+Struct static;
+Struct dynamic;
+Struct specials
+
+
+
+ com.umlet.element.Relation
+
+ 680
+ 176
+ 152
+ 56
+
+ lt=-
+m1=1..1
+m2=1..1
+Uses>
+ 24;40;136;40
+
+
+ com.umlet.element.Class
+
+ 816
+ 192
+ 128
+ 40
+
+ Resource Loader
+<<Dennis>><<Singleton>
+
+
+
+ com.umlet.element.Class
+
+ 928
+ 560
+ 200
+ 120
+
+ Collection of functions
+<<lots of functions>>
+--
+functions for creating the right structs
+
+
+
+ com.umlet.element.Relation
+
+ 768
+ 576
+ 176
+ 56
+
+ lt=-
+m1=1..1
+m2=1..1
+Uses>
+ 24;40;160;40
+
+
+ com.umlet.element.Class
+
+ 560
+ 360
+ 232
+ 136
+
+ LevelLoader
+<<API>><Interface>>
+--
+Functions:
+vector<struct> LoadLevel(String fileName);
+struct LoadLevelHeader(String fileName);
+-
+Privates:
+
+
+
+
+
+ com.umlet.element.Relation
+
+ 344
+ 208
+ 40
+ 168
+
+ lt=<<.
+ 24;24;24;152
+
+
+ com.umlet.element.Relation
+
+ 840
+ 208
+ 88
+ 168
+
+ lt=.
+<Uses
+ 24;24;24;64;72;64;72;152
+
+
+ com.umlet.element.Relation
+
+ 656
+ 472
+ 40
+ 88
+
+ lt=<<<<-
+ 24;72;24;24
+
+
+ com.umlet.element.Relation
+
+ 544
+ 64
+ 136
+ 160
+
+ lt=lt=->>>>
+m1=1..1
+m2=1..1
+Uses>
+ 24;40;80;40;120;40;120;144
+
+
diff --git a/Code/Dokumentation/Other/Timestep_Impulse_Fix.odt b/Code/Dokumentation/Other/Timestep_Impulse_Fix.odt
new file mode 100644
index 00000000..1ad0992a
Binary files /dev/null and b/Code/Dokumentation/Other/Timestep_Impulse_Fix.odt differ
diff --git a/Code/Dokumentation/Other/Timestep_Impulse_Fix.pdf b/Code/Dokumentation/Other/Timestep_Impulse_Fix.pdf
new file mode 100644
index 00000000..4b99c319
Binary files /dev/null and b/Code/Dokumentation/Other/Timestep_Impulse_Fix.pdf differ
diff --git a/Code/Dokumentation/Other/angular momentum to angular velocity.odt b/Code/Dokumentation/Other/angular momentum to angular velocity.odt
new file mode 100644
index 00000000..d0faa22d
Binary files /dev/null and b/Code/Dokumentation/Other/angular momentum to angular velocity.odt differ
diff --git a/Code/Dokumentation/Other/angular momentum to angular velocity.pdf b/Code/Dokumentation/Other/angular momentum to angular velocity.pdf
new file mode 100644
index 00000000..8c6ef85b
Binary files /dev/null and b/Code/Dokumentation/Other/angular momentum to angular velocity.pdf differ
diff --git a/Code/Dokumentation/Other/angular_momentum_to_angular_velocity.pdf b/Code/Dokumentation/Other/angular_momentum_to_angular_velocity.pdf
new file mode 100644
index 00000000..820bf412
Binary files /dev/null and b/Code/Dokumentation/Other/angular_momentum_to_angular_velocity.pdf differ
diff --git a/Code/Dokumentation/Physics_Sprint3.uxf b/Code/Dokumentation/Physics_Sprint3.uxf
new file mode 100644
index 00000000..6b74de3e
--- /dev/null
+++ b/Code/Dokumentation/Physics_Sprint3.uxf
@@ -0,0 +1,1059 @@
+
+
+ 7
+
+
+ com.umlet.element.Class
+
+ 357
+ 518
+ 252
+ 406
+
+ Formula : <<namespace>>
+<<extern>>
+--
+LinearMomentum( .. ) : Vector
+LinearVelocity( .. ) : Vector
+AngularMomentum( .. ) : Vector
+AngularVelocity( .. ) : Vector
+TangientialLinearMomentum( .. ) : Vector
+LinearKineticEnergy( .. ) : Float
+AngularKineticEnergy( .. ) : Float
+TangientialImpulseForce( .. ) : Vector
+AngularImpulseAcceleration( .. ) : Vector
+TangientialImpulseAcceleration( .. ) : Vector
+TangientialLinearVelocity( .. ) : Vector
+LinearImpulseAcceleration( .. ) : Vector
+ImpulseForce( .. ) : Vector
+ImpulseTorque( .. ) : Vector
+Forcefield( .. ) : Float
+
+
+
+ com.umlet.element.Class
+
+ 364
+ 728
+ 238
+ 189
+
+ MomentOfInertia : <<namespace>>
+<<extern>>
+--
+CalculateSphere( .. ) : Float
+Sphere( .. ) : Matrix
+CalculateHollowSphere( .. ) : Float
+HollowSphere( .. ) : Matrix
+CalculateCuboidX( .. ) : Float
+CalculateCuboidY( .. ) : Float
+CalculateCuboidZ( .. ) : Float
+Cuboid( .. ) : Matrix
+CalculateRodCenter( .. ) : Float
+RodCenter( .. ) : Matrix
+CalculateCylinderXY( .. ) : Float
+CalculateCylinderZ( .. ) : Float
+Cylinder( .. ) : Matrix
+
+
+
+ com.umlet.element.Class
+
+ 616
+ 518
+ 210
+ 35
+
+ RigidBody : struct
+--
+Update_LeapFrog( deltatime : Float ) : void
+
+
+
+ com.umlet.element.Class
+
+ 616
+ 581
+ 210
+ 203
+
+ MomentOfInertia : struct
+--
+CalculateAngularVelocity( .. ) : Vector
+CalculateAngularMomentum( .. ) : Vector
+--
+<<static>> CalculateSphere( .. ) : Float
+<<static>> Sphere( .. ) : MomentOfInertia
+<<static>> CalculateHollowSphere( .. ) : Float
+<<static>> HollowSphere( .. ) : MomentOfInertia
+<<static>> CalculateCuboidX( .. ) : Float
+<<static>> CalculateCuboidY( .. ) : Float
+<<static>> CalculateCuboidZ( .. ) : Float
+<<static>> Cuboid( .. ) : MomentOfInertia
+<<static>> CalculateRodCenter( .. ) : Float
+<<static>> RodCenter( .. ) : MomentOfInertia
+<<static>> CalculateCylinderXY( .. ) : Float
+<<static>> CalculateCylinderZ( .. ) : Float
+<<static>> Cylinder( .. ) : MomentOfInertia
+
+
+
+ com.umlet.element.Class
+
+ 728
+ 847
+ 98
+ 21
+
+ FluidDrag : struct
+
+
+
+ com.umlet.element.Class
+
+ 728
+ 875
+ 98
+ 21
+
+ Particle : struct
+
+
+
+ com.umlet.element.Class
+
+ 728
+ 903
+ 98
+ 21
+
+ Spring : struct
+
+
+
+ com.umlet.element.Relation
+
+ 644
+ 532
+ 132
+ 62
+
+ lt=<-
+<<uses>>
+ 119;49;119;35;21;35;21;21
+
+
+ com.umlet.element.Class
+
+ 350
+ 483
+ 483
+ 448
+
+ Physics3D : <<namespace>>
+<<extern>>
+bg=green
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 560
+ 420
+ 161
+ 49
+
+ Constant : <<namespace>>
+<<extern>>
+--
+gravity_constant : const Float
+
+
+
+
+ com.umlet.element.Class
+
+ 224
+ 385
+ 329
+ 84
+
+ Default : <<namespace>>
+<<intern>>
+--
+EventAction_Destruction : <<PhysicsAPI::EventAction_Destruction>>
+EventAction_Collision : <<ICustomBody::EventAction_Collision>>
+EventAction_CollisionResponse : <<ICustomBody::EventAction_Collision>>
+EventAction_Move : <<ICustomBody::EventAction_Collision>>
+
+
+
+
+ com.umlet.element.Class
+
+ 245
+ 63
+ 224
+ 196
+
+ API : <<interface>>
+--
+{innerclass
+ EventAction_Destruction : <<FunctionPointer>>
+innerclass}
+
+Init( .. ) : void
+SetFrameTimeLength( .. ) : void
+SetGravityConstant( .. ) : void
+SetSubscription( .. ) : void
+Update() : void
+IsInLimbo( .. ) : bool
+MoveToLimbo( .. ) : void
+ReleaseFromLimbo( .. ) : void
+AddObject( .. ) : void
+ExtractObject( .. ) : ICustomBody*
+DestroyObject( .. ) : void
+AddGravity( .. ) : void
+RemoveGravity( .. ) : void
+ApplyEffect( .. ) : void
+CreateRigidBody( .. ) : ICustomBody*
+
+
+
+ com.umlet.element.Class
+
+ 273
+ 280
+ 133
+ 28
+
+ API_Impl : <<class>>
+--
+<<uses>> OctTree : class
+
+
+
+ com.umlet.element.Class
+
+ 476
+ 63
+ 280
+ 287
+
+ ICustomBody : <<interface>>
+
+{innerclass
+ SubscriptMessage : Enum
+innerclass}
+
+{innerclass
+ EventAction_Collision : <<Subscription : SubscriptMessage>>
+innerclass}
+
+{innerclass
+ EventAction_CollisionResponse : <<Subscription : void>>
+innerclass}
+
+{innerclass
+ EventAction_Move : <<Subscription : void>>
+innerclass}
+
+Clone() : ICustomBody*
+CallSubscription_Collision( .. ) : SubscriptMessage
+CallSubscription_CollisionResponse( .. ) : void
+CallSubscription_Move() : void
+GetState( .. ) : State
+SetState( .. ) : void
+IsAffectedByGravity() : bool
+Intersects( .. ) : bool
+GetBoundingSphere : Sphere
+GetNormalAt( .. ) : Vector
+GetGravityNormal( .. ) : Vector
+GetCustomTag() : void*
+Update( .. ) : UpdateState
+Predict( .. ) : void
+SetScene( .. ) : void
+SetSubscription( .. ) : void
+SetGravity( .. ) : void
+SetGravityNormal( .. ) : void
+SetCustomTag( .. ) : void
+
+
+
+ com.umlet.element.Class
+
+ 273
+ 315
+ 175
+ 28
+
+ SimpleRigidBody : <<class>>
+--
+<<uses>> Physics3D::RigidBody : struct
+
+
+
+ com.umlet.element.Class
+
+ 273
+ 350
+ 175
+ 28
+
+ SphericalRigidBody : <<class>>
+--
+<<uses>> Physics3D::RigidBody : struct
+
+
+
+ com.umlet.element.Class
+
+ 21
+ 273
+ 196
+ 196
+
+ Formula : <<namespace>>
+<<intern>>
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 308
+ 175
+ 84
+
+ MomentOfInertia : <<namespace>>
+<<intern>>
+--
+CreateSphereMatrix( .. ) : Matrix
+CreateHollowSphereMatrix( .. ) : Matrix
+CreateCuboidMatrix( .. ) : Matrix
+CreateCylinderMatrix( .. ) : Matrix
+CreateRodMatrix( .. ) : Matrix
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 406
+ 175
+ 56
+
+ CollisionResponse : <<namespace>>
+<<intern>>
+--
+Bounce( .. ) : Float
+Friction( .. ) : Vector
+
+
+
+ com.umlet.element.Relation
+
+ 308
+ 238
+ 34
+ 55
+
+ lt=<<.
+ 21;21;21;42
+
+
+ com.umlet.element.Relation
+
+ 427
+ 308
+ 97
+ 76
+
+ lt=<<.
+ 84;42;84;63;35;63;35;21;21;21
+
+
+ com.umlet.element.Class
+
+ 560
+ 371
+ 203
+ 42
+
+ OctTree : <<class>>
+--
+<<uses>> Collision3D::Sphere : struct
+<<uses>> Collision3D::BoxAxisAligned : struct
+
+
+
+ com.umlet.element.Relation
+
+ 518
+ 329
+ 100
+ 55
+
+ lt=<-
+ <<uses>>
+ 56;21;56;42
+
+
+ com.umlet.element.Relation
+
+ 427
+ 329
+ 97
+ 55
+
+ lt=.
+ 84;21;84;42;21;42
+
+
+ com.umlet.element.Class
+
+ 21
+ 63
+ 182
+ 196
+
+ Struct : <<namespace>>
+<<extern>>
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 203
+ 168
+ 14
+
+ SimpleBodyDescription : struct
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 231
+ 168
+ 14
+
+ SimpleSphericalDescription : struct
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 175
+ 168
+ 14
+
+ CustomBodyState : struct
+
+
+
+ com.umlet.element.Class
+
+ 28
+ 91
+ 168
+ 63
+
+ Gravity : struct
+{innerclass
+ GravityWell
+innerclass}
+{innerclass
+ GravityDirected
+innerclass}
+{innerclass
+ GravityDirectedField
+innerclass}
+
+
+
+ com.umlet.element.Relation
+
+ 182
+ 105
+ 104
+ 195
+
+ lt=<-
+ <<uses>>
+ 21;21;56;21;56;168;91;168;91;182
+
+
+ com.umlet.element.Relation
+
+ 182
+ 161
+ 104
+ 139
+
+ lt=<-
+ 21;21;56;21;56;112;91;112;91;126
+
+
+ com.umlet.element.Relation
+
+ 385
+ 252
+ 104
+ 49
+
+ lt=<-
+<<uses>>
+ 91;35;21;35
+
+
+ com.umlet.element.Relation
+
+ 182
+ 189
+ 104
+ 181
+
+ lt=<-
+ 21;21;42;21;42;168;91;168
+
+
+ com.umlet.element.Relation
+
+ 175
+ 217
+ 111
+ 153
+
+ lt=<-
+ <<uses>>
+ 28;21;49;21;49;140;98;140
+
+
+ com.umlet.element.Relation
+
+ 231
+ 301
+ 55
+ 69
+
+ lt=-
+ 42;21;42;21;21;21;21;56
+
+
+ com.umlet.element.Class
+
+ 14
+ 35
+ 756
+ 441
+
+ Physics : <<namespace>>
+<<extern>>
+bg=green
+--
+
+
+
+
+ com.umlet.element.Class
+
+ 0
+ 0
+ 847
+ 945
+
+ Oyster : <<namespace>>
+<<extern>>
+bg=orange
+--
+
+
+
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 546
+ 126
+ 21
+
+ Box : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 518
+ 126
+ 21
+
+ ICollideAble : <<interface>>
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 574
+ 126
+ 21
+
+ AxisAlignedBox : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 602
+ 126
+ 21
+
+ Point : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 630
+ 126
+ 21
+
+ Sphere : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 770
+ 126
+ 21
+
+ Frustrum : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 658
+ 126
+ 21
+
+ Ray : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 700
+ 126
+ 21
+
+ Line : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 728
+ 126
+ 21
+
+ Plane : class
+
+
+
+ com.umlet.element.Class
+
+ 175
+ 798
+ 126
+ 21
+
+ Universe : class
+
+
+
+ com.umlet.element.Class
+
+ 21
+ 518
+ 126
+ 70
+
+ Utility : <<namespace>>
+<<extern>>
+--
+Compare( .. ) : void
+Intersect( .. ) : bool
+Contain( .. ) : bool
+
+
+
+ com.umlet.element.Relation
+
+ 280
+ 504
+ 55
+ 321
+
+ lt=<<.
+ 21;21;42;21;42;308;21;308
+
+
+ com.umlet.element.Relation
+
+ 280
+ 721
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 693
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 651
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 763
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 623
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 595
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 567
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 280
+ 539
+ 55
+ 34
+
+ lt=.
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 196
+ 658
+ 83
+ 55
+
+ lt=<-
+<<uses>>
+ 21;21;21;35;70;35;70;42
+
+
+ com.umlet.element.Relation
+
+ 35
+ 567
+ 153
+ 84
+
+ lt=<-
+ <<uses>>
+ 49;21;49;70;140;70
+
+
+ com.umlet.element.Relation
+
+ 133
+ 504
+ 55
+ 286
+
+ lt=-
+ 42;21;21;21;21;273;42;273
+
+
+ com.umlet.element.Relation
+
+ 196
+ 728
+ 83
+ 55
+
+ lt=<-
+<<uses>>
+ 21;21;21;35;70;35;70;42
+
+
+ com.umlet.element.Relation
+
+ 133
+ 714
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 644
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 588
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 560
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 133
+ 532
+ 55
+ 34
+
+ lt=-
+ 42;21;21;21
+
+
+ com.umlet.element.Class
+
+ 14
+ 483
+ 329
+ 343
+
+ Collision3D : <<namespace>>
+<<extern>>
+bg=green
+--
+
+
+
+
+
+ com.umlet.element.Class
+
+ 938
+ 77
+ 98
+ 28
+
+ OysterPhysics3D
+<<lib>>
+bg=green
+
+
+
+ com.umlet.element.Class
+
+ 896
+ 175
+ 42
+ 21
+
+ Misc
+bg=green
+
+
+
+ com.umlet.element.Class
+
+ 952
+ 175
+ 70
+ 21
+
+ OysterMath
+bg=green
+
+
+
+ com.umlet.element.Relation
+
+ 896
+ 98
+ 34
+ 90
+
+ lt=())
+ 21;77;21;21
+
+
+ com.umlet.element.Relation
+
+ 966
+ 98
+ 28
+ 84
+
+ lt=())
+ 21;77;21;21
+
+
+ com.umlet.element.Class
+
+ 896
+ 28
+ 161
+ 28
+
+ GamePhysics
+<<dll>>
+bg=green
+
+
+
+ com.umlet.element.Relation
+
+ 896
+ 35
+ 48
+ 97
+
+ lt=-
+ 35;84;21;84;21;21
+
+
+ com.umlet.element.Class
+
+ 889
+ 0
+ 175
+ 133
+
+ Project Dependencies
+--
+bg=blue
+
+
+
+ com.umlet.element.Relation
+
+ 910
+ 84
+ 90
+ 48
+
+ lt=-
+ 21;35;77;35;77;21
+
+
+ com.umlet.element.Relation
+
+ 1036
+ 21
+ 105
+ 28
+
+ lt=<()
+r1=provide
+ 98;21;21;21
+
+
+ com.umlet.element.Relation
+
+ 1015
+ 70
+ 126
+ 28
+
+ lt=<()
+r1=provide
+ 119;21;21;21
+
+
+
diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h
index 360d1c60..f7214b32 100644
--- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h
+++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h
@@ -13,6 +13,13 @@ struct GameRecieverObject :public Oyster::Network::NetworkClient
// parsing protocols and sending it to the gameState
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
{
+
+ //if( IsGameplayProtocol(p[protocol_INDEX_ID].value.netShort) )
+ //ParseGameplayEvent(e.protocol, e.gameClient);
+
+ //if( IsGeneralProtocol(p[protocol_INDEX_ID].value.netShort) )
+ //ParseGeneralEvent(e.protocol, e.gameClient);
+
int pType = p[0].value.netInt;
switch (pType)
{
@@ -88,18 +95,15 @@ struct GameRecieverObject :public Oyster::Network::NetworkClient
case protocol_Gameplay_ObjectPosition:
{
- Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos;
- protocolData->object_ID = p[1].value.netInt;
+ Client::GameClientState::ObjPos protocolData;
+ protocolData.object_ID = p[1].value.netInt;
for(int i = 0; i< 16; i++)
{
- protocolData->worldPos[i] = p[i+2].value.netFloat;
+ protocolData.worldPos[i] = p[i+2].value.netFloat;
}
if(dynamic_cast(gameClientState))
- ((Client::GameState*)gameClientState)->Protocol(protocolData);
-
- delete protocolData;
- protocolData = NULL;
+ ((Client::GameState*)gameClientState)->Protocol(&protocolData);
}
break;
@@ -107,6 +111,8 @@ struct GameRecieverObject :public Oyster::Network::NetworkClient
break;
}
+
+
}
};
}
diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp
index 3e89a824..871ff558 100644
--- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp
+++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp
@@ -75,33 +75,10 @@ bool GameState::LoadModels(std::wstring mapFile)
// init models
privData->modelCount = 2;
+ // add world model
ModelInitData modelData;
-
- modelData.world = Oyster::Math3D::Float4x4::identity;
- Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
- modelData.world = modelData.world * translate;
- modelData.visible = true;
- modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
- modelData.id = 0;
- // load models
- C_Object* obj = new C_Player();
- privData->object.push_back(obj);
- privData->object[privData->object.size() -1 ]->Init(modelData);
-
- translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2));
- modelData.world = modelData.world * translate;
- modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
- modelData.id ++;
-
- obj = new C_Player();
- privData->object.push_back(obj);
- privData->object[privData->object.size() -1 ]->Init(modelData);
-
- /*translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
- modelData.world = modelData.world * translate;
- modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
- modelData.id ++;*/
-
+ Oyster::Math3D::Float4x4 translate;
+ C_Object* obj;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
scale.v[0].x = 8;
@@ -109,12 +86,40 @@ bool GameState::LoadModels(std::wstring mapFile)
scale.v[2].z = 8;
modelData.world = scale; //modelData.world * translate
modelData.modelPath = L"..\\Content\\Models\\ball.dan";
- modelData.id ++;
+ modelData.id = 0;
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
+ // add box model
+ modelData.world = Oyster::Math3D::Float4x4::identity;
+ translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-5,15,0));
+ modelData.world = modelData.world * translate;
+ modelData.modelPath = L"..\\Content\\Models\\box.dan";
+ modelData.id = 1;
+
+ obj = new C_Player();
+ privData->object.push_back(obj);
+ privData->object[privData->object.size() -1 ]->Init(modelData);
+ modelData.world = Oyster::Math3D::Float4x4::identity;
+
+ // add player model
+ modelData.world = Oyster::Math3D::Float4x4::identity;
+ translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 15, 0));
+ modelData.world = modelData.world * translate;
+ modelData.visible = true;
+ modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
+ modelData.id = 2;
+ // load models
+ obj = new C_Player();
+ privData->object.push_back(obj);
+ privData->object[privData->object.size() -1 ]->Init(modelData);
+
+
+
+
+
return true;
}
@@ -195,8 +200,6 @@ bool GameState::Release()
privData->object[i] = NULL;
}
- delete this->camera;
-
delete privData;
privData = NULL;
return true;
@@ -330,10 +333,10 @@ void GameState::Protocol( ObjPos* pos )
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
//camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6])));
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
- if(i == 0)
+ if(i == 2) // playerobj
{
- camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
- camera->UpdateViewMatrix();
+ //camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
+ //camera->UpdateViewMatrix();
}
}
}
diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp
index 38f499eb..95bad91c 100644
--- a/Code/Game/DanBiasLauncher/Launcher.cpp
+++ b/Code/Game/DanBiasLauncher/Launcher.cpp
@@ -18,7 +18,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
DanBias::DanBiasGameDesc gameDesc;
gameDesc.port = 15151;
//gameDesc.port = 15152;
- //gameDesc.IP = "193.11.184.196";
+ //gameDesc.IP = "193.11.184.109";
//gameDesc.IP = "193.11.184.31";
//gameDesc.IP = "194.47.150.56";
gameDesc.IP = "127.0.0.1";
diff --git a/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp b/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp
index fbf19b57..62e2b828 100644
--- a/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp
+++ b/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp
@@ -19,12 +19,17 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
WindowShell::CreateConsoleWindow();
- DanBias::GameServerAPI::GameInitDesc desc;
+ DanBias::GameServerAPI::ServerInitDesc desc;
desc.listenPort = 15151;
- if(DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess)
+ if(DanBias::GameServerAPI::ServerInitiate(desc) == DanBias::DanBiasServerReturn_Sucess)
{
- DanBias::GameServerAPI::Start();
- DanBias::GameServerAPI::Terminate();
+ DanBias::GameServerAPI::ServerStart();
+ while (!(GetAsyncKeyState(0x51))) //Q for exit
+ {
+ DanBias::GameServerAPI::ServerUpdate();
+ Sleep(1);
+ }
+ DanBias::GameServerAPI::ServerStop();
}
return cmdShow;
}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp
index 6ec70e1b..9343ba5b 100644
--- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp
+++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp
@@ -3,71 +3,70 @@
using namespace GameLogic;
-struct AttatchmentMassDriver::PrivateData
-{
- PrivateData()
- {
-
- }
-
- ~PrivateData()
- {
-
- }
-
-}myData;
AttatchmentMassDriver::AttatchmentMassDriver(void)
{
- myData = new PrivateData();
this->owner = 0;
}
AttatchmentMassDriver::AttatchmentMassDriver(Player &owner)
{
- myData = new PrivateData();
+
this->owner = &owner;
}
AttatchmentMassDriver::~AttatchmentMassDriver(void)
{
- delete myData;
+
}
/********************************************************
* Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used
********************************************************/
-void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage)
+void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, float dt)
{
//switch case to determin what functionallity to use in the attatchment
switch (usage)
{
case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS:
- ForcePush(usage);
+ ForcePush(usage,dt);
break;
case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS:
- ForcePull(usage);
+ ForcePull(usage,dt);
break;
}
-
+
}
/********************************************************
* Pushes objects in a cone in front of the weapon when fired
********************************************************/
-void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage)
+void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt)
{
- //create coneRigidBody that will then collide with object and push them in the aimed direction
+ //Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt);
+ Oyster::Math::Float3 weaponPos;
+ weaponPos = owner->GetPosition() + 5 * owner->GetLookDir();
+ Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), weaponPos);
+ Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20);
+ Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace));
+
+ Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,NULL, ForcePushAction);
+
}
/********************************************************
* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack)
********************************************************/
-void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage)
+void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt)
{
- //Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100);
+ Oyster::Physics::Struct::CustomBodyState state = this->owner->GetRigidBody()->GetState();
+
+ //do something with state
+ state.ApplyLinearImpulse(Oyster::Math::Float3(this->owner->GetLookDir()) * (500 * dt));
+
+ this->owner->GetRigidBody()->SetState(state);
}
diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h
index a1ededd0..594ea4fd 100644
--- a/Code/Game/GameLogic/AttatchmentMassDriver.h
+++ b/Code/Game/GameLogic/AttatchmentMassDriver.h
@@ -15,30 +15,31 @@ namespace GameLogic
~AttatchmentMassDriver(void);
- void UseAttatchment(const WEAPON_FIRE &usage);
+ void UseAttatchment(const WEAPON_FIRE &usage, float dt);
private:
/********************************************************
* Pushes objects and players in a cone in front of the player
* @param fireInput: allows switching on different functionality in this specific function
********************************************************/
- void ForcePush(const WEAPON_FIRE &usage);
+ void ForcePush(const WEAPON_FIRE &usage, float dt);
/********************************************************
* Pulls the player forward, this is a movement tool
* @param fireInput: allows switching on different functionality in this specific function
********************************************************/
- void ForcePull(const WEAPON_FIRE &usage);
+ void ForcePull(const WEAPON_FIRE &usage, float dt);
/********************************************************
* Sucks objects towards the player, the player can then pick up an object and throw it as a projectile
* @param fireInput: allows switching on different functionality in this specific function
********************************************************/
- void ForceSuck(const WEAPON_FIRE &usage);
+ void ForceSuck(const WEAPON_FIRE &usage, float dt);
+
+ static void ForcePushAction(Oyster::Physics::ICustomBody *obj, void* args);
private:
- struct PrivateData;
- PrivateData *myData;
+
};
}
#endif
diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp
index a3d9097c..4a663bef 100644
--- a/Code/Game/GameLogic/AttatchmentSocket.cpp
+++ b/Code/Game/GameLogic/AttatchmentSocket.cpp
@@ -5,25 +5,10 @@
using namespace GameLogic;
using namespace Utility::DynamicMemory;
-struct AttatchmentSocket::PrivateData
-{
- PrivateData()
- {
-
- }
-
- ~PrivateData()
- {
-
- }
-
- SmartPointer attatchment;
-
-
-}myData;
AttatchmentSocket::AttatchmentSocket(void)
{
+ this->attatchment = 0;
}
@@ -34,17 +19,17 @@ AttatchmentSocket::~AttatchmentSocket(void)
IAttatchment* AttatchmentSocket::GetAttatchment()
{
- return myData->attatchment;
+ return this->attatchment;
}
void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment)
{
- myData->attatchment = attatchment;
+ this->attatchment = attatchment;
}
void AttatchmentSocket::RemoveAttatchment()
{
- myData->attatchment = 0;
+ this->attatchment = 0;
}
diff --git a/Code/Game/GameLogic/AttatchmentSocket.h b/Code/Game/GameLogic/AttatchmentSocket.h
index 2257dd7a..8c5745c5 100644
--- a/Code/Game/GameLogic/AttatchmentSocket.h
+++ b/Code/Game/GameLogic/AttatchmentSocket.h
@@ -19,8 +19,7 @@ namespace GameLogic
void RemoveAttatchment();
private:
- struct PrivateData;
- PrivateData *myData;
+ IAttatchment *attatchment;
};
}
#endif
\ No newline at end of file
diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp
index 4cdb3689..00830301 100644
--- a/Code/Game/GameLogic/CollisionManager.cpp
+++ b/Code/Game/GameLogic/CollisionManager.cpp
@@ -1,62 +1,89 @@
-#include "CollisionManager.h"
#include "PhysicsAPI.h"
#include "Object.h"
#include "DynamicObject.h"
#include "Player.h"
+#include "Level.h"
+#include "AttatchmentMassDriver.h"
+#include "Game.h"
using namespace Oyster;
using namespace GameLogic;
- void PlayerVBox(Player &player, DynamicObject &box);
+ void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss);
+ void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss);
-
- Physics::ICustomBody::SubscriptMessage CollisionManager::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
+ //Physics::ICustomBody::SubscriptMessage
+ void Player::PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
{
- //Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef));
- //Object *realObj = (Object*)obj->gameObjectRef;
+
+ Player *player = ((Game::PlayerData*)(rigidBodyPlayer->GetCustomTag()))->player;
+ Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed?
- //switch (realObj->GetType())
- //{
- //case OBJECT_TYPE::OBJECT_TYPE_BOX:
- // PlayerVBox(*player,(*(DynamicObject*) realObj));
- // break;
- //case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
- //
- // break;
- //}
+ switch (realObj->GetType())
+ {
+ case OBJECT_TYPE::OBJECT_TYPE_GENERIC:
+ PlayerVObject(*player,*realObj, kineticEnergyLoss);
+ //return Physics::ICustomBody::SubscriptMessage_none;
+ break;
+
+ case OBJECT_TYPE::OBJECT_TYPE_BOX:
+ PlayerVBox(*player,(*(DynamicObject*) realObj), kineticEnergyLoss);
+ //return Physics::ICustomBody::SubscriptMessage_none;
+ break;
+ case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
+ //return Physics::ICustomBody::SubscriptMessage_none;
+ break;
+ case OBJECT_TYPE::OBJECT_TYPE_WORLD:
+ int test = 5;
+ break;
+ }
- return Physics::ICustomBody::SubscriptMessage_none;
+ //return Physics::ICustomBody::SubscriptMessage_none;
}
- void PlayerVBox(Player &player, DynamicObject &box)
+ void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss)
{
+ //use kinetic energyloss of the collision in order too determin how much damage to take
+ //use as part of the damage algorithm
player.DamageLife(20);
}
-
- Physics::ICustomBody::SubscriptMessage CollisionManager::BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj)
+
+ void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss)
{
- if(rigidBodyBox == 0)
+ //Collision between a player and a general static or dynamic object
+ //use kinetic energyloss of the collision in order too determin how much damage to take
+ //use as part of the damage algorithm
+ int damageDone = 0;
+ int forceThreashHold = 200;
+
+ if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
{
- return Physics::ICustomBody::SubscriptMessage::SubscriptMessage_none;
+ damageDone = kineticEnergyLoss * 0.10f;
+ player.DamageLife(damageDone);
}
- //DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef;
- //Object *realObj = (Object*)obj->gameObjectRef;
-
- //switch (realObj->GetType())
- //{
- //case OBJECT_TYPE::OBJECT_TYPE_BOX:
- //
- // break;
- //case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
- // //PlayerVBox(*(Player*)realObj,*box);
- // break;
- //}
-
+
+ }
+ Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
+ {
return Physics::ICustomBody::SubscriptMessage_none;
}
-
- Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj)
+ //Oyster::Physics::ICustomBody::SubscriptMessage
+ Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
}
+ Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
+ {
+ return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
+ }
+
+ void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj, void* args)
+ {
+ Oyster::Math::Float3 pushForce = Oyster::Math::Float4(1,0,0) * (20);
+ Oyster::Physics::ICustomBody::State state;
+ state = obj->GetState();
+ state.ApplyLinearImpulse(pushForce);
+ obj->SetState(state);
+ //((Object*)obj->GetCustomTag())->ApplyLinearImpulse(pushForce);
+ }
diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h
index 21723885..6179333f 100644
--- a/Code/Game/GameLogic/CollisionManager.h
+++ b/Code/Game/GameLogic/CollisionManager.h
@@ -10,14 +10,7 @@ namespace GameLogic
class CollisionManager
{
public:
- //these are the main collision functions
- //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
- static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
- static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj);
- static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj);
- //these are the specific collision case functions
- //void PlayerVBox(Player &player, DynamicObject &box);
- //void BoxVBox(DynamicObject &box1, DynamicObject &box2);
+ //put general collision functions here that are not part of a specific object
};
diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp
index a8ea1ab4..437dca2c 100644
--- a/Code/Game/GameLogic/DynamicObject.cpp
+++ b/Code/Game/GameLogic/DynamicObject.cpp
@@ -7,15 +7,34 @@ using namespace GameLogic;
DynamicObject::DynamicObject()
:Object()
{
-
-}
-DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type)
- :Object(collisionFunc, type)
+}
+DynamicObject::DynamicObject(OBJECT_TYPE type)
+ :Object(type)
+{
+
+}
+DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
+ :Object(rigidBody,type)
{
}
+DynamicObject::DynamicObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+ :Object(collisionFuncBefore,collisionFuncAfter,type)
+{
+
+}
+DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+ :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
+{
+
+}
+DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
+ :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
+{
+
+}
DynamicObject::~DynamicObject(void)
{
diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h
index 70b5efe7..3fcdae39 100644
--- a/Code/Game/GameLogic/DynamicObject.h
+++ b/Code/Game/GameLogic/DynamicObject.h
@@ -14,7 +14,12 @@ namespace GameLogic
public:
DynamicObject();
- DynamicObject(void* collisionFunc, OBJECT_TYPE type);
+ DynamicObject(OBJECT_TYPE type);
+ DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
+ DynamicObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
+
~DynamicObject(void);
private:
diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp
index 4380777e..ca666c2f 100644
--- a/Code/Game/GameLogic/Game.cpp
+++ b/Code/Game/GameLogic/Game.cpp
@@ -104,6 +104,7 @@ bool Game::NewFrame()
{
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
+ //gameInstance.onMoveFnc(this->level);
return true;
}
diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h
index 7d40a3c5..cba5bb52 100644
--- a/Code/Game/GameLogic/Game.h
+++ b/Code/Game/GameLogic/Game.h
@@ -32,15 +32,14 @@ namespace GameLogic
~PlayerData();
void Move(const PLAYER_MOVEMENT &movement) override;
+ void Rotate(const Oyster::Math3D::Float3 lookDir) override;
void UseWeapon(const WEAPON_FIRE &usage) override;
int GetTeamID() const override;
PLAYER_STATE GetState() const override;
Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
- OBJECT_TYPE GetObjectType() const override;
- void Rotate(const Oyster::Math3D::Float3 lookDir) override;
-
+ OBJECT_TYPE GetType() const override;
Player *player;
};
@@ -52,8 +51,9 @@ namespace GameLogic
Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
- OBJECT_TYPE GetObjectType() const override;
-
+ OBJECT_TYPE GetType() const override;
+ IObjectData* GetObjectAt( int ID ) const override;
+
Level *level;
};
diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h
index 2f052927..f4945761 100644
--- a/Code/Game/GameLogic/GameAPI.h
+++ b/Code/Game/GameLogic/GameAPI.h
@@ -13,7 +13,6 @@
#include "GameLogicStates.h"
#include
-
namespace GameLogic
{
class IObjectData;
@@ -62,7 +61,7 @@ namespace GameLogic
/** Get the type of the object
* @return The OBJECT_TYPE of the object is returned
*/
- virtual OBJECT_TYPE GetObjectType() const = 0;
+ virtual OBJECT_TYPE GetType() const = 0;
};
class IPlayerData :public IObjectData
@@ -100,6 +99,7 @@ namespace GameLogic
class ILevelData :public IObjectData
{
public:
+ virtual IObjectData* GetObjectAt( int ID) const = 0;
};
diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h
index 4c7c4197..2b0d0b8b 100644
--- a/Code/Game/GameLogic/GameLogicStates.h
+++ b/Code/Game/GameLogic/GameLogicStates.h
@@ -24,7 +24,8 @@ namespace GameLogic
{
OBJECT_TYPE_PLAYER = 0,
OBJECT_TYPE_BOX = 1,
- OBJECT_TYPE_WORLD = 2,
+ OBJECT_TYPE_WORLD = 2,
+ OBJECT_TYPE_GENERIC = 4,
OBJECT_TYPE_UNKNOWN = -1,
};
diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp
index a9434f69..6f377f40 100644
--- a/Code/Game/GameLogic/Game_LevelData.cpp
+++ b/Code/Game/GameLogic/Game_LevelData.cpp
@@ -25,13 +25,18 @@ Oyster::Math::Float4x4 Game::LevelData::GetOrientation()
//return this->level->GetOrientation();
return Oyster::Math::Float4x4();
}
+
int Game::LevelData::GetID() const
{
- //this->level->GetID();
- return -1;
+ return ((IObjectData*)this->level)->GetID();
}
-OBJECT_TYPE Game::LevelData::GetObjectType() const
+OBJECT_TYPE Game::LevelData::GetType() const
{
- //return this->level->GetType();
- return OBJECT_TYPE_UNKNOWN;
+ return ((IObjectData*)this->level)->GetType();
+ //return OBJECT_TYPE_UNKNOWN;
}
+
+IObjectData* Game::LevelData::GetObjectAt(int ID) const
+{
+ return this->level->GetObj(ID);
+}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp
index ed628c5e..31461f8a 100644
--- a/Code/Game/GameLogic/Game_PlayerData.cpp
+++ b/Code/Game/GameLogic/Game_PlayerData.cpp
@@ -4,9 +4,19 @@
using namespace GameLogic;
Game::PlayerData::PlayerData()
-{
- this->player = new Player();
+{
+ //set some stats that are appropriate to a player
+ Oyster::Physics::API::SimpleBodyDescription sbDesc;
+ sbDesc.centerPosition = Oyster::Math::Float3(0,15,0);
+ sbDesc.size = Oyster::Math::Float3(4,7,4);
+
+ //create rigid body
+ Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
+
+ //create player with this rigid body
+ this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this);
+
}
Game::PlayerData::PlayerData(int playerID,int teamID)
{
@@ -45,11 +55,12 @@ int Game::PlayerData::GetTeamID() const
{
return this->player->GetTeamID();
}
-OBJECT_TYPE Game::PlayerData::GetObjectType() const
+
+OBJECT_TYPE Game::PlayerData::GetType() const
{
return this->player->GetType();
}
void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir)
{
-
+ this->player->Rotate(lookDir);
}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h
index 5bc400e6..e458fdbf 100644
--- a/Code/Game/GameLogic/IAttatchment.h
+++ b/Code/Game/GameLogic/IAttatchment.h
@@ -19,7 +19,7 @@ namespace GameLogic
IAttatchment(void);
~IAttatchment(void);
- virtual void UseAttatchment(const WEAPON_FIRE &usage) = 0;
+ virtual void UseAttatchment(const WEAPON_FIRE &usage, float dt) = 0;
private:
diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp
index b2bbe60c..02fc8961 100644
--- a/Code/Game/GameLogic/Level.cpp
+++ b/Code/Game/GameLogic/Level.cpp
@@ -8,6 +8,7 @@ using namespace Oyster::Physics;
Level::Level(void)
{
+
}
Level::~Level(void)
{
@@ -19,29 +20,48 @@ void Level::InitiateLevel(std::string levelPath)
}
void Level::InitiateLevel(float radius)
{
+
+ // add level sphere
API::SphericalBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
sbDesc.ignoreGravity = true;
- sbDesc.radius = 8; //radius;
+ sbDesc.radius = 8;
sbDesc.mass = 10e12f;
- //sbDesc.mass = 0; //10^16
- sbDesc.subscription_onCollision = CollisionManager::LevelCollision;
-
+
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
- API::Instance().AddObject(rigidBody);
+
ICustomBody::State state;
rigidBody->GetState(state);
- state.SetRestitutionCoeff(0.1);
+ state.SetRestitutionCoeff(0.01);
rigidBody->SetState(state);
+
+ levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD);
+ rigidBody->SetCustomTag(levelObj);
+
+
+ // add box
+ API::SimpleBodyDescription sbDesc_TestBox;
+ sbDesc_TestBox.centerPosition = Oyster::Math::Float4(-5,15,0,0);
+ sbDesc_TestBox.ignoreGravity = false;
+ sbDesc_TestBox.mass = 10;
+ sbDesc_TestBox.size = Oyster::Math::Float4(0.5f,0.5f,0.5f,0);
+
+ ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
+ rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
+ testBox = new DynamicObject(rigidBody_TestBox, OBJECT_TYPE::OBJECT_TYPE_BOX);
+ rigidBody_TestBox->SetCustomTag(testBox);
+ rigidBody_TestBox->GetState(state);
+ state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,4));
+ rigidBody_TestBox->SetState(state);
+
+
+ // add gravitation
API::Gravity gravityWell;
-
gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = 10e12f;
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
-
API::Instance().AddGravity(gravityWell);
-
}
void Level::AddPlayerToTeam(Player *player, int teamID)
@@ -59,4 +79,15 @@ void Level::RespawnPlayer(Player *player)
this->teamManager.RespawnPlayerRandom(player);
}
-
+Object* Level::GetObj( int ID) const
+{
+ if( ID == 0 )
+ return (Object*)levelObj;
+ else
+ return (Object*)testBox;
+}
+void Level::PhysicsOnMoveLevel(const ICustomBody *object)
+{
+ // function call from physics update when object was moved
+ Object* temp = (Object*)object->GetCustomTag();
+}
diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h
index 2242a8b2..60f7a932 100644
--- a/Code/Game/GameLogic/Level.h
+++ b/Code/Game/GameLogic/Level.h
@@ -51,12 +51,27 @@ namespace GameLogic
********************************************************/
void RespawnPlayer(Player *player);
+ /********************************************************
+ * Collision function for level, this is to be sent to physics through the subscribe function with the rigidbody
+ * Will be called when the physics detect a collision
+ * @param rigidBodyLevel: physics object of the level
+ * @param obj: physics object for the object that collided with the level
+ ********************************************************/
+ static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
+ static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
+
+ Object* GetObj( int ID ) const;
+ static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);
+
+
private:
TeamManager teamManager;
Utility::DynamicMemory::DynamicArray> staticObjects;
Utility::DynamicMemory::DynamicArray> dynamicObjects;
GameMode gameMode;
Utility::DynamicMemory::SmartPointer rigidBodyLevel;
+ StaticObject *levelObj;
+ DynamicObject *testBox;
};
diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp
index 2937c605..9ec51f1e 100644
--- a/Code/Game/GameLogic/Object.cpp
+++ b/Code/Game/GameLogic/Object.cpp
@@ -16,37 +16,83 @@ const Game *Object::gameInstance = (Game*)(&Game::Instance());
Object::Object()
{
API::SimpleBodyDescription sbDesc;
- //sbDesc.centerPosition =
-
- //poi
- ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
-
+ this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
- //rigidBody->gameObjectRef = this;
-
- this->objectID = GID();
-
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
+ this->objectID = GID();
+ this->getState = this->rigidBody->GetState();
+ this->setState = this->getState;
}
-Object::Object(void* collisionFunc, OBJECT_TYPE type)
+Object::Object(OBJECT_TYPE type)
{
API::SimpleBodyDescription sbDesc;
- //poi
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
+ Oyster::Physics::API::Instance().AddObject(rigidBody);
+ this->type = type;
+ this->objectID = GID();
+ this->getState = this->rigidBody->GetState();
+ this->setState = this->getState;
+}
+Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
+{
+ Oyster::Physics::API::Instance().AddObject(rigidBody);
+ this->rigidBody = rigidBody;
+ this->type = type;
+ this->objectID = GID();
+ this->getState = this->rigidBody->GetState();
+ this->setState = this->getState;
+}
+
+Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+{
+ API::SimpleBodyDescription sbDesc;
+
+ this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
- rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
-
- //rigidBody->gameObjectRef = this;
-
+ this->type = type;
this->objectID = GID();
+ this->getState = this->rigidBody->GetState();
+ this->setState = this->getState;
+}
+
+Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+{
+ Oyster::Physics::API::Instance().AddObject(rigidBody);
+
+ this->rigidBody = rigidBody;
+ this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
+ this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
this->type = type;
+ this->objectID = GID();
+ this->getState = this->rigidBody->GetState();
+ this->setState = this->getState;
+}
+
+Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
+{
+ Oyster::Physics::API::Instance().AddObject(rigidBody);
+
+ this->rigidBody = rigidBody;
+ this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
+ this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
+
+
+ this->type = type;
+ this->objectID = GID();
+ this->getState = this->rigidBody->GetState();
+ this->setState = this->getState;
+}
+
+void Object::ApplyLinearImpulse(Oyster::Math::Float3 force)
+{
+ setState.ApplyLinearImpulse(force);
}
@@ -72,10 +118,30 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
void Object::BeginFrame()
{
+
this->rigidBody->SetState(this->setState);
+
}
+// update physic
void Object::EndFrame()
{
- this->rigidBody->GetState(this->getState);
+
+ Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis);
+ //Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal());
+ //setState.SetOrientation(rotMatrix);
+
+ this->getState = this->rigidBody->GetState();
this->setState = this->getState;
+}
+Oyster::Math::Float3 Object::GetPosition()
+{
+ Oyster::Physics::ICustomBody::State state;
+ state = this->rigidBody->GetState();
+ return state.GetCenterPosition();
+}
+Oyster::Math::Float4x4 Object::GetOrientation()
+{
+ Oyster::Physics::ICustomBody::State state;
+ state = this->rigidBody->GetState();
+ return state.GetOrientation();
}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h
index 1316b287..24149116 100644
--- a/Code/Game/GameLogic/Object.h
+++ b/Code/Game/GameLogic/Object.h
@@ -7,26 +7,37 @@
#define OBJECT_H
#include "GameLogicStates.h"
+#include "GameAPI.h"
#include
namespace GameLogic
{
class Game;
- class Object
+ class Object :public IObjectData
{
public:
Object();
- Object(void* collisionFunc, OBJECT_TYPE type);
+ Object(OBJECT_TYPE type);
+ Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
+ Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Object(void);
+ // API overrides
OBJECT_TYPE GetType() const;
int GetID() const;
+ Oyster::Math::Float3 GetPosition();
+ Oyster::Math::Float4x4 GetOrientation();
+
+
Oyster::Physics::ICustomBody* GetRigidBody();
+ void ApplyLinearImpulse(Oyster::Math::Float3 force);
void BeginFrame();
void EndFrame();
-
+ static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
private:
OBJECT_TYPE type;
int objectID;
diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp
index dd65c375..c366fb8f 100644
--- a/Code/Game/GameLogic/Player.cpp
+++ b/Code/Game/GameLogic/Player.cpp
@@ -8,27 +8,56 @@ using namespace GameLogic;
using namespace Oyster::Physics;
Player::Player()
- :DynamicObject(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
+ :DynamicObject()
{
- weapon = new Weapon();
-
- life = 100;
- teamID = -1;
- playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
- lookDir = Oyster::Math::Float4(0,0,-1,0);
- setState.SetCenterPosition(Oyster::Math::Float4(0,15,0,1));
- setState.SetReach(Oyster::Math::Float4(2,3.5,2,0));
-
}
+Player::Player(OBJECT_TYPE type)
+ :DynamicObject(type)
+{
+ InitPlayer();
+}
+Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
+ :DynamicObject(rigidBody,type)
+{
+ InitPlayer();
+}
+
+Player::Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+ :DynamicObject(collisionFuncBefore,collisionFuncAfter,type)
+{
+ InitPlayer();
+}
+Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+ :DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
+{
+ InitPlayer();
+}
+Player::Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
+ :DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
+{
+ InitPlayer();
+}
+
+void Player::InitPlayer()
+{
+ weapon = new Weapon(2,this);
+
+ this->life = 100;
+ this->teamID = -1;
+ this->playerState = PLAYER_STATE_IDLE;
+ lookDir = Oyster::Math::Float4(0,0,-1,0);
+}
Player::~Player(void)
{
- delete weapon;
- weapon = NULL;
+ if(weapon)
+ {
+ delete weapon;
+ weapon = NULL;
+ }
}
-
void Player::Move(const PLAYER_MOVEMENT &movement)
{
switch(movement)
@@ -66,7 +95,7 @@ void Player::MoveBackwards()
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
- Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
+ Oyster::Math::Float3 r = Oyster::Math::Float4(1, 0, 0);
//Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(r * 20 * this->gameInstance->GetFrameTime());
@@ -74,14 +103,14 @@ void Player::MoveRight()
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
- Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
+ Oyster::Math::Float3 r = Oyster::Math::Float4(1, 0, 0 );
//Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero
setState.ApplyLinearImpulse(-r * 20 * this->gameInstance->GetFrameTime());
}
void Player::UseWeapon(const WEAPON_FIRE &usage)
{
- this->weapon->Use(usage);
+ this->weapon->Use(usage,gameInstance->GetFrameTime());
}
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
@@ -92,9 +121,20 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint)
this->lookDir = Oyster::Math::Float4(1,0,0);
}
-void Player::Rotate(float x, float y)
+void Player::Rotate(const Oyster::Math3D::Float3 lookDir)
{
- this->setState.AddRotation(Oyster::Math::Float4(x, y));
+ this->lookDir = lookDir;
+
+ Oyster::Math::Float4 up(0,1,0,0);//-setState.GetGravityNormal();
+ Oyster::Math::Float4 pos = setState.GetCenterPosition();
+ Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz);
+ // cant set rotation
+ //setState.SetOrientation(world);
+ //this->lookDir = lookDir - up.xyz;
+ //this->lookDir = lookDir;
+
+ //this->setState.AddRotation(Oyster::Math::Float4(x, y));
+ //this->setState.SetRotation();
}
void Player::Jump()
@@ -125,7 +165,7 @@ Oyster::Math::Float4x4 Player::GetOrientation() const
}
Oyster::Math::Float3 Player::GetLookDir() const
{
- return this->lookDir.xyz;
+ return this->lookDir;
}
int Player::GetTeamID() const
{
diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h
index 39e8f5f6..0df0d040 100644
--- a/Code/Game/GameLogic/Player.h
+++ b/Code/Game/GameLogic/Player.h
@@ -16,7 +16,13 @@ namespace GameLogic
{
public:
Player(void);
+ Player(OBJECT_TYPE type);
+ Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
+ Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Player(void);
+ void InitPlayer();
/********************************************************
* Moves the player based on input
@@ -41,7 +47,17 @@ namespace GameLogic
********************************************************/
void Respawn(Oyster::Math::Float3 spawnPoint);
- void Rotate(float x, float y);
+
+ void Rotate(const Oyster::Math3D::Float3 lookDir);
+
+ /********************************************************
+ * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody
+ * Will be called when the physics detect a collision
+ * @param rigidBodyPlayer: physics object of the player
+ * @param obj: physics object for the object that collided with the player
+ ********************************************************/
+ static void PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
+
bool IsWalking();
bool IsJumping();
@@ -63,7 +79,10 @@ namespace GameLogic
int teamID;
Weapon *weapon;
PLAYER_STATE playerState;
- Oyster::Math::Float4 lookDir;
+ Oyster::Math::Float3 lookDir;
+
+ bool hasTakenDamage;
+ float invincibleCooldown;
};
}
diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp
index 155834fe..21b339be 100644
--- a/Code/Game/GameLogic/StaticObject.cpp
+++ b/Code/Game/GameLogic/StaticObject.cpp
@@ -9,13 +9,32 @@ StaticObject::StaticObject()
{
}
+StaticObject::StaticObject(OBJECT_TYPE type)
+ :Object(type)
+{
-StaticObject::StaticObject(void* collisionFunc, OBJECT_TYPE type)
- :Object(collisionFunc,type)
+}
+StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
+ :Object(rigidBody,type)
{
}
+StaticObject::StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+ :Object(collisionFuncBefore,collisionFuncAfter,type)
+{
+
+}
+StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
+ :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
+{
+
+}
+StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
+ :Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
+{
+
+}
StaticObject::~StaticObject(void)
{
diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h
index 31121447..c51f93a1 100644
--- a/Code/Game/GameLogic/StaticObject.h
+++ b/Code/Game/GameLogic/StaticObject.h
@@ -16,7 +16,12 @@ namespace GameLogic
public:
StaticObject();
- StaticObject(void* collisionFunc, OBJECT_TYPE type);
+ StaticObject(OBJECT_TYPE type);
+ StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
+ StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
+ StaticObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
+
~StaticObject(void);
private:
diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp
index 28765cf3..a4c87e9e 100644
--- a/Code/Game/GameLogic/Weapon.cpp
+++ b/Code/Game/GameLogic/Weapon.cpp
@@ -1,60 +1,52 @@
#include "Weapon.h"
-#include "AttatchmentSocket.h"
#include "AttatchmentMassDriver.h"
-#include "DynamicArray.h"
+#include "Player.h"
+
using namespace GameLogic;
using namespace Utility::DynamicMemory;
-struct Weapon::PrivateData
-{
- PrivateData()
- {
- weaponState = WEAPON_STATE_IDLE;
- selectedAttatchment = 0;
- currentNrOfAttatchments = 0;
- selectedSocketID = 0;
- attatchmentSockets = 0;
- }
-
- ~PrivateData()
- {
- }
-
- WEAPON_STATE weaponState;
-
- DynamicArray> attatchmentSockets;
- int currentNrOfAttatchments;
- SmartPointer selectedAttatchment;
- int selectedSocketID;
-
-}myData;
Weapon::Weapon()
{
- myData = new PrivateData();
+ weaponState = WEAPON_STATE_IDLE;
+ selectedAttatchment = 0;
+ currentNrOfAttatchments = 0;
+ selectedSocketID = 0;
+ attatchmentSockets = 0;
}
-Weapon::Weapon(int MaxNrOfSockets)
+Weapon::Weapon(int MaxNrOfSockets,Player *owner)
{
- myData = new PrivateData();
- myData->attatchmentSockets.Resize(MaxNrOfSockets);
+ attatchmentSockets.Resize(MaxNrOfSockets);
+ attatchmentSockets[0] = new AttatchmentSocket();
+
+ weaponState = WEAPON_STATE_IDLE;
+ currentNrOfAttatchments = 0;
+ selectedAttatchment = 0;
+
+ //give the weapon a massdriver on socket 0
+ IAttatchment *mD = new AttatchmentMassDriver(*owner);
+ attatchmentSockets[0]->SetAttatchment(mD);
+ this->currentNrOfAttatchments = 1;
+ SelectAttatchment(0);
+ //give the weapon a massdriver on socket 0
}
Weapon::~Weapon(void)
{
- delete myData;
+
}
/********************************************************
* Uses the weapon based on the input given and the current chosen attatchment
********************************************************/
-void Weapon::Use(const WEAPON_FIRE &usage)
+void Weapon::Use(const WEAPON_FIRE &usage, float dt)
{
- if (myData->selectedAttatchment)
+ if (selectedAttatchment)
{
- myData->selectedAttatchment->UseAttatchment(usage);
+ selectedAttatchment->UseAttatchment(usage, dt);
}
}
@@ -68,24 +60,24 @@ void Weapon::Use(const WEAPON_FIRE &usage)
********************************************************/
bool Weapon::IsFireing()
{
- return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
+ return (weaponState == WEAPON_STATE::WEAPON_STATE_FIRING);
}
bool Weapon::IsIdle()
{
- return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
+ return (weaponState == WEAPON_STATE::WEAPON_STATE_IDLE);
}
bool Weapon::IsReloading()
{
- return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
+ return (weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING);
}
bool Weapon::IsValidSocket(int socketID)
{
- if(socketID < (int)myData->attatchmentSockets.Size() && socketID >= 0)
+ if(socketID < (int)attatchmentSockets.Size() && socketID >= 0)
{
- if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0)
+ if (attatchmentSockets[socketID]->GetAttatchment() != 0)
{
return true;
}
@@ -96,16 +88,16 @@ bool Weapon::IsValidSocket(int socketID)
int Weapon::GetCurrentSocketID()
{
- return myData->selectedSocketID;
+ return selectedSocketID;
}
void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner)
{
- if(myData->currentNrOfAttatchments < (int)myData->attatchmentSockets.Size())
+ if(currentNrOfAttatchments < (int)attatchmentSockets.Size())
{
- myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment);
- myData->currentNrOfAttatchments++;
+ attatchmentSockets[currentNrOfAttatchments]->SetAttatchment(attatchment);
+ currentNrOfAttatchments++;
}
}
@@ -113,7 +105,7 @@ void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *
{
if (IsValidSocket(socketID))
{
- myData->attatchmentSockets[socketID]->SetAttatchment(attatchment);
+ attatchmentSockets[socketID]->SetAttatchment(attatchment);
}
}
@@ -121,7 +113,7 @@ void Weapon::RemoveAttatchment(int socketID)
{
if (IsValidSocket(socketID))
{
- myData->attatchmentSockets[socketID]->RemoveAttatchment();
+ attatchmentSockets[socketID]->RemoveAttatchment();
}
}
@@ -129,8 +121,8 @@ void Weapon::SelectAttatchment(int socketID)
{
if (IsValidSocket(socketID))
{
- myData->selectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment();
- myData->selectedSocketID = socketID;
+ selectedAttatchment = attatchmentSockets[socketID]->GetAttatchment();
+ selectedSocketID = socketID;
}
}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h
index 719a853c..5138b2ac 100644
--- a/Code/Game/GameLogic/Weapon.h
+++ b/Code/Game/GameLogic/Weapon.h
@@ -6,21 +6,20 @@
#include "GameLogicStates.h"
#include "IAttatchment.h"
#include "Player.h"
+#include "AttatchmentSocket.h"
+#include "DynamicArray.h"
namespace GameLogic
{
class Weapon
{
-
public:
-
-
Weapon(void);
- Weapon(int nrOfAttatchmentSockets);
+ Weapon(int nrOfAttatchmentSockets, Player *owner);
~Weapon(void);
- void Use(const WEAPON_FIRE &fireInput);
+ void Use(const WEAPON_FIRE &usage, float dt);
void AddNewAttatchment(IAttatchment *attatchment, Player *owner);
void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner);
@@ -35,9 +34,12 @@ namespace GameLogic
int GetCurrentSocketID();
- private:
- struct PrivateData;
- PrivateData *myData;
+ private:
+ WEAPON_STATE weaponState;
+ Utility::DynamicMemory::DynamicArray attatchmentSockets;
+ int currentNrOfAttatchments;
+ IAttatchment *selectedAttatchment;
+ int selectedSocketID;
};
}
diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h
index 8968de74..87aad62e 100644
--- a/Code/Game/GameProtocols/LobbyProtocols.h
+++ b/Code/Game/GameProtocols/LobbyProtocols.h
@@ -14,6 +14,7 @@
namespace GameLogic
{
+ /*
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
{
char* mapName;
@@ -42,7 +43,7 @@ namespace GameLogic
private:
Oyster::Network::CustomNetProtocol protocol;
};
-
+ */
struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject
{
short gameId;
diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h
index 0bb902c6..56f18876 100644
--- a/Code/Game/GameProtocols/ProtocolIdentificationID.h
+++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h
@@ -48,7 +48,7 @@
#define protocol_GameplayMIN 300
#define protocol_Gameplay_PlayerMovement 300
#define protocol_Gameplay_PlayerLookDir 301
-#define protocol_Gameplay_PlayerChangeWeapon 302
+#define protocol_Gameplay_PlayerChangeWeapon 302
#define protocol_Gameplay_PlayerShot 303
#define protocol_Gameplay_ObjectPickup 304
#define protocol_Gameplay_ObjectDamage 305
diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h
index 47e3b329..2b9f4bc4 100644
--- a/Code/Game/GameServer/GameLobby.h
+++ b/Code/Game/GameServer/GameLobby.h
@@ -20,14 +20,16 @@ namespace DanBias
void Release();
void Update();
- operator bool();
+ void SetGameDesc(const GameSession::GameDescription& desc);
+ void GetGameDesc(GameSession::GameDescription& desc);
+ bool StartGameSession();
private:
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c);
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
- void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
+ //void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
void LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
@@ -42,7 +44,8 @@ namespace DanBias
private:
Utility::WinTimer timer;
float refreshFrequency;
- GameSession* gameSession;
+ GameSession gameSession;
+ GameSession::GameDescription description;
};
}//End namespace DanBias
#endif // !DANBIASGAME_GAMELOBBY_H
diff --git a/Code/Game/GameServer/GameServerAPI.h b/Code/Game/GameServer/GameServerAPI.h
index cc03ec01..e76b4264 100644
--- a/Code/Game/GameServer/GameServerAPI.h
+++ b/Code/Game/GameServer/GameServerAPI.h
@@ -28,17 +28,39 @@ namespace DanBias
class DANBIAS_SERVER_DLL GameServerAPI
{
public:
- struct GameInitDesc
+ struct ServerInitDesc
{
+ char* serverName;
int listenPort;
- bool threaded;
+ ServerInitDesc()
+ : serverName("Game Server")
+ , listenPort(15151)
+ {};
+ };
+ struct GameServerInfo
+ {
+ unsigned int listenPort; // If set to 0, the default port 15151 will be used
+ const char *serverIp; // This cant be mofidfied..
};
public:
- static DanBiasServerReturn Create(const GameInitDesc& desc);
- static void Start();
- static void Stop();
- static void Terminate();
+ static DanBiasServerReturn ServerInitiate(const ServerInitDesc& desc);
+ static void ServerStart();
+ static void ServerStop();
+ static void ServerUpdate();
+ static GameServerInfo ServerGetInfo();
+
+ static void GameSetMapId(const int& val);
+ static void GameSetMaxClients(const int& val);
+ static void GameSetGameMode(const int& val);
+ static void GameSetGameTime(const int& val);
+ static int GameGetMapId();
+ static int GameGetMaxClients();
+ static int GameGetGameMode();
+ static int GameGetGameTime();
+ static const char* GameGetGameName();
+ static bool GameStart();
+
};//End class DanBiasServer
}//End Extern "C"
diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h
index e75be66d..4685440a 100644
--- a/Code/Game/GameServer/GameSession.h
+++ b/Code/Game/GameServer/GameSession.h
@@ -31,7 +31,11 @@ namespace DanBias
*/
struct GameDescription
{
- std::wstring mapName;
+ int mapNumber;
+ int maxClients;
+ int gameMode;
+ int gameTime;
+ std::string gameName;
Oyster::Network::NetworkSession* owner;
Utility::DynamicMemory::DynamicArray clients;
};
@@ -82,6 +86,9 @@ namespace DanBias
void General_Status ( GameLogic::Protocol_General_Status& p, DanBias::GameClient* c );
void General_Text ( GameLogic::Protocol_General_Text& p, DanBias::GameClient* c );
+ //Callback method recieving from gamelogic
+ static void ObjectMove(GameLogic::IObjectData* movedObject);
+
//Private member variables
private:
Utility::DynamicMemory::DynamicArray> clients;
@@ -92,10 +99,10 @@ namespace DanBias
bool isCreated;
bool isRunning;
Utility::WinTimer timer;
+ GameDescription description;
- //Callback method recieving from gamelogic
- static void ObjectMove(GameLogic::IObjectData* movedObject);
-
+ //TODO: Remove this uggly hax
+ static GameSession* gameSession;
};//End GameSession
}//End namespace DanBias
diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp
index 9396d71d..24ca7887 100644
--- a/Code/Game/GameServer/Implementation/GameLobby.cpp
+++ b/Code/Game/GameServer/Implementation/GameLobby.cpp
@@ -25,14 +25,27 @@ namespace DanBias
void GameLobby::Update()
{
- if(GetAsyncKeyState(VK_DOWN))
+ if(GetAsyncKeyState(VK_DOWN)) //TODO: Dont forget to remove this...
this->Send(*GameLogic::Protocol_General_Status().GetProtocol());
this->ProcessClients();
}
- GameLobby::operator bool()
+ void GameLobby::SetGameDesc(const GameSession::GameDescription& desc)
{
- return true;
+ this->description = desc;
+ }
+ void GameLobby::GetGameDesc(GameSession::GameDescription& desc)
+ {
+ desc = this->description;
+ }
+ bool GameLobby::StartGameSession()
+ {
+ if(this->gameSession.Create(this->description))
+ {
+ this->gameSession.Run();
+ return true;
+ }
+ return false;
}
void GameLobby::ClientEventCallback(NetEvent e)
diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp
index 335bf55b..0de7b062 100644
--- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp
+++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp
@@ -13,8 +13,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
break;
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
break;
- case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
- break;
+ //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
+ //break;
case protocol_Lobby_Start: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
break;
case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
@@ -54,10 +54,10 @@ void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network
{
printf(p.text.c_str());
}
-void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c)
-{
-
-}
+//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c)
+//{
+//
+//}
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
{
diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp
index d98794a4..0489a12d 100644
--- a/Code/Game/GameServer/Implementation/GameServer.cpp
+++ b/Code/Game/GameServer/Implementation/GameServer.cpp
@@ -16,7 +16,7 @@
#include
#include
#include
-#include
+#include
using namespace DanBias;
using namespace Oyster::Network;
@@ -28,37 +28,37 @@ namespace
GameLobby lobby;
NetworkServer server;
WinTimer timer;
- GameServerAPI instance;
- //typedef void(*WorkerThreadFnc)(GameServerAPI*);
}
-DanBiasServerReturn GameServerAPI::Create(const GameInitDesc& desc)
+
+DanBiasServerReturn GameServerAPI::ServerInitiate(const ServerInitDesc& desc)
{
-
if(server.Init(desc.listenPort, &lobby) == NetworkServer::ServerReturnCode_Error)
{
return DanBiasServerReturn_Error;
}
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ d.gameName.assign(desc.serverName);
+ lobby.SetGameDesc(d);
std::printf("Server created!\t-\t%s: [%i]\n\n", server.GetLanAddress().c_str(), desc.listenPort);
return DanBiasServerReturn_Sucess;
}
-void GameServerAPI::Start()
+void GameServerAPI::ServerStart()
{
+ timer.reset();
server.Start();
- timer.reset();
-
- while (true)
- {
- server.ProcessConnectedClients();
- lobby.Update();
-
- if(GetAsyncKeyState(0x51)) //Q for exit
- break;
- }
+
+}
+void GameServerAPI::ServerStop()
+{
+ lobby.Release();
+ server.Shutdown();
+
double total = timer.getElapsedSeconds();
int time = (int)total;
@@ -72,23 +72,87 @@ void GameServerAPI::Start()
printf( "Server has been running for: %i:%i:%i - [hh:mm:ss] \n\n", hour, min, sec );
printf( "Terminating in : ");
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 3; i++)
{
printf( "%i ", 3-i );
Sleep(1000);
}
-
+ printf( "\nServer terminated!" );
}
-void GameServerAPI::Stop()
+void GameServerAPI::ServerUpdate()
{
- server.Stop();
- lobby.ProcessClients();
-}
-void GameServerAPI::Terminate()
-{
- lobby.Release();
- server.Shutdown();
-
- printf( "Server terminated!" );
+ server.Update();
+ lobby.Update();
}
+
+GameServerAPI::GameServerInfo GameServerAPI::ServerGetInfo()
+{
+ GameServerAPI::GameServerInfo i;
+ i.serverIp = server.GetLanAddress().c_str();
+ i.listenPort = server.GetPort();
+ return i;
+}
+void GameServerAPI::GameSetMapId(const int& val)
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ d.mapNumber = val;
+ lobby.SetGameDesc(d);
+}
+void GameServerAPI::GameSetMaxClients(const int& val)
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ d.maxClients = val;
+ lobby.SetGameDesc(d);
+}
+void GameServerAPI::GameSetGameMode(const int& val)
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ d.gameMode = val;
+ lobby.SetGameDesc(d);
+}
+void GameServerAPI::GameSetGameTime(const int& val)
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ d.gameTime = val;
+ lobby.SetGameDesc(d);
+}
+int GameServerAPI::GameGetMapId()
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ return d.mapNumber;
+}
+int GameServerAPI::GameGetMaxClients()
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ return d.maxClients;
+}
+int GameServerAPI::GameGetGameMode()
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ return d.gameMode;
+}
+int GameServerAPI::GameGetGameTime()
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ return d.gameTime;
+}
+const char* GameServerAPI::GameGetGameName()
+{
+ GameSession::GameDescription d;
+ lobby.GetGameDesc(d);
+ return d.gameName.c_str();
+}
+bool GameServerAPI::GameStart()
+{
+ return lobby.StartGameSession();
+}
+
diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp
index 306837d9..945198af 100644
--- a/Code/Game/GameServer/Implementation/GameSession_General.cpp
+++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp
@@ -19,12 +19,17 @@ using namespace GameLogic;
namespace DanBias
{
+ GameSession* GameSession::gameSession = nullptr;
+
GameSession::GameSession()
:gameInstance(GameAPI::Instance())
{
this->owner = 0;
this->isCreated = false;
this->isRunning = false;
+ this->gameSession = this;
+
+ memset(&this->description, 0, sizeof(GameDescription));
}
GameSession::~GameSession()
@@ -39,10 +44,10 @@ namespace DanBias
bool GameSession::Create(GameDescription& desc)
{
+ this->description = desc;
/* Do some error checking */
if(desc.clients.Size() == 0) return false;
if(!desc.owner) return false;
- if(!desc.mapName.size()) return false;
if(this->isCreated) return false;
/* standard initialization of some data */
diff --git a/Code/Game/aDanBiasGameLauncher/Launcher.cpp b/Code/Game/aDanBiasGameLauncher/Launcher.cpp
index 17e3c8bc..e13baff1 100644
--- a/Code/Game/aDanBiasGameLauncher/Launcher.cpp
+++ b/Code/Game/aDanBiasGameLauncher/Launcher.cpp
@@ -11,13 +11,19 @@
void ServerFnc()
{
- DanBias::GameServerAPI::GameInitDesc desc;
+ DanBias::GameServerAPI::ServerInitDesc desc;
desc.listenPort = 15151;
- if( DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess)
+ if(DanBias::GameServerAPI::ServerInitiate(desc) == DanBias::DanBiasServerReturn_Sucess)
{
- DanBias::GameServerAPI::Start();
- DanBias::GameServerAPI::Terminate();
+ DanBias::GameServerAPI::ServerStart();
+ while (!(GetAsyncKeyState(0x51))) //Q for exit
+ {
+ DanBias::GameServerAPI::ServerUpdate();
+ Sleep(1);
+ }
+ DanBias::GameServerAPI::ServerStop();
}
+
Sleep(100);
}
void ClientFnc()
diff --git a/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj
index 303d075f..6507336c 100644
--- a/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj
+++ b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj
@@ -111,7 +111,7 @@
Windows
true
DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)
- DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)
+ DanBiasGame_$(PlatformShortName)D.lib;GameServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)
@@ -127,7 +127,7 @@
Windows
true
DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)
- DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)
+ DanBiasGame_$(PlatformShortName)D.lib;GameServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)
@@ -147,7 +147,7 @@
true
true
DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)
- DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)
+ DanBiasGame_$(PlatformShortName).lib;GameServer_$(PlatformShortName).lib;%(AdditionalDependencies)
@@ -167,7 +167,7 @@
true
true
DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)
- DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)
+ DanBiasGame_$(PlatformShortName).lib;GameServer_$(PlatformShortName).lib;%(AdditionalDependencies)
diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp
index a1ccdbd8..b4395516 100644
--- a/Code/GamePhysics/Implementation/Octree.cpp
+++ b/Code/GamePhysics/Implementation/Octree.cpp
@@ -108,7 +108,7 @@ std::vector& Octree::Sample(const Oyster::Collision3D::ICollideabl
return updateList;
}
-void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction )
+void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction )
{
auto object = this->mapReferences.find(customBodyRef);
@@ -128,13 +128,13 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction )
}
}
-void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction)
+void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, void* args, VisitorActionCollideable hitAction)
{
for(unsigned int i = 0; ileafData.size(); i++)
{
- if(this->leafData[i].container.Intersects(collideable))
+ if(collideable.Intersects(this->leafData[i].container))
{
- //hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable
+ hitAction( this->GetCustomBody(i), args );
}
}
}
diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h
index 96631605..50b9569a 100644
--- a/Code/GamePhysics/Implementation/Octree.h
+++ b/Code/GamePhysics/Implementation/Octree.h
@@ -17,7 +17,8 @@ namespace Oyster
public:
static const unsigned int invalid_ref;
- typedef void(*VistorAction)(Octree&, unsigned int, unsigned int);
+ typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int);
+ typedef void(*VisitorActionCollideable)(ICustomBody*, void*);
struct Data
{
@@ -51,8 +52,8 @@ namespace Oyster
std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList);
std::vector& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector& updateList);
- void Visit(ICustomBody* customBodyRef, VistorAction hitAction );
- void Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction );
+ void Visit(ICustomBody* customBodyRef, VisitorAction hitAction );
+ void Visit(const Oyster::Collision3D::ICollideable& collideable, void* args, VisitorActionCollideable hitAction );
ICustomBody* GetCustomBody(const unsigned int tempRef);
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
index 46346099..6f164810 100644
--- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
@@ -22,84 +22,71 @@ namespace
Float4 worldPointOfContact;
if( proto->Intersects(*deuter, worldPointOfContact) )
{
- switch( proto->CallSubscription_Collision(deuter) )
- {
- case ICustomBody::SubscriptMessage_ignore_collision_response:
- break;
- default:
- { // Apply CollisionResponse in pure gather pattern
- ICustomBody::State protoState; proto->GetState( protoState );
- ICustomBody::State deuterState; deuter->GetState( deuterState );
+ // Apply CollisionResponse in pure gather pattern
+ ICustomBody::State protoState; proto->GetState( protoState );
+ ICustomBody::State deuterState; deuter->GetState( deuterState );
- Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact ),
- deuterG = deuterState.GetLinearMomentum( worldPointOfContact );
+ Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
+ deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
- // calc from perspective of deuter
- Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
- Float protoG_Magnitude = protoG.Dot( normal ),
- deuterG_Magnitude = deuterG.Dot( normal );
-
- // if they are not relatively moving towards eachother, there is no collision
- Float deltaPos = normal.Dot( deuterState.GetCenterPosition() - protoState.GetCenterPosition() );
- if( deltaPos < 0.0f )
- {
- if( protoG_Magnitude >= deuterG_Magnitude )
- {
- break;
- }
- }
- else if( deltaPos > 0.0f )
- {
- if( protoG_Magnitude <= deuterG_Magnitude )
- {
- break;
- }
- }
- else
- {
- break;
- }
-
- // bounce
- Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(),
- deuterState.GetMass(), deuterG_Magnitude,
- protoState.GetMass(), protoG_Magnitude );
-
- //sumJ -= Formula::CollisionResponse::Friction( impulse, normal,
- // protoState.GetLinearMomentum(), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(),
- // deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass());
-
- // calc from perspective of proto
- proto->GetNormalAt( worldPointOfContact, normal );
- protoG_Magnitude = protoG.Dot( normal ),
+ // calc from perspective of deuter
+ Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
+ Float protoG_Magnitude = protoG.Dot( normal ),
deuterG_Magnitude = deuterG.Dot( normal );
-
- // bounce
- Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
- protoState.GetMass(), protoG_Magnitude,
- deuterState.GetMass(), deuterG_Magnitude );
- Float4 bounce = Average( bounceD, bounceP );
- //Float4 bounce = bounceD + bounceP;
-
- // FRICTION
- // Apply
- //sumJ += ( 1 / deuterState.GetMass() )*frictionImpulse;
- // FRICTION END
-
-// Float4 forwardedDeltaPos, forwardedDeltaAxis;
-// { // @todo TODO: is this right?
-// Float4 bounceAngularImpulse = ::Oyster::Math::Float4( (worldPointOfContact - protoState.GetCenterPosition()).xyz.Cross(bounce.xyz), 0.0f ),
-// bounceLinearImpulse = bounce - bounceAngularImpulse;
-// proto->Predict( forwardedDeltaPos, forwardedDeltaAxis, bounceLinearImpulse, bounceAngularImpulse, API_instance.GetFrameTimeLength() );
-// }
-
-// protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis );
- protoState.ApplyImpulse( bounce, worldPointOfContact, normal );
- proto->SetState( protoState );
+ // if they are not relatively moving towards eachother, there is no collision
+ Float deltaPos = normal.Dot( Float4(deuterState.GetCenterPosition(), 1) - Float4(protoState.GetCenterPosition(), 1) );
+ if( deltaPos < 0.0f )
+ {
+ if( protoG_Magnitude >= deuterG_Magnitude )
+ {
+ return;
}
- break;
}
+ else if( deltaPos > 0.0f )
+ {
+ if( protoG_Magnitude <= deuterG_Magnitude )
+ {
+ return;
+ }
+ }
+ else
+ {
+ return;
+ }
+
+ if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_ignore_collision_response )
+ {
+ return;
+ }
+
+
+ // bounce
+ Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(),
+ deuterState.GetMass(), deuterG_Magnitude,
+ protoState.GetMass(), protoG_Magnitude );
+
+
+ // calc from perspective of proto
+ proto->GetNormalAt( worldPointOfContact, normal );
+ protoG_Magnitude = protoG.Dot( normal ),
+ deuterG_Magnitude = deuterG.Dot( normal );
+
+ // bounce
+ Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
+ protoState.GetMass(), protoG_Magnitude,
+ deuterState.GetMass(), deuterG_Magnitude );
+
+ Float4 bounce = Average( bounceD, bounceP );
+
+ Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() );
+
+ protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz );
+ proto->SetState( protoState );
+
+ Float kineticEnergyPAFter = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), (protoState.GetLinearMomentum() + protoState.GetLinearImpulse())/protoState.GetMass() );
+
+ proto->CallSubscription_AfterCollisionResponse( deuter, kineticEnergyPBefore - kineticEnergyPAFter );
}
}
}
@@ -112,6 +99,7 @@ API & API::Instance()
API_Impl::API_Impl()
{
this->gravityConstant = Constant::gravity_constant;
+ this->epsilon = Constant::epsilon;
this->updateFrameLength = 1.0f / 120.0f;
this->destructionAction = Default::EventAction_Destruction;
this->gravity = ::std::vector();
@@ -138,6 +126,11 @@ void API_Impl::SetGravityConstant( float g )
this->gravityConstant = g;
}
+void API_Impl::SetEpsilon( float e )
+{
+ this->epsilon = e;
+}
+
void API_Impl::SetSubscription( API::EventAction_Destruction functionPointer )
{
if( functionPointer )
@@ -171,7 +164,7 @@ void API_Impl::Update()
{
case Gravity::GravityType_Well:
{
- Float4 d = Float4( this->gravity[i].well.position, 1.0f ) - state.GetCenterPosition();
+ Float4 d = Float4( this->gravity[i].well.position, 1.0f ) - Float4( state.GetCenterPosition(), 1.0f );
Float rSquared = d.Dot( d );
if( rSquared != 0.0 )
{
@@ -193,7 +186,7 @@ void API_Impl::Update()
if( gravityImpulse != Float4::null )
{
- state.ApplyLinearImpulse( gravityImpulse );
+ state.ApplyLinearImpulse( gravityImpulse.xyz );
(*proto)->SetGravityNormal( gravityImpulse.GetNormalized().xyz );
(*proto)->SetState( state );
}
@@ -205,12 +198,31 @@ void API_Impl::Update()
proto = updateList.begin();
for( ; proto != updateList.end(); ++proto )
{
+ Float3 lM = state.GetLinearMomentum() + state.GetLinearImpulse();
+
+ if( lM.x < this->epsilon )
+ {
+ state.SetLinearMomentum( Float3(0, lM.y, lM.z) );
+ state.SetLinearImpulse( Float3(0, lM.y, lM.z) );
+ }
+ if( lM.y < this->epsilon )
+ {
+ state.SetLinearMomentum( Float3(lM.x, 0, lM.z) );
+ state.SetLinearImpulse( Float3(lM.x, 0, lM.z) );
+ }
+ if( lM.z < this->epsilon )
+ {
+ state.SetLinearMomentum( Float3(lM.x, lM.y, 0) );
+ state.SetLinearImpulse( Float3(lM.x, lM.y, 0) );
+ }
+
switch( (*proto)->Update(this->updateFrameLength) )
{
case UpdateState_altered:
this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) );
(*proto)->CallSubscription_Move();
- case UpdateState_resting: default:
+ case UpdateState_resting:
+ default:
break;
}
}
@@ -268,6 +280,11 @@ void API_Impl::RemoveGravity( const API::Gravity &g )
}
}
+void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) )
+{
+ this->worldScene.Visit(collideable, args, hitAction);
+}
+
//void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
//{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
@@ -371,11 +388,16 @@ namespace Oyster { namespace Physics
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto )
{ /* Do nothing except allowing the proto uniquePointer destroy itself. */ }
- ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter )
+ ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_BeforeCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter )
{ /* Do nothing except returning business as usual. */
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
}
+ void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
+ { /* Do nothing except returning business as usual. */
+
+ }
+
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object )
{ /* Do nothing. */ }
}
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
index 8b38004c..21460944 100644
--- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
@@ -18,6 +18,7 @@ namespace Oyster
void SetFrameTimeLength( float deltaTime );
void SetGravityConstant( float g );
+ void SetEpsilon( float e );
void SetSubscription( EventAction_Destruction functionPointer );
float GetFrameTimeLength() const;
@@ -35,6 +36,8 @@ namespace Oyster
void AddGravity( const API::Gravity &g );
void RemoveGravity( const API::Gravity &g );
+ void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) );
+
//void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF );
//void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI );
@@ -50,7 +53,7 @@ namespace Oyster
::Utility::DynamicMemory::UniquePointer CreateRigidBody( const SphericalBodyDescription &desc ) const;
private:
- ::Oyster::Math::Float gravityConstant, updateFrameLength;
+ ::Oyster::Math::Float gravityConstant, updateFrameLength, epsilon;
EventAction_Destruction destructionAction;
::std::vector gravity;
Octree worldScene;
@@ -59,7 +62,8 @@ namespace Oyster
namespace Default
{
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
- ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
+ ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_BeforeCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
+ void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
}
}
diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
index df191059..ef3027ee 100644
--- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
+++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
@@ -46,7 +46,8 @@ SimpleRigidBody::SimpleRigidBody()
this->rigid = RigidBody();
this->rigid.SetMass_KeepMomentum( 16.0f );
this->gravityNormal = Float3::null;
- this->onCollision = Default::EventAction_Collision;
+ this->onCollision = Default::EventAction_BeforeCollisionResponse;
+ this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
this->onMovement = Default::EventAction_Move;
this->scene = nullptr;
this->customTag = nullptr;
@@ -55,7 +56,7 @@ SimpleRigidBody::SimpleRigidBody()
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
{
- this->rigid.SetRotation( desc.rotation );
+ //this->rigid.SetRotation( desc.rotation );
this->rigid.centerPos = desc.centerPosition;
this->rigid.SetSize( desc.size );
this->rigid.SetMass_KeepMomentum( desc.mass );
@@ -71,7 +72,16 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
}
else
{
- this->onCollision = Default::EventAction_Collision;
+ this->onCollision = Default::EventAction_BeforeCollisionResponse;
+ }
+
+ if( desc.subscription_onCollisionResponse )
+ {
+ this->onCollisionResponse = desc.subscription_onCollisionResponse;
+ }
+ else
+ {
+ this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
}
if( desc.subscription_onMovement )
@@ -101,7 +111,8 @@ SimpleRigidBody::State SimpleRigidBody::GetState() const
this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic,
this->rigid.GetMomentOfInertia(), this->rigid.boundingReach,
this->rigid.centerPos, this->rigid.axis,
- this->rigid.momentum_Linear, this->rigid.momentum_Angular );
+ this->rigid.momentum_Linear, this->rigid.momentum_Angular,
+ this->rigid.gravityNormal );
}
SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const
@@ -110,7 +121,8 @@ SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targ
this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic,
this->rigid.GetMomentOfInertia(), this->rigid.boundingReach,
this->rigid.centerPos, this->rigid.axis,
- this->rigid.momentum_Linear, this->rigid.momentum_Angular );
+ this->rigid.momentum_Linear, this->rigid.momentum_Angular,
+ this->rigid.gravityNormal );
}
void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
@@ -127,11 +139,12 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic();
this->rigid.SetMass_KeepMomentum( state.GetMass() );
this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() );
+ this->rigid.gravityNormal = state.GetGravityNormal();
if( state.IsForwarded() )
{
- this->deltaPos += state.GetForward_DeltaPos();
- this->deltaAxis += state.GetForward_DeltaAxis();
+ this->deltaPos += Float4(state.GetForward_DeltaPos(), 0);
+ this->deltaAxis += Float4(state.GetForward_DeltaAxis(), 0);
this->isForwarded;
}
@@ -150,11 +163,16 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
}
}
-ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_Collision( const ICustomBody *deuter )
+ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter )
{
return this->onCollision( this, deuter );
}
+void SimpleRigidBody::CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
+{
+ return this->onCollisionResponse( this, deuter, kineticEnergyLoss );
+}
+
void SimpleRigidBody::CallSubscription_Move()
{
this->onMovement( this );
@@ -187,7 +205,7 @@ Sphere & SimpleRigidBody::GetBoundingSphere( Sphere &targetMem ) const
Float4 & SimpleRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
{
- Float4 offset = worldPos - this->rigid.centerPos;
+ Float4 offset = worldPos.xyz - this->rigid.centerPos;
Float distance = offset.Dot( offset );
Float3 normal = Float3::null;
@@ -277,7 +295,7 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
{
if( this->isForwarded )
{
- this->rigid.Move( this->deltaPos, this->deltaAxis );
+ this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz );
this->deltaPos = Float4::null;
this->deltaAxis = Float4::null;
this->isForwarded = false;
@@ -292,7 +310,7 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
void SimpleRigidBody::Predict( Float4 &outDeltaPos, Float4 &outDeltaAxis, const Float4 &actingLinearImpulse, const Float4 &actingAngularImpulse, Float deltaTime )
{
- this->rigid.Predict_LeapFrog( outDeltaPos, outDeltaAxis, actingLinearImpulse, actingAngularImpulse, deltaTime );
+ this->rigid.Predict_LeapFrog( outDeltaPos.xyz, outDeltaAxis.xyz, actingLinearImpulse.xyz, actingAngularImpulse.xyz, deltaTime );
}
void SimpleRigidBody::SetScene( void *scene )
@@ -300,7 +318,7 @@ void SimpleRigidBody::SetScene( void *scene )
this->scene = (Octree*)scene;
}
-void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
+void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_BeforeCollisionResponse functionPointer )
{
if( functionPointer )
{
@@ -308,7 +326,19 @@ void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functi
}
else
{
- this->onCollision = Default::EventAction_Collision;
+ this->onCollision = Default::EventAction_BeforeCollisionResponse;
+ }
+}
+
+void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_AfterCollisionResponse functionPointer )
+{
+ if( functionPointer )
+ {
+ this->onCollisionResponse = functionPointer;
+ }
+ else
+ {
+ this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
}
}
@@ -333,6 +363,7 @@ void SimpleRigidBody::SetGravity( bool ignore)
void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
{
this->gravityNormal = normalizedVector;
+ this->rigid.gravityNormal = Float4( this->gravityNormal, 0 );
}
void SimpleRigidBody::SetCustomTag( void *ref )
diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h
index cce657da..9e61cee3 100644
--- a/Code/GamePhysics/Implementation/SimpleRigidBody.h
+++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h
@@ -21,7 +21,8 @@ namespace Oyster { namespace Physics
void SetState( const State &state );
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
- SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
+ SubscriptMessage CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter );
+ void CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
void CallSubscription_Move();
bool IsAffectedByGravity() const;
@@ -43,7 +44,8 @@ namespace Oyster { namespace Physics
void SetScene( void *scene );
- void SetSubscription( EventAction_Collision functionPointer );
+ void SetSubscription( EventAction_BeforeCollisionResponse functionPointer );
+ void SetSubscription( EventAction_AfterCollisionResponse functionPointer );
void SetSubscription( EventAction_Move functionPointer );
void SetGravity( bool ignore);
@@ -63,7 +65,8 @@ namespace Oyster { namespace Physics
::Oyster::Physics3D::RigidBody rigid;
::Oyster::Math::Float4 deltaPos, deltaAxis;
::Oyster::Math::Float3 gravityNormal;
- EventAction_Collision onCollision;
+ EventAction_BeforeCollisionResponse onCollision;
+ EventAction_AfterCollisionResponse onCollisionResponse;
EventAction_Move onMovement;
Octree *scene;
void *customTag;
diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp
index 7b15510a..539093db 100644
--- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp
+++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp
@@ -13,7 +13,8 @@ SphericalRigidBody::SphericalRigidBody()
this->rigid = RigidBody();
this->rigid.SetMass_KeepMomentum( 10.0f );
this->gravityNormal = Float3::null;
- this->onCollision = Default::EventAction_Collision;
+ this->onCollision = Default::EventAction_BeforeCollisionResponse;
+ this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
this->onMovement = Default::EventAction_Move;
this->scene = nullptr;
this->customTag = nullptr;
@@ -23,11 +24,11 @@ SphericalRigidBody::SphericalRigidBody()
SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc )
{
this->rigid = RigidBody();
- this->rigid.SetRotation( desc.rotation );
+ //this->rigid.SetRotation( desc.rotation );
this->rigid.centerPos = desc.centerPosition;
this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f );
this->rigid.SetMass_KeepMomentum( desc.mass );
- this->rigid.SetMomentOfInertia_KeepMomentum( Formula::MomentOfInertia::CreateSphereMatrix( desc.mass, desc.radius ) );
+ this->rigid.SetMomentOfInertia_KeepMomentum( MomentOfInertia::Sphere(desc.mass, desc.radius) );
this->deltaPos = Float4::null;
this->deltaAxis = Float4::null;
@@ -39,7 +40,16 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
}
else
{
- this->onCollision = Default::EventAction_Collision;
+ this->onCollision = Default::EventAction_BeforeCollisionResponse;
+ }
+
+ if( desc.subscription_onCollisionResponse )
+ {
+ this->onCollisionResponse = desc.subscription_onCollisionResponse;
+ }
+ else
+ {
+ this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
}
if( desc.subscription_onMovement )
@@ -98,8 +108,8 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
if( state.IsForwarded() )
{
- this->deltaPos += state.GetForward_DeltaPos();
- this->deltaAxis += state.GetForward_DeltaAxis();
+ this->deltaPos += Float4(state.GetForward_DeltaPos(), 0);
+ this->deltaAxis += Float4(state.GetForward_DeltaAxis());
this->isForwarded = false;
}
@@ -118,11 +128,17 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
}
}
-ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_Collision( const ICustomBody *deuter )
+ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter )
{
return this->onCollision( this, deuter );
}
+void SphericalRigidBody::CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
+{
+ this->onCollisionResponse( this, deuter, kineticEnergyLoss);
+}
+
+
void SphericalRigidBody::CallSubscription_Move()
{
this->onMovement( this );
@@ -155,7 +171,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
Float4 & SphericalRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
{
- targetMem = worldPos - this->rigid.centerPos;
+ targetMem = Float4( worldPos.xyz - this->rigid.centerPos, 0);
Float magnitude = targetMem.GetMagnitude();
if( magnitude != 0.0f )
{ // sanity check
@@ -204,7 +220,7 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength )
{
if( this->isForwarded )
{
- this->rigid.Move( this->deltaPos, this->deltaAxis );
+ this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz );
this->deltaPos = Float4::null;
this->deltaAxis = Float4::null;
this->isForwarded = false;
@@ -219,10 +235,10 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength )
void SphericalRigidBody::Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime )
{
- this->rigid.Predict_LeapFrog( outDeltaPos, outDeltaAxis, actingLinearImpulse, actingAngularImpulse, deltaTime );
+ this->rigid.Predict_LeapFrog( outDeltaPos.xyz, outDeltaAxis.xyz, actingLinearImpulse.xyz, actingAngularImpulse.xyz, deltaTime );
}
-void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
+void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_BeforeCollisionResponse functionPointer )
{
if( functionPointer )
{
@@ -230,7 +246,19 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision fun
}
else
{
- this->onCollision = Default::EventAction_Collision;
+ this->onCollision = Default::EventAction_BeforeCollisionResponse;
+ }
+}
+
+void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_AfterCollisionResponse functionPointer )
+{
+ if( functionPointer )
+ {
+ this->onCollisionResponse = functionPointer;
+ }
+ else
+ {
+ this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
}
}
diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h
index 49c8fb8c..390b7171 100644
--- a/Code/GamePhysics/Implementation/SphericalRigidBody.h
+++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h
@@ -22,7 +22,8 @@ namespace Oyster { namespace Physics
void SetState( const State &state );
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
- SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
+ SubscriptMessage CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter );
+ void CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
void CallSubscription_Move();
bool IsAffectedByGravity() const;
@@ -44,7 +45,8 @@ namespace Oyster { namespace Physics
void SetScene( void *scene );
- void SetSubscription( EventAction_Collision functionPointer );
+ void SetSubscription( EventAction_BeforeCollisionResponse functionPointer );
+ void SetSubscription( EventAction_AfterCollisionResponse functionPointer );
void SetSubscription( EventAction_Move functionPointer );
void SetGravity( bool ignore);
@@ -64,7 +66,8 @@ namespace Oyster { namespace Physics
::Oyster::Physics3D::RigidBody rigid;
::Oyster::Math::Float4 deltaPos, deltaAxis;
::Oyster::Math::Float3 gravityNormal;
- EventAction_Collision onCollision;
+ EventAction_BeforeCollisionResponse onCollision;
+ EventAction_AfterCollisionResponse onCollisionResponse;
EventAction_Move onMovement;
Octree *scene;
void *customTag;
diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h
index 4fcd2940..78b65f5e 100644
--- a/Code/GamePhysics/PhysicsAPI.h
+++ b/Code/GamePhysics/PhysicsAPI.h
@@ -34,6 +34,7 @@ namespace Oyster
namespace Constant
{
const float gravity_constant = (const float)6.67284e-11; //!< The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields.
+ const float epsilon = (const float)1.0e-7;
}
class PHYSICS_DLL_USAGE API
@@ -136,6 +137,15 @@ namespace Oyster
********************************************************/
virtual void RemoveGravity( const API::Gravity &g ) = 0;
+ /********************************************************
+ * Applies an effect to objects that collide with the set volume.
+ * @param collideable: An ICollideable that defines the volume of the effect.
+ * @param args: The arguments needed for the hitAction function.
+ * @param hitAction: A function that contains the effect. Parameterlist contains the custom body
+ the collideable hits, and the arguments sent to the function.
+ ********************************************************/
+ virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) ) = 0;
+
///********************************************************
// * Apply force on an object.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
@@ -231,10 +241,12 @@ namespace Oyster
enum SubscriptMessage
{
SubscriptMessage_none,
+ SubscriptMessage_kineticLoss,
SubscriptMessage_ignore_collision_response
};
- typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
+ typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter );
+ typedef void (*EventAction_AfterCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
typedef void (*EventAction_Move)( const ICustomBody *object );
typedef Struct::SimpleBodyDescription SimpleBodyDescription;
typedef Struct::SphericalBodyDescription SphericalBodyDescription;
@@ -251,7 +263,12 @@ namespace Oyster
/********************************************************
* @todo TODO: need doc
********************************************************/
- virtual SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ) = 0;
+ virtual SubscriptMessage CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter ) = 0;
+
+ /********************************************************
+ * @todo TODO: need doc
+ ********************************************************/
+ virtual void CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ) = 0;
/********************************************************
* @todo TODO: need doc
@@ -381,7 +398,14 @@ namespace Oyster
* whenever a collision occurs.
* @param functionPointer: If NULL, an empty default function will be set.
********************************************************/
- virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
+ virtual void SetSubscription( EventAction_BeforeCollisionResponse functionPointer ) = 0;
+
+ /********************************************************
+ * Sets the function that will be called by the engine
+ * whenever a collision has finished.
+ * @param functionPointer: If NULL, an empty default function will be set.
+ ********************************************************/
+ virtual void SetSubscription( EventAction_AfterCollisionResponse functionPointer ) = 0;
/********************************************************
* Sets the function that will be called by the engine
diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h
index 2f218095..fa5533fa 100644
--- a/Code/GamePhysics/PhysicsStructs-Impl.h
+++ b/Code/GamePhysics/PhysicsStructs-Impl.h
@@ -13,11 +13,15 @@ namespace Oyster
inline SimpleBodyDescription::SimpleBodyDescription()
{
this->rotation = ::Oyster::Math::Float4x4::identity;
- this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
- this->size = ::Oyster::Math::Float4( 1.0f );
+ this->centerPosition = ::Oyster::Math::Float3::null;
+ this->size = ::Oyster::Math::Float3( 1.0f );
this->mass = 12.0f;
- this->inertiaTensor = ::Oyster::Math::Float4x4::identity;
+ this->restitutionCoeff = 1.0f;
+ this->frictionCoeff_Dynamic = 0.5f;
+ this->frictionCoeff_Static = 0.5f;
+ this->inertiaTensor = ::Oyster::Physics3D::MomentOfInertia();
this->subscription_onCollision = NULL;
+ this->subscription_onCollisionResponse = NULL;
this->subscription_onMovement = NULL;
this->ignoreGravity = false;
}
@@ -25,15 +29,19 @@ namespace Oyster
inline SphericalBodyDescription::SphericalBodyDescription()
{
this->rotation = ::Oyster::Math::Float4x4::identity;
- this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
+ this->centerPosition = ::Oyster::Math::Float3::null;
this->radius = 0.5f;
this->mass = 10.0f;
+ this->restitutionCoeff = 1.0f;
+ this->frictionCoeff_Dynamic = 0.5f;
+ this->frictionCoeff_Static = 0.5f;
this->subscription_onCollision = NULL;
+ this->subscription_onCollisionResponse = NULL;
this->subscription_onMovement = NULL;
this->ignoreGravity = false;
}
- inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 ¢erPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum )
+ inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Physics3D::MomentOfInertia &inertiaTensor, const ::Oyster::Math::Float3 &reach, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Float3 &rotation, const ::Oyster::Math::Float3 &linearMomentum, const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &gravityNormal )
{
this->mass = mass;
this->restitutionCoeff = restitutionCoeff;
@@ -45,9 +53,10 @@ namespace Oyster
this->angularAxis = rotation;
this->linearMomentum = linearMomentum;
this->angularMomentum = angularMomentum;
- this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float4::null;
- this->deltaPos = this->deltaAxis = ::Oyster::Math::Float4::null;
+ this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float3::null;
+ this->deltaPos = this->deltaAxis = ::Oyster::Math::Float3::null;
this->isSpatiallyAltered = this->isDisturbed = this->isForwarded = false;
+ this->gravityNormal = gravityNormal;
}
inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state )
@@ -69,6 +78,7 @@ namespace Oyster
this->isSpatiallyAltered = state.isSpatiallyAltered;
this->isDisturbed = state.isDisturbed;
this->isForwarded = state.isForwarded;
+ this->gravityNormal = state.gravityNormal;
return *this;
}
@@ -92,91 +102,96 @@ namespace Oyster
return this->kineticFrictionCoeff;
}
- inline const ::Oyster::Math::Float4x4 & CustomBodyState::GetMomentOfInertia() const
+ inline const ::Oyster::Physics3D::MomentOfInertia & CustomBodyState::GetMomentOfInertia() const
{
return this->inertiaTensor;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetReach() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetReach() const
{
return this->reach;
}
- inline ::Oyster::Math::Float4 CustomBodyState::GetSize() const
+ inline ::Oyster::Math::Float3 CustomBodyState::GetSize() const
{
return 2.0f * this->GetReach();
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetCenterPosition() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetCenterPosition() const
{
return this->centerPos;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularAxis() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularAxis() const
{
return this->angularAxis;
}
inline ::Oyster::Math::Float4x4 CustomBodyState::GetRotation() const
{
- return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis().xyz );
+ return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis() );
}
inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation() const
{
- return ::Oyster::Math3D::OrientationMatrix( this->angularAxis.xyz, this->centerPos.xyz );
+ return ::Oyster::Math3D::OrientationMatrix( this->angularAxis, this->centerPos );
}
- inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation( const ::Oyster::Math::Float4 &offset ) const
+ inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation( const ::Oyster::Math::Float3 &offset ) const
{
- return ::Oyster::Math3D::OrientationMatrix( this->angularAxis.xyz, (this->centerPos + offset).xyz );
+ return ::Oyster::Math3D::OrientationMatrix( this->angularAxis, (this->centerPos + offset) );
}
inline ::Oyster::Math::Float4x4 CustomBodyState::GetView() const
{
- return ::Oyster::Math3D::ViewMatrix( this->angularAxis.xyz, this->centerPos.xyz );
+ return ::Oyster::Math3D::ViewMatrix( this->angularAxis, this->centerPos );
}
- inline ::Oyster::Math::Float4x4 CustomBodyState::GetView( const ::Oyster::Math::Float4 &offset ) const
+ inline ::Oyster::Math::Float4x4 CustomBodyState::GetView( const ::Oyster::Math::Float3 &offset ) const
{
- return ::Oyster::Math3D::ViewMatrix( this->angularAxis.xyz, (this->centerPos + offset).xyz );
+ return ::Oyster::Math3D::ViewMatrix( this->angularAxis, (this->centerPos + offset) );
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetLinearMomentum() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetLinearMomentum() const
{
return this->linearMomentum;
}
- inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const
+ inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
{
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos );
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularMomentum() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const
{
return this->angularMomentum;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetLinearImpulse() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetLinearImpulse() const
{
return this->linearImpulse;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularImpulse() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularImpulse() const
{
return this->angularImpulse;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetForward_DeltaPos() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetForward_DeltaPos() const
{
return this->deltaPos;
}
- inline const ::Oyster::Math::Float4 & CustomBodyState::GetForward_DeltaAxis() const
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetForward_DeltaAxis() const
{
return this->deltaAxis;
}
+ inline const ::Oyster::Math::Float3 & CustomBodyState::GetGravityNormal() const
+ {
+ return this->gravityNormal;
+ }
+
inline void CustomBodyState::SetMass_KeepMomentum( ::Oyster::Math::Float m )
{
this->mass = m;
@@ -204,47 +219,51 @@ namespace Oyster
this->kineticFrictionCoeff = kineticU;
}
- inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor )
+ inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Physics3D::MomentOfInertia &tensor )
{
this->inertiaTensor = tensor;
}
- inline void CustomBodyState::SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor )
+ inline void CustomBodyState::SetMomentOfInertia_KeepVelocity( const ::Oyster::Physics3D::MomentOfInertia &tensor )
{
- if( tensor.GetDeterminant() != 0.0f )
- { // sanity block!
- ::Oyster::Math::Float4x4 rotation = ::Oyster::Math3D::RotationMatrix(this->angularAxis.xyz);
- ::Oyster::Math::Float4 w = ::Oyster::Physics3D::Formula::AngularVelocity( (rotation * this->inertiaTensor).GetInverse(), this->angularMomentum );
- this->inertiaTensor = tensor;
- this->angularMomentum = ::Oyster::Physics3D::Formula::AngularMomentum( rotation * tensor, w );
- }
+ ::Oyster::Math::Quaternion rotation = ::Oyster::Math3D::Rotation(this->angularAxis);
+ ::Oyster::Math::Float3 w = this->inertiaTensor.CalculateAngularVelocity( rotation, this->angularMomentum );
+ this->inertiaTensor = tensor;
+ this->angularMomentum = this->inertiaTensor.CalculateAngularMomentum( rotation, w );
}
- inline void CustomBodyState::SetSize( const ::Oyster::Math::Float4 &size )
+ inline void CustomBodyState::SetSize( const ::Oyster::Math::Float3 &size )
{
this->SetReach( 0.5f * size );
}
- inline void CustomBodyState::SetReach( const ::Oyster::Math::Float4 &halfSize )
+ inline void CustomBodyState::SetReach( const ::Oyster::Math::Float3 &halfSize )
{
- this->reach.xyz = halfSize;
- this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float4::null );
+ this->reach = halfSize;
+ this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float3::null );
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float4 ¢erPos )
+ inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos )
{
- this->centerPos.xyz = centerPos;
+ this->centerPos = centerPos;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4 &angularAxis )
+ inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float3 &angularAxis )
{
- this->angularAxis.xyz = angularAxis;
+ this->angularAxis = angularAxis;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation )
+ inline void CustomBodyState::SetOrientation( const ::Oyster::Math::Float3 &angularAxis, const ::Oyster::Math::Float3 &translation )
+ {
+ this->angularAxis = angularAxis ;
+ this->centerPos = translation;
+ this->isSpatiallyAltered = this->isDisturbed = true;
+ }
+
+ /*inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation )
{
this->SetRotation( ::Oyster::Math3D::AngularAxis(rotation) );
}
@@ -253,67 +272,74 @@ namespace Oyster
{
this->SetRotation( ::Oyster::Math3D::ExtractAngularAxis(orientation) );
this->SetCenterPosition( orientation.v[3] );
- }
+ }*/
- inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float4 &g )
+
+
+ inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float3 &g )
{
- this->linearMomentum.xyz = g;
+ this->linearMomentum = g;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float4 &h )
+ inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float3 &h )
{
- this->angularMomentum.xyz = h;
+ this->angularMomentum = h;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetLinearImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::SetLinearImpulse( const ::Oyster::Math::Float3 &j )
{
- this->linearImpulse.xyz = j;
+ this->linearImpulse = j;
this->isDisturbed = true;
}
- inline void CustomBodyState::SetAngularImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::SetAngularImpulse( const ::Oyster::Math::Float3 &j )
{
- this->angularImpulse.xyz = j;
+ this->angularImpulse = j;
this->isDisturbed = true;
}
- inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float4 &angularAxis )
+ inline void CustomBodyState::SetGravityNormal( const ::Oyster::Math::Float3 &gravityNormal )
+ {
+ this->gravityNormal = gravityNormal;
+ }
+
+ inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float3 &angularAxis )
{
this->angularAxis += angularAxis;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::AddTranslation( const ::Oyster::Math::Float4 &deltaPos )
+ inline void CustomBodyState::AddTranslation( const ::Oyster::Math::Float3 &deltaPos )
{
this->centerPos += deltaPos;
this->isSpatiallyAltered = this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyLinearImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::ApplyLinearImpulse( const ::Oyster::Math::Float3 &j )
{
this->linearImpulse += j;
this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyAngularImpulse( const ::Oyster::Math::Float4 &j )
+ inline void CustomBodyState::ApplyAngularImpulse( const ::Oyster::Math::Float3 &j )
{
this->angularImpulse += j;
this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal )
+ inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal )
{
- ::Oyster::Math::Float4 offset = at - this->centerPos;
- ::Oyster::Math::Float4 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
+ ::Oyster::Math::Float3 offset = at - this->centerPos;
+ ::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
this->linearImpulse += j - ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset );
this->angularImpulse += deltaAngularImpulse;
this->isDisturbed = true;
}
- inline void CustomBodyState::ApplyForwarding( const ::Oyster::Math::Float4 &deltaPos, const ::Oyster::Math::Float4 &deltaAxis )
+ inline void CustomBodyState::ApplyForwarding( const ::Oyster::Math::Float3 &deltaPos, const ::Oyster::Math::Float3 &deltaAxis )
{
this->deltaPos += deltaPos;
this->deltaAxis += deltaAxis;
diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h
index 1d3d58dd..00c07b2d 100644
--- a/Code/GamePhysics/PhysicsStructs.h
+++ b/Code/GamePhysics/PhysicsStructs.h
@@ -3,6 +3,7 @@
#include "OysterMath.h"
#include "PhysicsAPI.h"
+#include "Inertia.h"
namespace Oyster { namespace Physics
{
@@ -11,11 +12,15 @@ namespace Oyster { namespace Physics
struct SimpleBodyDescription
{
::Oyster::Math::Float4x4 rotation;
- ::Oyster::Math::Float4 centerPosition;
- ::Oyster::Math::Float4 size;
+ ::Oyster::Math::Float3 centerPosition;
+ ::Oyster::Math::Float3 size;
::Oyster::Math::Float mass;
- ::Oyster::Math::Float4x4 inertiaTensor;
- ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
+ ::Oyster::Math::Float restitutionCoeff;
+ ::Oyster::Math::Float frictionCoeff_Static;
+ ::Oyster::Math::Float frictionCoeff_Dynamic;
+ ::Oyster::Physics3D::MomentOfInertia inertiaTensor;
+ ::Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse subscription_onCollision;
+ ::Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse subscription_onCollisionResponse;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
bool ignoreGravity;
@@ -25,10 +30,14 @@ namespace Oyster { namespace Physics
struct SphericalBodyDescription
{
::Oyster::Math::Float4x4 rotation;
- ::Oyster::Math::Float4 centerPosition;
+ ::Oyster::Math::Float3 centerPosition;
::Oyster::Math::Float radius;
::Oyster::Math::Float mass;
- ::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
+ ::Oyster::Math::Float restitutionCoeff;
+ ::Oyster::Math::Float frictionCoeff_Static;
+ ::Oyster::Math::Float frictionCoeff_Dynamic;
+ ::Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse subscription_onCollision;
+ ::Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse subscription_onCollisionResponse;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
bool ignoreGravity;
@@ -42,12 +51,13 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float restitutionCoeff = 1.0f,
::Oyster::Math::Float staticFrictionCoeff = 1.0f,
::Oyster::Math::Float kineticFrictionCoeff = 1.0f,
- const ::Oyster::Math::Float4x4 &inertiaTensor = ::Oyster::Math::Float4x4::identity,
- const ::Oyster::Math::Float4 &reach = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 ¢erPos = ::Oyster::Math::Float4::standard_unit_w,
- const ::Oyster::Math::Float4 &rotation = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 &linearMomentum = ::Oyster::Math::Float4::null,
- const ::Oyster::Math::Float4 &angularMomentum = ::Oyster::Math::Float4::null );
+ const ::Oyster::Physics3D::MomentOfInertia &inertiaTensor = ::Oyster::Physics3D::MomentOfInertia(),
+ const ::Oyster::Math::Float3 &reach = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 ¢erPos = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &rotation = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &linearMomentum = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &angularMomentum = ::Oyster::Math::Float3::null,
+ const ::Oyster::Math::Float3 &gravityNormal = ::Oyster::Math::Float3::null);
CustomBodyState & operator = ( const CustomBodyState &state );
@@ -55,48 +65,51 @@ namespace Oyster { namespace Physics
const ::Oyster::Math::Float GetRestitutionCoeff() const;
const ::Oyster::Math::Float GetFrictionCoeff_Static() const;
const ::Oyster::Math::Float GetFrictionCoeff_Kinetic() const;
- const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const;
- const ::Oyster::Math::Float4 & GetReach() const;
- ::Oyster::Math::Float4 GetSize() const;
- const ::Oyster::Math::Float4 & GetCenterPosition() const;
- const ::Oyster::Math::Float4 & GetAngularAxis() const;
+ const ::Oyster::Physics3D::MomentOfInertia & GetMomentOfInertia() const;
+ const ::Oyster::Math::Float3 & GetReach() const;
+ ::Oyster::Math::Float3 GetSize() const;
+ const ::Oyster::Math::Float3 & GetCenterPosition() const;
+ const ::Oyster::Math::Float3 & GetAngularAxis() const;
::Oyster::Math::Float4x4 GetRotation() const;
::Oyster::Math::Float4x4 GetOrientation() const;
- ::Oyster::Math::Float4x4 GetOrientation( const ::Oyster::Math::Float4 &offset ) const;
+ ::Oyster::Math::Float4x4 GetOrientation( const ::Oyster::Math::Float3 &offset ) const;
::Oyster::Math::Float4x4 GetView() const;
- ::Oyster::Math::Float4x4 GetView( const ::Oyster::Math::Float4 &offset ) const;
- const ::Oyster::Math::Float4 & GetLinearMomentum() const;
- ::Oyster::Math::Float4 GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const;
- const ::Oyster::Math::Float4 & GetAngularMomentum() const;
- const ::Oyster::Math::Float4 & GetLinearImpulse() const;
- const ::Oyster::Math::Float4 & GetAngularImpulse() const;
- const ::Oyster::Math::Float4 & GetForward_DeltaPos() const;
- const ::Oyster::Math::Float4 & GetForward_DeltaAxis() const;
+ ::Oyster::Math::Float4x4 GetView( const ::Oyster::Math::Float3 &offset ) const;
+ const ::Oyster::Math::Float3 & GetLinearMomentum() const;
+ ::Oyster::Math::Float3 GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const;
+ const ::Oyster::Math::Float3 & GetAngularMomentum() const;
+ const ::Oyster::Math::Float3 & GetLinearImpulse() const;
+ const ::Oyster::Math::Float3 & GetAngularImpulse() const;
+ const ::Oyster::Math::Float3 & GetForward_DeltaPos() const;
+ const ::Oyster::Math::Float3 & GetForward_DeltaAxis() const;
+ const ::Oyster::Math::Float3 & GetGravityNormal() const;
void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
void SetRestitutionCoeff( ::Oyster::Math::Float e );
void SetFrictionCoeff( ::Oyster::Math::Float staticU, ::Oyster::Math::Float kineticU );
- void SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor );
- void SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor );
- void SetSize( const ::Oyster::Math::Float4 &size );
- void SetReach( const ::Oyster::Math::Float4 &halfSize );
- void SetCenterPosition( const ::Oyster::Math::Float4 ¢erPos );
- void SetRotation( const ::Oyster::Math::Float4 &angularAxis );
- void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
- void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
- void SetLinearMomentum( const ::Oyster::Math::Float4 &g );
- void SetAngularMomentum( const ::Oyster::Math::Float4 &h );
- void SetLinearImpulse( const ::Oyster::Math::Float4 &j );
- void SetAngularImpulse( const ::Oyster::Math::Float4 &j );
+ void SetMomentOfInertia_KeepMomentum( const ::Oyster::Physics3D::MomentOfInertia &tensor );
+ void SetMomentOfInertia_KeepVelocity( const ::Oyster::Physics3D::MomentOfInertia &tensor );
+ void SetSize( const ::Oyster::Math::Float3 &size );
+ void SetReach( const ::Oyster::Math::Float3 &halfSize );
+ void SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos );
+ void SetRotation( const ::Oyster::Math::Float3 &angularAxis );
+ //void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
+ //void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
+ void SetOrientation( const ::Oyster::Math::Float3 &angularAxis, const ::Oyster::Math::Float3 &translation );
+ void SetLinearMomentum( const ::Oyster::Math::Float3 &g );
+ void SetAngularMomentum( const ::Oyster::Math::Float3 &h );
+ void SetLinearImpulse( const ::Oyster::Math::Float3 &j );
+ void SetAngularImpulse( const ::Oyster::Math::Float3 &j );
+ void SetGravityNormal( const ::Oyster::Math::Float3 &gravityNormal );
- void AddRotation( const ::Oyster::Math::Float4 &angularAxis );
- void AddTranslation( const ::Oyster::Math::Float4 &deltaPos );
+ void AddRotation( const ::Oyster::Math::Float3 &angularAxis );
+ void AddTranslation( const ::Oyster::Math::Float3 &deltaPos );
- void ApplyLinearImpulse( const ::Oyster::Math::Float4 &j );
- void ApplyAngularImpulse( const ::Oyster::Math::Float4 &j );
- void ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal );
- void ApplyForwarding( const ::Oyster::Math::Float4 &deltaPos, const ::Oyster::Math::Float4 &deltaAxis );
+ void ApplyLinearImpulse( const ::Oyster::Math::Float3 &j );
+ void ApplyAngularImpulse( const ::Oyster::Math::Float3 &j );
+ void ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal );
+ void ApplyForwarding( const ::Oyster::Math::Float3 &deltaPos, const ::Oyster::Math::Float3 &deltaAxis );
bool IsSpatiallyAltered() const;
bool IsDisturbed() const;
@@ -104,11 +117,12 @@ namespace Oyster { namespace Physics
private:
::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, kineticFrictionCoeff;
- ::Oyster::Math::Float4x4 inertiaTensor;
- ::Oyster::Math::Float4 reach, centerPos, angularAxis;
- ::Oyster::Math::Float4 linearMomentum, angularMomentum;
- ::Oyster::Math::Float4 linearImpulse, angularImpulse;
- ::Oyster::Math::Float4 deltaPos, deltaAxis; // Forwarding data sum
+ ::Oyster::Physics3D::MomentOfInertia inertiaTensor;
+ ::Oyster::Math::Float3 reach, centerPos, angularAxis;
+ ::Oyster::Math::Float3 linearMomentum, angularMomentum;
+ ::Oyster::Math::Float3 linearImpulse, angularImpulse;
+ ::Oyster::Math::Float3 deltaPos, deltaAxis; // Forwarding data sum
+ ::Oyster::Math::Float3 gravityNormal;
bool isSpatiallyAltered, isDisturbed, isForwarded;
};
diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp
index 45807e84..79c7c700 100644
--- a/Code/Misc/Thread/OysterThread_Impl.cpp
+++ b/Code/Misc/Thread/OysterThread_Impl.cpp
@@ -296,7 +296,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker)
}
OYSTER_THREAD_ERROR OysterThread::Terminate()
{
- return this->privateData->Terminate();
+ if(this->privateData)
+ return this->privateData->Terminate();
+ return OYSTER_THREAD_ERROR_SUCCESS;
}
OYSTER_THREAD_ERROR OysterThread::Wait()
{
diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h
index 7e76dbba..9c71a515 100644
--- a/Code/Misc/Utilities.h
+++ b/Code/Misc/Utilities.h
@@ -327,6 +327,10 @@ namespace Utility
inline ValueType Min( const ValueType &valueA, const ValueType &valueB )
{ return valueA < valueB ? valueA : valueB; }
+ template
+ inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max )
+ { return value < min ? Max( value, max ) : min; }
+
template
inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
{ return (valueA + valueB) * 0.5f; }
diff --git a/Code/Network/NetworkAPI/NetworkServer.cpp b/Code/Network/NetworkAPI/NetworkServer.cpp
index 9a4195a2..4bdc4abf 100644
--- a/Code/Network/NetworkAPI/NetworkServer.cpp
+++ b/Code/Network/NetworkAPI/NetworkServer.cpp
@@ -224,7 +224,7 @@ void NetworkServer::Shutdown()
this->privateData->isReleased = true;
}
-int NetworkServer::ProcessConnectedClients()
+int NetworkServer::Update()
{
int c = 0;
while(!this->privateData->clientQueue.IsEmpty())
@@ -282,6 +282,10 @@ std::string NetworkServer::GetLanAddress()
szLocalIP = buff;
return szLocalIP;
}
+int NetworkServer::GetPort()
+{
+ return this->privateData->port;
+}
diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h
index ca33ebbe..97a3e024 100644
--- a/Code/Network/NetworkAPI/NetworkServer.h
+++ b/Code/Network/NetworkAPI/NetworkServer.h
@@ -46,6 +46,10 @@ namespace Oyster
*/
ServerReturnCode Start();
+ /** Parses asynchronous connected clients.
+ */
+ int Update();
+
/**
*
*/
@@ -55,10 +59,6 @@ namespace Oyster
*/
void Shutdown();
- /** Parses asynchronous connected clients.
- */
- int ProcessConnectedClients();
-
/** Set the main session connected clients will enter when connected to server.
* @param mainSession The session to connect as main server session.
*/
@@ -84,6 +84,11 @@ namespace Oyster
*/
std::string GetLanAddress();
+ /**
+ *
+ */
+ int NetworkServer::GetPort();
+
private:
struct PrivateData;
PrivateData* privateData;
diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h
index b5eab471..50bcd36b 100644
--- a/Code/OysterMath/LinearMath.h
+++ b/Code/OysterMath/LinearMath.h
@@ -35,7 +35,7 @@ namespace std
// x2
template
-::LinearAlgebra::Matrix2x2 operator * ( const ::LinearAlgebra::Matrix2x2 &left, const ::LinearAlgebra::Matrix2x2 &right )
+inline ::LinearAlgebra::Matrix2x2 operator * ( const ::LinearAlgebra::Matrix2x2 &left, const ::LinearAlgebra::Matrix2x2 &right )
{
return ::LinearAlgebra::Matrix2x2( (left.m11 * right.m11) + (left.m12 * right.m21),
(left.m11 * right.m12) + (left.m12 * right.m22),
@@ -44,14 +44,14 @@ template
}
template
-::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Matrix2x2 &matrix, const ::LinearAlgebra::Vector2 &vector )
+inline ::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Matrix2x2 &matrix, const ::LinearAlgebra::Vector2 &vector )
{
return ::LinearAlgebra::Vector2( (matrix.m11 * vector.x) + (matrix.m12 * vector.y),
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) );
}
template
-::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Vector2 &vector, const ::LinearAlgebra::Matrix2x2 &left )
+inline ::LinearAlgebra::Vector2 operator * ( const ::LinearAlgebra::Vector2 &vector, const ::LinearAlgebra::Matrix2x2 &left )
{
return ::LinearAlgebra::Vector2( (vector.x * matrix.m11) + (vector.y * matrix.m21),
(vector.x * matrix.m12) + (vector.y * matrix.m22) );
@@ -60,7 +60,7 @@ template
// x3
template
-::LinearAlgebra::Matrix3x3 operator * ( const ::LinearAlgebra::Matrix3x3 &left, const ::LinearAlgebra::Matrix3x3 &right )
+inline ::LinearAlgebra::Matrix3x3 operator * ( const ::LinearAlgebra::Matrix3x3 &left, const ::LinearAlgebra::Matrix3x3 &right )
{
return ::LinearAlgebra::Matrix3x3( (left.m11 * right.m11) + (left.m12 * right.m21) + (left.m13 * right.m31), (left.m11 * right.m12) + (left.m12 * right.m22) + (left.m13 * right.m32), (left.m11 * right.m13) + (left.m12 * right.m23) + (left.m13 * right.m33),
(left.m21 * right.m11) + (left.m22 * right.m21) + (left.m23 * right.m31), (left.m21 * right.m12) + (left.m22 * right.m22) + (left.m23 * right.m32), (left.m21 * right.m13) + (left.m22 * right.m23) + (left.m23 * right.m33),
@@ -68,7 +68,7 @@ template
}
template
-::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Matrix3x3 &matrix, const ::LinearAlgebra::Vector3 &vector )
+inline ::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Matrix3x3 &matrix, const ::LinearAlgebra::Vector3 &vector )
{
return ::LinearAlgebra::Vector3( (matrix.m11 * vector.x) + (matrix.m12 * vector.y) + (matrix.m13 * vector.z),
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) + (matrix.m23 * vector.z),
@@ -76,7 +76,7 @@ template
}
template
-::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Vector3 &vector, const ::LinearAlgebra::Matrix3x3 &left )
+inline ::LinearAlgebra::Vector3 operator * ( const ::LinearAlgebra::Vector3 &vector, const ::LinearAlgebra::Matrix3x3 &left )
{
return ::LinearAlgebra::Vector3( (vector.x * matrix.m11) + (vector.y * matrix.m21) + (vector.z * matrix.m31),
(vector.x * matrix.m12) + (vector.y * matrix.m22) + (vector.z * matrix.m32),
@@ -86,7 +86,7 @@ template
// x4
template
-::LinearAlgebra::Matrix4x4 operator * ( const ::LinearAlgebra::Matrix4x4 &left, const ::LinearAlgebra::Matrix4x4 &right )
+inline ::LinearAlgebra::Matrix4x4 operator * ( const ::LinearAlgebra::Matrix4x4 &left, const ::LinearAlgebra::Matrix4x4 &right )
{
return ::LinearAlgebra::Matrix4x4( (left.m11 * right.m11) + (left.m12 * right.m21) + (left.m13 * right.m31) + (left.m14 * right.m41), (left.m11 * right.m12) + (left.m12 * right.m22) + (left.m13 * right.m32) + (left.m14 * right.m42), (left.m11 * right.m13) + (left.m12 * right.m23) + (left.m13 * right.m33) + (left.m14 * right.m43), (left.m11 * right.m14) + (left.m12 * right.m24) + (left.m13 * right.m34) + (left.m14 * right.m44),
(left.m21 * right.m11) + (left.m22 * right.m21) + (left.m23 * right.m31) + (left.m24 * right.m41), (left.m21 * right.m12) + (left.m22 * right.m22) + (left.m23 * right.m32) + (left.m24 * right.m42), (left.m21 * right.m13) + (left.m22 * right.m23) + (left.m23 * right.m33) + (left.m24 * right.m43), (left.m21 * right.m14) + (left.m22 * right.m24) + (left.m23 * right.m34) + (left.m24 * right.m44),
@@ -95,7 +95,7 @@ template
}
template
-::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Matrix4x4 &matrix, const ::LinearAlgebra::Vector4 &vector )
+inline ::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Matrix4x4 &matrix, const ::LinearAlgebra::Vector4 &vector )
{
return ::LinearAlgebra::Vector4( (matrix.m11 * vector.x) + (matrix.m12 * vector.y) + (matrix.m13 * vector.z) + (matrix.m14 * vector.w),
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) + (matrix.m23 * vector.z) + (matrix.m24 * vector.w),
@@ -104,7 +104,7 @@ template
}
template
-::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Matrix4x4 &matrix )
+inline ::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Matrix4x4 &matrix )
{
return ::LinearAlgebra::Vector4( (vector.x * matrix.m11) + (vector.y * matrix.m21) + (vector.z * matrix.m31) + (vector.w * matrix.m41),
(vector.x * matrix.m12) + (vector.y * matrix.m22) + (vector.z * matrix.m32) + (vector.w * matrix.m42),
@@ -146,6 +146,77 @@ namespace LinearAlgebra
targetMem = out * (in.GetAdjoint() /= d);
return true;
}
+
+ /********************************************************************
+ * Linear Interpolation
+ * @return start * (1-t) + end * t
+ ********************************************************************/
+ template
+ inline PointType Lerp( const PointType &start, const PointType &end, const ScalarType &t )
+ {
+ return end * t + start * ( 1 - t );
+ }
+
+ /********************************************************************
+ * Normalized Linear Interpolation
+ * @return nullvector if Lerp( start, end, t ) is nullvector.
+ ********************************************************************/
+ template
+ inline Vector2 Nlerp( const Vector2 &start, const Vector2 &end, const ScalarType &t )
+ {
+ Vector2 output = Lerp( start, end, t );
+ ScalarType magnitudeSquared = output.Dot( output );
+ if( magnitudeSquared != 0 )
+ {
+ return output /= (ScalarType)::std::sqrt( magnitudeSquared );
+ }
+ return output; // error: returning nullvector
+ }
+
+ /********************************************************************
+ * Normalized Linear Interpolation
+ * @return nullvector if Lerp( start, end, t ) is nullvector.
+ ********************************************************************/
+ template
+ inline Vector3 Nlerp( const Vector3 &start, const Vector3 &end, const ScalarType &t )
+ {
+ Vector3 output = Lerp( start, end, t );
+ ScalarType magnitudeSquared = output.Dot( output );
+ if( magnitudeSquared != 0 )
+ {
+ return output /= (ScalarType)::std::sqrt( magnitudeSquared );
+ }
+ return output; // error: returning nullvector
+ }
+
+ /********************************************************************
+ * Normalized Linear Interpolation
+ * @return nullvector if Lerp( start, end, t ) is nullvector.
+ ********************************************************************/
+ template
+ inline Vector4 Nlerp( const Vector4 &start, const Vector4 &end, const ScalarType &t )
+ {
+ Vector4 output = Lerp( start, end, t );
+ ScalarType magnitudeSquared = output.Dot( output );
+ if( magnitudeSquared != 0 )
+ {
+ return output /= (ScalarType)::std::sqrt( magnitudeSquared );
+ }
+ return output; // error: returning nullvector
+ }
+
+ /********************************************************************
+ * Spherical Linear Interpolation on Quaternions
+ ********************************************************************/
+ template
+ inline Quaternion Slerp( const Quaternion &start, const Quaternion &end, const ScalarType &t )
+ {
+ ScalarType angle = (ScalarType)::std::acos( Vector4(start.imaginary, start.real).Dot(Vector4(end.imaginary, end.real)) );
+ Quaternion result = start * (ScalarType)::std::sin( angle * (1 - t) );
+ result += end * (ScalarType)::std::sin( angle * t );
+ result *= (ScalarType)1.0f / (ScalarType)::std::sin( angle );
+ return result;
+ }
}
namespace LinearAlgebra2D
@@ -254,23 +325,24 @@ namespace LinearAlgebra2D
namespace LinearAlgebra3D
{
- template
- inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix )
- {
- return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
- }
+ // All Matrix to AngularAxis conversions here is incorrect
+ //template
+ //inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix )
+ //{
+ // return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
+ //}
- template
- inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix4x4 &rotationMatrix )
- {
- return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
- }
+ //template
+ //inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix4x4 &rotationMatrix )
+ //{
+ // return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
+ //}
- template
- inline ::LinearAlgebra::Vector4 ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4 &orientationMatrix )
- {
- return ::std::asin( ::LinearAlgebra::Vector4(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 0) );
- }
+ //template
+ //inline ::LinearAlgebra::Vector4 ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4 &orientationMatrix )
+ //{
+ // return ::std::asin( ::LinearAlgebra::Vector4(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 0) );
+ //}
template
inline ::LinearAlgebra::Matrix4x4 & TranslationMatrix( const ::LinearAlgebra::Vector3 &position, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() )
@@ -668,6 +740,58 @@ namespace LinearAlgebra3D
template
inline ::LinearAlgebra::Vector4 NormalProjection( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Vector4 &normalizedAxis )
{ return normalizedAxis * ( vector.Dot(normalizedAxis) ); }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & SnapAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis )
+ {
+ ScalarType projectedMagnitude = rotation.v[0].Dot( normalizedAxis );
+ if( projectedMagnitude == 1 )
+ { // infinite possible solutions -> roadtrip!
+ ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, (ScalarType)0.5f );
+
+ // interpolated.Dot( interpolated ) == 0 should be impossible at this point
+ projectedMagnitude = rotation.v[0].Dot( interpolated );
+ rotation.v[0] -= projectedMagnitude * interpolated;
+ rotation.v[0].Normalize();
+ projectedMagnitude = rotation.v[0].Dot( normalizedAxis );
+ }
+ rotation.v[0] -= projectedMagnitude * normalizedAxis;
+ rotation.v[0].Normalize();
+ rotation.v[1] = normalizedAxis;
+ rotation.v[2].xyz = rotation.v[0].xyz.Cross( rotation.v[1].xyz );
+ return rotation;
+ }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis, ScalarType t )
+ {
+ ::LinearAlgebra::Vector4 interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t );
+ if( interpolated.Dot(interpolated) == 0 )
+ return rotation; // return no change
+ return SnapAxisYToNormal_UsingNlerp( rotation, interpolated );
+ }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem )
+ {
+ targetMem.v[0] = ::LinearAlgebra::Nlerp( start.v[0], end.v[0], t );
+ targetMem.v[1] = ::LinearAlgebra::Nlerp( start.v[1], end.v[1], t );
+ targetMem.v[2] = ::LinearAlgebra::Nlerp( start.v[2], end.v[2], t );
+ targetMem.v[3] = ::LinearAlgebra::Lerp( start.v[3], end.v[3], t );
+ return targetMem;
+ }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Quaternion &startR, const ::LinearAlgebra::Vector3 &startT, const ::LinearAlgebra::Quaternion &endR, const ::LinearAlgebra::Vector3 &endT, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem )
+ {
+ return InterpolateOrientation_UsingNonRigidNlerp( OrientationMatrix(startR, startT), OrientationMatrix(endR, endT), t, targetMem );
+ }
+
+ template
+ ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingSlerp( const ::LinearAlgebra::Quaternion &startR, const ::LinearAlgebra::Vector3 &startT, const ::LinearAlgebra::Quaternion &endR, const ::LinearAlgebra::Vector3 &endT, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem )
+ {
+ return OrientationMatrix( ::LinearAlgebra::Slerp(startR, endR, t), ::LinearAlgebra::Lerp(::LinearAlgebra::Vector4(startT, (ScalarType)1.0f), ::LinearAlgebra::Vector4(endT, (ScalarType)1.0f), t).xyz, targetMem );
+ }
}
#include "Utilities.h"
diff --git a/Code/OysterMath/Matrix.h b/Code/OysterMath/Matrix.h
index c7b6b9e0..5d129431 100644
--- a/Code/OysterMath/Matrix.h
+++ b/Code/OysterMath/Matrix.h
@@ -163,12 +163,18 @@ namespace LinearAlgebra
Vector4 GetRowVector( unsigned int rowID ) const;
const Vector4 & GetColumnVector( unsigned int colID ) const;
};
+}
+template LinearAlgebra::Matrix2x2 operator * ( const ScalarType &left, const LinearAlgebra::Matrix2x2 &right );
+template LinearAlgebra::Matrix3x3 operator * ( const ScalarType &left, const LinearAlgebra::Matrix3x3 &right );
+template LinearAlgebra::Matrix4x4 operator * ( const ScalarType &left, const LinearAlgebra::Matrix4x4 &right );
///////////////////////////////////////////////////////////////////////////////////
// Body
///////////////////////////////////////////////////////////////////////////////////
+namespace LinearAlgebra
+{
// Matrix2x2 ///////////////////////////////////////
template
@@ -753,4 +759,22 @@ namespace LinearAlgebra
{ return this->v[colID]; }
}
+template
+inline LinearAlgebra::Matrix2x2 operator * ( const ScalarType &left, const LinearAlgebra::Matrix2x2 &right )
+{
+ return right * left;
+}
+
+template
+inline LinearAlgebra::Matrix3x3 operator * ( const ScalarType &left, const LinearAlgebra::Matrix3x3 &right )
+{
+ return right * left;
+}
+
+template
+inline LinearAlgebra::Matrix4x4 operator * ( const ScalarType &left, const LinearAlgebra::Matrix4x4 &right )
+{
+ return right * left;
+}
+
#endif
\ No newline at end of file
diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp
index f44de9fd..bbaccf11 100644
--- a/Code/OysterMath/OysterMath.cpp
+++ b/Code/OysterMath/OysterMath.cpp
@@ -81,20 +81,20 @@ namespace Oyster { namespace Math2D
namespace Oyster { namespace Math3D
{
- Float4 AngularAxis( const Float3x3 &rotationMatrix )
- {
- return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
- }
+ //Float4 AngularAxis( const Float3x3 &rotationMatrix )
+ //{
+ // return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
+ //}
- Float4 AngularAxis( const Float4x4 &rotationMatrix )
- {
- return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
- }
+ //Float4 AngularAxis( const Float4x4 &rotationMatrix )
+ //{
+ // return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
+ //}
- Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix )
- {
- return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
- }
+ //Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix )
+ //{
+ // return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
+ //}
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem )
{
diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h
index 2fe57718..5970face 100644
--- a/Code/OysterMath/OysterMath.h
+++ b/Code/OysterMath/OysterMath.h
@@ -45,59 +45,50 @@ namespace Oyster { namespace Math //! Oyster's native math library
//! Creates a solution matrix for 'outī= 'targetMem' * 'in'.
//! Returns false if there is no explicit solution.
bool SuperpositionMatrix( const Float4x4 &in, const Float4x4 &out, Float4x4 &targetMem );
+
+ /********************************************************************
+ * Linear Interpolation
+ * @return start * (1-t) + end * t
+ ********************************************************************/
+ using ::LinearAlgebra::Lerp;
+
+ /********************************************************************
+ * Normalized Linear Interpolation
+ * @return nullvector if Lerp( start, end, t ) is nullvector.
+ ********************************************************************/
+ using ::LinearAlgebra::Nlerp;
+
+ /********************************************************************
+ * Spherical Linear Interpolation on Quaternions
+ ********************************************************************/
+ using ::LinearAlgebra::Slerp;
} }
inline ::Oyster::Math::Float2 & operator *= ( ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right )
{
- left.x *= right.x;
- left.y *= right.y;
- return left;
+ return left.PiecewiseMultiplicationAdd( right );
}
inline ::Oyster::Math::Float2 operator * ( const ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right )
-{ return ::Oyster::Math::Float2(left) *= right; }
-
-inline ::Oyster::Math::Float2 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float2 &right )
-{ return ::Oyster::Math::Float2(right) *= left; }
+{
+ return left.PiecewiseMultiplication( right );
+}
inline ::Oyster::Math::Float3 & operator *= ( ::Oyster::Math::Float3 &left, const ::Oyster::Math::Float3 &right )
{
- left.x *= right.x;
- left.y *= right.y;
- left.z *= right.z;
- return left;
+ return left.PiecewiseMultiplicationAdd( right );
}
inline ::Oyster::Math::Float3 operator * ( const ::Oyster::Math::Float3 &left, const ::Oyster::Math::Float3 &right )
-{ return ::Oyster::Math::Float3(left) *= right; }
-
-inline ::Oyster::Math::Float3 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float3 &right )
-{ return ::Oyster::Math::Float3(right) *= left; }
+{
+ return left.PiecewiseMultiplication( right );
+}
inline ::Oyster::Math::Float4 & operator *= ( ::Oyster::Math::Float4 &left, const ::Oyster::Math::Float4 &right )
{
- left.x *= right.x;
- left.y *= right.y;
- left.z *= right.z;
- left.w *= right.w;
- return left;
+ return left.PiecewiseMultiplicationAdd( right );
}
-inline ::Oyster::Math::Float4 operator * ( const ::Oyster::Math::Float4 &left, const ::Oyster::Math::Float4 &right )
-{ return ::Oyster::Math::Float4(left) *= right; }
-
-inline ::Oyster::Math::Float4 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float4 &right )
-{ return ::Oyster::Math::Float4(right) *= left; }
-
-inline ::Oyster::Math::Float2x2 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float2x2 &right )
-{ return ::Oyster::Math::Float2x2(right) *= left; }
-
-inline ::Oyster::Math::Float3x3 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float3x3 &right )
-{ return ::Oyster::Math::Float3x3(right) *= left; }
-
-inline ::Oyster::Math::Float4x4 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float4x4 &right )
-{ return ::Oyster::Math::Float4x4(right) *= left; }
-
namespace Oyster { namespace Math2D //! Oyster's native math library specialized for 2D
{
using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace
@@ -150,13 +141,13 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace
//! Extracts the angularAxis from rotationMatrix
- Float4 AngularAxis( const Float3x3 &rotationMatrix );
+ //Float4 AngularAxis( const Float3x3 &rotationMatrix );
- //! Extracts the angularAxis from rotationMatrix
- Float4 AngularAxis( const Float4x4 &rotationMatrix );
+ ////! Extracts the angularAxis from rotationMatrix
+ //Float4 AngularAxis( const Float4x4 &rotationMatrix );
- //! Extracts the angularAxis from orientationMatrix
- Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
+ ////! Extracts the angularAxis from orientationMatrix
+ //Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
//! Sets and returns targetMem to a translationMatrix with position as translation.
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() );
@@ -328,6 +319,11 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
//! Helper inline function that sets and then returns targetMem = transformer * transformee
inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() )
{ return targetMem = transformer * transformee; }
+
+ using ::LinearAlgebra3D::SnapAxisYToNormal_UsingNlerp;
+ using ::LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp;
+ using ::LinearAlgebra3D::InterpolateOrientation_UsingNonRigidNlerp;
+ using ::LinearAlgebra3D::InterpolateOrientation_UsingSlerp;
} }
#endif
\ No newline at end of file
diff --git a/Code/OysterMath/Vector.h b/Code/OysterMath/Vector.h
index 901ea5e4..ea36cfc9 100644
--- a/Code/OysterMath/Vector.h
+++ b/Code/OysterMath/Vector.h
@@ -57,6 +57,12 @@ namespace LinearAlgebra
ScalarType GetMagnitude( ) const;
ScalarType Dot( const Vector2 &vector ) const;
+ //! @return (a.x * b.x, a.y * b.y)
+ Vector2 PiecewiseMultiplication( const Vector2 &vector ) const;
+
+ //! @return a = (a.x * b.x, a.y * b.y)
+ Vector2 & PiecewiseMultiplicationAdd( const Vector2 &vector );
+
Vector2 & Normalize( );
Vector2 GetNormalized( ) const;
};
@@ -112,6 +118,12 @@ namespace LinearAlgebra
ScalarType Dot( const Vector3 &vector ) const;
Vector3 Cross( const Vector3 &vector ) const;
+ //! @return (a.x * b.x, a.y * b.y, a.z * b.z)
+ Vector3 PiecewiseMultiplication( const Vector3 &vector ) const;
+
+ //! @return a = (a.x * b.x, a.y * b.y, a.z * b.z)
+ Vector3 & PiecewiseMultiplicationAdd( const Vector3 &vector );
+
Vector3 & Normalize( );
Vector3 GetNormalized( ) const;
};
@@ -169,14 +181,27 @@ namespace LinearAlgebra
ScalarType GetMagnitude( ) const;
ScalarType Dot( const Vector4 &vector ) const;
+ //! @return (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
+ Vector4 PiecewiseMultiplication( const Vector4 &vector ) const;
+
+ //! @return a = (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
+ Vector4 & PiecewiseMultiplicationAdd( const Vector4 &vector );
+
Vector4 & Normalize( );
Vector4 GetNormalized( ) const;
};
+}
+
+template ::LinearAlgebra::Vector2 operator * ( const ScalarType &left, const ::LinearAlgebra::Vector2 &right );
+template ::LinearAlgebra::Vector3 operator * ( const ScalarType &left, const ::LinearAlgebra::Vector3 &right );
+template ::LinearAlgebra::Vector4 operator * ( const ScalarType &left, const ::LinearAlgebra::Vector4 &right );
///////////////////////////////////////////////////////////////////////////////////
// Body
///////////////////////////////////////////////////////////////////////////////////
+namespace LinearAlgebra
+{
// Vector2 ///////////////////////////////////////
template const Vector2 Vector2::null = Vector2