File: Plane3.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (41 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "Plane3.h"

#include "AABB.h"
#include "Matrix4.h"

double Plane3::distanceToOrientedExtents(const Vector3& extents, const Matrix4& orientation) const
{
	return fabs(extents[0] * normal().dot(orientation.xCol3())) +
		   fabs(extents[1] * normal().dot(orientation.yCol3())) +
		   fabs(extents[2] * normal().dot(orientation.zCol3()));
}

bool Plane3::containsAABB(const AABB& aabb, const Matrix4& orientation) const
{
	double dot = distanceToPoint(aabb.origin);

	return !(dot > 0 || -dot < distanceToOrientedExtents(aabb.extents, orientation));
}

void Plane3::translate(const Vector3& translation)
{
    _dist = _dist - ( translation.x() * _normal.x()
                    + translation.y() * _normal.y()
                    + translation.z() * _normal.z());
}

Plane3& Plane3::transform(const Matrix4& m)
{
    _normal = m.transformDirection(_normal);

    _dist = _normal.x() * (_dist * _normal.x() - m.tx())
          + _normal.y() * (_dist * _normal.y() - m.ty())
          + _normal.z() * (_dist * _normal.z() - m.tz());

    return *this;
}

Plane3 Plane3::transformed(const Matrix4& m) const
{
    return Plane3(*this).transform(m);
}