Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius committed Mar 15, 2018
1 parent b4ea730 commit 3747690
Show file tree
Hide file tree
Showing 55 changed files with 5,746 additions and 1,438 deletions.
36 changes: 21 additions & 15 deletions OpcodeDistrib/OPC_AABB.cpp → OpcodeDistrib/IceAABB.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
* OPCODE - Optimized Collision Detection
* Copyright (C) 2001 Pierre Terdiman
* Homepage: http://www.codercorner.com/Opcode.htm
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Contains AABB-related code.
* \file OPC_AABB.cpp
* \file IceAABB.cpp
* \author Pierre Terdiman
* \date January, 29, 2000
*/
Expand All @@ -28,13 +20,9 @@
// Precompiled Header
#include "Stdafx.h"

using namespace Opcode;

#ifndef __MESHMERIZER_H__

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to compute the sum of two AABBs.
* Computes the sum of two AABBs.
* \param aabb [in] the other AABB
* \return Self-Reference
*/
Expand All @@ -55,4 +43,22 @@ AABB& AABB::Add(const AABB& aabb)
return *this;
}

#endif // __MESHMERIZER_H__
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Checks a box is inside another box.
* \param box [in] the other AABB
* \return true if current box is inside input box
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool AABB::IsInside(const AABB& box) const
{
if(box.GetMin(0)>GetMin(0)) return false;
if(box.GetMin(1)>GetMin(1)) return false;
if(box.GetMin(2)>GetMin(2)) return false;
if(box.GetMax(0)<GetMax(0)) return false;
if(box.GetMax(1)<GetMax(1)) return false;
if(box.GetMax(2)<GetMax(2)) return false;
return true;
}


223 changes: 196 additions & 27 deletions OpcodeDistrib/OPC_AABB.h → OpcodeDistrib/IceAABB.h

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions OpcodeDistrib/IceBoundingSphere.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Contains code to compute the minimal bounding sphere.
* \file IceBoundingSphere.h
* \author Pierre Terdiman
* \date January, 29, 2000
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Guard
#ifndef __ICEBOUNDINGSPHERE_H__
#define __ICEBOUNDINGSPHERE_H__

class MESHMERIZER_API Sphere
{
public:
// Constructor/Destructor
Sphere() {}
Sphere(const Point& center, float radius) : mCenter(center), mRadius(radius) {}
Sphere(const udword n, Point* p);

bool Compute(udword nbverts, Point* verts);
bool FastCompute(udword nbverts, Point* verts);

// Access methods
__forceinline const Point& GetCenter() const { return mCenter; }
__forceinline float GetRadius() const { return mRadius; }

__forceinline const Point& Center() const { return mCenter; }
__forceinline float Radius() const { return mRadius; }

__forceinline Sphere& Set(const Point& center, float radius) { mCenter = center; mRadius = radius; return *this; }
__forceinline Sphere& SetCenter(const Point& center) { mCenter = center; return *this; }
__forceinline Sphere& SetRadius(float radius) { mRadius = radius; return *this; }

public:
Point mCenter; //!< Sphere center
float mRadius; //!< Sphere radius
};

#endif // __ICEBOUNDINGSPHERE_H__
133 changes: 114 additions & 19 deletions OpcodeDistrib/OPC_Container.cpp → OpcodeDistrib/IceContainer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
* OPCODE - Optimized Collision Detection
* Copyright (C) 2001 Pierre Terdiman
* Homepage: http://www.codercorner.com/Opcode.htm
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Contains a simple container class.
Expand All @@ -32,10 +24,6 @@
// Precompiled Header
#include "Stdafx.h"

using namespace Opcode;

#ifndef __ICECORE_H__

