change pin API

main
cosmonaut 2021-09-22 18:11:25 -07:00
parent 40b3a6596d
commit 11b0a53f40
2 changed files with 18 additions and 19 deletions

View File

@ -283,14 +283,16 @@ void Silkworm_NodeSetDestroyable(double nodeId)
LookupNode(nodeId)->destroyable = true;
}
void Silkworm_NodePin(double nodeId)
void Silkworm_ClothNodePin(double clothId, double i, double j)
{
LookupNode(nodeId)->pinned = true;
Silkworm_Cloth* cloth = LookupCloth(clothId);
context->nodes[cloth->nodeIndices[(uint64_t)i][(uint64_t)j]]->pinned = true;
}
void Silkworm_NodeUnpin(double nodeId)
void Silkworm_ClothNodeUnpin(double clothId, double i, double j)
{
LookupNode(nodeId)->pinned = false;
Silkworm_Cloth* cloth = LookupCloth(clothId);
context->nodes[cloth->nodeIndices[(uint64_t)i][(uint64_t)j]]->pinned = false;
}
double Silkworm_CreateLink(double aId, double bId, double distance, double tearThreshold)
@ -339,22 +341,27 @@ double Silkworm_CreateCloth(double xPosition, double yPosition, double horizonta
cloth->verticalNodeCount = (uint32_t) verticalNodeCount;
cloth->nodeIndices = malloc(sizeof(uint64_t*) * cloth->horizontalNodeCount);
cloth->id = context->clothCount;
context->cloths = realloc(context->cloths, sizeof(Silkworm_Cloth*) * (context->clothCount + 1));
context->cloths[context->clothCount] = cloth;
context->clothCount += 1;
for (i = 0; i < horizontalNodeCount; i += 1)
{
cloth->nodeIndices[i] = malloc(sizeof(uint64_t) * cloth->verticalNodeCount);
for (j = 0; j < verticalNodeCount; j += 1)
{
uint64_t id = (uint64_t) Silkworm_CreateNode(xPosition + i * context->clothDensity, yPosition + j * context->clothDensity, mass, friction, 1, 0.5);
uint64_t nodeId = (uint64_t) Silkworm_CreateNode(xPosition + i * context->clothDensity, yPosition + j * context->clothDensity, mass, friction, 1, 0.5);
cloth->nodeIndices[i][j] = nodeId;
if (j == 0)
{
Silkworm_NodePin((double)id);
Silkworm_ClothNodePin((double)cloth->id, (double)i, (double)j);
}
Silkworm_NodeSetDestroyable((double)id);
cloth->nodeIndices[i][j] = id;
Silkworm_NodeSetDestroyable((double)nodeId);
}
}
@ -427,14 +434,6 @@ double Silkworm_CreateCloth(double xPosition, double yPosition, double horizonta
}
}
uint64_t id;
id = context->clothCount;
cloth->id = id;
context->cloths = realloc(context->cloths, sizeof(Silkworm_Cloth*) * (context->clothCount + 1));
context->cloths[context->clothCount] = cloth;
context->clothCount += 1;
return (double)cloth->id;
}

View File

@ -137,8 +137,8 @@ SILKWORMAPI void Silkworm_Update(double delta);
SILKWORMAPI double Silkworm_CreateNode(double xPosition, double yPosition, double mass, double friction, double radius, double pushFactor);
SILKWORMAPI void Silkworm_NodeSetDestroyable(double nodeId);
SILKWORMAPI void Silkworm_NodePin(double nodeId);
SILKWORMAPI void Silkworm_NodeUnpin(double nodeId);
SILKWORMAPI void Silkworm_ClothNodePin(double clothId, double i, double j);
SILKWORMAPI void Silkworm_ClothNodeUnpin(double clothId, double i, double j);
SILKWORMAPI double Silkworm_CreateLink(double aId, double bId, double distance, double tearThreshold);