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

Added function to retrieve ShapeFrames from CollisionGroups #711

Merged
merged 1 commit into from
May 2, 2016
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
11 changes: 11 additions & 0 deletions dart/collision/CollisionGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ std::size_t CollisionGroup::getNumShapeFrames() const
return mShapeFrameMap.size();
}

//==============================================================================
const dynamics::ShapeFrame* CollisionGroup::getShapeFrame(
std::size_t index) const
{
assert(index < mShapeFrameMap.size());
if(index < mShapeFrameMap.size())
return mShapeFrameMap[index].first;

return nullptr;
}

//==============================================================================
bool CollisionGroup::collide(const CollisionOption& option, CollisionResult& result)
{
Expand Down
3 changes: 3 additions & 0 deletions dart/collision/CollisionGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class CollisionGroup
/// Return number of ShapeFrames added to this CollisionGroup
std::size_t getNumShapeFrames() const;

/// Get the ShapeFrame corresponding to the given index
const dynamics::ShapeFrame* getShapeFrame(std::size_t index) const;

/// Perform collision detection within this CollisionGroup.
bool collide(const CollisionOption& option, CollisionResult& result);

Expand Down
13 changes: 13 additions & 0 deletions unittests/testCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,19 @@ void testSimpleFrames(const std::shared_ptr<CollisionDetector>& cd)
+ group2->getNumShapeFrames()
+ group3->getNumShapeFrames());

for(std::size_t i=0; i < group1->getNumShapeFrames(); ++i)
EXPECT_EQ(groupAll->getShapeFrame(i), group1->getShapeFrame(i));

std::size_t start = group1->getNumShapeFrames();
std::size_t end = start + group2->getNumShapeFrames();
for(std::size_t i=start; i < end; ++i)
EXPECT_EQ(groupAll->getShapeFrame(i), group2->getShapeFrame(i-start));

start = start + group2->getNumShapeFrames();
end = start + group3->getNumShapeFrames();
for(std::size_t i=start; i < end; ++i)
EXPECT_EQ(groupAll->getShapeFrame(i), group3->getShapeFrame(i-start));

collision::CollisionOption option;
collision::CollisionResult result;

Expand Down