2012-08-30 22:37:44 +00:00
|
|
|
//
|
|
|
|
|
// KRAABB.h
|
|
|
|
|
// KREngine
|
|
|
|
|
//
|
|
|
|
|
// Created by Kearwood Gilbert on 2012-08-30.
|
|
|
|
|
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Axis aligned bounding box
|
|
|
|
|
|
|
|
|
|
#ifndef KRAABB_H
|
|
|
|
|
#define KRAABB_H
|
|
|
|
|
|
|
|
|
|
#include "KRVector3.h"
|
|
|
|
|
|
2012-09-11 03:06:35 +00:00
|
|
|
class KRMat4;
|
2012-10-05 02:23:00 +00:00
|
|
|
class KRVector2;
|
2012-09-11 03:06:35 +00:00
|
|
|
|
2012-08-30 22:37:44 +00:00
|
|
|
class KRAABB {
|
|
|
|
|
public:
|
|
|
|
|
KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint);
|
2012-11-03 02:57:35 +00:00
|
|
|
KRAABB(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 &modelMatrix);
|
2013-04-08 21:40:53 -07:00
|
|
|
KRAABB();
|
2012-08-30 22:37:44 +00:00
|
|
|
~KRAABB();
|
|
|
|
|
|
2012-11-22 09:02:25 +00:00
|
|
|
void scale(const KRVector3 &s);
|
|
|
|
|
void scale(float s);
|
|
|
|
|
|
2012-09-05 18:14:08 +00:00
|
|
|
KRVector3 center() const;
|
|
|
|
|
KRVector3 size() const;
|
2012-11-23 01:02:22 +00:00
|
|
|
float volume() const;
|
2012-09-05 18:14:08 +00:00
|
|
|
bool intersects(const KRAABB& b) const;
|
2012-09-11 03:06:35 +00:00
|
|
|
bool contains(const KRAABB &b) const;
|
2012-09-21 07:31:18 +00:00
|
|
|
bool contains(const KRVector3 &v) const;
|
2013-04-24 12:48:55 -07:00
|
|
|
|
2012-12-20 01:23:57 +00:00
|
|
|
bool intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const;
|
2012-12-20 19:24:02 +00:00
|
|
|
bool intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const;
|
2014-02-13 00:36:54 -08:00
|
|
|
bool intersectsSphere(const KRVector3 ¢er, float radius) const;
|
2013-04-04 16:09:29 -07:00
|
|
|
void encapsulate(const KRAABB & b);
|
2012-08-30 22:37:44 +00:00
|
|
|
|
|
|
|
|
KRAABB& operator =(const KRAABB& b);
|
|
|
|
|
bool operator ==(const KRAABB& b) const;
|
|
|
|
|
bool operator !=(const KRAABB& b) const;
|
|
|
|
|
|
|
|
|
|
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
|
|
|
|
bool operator >(const KRAABB& b) const;
|
|
|
|
|
bool operator <(const KRAABB& b) const;
|
|
|
|
|
|
|
|
|
|
KRVector3 min;
|
|
|
|
|
KRVector3 max;
|
2012-09-11 03:06:35 +00:00
|
|
|
|
|
|
|
|
static KRAABB Infinite();
|
2013-04-08 21:40:53 -07:00
|
|
|
static KRAABB Zero();
|
2013-04-24 12:48:55 -07:00
|
|
|
|
2012-11-29 21:28:49 +00:00
|
|
|
float longest_radius() const;
|
2013-04-08 21:40:53 -07:00
|
|
|
KRVector3 nearestPoint(const KRVector3 & v) const;
|
2012-08-30 22:37:44 +00:00
|
|
|
};
|
|
|
|
|
|
2013-04-24 18:12:03 -07:00
|
|
|
namespace std {
|
|
|
|
|
template<>
|
|
|
|
|
struct hash<KRAABB> {
|
|
|
|
|
public:
|
|
|
|
|
size_t operator()(const KRAABB &s) const
|
|
|
|
|
{
|
2013-04-25 17:23:36 -07:00
|
|
|
size_t h1 = hash<KRVector3>()(s.min);
|
|
|
|
|
size_t h2 = hash<KRVector3>()(s.max);
|
2013-04-24 18:12:03 -07:00
|
|
|
return h1 ^ ( h2 << 1 );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-30 22:37:44 +00:00
|
|
|
|
|
|
|
|
#endif /* defined(KRAABB_H) */
|