18 #define MSTRINGIFY(A) A
19 #include "../OpenCLC10/ApplyForces.cl"
20 #include "../OpenCLC10/Integrate.cl"
21 #include "../OpenCLC10/PrepareLinks.cl"
22 #include "../OpenCLC10/SolvePositions.cl"
23 #include "../OpenCLC10/UpdateNodes.cl"
24 #include "../OpenCLC10/UpdateNormals.cl"
25 #include "../OpenCLC10/UpdatePositions.cl"
26 #include "../OpenCLC10/UpdatePositionsFromVelocities.cl"
27 #include "../OpenCLC10/VSolveLinks.cl"
28 #include "../OpenCLC10/UpdateFixedVertexPositions.cl"
47 return a.x*b.x + a.y*b.y + a.z*b.z;
63 int softBodyIdentifier;
64 int collisionShapeType;
87 float4 row0 =
float4(matrix[0].x, matrix[1].x, matrix[2].x, matrix[3].x);
88 float4 row1 =
float4(matrix[0].y, matrix[1].y, matrix[2].y, matrix[3].y);
89 float4 row2 =
float4(matrix[0].z, matrix[1].z, matrix[2].z, matrix[3].z);
90 float4 row3 =
float4(matrix[0].w, matrix[1].w, matrix[2].w, matrix[3].w);
91 returnVector.
x =
dot(row0, vector);
92 returnVector.
y =
dot(row1, vector);
93 returnVector.
z =
dot(row2, vector);
94 returnVector.
w =
dot(row3, vector);
101 const float isolverdt,
102 __global int *g_vertexClothIdentifier,
104 __global float * g_perClothFriction,
105 __global float * g_clothDampingFactor,
117 int clothIdentifier = g_vertexClothIdentifier[nodeID];
120 if( clothIdentifier < 0 )
124 float4 position (g_vertexPositions[nodeID].xyz, 1.f);
125 float4 previousPosition (g_vertexPreviousPositions[nodeID].xyz, 1.f);
127 float clothFriction = g_perClothFriction[clothIdentifier];
128 float dampingFactor = g_clothDampingFactor[clothIdentifier];
129 float velocityCoefficient = (1.f - dampingFactor);
130 float4 difference = position - previousPosition;
131 float4 velocity = difference*velocityCoefficient*isolverdt;
140 for(
int collision = collisionObjectIndices.
firstObject; collision < collisionObjectIndices.
endObject; ++collision )
143 float colliderFriction = shapeDescription.
friction;
149 float capsuleHalfHeight = shapeDescription.
halfHeight;
150 float capsuleRadius = shapeDescription.
radius;
151 float capsuleMargin = shapeDescription.
margin;
152 int capsuleupAxis = shapeDescription.
upAxis;
162 float4 c1 (0.f, 0.f, 0.f, 1.f);
163 float4 c2 (0.f, 0.f, 0.f, 1.f);
164 c1.
x =
select( 0.f, -capsuleHalfHeight, capsuleupAxis == 0 );
165 c1.
y =
select( 0.f, -capsuleHalfHeight, capsuleupAxis == 1 );
166 c1.
z =
select( 0.f, -capsuleHalfHeight, capsuleupAxis == 2 );
174 float4 segment = (worldC2 - worldC1);
177 float distanceAlongSegment = -(
mydot3a( (worldC1 - position), segment ) /
mydot3a(segment, segment) );
179 float4 closestPoint = (worldC1 + (segment * distanceAlongSegment));
180 float distanceFromLine =
length(position - closestPoint);
181 float distanceFromC1 =
length(worldC1 - position);
182 float distanceFromC2 =
length(worldC2 - position);
188 if( distanceAlongSegment < 0 )
190 dist = distanceFromC1;
192 }
else if( distanceAlongSegment > 1.f ) {
193 dist = distanceFromC2;
196 dist = distanceFromLine;
202 float4 velocityOfSurfacePoint = colliderLinearVelocity +
cross(colliderAngularVelocity, position -
float4(worldTransform[0].w, worldTransform[1].w, worldTransform[2].w, 0.f));
204 float minDistance = capsuleRadius + capsuleMargin;
207 velocity = (position - previousPosition) * velocityCoefficient * isolverdt;
211 if( dist < minDistance )
214 position = position +
float4(normalVector*(minDistance - dist)*0.9f);
215 velocity = (position - previousPosition) * velocityCoefficient * isolverdt;
216 float4 relativeVelocity = velocity - velocityOfSurfacePoint;
221 float4 frictionVector = p1*
mydot3a(relativeVelocity, p1) + p2*
mydot3a(relativeVelocity, p2);
224 frictionVector = frictionVector * (colliderFriction*clothFriction);
226 float approachSpeed =
dot(relativeVelocity, normalVector);
228 if( approachSpeed <= 0.0f )
229 forceOnVertex -= frictionVector;
235 g_vertexVelocities[nodeID] =
float4(velocity.
xyz, 0.f);
238 g_vertexForces[nodeID] =
float4(forceOnVertex.
xyz, 0.f);
240 g_vertexPositions[nodeID] =
float4(position.
xyz, 0.f);
btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Vectormath::Aos::Vector3 linearVelocity
float4 matrixVectorMul(float4 matrix[4], float4 vector)
float dist(const Point3 &pnt0, const Point3 &pnt1)
__constant int CAPSULE_SHAPE_PROXYTYPE
static float4 normalize(const float4 &a)
__kernel void SolveCollisionsAndUpdateVelocitiesKernel(const int numNodes, const float isolverdt, __global int *g_vertexClothIdentifier, __global float4 *g_vertexPreviousPositions, __global float *g_perClothFriction, __global float *g_clothDampingFactor, __global CollisionObjectIndices *g_perClothCollisionObjectIndices, __global CollisionShapeDescription *g_collisionObjectDetails, __global float4 *g_vertexForces, __global float4 *g_vertexVelocities, __global float4 *g_vertexPositions GUID_ARG)
Vectormath::Aos::Transform3 shapeTransform
Entry in the collision shape array.
float select(float arg0, float arg1, bool select)
Vectormath::Aos::Vector3 angularVelocity
static float4 cross(const float4 &a, const float4 &b)
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
float mydot3a(float4 a, float4 b)
MINICL_REGISTER(SolveCollisionsAndUpdateVelocitiesKernel)