Merge branch 'master' of https://github.com/dean11/Danbias into Graphics

This commit is contained in:
lanariel 2013-11-18 14:18:25 +01:00
commit a628d8a488
32 changed files with 454 additions and 171 deletions

View File

@ -90,7 +90,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -101,7 +101,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -114,7 +114,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -129,7 +129,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -141,6 +141,15 @@
<ProjectReference Include="..\GamePhysics\GamePhysics.vcxproj"> <ProjectReference Include="..\GamePhysics\GamePhysics.vcxproj">
<Project>{104fa3e9-94d9-4e1d-a941-28a03bc8a095}</Project> <Project>{104fa3e9-94d9-4e1d-a941-28a03bc8a095}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Misc\Misc.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>
<ProjectReference Include="..\OysterMath\OysterMath.vcxproj">
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
</ProjectReference>
<ProjectReference Include="..\OysterPhysics3D\OysterPhysics3D.vcxproj">
<Project>{4285bd3f-3c6c-4670-b7af-a29afef5f6a8}</Project>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -0,0 +1,36 @@
#ifndef PHYSICS_API_H
#define PHYSICS_API_H
#include "OysterMath.h"
namespace Oyster
{
namespace Physics
{
class API;
class IRigidBody;
class IParticle;
class API
{
public:
static API & Instance();
};
class IRigidBody
{
public:
};
class IParticle
{
public:
};
}
namespace Collision
{}
}
#endif

View File

@ -142,6 +142,7 @@
<ClCompile Include="WinTimer.cpp" /> <ClCompile Include="WinTimer.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Utilities-InlineImpl.h" />
<ClInclude Include="Utilities.h" /> <ClInclude Include="Utilities.h" />
<ClInclude Include="WinTimer.h" /> <ClInclude Include="WinTimer.h" />
</ItemGroup> </ItemGroup>

View File

@ -29,5 +29,8 @@
<ClInclude Include="WinTimer.h"> <ClInclude Include="WinTimer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Utilities-InlineImpl.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

168
Misc/Utilities-InlineImpl.h Normal file
View File

@ -0,0 +1,168 @@
/////////////////////////////////////////////////////////////////////
// Inline and template implementations for
// the Utility Collection of Miscellanious Handy Functions
// © Dan Andersson 2013
/////////////////////////////////////////////////////////////////////
#ifndef UTILITIES_INLINE_IMPL_H
#define UTILITIES_INLINE_IMPL_H
#include "Utilities.h"
namespace Utility
{
namespace DynamicMemory
{
template<typename Type>
inline void SafeDeleteInstance( Type *dynamicInstance )
{
if( dynamicInstance )
{
delete dynamicInstance;
}
}
template<typename Type>
void SafeDeleteArray( Type dynamicArray[] )
{
if( dynamicArray )
{
delete [] dynamicArray;
}
}
template<typename Type>
UniquePointer<Type>::UniquePointer( Type *assignedInstance )
{
this->ownedInstance = assignedInstance;
}
template<typename Type>
UniquePointer<Type>::~UniquePointer()
{
SafeDeleteInstance( this->ownedInstance );
}
template<typename Type>
UniquePointer<Type> & UniquePointer<Type>::operator = ( Type *assignedInstance )
{
SafeDeleteInstance( this->ownedInstance );
this->ownedInstance = assignedInstance;
return *this;
}
template<typename Type>
UniquePointer<Type> & UniquePointer<Type>::operator = ( const UniquePointer<Type> &donor )
{
SafeDeleteInstance( this->ownedInstance );
this->ownedInstance = donor.ownedInstance;
donor.ownedInstance = NULL;
return *this;
}
template<typename Type>
UniquePointer<Type>::operator Type* ()
{
return this->ownedInstance;
}
template<typename Type>
UniquePointer<Type>::operator const Type* () const
{
return this->ownedInstance;
}
template<typename Type>
Type * UniquePointer<Type>::operator -> ()
{
return this->ownedInstance;
}
template<typename Type>
const Type * UniquePointer<Type>::operator -> () const
{
return this->ownedInstance;
}
template<typename Type>
UniquePointer<Type>::operator bool() const
{
return this->ownedInstance != NULL;
}
template<typename Type>
Type* UniquePointer<Type>::Release()
{
Type *copy = this->ownedInstance;
this->ownedInstance = NULL;
return copy;
}
template<typename Type>
inline bool UniquePointer<Type>::HaveOwnership() const
{
return this->operator bool();
}
template<typename Type>
UniqueArray<Type>::UniqueArray( Type assignedArray[] )
{
this->ownedArray = assignedArray;
}
template<typename Type>
UniqueArray<Type>::~UniqueArray()
{
SafeDeleteArray( this->ownedArray );
}
template<typename Type>
UniqueArray<Type> & UniqueArray<Type>::operator = ( Type assignedArray[] )
{
SafeDeleteArray( this->ownedArray );
this->ownedArray = assignedArray;
}
template<typename Type>
UniqueArray<Type> & UniqueArray<Type>::operator = ( const UniqueArray<Type> &donor )
{
SafeDeleteArray( this->ownedArray );
this->ownedArray = donor.ownedInstance;
donor.owned = NULL;
}
template<typename Type> template<typename Index>
Type & UniqueArray<Type>::operator [] ( Index i )
{
return this->ownedArray[i];
}
template<typename Type> template<typename Index>
const Type & UniqueArray<Type>::operator [] ( Index i ) const
{
return this->ownedArray[i];
}
template<typename Type>
UniqueArray<Type>::operator bool () const
{
return this->ownedArray != NULL;
}
template<typename Type>
Type* UniqueArray<Type>::Release()
{
Type *copy = this->ownedArray;
this->ownedArray = NULL;
return copy;
}
template<typename Type>
inline bool UniqueArray<Type>::HaveOwnership() const
{
return this->operator bool();
}
}
}
#endif

