Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
89a459f
add resolve_collision
matt439 Nov 20, 2024
4f16611
add collision resolution functions
matt439 Nov 22, 2024
0d8b23d
add collision resolution tests
matt439 Nov 22, 2024
3804620
fix bug in 1st iteration
matt439 Nov 22, 2024
4785591
change sprite functions to generic point and rectangle
matt439 Nov 25, 2024
f48b45b
add collision resolution tests
matt439 Nov 27, 2024
d322135
adding overloads to sprite resolution
matt439 Nov 27, 2024
e9bedae
add triangle_quad_intersect funtion
matt439 Nov 27, 2024
0c03344
add rectangels around shapes
matt439 Nov 27, 2024
2d36d1c
fix bug in line_intersects_rect
matt439 Nov 27, 2024
0107947
simplify and remove comments
matt439 Nov 27, 2024
efba9ef
change test names
matt439 Nov 27, 2024
968e62a
add shape overloads
matt439 Nov 28, 2024
f4b8c37
add circle_quad_intersect
matt439 Nov 28, 2024
8c422e8
add rectangle_circle_intersect
matt439 Nov 28, 2024
64f1b5b
fix segmentaton fault bugs
matt439 Nov 29, 2024
ea1d2de
add tests for different objects
matt439 Nov 29, 2024
d559c6f
improve collision tests
matt439 Nov 29, 2024
7e8b2ea
change quad spawn location
matt439 Nov 29, 2024
5465c8f
add unit tests
matt439 Nov 29, 2024
a748f0b
add unit tests
matt439 Nov 29, 2024
193c5b2
remove unused constant
matt439 Nov 29, 2024
a83edda
add function description
matt439 Nov 29, 2024
cfbe64a
update parameter names in collision functions
matt439 Dec 13, 2024
cc9e2cf
add suffix to collision function overloads for translator
matt439 Dec 13, 2024
6fba89f
Change naming from sprite to object
matt439 Dec 27, 2024
ce8659d
adding templates to replace function and void pointers
matt439 Jan 18, 2025
11180e7
refactor collision functions to use const references for parameters
matt439 Jan 19, 2025
6795fa1
alter the function documentation to reflect change from enum to vecto…
matt439 Jan 19, 2025
59e529e
change collision_direction enum to vector_2d
matt439 Jan 19, 2025
94c0a00
alter tests to use vector_2d functions
matt439 Jan 19, 2025
16d0248
remove collision_direction enum
matt439 Jan 19, 2025
421c048
add collision_direction enum and rename to private
matt439 Jan 19, 2025
0111fef
refactor tests to use vector_2d instead of enum
matt439 Jan 19, 2025
3ba9589
rename calculate__collision_direction to calculate_collision_directio…
matt439 Jan 19, 2025
2cff329
add that the returned vector is a unit vector to documentation
matt439 Jan 20, 2025
2d37647
use unit vectors for diagonal directions
matt439 Jan 20, 2025
bacc8fe
removing enums and using vectors for direction
matt439 Jan 21, 2025
bfefb91
alter the use of unit_vector to be used only in _resolve_object_colli…
matt439 Jan 21, 2025
b57b875
reduce ambiguity between collision and movement direction parameters
matt439 Jan 24, 2025
e628139
reduced code duplication with template methods
matt439 Feb 28, 2025
e7c9ce4
add documentation for collision_test_type in test_sprites.cpp
matt439 Feb 28, 2025
226dada
Move global constants to local functions as no need for global
omckeon Feb 28, 2025
2fa7d93
Update constants
omckeon Feb 28, 2025
8932a5f
Merge branch 'develop' of https://github.com/thoth-tech/splashkit-cor…
omckeon Feb 28, 2025
d8d7bcf
Remove file for simpler merging
omckeon Feb 28, 2025
b340e25
Add updated geometry tests from original file
omckeon Feb 28, 2025
f702b4e
Move constant to be local
omckeon Feb 28, 2025
7debbb2
Minor formatting
omckeon Feb 28, 2025
d13cca6
Add ability to decode base64 image resources (#72)
Wills2022 Feb 28, 2025
0354a5b
Fix issues + formatting
omckeon Feb 28, 2025
0411476
Merge branch 'develop' of https://github.com/thoth-tech/splashkit-cor…
omckeon Feb 28, 2025
16f15b2
Merge branch 't3-2024' of https://github.com/thoth-tech/splashkit-cor…
omckeon Feb 28, 2025
c9ce798
Add ray intersection tests for primitive shapes (#87)
matt439 Feb 28, 2025
cba15df
Clean up some unnecessary templates
omckeon Feb 28, 2025
e89722e
Merge remote-tracking branch 'origin/t3-2024' into pr/matt439/83
omckeon Feb 28, 2025
3c8ed9f
Add missing header comment
omckeon Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions coresdk/src/backend/graphics_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2129,15 +2129,10 @@ namespace splashkit_lib
return result;
}

sk_drawing_surface sk_load_bitmap(const char * filename)
sk_drawing_surface sk_load_from_surface(SDL_Surface *surface)
{
internal_sk_init();
sk_drawing_surface result = { SGDS_Unknown, 0, 0, nullptr };

SDL_Surface *surface;

surface = IMG_Load(filename);

if ( ! surface ) {
std::cout << "error loading image " << IMG_GetError() << std::endl;
return result;
Expand Down Expand Up @@ -2171,7 +2166,23 @@ namespace splashkit_lib

return result;
}


sk_drawing_surface sk_load_bitmap(const char * filename)
{
internal_sk_init();

return sk_load_from_surface(IMG_Load(filename));
}

sk_drawing_surface sk_load_bitmap_from_memory(const vector<int8_t>& img_data)
{
internal_sk_init();

SDL_RWops *rw = SDL_RWFromConstMem(&img_data[0], img_data.size());

return sk_load_from_surface(IMG_LoadTyped_RW(rw, 1, "PNG"));
}

//x, y is the position to draw the bitmap to. As bitmaps scale around their centre, (x, y) is the top-left of the bitmap IF and ONLY IF scale = 1.
//Angle is in degrees, 0 being right way up
//Centre is the point to rotate around, relative to the bitmap centre (therefore (0,0) would rotate around the centre point)
Expand Down
2 changes: 1 addition & 1 deletion coresdk/src/backend/graphics_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace splashkit_lib
sk_drawing_surface sk_create_bitmap(int width, int height);

sk_drawing_surface sk_load_bitmap(const char * filename);

sk_drawing_surface sk_load_bitmap_from_memory(const vector<int8_t>& img_data);

void sk_draw_bitmap( sk_drawing_surface * src, sk_drawing_surface * dst, double * src_data, int src_data_sz, double * dst_data, int dst_data_sz, sk_renderer_flip flip );

Expand Down
43 changes: 43 additions & 0 deletions coresdk/src/backend/utility_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,47 @@ namespace splashkit_lib
double lin_interp(double v0, double v1, double t) {
return v0 * (1.0 - t) + v1 * t;
}

vector<int8_t> base64_decode_data(const char* in)
{
const string BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

//Lookup decimal values for base64 string (base64 -> base10)
vector<uint8_t> map;
for (int i = 0; i < strlen(in); i++)
{
for(int j = 0; j < 64; j++)
{
if(in[i] == BASE64_CHARS[j])
{
//Remove 00 prefix from byte by bit shifting
map.push_back(j << 2);
}
}
}

vector<int8_t> out;
int8_t a;
int8_t b;
int lb = 0;
int rb = 6;
//Base64 encoded data should always be divisible into chunks of four
for (int i = 0; i < map.size(); i++)
{
//Concatenate six bits of a and two bits of b to get val c
a = (map[i] << lb);
b = (map[i+1] >> rb);
out.push_back(a + b);
//Shift cursors to concatenate correct chunks
lb+=2;
rb-=2;
if(rb == 0)
{
lb = 0;
rb = 6;
++i;
}
}
return out;
}
}
2 changes: 2 additions & 0 deletions coresdk/src/backend/utility_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ collection.erase(collection.begin());\

double lin_interp(double v0, double v1, double t);

vector<int8_t> base64_decode_data(const char* in);

// Notify the listeners that a resource has been freed. Implemented in resources.
void notify_of_free(void *resource);
}
Expand Down
50 changes: 50 additions & 0 deletions coresdk/src/coresdk/circle_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@ namespace splashkit_lib
return (v - sqrt(d));
}

bool circle_ray_intersection(const point_2d &origin, const vector_2d &heading, const circle &circ)
{
point_2d hit_point;
double hit_distance;
return circle_ray_intersection(origin, heading, circ, hit_point, hit_distance);
}

bool circle_ray_intersection(const point_2d &origin, const vector_2d &heading, const circle &circ, point_2d &hit_point, double &hit_distance)
{
vector_2d unit_heading = unit_vector(heading);

// check whether unit heading is a zero vector
if (vector_magnitude_squared(unit_heading) < __DBL_EPSILON__)
{
return false;
}

if (point_in_circle(origin, circ))
{
hit_point = origin;
hit_distance = 0.0;
return true;
}

float distance = ray_circle_intersect_distance(origin, unit_heading, circ);
if (distance < 0.0f)
{
return false;
}

hit_distance = static_cast<double>(distance);
hit_point = point_offset_by(origin, vector_multiply(unit_heading, hit_distance));
return true;
}

bool circles_intersect(circle c1, circle c2)
{
return point_point_distance(c1.center, c2.center) < c1.radius + c2.radius;
Expand Down Expand Up @@ -192,4 +227,19 @@ namespace splashkit_lib

return true;
}

bool circle_quad_intersect(const circle &c, const quad &q)
{
vector<triangle> q_tris = triangles_from(q);

for (size_t i = 0; i < q_tris.size(); i++)
{
if (circle_triangle_intersect(c, q_tris[i]))
{
return true;
}
}

return false;
}
}
37 changes: 37 additions & 0 deletions coresdk/src/coresdk/circle_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,35 @@ namespace splashkit_lib
*/
float ray_circle_intersect_distance(const point_2d &ray_origin, const vector_2d &ray_heading, const circle &c);

/**
* Detects if a ray intersects a circle.
*
* @param origin The starting point of the ray
* @param heading The direction of the ray as a vector
* @param circ The circle to check for intersection
* @returns True if the ray intersects the circle, false otherwise
*/
bool circle_ray_intersection(const point_2d &origin, const vector_2d &heading, const circle &circ);

/**
* Detects if a ray intersects a circle. If an intersection is found, the
* `hit_point` and `hit_distance` are set to the point of intersection and the
* distance from the ray's origin to the intersection point. If the ray's `origin`
* is contained within the circle, `hit_point` is set to the `origin` and `hit_distance`
* is set to 0. If no intersection is found, `hit_point` and `hit_distance` are not modified.
*
* @param origin The starting point of the ray
* @param heading The direction of the ray as a vector
* @param circ The circle to check for intersection
* @param hit_point The point to set to where the ray intersects the circle
* @param hit_distance The double to set to the distance from the ray's origin to
* the intersection point
* @returns True if the ray intersects the circle, false otherwise
*
* @attribute suffix with_hit_point_and_distance
*/
bool circle_ray_intersection(const point_2d &origin, const vector_2d &heading, const circle &circ, point_2d &hit_point, double &hit_distance);

/**
* Returns the circle radius.
*
Expand Down Expand Up @@ -217,5 +246,13 @@ namespace splashkit_lib
*/
bool tangent_points(const point_2d &from_pt, const circle &c, point_2d &p1, point_2d &p2);

/**
* Detects if a circle intersects with a quad.
*
* @param c The circle to test
* @param q The quad to test
* @return True if the circle and quad intersect, false otherwise
*/
bool circle_quad_intersect(const circle &c, const quad &q);
}
#endif /* circle_geometry_hpp */
Loading
Loading