// Static members
#ifdef CONTAINER_STATS
udword Container::mNbContainers = 0;
Expand All @@ -47,14 +35,28 @@ udword Container::mUsedRam = 0;
* Constructor. No entries allocated there.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Container::Container() : mMaxNbEntries(0), mCurNbEntries(0), mEntries(null)
Container::Container() : mMaxNbEntries(0), mCurNbEntries(0), mEntries(null), mGrowthFactor(2.0f)
{
#ifdef CONTAINER_STATS
mNbContainers++;
mUsedRam+=sizeof(Container);
#endif
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor. Also allocates a given number of entries.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Container::Container(udword size, float growthfactor) : mMaxNbEntries(0), mCurNbEntries(0), mEntries(null), mGrowthFactor(growthfactor)
{
#ifdef CONTAINER_STATS
mNbContainers++;
mUsedRam+=sizeof(Container);
#endif
SetSize(size);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor. Frees everything and leaves.
Expand Down Expand Up @@ -82,8 +84,8 @@ bool Container::Resize()
mUsedRam-=mMaxNbEntries*sizeof(udword);
#endif

// Get twice as many entries as before
mMaxNbEntries = mMaxNbEntries ? (mMaxNbEntries<<1) : 2; // Default nb Entries = 2
// Get more entries
mMaxNbEntries = mMaxNbEntries ? udword(float(mMaxNbEntries)*mGrowthFactor) : 2; // Default nb Entries = 2

// Get some bytes for new entries
udword* NewEntries = new udword[mMaxNbEntries];
Expand All @@ -106,6 +108,73 @@ bool Container::Resize()
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to set the initial size of the container. If it already contains something, it's discarded.
* \param nb [in] Number of entries
* \return true if success
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Container::SetSize(udword nb)
{
// Make sure it's empty
Empty();

// Checkings
if(!nb) return false;

// Initialize for nb entries
mMaxNbEntries = nb;

// Get some bytes for new entries
mEntries = new udword[mMaxNbEntries];
CHECKALLOC(mEntries);

#ifdef CONTAINER_STATS
// Add current amount of bytes
mUsedRam+=mMaxNbEntries*sizeof(udword);
#endif
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to refit the container and get rid of unused bytes.
* \return true if success
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Container::Refit()
{
#ifdef CONTAINER_STATS
// Subtract previous amount of bytes
mUsedRam-=mMaxNbEntries*sizeof(udword);
#endif

// Get just enough entries
mMaxNbEntries = mCurNbEntries;
if(!mMaxNbEntries) return false;

// Get just enough bytes
udword* NewEntries = new udword[mMaxNbEntries];
CHECKALLOC(NewEntries);

#ifdef CONTAINER_STATS
// Add current amount of bytes
mUsedRam+=mMaxNbEntries*sizeof(udword);
#endif

// Copy old data
CopyMemory(NewEntries, mEntries, mCurNbEntries*sizeof(udword));

// Delete old data
DELETEARRAY(mEntries);

// Assign new pointer
mEntries = NewEntries;

return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to check whether the container already contains a given value.
Expand Down Expand Up @@ -136,7 +205,7 @@ bool Container::Contains(udword entry, udword* location) const
* A method to delete an entry. If the container contains such an entry, it's removed.
* \param entry [in] the value to delete.
* \return true if the value has been found in the container, else false.
* \warning this method is arbitrary slow and should be used carefully.
* \warning This method is arbitrary slow (O(n)) and should be used carefully. Insertion order is not preserved.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Container::Delete(udword entry)
Expand All @@ -147,7 +216,35 @@ bool Container::Delete(udword entry)
if(mEntries[i]==entry)
{
// Entry has been found at index i. The strategy is to copy the last current entry at index i, and decrement the current number of entries.
mEntries[i] = mEntries[--mCurNbEntries];
DeleteIndex(i);
return true;
}
}
return false;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to delete an entry, preserving the insertion order. If the container contains such an entry, it's removed.
* \param entry [in] the value to delete.
* \return true if the value has been found in the container, else false.
* \warning This method is arbitrary slow (O(n)) and should be used carefully.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Container::DeleteKeepingOrder(udword entry)
{
// Look for the entry
for(udword i=0;i<mCurNbEntries;i++)
{
if(mEntries[i]==entry)
{
// Entry has been found at index i.
// Shift entries to preserve order. You really should use a linked list instead.
mCurNbEntries--;
for(udword j=i;j<mCurNbEntries;j++)
{
mEntries[j] = mEntries[j+1];
}
return true;
}
}
Expand Down Expand Up @@ -204,5 +301,3 @@ udword Container::GetUsedRam() const
{
return sizeof(Container) + mMaxNbEntries * sizeof(udword);
}

#endif // __ICECORE_H__
Loading

0 comments on commit 3747690

Please sign in to comment.