View File

@ -3,7 +3,6 @@
// © Dan Andersson 2013 // © Dan Andersson 2013
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
#pragma once
#ifndef UTILITIES_H #ifndef UTILITIES_H
#define UTILITIES_H #define UTILITIES_H
@ -15,100 +14,97 @@
namespace Utility namespace Utility
{ {
namespace Memory namespace DynamicMemory
{ {
/// If dynamicInstance is not NULL, then delete
template<typename Type> void SafeDeleteInstance( Type *dynamicInstance );
/// If dynamicArray is not NULL, then delete []
template<typename Type> void SafeDeleteArray( Type dynamicArray[] );
template<typename Type> template<typename Type>
struct UniquePointer struct UniquePointer
{ { /// Wrapper to safely transfer dynamic ownership/responsibility
public: public:
UniquePointer( Type *assignedMemory = NULL ); /// Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
/// If NULL is assigned is equavalent with clearing all responsibilities from this UniquePointer.
UniquePointer( Type *assignedInstance = NULL );
/// Will auto delete assigned dynamic instance.
~UniquePointer(); ~UniquePointer();
UniquePointer<Type> & operator = ( Type *assignedMemory ); /// Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
/// If NULL is assigned is equavalent with clearing all responsibilities from this UniquePointer.
UniquePointer<Type> & operator = ( Type *assignedInstance );
/// Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted.
/// If donor had nothing, is equavalent with clearing all responsibilities from this UniquePointer.
UniquePointer<Type> & operator = ( const UniquePointer<Type> &donor ); UniquePointer<Type> & operator = ( const UniquePointer<Type> &donor );
/// Access the assigned dynamic instance. Will crash if nothing there
operator Type* (); operator Type* ();
operator const Type* () const;
Type * operator -> ();
const Type * operator -> () const;
template<typename Index> Type & operator [] ( Index i );
template<typename Index> const Type & operator [] ( Index i ) const;
/// Access the assigned dynamic instance. Will crash if nothing there
operator const Type* () const;
/// Access members of the assigned dynamic instance. Will crash if nothing there
Type * operator -> ();
/// Access members of the assigned dynamic instance. Will crash if nothing there
const Type * operator -> () const;
/// If true, this UniquePointer have a current ownership/responsibility of a dynamic instance.
operator bool () const; operator bool () const;
/// This UniquePointer drops all claims of ownership/responsibility and returns the dynamic instance. Now it is your responsibility to delete.
Type* Release(); Type* Release();
bool haveOwnership() const;
/// (inline) If true, this UniquePointer have a current ownership/responsibility of a dynamic instance.
bool HaveOwnership() const;
private: private:
mutable Type *ownedMemory; mutable Type *ownedInstance;
}; };
// IMPLEMENTATIONS ////////////////////////////////////////////////
template<typename Type> template<typename Type>
UniquePointer<Type>::UniquePointer( Type *assignedMemory ) struct UniqueArray
{ this->ownedMemory = assignedMemory; } { /// Wrapper to safely transfer dynamic ownership/responsibility
public:
/// Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
/// If NULL is assigned is equavalent with clearing all responsibilities from this UniqueArray.
UniqueArray( Type assignedArray[] = NULL );
template<typename Type> /// Will auto delete assigned dynamic array.
UniquePointer<Type>::~UniquePointer() ~UniqueArray();
{ if( this->ownedMemory ) delete this->ownedMemory; }
template<typename Type> /// Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
UniquePointer<Type> & UniquePointer<Type>::operator = ( Type *assignedMemory ) /// If NULL is assigned is equavalent with clearing all responsibilities from this UniqueArray.
{ UniqueArray<Type> & operator = ( Type assignedArray[] );
if( this->ownedPointer ) delete this->ownedMemory;
this->ownedMemory = assignedMemory;
return *this;
}
template<typename Type> /// Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted.
UniquePointer<Type> & UniquePointer<Type>::operator = ( const UniquePointer<Type> &donor ) /// If donor had nothing, is equavalent with clearing all responsibilities from this UniqueArray.
{ UniqueArray<Type> & operator = ( const UniqueArray<Type> &donor );
if( this->ownedMemory ) delete this->ownedMemory;
this->ownedMemory = donor.ownedMemory;
donor.ownedMemory = NULL;
return *this;
}
template<typename Type> /// Accesses the instance at index i of this UniqeArray's owned dynamic array.
UniquePointer<Type>::operator Type* () /// Will crash if out-of-bound or there is no assigned array.
{ return this->ownedMemory; } template<typename Index> Type & operator [] ( Index i );
template<typename Type> /// Accesses the instance at index i of this UniqeArray's owned dynamic array.
UniquePointer<Type>::operator const Type* () const /// Will crash if out-of-bound or there is no assigned array.
{ return this->ownedMemory; } template<typename Index> const Type & operator [] ( Index i ) const;
template<typename Type> /// If true, this UniqueArray have a current ownership/responsibility of a dynamic instance.
Type * UniquePointer<Type>::operator -> () operator bool () const;
{ return this->ownedMemory; }
template<typename Type> /// This UniqueArray drops all claims of ownership/responsibility and returns the dynamic array. Now it is your responsibility to delete.
const Type * UniquePointer<Type>::operator -> () const Type* Release();
{ return this->ownedMemory; }
template<typename Type> template<typename Index> /// (inline) If true, this UniqueArray have a current ownership/responsibility of a dynamic array.
Type & UniquePointer<Type>::operator [] ( Index i ) bool HaveOwnership() const;
{ return this->ownedMemory[i]; }
template<typename Type> template<typename Index> private:
const Type & UniquePointer<Type>::operator [] ( Index i ) const mutable Type *ownedArray;
{ return this->ownedMemory[i]; } };
template<typename Type>
UniquePointer<Type>::operator bool() const
{ return this->ownedMemory != NULL; }
template<typename Type>
Type* UniquePointer<Type>::Release()
{
Type *copy = this->ownedMemory;
this->ownedMemory = NULL;
return copy;
}
template<typename Type>
inline bool UniquePointer<Type>::haveOwnership() const
{ return this->operator bool(); }
} }
namespace String namespace String
@ -249,4 +245,6 @@ namespace Utility
} }
} }
#include "Utilities-InlineImpl.h"
#endif #endif

