Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SphereShape.cpp « CollisionShapes « Bullet « bullet « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbffb8137dec201ab99f5989e609acce1e6a2cf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies.
 * Erwin Coumans makes no representations about the suitability 
 * of this software for any purpose.  
 * It is provided "as is" without express or implied warranty.
 */

#include "SphereShape.h"
#include "CollisionShapes/CollisionMargin.h"

#include "SimdQuaternion.h"


SphereShape ::SphereShape (SimdScalar radius)
: m_radius(radius)
{	
}

SimdVector3	SphereShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
{
	float radius = m_radius - GetMargin();

	SimdScalar len = vec.length2();
	if (SimdFabs(len) < 0.0001f)
	{
		return SimdVector3(m_localScaling[0] * radius,m_localScaling[1]*radius,m_localScaling[2]*radius);
	} 
	return vec *  (m_localScaling*(radius / SimdSqrt(len)));
}

SimdVector3	SphereShape::LocalGetSupportingVertex(const SimdVector3& vec)const
{
	SimdVector3 supVertex;
	supVertex = LocalGetSupportingVertexWithoutMargin(vec);

	if ( GetMargin()!=0.f )
	{
		SimdVector3 vecnorm = vec;
		if (vecnorm .length2() == 0.f)
		{
			vecnorm.setValue(-1.f,-1.f,-1.f);
		} 
		vecnorm.normalize();
		supVertex+= GetMargin() * vecnorm;
	}
	return supVertex;
}

/*
//broken due to scaling
void SphereShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
{
	const SimdVector3& center = t.getOrigin();
	SimdScalar radius = m_radius;
	
	SimdVector3 extent = m_localScaling*radius;
	extent+= SimdVector3(GetMargin(),GetMargin(),GetMargin());

	aabbMin = center - extent;
	aabbMax = center + extent;
}
*/


void	SphereShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
{
	SimdScalar elem = 0.4f * mass * m_radius*m_radius;
	inertia[0] = inertia[1] = inertia[2] = elem;

}