Skip to content

Commit

Permalink
Hide symbols, add metaball prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
casensiom committed Nov 26, 2023
1 parent 97b23a1 commit 8a8a887
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 73 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ Include the header file and the definition to include the implementation code in
#include "metaballs.h"
```

Refer [main.c](https://github.com/casensiom/metaballs/main.c) to see the library usage.
Refer the [examples](https://github.com/casensiom/metaballs/examples/exmaple0.c) to see the library usage.

### Create

Creates the metaballs workspace
```c
Index3d count = {.x = 10, .y = 10, .z = 10};
Vector3d size = {.x = 2, .y = 2, .z = 2};
Vector3d pos = {.x = 0, .y = 0, .z = 0};
Grid grid = metaball_grid_create(count, size, pos);
```
### Generate mesh
Builds up the mesh to render the metaballs
```c
metaball_generate_mesh(&grid, balls);
```

### Destroy
Destroys the metaballs workspace
```c
metaball_grid_destroy(&grid);
```
## Features
- **Iteration**: Added a method to visit only valid neighbors.
Expand Down
9 changes: 3 additions & 6 deletions examples/example0.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main(int argc, char *argv[])
Index3d count = {.x = 10, .y = 10, .z = 10};
Vector3d size = {.x = 2, .y = 2, .z = 2};
Vector3d pos = {.x = 0, .y = 0, .z = 0};
Grid grid = grid_create(count, size, pos);
Grid grid = metaball_grid_create(count, size, pos);

BallArray balls = MB_CREATE_ARRAY(Ball, 3);

Expand Down Expand Up @@ -83,7 +83,7 @@ int main(int argc, char *argv[])
grid.config.threshold -= 0.05f;
}

generate_mesh(&grid, balls);
metaball_generate_mesh(&grid, balls);

BeginDrawing();
ClearBackground(RAYWHITE);
Expand All @@ -95,17 +95,14 @@ int main(int argc, char *argv[])
char label_fps[256];
sprintf(label_fps, "FPS: %d", GetFPS());
DrawText(label_fps, 10, 10, 20, BLACK);

// sprintf(label_fps, "CACHE HIT: %lu, MISS: %lu", cache_hit, cache_miss);
// DrawText(label_fps, 10, 50, 20, BLACK);
EndDrawing();
}


// RL unload mesh
raylib_unload_mesh(&rayMesh);
MB_DESTROY_ARRAY(balls);
grid_destroy(&grid);
metaball_grid_destroy(&grid);

CloseWindow();

Expand Down
10 changes: 3 additions & 7 deletions examples/example1.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void update_balls(BallArray balls, Vector3d pos, float radius) {
}
}


int main(int argc, char *argv[])
{
const int screenWidth = 800;
Expand All @@ -36,7 +35,7 @@ int main(int argc, char *argv[])
Index3d count = {.x = 20 * 2, .y = 20 * 2, .z = 20 * 2};
Vector3d size = {.x = 10 / 2, .y = 10 / 2, .z = 10 / 2};
Vector3d pos = {.x = 0, .y = 0, .z = 0};
Grid grid = grid_create(count, size, pos);
Grid grid = metaball_grid_create(count, size, pos);

BallArray balls = MB_CREATE_ARRAY(Ball, 5);
for (size_t i = 0; i < balls.capacity; i++)
Expand Down Expand Up @@ -98,7 +97,7 @@ int main(int argc, char *argv[])
grid.config.threshold -= 0.05f;
}

generate_mesh(&grid, balls);
metaball_generate_mesh(&grid, balls);

BeginDrawing();
ClearBackground(RAYWHITE);
Expand All @@ -110,17 +109,14 @@ int main(int argc, char *argv[])
char label_fps[256];
sprintf(label_fps, "FPS: %d", GetFPS());
DrawText(label_fps, 10, 10, 20, BLACK);

// sprintf(label_fps, "CACHE HIT: %lu, MISS: %lu", cache_hit, cache_miss);
// DrawText(label_fps, 10, 50, 20, BLACK);
EndDrawing();
}


// RL unload mesh
raylib_unload_mesh(&rayMesh);
MB_DESTROY_ARRAY(balls);
grid_destroy(&grid);
metaball_grid_destroy(&grid);

CloseWindow();

Expand Down
6 changes: 3 additions & 3 deletions examples/example2.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main(int argc, char *argv[])
Index3d count = {.x = 40, .y = 10, .z = 20};
Vector3d size = {.x = 10, .y = 10, .z = 10};
Vector3d pos = {.x = 0, .y = 0, .z = 0};
Grid grid = grid_create(count, size, pos);
Grid grid = metaball_grid_create(count, size, pos);
grid.config.wired = true;
grid.config.threshold = 0.2;

Expand Down Expand Up @@ -110,7 +110,7 @@ int main(int argc, char *argv[])
if(IsKeyPressed(KEY_J)) {
grid.config.threshold -= 0.05f;
}
generate_mesh(&grid, balls);
metaball_generate_mesh(&grid, balls);

BeginDrawing();
ClearBackground(RAYWHITE);
Expand All @@ -125,7 +125,7 @@ int main(int argc, char *argv[])
// RL unload mesh
raylib_unload_mesh(&rayMesh);
MB_DESTROY_ARRAY(balls);
grid_destroy(&grid);
metaball_grid_destroy(&grid);

CloseWindow();

Expand Down
Loading

0 comments on commit 8a8a887

Please sign in to comment.