View File

@ -336,6 +336,19 @@ namespace LinearAlgebra3D
0, 0, 0, 1 ); 0, 0, 0, 1 );
} }
// O0 = T0 * R0
// O1 = T1 * T0 * R1 * R0
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & UpdateOrientationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &deltaPosition, const ::LinearAlgebra::Matrix4x4<ScalarType> &deltaRotationMatrix, ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix )
{
::LinearAlgebra::Vector3<ScalarType> position = deltaPosition + orientationMatrix.v[3].xyz;
orientationMatrix.v[3].xyz = ::LinearAlgebra::Vector3<ScalarType>::null;
orientationMatrix = deltaRotationMatrix * orientationMatrix;
orientationMatrix.v[3].xyz = position;
return orientationMatrix;
}
/* Creates an orthographic projection matrix designed for DirectX enviroment. /* Creates an orthographic projection matrix designed for DirectX enviroment.
width; of the projection sample volume. width; of the projection sample volume.
height; of the projection sample volume. height; of the projection sample volume.

View File

@ -75,6 +75,9 @@ namespace Oyster { namespace Math3D
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem ) Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem )
{ return ::LinearAlgebra3D::InverseOrientationMatrix( orientationMatrix, targetMem ); } { return ::LinearAlgebra3D::InverseOrientationMatrix( orientationMatrix, targetMem ); }
Float4x4 & UpdateOrientationMatrix( const Float3 &deltaPosition, const Float4x4 &deltaRotationMatrix, Float4x4 &orientationMatrix )
{ return ::LinearAlgebra3D::UpdateOrientationMatrix( deltaPosition, deltaRotationMatrix, orientationMatrix ); }
Float4x4 & ProjectionMatrix_Orthographic( const Float &width, const Float &height, const Float &nearClip, const Float &farClip, Float4x4 &targetMem ) Float4x4 & ProjectionMatrix_Orthographic( const Float &width, const Float &height, const Float &nearClip, const Float &farClip, Float4x4 &targetMem )
{ return ::LinearAlgebra3D::ProjectionMatrix_Orthographic( width, height, nearClip, farClip, targetMem ); } { return ::LinearAlgebra3D::ProjectionMatrix_Orthographic( width, height, nearClip, farClip, targetMem ); }

View File

@ -183,6 +183,10 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
/// If orientationMatrix is assumed to be by all definitions a rigid orientation matrix aka rigid body matrix. Then this is a much faster inverse method. /// If orientationMatrix is assumed to be by all definitions a rigid orientation matrix aka rigid body matrix. Then this is a much faster inverse method.
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem = Float4x4() ); Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem = Float4x4() );
// O0 = T0 * R0
// O1 = T1 * T0 * R1 * R0
Float4x4 & UpdateOrientationMatrix( const Float3 &deltaPosition, const Float4x4 &deltaRotationMatrix, Float4x4 &orientationMatrix );
/******************************************************************* /*******************************************************************
* Creates an orthographic projection matrix designed for DirectX enviroment. * Creates an orthographic projection matrix designed for DirectX enviroment.
* @param width; of the projection sample volume. * @param width; of the projection sample volume.

View File

@ -19,8 +19,8 @@ Box & Box::operator = ( const Box &box )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> Box::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Box::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Box(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Box(*this) ); }
bool Box::Intersects( const ICollideable *target ) const bool Box::Intersects( const ICollideable *target ) const
{ {

View File

@ -33,7 +33,7 @@ namespace Oyster { namespace Collision3D
Box & operator = ( const Box &box ); Box & operator = ( const Box &box );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -21,8 +21,8 @@ BoxAxisAligned & BoxAxisAligned::operator = ( const BoxAxisAligned &box )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> BoxAxisAligned::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> BoxAxisAligned::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new BoxAxisAligned(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new BoxAxisAligned(*this) ); }
bool BoxAxisAligned::Intersects( const ICollideable *target ) const bool BoxAxisAligned::Intersects( const ICollideable *target ) const
{ {

View File

@ -27,7 +27,7 @@ namespace Oyster { namespace Collision3D
BoxAxisAligned & operator = ( const BoxAxisAligned &box ); BoxAxisAligned & operator = ( const BoxAxisAligned &box );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -188,8 +188,8 @@ void Frustrum::WriteToByte( unsigned int &nextIndex, unsigned char targetMem[] )
nextIndex += 6 * ::Utility::StaticArray::NumElementsOf( this->plane[0].byte ); nextIndex += 6 * ::Utility::StaticArray::NumElementsOf( this->plane[0].byte );
} }
::Utility::Memory::UniquePointer<ICollideable> Frustrum::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Frustrum::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Frustrum(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Frustrum(*this) ); }
bool Frustrum::Intersects( const ICollideable *target ) const bool Frustrum::Intersects( const ICollideable *target ) const
{ {

View File

@ -37,7 +37,7 @@ namespace Oyster { namespace Collision3D
void Split( Frustrum targetList[], unsigned int numX, unsigned int numY = 1U, unsigned int numZ = 1u ) const; /// DEPRECATED void Split( Frustrum targetList[], unsigned int numX, unsigned int numY = 1U, unsigned int numZ = 1u ) const; /// DEPRECATED
void WriteToByte( unsigned char targetMem[], unsigned int &nextIndex ) const; /// DEPRECATED void WriteToByte( unsigned char targetMem[], unsigned int &nextIndex ) const; /// DEPRECATED
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -33,7 +33,7 @@ namespace Oyster { namespace Collision3D /// Contains a collection of 3D shapes
ICollideable( Type type = Type_undefined ); ICollideable( Type type = Type_undefined );
virtual ~ICollideable(); virtual ~ICollideable();
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const = 0; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const = 0;
virtual bool Intersects( const ICollideable *target ) const = 0; virtual bool Intersects( const ICollideable *target ) const = 0;
virtual bool Contains( const ICollideable *target ) const = 0; virtual bool Contains( const ICollideable *target ) const = 0;
}; };

View File

@ -20,8 +20,8 @@ Line & Line::operator = ( const Line &line )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> Line::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Line::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Line(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Line(*this) ); }
bool Line::Intersects( const ICollideable *target ) const bool Line::Intersects( const ICollideable *target ) const
{ {

View File

@ -28,7 +28,7 @@ namespace Oyster { namespace Collision3D
Line & operator = ( const Line &line ); Line & operator = ( const Line &line );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -57,6 +57,15 @@ namespace Oyster { namespace Physics3D
return ( momentOfInertia * ::Oyster::Math::Float4(angularVelocity, 0.0f) ).xyz; return ( momentOfInertia * ::Oyster::Math::Float4(angularVelocity, 0.0f) ).xyz;
} }
/******************************************************************
* Returns the local angular momentum of a mass in rotation.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float3 AngularMomentum( const ::Oyster::Math::Float3 linearMomentum, const ::Oyster::Math::Float3 &offset )
{
return offset.Cross( linearMomentum );
}
/****************************************************************** /******************************************************************
* Returns the local tangential momentum at localPos, of a mass in rotation. * Returns the local tangential momentum at localPos, of a mass in rotation.
* @todo TODO: improve doc * @todo TODO: improve doc
@ -160,7 +169,7 @@ namespace Oyster { namespace Physics3D
* *
* @todo TODO: improve doc * @todo TODO: improve doc
******************************************************************/ ******************************************************************/
inline ::Oyster::Math::Float3 ImpulseTorque( const ::Oyster::Math::Float3 & offset, const ::Oyster::Math::Float3 &impulseForce ) inline ::Oyster::Math::Float3 ImpulseTorque( const ::Oyster::Math::Float3 & impulseForce, const ::Oyster::Math::Float3 &offset )
{ {
return offset.Cross( impulseForce ); return offset.Cross( impulseForce );
} }

