Review code formatting
This commit is contained in:
parent
edeaff4bd4
commit
121c689b78
3 changed files with 47 additions and 43 deletions
|
@ -105,7 +105,8 @@ int main(void)
|
||||||
// Check ray collision against test sphere
|
// Check ray collision against test sphere
|
||||||
RayCollision sphereHitInfo = GetRayCollisionSphere(ray, sp, sr);
|
RayCollision sphereHitInfo = GetRayCollisionSphere(ray, sp, sr);
|
||||||
|
|
||||||
if ((sphereHitInfo.hit) && (sphereHitInfo.distance < collision.distance)) {
|
if ((sphereHitInfo.hit) && (sphereHitInfo.distance < collision.distance))
|
||||||
|
{
|
||||||
collision = sphereHitInfo;
|
collision = sphereHitInfo;
|
||||||
cursorColor = ORANGE;
|
cursorColor = ORANGE;
|
||||||
hitObjectName = "Sphere";
|
hitObjectName = "Sphere";
|
||||||
|
|
39
src/models.c
39
src/models.c
|
@ -2992,7 +2992,8 @@ RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius)
|
||||||
collision.hit = d >= 0.0f;
|
collision.hit = d >= 0.0f;
|
||||||
|
|
||||||
// Check if ray origin is inside the sphere to calculate the correct collision point
|
// Check if ray origin is inside the sphere to calculate the correct collision point
|
||||||
if (distance < radius) { // inside
|
if (distance < radius)
|
||||||
|
{
|
||||||
collision.distance = vector + sqrtf(d);
|
collision.distance = vector + sqrtf(d);
|
||||||
|
|
||||||
// Calculate collision point
|
// Calculate collision point
|
||||||
|
@ -3000,7 +3001,9 @@ RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius)
|
||||||
|
|
||||||
// Calculate collision normal (pointing outwards)
|
// Calculate collision normal (pointing outwards)
|
||||||
collision.normal = Vector3Negate(Vector3Normalize(Vector3Subtract(collision.point, center)));
|
collision.normal = Vector3Negate(Vector3Normalize(Vector3Subtract(collision.point, center)));
|
||||||
} else { // outside
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
collision.distance = vector - sqrtf(d);
|
collision.distance = vector - sqrtf(d);
|
||||||
|
|
||||||
// Calculate collision point
|
// Calculate collision point
|
||||||
|
@ -3020,14 +3023,11 @@ RayCollision GetRayCollisionBox(Ray ray, BoundingBox box)
|
||||||
|
|
||||||
// Note: If ray.position is inside the box, the distance is negative (as if the ray was reversed)
|
// Note: If ray.position is inside the box, the distance is negative (as if the ray was reversed)
|
||||||
// Reversing ray.direction will give use the correct result.
|
// Reversing ray.direction will give use the correct result.
|
||||||
bool insideBox =
|
bool insideBox = (ray.position.x > box.min.x) && (ray.position.x < box.max.x) &&
|
||||||
ray.position.x > box.min.x && ray.position.x < box.max.x &&
|
(ray.position.y > box.min.y) && (ray.position.y < box.max.y) &&
|
||||||
ray.position.y > box.min.y && ray.position.y < box.max.y &&
|
(ray.position.z > box.min.z) && (ray.position.z < box.max.z);
|
||||||
ray.position.z > box.min.z && ray.position.z < box.max.z;
|
|
||||||
|
|
||||||
if (insideBox) {
|
if (insideBox) ray.direction = Vector3Negate(ray.direction);
|
||||||
ray.direction = Vector3Negate(ray.direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
float t[11] = { 0 };
|
float t[11] = { 0 };
|
||||||
|
|
||||||
|
@ -3044,7 +3044,7 @@ RayCollision GetRayCollisionBox(Ray ray, BoundingBox box)
|
||||||
t[6] = (float)fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
|
t[6] = (float)fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
|
||||||
t[7] = (float)fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
|
t[7] = (float)fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
|
||||||
|
|
||||||
collision.hit = !(t[7] < 0 || t[6] > t[7]);
|
collision.hit = !((t[7] < 0) || (t[6] > t[7]));
|
||||||
collision.distance = t[6];
|
collision.distance = t[6];
|
||||||
collision.point = Vector3Add(ray.position, Vector3Scale(ray.direction, collision.distance));
|
collision.point = Vector3Add(ray.position, Vector3Scale(ray.direction, collision.distance));
|
||||||
|
|
||||||
|
@ -3053,10 +3053,10 @@ RayCollision GetRayCollisionBox(Ray ray, BoundingBox box)
|
||||||
// Get vector center point->hit point
|
// Get vector center point->hit point
|
||||||
collision.normal = Vector3Subtract(collision.point, collision.normal);
|
collision.normal = Vector3Subtract(collision.point, collision.normal);
|
||||||
// Scale vector to unit cube
|
// Scale vector to unit cube
|
||||||
// we use an additional .01 to fix numerical errors
|
// NOTE: We use an additional .01 to fix numerical errors
|
||||||
collision.normal = Vector3Scale(collision.normal, 2.01f);
|
collision.normal = Vector3Scale(collision.normal, 2.01f);
|
||||||
collision.normal = Vector3Divide(collision.normal, Vector3Subtract(box.max, box.min));
|
collision.normal = Vector3Divide(collision.normal, Vector3Subtract(box.max, box.min));
|
||||||
// the relevant elemets of the vector are now slightly larger than 1.0f (or smaller than -1.0f)
|
// The relevant elemets of the vector are now slightly larger than 1.0f (or smaller than -1.0f)
|
||||||
// and the others are somewhere between -1.0 and 1.0
|
// and the others are somewhere between -1.0 and 1.0
|
||||||
// casting to int is exactly our wanted normal!
|
// casting to int is exactly our wanted normal!
|
||||||
collision.normal.x = (int)collision.normal.x;
|
collision.normal.x = (int)collision.normal.x;
|
||||||
|
@ -3065,7 +3065,8 @@ RayCollision GetRayCollisionBox(Ray ray, BoundingBox box)
|
||||||
|
|
||||||
collision.normal = Vector3Normalize(collision.normal);
|
collision.normal = Vector3Normalize(collision.normal);
|
||||||
|
|
||||||
if (insideBox) {
|
if (insideBox)
|
||||||
|
{
|
||||||
// Reset ray.direction
|
// Reset ray.direction
|
||||||
ray.direction = Vector3Negate(ray.direction);
|
ray.direction = Vector3Negate(ray.direction);
|
||||||
// Fix result
|
// Fix result
|
||||||
|
@ -3203,7 +3204,8 @@ RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3
|
||||||
|
|
||||||
// Get collision info between ray and quad
|
// Get collision info between ray and quad
|
||||||
// NOTE: The points are expected to be in counter-clockwise winding
|
// NOTE: The points are expected to be in counter-clockwise winding
|
||||||
RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4) {
|
RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4)
|
||||||
|
{
|
||||||
RayCollision collision = { 0 };
|
RayCollision collision = { 0 };
|
||||||
|
|
||||||
collision = GetRayCollisionTriangle(ray, p1, p2, p4);
|
collision = GetRayCollisionTriangle(ray, p1, p2, p4);
|
||||||
|
@ -4437,12 +4439,14 @@ static void InitGLTFBones(Model* model, const cgltf_data* data)
|
||||||
bool* completedBones = RL_CALLOC(model->boneCount, sizeof(bool));
|
bool* completedBones = RL_CALLOC(model->boneCount, sizeof(bool));
|
||||||
int numberCompletedBones = 0;
|
int numberCompletedBones = 0;
|
||||||
|
|
||||||
while (numberCompletedBones < model->boneCount) {
|
while (numberCompletedBones < model->boneCount)
|
||||||
|
{
|
||||||
for (int i = 0; i < model->boneCount; i++)
|
for (int i = 0; i < model->boneCount; i++)
|
||||||
{
|
{
|
||||||
if (completedBones[i]) continue;
|
if (completedBones[i]) continue;
|
||||||
|
|
||||||
if (model->bones[i].parent < 0) {
|
if (model->bones[i].parent < 0)
|
||||||
|
{
|
||||||
completedBones[i] = true;
|
completedBones[i] = true;
|
||||||
numberCompletedBones++;
|
numberCompletedBones++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -4453,8 +4457,7 @@ static void InitGLTFBones(Model* model, const cgltf_data* data)
|
||||||
Transform* currentTransform = &model->bindPose[i];
|
Transform* currentTransform = &model->bindPose[i];
|
||||||
BoneInfo* currentBone = &model->bones[i];
|
BoneInfo* currentBone = &model->bones[i];
|
||||||
int root = currentBone->parent;
|
int root = currentBone->parent;
|
||||||
if (root >= model->boneCount)
|
if (root >= model->boneCount) root = 0;
|
||||||
root = 0;
|
|
||||||
Transform* parentTransform = &model->bindPose[root];
|
Transform* parentTransform = &model->bindPose[root];
|
||||||
|
|
||||||
currentTransform->rotation = QuaternionMultiply(parentTransform->rotation, currentTransform->rotation);
|
currentTransform->rotation = QuaternionMultiply(parentTransform->rotation, currentTransform->rotation);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue