Implemented missing method to transform a frustum with a 3x3 matrix; required new multiply overload to transform planes with 3x3 matrices.

ver1_6_1
Chris Laurel 2008-02-26 02:52:06 +00:00
parent 2a674edecd
commit 9157032670
3 changed files with 30 additions and 9 deletions

View File

@ -152,8 +152,18 @@ Frustum::Aspect Frustum::testHalfSpace(const Planef& plane)
#endif
void Frustum::transform(const Mat3f&)
void Frustum::transform(const Mat3f& m)
{
int nPlanes = infinite ? 5 : 6;
Mat3f invTranspose = m.inverse().transpose();
for (int i = 0; i < nPlanes; i++)
{
planes[i] = planes[i] * invTranspose;
float s = 1.0f / planes[i].normal.length();
planes[i].normal = planes[i].normal * s;
planes[i].d *= s;
}
}

View File

@ -1,14 +1,14 @@
// frustum.h
//
// Copyright (C) 2000, Chris Laurel <claurel@shatters.net>
// Copyright (C) 2000-2008, Chris Laurel <claurel@shatters.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#ifndef _FRUSTUM_H_
#define _FRUSTUM_H_
#ifndef _CELMATH_FRUSTUM_H_
#define _CELMATH_FRUSTUM_H_
#include <celmath/plane.h>
#include <celmath/capsule.h>
@ -57,4 +57,4 @@ Planef Frustum::getPlane(int which) const
return planes[which];
}
#endif // _FRUSTUM_H_
#endif // _CELMATH_FRUSTUM_H_

View File

@ -1,14 +1,14 @@
// plane.h
//
// Copyright (C) 2000, Chris Laurel <claurel@shatters.net>
// Copyright (C) 2000-2008, Chris Laurel <claurel@shatters.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#ifndef _PLANE_H_
#define _PLANE_H_
#ifndef _CELMATH_PLANE_H_
#define _CELMATH_PLANE_H_
#include <celmath/mathlib.h>
#include <celmath/vecmath.h>
@ -99,6 +99,17 @@ template<class T> T Plane<T>::distanceToSegment(const Point3<T>& origin,
}
template<class T> Plane<T> operator*(const Matrix3<T>& m, const Plane<T>& p)
{
Vector3<T> v = m * p.normal;
return Plane<T>(v, p.d);
}
template<class T> Plane<T> operator*(const Plane<T>& p, const Matrix3<T>& m)
{
Vector3<T> v = p.normal * m;
return Plane<T>(v, p.d);
}
template<class T> Plane<T> operator*(const Matrix4<T>& m, const Plane<T>& p)
{
@ -124,4 +135,4 @@ template<class T> Point3<T> Plane<T>::intersection(const Plane<T>& p0,
return Point3<T>(v.x, v.y, v.z);
}
#endif // _PLANE_H_
#endif // _CELMATH_PLANE_H_