Skip to content

Commit

Permalink
trigger + collision callbacks improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurVoxowl committed Feb 1, 2023
1 parent c09fc93 commit 9dcfdb9
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 361 deletions.
38 changes: 30 additions & 8 deletions core/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "box.h"

#include <stdlib.h>
#include <string.h>

Box *box_new() {
Box *b = (Box *)malloc(sizeof(Box));
Expand Down Expand Up @@ -439,6 +440,16 @@ void box_to_aabox2(const Box *b,
const Matrix4x4 *mtx,
const float3 *offset,
SquarifyType squarify) {

box_model1_to_model2_aabox(b, aab, mtx, NULL, offset, squarify);
}

void box_model1_to_model2_aabox(const Box *b,
Box *aab,
const Matrix4x4 *model1,
const Matrix4x4 *invModel2,
const float3 *offset,
SquarifyType squarify) {
float3 min = b->min;
float3 max = b->max;

Expand All @@ -459,14 +470,25 @@ void box_to_aabox2(const Box *b,
float3 transformed[8];

// transform all 8 box points
matrix4x4_op_multiply_vec_point(&transformed[0], &points[0], mtx);
matrix4x4_op_multiply_vec_point(&transformed[1], &points[1], mtx);
matrix4x4_op_multiply_vec_point(&transformed[2], &points[2], mtx);
matrix4x4_op_multiply_vec_point(&transformed[3], &points[3], mtx);
matrix4x4_op_multiply_vec_point(&transformed[4], &points[4], mtx);
matrix4x4_op_multiply_vec_point(&transformed[5], &points[5], mtx);
matrix4x4_op_multiply_vec_point(&transformed[6], &points[6], mtx);
matrix4x4_op_multiply_vec_point(&transformed[7], &points[7], mtx);
matrix4x4_op_multiply_vec_point(&transformed[0], &points[0], model1);
matrix4x4_op_multiply_vec_point(&transformed[1], &points[1], model1);
matrix4x4_op_multiply_vec_point(&transformed[2], &points[2], model1);
matrix4x4_op_multiply_vec_point(&transformed[3], &points[3], model1);
matrix4x4_op_multiply_vec_point(&transformed[4], &points[4], model1);
matrix4x4_op_multiply_vec_point(&transformed[5], &points[5], model1);
matrix4x4_op_multiply_vec_point(&transformed[6], &points[6], model1);
matrix4x4_op_multiply_vec_point(&transformed[7], &points[7], model1);
if (invModel2 != NULL) {
memcpy(points, transformed, sizeof(float3) * 8);
matrix4x4_op_multiply_vec_point(&transformed[0], &points[0], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[1], &points[1], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[2], &points[2], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[3], &points[3], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[4], &points[4], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[5], &points[5], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[6], &points[6], invModel2);
matrix4x4_op_multiply_vec_point(&transformed[7], &points[7], invModel2);
}

// get box min/max in that new space
aab->min = transformed[0];
Expand Down
7 changes: 7 additions & 0 deletions core/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ void box_to_aabox2(const Box *b,
const float3 *offset,
SquarifyType squarify);

void box_model1_to_model2_aabox(const Box *b,
Box *aab,
const Matrix4x4 *model1,
const Matrix4x4 *invModel2,
const float3 *offset,
SquarifyType squarify);

void box_op_merge(const Box *b1, const Box *b2, Box *result);

float box_get_volume(const Box *b);
Expand Down
18 changes: 18 additions & 0 deletions core/doubly_linked_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ bool doubly_linked_list_contains(const DoublyLinkedList *list, void *ptr) {
return false;
}

bool doubly_linked_list_contains_func(const DoublyLinkedList *list,
pointer_doubly_linked_list_contains_func func,
void *ptr,
void **out) {
DoublyLinkedListNode *n = list->first;
while (n != NULL) {
if (func(n->ptr, ptr)) {
if (out != NULL) {
*out = n->ptr;
}
return true;
}
n = n->next;
}

return false;
}

//---------------------
// DoublyLinkedNode
//---------------------
Expand Down
5 changes: 5 additions & 0 deletions core/doubly_linked_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ size_t doubly_linked_list_node_count(const DoublyLinkedList *list);
DoublyLinkedListNode *doubly_linked_list_node_at_index(const DoublyLinkedList *list, size_t i);

bool doubly_linked_list_contains(const DoublyLinkedList *list, void *ptr);
typedef bool (*pointer_doubly_linked_list_contains_func)(void *nodePtr, void *data);
bool doubly_linked_list_contains_func(const DoublyLinkedList *list,
pointer_doubly_linked_list_contains_func func,
void *ptr,
void **out);

//--------------------
// MARK: - DoublyLinkedListNode -
Expand Down
Loading

0 comments on commit 9dcfdb9

Please sign in to comment.