Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Some Implementations from ndShapeCompount.h to ndShapeCompount.cpp #267

Merged
merged 2 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions newton-4.00/sdk/dCollision/ndShapeCompound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,93 @@ ndShapeCompound::ndNodeBase::~ndNodeBase()
}
}


ndShapeCompound::ndNodeBase::ndNodeBase()
:ndClassAlloc()
, m_type(m_node)
, m_left(nullptr)
, m_right(nullptr)
, m_parent(nullptr)
, m_myNode(nullptr)
, m_shapeInstance(nullptr)
{
}

ndShapeCompound::ndNodeBase::ndNodeBase(const ndNodeBase& copyFrom)
:ndClassAlloc()
, m_p0(copyFrom.m_p0)
, m_p1(copyFrom.m_p1)
, m_size(copyFrom.m_size)
, m_origin(copyFrom.m_origin)
, m_area(copyFrom.m_area)
, m_type(copyFrom.m_type)
, m_left(nullptr)
, m_right(nullptr)
, m_parent(nullptr)
, m_myNode(nullptr)
, m_shapeInstance(nullptr)
{
dAssert(!copyFrom.m_shapeInstance);
}

ndShapeCompound::ndNodeBase::ndNodeBase(ndShapeInstance* const instance)
:ndClassAlloc()
, m_type(m_leaf)
, m_left(nullptr)
, m_right(nullptr)
, m_parent(nullptr)
, m_myNode(nullptr)
, m_shapeInstance(new ndShapeInstance(*instance))
{
CalculateAABB();
}

ndShapeCompound::ndNodeBase::ndNodeBase(ndNodeBase* const left, ndNodeBase* const right)
:ndClassAlloc()
, m_type(m_node)
, m_left(left)
, m_right(right)
, m_parent(nullptr)
, m_myNode(nullptr)
, m_shapeInstance(nullptr)
{
m_left->m_parent = this;
m_right->m_parent = this;

ndVector p0(left->m_p0.GetMin(right->m_p0));
ndVector p1(left->m_p1.GetMax(right->m_p1));
SetBox(p0, p1);
}

ndShapeInstance* ndShapeCompound::ndNodeBase::GetShape() const
{
return m_shapeInstance;
}

inline void ndShapeCompound::ndNodeBase::CalculateAABB()
{
ndVector p0;
ndVector p1;
m_shapeInstance->CalculateAabb(m_shapeInstance->GetLocalMatrix(), p0, p1);
SetBox(p0, p1);
}

inline void ndShapeCompound::ndNodeBase::SetBox(const ndVector& p0, const ndVector& p1)
{
m_p0 = p0;
m_p1 = p1;
dAssert(m_p0.m_w == ndFloat32(0.0f));
dAssert(m_p1.m_w == ndFloat32(0.0f));
m_size = ndVector::m_half * (m_p1 - m_p0);
m_origin = ndVector::m_half * (m_p1 + m_p0);
m_area = m_size.DotProduct(m_size.ShiftTripleRight()).m_x;
}

const ndShapeCompound::ndTreeArray& ndShapeCompound::GetTree() const
{
return m_array;
}

class ndShapeCompound::ndSpliteInfo
{
public:
Expand Down
89 changes: 2 additions & 87 deletions newton-4.00/sdk/dCollision/ndShapeCompound.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ndShapeCompound: public ndShape

void SetOwner(const ndShapeInstance* const myInstance);

const ndTreeArray& GetTree() const;
D_COLLISION_API const ndTreeArray& GetTree() const;

D_COLLISION_API virtual void BeginAddRemove();
D_COLLISION_API virtual ndTreeArray::ndNode* AddCollision(ndShapeInstance* const part);
Expand Down Expand Up @@ -125,7 +125,7 @@ class ndShapeCompound::ndNodeBase: public ndClassAlloc
~ndNodeBase();

//void Sanity(int level = 0);
ndShapeInstance* GetShape() const;
D_COLLISION_API ndShapeInstance* GetShape() const;

private:
void CalculateAABB();
Expand All @@ -149,91 +149,6 @@ class ndShapeCompound::ndNodeBase: public ndClassAlloc
friend class ndStackBvhStackEntry;
};

inline ndShapeCompound::ndNodeBase::ndNodeBase()
:ndClassAlloc()
,m_type(m_node)
,m_left(nullptr)
,m_right(nullptr)
,m_parent(nullptr)
,m_myNode(nullptr)
,m_shapeInstance(nullptr)
{
}

inline ndShapeCompound::ndNodeBase::ndNodeBase(const ndNodeBase& copyFrom)
:ndClassAlloc()
,m_p0(copyFrom.m_p0)
,m_p1(copyFrom.m_p1)
,m_size(copyFrom.m_size)
,m_origin(copyFrom.m_origin)
,m_area(copyFrom.m_area)
,m_type(copyFrom.m_type)
,m_left(nullptr)
,m_right(nullptr)
,m_parent(nullptr)
,m_myNode(nullptr)
,m_shapeInstance(nullptr)
{
dAssert(!copyFrom.m_shapeInstance);
}

inline ndShapeCompound::ndNodeBase::ndNodeBase(ndShapeInstance* const instance)
:ndClassAlloc()
,m_type(m_leaf)
,m_left(nullptr)
,m_right(nullptr)
,m_parent(nullptr)
,m_myNode(nullptr)
,m_shapeInstance(new ndShapeInstance(*instance))
{
CalculateAABB();
}

inline ndShapeCompound::ndNodeBase::ndNodeBase(ndNodeBase* const left, ndNodeBase* const right)
:ndClassAlloc()
,m_type(m_node)
,m_left(left)
,m_right(right)
,m_parent(nullptr)
,m_myNode(nullptr)
,m_shapeInstance(nullptr)
{
m_left->m_parent = this;
m_right->m_parent = this;

ndVector p0(left->m_p0.GetMin(right->m_p0));
ndVector p1(left->m_p1.GetMax(right->m_p1));
SetBox(p0, p1);
}

inline ndShapeInstance* ndShapeCompound::ndNodeBase::GetShape() const
{
return m_shapeInstance;
}

inline void ndShapeCompound::ndNodeBase::CalculateAABB()
{
ndVector p0;
ndVector p1;
m_shapeInstance->CalculateAabb(m_shapeInstance->GetLocalMatrix(), p0, p1);
SetBox(p0, p1);
}

inline void ndShapeCompound::ndNodeBase::SetBox(const ndVector& p0, const ndVector& p1)
{
m_p0 = p0;
m_p1 = p1;
dAssert(m_p0.m_w == ndFloat32(0.0f));
dAssert(m_p1.m_w == ndFloat32(0.0f));
m_size = ndVector::m_half * (m_p1 - m_p0);
m_origin = ndVector::m_half * (m_p1 + m_p0);
m_area = m_size.DotProduct(m_size.ShiftTripleRight()).m_x;
}

inline const ndShapeCompound::ndTreeArray& ndShapeCompound::GetTree() const
{
return m_array;
}

#endif

Expand Down
4 changes: 3 additions & 1 deletion newton-4.00/sdk/dNewton/ndLoadSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*
* 3. This notice may not be removed or altered from any source distribution.
*/

#include "ndCollisionStdafx.h"
#include "ndCoreStdafx.h"
#include "ndNewtonStdafx.h"
#include "ndWorld.h"
#include "ndModel.h"
#include "ndLoadSave.h"
#include "ndShapeCompound.h"
#include "ndShapeInstance.h"
#include "ndBodyDynamic.h"

D_CLASS_REFLECTION_IMPLEMENT_LOADER(ndWordSettings);
Expand Down