summaryrefslogtreecommitdiff
path: root/thirdparty/bullet/Bullet3OpenCL/RigidBody/b3GpuGenericConstraint.h
blob: 1f163ba7d5b95e00022db3cffbca5e2ccc7b61fd (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Copyright (c) 2013 Advanced Micro Devices, Inc.  

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.
*/
//Originally written by Erwin Coumans

#ifndef B3_GPU_GENERIC_CONSTRAINT_H
#define B3_GPU_GENERIC_CONSTRAINT_H

#include "Bullet3Common/b3Quaternion.h"
struct b3RigidBodyData;
enum B3_CONSTRAINT_FLAGS
{
	B3_CONSTRAINT_FLAG_ENABLED = 1,
};

enum b3GpuGenericConstraintType
{
	B3_GPU_POINT2POINT_CONSTRAINT_TYPE = 3,
	B3_GPU_FIXED_CONSTRAINT_TYPE = 4,
	//	B3_HINGE_CONSTRAINT_TYPE,
	//	B3_CONETWIST_CONSTRAINT_TYPE,
	//	B3_D6_CONSTRAINT_TYPE,
	//	B3_SLIDER_CONSTRAINT_TYPE,
	//	B3_CONTACT_CONSTRAINT_TYPE,
	//	B3_D6_SPRING_CONSTRAINT_TYPE,
	//	B3_GEAR_CONSTRAINT_TYPE,

	B3_GPU_MAX_CONSTRAINT_TYPE
};

struct b3GpuConstraintInfo2
{
	// integrator parameters: frames per second (1/stepsize), default error
	// reduction parameter (0..1).
	b3Scalar fps, erp;

	// for the first and second body, pointers to two (linear and angular)
	// n*3 jacobian sub matrices, stored by rows. these matrices will have
	// been initialized to 0 on entry. if the second body is zero then the
	// J2xx pointers may be 0.
	b3Scalar *m_J1linearAxis, *m_J1angularAxis, *m_J2linearAxis, *m_J2angularAxis;

	// elements to jump from one row to the next in J's
	int rowskip;

	// right hand sides of the equation J*v = c + cfm * lambda. cfm is the
	// "constraint force mixing" vector. c is set to zero on entry, cfm is
	// set to a constant value (typically very small or zero) value on entry.
	b3Scalar *m_constraintError, *cfm;

	// lo and hi limits for variables (set to -/+ infinity on entry).
	b3Scalar *m_lowerLimit, *m_upperLimit;

	// findex vector for variables. see the LCP solver interface for a
	// description of what this does. this is set to -1 on entry.
	// note that the returned indexes are relative to the first index of
	// the constraint.
	int* findex;
	// number of solver iterations
	int m_numIterations;

	//damping of the velocity
	b3Scalar m_damping;
};

B3_ATTRIBUTE_ALIGNED16(struct)
b3GpuGenericConstraint
{
	int m_constraintType;
	int m_rbA;
	int m_rbB;
	float m_breakingImpulseThreshold;

	b3Vector3 m_pivotInA;
	b3Vector3 m_pivotInB;
	b3Quaternion m_relTargetAB;

	int m_flags;
	int m_uid;
	int m_padding[2];

	int getRigidBodyA() const
	{
		return m_rbA;
	}
	int getRigidBodyB() const
	{
		return m_rbB;
	}

	const b3Vector3& getPivotInA() const
	{
		return m_pivotInA;
	}

	const b3Vector3& getPivotInB() const
	{
		return m_pivotInB;
	}

	int isEnabled() const
	{
		return m_flags & B3_CONSTRAINT_FLAG_ENABLED;
	}

	float getBreakingImpulseThreshold() const
	{
		return m_breakingImpulseThreshold;
	}

	///internal method used by the constraint solver, don't use them directly
	void getInfo1(unsigned int* info, const b3RigidBodyData* bodies);

	///internal method used by the constraint solver, don't use them directly
	void getInfo2(b3GpuConstraintInfo2 * info, const b3RigidBodyData* bodies);
};

#endif  //B3_GPU_GENERIC_CONSTRAINT_H