/* Silkworm2 - Verlet cloth physics in C * * Copyright (c) 2022 Evan Hemsley * * 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. * * Evan "cosmonaut" Hemsley * */ #ifndef SILKWORM_H #define SILKWORM_H #include #include #include #ifdef _WIN32 #define SILKWORMAPI __declspec(dllexport) #define SILKWORMCALL __cdecl #else #define SILKWORMAPI #define SILKWORMCALL #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* Version API */ #define SILKWORM_ABI_VERSION 0 #define SILKWORM_MAJOR_VERSION 0 #define SILKWORM_MINOR_VERSION 1 #define SILKWORM_PATCH_VERSION 0 #define SILKWORM_COMPILED_VERSION ( \ (SILKWORM_ABI_VERSION * 100 * 100 * 100) + \ (SILKWORM_MAJOR_VERSION * 100 * 100) + \ (SILKWORM_MINOR_VERSION * 100) + \ (SILKWORM_PATCH_VERSION) \ ) typedef struct Silkworm_NodeCreateInfo { int32_t x; int32_t y; float mass; float friction; float radius; bool pinned; float pushFactor; float windFactor; bool destroyable; } Silkworm_NodeCreateInfo; typedef struct Silkworm_ClothCreateInfo { int32_t x; int32_t y; int32_t horizontalNodeCount; int32_t verticalNodeCount; float mass; float friction; float windFactor; float tearThreshold; } Silkworm_ClothCreateInfo; typedef struct Silkworm_Vertex { float x; float y; float z; float u; float v; } Silkworm_Vertex; SILKWORMAPI void Silkworm_Init(); SILKWORMAPI void Silkworm_Update(float delta, float windSpeedX, float windSpeedY); SILKWORMAPI void* Silkworm_CreateNode(Silkworm_NodeCreateInfo* nodeCreateInfo); SILKWORMAPI void Silkworm_DestroyNode(void* nodePtr); SILKWORMAPI void* Silkworm_CreateLink(void* nodeAPtr, void* nodeBPtr, float distance, float tearThreshold); SILKWORMAPI void* Silkworm_ClothCreate(Silkworm_ClothCreateInfo* clothCreateInfo); SILKWORMAPI void Silkworm_ClothNodePin(void* clothPtr, uint32_t i, uint32_t j); SILKWORMAPI void Silkworm_ClothNodeUnpin(void* clothPtr, uint32_t i, uint32_t j); SILKWORMAPI void Silkworm_ClothNodeDestroy(void* clothPtr, uint32_t i, uint32_t j); SILKWORMAPI int32_t Silkworm_ClothFillTriangleBuffer(void* clothPtr, void* vertexBufferPtr, float depth, float leftUV, float widthUV, float topUV, float heightUV); SILKWORMAPI void Silkworm_ClothDestroy(void* clothPtr); SILKWORMAPI void Silkworm_PinNodesInRadius(float x, float y, float radius); SILKWORMAPI void Silkworm_UnpinNodesInRadius(float x, float y, float radius); SILKWORMAPI void Silkworm_PushNodesInRadius(float x, float y, float radius, float xDirection, float yDirection); SILKWORMAPI void Silkworm_DestroyNodesInRadius(float x, float y, float radius); SILKWORMAPI void* Silkworm_FindClothInRadius(float x, float y, float radius); SILKWORMAPI void Silkworm_PerformDestroys(); SILKWORMAPI void Silkworm_ClearAll(); SILKWORMAPI void Silkworm_Finish(); #endif /* SILKWORM_H */