GameServer - Merged with GameLogic
This commit is contained in:
commit
fa29cd7307
|
@ -1,2 +0,0 @@
|
|||
port 15151
|
||||
clients 200
|
|
@ -1,4 +0,0 @@
|
|||
ServerInit ..\Settings\ServerInit.ini
|
||||
More a
|
||||
more b
|
||||
more c
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,277 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="12.0">
|
||||
<zoom_level>8</zoom_level>
|
||||
<element>
|
||||
<type>com.umlet.element.Package</type>
|
||||
<coordinates>
|
||||
<x>552</x>
|
||||
<y>320</y>
|
||||
<w>584</w>
|
||||
<h>368</h>
|
||||
</coordinates>
|
||||
<panel_attributes>LevelLoader</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>440</x>
|
||||
<y>88</y>
|
||||
<w>128</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>GameLogic
|
||||
<<Erik>></panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>768</x>
|
||||
<y>472</y>
|
||||
<w>136</w>
|
||||
<h>104</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<<<-</panel_attributes>
|
||||
<additional_attributes>120;24;120;88;24;88</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>560</x>
|
||||
<y>544</y>
|
||||
<w>232</w>
|
||||
<h>136</h>
|
||||
</coordinates>
|
||||
<panel_attributes><<Interface>>
|
||||
Parser
|
||||
--
|
||||
Functions:
|
||||
vector<struct> Parse();
|
||||
-
|
||||
Privates:
|
||||
enum headerType;
|
||||
const int FileHeaderSize;
|
||||
const int FileVersion;
|
||||
</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>624</x>
|
||||
<y>208</y>
|
||||
<w>80</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>LevelLoader
|
||||
</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>640</x>
|
||||
<y>208</y>
|
||||
<w>40</w>
|
||||
<h>168</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<.</panel_attributes>
|
||||
<additional_attributes>24;24;24;152</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>384</x>
|
||||
<y>176</y>
|
||||
<w>256</w>
|
||||
<h>56</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=->>>>
|
||||
m1=1..1
|
||||
m2=1..1
|
||||
<Knows about</panel_attributes>
|
||||
<additional_attributes>240;40;24;40</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Package</type>
|
||||
<coordinates>
|
||||
<x>248</x>
|
||||
<y>320</y>
|
||||
<w>248</w>
|
||||
<h>160</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Defines</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>800</x>
|
||||
<y>360</y>
|
||||
<w>208</w>
|
||||
<h>136</h>
|
||||
</coordinates>
|
||||
<panel_attributes><<Interface>>
|
||||
Loader
|
||||
--
|
||||
Functions:
|
||||
wchar* LoadFile(string fileName);
|
||||
Model* LoadModel(string modelName);
|
||||
Model* LoadModel(int modelID);
|
||||
-
|
||||
Privates:</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>328</x>
|
||||
<y>208</y>
|
||||
<w>80</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Defines</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>256</x>
|
||||
<y>360</y>
|
||||
<w>232</w>
|
||||
<h>104</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Defines.h
|
||||
<<Header file>>
|
||||
--
|
||||
Enum ObjectType(static, dynamic, specials);
|
||||
.
|
||||
Struct static;
|
||||
Struct dynamic;
|
||||
Struct specials</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>680</x>
|
||||
<y>176</y>
|
||||
<w>152</w>
|
||||
<h>56</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-
|
||||
m1=1..1
|
||||
m2=1..1
|
||||
Uses></panel_attributes>
|
||||
<additional_attributes>24;40;136;40</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>816</x>
|
||||
<y>192</y>
|
||||
<w>128</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Resource Loader
|
||||
<<Dennis>><<Singleton></panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>928</x>
|
||||
<y>560</y>
|
||||
<w>200</w>
|
||||
<h>120</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Collection of functions
|
||||
<<lots of functions>>
|
||||
--
|
||||
functions for creating the right structs</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>768</x>
|
||||
<y>576</y>
|
||||
<w>176</w>
|
||||
<h>56</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-
|
||||
m1=1..1
|
||||
m2=1..1
|
||||
Uses></panel_attributes>
|
||||
<additional_attributes>24;40;160;40</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Class</type>
|
||||
<coordinates>
|
||||
<x>560</x>
|
||||
<y>360</y>
|
||||
<w>232</w>
|
||||
<h>136</h>
|
||||
</coordinates>
|
||||
<panel_attributes>LevelLoader
|
||||
<<API>><Interface>>
|
||||
--
|
||||
Functions:
|
||||
vector<struct> LoadLevel(String fileName);
|
||||
struct LoadLevelHeader(String fileName);
|
||||
-
|
||||
Privates:
|
||||
|
||||
</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>344</x>
|
||||
<y>208</y>
|
||||
<w>40</w>
|
||||
<h>168</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<.</panel_attributes>
|
||||
<additional_attributes>24;24;24;152</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>840</x>
|
||||
<y>208</y>
|
||||
<w>88</w>
|
||||
<h>168</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=.
|
||||
<Uses</panel_attributes>
|
||||
<additional_attributes>24;24;24;64;72;64;72;152</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>656</x>
|
||||
<y>472</y>
|
||||
<w>40</w>
|
||||
<h>88</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<<<-</panel_attributes>
|
||||
<additional_attributes>24;72;24;24</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<type>com.umlet.element.Relation</type>
|
||||
<coordinates>
|
||||
<x>544</x>
|
||||
<y>64</y>
|
||||
<w>136</w>
|
||||
<h>160</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=lt=->>>>
|
||||
m1=1..1
|
||||
m2=1..1
|
||||
Uses></panel_attributes>
|
||||
<additional_attributes>24;40;80;40;120;40;120;144</additional_attributes>
|
||||
</element>
|
||||
</diagram>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -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<Client::GameState*>(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -3,52 +3,38 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -57,17 +43,30 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage)
|
|||
/********************************************************
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,25 +5,10 @@
|
|||
using namespace GameLogic;
|
||||
using namespace Utility::DynamicMemory;
|
||||
|
||||
struct AttatchmentSocket::PrivateData
|
||||
{
|
||||
PrivateData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~PrivateData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SmartPointer<IAttatchment> 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;
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace GameLogic
|
|||
void RemoveAttatchment();
|
||||
|
||||
private:
|
||||
struct PrivateData;
|
||||
PrivateData *myData;
|
||||
IAttatchment *attatchment;
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -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;
|
||||
|
||||
//switch (realObj->GetType())
|
||||
//{
|
||||
//case OBJECT_TYPE::OBJECT_TYPE_BOX:
|
||||
// PlayerVBox(*player,(*(DynamicObject*) realObj));
|
||||
// break;
|
||||
//case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
|
||||
//
|
||||
// break;
|
||||
//}
|
||||
Player *player = ((Game::PlayerData*)(rigidBodyPlayer->GetCustomTag()))->player;
|
||||
Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed?
|
||||
|
||||
return Physics::ICustomBody::SubscriptMessage_none;
|
||||
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;
|
||||
}
|
||||
|
||||
void PlayerVBox(Player &player, DynamicObject &box)
|
||||
//return Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -9,13 +9,32 @@ DynamicObject::DynamicObject()
|
|||
{
|
||||
|
||||
}
|
||||
DynamicObject::DynamicObject(OBJECT_TYPE type)
|
||||
:Object(type)
|
||||
{
|
||||
|
||||
DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type)
|
||||
:Object(collisionFunc, 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)
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -104,6 +104,7 @@ bool Game::NewFrame()
|
|||
{
|
||||
if(this->players[i]->player) this->players[i]->player->EndFrame();
|
||||
}
|
||||
//gameInstance.onMoveFnc(this->level);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,7 +51,8 @@ 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;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "GameLogicStates.h"
|
||||
#include <OysterMath.h>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace GameLogic
|
|||
OBJECT_TYPE_PLAYER = 0,
|
||||
OBJECT_TYPE_BOX = 1,
|
||||
OBJECT_TYPE_WORLD = 2,
|
||||
OBJECT_TYPE_GENERIC = 4,
|
||||
OBJECT_TYPE_UNKNOWN = -1,
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -5,8 +5,18 @@ 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);
|
||||
}
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
API::Gravity gravityWell;
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
|
||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> dynamicObjects;
|
||||
GameMode gameMode;
|
||||
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
|
||||
StaticObject *levelObj;
|
||||
DynamicObject *testBox;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -7,26 +7,37 @@
|
|||
#define OBJECT_H
|
||||
|
||||
#include "GameLogicStates.h"
|
||||
#include "GameAPI.h"
|
||||
#include <PhysicsAPI.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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);
|
||||
setState.SetCenterPosition(Oyster::Math::Float4(0,15,0,1));
|
||||
setState.SetReach(Oyster::Math::Float4(2,3.5,2,0));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Player::~Player(void)
|
||||
{
|
||||
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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
Weapon::Weapon()
|
||||
{
|
||||
PrivateData()
|
||||
{
|
||||
weaponState = WEAPON_STATE_IDLE;
|
||||
selectedAttatchment = 0;
|
||||
currentNrOfAttatchments = 0;
|
||||
selectedSocketID = 0;
|
||||
attatchmentSockets = 0;
|
||||
}
|
||||
|
||||
~PrivateData()
|
||||
{
|
||||
}
|
||||
|
||||
WEAPON_STATE weaponState;
|
||||
|
||||
DynamicArray<SmartPointer<AttatchmentSocket>> attatchmentSockets;
|
||||
int currentNrOfAttatchments;
|
||||
SmartPointer<IAttatchment> selectedAttatchment;
|
||||
int selectedSocketID;
|
||||
|
||||
}myData;
|
||||
|
||||
Weapon::Weapon()
|
||||
{
|
||||
myData = new PrivateData();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
@ -36,8 +35,11 @@ namespace GameLogic
|
|||
int GetCurrentSocketID();
|
||||
|
||||
private:
|
||||
struct PrivateData;
|
||||
PrivateData *myData;
|
||||
WEAPON_STATE weaponState;
|
||||
Utility::DynamicMemory::DynamicArray<AttatchmentSocket*> attatchmentSockets;
|
||||
int currentNrOfAttatchments;
|
||||
IAttatchment *selectedAttatchment;
|
||||
int selectedSocketID;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<Oyster::Network::NetClient> 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<Utility::DynamicMemory::SmartPointer<GameClient>> 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
|
||||
|
|
|
@ -25,15 +25,28 @@ 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)
|
||||
{
|
||||
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<NetworkClient*, NetworkClient::ClientEventArgs> e)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <WindowShell.h>
|
||||
#include <Utilities.h>
|
||||
#include <WinTimer.h>
|
||||
#include <Thread\OysterThread.h>
|
||||
#include <thread>
|
||||
|
||||
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();
|
||||
}
|
||||
void GameServerAPI::ServerStop()
|
||||
{
|
||||
lobby.Release();
|
||||
server.Shutdown();
|
||||
|
||||
if(GetAsyncKeyState(0x51)) //Q for exit
|
||||
break;
|
||||
}
|
||||
|
||||
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();
|
||||
server.Update();
|
||||
lobby.Update();
|
||||
|
||||
}
|
||||
void GameServerAPI::Terminate()
|
||||
|
||||
GameServerAPI::GameServerInfo GameServerAPI::ServerGetInfo()
|
||||
{
|
||||
lobby.Release();
|
||||
server.Shutdown();
|
||||
|
||||
printf( "Server terminated!" );
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -111,7 +111,7 @@
|
|||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;GameServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -127,7 +127,7 @@
|
|||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName)D.lib;GameServer_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -147,7 +147,7 @@
|
|||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;GameServer_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
@ -167,7 +167,7 @@
|
|||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<DelayLoadDLLs>DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>DanBiasGame_$(PlatformShortName).lib;GameServer_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -108,7 +108,7 @@ std::vector<ICustomBody*>& 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; i<this->leafData.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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
|
||||
std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& 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);
|
||||
|
||||
|
|
|
@ -22,17 +22,12 @@ 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
|
||||
// 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 );
|
||||
|
@ -40,34 +35,37 @@ namespace
|
|||
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() );
|
||||
Float deltaPos = normal.Dot( Float4(deuterState.GetCenterPosition(), 1) - Float4(protoState.GetCenterPosition(), 1) );
|
||||
if( deltaPos < 0.0f )
|
||||
{
|
||||
if( protoG_Magnitude >= deuterG_Magnitude )
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if( deltaPos > 0.0f )
|
||||
{
|
||||
if( protoG_Magnitude <= deuterG_Magnitude )
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
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 );
|
||||
|
||||
//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 );
|
||||
|
@ -80,26 +78,15 @@ namespace
|
|||
deuterState.GetMass(), deuterG_Magnitude );
|
||||
|
||||
Float4 bounce = Average( bounceD, bounceP );
|
||||
//Float4 bounce = bounceD + bounceP;
|
||||
|
||||
// FRICTION
|
||||
// Apply
|
||||
//sumJ += ( 1 / deuterState.GetMass() )*frictionImpulse;
|
||||
// FRICTION END
|
||||
Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() );
|
||||
|
||||
// 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 );
|
||||
protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz );
|
||||
proto->SetState( protoState );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
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<Gravity>();
|
||||
|
@ -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. */ }
|
||||
}
|
||||
|
|
|
@ -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<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const;
|
||||
|
||||
private:
|
||||
::Oyster::Math::Float gravityConstant, updateFrameLength;
|
||||
::Oyster::Math::Float gravityConstant, updateFrameLength, epsilon;
|
||||
EventAction_Destruction destructionAction;
|
||||
::std::vector<API::Gravity> 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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
::Oyster::Math::Quaternion rotation = ::Oyster::Math3D::Rotation(this->angularAxis);
|
||||
::Oyster::Math::Float3 w = this->inertiaTensor.CalculateAngularVelocity( rotation, this->angularMomentum );
|
||||
this->inertiaTensor = tensor;
|
||||
this->angularMomentum = ::Oyster::Physics3D::Formula::AngularMomentum( rotation * tensor, w );
|
||||
}
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -296,7 +296,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker)
|
|||
}
|
||||
OYSTER_THREAD_ERROR OysterThread::Terminate()
|
||||
{
|
||||
if(this->privateData)
|
||||
return this->privateData->Terminate();
|
||||
return OYSTER_THREAD_ERROR_SUCCESS;
|
||||
}
|
||||
OYSTER_THREAD_ERROR OysterThread::Wait()
|
||||
{
|
||||
|
|
|
@ -327,6 +327,10 @@ namespace Utility
|
|||
inline ValueType Min( const ValueType &valueA, const ValueType &valueB )
|
||||
{ return valueA < valueB ? valueA : valueB; }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max )
|
||||
{ return value < min ? Max( value, max ) : min; }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
|
||||
{ return (valueA + valueB) * 0.5f; }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace std
|
|||
// x2
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Matrix2x2<ScalarType> operator * ( const ::LinearAlgebra::Matrix2x2<ScalarType> &left, const ::LinearAlgebra::Matrix2x2<ScalarType> &right )
|
||||
inline ::LinearAlgebra::Matrix2x2<ScalarType> operator * ( const ::LinearAlgebra::Matrix2x2<ScalarType> &left, const ::LinearAlgebra::Matrix2x2<ScalarType> &right )
|
||||
{
|
||||
return ::LinearAlgebra::Matrix2x2<ScalarType>( (left.m11 * right.m11) + (left.m12 * right.m21),
|
||||
(left.m11 * right.m12) + (left.m12 * right.m22),
|
||||
|
@ -44,14 +44,14 @@ template<typename ScalarType>
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Vector2<ScalarType> operator * ( const ::LinearAlgebra::Matrix2x2<ScalarType> &matrix, const ::LinearAlgebra::Vector2<ScalarType> &vector )
|
||||
inline ::LinearAlgebra::Vector2<ScalarType> operator * ( const ::LinearAlgebra::Matrix2x2<ScalarType> &matrix, const ::LinearAlgebra::Vector2<ScalarType> &vector )
|
||||
{
|
||||
return ::LinearAlgebra::Vector2<ScalarType>( (matrix.m11 * vector.x) + (matrix.m12 * vector.y),
|
||||
(matrix.m21 * vector.x) + (matrix.m22 * vector.y) );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Vector2<ScalarType> operator * ( const ::LinearAlgebra::Vector2<ScalarType> &vector, const ::LinearAlgebra::Matrix2x2<ScalarType> &left )
|
||||
inline ::LinearAlgebra::Vector2<ScalarType> operator * ( const ::LinearAlgebra::Vector2<ScalarType> &vector, const ::LinearAlgebra::Matrix2x2<ScalarType> &left )
|
||||
{
|
||||
return ::LinearAlgebra::Vector2<ScalarType>( (vector.x * matrix.m11) + (vector.y * matrix.m21),
|
||||
(vector.x * matrix.m12) + (vector.y * matrix.m22) );
|
||||
|
@ -60,7 +60,7 @@ template<typename ScalarType>
|
|||
// x3
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Matrix3x3<ScalarType> operator * ( const ::LinearAlgebra::Matrix3x3<ScalarType> &left, const ::LinearAlgebra::Matrix3x3<ScalarType> &right )
|
||||
inline ::LinearAlgebra::Matrix3x3<ScalarType> operator * ( const ::LinearAlgebra::Matrix3x3<ScalarType> &left, const ::LinearAlgebra::Matrix3x3<ScalarType> &right )
|
||||
{
|
||||
return ::LinearAlgebra::Matrix3x3<ScalarType>( (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<typename ScalarType>
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Vector3<ScalarType> operator * ( const ::LinearAlgebra::Matrix3x3<ScalarType> &matrix, const ::LinearAlgebra::Vector3<ScalarType> &vector )
|
||||
inline ::LinearAlgebra::Vector3<ScalarType> operator * ( const ::LinearAlgebra::Matrix3x3<ScalarType> &matrix, const ::LinearAlgebra::Vector3<ScalarType> &vector )
|
||||
{
|
||||
return ::LinearAlgebra::Vector3<ScalarType>( (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<typename ScalarType>
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Vector3<ScalarType> operator * ( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Matrix3x3<ScalarType> &left )
|
||||
inline ::LinearAlgebra::Vector3<ScalarType> operator * ( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Matrix3x3<ScalarType> &left )
|
||||
{
|
||||
return ::LinearAlgebra::Vector3<ScalarType>( (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<typename ScalarType>
|
|||
// x4
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Matrix4x4<ScalarType> operator * ( const ::LinearAlgebra::Matrix4x4<ScalarType> &left, const ::LinearAlgebra::Matrix4x4<ScalarType> &right )
|
||||
inline ::LinearAlgebra::Matrix4x4<ScalarType> operator * ( const ::LinearAlgebra::Matrix4x4<ScalarType> &left, const ::LinearAlgebra::Matrix4x4<ScalarType> &right )
|
||||
{
|
||||
return ::LinearAlgebra::Matrix4x4<ScalarType>( (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<typename ScalarType>
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Vector4<ScalarType> operator * ( const ::LinearAlgebra::Matrix4x4<ScalarType> &matrix, const ::LinearAlgebra::Vector4<ScalarType> &vector )
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> operator * ( const ::LinearAlgebra::Matrix4x4<ScalarType> &matrix, const ::LinearAlgebra::Vector4<ScalarType> &vector )
|
||||
{
|
||||
return ::LinearAlgebra::Vector4<ScalarType>( (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<typename ScalarType>
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Vector4<ScalarType> operator * ( const ::LinearAlgebra::Vector4<ScalarType> &vector, const ::LinearAlgebra::Matrix4x4<ScalarType> &matrix )
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> operator * ( const ::LinearAlgebra::Vector4<ScalarType> &vector, const ::LinearAlgebra::Matrix4x4<ScalarType> &matrix )
|
||||
{
|
||||
return ::LinearAlgebra::Vector4<ScalarType>( (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<typename PointType, typename ScalarType>
|
||||
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<typename ScalarType>
|
||||
inline Vector2<ScalarType> Nlerp( const Vector2<ScalarType> &start, const Vector2<ScalarType> &end, const ScalarType &t )
|
||||
{
|
||||
Vector2<ScalarType> 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<typename ScalarType>
|
||||
inline Vector3<ScalarType> Nlerp( const Vector3<ScalarType> &start, const Vector3<ScalarType> &end, const ScalarType &t )
|
||||
{
|
||||
Vector3<ScalarType> 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<typename ScalarType>
|
||||
inline Vector4<ScalarType> Nlerp( const Vector4<ScalarType> &start, const Vector4<ScalarType> &end, const ScalarType &t )
|
||||
{
|
||||
Vector4<ScalarType> 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<typename ScalarType>
|
||||
inline Quaternion<ScalarType> Slerp( const Quaternion<ScalarType> &start, const Quaternion<ScalarType> &end, const ScalarType &t )
|
||||
{
|
||||
ScalarType angle = (ScalarType)::std::acos( Vector4<ScalarType>(start.imaginary, start.real).Dot(Vector4<ScalarType>(end.imaginary, end.real)) );
|
||||
Quaternion<ScalarType> 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<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> AngularAxis( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotationMatrix )
|
||||
{
|
||||
return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
|
||||
}
|
||||
// All Matrix to AngularAxis conversions here is incorrect
|
||||
//template<typename ScalarType>
|
||||
//inline ::LinearAlgebra::Vector4<ScalarType> AngularAxis( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotationMatrix )
|
||||
//{
|
||||
// return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
|
||||
//}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> AngularAxis( const ::LinearAlgebra::Matrix4x4<ScalarType> &rotationMatrix )
|
||||
{
|
||||
return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
|
||||
}
|
||||
//template<typename ScalarType>
|
||||
//inline ::LinearAlgebra::Vector4<ScalarType> AngularAxis( const ::LinearAlgebra::Matrix4x4<ScalarType> &rotationMatrix )
|
||||
//{
|
||||
// return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
|
||||
//}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix )
|
||||
{
|
||||
return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 0) );
|
||||
}
|
||||
//template<typename ScalarType>
|
||||
//inline ::LinearAlgebra::Vector4<ScalarType> ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix )
|
||||
//{
|
||||
// return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 0) );
|
||||
//}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Matrix4x4<ScalarType> & TranslationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &position, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
|
||||
|
@ -668,6 +740,58 @@ namespace LinearAlgebra3D
|
|||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> NormalProjection( const ::LinearAlgebra::Vector4<ScalarType> &vector, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis )
|
||||
{ return normalizedAxis * ( vector.Dot(normalizedAxis) ); }
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Matrix4x4<ScalarType> & SnapAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4<ScalarType> &rotation, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis )
|
||||
{
|
||||
ScalarType projectedMagnitude = rotation.v[0].Dot( normalizedAxis );
|
||||
if( projectedMagnitude == 1 )
|
||||
{ // infinite possible solutions -> roadtrip!
|
||||
::LinearAlgebra::Vector4<ScalarType> 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<typename ScalarType>
|
||||
::LinearAlgebra::Matrix4x4<ScalarType> & InterpolateAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4<ScalarType> &rotation, const ::LinearAlgebra::Vector4<ScalarType> &normalizedAxis, ScalarType t )
|
||||
{
|
||||
::LinearAlgebra::Vector4<ScalarType> interpolated = ::LinearAlgebra::Nlerp( rotation.v[1], normalizedAxis, t );
|
||||
if( interpolated.Dot(interpolated) == 0 )
|
||||
return rotation; // return no change
|
||||
return SnapAxisYToNormal_UsingNlerp( rotation, interpolated );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Matrix4x4<ScalarType> & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Matrix4x4<ScalarType> &start, const ::LinearAlgebra::Matrix4x4<ScalarType> &end, ScalarType t, ::LinearAlgebra::Matrix4x4<ScalarType> &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<typename ScalarType>
|
||||
::LinearAlgebra::Matrix4x4<ScalarType> & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Quaternion<ScalarType> &startR, const ::LinearAlgebra::Vector3<ScalarType> &startT, const ::LinearAlgebra::Quaternion<ScalarType> &endR, const ::LinearAlgebra::Vector3<ScalarType> &endT, ScalarType t, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem )
|
||||
{
|
||||
return InterpolateOrientation_UsingNonRigidNlerp( OrientationMatrix(startR, startT), OrientationMatrix(endR, endT), t, targetMem );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
::LinearAlgebra::Matrix4x4<ScalarType> & InterpolateOrientation_UsingSlerp( const ::LinearAlgebra::Quaternion<ScalarType> &startR, const ::LinearAlgebra::Vector3<ScalarType> &startT, const ::LinearAlgebra::Quaternion<ScalarType> &endR, const ::LinearAlgebra::Vector3<ScalarType> &endT, ScalarType t, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem )
|
||||
{
|
||||
return OrientationMatrix( ::LinearAlgebra::Slerp(startR, endR, t), ::LinearAlgebra::Lerp(::LinearAlgebra::Vector4<ScalarType>(startT, (ScalarType)1.0f), ::LinearAlgebra::Vector4<ScalarType>(endT, (ScalarType)1.0f), t).xyz, targetMem );
|
||||
}
|
||||
}
|
||||
|
||||
#include "Utilities.h"
|
||||
|
|
|
@ -163,12 +163,18 @@ namespace LinearAlgebra
|
|||
Vector4<ScalarType> GetRowVector( unsigned int rowID ) const;
|
||||
const Vector4<ScalarType> & GetColumnVector( unsigned int colID ) const;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename ScalarType> LinearAlgebra::Matrix2x2<ScalarType> operator * ( const ScalarType &left, const LinearAlgebra::Matrix2x2<ScalarType> &right );
|
||||
template<typename ScalarType> LinearAlgebra::Matrix3x3<ScalarType> operator * ( const ScalarType &left, const LinearAlgebra::Matrix3x3<ScalarType> &right );
|
||||
template<typename ScalarType> LinearAlgebra::Matrix4x4<ScalarType> operator * ( const ScalarType &left, const LinearAlgebra::Matrix4x4<ScalarType> &right );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Body
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace LinearAlgebra
|
||||
{
|
||||
// Matrix2x2<ScalarType> ///////////////////////////////////////
|
||||
|
||||
template<typename ScalarType>
|
||||
|
@ -753,4 +759,22 @@ namespace LinearAlgebra
|
|||
{ return this->v[colID]; }
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline LinearAlgebra::Matrix2x2<ScalarType> operator * ( const ScalarType &left, const LinearAlgebra::Matrix2x2<ScalarType> &right )
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline LinearAlgebra::Matrix3x3<ScalarType> operator * ( const ScalarType &left, const LinearAlgebra::Matrix3x3<ScalarType> &right )
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline LinearAlgebra::Matrix4x4<ScalarType> operator * ( const ScalarType &left, const LinearAlgebra::Matrix4x4<ScalarType> &right )
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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
|
|
@ -57,6 +57,12 @@ namespace LinearAlgebra
|
|||
ScalarType GetMagnitude( ) const;
|
||||
ScalarType Dot( const Vector2<ScalarType> &vector ) const;
|
||||
|
||||
//! @return (a.x * b.x, a.y * b.y)
|
||||
Vector2<ScalarType> PiecewiseMultiplication( const Vector2<ScalarType> &vector ) const;
|
||||
|
||||
//! @return a = (a.x * b.x, a.y * b.y)
|
||||
Vector2<ScalarType> & PiecewiseMultiplicationAdd( const Vector2<ScalarType> &vector );
|
||||
|
||||
Vector2<ScalarType> & Normalize( );
|
||||
Vector2<ScalarType> GetNormalized( ) const;
|
||||
};
|
||||
|
@ -112,6 +118,12 @@ namespace LinearAlgebra
|
|||
ScalarType Dot( const Vector3<ScalarType> &vector ) const;
|
||||
Vector3<ScalarType> Cross( const Vector3<ScalarType> &vector ) const;
|
||||
|
||||
//! @return (a.x * b.x, a.y * b.y, a.z * b.z)
|
||||
Vector3<ScalarType> PiecewiseMultiplication( const Vector3<ScalarType> &vector ) const;
|
||||
|
||||
//! @return a = (a.x * b.x, a.y * b.y, a.z * b.z)
|
||||
Vector3<ScalarType> & PiecewiseMultiplicationAdd( const Vector3<ScalarType> &vector );
|
||||
|
||||
Vector3<ScalarType> & Normalize( );
|
||||
Vector3<ScalarType> GetNormalized( ) const;
|
||||
};
|
||||
|
@ -169,14 +181,27 @@ namespace LinearAlgebra
|
|||
ScalarType GetMagnitude( ) const;
|
||||
ScalarType Dot( const Vector4<ScalarType> &vector ) const;
|
||||
|
||||
//! @return (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
|
||||
Vector4<ScalarType> PiecewiseMultiplication( const Vector4<ScalarType> &vector ) const;
|
||||
|
||||
//! @return a = (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)
|
||||
Vector4<ScalarType> & PiecewiseMultiplicationAdd( const Vector4<ScalarType> &vector );
|
||||
|
||||
Vector4<ScalarType> & Normalize( );
|
||||
Vector4<ScalarType> GetNormalized( ) const;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename ScalarType> ::LinearAlgebra::Vector2<ScalarType> operator * ( const ScalarType &left, const ::LinearAlgebra::Vector2<ScalarType> &right );
|
||||
template<typename ScalarType> ::LinearAlgebra::Vector3<ScalarType> operator * ( const ScalarType &left, const ::LinearAlgebra::Vector3<ScalarType> &right );
|
||||
template<typename ScalarType> ::LinearAlgebra::Vector4<ScalarType> operator * ( const ScalarType &left, const ::LinearAlgebra::Vector4<ScalarType> &right );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Body
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace LinearAlgebra
|
||||
{
|
||||
// Vector2<ScalarType> ///////////////////////////////////////
|
||||
|
||||
template<typename ScalarType> const Vector2<ScalarType> Vector2<ScalarType>::null = Vector2<ScalarType>( 0, 0 );
|
||||
|
@ -184,22 +209,22 @@ namespace LinearAlgebra
|
|||
template<typename ScalarType> const Vector2<ScalarType> Vector2<ScalarType>::standard_unit_y = Vector2<ScalarType>( 0, 1 );
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType>::Vector2( ) : x(), y() {}
|
||||
inline Vector2<ScalarType>::Vector2( ) : x(), y() {}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType>::Vector2( const Vector2<ScalarType> &vector )
|
||||
inline Vector2<ScalarType>::Vector2( const Vector2<ScalarType> &vector )
|
||||
{ this->x = vector.x; this->y = vector.y; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType>::Vector2( const ScalarType &_element )
|
||||
inline Vector2<ScalarType>::Vector2( const ScalarType &_element )
|
||||
{ this->x = this->y = _element; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType>::Vector2( const ScalarType _element[2] )
|
||||
inline Vector2<ScalarType>::Vector2( const ScalarType _element[2] )
|
||||
{ this->x = _element[0]; this->y = _element[1]; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType>::Vector2( const ScalarType &_x, const ScalarType &_y )
|
||||
inline Vector2<ScalarType>::Vector2( const ScalarType &_x, const ScalarType &_y )
|
||||
{ this->x = _x; this->y = _y; }
|
||||
|
||||
template<typename ScalarType>
|
||||
|
@ -227,7 +252,7 @@ namespace LinearAlgebra
|
|||
{ return this->element[i]; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType> & Vector2<ScalarType>::operator = ( const Vector2<ScalarType> &vector )
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::operator = ( const Vector2<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] = vector.element[0];
|
||||
this->element[1] = vector.element[1];
|
||||
|
@ -235,7 +260,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType> & Vector2<ScalarType>::operator = ( const ScalarType _element[2] )
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::operator = ( const ScalarType _element[2] )
|
||||
{
|
||||
this->element[0] = _element[0];
|
||||
this->element[1] = _element[1];
|
||||
|
@ -243,7 +268,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType> & Vector2<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
{
|
||||
this->element[0] *= scalar;
|
||||
this->element[1] *= scalar;
|
||||
|
@ -251,7 +276,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType> & Vector2<ScalarType>::operator /= ( const ScalarType &scalar )
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::operator /= ( const ScalarType &scalar )
|
||||
{
|
||||
this->element[0] /= scalar;
|
||||
this->element[1] /= scalar;
|
||||
|
@ -259,7 +284,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType> & Vector2<ScalarType>::operator += ( const Vector2<ScalarType> &vector )
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::operator += ( const Vector2<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] += vector.element[0];
|
||||
this->element[1] += vector.element[1];
|
||||
|
@ -267,7 +292,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector2<ScalarType> & Vector2<ScalarType>::operator -= ( const Vector2<ScalarType> &vector )
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::operator -= ( const Vector2<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] -= vector.element[0];
|
||||
this->element[1] -= vector.element[1];
|
||||
|
@ -295,7 +320,7 @@ namespace LinearAlgebra
|
|||
{ return Vector2<ScalarType>(-this->x, -this->y); }
|
||||
|
||||
template<typename ScalarType>
|
||||
bool Vector2<ScalarType>::operator == ( const Vector2<ScalarType> &vector ) const
|
||||
inline bool Vector2<ScalarType>::operator == ( const Vector2<ScalarType> &vector ) const
|
||||
{
|
||||
if( this->x != vector.x ) return false;
|
||||
if( this->y != vector.y ) return false;
|
||||
|
@ -303,7 +328,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
bool Vector2<ScalarType>::operator != ( const Vector2<ScalarType> &vector ) const
|
||||
inline bool Vector2<ScalarType>::operator != ( const Vector2<ScalarType> &vector ) const
|
||||
{
|
||||
if( this->x != vector.x ) return true;
|
||||
if( this->y != vector.y ) return true;
|
||||
|
@ -319,7 +344,7 @@ namespace LinearAlgebra
|
|||
{ return (ScalarType) ::sqrt( this->Dot(*this) ); }
|
||||
|
||||
template<typename ScalarType>
|
||||
ScalarType Vector2<ScalarType>::Dot( const Vector2<ScalarType> &vector ) const
|
||||
inline ScalarType Vector2<ScalarType>::Dot( const Vector2<ScalarType> &vector ) const
|
||||
{
|
||||
ScalarType value = 0;
|
||||
value += this->element[0] * vector.element[0];
|
||||
|
@ -327,6 +352,20 @@ namespace LinearAlgebra
|
|||
return value;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector2<ScalarType> Vector2<ScalarType>::PiecewiseMultiplication( const Vector2<ScalarType> &vector ) const
|
||||
{
|
||||
return Vector2<ScalarType>( this->x * vector.x, this->y * vector.y );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::PiecewiseMultiplicationAdd( const Vector2<ScalarType> &vector )
|
||||
{
|
||||
this->x *= vector.x;
|
||||
this->y *= vector.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector2<ScalarType> & Vector2<ScalarType>::Normalize( )
|
||||
{ return (*this) /= this->GetLength(); }
|
||||
|
@ -343,26 +382,26 @@ namespace LinearAlgebra
|
|||
template<typename ScalarType> const Vector3<ScalarType> Vector3<ScalarType>::standard_unit_z = Vector3<ScalarType>( 0, 0, 1 );
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType>::Vector3( ) : x(), y(), z() {}
|
||||
inline Vector3<ScalarType>::Vector3( ) : x(), y(), z() {}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType>::Vector3( const Vector3<ScalarType> &vector )
|
||||
inline Vector3<ScalarType>::Vector3( const Vector3<ScalarType> &vector )
|
||||
{ this->x = vector.x; this->y = vector.y; this->z = vector.z; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType>::Vector3( const Vector2<ScalarType> &vector, const ScalarType &_z )
|
||||
inline Vector3<ScalarType>::Vector3( const Vector2<ScalarType> &vector, const ScalarType &_z )
|
||||
{ this->x = vector.x; this->y = vector.y; this->z = _z; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType>::Vector3( const ScalarType &_element )
|
||||
inline Vector3<ScalarType>::Vector3( const ScalarType &_element )
|
||||
{ this->x = this->y = this->z = _element; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType>::Vector3( const ScalarType _element[3] )
|
||||
inline Vector3<ScalarType>::Vector3( const ScalarType _element[3] )
|
||||
{ this->x = _element[0]; this->y = _element[1]; this->z = _element[2]; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType>::Vector3( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z )
|
||||
inline Vector3<ScalarType>::Vector3( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z )
|
||||
{ this->x = _x; this->y = _y; this->z = _z; }
|
||||
|
||||
template<typename ScalarType>
|
||||
|
@ -382,7 +421,7 @@ namespace LinearAlgebra
|
|||
{ return this->element[i]; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> & Vector3<ScalarType>::operator = ( const Vector3<ScalarType> &vector )
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::operator = ( const Vector3<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] = vector.element[0];
|
||||
this->element[1] = vector.element[1];
|
||||
|
@ -391,7 +430,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> & Vector3<ScalarType>::operator = ( const ScalarType element[3] )
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::operator = ( const ScalarType element[3] )
|
||||
{
|
||||
this->element[0] = element[0];
|
||||
this->element[1] = element[1];
|
||||
|
@ -400,7 +439,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> & Vector3<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
{
|
||||
this->element[0] *= scalar;
|
||||
this->element[1] *= scalar;
|
||||
|
@ -409,7 +448,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> & Vector3<ScalarType>::operator /= ( const ScalarType &scalar )
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::operator /= ( const ScalarType &scalar )
|
||||
{
|
||||
this->element[0] /= scalar;
|
||||
this->element[1] /= scalar;
|
||||
|
@ -418,7 +457,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> & Vector3<ScalarType>::operator += ( const Vector3<ScalarType> &vector )
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::operator += ( const Vector3<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] += vector.element[0];
|
||||
this->element[1] += vector.element[1];
|
||||
|
@ -427,7 +466,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> & Vector3<ScalarType>::operator -= ( const Vector3<ScalarType> &vector )
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::operator -= ( const Vector3<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] -= vector.element[0];
|
||||
this->element[1] -= vector.element[1];
|
||||
|
@ -456,7 +495,7 @@ namespace LinearAlgebra
|
|||
{ return Vector3<ScalarType>(-this->x, -this->y, -this->z); }
|
||||
|
||||
template<typename ScalarType>
|
||||
bool Vector3<ScalarType>::operator == ( const Vector3<ScalarType> &vector ) const
|
||||
inline bool Vector3<ScalarType>::operator == ( const Vector3<ScalarType> &vector ) const
|
||||
{
|
||||
if( this->x != vector.x ) return false;
|
||||
if( this->y != vector.y ) return false;
|
||||
|
@ -465,7 +504,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
bool Vector3<ScalarType>::operator != ( const Vector3<ScalarType> &vector ) const
|
||||
inline bool Vector3<ScalarType>::operator != ( const Vector3<ScalarType> &vector ) const
|
||||
{
|
||||
if( this->x != vector.x ) return true;
|
||||
if( this->y != vector.y ) return true;
|
||||
|
@ -482,7 +521,7 @@ namespace LinearAlgebra
|
|||
{ return (ScalarType) ::sqrt( this->Dot(*this) ); }
|
||||
|
||||
template<typename ScalarType>
|
||||
ScalarType Vector3<ScalarType>::Dot( const Vector3<ScalarType> &vector ) const
|
||||
inline ScalarType Vector3<ScalarType>::Dot( const Vector3<ScalarType> &vector ) const
|
||||
{
|
||||
ScalarType value = 0;
|
||||
value += this->element[0] * vector.element[0];
|
||||
|
@ -492,13 +531,28 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector3<ScalarType> Vector3<ScalarType>::Cross( const Vector3<ScalarType> &vector ) const
|
||||
inline Vector3<ScalarType> Vector3<ScalarType>::Cross( const Vector3<ScalarType> &vector ) const
|
||||
{
|
||||
return Vector3<ScalarType>( (this->y*vector.z) - (this->z*vector.y),
|
||||
(this->z*vector.x) - (this->x*vector.z),
|
||||
(this->x*vector.y) - (this->y*vector.x) );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector3<ScalarType> Vector3<ScalarType>::PiecewiseMultiplication( const Vector3<ScalarType> &vector ) const
|
||||
{
|
||||
return Vector3<ScalarType>( this->x * vector.x, this->y * vector.y, this->z * vector.z );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::PiecewiseMultiplicationAdd( const Vector3<ScalarType> &vector )
|
||||
{
|
||||
this->x *= vector.x;
|
||||
this->y *= vector.y;
|
||||
this->z *= vector.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector3<ScalarType> & Vector3<ScalarType>::Normalize( )
|
||||
{ return (*this) /= this->GetLength(); }
|
||||
|
@ -516,30 +570,30 @@ namespace LinearAlgebra
|
|||
template<typename ScalarType> const Vector4<ScalarType> Vector4<ScalarType>::standard_unit_w = Vector4<ScalarType>( 0, 0, 0, 1 );
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( ) : x(), y(), z(), w() {}
|
||||
inline Vector4<ScalarType>::Vector4( ) : x(), y(), z(), w() {}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( const Vector4<ScalarType> &vector )
|
||||
inline Vector4<ScalarType>::Vector4( const Vector4<ScalarType> &vector )
|
||||
{ this->x = vector.x; this->y = vector.y; this->z = vector.z; this->w = vector.w; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( const Vector3<ScalarType> &vector, const ScalarType &_w )
|
||||
inline Vector4<ScalarType>::Vector4( const Vector3<ScalarType> &vector, const ScalarType &_w )
|
||||
{ this->x = vector.x; this->y = vector.y; this->z = vector.z; this->w = _w; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( const Vector2<ScalarType> &vector, const ScalarType &_z, const ScalarType &_w )
|
||||
inline Vector4<ScalarType>::Vector4( const Vector2<ScalarType> &vector, const ScalarType &_z, const ScalarType &_w )
|
||||
{ this->x = vector.x; this->y = vector.y; this->z = _z; this->w = _w; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( const ScalarType &_element )
|
||||
inline Vector4<ScalarType>::Vector4( const ScalarType &_element )
|
||||
{ this->x = this->y = this->z = this->w = _element; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( const ScalarType _element[4] )
|
||||
inline Vector4<ScalarType>::Vector4( const ScalarType _element[4] )
|
||||
{ this->x = _element[0]; this->y = _element[1]; this->z = _element[2]; this->w = _element[3]; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType>::Vector4( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z, const ScalarType &_w )
|
||||
inline Vector4<ScalarType>::Vector4( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z, const ScalarType &_w )
|
||||
{ this->x = _x; this->y = _y; this->z = _z; this->w = _w; }
|
||||
|
||||
template<typename ScalarType>
|
||||
|
@ -559,7 +613,7 @@ namespace LinearAlgebra
|
|||
{ return this->element[i]; }
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType> & Vector4<ScalarType>::operator = ( const Vector4<ScalarType> &vector )
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::operator = ( const Vector4<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] = vector.element[0];
|
||||
this->element[1] = vector.element[1];
|
||||
|
@ -569,7 +623,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType> & Vector4<ScalarType>::operator = ( const ScalarType element[4] )
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::operator = ( const ScalarType element[4] )
|
||||
{
|
||||
this->element[0] = element[0];
|
||||
this->element[1] = element[1];
|
||||
|
@ -579,7 +633,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType> & Vector4<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::operator *= ( const ScalarType &scalar )
|
||||
{
|
||||
this->element[0] *= scalar;
|
||||
this->element[1] *= scalar;
|
||||
|
@ -589,7 +643,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType> & Vector4<ScalarType>::operator /= ( const ScalarType &scalar )
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::operator /= ( const ScalarType &scalar )
|
||||
{
|
||||
this->element[0] /= scalar;
|
||||
this->element[1] /= scalar;
|
||||
|
@ -599,7 +653,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType> & Vector4<ScalarType>::operator += ( const Vector4<ScalarType> &vector )
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::operator += ( const Vector4<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] += vector.element[0];
|
||||
this->element[1] += vector.element[1];
|
||||
|
@ -609,7 +663,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
Vector4<ScalarType> & Vector4<ScalarType>::operator -= ( const Vector4<ScalarType> &vector )
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::operator -= ( const Vector4<ScalarType> &vector )
|
||||
{
|
||||
this->element[0] -= vector.element[0];
|
||||
this->element[1] -= vector.element[1];
|
||||
|
@ -639,7 +693,7 @@ namespace LinearAlgebra
|
|||
{ return Vector4<ScalarType>(-this->x, -this->y, -this->z, -this->w); }
|
||||
|
||||
template<typename ScalarType>
|
||||
bool Vector4<ScalarType>::operator == ( const Vector4<ScalarType> &vector ) const
|
||||
inline bool Vector4<ScalarType>::operator == ( const Vector4<ScalarType> &vector ) const
|
||||
{
|
||||
if( this->x != vector.x ) return false;
|
||||
if( this->y != vector.y ) return false;
|
||||
|
@ -649,7 +703,7 @@ namespace LinearAlgebra
|
|||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
bool Vector4<ScalarType>::operator != ( const Vector4<ScalarType> &vector ) const
|
||||
inline bool Vector4<ScalarType>::operator != ( const Vector4<ScalarType> &vector ) const
|
||||
{
|
||||
if( this->x != vector.x ) return true;
|
||||
if( this->y != vector.y ) return true;
|
||||
|
@ -667,7 +721,7 @@ namespace LinearAlgebra
|
|||
{ return (ScalarType) ::sqrt( this->Dot(*this) ); }
|
||||
|
||||
template<typename ScalarType>
|
||||
ScalarType Vector4<ScalarType>::Dot( const Vector4<ScalarType> &vector ) const
|
||||
inline ScalarType Vector4<ScalarType>::Dot( const Vector4<ScalarType> &vector ) const
|
||||
{
|
||||
ScalarType value = 0;
|
||||
value += this->element[0] * vector.element[0];
|
||||
|
@ -677,6 +731,22 @@ namespace LinearAlgebra
|
|||
return value;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector4<ScalarType> Vector4<ScalarType>::PiecewiseMultiplication( const Vector4<ScalarType> &vector ) const
|
||||
{
|
||||
return Vector4<ScalarType>( this->x * vector.x, this->y * vector.y, this->z * vector.z, this->w * vector.w );
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::PiecewiseMultiplicationAdd( const Vector4<ScalarType> &vector )
|
||||
{
|
||||
this->x *= vector.x;
|
||||
this->y *= vector.y;
|
||||
this->z *= vector.z;
|
||||
this->w *= vector.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline Vector4<ScalarType> & Vector4<ScalarType>::Normalize( )
|
||||
{ return (*this) /= this->GetLength(); }
|
||||
|
@ -686,4 +756,22 @@ namespace LinearAlgebra
|
|||
{ return Vector4<ScalarType>(*this).Normalize(); }
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector2<ScalarType> operator * ( const ScalarType &left, const ::LinearAlgebra::Vector2<ScalarType> &right )
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector3<ScalarType> operator * ( const ScalarType &left, const ::LinearAlgebra::Vector3<ScalarType> &right )
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
template<typename ScalarType>
|
||||
inline ::LinearAlgebra::Vector4<ScalarType> operator * ( const ScalarType &left, const ::LinearAlgebra::Vector4<ScalarType> &right )
|
||||
{
|
||||
return right * left;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -242,3 +242,8 @@ bool Frustrum::Contains( const ICollideable &target ) const
|
|||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
::Oyster::Math::Float3 Frustrum::ExtractForwad()
|
||||
{
|
||||
return this->bottomPlane.normal.xyz;
|
||||
}
|
|
@ -41,6 +41,8 @@ namespace Oyster { namespace Collision3D
|
|||
bool Intersects( const ICollideable &target ) const;
|
||||
bool Intersects( const ICollideable &target, Oyster::Math::Float4 &worldPointOfContact ) const;
|
||||
bool Contains( const ICollideable &target ) const;
|
||||
|
||||
::Oyster::Math::Float3 ExtractForwad();
|
||||
};
|
||||
|
||||
// INLINE IMPLEMENTATIONS ///////////////////////////////////////
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/********************************************************************
|
||||
* Created by Dan Andersson 2014
|
||||
********************************************************************/
|
||||
|
||||
#include "Inertia.h"
|
||||
|
||||
using namespace ::Oyster::Math3D;
|
||||
using namespace ::Oyster::Physics3D;
|
||||
|
||||
MomentOfInertia::MomentOfInertia()
|
||||
{
|
||||
this->rotation = Quaternion::identity;
|
||||
this->magnitude = Float3( 1.0f );
|
||||
}
|
||||
|
||||
MomentOfInertia::MomentOfInertia( const Quaternion &r, const Float3 &m )
|
||||
{
|
||||
this->rotation = r;
|
||||
this->magnitude = m;
|
||||
}
|
||||
|
||||
MomentOfInertia & MomentOfInertia::operator = ( const MomentOfInertia &i )
|
||||
{
|
||||
this->rotation = i.rotation;
|
||||
this->magnitude = i.magnitude;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Float3 MomentOfInertia::CalculateAngularVelocity( const Quaternion &externR, const Float3 &h ) const
|
||||
{
|
||||
return this->CalculateAngularVelocity( externR, h, Float3() );
|
||||
}
|
||||
|
||||
Float3 & MomentOfInertia::CalculateAngularVelocity( const Quaternion &externR, const Float3 &h, Float3 &targetMem ) const
|
||||
{ // w = (R * I_R) * I_M^-1 * (R * I_R)^-1 * h
|
||||
Float4x4 rotation = RotationMatrix( externR ) * RotationMatrix( this->rotation );
|
||||
Float4 w = rotation.GetInverse() * Float4( h, 0.0f );
|
||||
return targetMem = rotation * w.PiecewiseMultiplicationAdd( Float4(1.0f / this->magnitude.x, 1.0f / this->magnitude.y, 1.0f / this->magnitude.z, 0.0f) );
|
||||
}
|
||||
|
||||
Float3 MomentOfInertia::CalculateAngularMomentum( const Quaternion &externR, const Float3 &w ) const
|
||||
{
|
||||
return this->CalculateAngularMomentum( externR, w, Float3() );
|
||||
}
|
||||
|
||||
Float3 & MomentOfInertia::CalculateAngularMomentum( const Quaternion &externR, const Float3 &w, Float3 &targetMem ) const
|
||||
{ // h = (R * I_R) * I_M * (R * I_R)^-1 * w
|
||||
Float4x4 rotation = RotationMatrix( externR ) * RotationMatrix( this->rotation );
|
||||
Float4 h = rotation.GetInverse() * Float4( w, 0.0f );
|
||||
return targetMem = rotation * h.PiecewiseMultiplicationAdd( Float4(this->magnitude.x, this->magnitude.y, this->magnitude.z, 0.0f) );
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/********************************************************************
|
||||
* Created by Dan Andersson & Robin Engman 2014
|
||||
********************************************************************/
|
||||
|
||||
#ifndef OYSTER_PHYSICS_3D_INERTIA_H
|
||||
#define OYSTER_PHYSICS_3D_INERTIA_H
|
||||
|
||||
#include "OysterMath.h"
|
||||
|
||||
namespace Oyster { namespace Physics3D
|
||||
{
|
||||
struct MomentOfInertia
|
||||
{
|
||||
::Oyster::Math::Quaternion rotation;
|
||||
::Oyster::Math::Float3 magnitude;
|
||||
|
||||
MomentOfInertia();
|
||||
MomentOfInertia( const ::Oyster::Math::Quaternion &r, const ::Oyster::Math::Float3 &m );
|
||||
|
||||
MomentOfInertia & operator = ( const MomentOfInertia &i );
|
||||
|
||||
::Oyster::Math::Float3 CalculateAngularVelocity( const ::Oyster::Math::Quaternion &externR, const ::Oyster::Math::Float3 &angularMomentum ) const;
|
||||
::Oyster::Math::Float3 & CalculateAngularVelocity( const ::Oyster::Math::Quaternion &externR, const ::Oyster::Math::Float3 &angularMomentum, ::Oyster::Math::Float3 &targetMem ) const;
|
||||
|
||||
::Oyster::Math::Float3 CalculateAngularMomentum( const ::Oyster::Math::Quaternion &externR, const ::Oyster::Math::Float3 &angularVelocity ) const;
|
||||
::Oyster::Math::Float3 & CalculateAngularMomentum( const ::Oyster::Math::Quaternion &externR, const ::Oyster::Math::Float3 &angularVelocity, ::Oyster::Math::Float3 &targetMem ) const;
|
||||
|
||||
static ::Oyster::Math::Float CalculateSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius );
|
||||
static ::Oyster::Math::Float CalculateHollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius );
|
||||
static ::Oyster::Math::Float CalculateCuboidX( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float depth );
|
||||
static ::Oyster::Math::Float CalculateCuboidY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth );
|
||||
static ::Oyster::Math::Float CalculateCuboidZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float height );
|
||||
static ::Oyster::Math::Float CalculateRodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length );
|
||||
static ::Oyster::Math::Float CalculateCylinderXY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius );
|
||||
static ::Oyster::Math::Float CalculateCylinderZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius );
|
||||
|
||||
static MomentOfInertia Sphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius );
|
||||
static MomentOfInertia HollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius );
|
||||
static MomentOfInertia Cuboid( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth );
|
||||
static MomentOfInertia RodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length );
|
||||
static MomentOfInertia Cylinder( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius );
|
||||
};
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return (2.0f / 5.0f) * mass * radius * radius;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateHollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return (2.0f / 3.0f) * mass * radius * radius;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateCuboidX( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float depth )
|
||||
{
|
||||
return (1.0f / 12.0f) * mass * (height * height + depth * depth);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateCuboidY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth )
|
||||
{
|
||||
return (1.0f / 12.0f) * mass * (width * width + depth * depth);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateCuboidZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float height )
|
||||
{
|
||||
return (1.0f / 12.0f) * mass * (height * height + width * width);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateRodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length )
|
||||
{
|
||||
return (1.0f / 12.0f) * mass * length * length;
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateCylinderXY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return (1.0f / 12.0f) * mass * (3.0f * radius * radius + height * height);
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float MomentOfInertia::CalculateCylinderZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return 0.5f * mass * radius * radius;
|
||||
}
|
||||
|
||||
inline MomentOfInertia MomentOfInertia::Sphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return MomentOfInertia( ::Oyster::Math::Quaternion::identity,
|
||||
::Oyster::Math::Float3(MomentOfInertia::CalculateSphere(mass, radius)) );
|
||||
}
|
||||
|
||||
inline MomentOfInertia MomentOfInertia::HollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
return MomentOfInertia( ::Oyster::Math::Quaternion::identity,
|
||||
::Oyster::Math::Float3(MomentOfInertia::CalculateHollowSphere(mass, radius)) );
|
||||
}
|
||||
|
||||
inline MomentOfInertia MomentOfInertia::Cuboid( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth )
|
||||
{
|
||||
return MomentOfInertia( ::Oyster::Math::Quaternion::identity,
|
||||
::Oyster::Math::Float3(MomentOfInertia::CalculateCuboidX(mass, height, depth),
|
||||
MomentOfInertia::CalculateCuboidY(mass, width, depth),
|
||||
MomentOfInertia::CalculateCuboidZ(mass, height, width)) );
|
||||
}
|
||||
|
||||
inline MomentOfInertia MomentOfInertia::RodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length )
|
||||
{
|
||||
return MomentOfInertia( ::Oyster::Math::Quaternion::identity,
|
||||
::Oyster::Math::Float3(MomentOfInertia::CalculateRodCenter(mass , length)) );
|
||||
}
|
||||
|
||||
inline MomentOfInertia MomentOfInertia::Cylinder( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius )
|
||||
{
|
||||
::Oyster::Math::Float cylinderXY = MomentOfInertia::CalculateCylinderXY( mass , height, radius );
|
||||
return MomentOfInertia( ::Oyster::Math::Quaternion::identity,
|
||||
::Oyster::Math::Float3(cylinderXY, cylinderXY,
|
||||
MomentOfInertia::CalculateCylinderZ(mass, radius)) );
|
||||
}
|
||||
} }
|
||||
|
||||
#endif
|
|
@ -155,6 +155,7 @@
|
|||
<ClInclude Include="FluidDrag.h" />
|
||||
<ClInclude Include="Frustrum.h" />
|
||||
<ClInclude Include="ICollideable.h" />
|
||||
<ClInclude Include="Inertia.h" />
|
||||
<ClInclude Include="Line.h" />
|
||||
<ClInclude Include="OysterCollision3D.h" />
|
||||
<ClInclude Include="OysterPhysics3D.h" />
|
||||
|
@ -174,6 +175,7 @@
|
|||
<ClCompile Include="FluidDrag.cpp" />
|
||||
<ClCompile Include="Frustrum.cpp" />
|
||||
<ClCompile Include="ICollideable.cpp" />
|
||||
<ClCompile Include="Inertia.cpp" />
|
||||
<ClCompile Include="Line.cpp" />
|
||||
<ClCompile Include="OysterCollision3D.cpp" />
|
||||
<ClCompile Include="Particle.cpp" />
|
||||
|
|
|
@ -78,6 +78,9 @@
|
|||
<ClInclude Include="RigidBody_Inline.h">
|
||||
<Filter>Header Files\Physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inertia.h">
|
||||
<Filter>Header Files\Physics</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Box.cpp">
|
||||
|
@ -125,5 +128,8 @@
|
|||
<ClCompile Include="Particle.cpp">
|
||||
<Filter>Source Files\Physics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Inertia.cpp">
|
||||
<Filter>Source Files\Physics</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -23,7 +23,7 @@ RigidBody::RigidBody( )
|
|||
this->frictionCoeff_Static = 0.5f;
|
||||
this->frictionCoeff_Kinetic = 1.0f;
|
||||
this->mass = 10;
|
||||
this->momentOfInertiaTensor = Float4x4::identity;
|
||||
this->momentOfInertiaTensor = MomentOfInertia();
|
||||
this->rotation = Quaternion::identity;
|
||||
}
|
||||
|
||||
|
@ -53,15 +53,16 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength )
|
|||
this->centerPos += ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear );
|
||||
|
||||
// updating the angular
|
||||
Float4x4 rotationMatrix; ::Oyster::Math3D::RotationMatrix( this->rotation, rotationMatrix );
|
||||
//Float4x4 rotationMatrix; ::Oyster::Math3D::RotationMatrix( this->rotation, rotationMatrix );
|
||||
// Important! The member data is all world data except the Inertia tensor. Thus a new InertiaTensor needs to be created to be compatible with the rest of the world data.
|
||||
Float4x4 wMomentOfInertiaTensor = TransformMatrix( rotationMatrix, this->momentOfInertiaTensor ); // RI
|
||||
//Float4x4 wMomentOfInertiaTensor = TransformMatrix( rotationMatrix, this->momentOfInertiaTensor ); // RI
|
||||
|
||||
// dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H
|
||||
|
||||
//! HACK: @todo Rotation temporary disabled
|
||||
//this->axis += Radian( Formula::AngularVelocity(wMomentOfInertiaTensor.GetInverse(), AverageWithDelta(this->momentum_Angular, this->impulse_Angular)) );
|
||||
//this->rotation = Rotation( this->axis );
|
||||
this->axis += this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, AverageWithDelta(this->momentum_Angular, this->impulse_Angular) );
|
||||
this->rotation = Rotation( this->axis );
|
||||
|
||||
// update momentums and clear impulse_Linear and impulse_Angular
|
||||
this->momentum_Linear += this->impulse_Linear;
|
||||
|
@ -71,31 +72,32 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength )
|
|||
this->impulse_Angular = Float4::null;
|
||||
}
|
||||
|
||||
void RigidBody::Predict_LeapFrog( Float4 &outDeltaPos, Float4 &outDeltaAxis, const Float4 &actingLinearImpulse, const Float4 &actingAngularImpulse, Float deltaTime )
|
||||
void RigidBody::Predict_LeapFrog( Float3 &outDeltaPos, Float3 &outDeltaAxis, const Float3 &actingLinearImpulse, const Float3 &actingAngularImpulse, Float deltaTime )
|
||||
{
|
||||
// updating the linear
|
||||
// ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G
|
||||
outDeltaPos = ( deltaTime / this->mass ) * AverageWithDelta( this->momentum_Linear, actingLinearImpulse );
|
||||
|
||||
// updating the angular
|
||||
Float4x4 rotationMatrix; ::Oyster::Math3D::RotationMatrix( this->rotation, rotationMatrix );
|
||||
Float4x4 wMomentOfInertiaTensor = TransformMatrix( rotationMatrix, this->momentOfInertiaTensor ); // RI
|
||||
//Float4x4 rotationMatrix; ::Oyster::Math3D::RotationMatrix( this->rotation, rotationMatrix );
|
||||
//Float4x4 wMomentOfInertiaTensor = TransformMatrix( rotationMatrix, this->momentOfInertiaTensor ); // RI
|
||||
|
||||
// dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H
|
||||
outDeltaAxis = Formula::AngularVelocity( wMomentOfInertiaTensor.GetInverse(), AverageWithDelta(this->momentum_Angular, actingAngularImpulse) );
|
||||
//outDeltaAxis = Formula::AngularVelocity( wMomentOfInertiaTensor.GetInverse(), AverageWithDelta(this->momentum_Angular, actingAngularImpulse) );
|
||||
outDeltaAxis = this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, AverageWithDelta(this->momentum_Angular, this->impulse_Angular) );
|
||||
}
|
||||
|
||||
void RigidBody::Move( const Float4 &deltaPos, const Float4 &deltaAxis )
|
||||
void RigidBody::Move( const Float3 &deltaPos, const Float3 &deltaAxis )
|
||||
{
|
||||
this->centerPos += deltaPos;
|
||||
this->axis += deltaAxis;
|
||||
this->rotation = Rotation( this->axis );
|
||||
}
|
||||
|
||||
void RigidBody::ApplyImpulse( const Float4 &worldJ, const Float4 &atWorldPos )
|
||||
void RigidBody::ApplyImpulse( const Float3 &worldJ, const Float3 &atWorldPos )
|
||||
{ // by Dan Andersson
|
||||
Float4 worldOffset = atWorldPos - this->centerPos;
|
||||
if( worldOffset != Float4::null )
|
||||
Float3 worldOffset = atWorldPos - this->centerPos;
|
||||
if( worldOffset != Float3::null )
|
||||
{
|
||||
this->impulse_Linear += VectorProjection( worldJ, atWorldPos );
|
||||
this->impulse_Angular += Formula::ImpulseTorque( worldJ, atWorldPos );
|
||||
|
@ -106,7 +108,7 @@ void RigidBody::ApplyImpulse( const Float4 &worldJ, const Float4 &atWorldPos )
|
|||
}
|
||||
}
|
||||
|
||||
const Float4x4 & RigidBody::GetMomentOfInertia() const
|
||||
const MomentOfInertia & RigidBody::GetMomentOfInertia() const
|
||||
{ // by Dan Andersson
|
||||
return this->momentOfInertiaTensor;
|
||||
}
|
||||
|
@ -116,7 +118,7 @@ Float RigidBody::GetMass() const
|
|||
return this->mass;
|
||||
}
|
||||
|
||||
const Quaternion & RigidBody::GetRotation() const
|
||||
const Quaternion & RigidBody::GetRotationQuaternion() const
|
||||
{ // by Dan Andersson
|
||||
return this->rotation;
|
||||
}
|
||||
|
@ -136,46 +138,38 @@ Float4x4 RigidBody::GetView() const
|
|||
return ViewMatrix( this->rotation, this->centerPos );
|
||||
}
|
||||
|
||||
Float4 RigidBody::GetVelocity_Linear() const
|
||||
Float3 RigidBody::GetVelocity_Linear() const
|
||||
{ // by Dan Andersson
|
||||
return Formula::LinearVelocity( this->mass, this->momentum_Linear );
|
||||
}
|
||||
|
||||
Float4 RigidBody::GetVelocity_Angular() const
|
||||
Float3 RigidBody::GetVelocity_Angular() const
|
||||
{ // by Dan Andersson
|
||||
return Formula::AngularVelocity( this->momentOfInertiaTensor.GetInverse(), this->momentum_Angular );
|
||||
return this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, this->momentum_Angular );
|
||||
}
|
||||
|
||||
Float4 RigidBody::GetLinearMomentum( const Float4 &atWorldPos ) const
|
||||
Float3 RigidBody::GetLinearMomentum( const Float3 &atWorldPos ) const
|
||||
{ // by Dan Andersson
|
||||
return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, atWorldPos - this->centerPos );
|
||||
}
|
||||
|
||||
void RigidBody::SetMomentOfInertia_KeepVelocity( const Float4x4 &localTensorI )
|
||||
void RigidBody::SetMomentOfInertia_KeepVelocity( const MomentOfInertia &localTensorI )
|
||||
{ // by Dan Andersson
|
||||
if( localTensorI.GetDeterminant() != 0.0f )
|
||||
{ // insanity check! MomentOfInertiaTensor must be invertable
|
||||
Float4x4 rotationMatrix; RotationMatrix( this->rotation, rotationMatrix );
|
||||
|
||||
Float4 w = Formula::AngularVelocity( (rotationMatrix * this->momentOfInertiaTensor).GetInverse(), this->momentum_Angular );
|
||||
Float3 w = this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, this->momentum_Angular );
|
||||
this->momentOfInertiaTensor = localTensorI;
|
||||
this->momentum_Angular = Formula::AngularMomentum( rotationMatrix * localTensorI, w );
|
||||
}
|
||||
this->momentum_Angular = this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, w );
|
||||
}
|
||||
|
||||
void RigidBody::SetMomentOfInertia_KeepMomentum( const Float4x4 &localTensorI )
|
||||
void RigidBody::SetMomentOfInertia_KeepMomentum( const MomentOfInertia &localTensorI )
|
||||
{ // by Dan Andersson
|
||||
if( localTensorI.GetDeterminant() != 0.0f )
|
||||
{ // insanity check! MomentOfInertiaTensor must be invertable
|
||||
this->momentOfInertiaTensor = localTensorI;
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBody::SetMass_KeepVelocity( const Float &m )
|
||||
{ // by Dan Andersson
|
||||
if( m != 0.0f )
|
||||
{ // insanity check! Mass must be invertable
|
||||
Float4 v = Formula::LinearVelocity( this->mass, this->momentum_Linear );
|
||||
Float3 v = Formula::LinearVelocity( this->mass, this->momentum_Linear );
|
||||
this->mass = m;
|
||||
this->momentum_Linear = Formula::LinearMomentum( this->mass, v );
|
||||
}
|
||||
|
@ -189,46 +183,46 @@ void RigidBody::SetMass_KeepMomentum( const Float &m )
|
|||
}
|
||||
}
|
||||
|
||||
void RigidBody::SetOrientation( const Float4x4 &o )
|
||||
{ // by Dan Andersson
|
||||
this->axis = ExtractAngularAxis( o );
|
||||
this->rotation = Rotation( this->axis );
|
||||
this->centerPos = o.v[3].xyz;
|
||||
}
|
||||
//void RigidBody::SetOrientation( const Float4x4 &o )
|
||||
//{ // by Dan Andersson
|
||||
// this->axis = ExtractAngularAxis( o );
|
||||
// this->rotation = Rotation( this->axis );
|
||||
// this->centerPos = o.v[3].xyz;
|
||||
//}
|
||||
//
|
||||
//void RigidBody::SetRotation( const Float4x4 &r )
|
||||
//{ // by Dan Andersson
|
||||
// this->axis = ExtractAngularAxis( r );
|
||||
// this->rotation = Rotation( this->axis );
|
||||
//}
|
||||
|
||||
void RigidBody::SetRotation( const Float4x4 &r )
|
||||
void RigidBody::SetMomentum_Linear( const Float3 &worldG, const Float3 &atWorldPos )
|
||||
{ // by Dan Andersson
|
||||
this->axis = ExtractAngularAxis( r );
|
||||
this->rotation = Rotation( this->axis );
|
||||
}
|
||||
|
||||
void RigidBody::SetMomentum_Linear( const Float4 &worldG, const Float4 &atWorldPos )
|
||||
{ // by Dan Andersson
|
||||
Float4 worldOffset = atWorldPos - this->centerPos;
|
||||
Float3 worldOffset = atWorldPos - this->centerPos;
|
||||
this->momentum_Linear = VectorProjection( worldG, worldOffset );
|
||||
this->momentum_Angular = Formula::AngularMomentum( worldG, worldOffset );
|
||||
}
|
||||
|
||||
void RigidBody::SetVelocity_Linear( const Float4 &worldV )
|
||||
void RigidBody::SetVelocity_Linear( const Float3 &worldV )
|
||||
{ // by Dan Andersson
|
||||
this->momentum_Linear = Formula::LinearMomentum( this->mass, worldV );
|
||||
}
|
||||
|
||||
void RigidBody::SetVelocity_Linear( const Float4 &worldV, const Float4 &atWorldPos )
|
||||
void RigidBody::SetVelocity_Linear( const Float3 &worldV, const Float3 &atWorldPos )
|
||||
{ // by Dan Andersson
|
||||
Float4 worldOffset = atWorldPos - this->centerPos;
|
||||
Float3 worldOffset = atWorldPos - this->centerPos;
|
||||
this->momentum_Linear = Formula::LinearMomentum( this->mass, VectorProjection(worldV, worldOffset) );
|
||||
this->momentum_Angular = Formula::AngularMomentum( RotationMatrix(this->rotation) * this->momentOfInertiaTensor, Formula::AngularVelocity(worldV, worldOffset) );
|
||||
this->momentum_Angular = this->momentOfInertiaTensor.CalculateAngularMomentum( this->rotation, Formula::AngularVelocity(worldV, worldOffset) );
|
||||
}
|
||||
|
||||
void RigidBody::SetVelocity_Angular( const Float4 &worldW )
|
||||
void RigidBody::SetVelocity_Angular( const Float3 &worldW )
|
||||
{ // by Dan Andersson
|
||||
this->momentum_Angular = Formula::AngularMomentum( this->momentOfInertiaTensor, worldW );
|
||||
this->momentum_Angular = this->momentOfInertiaTensor.CalculateAngularMomentum( this->rotation, worldW );
|
||||
}
|
||||
|
||||
void RigidBody::SetImpulse_Linear( const Float4 &worldJ, const Float4 &atWorldPos )
|
||||
void RigidBody::SetImpulse_Linear( const Float3 &worldJ, const Float3 &atWorldPos )
|
||||
{ // by Dan Andersson
|
||||
Float4 worldOffset = atWorldPos - this->centerPos;
|
||||
Float3 worldOffset = atWorldPos - this->centerPos;
|
||||
this->impulse_Linear = VectorProjection( worldJ, worldOffset );
|
||||
this->impulse_Angular = Formula::ImpulseTorque( worldJ, worldOffset );
|
||||
}
|
|
@ -8,19 +8,21 @@
|
|||
#include "OysterMath.h"
|
||||
#include "OysterCollision3D.h"
|
||||
#include "OysterPhysics3D.h"
|
||||
#include "Inertia.h"
|
||||
|
||||
namespace Oyster { namespace Physics3D
|
||||
{
|
||||
struct RigidBody
|
||||
{ //! A struct of a simple rigid body.
|
||||
public:
|
||||
::Oyster::Math::Float4 centerPos, //!< Location of the body's center in the world.
|
||||
::Oyster::Math::Float3 centerPos, //!< Location of the body's center in the world.
|
||||
axis, //!< Euler rotationAxis of the body.
|
||||
boundingReach, //!<
|
||||
momentum_Linear, //!< The linear momentum G (kg*m/s).
|
||||
momentum_Angular, //!< The angular momentum H (Nm*s) around an parallell axis.
|
||||
impulse_Linear, //!< The linear impulse sum Jl (kg*m/s) that will be consumed each update.
|
||||
impulse_Angular; //!< The angular impulse sum Ja (kg*m^2/s) that will be consumed each update.
|
||||
impulse_Angular, //!< The angular impulse sum Ja (kg*m^2/s) that will be consumed each update.
|
||||
gravityNormal;
|
||||
::Oyster::Math::Float restitutionCoeff, //!<
|
||||
frictionCoeff_Static, //!<
|
||||
frictionCoeff_Kinetic; //!<
|
||||
|
@ -30,54 +32,55 @@ namespace Oyster { namespace Physics3D
|
|||
RigidBody & operator = ( const RigidBody &body );
|
||||
|
||||
void Update_LeapFrog( ::Oyster::Math::Float updateFrameLength );
|
||||
void Predict_LeapFrog( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime );
|
||||
void Predict_LeapFrog( ::Oyster::Math::Float3 &outDeltaPos, ::Oyster::Math::Float3 &outDeltaAxis, const ::Oyster::Math::Float3 &actingLinearImpulse, const ::Oyster::Math::Float3 &actingAngularImpulse, ::Oyster::Math::Float deltaTime );
|
||||
|
||||
void Move( const ::Oyster::Math::Float4 &deltaPos, const ::Oyster::Math::Float4 &deltaAxis );
|
||||
void ApplyImpulse( const ::Oyster::Math::Float4 &worldJ, const ::Oyster::Math::Float4 &atWorldPos );
|
||||
void ApplyImpulse_Linear( const ::Oyster::Math::Float4 &worldJ );
|
||||
void ApplyImpulse_Angular( const ::Oyster::Math::Float4 &worldJ );
|
||||
void ApplyForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength );
|
||||
void ApplyForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float4 &atWorldPos );
|
||||
void Move( const ::Oyster::Math::Float3 &deltaPos, const ::Oyster::Math::Float3 &deltaAxis );
|
||||
void ApplyImpulse( const ::Oyster::Math::Float3 &worldJ, const ::Oyster::Math::Float3 &atWorldPos );
|
||||
void ApplyImpulse_Linear( const ::Oyster::Math::Float3 &worldJ );
|
||||
void ApplyImpulse_Angular( const ::Oyster::Math::Float3 &worldJ );
|
||||
void ApplyForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength );
|
||||
void ApplyForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float3 &atWorldPos );
|
||||
|
||||
// GET METHODS ////////////////////////////////
|
||||
|
||||
const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const;
|
||||
const ::Oyster::Physics3D::MomentOfInertia & GetMomentOfInertia() const;
|
||||
::Oyster::Math::Float GetMass() const;
|
||||
const ::Oyster::Math::Quaternion & GetRotation() const;
|
||||
const ::Oyster::Math::Quaternion & GetRotationQuaternion() const;
|
||||
::Oyster::Math::Float4x4 GetRotationMatrix() const;
|
||||
::Oyster::Math::Float4x4 GetOrientation() const;
|
||||
::Oyster::Math::Float4x4 GetView() const;
|
||||
::Oyster::Math::Float4x4 GetToWorldMatrix() const;
|
||||
::Oyster::Math::Float4x4 GetToLocalMatrix() const;
|
||||
::Oyster::Math::Float4 GetSize() const;
|
||||
::Oyster::Math::Float4 GetVelocity_Linear() const;
|
||||
::Oyster::Math::Float4 GetVelocity_Angular() const;
|
||||
::Oyster::Math::Float4 GetLinearMomentum( const ::Oyster::Math::Float4 &atWorldPos ) const;
|
||||
::Oyster::Math::Float3 GetSize() const;
|
||||
::Oyster::Math::Float3 GetVelocity_Linear() const;
|
||||
::Oyster::Math::Float3 GetVelocity_Angular() const;
|
||||
::Oyster::Math::Float3 GetLinearMomentum( const ::Oyster::Math::Float3 &atWorldPos ) const;
|
||||
|
||||
// SET METHODS ////////////////////////////////
|
||||
|
||||
void SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &localTensorI );
|
||||
void SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &localTensorI );
|
||||
void SetMomentOfInertia_KeepVelocity( const ::Oyster::Physics3D::MomentOfInertia &localTensorI );
|
||||
void SetMomentOfInertia_KeepMomentum( const ::Oyster::Physics3D::MomentOfInertia &localTensorI );
|
||||
void SetMass_KeepVelocity( const ::Oyster::Math::Float &m );
|
||||
void SetMass_KeepMomentum( const ::Oyster::Math::Float &m );
|
||||
|
||||
void SetOrientation( const ::Oyster::Math::Float4x4 &o );
|
||||
void SetRotation( const ::Oyster::Math::Float4x4 &r );
|
||||
void SetSize( const ::Oyster::Math::Float4 &widthHeight );
|
||||
//void SetOrientation( const ::Oyster::Math::Float4x4 &o );
|
||||
//void SetRotation( const ::Oyster::Math::Float4x4 &r );
|
||||
void SetSize( const ::Oyster::Math::Float3 &widthHeight );
|
||||
|
||||
void SetMomentum_Linear( const ::Oyster::Math::Float4 &worldG, const ::Oyster::Math::Float4 &atWorldPos );
|
||||
void SetMomentum_Linear( const ::Oyster::Math::Float3 &worldG, const ::Oyster::Math::Float3 &atWorldPos );
|
||||
|
||||
void SetVelocity_Linear( const ::Oyster::Math::Float4 &worldV );
|
||||
void SetVelocity_Linear( const ::Oyster::Math::Float4 &worldV, const ::Oyster::Math::Float4 &atWorldPos );
|
||||
void SetVelocity_Angular( const ::Oyster::Math::Float4 &worldW );
|
||||
void SetVelocity_Linear( const ::Oyster::Math::Float3 &worldV );
|
||||
void SetVelocity_Linear( const ::Oyster::Math::Float3 &worldV, const ::Oyster::Math::Float3 &atWorldPos );
|
||||
void SetVelocity_Angular( const ::Oyster::Math::Float3 &worldW );
|
||||
|
||||
void SetImpulse_Linear( const ::Oyster::Math::Float4 &worldJ, const ::Oyster::Math::Float4 &atWorldPos );
|
||||
void SetForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength );
|
||||
void SetForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float4 &atWorldPos );
|
||||
void SetImpulse_Linear( const ::Oyster::Math::Float3 &worldJ, const ::Oyster::Math::Float3 &atWorldPos );
|
||||
//void SetForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength );
|
||||
//void SetForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float3 &atWorldPos );
|
||||
|
||||
private:
|
||||
::Oyster::Math::Float mass; //!< m (kg)
|
||||
::Oyster::Math::Float4x4 momentOfInertiaTensor; //!< I (Nm*s) Tensor matrix ( only need to be 3x3 matrix, but is 4x4 for future hardware acceleration ) (localValue)
|
||||
//::Oyster::Math::Float4x4 momentOfInertiaTensor; //!< I (Nm*s) Tensor matrix ( only need to be 3x3 matrix, but is 4x4 for future hardware acceleration ) (localValue)
|
||||
::Oyster::Physics3D::MomentOfInertia momentOfInertiaTensor;
|
||||
::Oyster::Math::Quaternion rotation; //!< RotationAxis of the body.
|
||||
};
|
||||
} }
|
||||
|
|
|
@ -10,22 +10,22 @@
|
|||
|
||||
namespace Oyster { namespace Physics3D
|
||||
{
|
||||
inline void RigidBody::ApplyImpulse_Linear( const ::Oyster::Math::Float4 &worldJ )
|
||||
inline void RigidBody::ApplyImpulse_Linear( const ::Oyster::Math::Float3 &worldJ )
|
||||
{
|
||||
this->impulse_Linear += worldJ;
|
||||
}
|
||||
|
||||
inline void RigidBody::ApplyImpulse_Angular( const ::Oyster::Math::Float4 &worldJ )
|
||||
inline void RigidBody::ApplyImpulse_Angular( const ::Oyster::Math::Float3 &worldJ )
|
||||
{
|
||||
this->impulse_Angular += worldJ;
|
||||
}
|
||||
|
||||
inline void RigidBody::ApplyForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength )
|
||||
inline void RigidBody::ApplyForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength )
|
||||
{
|
||||
this->impulse_Linear += worldF * updateFrameLength;
|
||||
}
|
||||
|
||||
inline void RigidBody::ApplyForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float4 &atWorldPos )
|
||||
inline void RigidBody::ApplyForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float3 &atWorldPos )
|
||||
{
|
||||
this->ApplyImpulse( worldF * updateFrameLength, atWorldPos );
|
||||
}
|
||||
|
@ -40,26 +40,25 @@ namespace Oyster { namespace Physics3D
|
|||
return this->GetView();
|
||||
}
|
||||
|
||||
inline ::Oyster::Math::Float4 RigidBody::GetSize() const
|
||||
inline ::Oyster::Math::Float3 RigidBody::GetSize() const
|
||||
{
|
||||
return 2.0f * this->boundingReach;
|
||||
}
|
||||
|
||||
inline void RigidBody::SetSize( const ::Oyster::Math::Float4 &widthHeight )
|
||||
inline void RigidBody::SetSize( const ::Oyster::Math::Float3 &widthHeight )
|
||||
{
|
||||
this->boundingReach = ::Utility::Value::Abs( 0.5f * widthHeight );
|
||||
}
|
||||
|
||||
inline void RigidBody::SetForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength )
|
||||
{
|
||||
this->impulse_Linear = worldF * updateFrameLength;
|
||||
}
|
||||
|
||||
inline void RigidBody::SetForce( const ::Oyster::Math::Float4 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float4 &atWorldPos )
|
||||
{
|
||||
this->SetImpulse_Linear( worldF * updateFrameLength, atWorldPos );
|
||||
}
|
||||
//inline void RigidBody::SetForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength )
|
||||
//{
|
||||
// this->impulse_Linear = worldF * updateFrameLength;
|
||||
//}
|
||||
|
||||
//inline void RigidBody::SetForce( const ::Oyster::Math::Float3 &worldF, ::Oyster::Math::Float updateFrameLength, const ::Oyster::Math::Float3 &atWorldPos )
|
||||
//{
|
||||
// this->SetImpulse_Linear( worldF * updateFrameLength, atWorldPos );
|
||||
//}
|
||||
} }
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue