Implement collision detection directly in the layout
Add a couple function that will provide collision detection.
Collision detection is simple:
- Center (vertical, and horizontal) and trick: find the closest card center;
- Hand: compute the polar coordinates, and if the radius is acceptable, then find the card that has the closest angle.
Of course, the z-index should be set appropriately so that pointed cards are always displayed last.
The interface change consists in adding functions with a _c
suffix, taking an additional array of Collisions. A collision is a 2D position and the index of the card touched. The array is in-out: the positions are read and the index is set.
struct TarotCollision
{
double x;
double y;
size_t index;
};
typedef struct TarotCollision TarotCollision;
size_t tarot_layout_hand_c (double view_w, double view_h, double card_w, double card_h, size_t n_cards, size_t max, size_t start, TarotPosition *position, size_t n_collisions, TarotCollision * collisions);
Edited by Vivien Kraus