A bit more code cleanup
This commit is contained in:
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "aabb.h"
|
||||
|
||||
bool aabbPoint2D(
|
||||
float pointX, float pointY,
|
||||
float x, float y, float width, float height,
|
||||
aabbpointhit2d_t *hit
|
||||
) {
|
||||
|
||||
float dx, px, sx, halfWidth;
|
||||
float dy, py, sy, halfHeight;
|
||||
|
||||
if(hit == NULL) {
|
||||
// Check X Axis, are we outside the box
|
||||
if(pointX < x || pointY < y) return false;
|
||||
if(pointX > x+width || pointY > y+height) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
halfWidth = width / 2;
|
||||
halfHeight = height / 2;
|
||||
x += halfWidth;
|
||||
y += halfHeight;
|
||||
|
||||
dx = pointX - x;
|
||||
px = halfWidth - mathAbs(dx);
|
||||
if(px <= 0) return false;
|
||||
|
||||
dy = pointY - y;
|
||||
py = halfHeight - mathAbs(dy);
|
||||
if(py <= 0) return false;
|
||||
|
||||
if(px < py) {
|
||||
sx = mathSign(dx);
|
||||
// float deltaX = px *sx;
|
||||
hit->normalX = sx;
|
||||
hit->normalY = 0;
|
||||
hit->hitX = x + (halfWidth * sx);
|
||||
hit->hitY = pointY;
|
||||
} else {
|
||||
sy = mathSign(dy);
|
||||
// float deltaY = py * sy;
|
||||
hit->normalX = 0;
|
||||
hit->normalY = sy;
|
||||
hit->hitX = pointX;
|
||||
hit->hitY = x + (halfHeight * sy);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "sphere.h"
|
||||
#include "../input/input.h"
|
||||
#include "../util/math.h"
|
||||
|
||||
typedef struct {
|
||||
float hitX;
|
||||
float hitY;
|
||||
|
||||
float normalX;
|
||||
float normalY;
|
||||
} aabbpointhit2d_t;
|
||||
|
||||
typedef struct {
|
||||
float time;
|
||||
|
||||
float normalX;
|
||||
float normalY;
|
||||
|
||||
float hitX;
|
||||
float hitY;
|
||||
} aabbvectorhit2d_t;
|
||||
|
||||
/**
|
||||
* Perform a test against a point and an AABB.
|
||||
*
|
||||
* @param pointX Point X coordinate.
|
||||
* @param pointY Point Y coordinate.
|
||||
* @param x Box X coordinate.
|
||||
* @param y Box Y coordinate.
|
||||
* @param width Box width.
|
||||
* @param height Box height.
|
||||
* @param hit Pointer to hit information to store result in, or NULL for none.
|
||||
* @return True if a hit occured, otherwise false.
|
||||
*/
|
||||
bool aabbPoint2D(
|
||||
float pointX, float pointY,
|
||||
float x, float y, float width, float height,
|
||||
aabbpointhit2d_t *hit
|
||||
);
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "sphere.h"
|
||||
|
||||
bool sphereDistance2D(float x0, float y0, float x1, float y1, float radius) {
|
||||
x0 = vectorDistance2D(x0, y0, x1, y1);
|
||||
return x0 <= radius;
|
||||
}
|
||||
|
||||
bool sphereDistance3D(
|
||||
float x0, float y0, float z0, float x1, float y1, float z1, float radius
|
||||
) {
|
||||
x0 = vectorDistance3D(x0, y0, z0, x1, y1, z1);
|
||||
return x0 <= radius;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "vector.h"
|
||||
|
||||
/**
|
||||
* Checks whether a point is colliding with a circle.
|
||||
*
|
||||
* @param x0 X Position of the vector.
|
||||
* @param y0 Y position of the vector.
|
||||
* @param x1 Center point of the circle. X Coordinate.
|
||||
* @param y1 Center point of the circle. Y Coordinate.
|
||||
* @param radius Radius of the circle
|
||||
* @return True if the point is colliding, otherwise false.
|
||||
*/
|
||||
bool sphereDistance2D(float x0, float y0, float x1, float y1, float radius);
|
||||
|
||||
/**
|
||||
* Checks whether a point is colliding with a sphere.
|
||||
*
|
||||
* @param x0 X Position of the vector.
|
||||
* @param y0 Y Position of the vector.
|
||||
* @param z0 Z Position of the vector.
|
||||
* @param x1 Center point of the circle, X Coordinate.
|
||||
* @param y1 Center point of the circle, Y Coordinate.
|
||||
* @param z1 Center point of the circle, Z Coordinate.
|
||||
* @param radius Radius of the sphere.
|
||||
* @return True if the point is colliding with the sphere.
|
||||
*/
|
||||
bool sphereDistance3D(
|
||||
float x0, float y0, float z0, float x1, float y1, float z1, float radius
|
||||
);
|
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
float vectorDistance2D(float x0, float y0, float x1, float y1) {
|
||||
x0 = x1 - x0;
|
||||
y0 = y1 - y0;
|
||||
return (float)sqrt(x0*x0 + y0*y0);
|
||||
}
|
||||
|
||||
|
||||
float vectorDistance3D(
|
||||
float x0, float y0, float z0, float x1, float y1, float z1
|
||||
) {
|
||||
x0 = x1 - x0;
|
||||
y0 = y1 - y0;
|
||||
z0 = z1 - z0;
|
||||
return (float)sqrt(x0*x0 + y0*y0 + z0*z0);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Calculate the distance between two points in 2D space.
|
||||
*
|
||||
* @param x0 First Position X Coordinate.
|
||||
* @param y0 First Position Y Coordinate.
|
||||
* @param x1 Second Position X Coordinate.
|
||||
* @param y1 Second Position Y Coordinate.
|
||||
* @return The distance measurement.
|
||||
*/
|
||||
float vectorDistance2D(float x0, float y0, float x1, float y1);
|
||||
|
||||
/**
|
||||
* Calculate the distance between two points in 3D space.
|
||||
*
|
||||
* @param x0 First Position X Coordinate.
|
||||
* @param y0 First Position Y Coordinate.
|
||||
* @param z0 First Position Z Coordinate.
|
||||
* @param x1 Second Position X Coordinate.
|
||||
* @param y1 Second Position Y Coordinate.
|
||||
* @param z1 Second Position Z Coordinate.
|
||||
* @return The distance measurement.
|
||||
*/
|
||||
float vectorDistance3D(
|
||||
float x0, float y0, float z0, float x1, float y1, float z1
|
||||
);
|
Reference in New Issue
Block a user