X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=libs%2Fgoat3d%2Fsrc%2Faabox.c;fp=libs%2Fgoat3d%2Fsrc%2Faabox.c;h=2bbfb3bc6234f3bb76818e833695e164e533423e;hb=d5f45e3128c537f272615cf76242e1dfebccdee7;hp=0000000000000000000000000000000000000000;hpb=dd7ce87b0ad2b8a1b4758bcc9354e993b71c8599;p=raydungeon diff --git a/libs/goat3d/src/aabox.c b/libs/goat3d/src/aabox.c new file mode 100644 index 0000000..2bbfb3b --- /dev/null +++ b/libs/goat3d/src/aabox.c @@ -0,0 +1,56 @@ +/* +goat3d - 3D scene, and animation file format library. +Copyright (C) 2013-2018 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#include +#include "aabox.h" + +void g3dimpl_aabox_init(struct aabox *box) +{ + cgm_vcons(&box->bmin, FLT_MAX, FLT_MAX, FLT_MAX); + cgm_vcons(&box->bmax, -FLT_MAX, -FLT_MAX, -FLT_MAX); +} + +void g3dimpl_aabox_cons(struct aabox *box, float x0, float y0, float z0, + float x1, float y1, float z1) +{ + cgm_vcons(&box->bmin, x0, y0, z0); + cgm_vcons(&box->bmax, x1, y1, z1); +} + + +int g3dimpl_aabox_equal(const struct aabox *a, const struct aabox *b) +{ + if(a->bmin.x != b->bmin.x || a->bmin.y != b->bmin.y || a->bmin.z != b->bmin.z) { + return 0; + } + if(a->bmax.x != b->bmax.x || a->bmax.y != b->bmax.y || a->bmax.z != b->bmax.z) { + return 0; + } + return 1; +} + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +void g3dimpl_aabox_union(struct aabox *res, const struct aabox *a, const struct aabox *b) +{ + res->bmin.x = MIN(a->bmin.x, b->bmin.x); + res->bmin.y = MIN(a->bmin.y, b->bmin.y); + res->bmin.z = MIN(a->bmin.z, b->bmin.z); + res->bmax.x = MAX(a->bmax.x, b->bmax.x); + res->bmax.y = MAX(a->bmax.y, b->bmax.y); + res->bmax.z = MAX(a->bmax.z, b->bmax.z); +}