Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c59ff507 authored by Frederik Schwarzer's avatar Frederik Schwarzer

Revert "Pull in new Version of Box2D."

This was not meant to be here.

This reverts commit a0517724.
parent 174df03b
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BOX2D_H
#define BOX2D_H
/**
\mainpage Box2D API Documentation
\section intro_sec Getting Started
For documentation please see http://box2d.org/documentation.html
For discussion please visit http://box2d.org/forum
*/
// These include files constitute the main Box2D API
#include <Box2D/Common/b2Settings.h>
#include <Box2D/Common/b2Draw.h>
#include <Box2D/Common/b2Timer.h>
#include <Box2D/Collision/Shapes/b2CircleShape.h>
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
#include <Box2D/Collision/Shapes/b2ChainShape.h>
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
#include <Box2D/Collision/b2BroadPhase.h>
#include <Box2D/Collision/b2Distance.h>
#include <Box2D/Collision/b2DynamicTree.h>
#include <Box2D/Collision/b2TimeOfImpact.h>
#include <Box2D/Dynamics/b2Body.h>
#include <Box2D/Dynamics/b2Fixture.h>
#include <Box2D/Dynamics/b2WorldCallbacks.h>
#include <Box2D/Dynamics/b2TimeStep.h>
#include <Box2D/Dynamics/b2World.h>
#include <Box2D/Dynamics/Contacts/b2Contact.h>
#include <Box2D/Dynamics/Joints/b2DistanceJoint.h>
#include <Box2D/Dynamics/Joints/b2FrictionJoint.h>
#include <Box2D/Dynamics/Joints/b2GearJoint.h>
#include <Box2D/Dynamics/Joints/b2MotorJoint.h>
#include <Box2D/Dynamics/Joints/b2MouseJoint.h>
#include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
#include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>
#include <Box2D/Dynamics/Joints/b2RopeJoint.h>
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>
#include <Box2D/Dynamics/Joints/b2WheelJoint.h>
#endif
# -*- cmake -*-
#
# Box2dConfig.cmake(.in)
#
# Use the following variables to compile and link against Box2d:
# BOX2D_FOUND - True if Box2d was found on your system
# BOX2D_USE_FILE - The file making Box2d usable
# BOX2D_DEFINITIONS - Definitions needed to build with Box2d
# BOX2D_INCLUDE_DIR - Box2d headers location
# BOX2D_INCLUDE_DIRS - List of directories where Box2d header file are
# BOX2D_LIBRARY - Library name
# BOX2D_LIBRARIES - List of libraries to link against
# BOX2D_LIBRARY_DIRS - List of directories containing Box2d libraries
# BOX2D_ROOT_DIR - The base directory of Box2d
# BOX2D_VERSION_STRING - A human-readable string containing the version
set ( BOX2D_FOUND 1 )
set ( BOX2D_USE_FILE "@BOX2D_USE_FILE@" )
set ( BOX2D_DEFINITIONS "@BOX2D_DEFINITIONS@" )
set ( BOX2D_INCLUDE_DIR "@BOX2D_INCLUDE_DIR@" )
set ( Box2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) # deprecated
set ( BOX2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" )
set ( BOX2D_LIBRARY "@BOX2D_LIBRARY@" )
set ( BOX2D_LIBRARIES "@BOX2D_LIBRARIES@" )
set ( BOX2D_LIBRARY_DIRS "@BOX2D_LIBRARY_DIRS@" )
set ( BOX2D_ROOT_DIR "@CMAKE_INSTALL_PREFIX@" )
set ( BOX2D_VERSION_STRING "@BOX2D_VERSION@" )
set(BOX2D_Collision_SRCS
Collision/b2BroadPhase.cpp
Collision/b2CollideCircle.cpp
Collision/b2CollideEdge.cpp
Collision/b2CollidePolygon.cpp
Collision/b2Collision.cpp
Collision/b2Distance.cpp
Collision/b2DynamicTree.cpp
Collision/b2TimeOfImpact.cpp
)
set(BOX2D_Collision_HDRS
Collision/b2BroadPhase.h
Collision/b2Collision.h
Collision/b2Distance.h
Collision/b2DynamicTree.h
Collision/b2TimeOfImpact.h
)
set(BOX2D_Shapes_SRCS
Collision/Shapes/b2CircleShape.cpp
Collision/Shapes/b2EdgeShape.cpp
Collision/Shapes/b2ChainShape.cpp
Collision/Shapes/b2PolygonShape.cpp
)
set(BOX2D_Shapes_HDRS
Collision/Shapes/b2CircleShape.h
Collision/Shapes/b2EdgeShape.h
Collision/Shapes/b2ChainShape.h
Collision/Shapes/b2PolygonShape.h
Collision/Shapes/b2Shape.h
)
set(BOX2D_Common_SRCS
Common/b2BlockAllocator.cpp
Common/b2Draw.cpp
Common/b2Math.cpp
Common/b2Settings.cpp
Common/b2StackAllocator.cpp
Common/b2Timer.cpp
)
set(BOX2D_Common_HDRS
Common/b2BlockAllocator.h
Common/b2Draw.h
Common/b2GrowableStack.h
Common/b2Math.h
Common/b2Settings.h
Common/b2StackAllocator.h
Common/b2Timer.h
)
set(BOX2D_Dynamics_SRCS
Dynamics/b2Body.cpp
Dynamics/b2ContactManager.cpp
Dynamics/b2Fixture.cpp
Dynamics/b2Island.cpp
Dynamics/b2World.cpp
Dynamics/b2WorldCallbacks.cpp
)
set(BOX2D_Dynamics_HDRS
Dynamics/b2Body.h
Dynamics/b2ContactManager.h
Dynamics/b2Fixture.h
Dynamics/b2Island.h
Dynamics/b2TimeStep.h
Dynamics/b2World.h
Dynamics/b2WorldCallbacks.h
)
set(BOX2D_Contacts_SRCS
Dynamics/Contacts/b2CircleContact.cpp
Dynamics/Contacts/b2Contact.cpp
Dynamics/Contacts/b2ContactSolver.cpp
Dynamics/Contacts/b2PolygonAndCircleContact.cpp
Dynamics/Contacts/b2EdgeAndCircleContact.cpp
Dynamics/Contacts/b2EdgeAndPolygonContact.cpp
Dynamics/Contacts/b2ChainAndCircleContact.cpp
Dynamics/Contacts/b2ChainAndPolygonContact.cpp
Dynamics/Contacts/b2PolygonContact.cpp
)
set(BOX2D_Contacts_HDRS
Dynamics/Contacts/b2CircleContact.h
Dynamics/Contacts/b2Contact.h
Dynamics/Contacts/b2ContactSolver.h
Dynamics/Contacts/b2PolygonAndCircleContact.h
Dynamics/Contacts/b2EdgeAndCircleContact.h
Dynamics/Contacts/b2EdgeAndPolygonContact.h
Dynamics/Contacts/b2ChainAndCircleContact.h
Dynamics/Contacts/b2ChainAndPolygonContact.h
Dynamics/Contacts/b2PolygonContact.h
)
set(BOX2D_Joints_SRCS
Dynamics/Joints/b2DistanceJoint.cpp
Dynamics/Joints/b2FrictionJoint.cpp
Dynamics/Joints/b2GearJoint.cpp
Dynamics/Joints/b2Joint.cpp
Dynamics/Joints/b2MotorJoint.cpp
Dynamics/Joints/b2MouseJoint.cpp
Dynamics/Joints/b2PrismaticJoint.cpp
Dynamics/Joints/b2PulleyJoint.cpp
Dynamics/Joints/b2RevoluteJoint.cpp
Dynamics/Joints/b2RopeJoint.cpp
Dynamics/Joints/b2WeldJoint.cpp
Dynamics/Joints/b2WheelJoint.cpp
)
set(BOX2D_Joints_HDRS
Dynamics/Joints/b2DistanceJoint.h
Dynamics/Joints/b2FrictionJoint.h
Dynamics/Joints/b2GearJoint.h
Dynamics/Joints/b2Joint.h
Dynamics/Joints/b2MotorJoint.h
Dynamics/Joints/b2MouseJoint.h
Dynamics/Joints/b2PrismaticJoint.h
Dynamics/Joints/b2PulleyJoint.h
Dynamics/Joints/b2RevoluteJoint.h
Dynamics/Joints/b2RopeJoint.h
Dynamics/Joints/b2WeldJoint.h
Dynamics/Joints/b2WheelJoint.h
)
set(BOX2D_Rope_SRCS
Rope/b2Rope.cpp
)
set(BOX2D_Rope_HDRS
Rope/b2Rope.h
)
set(BOX2D_General_HDRS
Box2D.h
)
include_directories( ../ )
if(BOX2D_BUILD_SHARED)
add_library(Box2D_shared SHARED
${BOX2D_General_HDRS}
${BOX2D_Joints_SRCS}
${BOX2D_Joints_HDRS}
${BOX2D_Contacts_SRCS}
${BOX2D_Contacts_HDRS}
${BOX2D_Dynamics_SRCS}
${BOX2D_Dynamics_HDRS}
${BOX2D_Common_SRCS}
${BOX2D_Common_HDRS}
${BOX2D_Shapes_SRCS}
${BOX2D_Shapes_HDRS}
${BOX2D_Collision_SRCS}
${BOX2D_Collision_HDRS}
${BOX2D_Rope_SRCS}
${BOX2D_Rope_HDRS}
)
set_target_properties(Box2D_shared PROPERTIES
OUTPUT_NAME "Box2D"
CLEAN_DIRECT_OUTPUT 1
VERSION ${BOX2D_VERSION}
)
endif()
if(BOX2D_BUILD_STATIC)
add_library(Box2D STATIC
${BOX2D_General_HDRS}
${BOX2D_Joints_SRCS}
${BOX2D_Joints_HDRS}
${BOX2D_Contacts_SRCS}
${BOX2D_Contacts_HDRS}
${BOX2D_Dynamics_SRCS}
${BOX2D_Dynamics_HDRS}
${BOX2D_Common_SRCS}
${BOX2D_Common_HDRS}
${BOX2D_Shapes_SRCS}
${BOX2D_Shapes_HDRS}
${BOX2D_Collision_SRCS}
${BOX2D_Collision_HDRS}
${BOX2D_Rope_SRCS}
${BOX2D_Rope_HDRS}
)
set_target_properties(Box2D PROPERTIES
CLEAN_DIRECT_OUTPUT 1
VERSION ${BOX2D_VERSION}
)
endif()
# These are used to create visual studio folders.
source_group(Collision FILES ${BOX2D_Collision_SRCS} ${BOX2D_Collision_HDRS})
source_group(Collision\\Shapes FILES ${BOX2D_Shapes_SRCS} ${BOX2D_Shapes_HDRS})
source_group(Common FILES ${BOX2D_Common_SRCS} ${BOX2D_Common_HDRS})
source_group(Dynamics FILES ${BOX2D_Dynamics_SRCS} ${BOX2D_Dynamics_HDRS})
source_group(Dynamics\\Contacts FILES ${BOX2D_Contacts_SRCS} ${BOX2D_Contacts_HDRS})
source_group(Dynamics\\Joints FILES ${BOX2D_Joints_SRCS} ${BOX2D_Joints_HDRS})
source_group(Include FILES ${BOX2D_General_HDRS})
source_group(Rope FILES ${BOX2D_Rope_SRCS} ${BOX2D_Rope_HDRS})
if(BOX2D_INSTALL)
# install headers
install(FILES ${BOX2D_General_HDRS} DESTINATION include/Box2D)
install(FILES ${BOX2D_Collision_HDRS} DESTINATION include/Box2D/Collision)
install(FILES ${BOX2D_Shapes_HDRS} DESTINATION include/Box2D/Collision/Shapes)
install(FILES ${BOX2D_Common_HDRS} DESTINATION include/Box2D/Common)
install(FILES ${BOX2D_Dynamics_HDRS} DESTINATION include/Box2D/Dynamics)
install(FILES ${BOX2D_Contacts_HDRS} DESTINATION include/Box2D/Dynamics/Contacts)
install(FILES ${BOX2D_Joints_HDRS} DESTINATION include/Box2D/Dynamics/Joints)
install(FILES ${BOX2D_Rope_HDRS} DESTINATION include/Box2D/Rope)
# install libraries
if(BOX2D_BUILD_SHARED)
install(TARGETS Box2D_shared EXPORT Box2D-targets
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION bin)
endif()
if(BOX2D_BUILD_STATIC)
install(TARGETS Box2D EXPORT Box2D-targets DESTINATION ${LIB_INSTALL_DIR})
endif()
# install build system hooks for third-party apps
install(EXPORT Box2D-targets DESTINATION ${LIB_INSTALL_DIR}/Box2D)
set (BOX2D_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
set (BOX2D_INCLUDE_DIRS ${BOX2D_INCLUDE_DIR} )
set (BOX2D_LIBRARY_DIRS ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR})
set (BOX2D_LIBRARY Box2D)
set (BOX2D_LIBRARIES ${BOX2D_LIBRARY})
set (BOX2D_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/cmake/Box2D/UseBox2D.cmake)
configure_file(Box2DConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/Box2DConfig.cmake @ONLY ESCAPE_QUOTES)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Box2DConfig.cmake UseBox2D.cmake DESTINATION ${LIB_INSTALL_DIR}/cmake/Box2D)
endif(BOX2D_INSTALL)
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
......@@ -18,6 +18,7 @@
#include <Box2D/Collision/Shapes/b2CircleShape.h>
#include <new>
using namespace std;
b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
{
......@@ -34,7 +35,7 @@ int32 b2CircleShape::GetChildCount() const
bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
{
b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
b2Vec2 center = transform.position + b2Mul(transform.R, m_p);
b2Vec2 d = p - center;
return b2Dot(d, d) <= m_radius * m_radius;
}
......@@ -48,15 +49,15 @@ bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input
{
B2_NOT_USED(childIndex);
b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
b2Vec2 position = transform.position + b2Mul(transform.R, m_p);
b2Vec2 s = input.p1 - position;
float32 b = b2Dot(s, s) - m_radius * m_radius;
qreal b = b2Dot(s, s) - m_radius * m_radius;
// Solve quadratic equation.
b2Vec2 r = input.p2 - input.p1;
float32 c = b2Dot(s, r);
float32 rr = b2Dot(r, r);
float32 sigma = c * c - rr * b;
qreal c = b2Dot(s, r);
qreal rr = b2Dot(r, r);
qreal sigma = c * c - rr * b;
// Check for negative discriminant and short segment.
if (sigma < 0.0f || rr < b2_epsilon)
......@@ -65,7 +66,7 @@ bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input
}
// Find the point of intersection of the line with the circle.
float32 a = -(c + b2Sqrt(sigma));
qreal a = -(c + b2Sqrt(sigma));
// Is the intersection point on the segment?
if (0.0f <= a && a <= input.maxFraction * rr)
......@@ -84,12 +85,12 @@ void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int3
{
B2_NOT_USED(childIndex);
b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
b2Vec2 p = transform.position + b2Mul(transform.R, m_p);
aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
}
void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
void b2CircleShape::ComputeMass(b2MassData* massData, qreal density) const
{
massData->mass = density * b2_pi * m_radius * m_radius;
massData->center = m_p;
......
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
......@@ -44,7 +44,7 @@ public:
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
/// @see b2Shape::ComputeMass
void ComputeMass(b2MassData* massData, float32 density) const;
void ComputeMass(b2MassData* massData, qreal density) const;
/// Get the supporting vertex index in the given direction.
int32 GetSupport(const b2Vec2& d) const;
......
/*
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
......@@ -18,6 +18,7 @@
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
#include <new>
using namespace std;
void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)
{
......@@ -57,8 +58,8 @@ bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
B2_NOT_USED(childIndex);
// Put the ray into the edge's frame of reference.
b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
b2Vec2 p1 = b2MulT(xf.R, input.p1 - xf.position);
b2Vec2 p2 = b2MulT(xf.R, input.p2 - xf.position);
b2Vec2 d = p2 - p1;
b2Vec2 v1 = m_vertex1;
......@@ -70,16 +71,16 @@ bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
// q = p1 + t * d
// dot(normal, q - v1) = 0
// dot(normal, p1 - v1) + t * dot(normal, d) = 0
float32 numerator = b2Dot(normal, v1 - p1);
float32 denominator = b2Dot(normal, d);
qreal numerator = b2Dot(normal, v1 - p1);
qreal denominator = b2Dot(normal, d);
if (denominator == 0.0f)
{
return false;
}
float32 t = numerator / denominator;
if (t < 0.0f || input.maxFraction < t)
qreal t = numerator / denominator;
if (t < 0.0f || 1.0f < t)
{
return false;
}
......@@ -89,13 +90,13 @@ bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
// q = v1 + s * r
// s = dot(q - v1, r) / dot(r, r)
b2Vec2 r = v2 - v1;
float32 rr = b2Dot(r, r);
qreal rr = b2Dot(r, r);
if (rr == 0.0f)
{
return false;
}
float32 s = b2Dot(q - v1, r) / rr;
qreal s = b2Dot(q - v1, r) / rr;
if (s < 0.0f || 1.0f < s)
{
return false;
......@@ -104,11 +105,11 @@ bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
output->fraction = t;
if (numerator > 0.0f)
{
output->normal = -b2Mul(xf.q, normal);
output->normal = -normal;
}
else
{
output->normal = b2Mul(xf.q, normal);
output->normal = normal;
}
return true;
}
......@@ -128,7 +129,7 @@ void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIn
aabb->upperBound = upper + r;
}
void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const
void b2EdgeShape::ComputeMass(b2MassData* massData, qreal density) const
{
B2_NOT_USED(density);
......
/*
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
......@@ -49,7 +49,7 @@ public:
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
/// @see b2Shape::ComputeMass
void ComputeMass(b2MassData* massData, float32 density) const;
void ComputeMass(b2MassData* massData, qreal density) const;
/// These are the edge vertices
b2Vec2 m_vertex1, m_vertex2;
......@@ -63,10 +63,6 @@ inline b2EdgeShape::b2EdgeShape()
{
m_type = e_edge;
m_radius = b2_polygonRadius;
m_vertex0.x = 0.0f;
m_vertex0.y = 0.0f;
m_vertex3.x = 0.0f;
m_vertex3.y = 0.0f;
m_hasVertex0 = false;
m_hasVertex3 = false;
}
......
/*
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
......@@ -16,136 +16,73 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <Box2D/Collision/Shapes/b2ChainShape.h>
#include <Box2D/Collision/Shapes/b2LoopShape.h>
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
#include <new>
#include <string.h>
#include <cstring>
using namespace std;
b2ChainShape::~b2ChainShape()
{
Clear();
}
void b2ChainShape::Clear()
b2LoopShape::~b2LoopShape()
{
b2Free(m_vertices);
m_vertices = NULL;
m_count = 0;
}
void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
{
b2Assert(m_vertices == NULL && m_count == 0);
b2Assert(count >= 3);
for (int32 i = 1; i < count; ++i)
{
b2Vec2 v1 = vertices[i-1];
b2Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
b2Assert(b2DistanceSquared(v1, v2) > b2_linearSlop * b2_linearSlop);
}
m_count = count + 1;
m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
m_vertices[count] = m_vertices[0];
m_prevVertex = m_vertices[m_count - 2];
m_nextVertex = m_vertices[1];
m_hasPrevVertex = true;
m_hasNextVertex = true;
}
void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
void b2LoopShape::Create(const b2Vec2* vertices, int32 count)
{
b2Assert(m_vertices == NULL && m_count == 0);
b2Assert(count >= 2);
for (int32 i = 1; i < count; ++i)
{
// If the code crashes here, it means your vertices are too close together.
b2Assert(b2DistanceSquared(vertices[i-1], vertices[i]) > b2_linearSlop * b2_linearSlop);
}
m_count = count;
m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
m_hasPrevVertex = false;
m_hasNextVertex = false;
m_prevVertex.SetZero();
m_nextVertex.SetZero();
}
void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
b2Shape* b2LoopShape::Clone(b2BlockAllocator* allocator) const
{
m_prevVertex = prevVertex;
m_hasPrevVertex = true;
}
void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
{
m_nextVertex = nextVertex;
m_hasNextVertex = true;
}
b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
{
void* mem = allocator->Allocate(sizeof(b2ChainShape));
b2ChainShape* clone = new (mem) b2ChainShape;
clone->CreateChain(m_vertices, m_count);
clone->m_prevVertex = m_prevVertex;
clone->m_nextVertex = m_nextVertex;
clone->m_hasPrevVertex = m_hasPrevVertex;
clone->m_hasNextVertex = m_hasNextVertex;
void* mem = allocator->Allocate(sizeof(b2LoopShape));
b2LoopShape* clone = new (mem) b2LoopShape;
clone->Create(m_vertices, m_count);
return clone;
}
int32 b2ChainShape::GetChildCount() const
int32 b2LoopShape::GetChildCount() const
{
// edge count = vertex count - 1
return m_count - 1;
return m_count;
}
void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
void b2LoopShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
{
b2Assert(0 <= index && index < m_count - 1);
b2Assert(2 <= m_count);
b2Assert(0 <= index && index < m_count);
edge->m_type = b2Shape::e_edge;
edge->m_radius = m_radius;
edge->m_vertex1 = m_vertices[index + 0];
edge->m_vertex2 = m_vertices[index + 1];
if (index > 0)
{
edge->m_vertex0 = m_vertices[index - 1];
edge->m_hasVertex0 = true;
}
else
edge->m_hasVertex0 = true;