Files
TrinityCore/dep/src/g3dlite/Cone.cpp
click e777161888 HIGHLY EXPERIMENTAL - USE AT YOUR OWN RISK
Implement the use of the new vmap3-format by Lynx3d (mad props to you for this, and thanks for the talks earlier)
+ reduced Vmap size to less than one third, and improve precision
+ indoor/outdoor check which allows automatic unmounting of players
+ additional area information from WMOAreaTable.dbc, removed existing "hacks"
+ WMO liquid information for swimming and fishing correctly in buildings/cities/caves/instances (lava and slime WILL hurt from now on!)
- buildfiles for windows are not properly done, and will need to be sorted out
NOTE: Do NOT annoy Lynx3d about this, any issues with this "port" is entirely our fault !
THIS REVISION IS CONSIDERED UNSTABLE AND CONTAINS WORK IN PROGRESS - USE AT YOUR OWN RISK!

--HG--
branch : trunk
2010-06-05 00:59:25 +02:00

80 lines
1.7 KiB
C++

/**
@file Cone.cpp
Cone class
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2001-07-09
@edited 2006-01-29
*/
#include "G3D/platform.h"
#include "G3D/Cone.h"
#include "G3D/Line.h"
#include "G3D/Sphere.h"
#include "G3D/Box.h"
namespace G3D {
Cone::Cone(const Vector3 &tip, const Vector3 &direction, float angle) {
this->tip = tip;
this->direction = direction.direction();
this->angle = angle;
debugAssert(angle >= 0);
debugAssert(angle <= pi());
}
/**
Forms the smallest cone that contains the box. Undefined if
the tip is inside or on the box.
*/
Cone::Cone(const Vector3& tip, const Box& box) {
this->tip = tip;
this->direction = (box.center() - tip).direction();
// Find the biggest angle
float smallestDotProduct = direction.dot((box.corner(0) - tip).direction());
for (int i = 1; i < 8; ++i) {
float dp = direction.dot((box.corner(i) - tip).direction());
debugAssert(dp > 0);
if (dp < smallestDotProduct) {
smallestDotProduct = dp;
}
}
angle = acosf(smallestDotProduct);
}
bool Cone::intersects(const Sphere& b) const {
// If the bounding sphere contains the tip, then
// they definitely touch.
if (b.contains(this->tip)) {
return true;
}
// Move the tip backwards, effectively making the cone bigger
// to account for the radius of the sphere.
Vector3 tip = this->tip - direction * b.radius / sinf(angle);
return Cone(tip, direction, angle).contains(b.center);
}
bool Cone::contains(const Vector3& v) const {
Vector3 d = (v - tip).direction();
float x = d.dot(direction);
return (x > 0) && (x >= cosf(angle));
}
}; // namespace