My Project: dynamics.mod/NewtonDynamics/source/physics/dgCollisionSphere.h Source File

My Project

dgCollisionSphere.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef _DG_COLLISION_SPHERE_H__
23 #define _DG_COLLISION_SPHERE_H__
24
25
26 #include "dgCollisionConvex.h"
27
28 #define DG_SPHERE_VERTEX_COUNT 18
29
30 class dgCollisionSphere: public dgCollisionConvex
31 {
32 public:
33 dgCollisionSphere(dgMemoryAllocator* allocator, dgUnsigned32 signature, dgFloat32 radius);
34 dgCollisionSphere(dgWorld* const world, dgDeserialize deserialization, void* const userData);
35 virtual ~dgCollisionSphere();
36
37
38 protected:
39 void Init (dgFloat32 radius, dgMemoryAllocator* allocator);
40 virtual dgVector SupportVertex (const dgVector& dir, dgInt32* const vertexIndex) const;
41
42 virtual void CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const;
43 virtual void DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const;
44 virtual dgFloat32 RayCast (const dgVector& localP0, const dgVector& localP1, dgFloat32 maxT, dgContactPoint& contactOut, const dgBody* const body, void* const userData, OnRayPrecastAction preFilter) const;
45
46 void TesselateTriangle (dgInt32 level, const dgVector& p0, const dgVector& p1, const dgVector& p2, dgInt32& count, dgVector* ouput) const;
47
48 // private:
49 static dgInt32 CalculateSignature (dgFloat32 radius);
50
51 virtual dgInt32 CalculateSignature () const;
52 virtual void SetCollisionBBox (const dgVector& p0, const dgVector& p1);
53
54 virtual void MassProperties ();
55
56 virtual dgInt32 CalculatePlaneIntersection (const dgVector& normal, const dgVector& point, dgVector* const contactsOut, dgFloat32 normalSign) const;
57
58 virtual void GetCollisionInfo(dgCollisionInfo* const info) const;
59 virtual void Serialize(dgSerialize callback, void* const userData) const;
60
61 // special feature based contact calculation for conics convex (ex spheres, capsules, tapered capsules, and chamfered cylinders)
62 // in newton we only deal with sub set of conic function, that can be expressed by the equation
63 // ((x - x0) / a)^2 + ((y - y0) / b)^2 + ((z - z0) / c)^2 = 1 and possible a linear or circular sweep of the same equation
64 // this preclude parabolic and hyperbolic conics
65 virtual dgVector ConvexConicSupporVertex (const dgVector& dir) const;
66 virtual dgVector ConvexConicSupporVertex (const dgVector& point, const dgVector& dir) const;
67 virtual dgInt32 CalculateContacts (const dgVector& point, const dgVector& normal, dgCollisionParamProxy& proxy, dgVector* const contactsOut) const;
68
69 dgFloat32 m_radius;
70 dgVector m_vertex[DG_SPHERE_VERTEX_COUNT];
71
72 static dgInt32 m_shapeRefCount;
73 static dgVector m_unitSphere[];
74 static dgConvexSimplexEdge m_edgeArray[];
75
76 friend class dgWorld;
77 };
78
79
80 class dgCollisionPoint: public dgCollisionSphere
81 {
82 public:
83 dgCollisionPoint (dgMemoryAllocator* const allocator)
84 :dgCollisionSphere(allocator, 0x12344321, dgFloat32 (0.25f))
85 {
86 }
87
88 virtual dgFloat32 GetVolume () const;
89 virtual dgVector SupportVertex (const dgVector& dir, dgInt32* const vertexIndex) const;
90 };
91
92 #endif
93
dgCollisionSphere
Definition: dgCollisionSphere.h:30
dgCollisionSphere::m_edgeArray
static dgConvexSimplexEdge m_edgeArray[]
Definition: dgCollisionSphere.h:74
dgCollision::OnDebugCollisionMeshCallback
void(dgApi * OnDebugCollisionMeshCallback)(void *userData, int vertexCount, const dgFloat32 *FaceArray, int faceId)
Definition: dgCollision.h:220
dgCollisionSphere::dgCollisionSphere
dgCollisionSphere(dgMemoryAllocator *allocator, dgUnsigned32 signature, dgFloat32 radius)
Definition: dgCollisionSphere.cpp:42
dgCollisionInfo
Definition: dgCollision.h:82
dgBody
Definition: dgBody.h:44
dgCollisionPoint::dgCollisionPoint
dgCollisionPoint(dgMemoryAllocator *const allocator)
Definition: dgCollisionSphere.h:83
DG_SPHERE_VERTEX_COUNT
#define DG_SPHERE_VERTEX_COUNT
Definition: dgCollisionSphere.h:28
dgCollisionSphere::MassProperties
virtual void MassProperties()
Definition: dgCollisionSphere.cpp:285
userData
void *const userData
Definition: dgBroadPhase.h:35
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgCollisionSphere::~dgCollisionSphere
virtual ~dgCollisionSphere()
Definition: dgCollisionSphere.cpp:56
dgConvexSimplexEdge
Definition: dgCollisionConvex.h:31
dgVector
Definition: dgVector.h:639
dgCollisionSphere::TesselateTriangle
void TesselateTriangle(dgInt32 level, const dgVector &p0, const dgVector &p1, const dgVector &p2, dgInt32 &count, dgVector *ouput) const
Definition: dgCollisionSphere.cpp:157
dgCollisionSphere::m_radius
dgFloat32 m_radius
Definition: dgCollisionSphere.h:69
dgCollisionSphere::CalculateContacts
virtual dgInt32 CalculateContacts(const dgVector &point, const dgVector &normal, dgCollisionParamProxy &proxy, dgVector *const contactsOut) const
Definition: dgCollisionSphere.cpp:321
dgCollisionSphere::GetCollisionInfo
virtual void GetCollisionInfo(dgCollisionInfo *const info) const
Definition: dgCollisionSphere.cpp:298
dgCollisionSphere::DebugCollision
virtual void DebugCollision(const dgMatrix &matrix, dgCollision::OnDebugCollisionMeshCallback callback, void *const userData) const
Definition: dgCollisionSphere.cpp:226
dgContactPoint
Definition: dgContact.h:78
dgSerialize
void(dgApi * dgSerialize)(void *const userData, const void *const buffer, size_t size)
Definition: dgTypes.h:280
dgCollisionSphere::CalculateSignature
virtual dgInt32 CalculateSignature() const
Definition: dgCollisionSphere.cpp:202
dgDeserialize
void(dgApi * dgDeserialize)(void *const userData, void *buffer, size_t size)
Definition: dgTypes.h:279
dgCollisionSphere::CalculatePlaneIntersection
virtual dgInt32 CalculatePlaneIntersection(const dgVector &normal, const dgVector &point, dgVector *const contactsOut, dgFloat32 normalSign) const
Definition: dgCollisionSphere.cpp:215
dgCollisionConvex::GetVolume
virtual dgFloat32 GetVolume() const
Definition: dgCollisionConvex.cpp:1801
dgCollisionSphere::ConvexConicSupporVertex
virtual dgVector ConvexConicSupporVertex(const dgVector &dir) const
Definition: dgCollisionSphere.cpp:311
dgCollisionSphere::Serialize
virtual void Serialize(dgSerialize callback, void *const userData) const
Definition: dgCollisionSphere.cpp:304
OnRayPrecastAction
dgUnsigned32(dgApi * OnRayPrecastAction)(const dgBody *const body, const dgCollisionInstance *const collision, void *const userData)
Definition: dgBroadPhase.h:36
dgCollisionSphere::SetCollisionBBox
virtual void SetCollisionBBox(const dgVector &p0, const dgVector &p1)
Definition: dgCollisionSphere.cpp:187
dgCollisionSphere::m_vertex
dgVector m_vertex[DG_SPHERE_VERTEX_COUNT]
Definition: dgCollisionSphere.h:70
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgCollisionConvex
Definition: dgCollisionConvex.h:42
dgCollisionSphere::SupportVertex
virtual dgVector SupportVertex(const dgVector &dir, dgInt32 *const vertexIndex) const
Definition: dgCollisionSphere.cpp:148
dgCollisionSphere::RayCast
virtual dgFloat32 RayCast(const dgVector &localP0, const dgVector &localP1, dgFloat32 maxT, dgContactPoint &contactOut, const dgBody *const body, void *const userData, OnRayPrecastAction preFilter) const
Definition: dgCollisionSphere.cpp:273
dgCollisionSphere::m_shapeRefCount
static dgInt32 m_shapeRefCount
Definition: dgCollisionSphere.h:72
dgCollisionSphere::m_unitSphere
static dgVector m_unitSphere[]
Definition: dgCollisionSphere.h:73
dgCollisionSphere::CalcAABB
virtual void CalcAABB(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const
Definition: dgCollisionSphere.cpp:207
dgMatrix
Definition: dgMatrix.h:40
dgMemoryAllocator
Definition: dgMemory.h:73
dgCollisionSphere::Init
void Init(dgFloat32 radius, dgMemoryAllocator *allocator)
Definition: dgCollisionSphere.cpp:66
dgWorld
Definition: dgWorld.h:129
dgCollisionPoint
Definition: dgCollisionSphere.h:80
dgCollisionConvex.h
dgCollisionParamProxy
Definition: dgContact.h:93