View File

@ -19,8 +19,8 @@ Plane & Plane::operator = ( const Plane &plane )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> Plane::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Plane::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Plane(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Plane(*this) ); }
bool Plane::Intersects( const ICollideable *target ) const bool Plane::Intersects( const ICollideable *target ) const
{ {

View File

@ -27,7 +27,7 @@ namespace Oyster { namespace Collision3D
Plane & operator = ( const Plane &plane ); Plane & operator = ( const Plane &plane );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -18,8 +18,8 @@ Point & Point::operator = ( const Point &point )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> Point::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Point::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Point(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Point(*this) ); }
bool Point::Intersects( const ICollideable *target ) const bool Point::Intersects( const ICollideable *target ) const
{ {

View File

@ -26,7 +26,7 @@ namespace Oyster { namespace Collision3D
Point & operator = ( const Point &point ); Point & operator = ( const Point &point );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -19,8 +19,8 @@ Ray & Ray::operator = ( const Ray &ray )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> Ray::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Ray::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Ray(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Ray(*this) ); }
bool Ray::Intersects( const ICollideable *target ) const bool Ray::Intersects( const ICollideable *target ) const
{ {

View File

@ -35,7 +35,7 @@ namespace Oyster { namespace Collision3D
Ray & operator = ( const Ray &ray ); Ray & operator = ( const Ray &ray );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -60,8 +60,10 @@ void RigidBody::Update_LeapFrog( Float deltaTime )
deltaRadian = ::std::sqrt( deltaRadian ); deltaRadian = ::std::sqrt( deltaRadian );
rotationAxis /= deltaRadian; rotationAxis /= deltaRadian;
// using rotationAxis, deltaRadian and deltaPos to create a matrix to transform the orientation matrix // using rotationAxis, deltaRadian and deltaPos to create a matrix to update the orientation matrix
this->box.orientation = OrientationMatrix( rotationAxis, deltaRadian, deltaPos ) * this->box.orientation; UpdateOrientationMatrix( deltaPos, RotationMatrix(deltaRadian, rotationAxis), this->box.orientation );
/** @todo TODO: ISSUE! how is momentOfInertiaTensor related to the orientation of the RigidBody? */
} }
else else
{ // no rotation, only use deltaPos to translate the RigidBody { // no rotation, only use deltaPos to translate the RigidBody
@ -85,7 +87,7 @@ void RigidBody::ApplyImpulseForceAt_Local( const Float3 &localForce, const Float
if( localOffset != Float3::null ) if( localOffset != Float3::null )
{ {
this->impulseForceSum += VectorProjection( localForce, localOffset ); this->impulseForceSum += VectorProjection( localForce, localOffset );
this->impulseTorqueSum += Formula::ImpulseTorque( localOffset, localForce ); this->impulseTorqueSum += Formula::ImpulseTorque( localForce, localOffset );
} }
else else
{ {
@ -284,138 +286,175 @@ Float3 RigidBody::GetTangentialLinearVelocityAt_World( const Float3 &worldPos )
return this->GetTangentialLinearVelocityAt_Local( (this->GetView() * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f return this->GetTangentialLinearVelocityAt_Local( (this->GetView() * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
} }
Float3 RigidBody::GetImpulseForceAt_Local( const Float3 &pos ) const Float3 RigidBody::GetImpulseForceAt_Local( const Float3 &localPos ) const
{ // by { // by Dan Andersson
return Float3::null; return this->impulseForceSum + Formula::TangentialImpulseForce( this->impulseForceSum, localPos );
} }
Float3 RigidBody::GetImpulseForceAt_World( const Float3 &pos ) const Float3 RigidBody::GetImpulseForceAt_World( const Float3 &worldPos ) const
{ // by { // by Dan Andersson
return Float3::null; Float4 localForce = Float4( this->GetImpulseForceAt_Local((this->GetView() * Float4(worldPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
return (this->box.orientation * localForce).xyz; // should not be any disform thus result.w = 0.0f
} }
Float3 RigidBody::GetLinearMomentumAt_Local( const Float3 &pos ) const Float3 RigidBody::GetLinearMomentumAt_Local( const Float3 &localPos ) const
{ // by { // by Dan Andersson
return Float3::null; // Reminder! Momentum is a world value.
return Float3::null; // TODO:
} }
Float3 RigidBody::GetLinearMomentumAt_World( const Float3 &pos ) const Float3 RigidBody::GetLinearMomentumAt_World( const Float3 &worldPos ) const
{ // by { // by Dan Andersson
return Float3::null; // Reminder! Momentum is a world value.
Float4 localMomentum = Float4( this->GetLinearMomentumAt_Local((this->GetView() * Float4(worldPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
return (this->box.orientation * localMomentum).xyz; // should not be any disform thus result.w = 0.0f
// TODO: angularMomentum is a local value!!
return this->linearMomentum + Formula::TangentialLinearMomentum( this->angularMomentum, worldPos );
} }
Float3 RigidBody::GetImpulseAccelerationAt_Local( const Float3 &pos ) const Float3 RigidBody::GetImpulseAccelerationAt_Local( const Float3 &localPos ) const
{ // by { // by Dan Andersson
return Float3::null; // Reminder! Acceleration is a world value.
Float4 worldAccel = Float4( this->GetImpulseAccelerationAt_Local((this->box.orientation * Float4(localPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
return (this->GetView() * worldAccel).xyz; // should not be any disform thus result.w = 0.0f
} }
Float3 RigidBody::GetImpulseAccelerationAt_World( const Float3 &pos ) const Float3 RigidBody::GetImpulseAccelerationAt_World( const Float3 &worldPos ) const
{ // by { // by Dan Andersson
return Float3::null; // Reminder! Acceleration is a world value.
return Formula::LinearImpulseAcceleration( this->mass, this->impulseForceSum )
+ Formula::TangentialImpulseAcceleration( this->momentOfInertiaTensor.GetInverse(), this->impulseTorqueSum, worldPos );
} }
Float3 RigidBody::GetLinearVelocityAt_Local( const Float3 &pos ) const Float3 RigidBody::GetLinearVelocityAt_Local( const Float3 &localPos ) const
{ // by { // by Dan Andersson
return Float3::null; // Reminder! Velocity is a world value.
Float4 worldV = Float4( this->GetLinearVelocityAt_Local((this->box.orientation * Float4(localPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
return (this->GetView() * worldV).xyz; // should not be any disform thus result.w = 0.0f
} }
Float3 RigidBody::GetLinearVelocityAt_World( const Float3 &pos ) const Float3 RigidBody::GetLinearVelocityAt_World( const Float3 &worldPos ) const
{ // by { // by Dan Andersson
return Float3::null; // Reminder! Velocity is a world value.
return Formula::LinearVelocity( this->mass, this->linearMomentum )
+ Formula::TangentialLinearVelocity( this->momentOfInertiaTensor.GetInverse(), this->angularMomentum, worldPos );
} }
void RigidBody::SetMomentOfInertia( const Float4x4 &i ) void RigidBody::SetMomentOfInertia( const Float4x4 &i )
{ // by { // by Dan Andersson
if( i.GetDeterminant() != 0.0f ) // insanitycheck! momentOfInertiaTensor must be invertable
{
this->momentOfInertiaTensor = i;
}
} }
void RigidBody::SetMass_KeepVelocity( const Float &m ) void RigidBody::SetMass_KeepVelocity( const Float &m )
{ // by { // by Dan Andersson
if( m != 0.0f ) // insanitycheck! mass must be invertable
{
Float3 velocity = Formula::LinearVelocity( this->mass, this->linearMomentum );
this->mass = m;
this->linearMomentum = Formula::LinearMomentum( this->mass, velocity );
}
} }
void RigidBody::SetMass_KeepMomentum( const Float &m ) void RigidBody::SetMass_KeepMomentum( const Float &m )
{ // by { // by Dan Anderson
if( m != 0.0f ) // insanitycheck! mass must be invertable
{
this->mass = m;
}
} }
void RigidBody::SetOrientation( const Float4x4 &o ) void RigidBody::SetOrientation( const Float4x4 &o )
{ // by { // by Dan Andersson
this->box.orientation = o;
} }
void RigidBody::SetSize( const Float3 &widthHeight ) void RigidBody::SetSize( const Float3 &widthHeight )
{ // by { // by Dan Andersson
this->box.boundingOffset = 0.5f * widthHeight;
} }
void RigidBody::SetCenter( const Float3 &p ) void RigidBody::SetCenter( const Float3 &p )
{ // by { // by Dan Andersson
this->box.center = p;
} }
void RigidBody::SetImpulsTorque( const Float3 &t ) void RigidBody::SetImpulseTorque( const Float3 &t )
{ // by { // by Dan Andersson
this->impulseTorqueSum = t;
} }
void RigidBody::SetAngularMomentum( const Float3 &h ) void RigidBody::SetAngularMomentum( const Float3 &h )
{ // by { // by Dan Andersson
this->angularMomentum = h;
} }
void RigidBody::SetAngularImpulseAcceleration( const Float3 &a ) void RigidBody::SetAngularImpulseAcceleration( const Float3 &a )
{ // by { // by Dan Andersson
this->impulseTorqueSum = Formula::ImpulseTorque( this->momentOfInertiaTensor, a );
} }
void RigidBody::SetAngularVelocity( const Float3 &w ) void RigidBody::SetAngularVelocity( const Float3 &w )
{ // by { // by Dan Andersson
this->angularMomentum = Formula::AngularMomentum( this->momentOfInertiaTensor, w );
} }
void RigidBody::SetImpulseForce( const Float3 &f ) void RigidBody::SetImpulseForce( const Float3 &f )
{ // by { // by Dan Andersson
this->impulseForceSum = f;
} }
void RigidBody::SetLinearMomentum( const Float3 &g ) void RigidBody::SetLinearMomentum( const Float3 &g )
{ // by { // by Dan Andersson
this->linearMomentum = g;
} }
void RigidBody::SetLinearImpulseAcceleration( const Float3 &a ) void RigidBody::SetLinearImpulseAcceleration( const Float3 &a )
{ // by { // by Dan Andersson
this->impulseForceSum = Formula::ImpulseForce( this->mass, a );
} }
void RigidBody::SetLinearVelocity( const Float3 &v ) void RigidBody::SetLinearVelocity( const Float3 &v )
{ // by { // by Dan Andersson
this->linearMomentum = Formula::LinearMomentum( this->mass, v );
} }
void RigidBody::SetImpulseForceAt_Local( const Float3 &localForce, const Float3 &localPos ) void RigidBody::SetImpulseForceAt_Local( const Float3 &localForce, const Float3 &localPos )
{ // by { // by Dan Andersson
// Reminder! Impulse force and torque is world values.
Float3 worldForce = ( this->box.orientation * Float4(localForce, 0.0f) ).xyz,
worldPos = ( this->box.orientation * Float4(localPos, 1.0f) ).xyz;
this->SetImpulseForceAt_World( worldForce, worldPos );
} }
void RigidBody::SetImpulseForceAt_World( const Float3 &worldForce, const Float3 &worldPos ) void RigidBody::SetImpulseForceAt_World( const Float3 &worldForce, const Float3 &worldPos )
{ // by { // by Dan Andersson
// Reminder! Impulse force and torque is world values.
this->impulseForceSum = VectorProjection( worldForce, worldPos );
this->impulseTorqueSum = Formula::ImpulseTorque( worldForce, worldPos );
} }
void RigidBody::SetLinearMomentumAt_Local( const Float3 &g, const Float3 &pos ) void RigidBody::SetLinearMomentumAt_Local( const Float3 &localG, const Float3 &localPos )
{ // by { // by Dan Andersson
// Reminder! Linear and angular momentum is world values.
Float3 worldG = ( this->box.orientation * Float4(localG, 0.0f) ).xyz,
worldPos = ( this->box.orientation * Float4(localPos, 1.0f) ).xyz;
this->SetLinearMomentumAt_World( worldG, worldPos );
} }
void RigidBody::SetLinearMomentumAt_World( const Float3 &g, const Float3 &pos ) void RigidBody::SetLinearMomentumAt_World( const Float3 &worldG, const Float3 &worldPos )
{ // by { // by Dan Andersson
// Reminder! Linear and angular momentum is world values.
this->linearMomentum = VectorProjection( worldG, worldPos );
this->angularMomentum = Formula::AngularMomentum( worldG, worldPos );
} }
void RigidBody::SetImpulseAccelerationAt_Local( const Float3 &a, const Float3 &pos ) void RigidBody::SetImpulseAccelerationAt_Local( const Float3 &a, const Float3 &pos )
{ // by { // by Dan Andersson
} }

