more rope API hooray

main
cosmonaut 2021-10-01 13:48:53 -07:00
parent 60de61552e
commit e72f70ae16
2 changed files with 89 additions and 5 deletions

View File

@ -1401,15 +1401,93 @@ double Silkworm_RopeNearestY(double ropeId, double xPosition, double yPosition)
return nearestY;
}
double Silkworm_RopeNodeCount(double ropeId)
{
Silkworm_Rope* rope = LookupRope(ropeId);
if (rope != NULL)
{
return rope->nodeCount;
}
return -1;
}
double Silkworm_RopeNodeXPosition(double ropeId, double nodeIndex)
{
Silkworm_Rope *rope = LookupRope(ropeId);
if (rope != NULL && nodeIndex < rope->nodeCount)
{
return rope->nodes[(uint32_t)nodeIndex]->position.x;
}
return -99999999999;
}
double Silkworm_RopeNodeYPosition(double ropeId, double nodeIndex)
{
Silkworm_Rope* rope = LookupRope(ropeId);
if (rope != NULL && nodeIndex < rope->nodeCount)
{
return rope->nodes[(uint32_t)nodeIndex]->position.y;
}
return -99999999999;
}
double Silkworm_RopeNodeXSpeed(double ropeId, double nodeIndex)
{
Silkworm_Rope* rope = LookupRope(ropeId);
if (rope != NULL && nodeIndex < rope->nodeCount)
{
return rope->nodes[(uint32_t)nodeIndex]->velocity.x;
}
return 0;
}
double Silkworm_RopeNodeYSpeed(double ropeId, double nodeIndex)
{
Silkworm_Rope* rope = LookupRope(ropeId);
if (rope != NULL && nodeIndex < rope->nodeCount)
{
return rope->nodes[(uint32_t)nodeIndex]->velocity.y;
}
return 0;
}
void Silkworm_UnpinRope(double ropeId)
{
Silkworm_Rope* rope = LookupRope(ropeId);
Silkworm_Node* node = rope->nodes[0];
if (node != NULL)
if (rope != NULL)
{
node->pinned = false;
Silkworm_Node* node = rope->nodes[0];
if (node != NULL)
{
node->pinned = false;
}
}
}
void Silkworm_DeleteEndNode(double ropeId)
{
Silkworm_Rope *rope = LookupRope(ropeId);
if (rope != NULL && rope->nodeCount > 0)
{
Silkworm_Node* node = rope->nodes[rope->nodeCount - 1];
if (node != NULL)
{
Silkworm_DestroyNode(node->id);
rope->nodeCount -= 1;
}
}
}
@ -1954,7 +2032,7 @@ double Silkworm_DestroyClothInRadius(double x, double y, double radius)
{
/* TODO: spatial hash implementation */
uint32_t i, j;
uint32_t i;
int32_t clothId = -1;
for (i = 0; i < context->nodeCount; i += 1)

View File

@ -84,7 +84,13 @@ SILKWORMAPI double Silkworm_RopeAddNode(double ropeId, double xPosition, double
SILKWORMAPI double Silkworm_RopeVerticalLength(double ropeId);
SILKWORMAPI double Silkworm_RopeNearestX(double ropeId, double xPosition, double yPosition);
SILKWORMAPI double Silkworm_RopeNearestY(double ropeId, double xPosition, double yPosition);
SILKWORMAPI double Silkworm_RopeNodeCount(double ropeId);
SILKWORMAPI double Silkworm_RopeNodeXPosition(double ropeId, double nodeIndex);
SILKWORMAPI double Silkworm_RopeNodeYPosition(double ropeId, double nodeIndex);
SILKWORMAPI double Silkworm_RopeNodeXSpeed(double ropeId, double nodeIndex);
SILKWORMAPI double Silkworm_RopeNodeYSpeed(double ropeId, double nodeIndex);
SILKWORMAPI void Silkworm_UnpinRope(double ropeId);
SILKWORMAPI void Silkworm_DeleteEndNode(double ropeId);
SILKWORMAPI void Silkworm_RopeDestroy(double ropeId);
SILKWORMAPI double Silkworm_RopeRequiredBufferSize(double ropeId);
SILKWORMAPI double Silkworm_RopeFillBuffer(double ropeId, double width, double leftUV, double widthUV, double topUV, double heightUV);