View File

@ -96,7 +96,7 @@ namespace Oyster { namespace Physics3D
void SetSize( const ::Oyster::Math::Float3 &widthHeight ); void SetSize( const ::Oyster::Math::Float3 &widthHeight );
void SetCenter( const ::Oyster::Math::Float3 &p ); void SetCenter( const ::Oyster::Math::Float3 &p );
void SetImpulsTorque( const ::Oyster::Math::Float3 &t ); void SetImpulseTorque( const ::Oyster::Math::Float3 &t );
void SetAngularMomentum( const ::Oyster::Math::Float3 &h ); void SetAngularMomentum( const ::Oyster::Math::Float3 &h );
void SetAngularImpulseAcceleration( const ::Oyster::Math::Float3 &a ); void SetAngularImpulseAcceleration( const ::Oyster::Math::Float3 &a );
void SetAngularVelocity( const ::Oyster::Math::Float3 &w ); void SetAngularVelocity( const ::Oyster::Math::Float3 &w );

View File

@ -15,8 +15,8 @@ Sphere & Sphere::operator = ( const Sphere &sphere )
return *this; return *this;
} }
::Utility::Memory::UniquePointer<ICollideable> Sphere::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Sphere::Clone( ) const
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Sphere(*this) ); } { return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Sphere(*this) ); }
bool Sphere::Intersects( const ICollideable *target ) const bool Sphere::Intersects( const ICollideable *target ) const
{ {

View File

@ -26,7 +26,7 @@ namespace Oyster { namespace Collision3D
Sphere & operator = ( const Sphere &sphere ); Sphere & operator = ( const Sphere &sphere );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };

View File

@ -2,7 +2,7 @@
#include "OysterCollision3D.h" #include "OysterCollision3D.h"
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Utility::Memory; using namespace ::Utility::DynamicMemory;
Universe::Universe() : ICollideable(Type_universe) {} Universe::Universe() : ICollideable(Type_universe) {}
Universe::~Universe() {} Universe::~Universe() {}

View File

@ -18,7 +18,7 @@ namespace Oyster { namespace Collision3D
Universe & operator = ( const Universe &universe ); Universe & operator = ( const Universe &universe );
virtual ::Utility::Memory::UniquePointer<ICollideable> Clone( ) const; virtual ::Utility::DynamicMemory::UniquePointer<ICollideable> Clone( ) const;
bool Intersects( const ICollideable *target ) const; bool Intersects( const ICollideable *target ) const;
bool Contains( const ICollideable *target ) const; bool Contains( const ICollideable *target ) const;
}; };