mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 18:15:31 +01:00
--HG-- branch : trunk rename : opt/cleanup/tab2spaces.sh => contrib/cleanup/tab2spaces.sh rename : opt/cleanup/whitespace.sh => contrib/cleanup/whitespace.sh rename : opt/conf_merge/README => contrib/conf_merge/README rename : opt/conf_merge/index.php => contrib/conf_merge/index.php rename : opt/conf_merge/merge.php => contrib/conf_merge/merge.php rename : doc/AuctionHouseBot.txt => docs/AuctionHouseBot.txt rename : doc/DocStructure.dox => docs/DocStructure.dox rename : doc/Doxyfile.in => docs/Doxyfile.in rename : doc/EventAI.txt => docs/EventAI.txt rename : doc/HowToScript.txt => docs/HowToScript.txt rename : doc/TextTables.txt => docs/TextTables.txt rename : doc/UnixInstall.txt => docs/UnixInstall.txt rename : externals/jemalloc/include/internal/arena.h => externals/jemalloc/jemalloc/internal/arena.h rename : externals/jemalloc/include/internal/base.h => externals/jemalloc/jemalloc/internal/base.h rename : externals/jemalloc/include/internal/chunk.h => externals/jemalloc/jemalloc/internal/chunk.h rename : externals/jemalloc/include/internal/chunk_dss.h => externals/jemalloc/jemalloc/internal/chunk_dss.h rename : externals/jemalloc/include/internal/chunk_mmap.h => externals/jemalloc/jemalloc/internal/chunk_mmap.h rename : externals/jemalloc/include/internal/chunk_swap.h => externals/jemalloc/jemalloc/internal/chunk_swap.h rename : externals/jemalloc/include/internal/ckh.h => externals/jemalloc/jemalloc/internal/ckh.h rename : externals/jemalloc/include/internal/ctl.h => externals/jemalloc/jemalloc/internal/ctl.h rename : externals/jemalloc/include/internal/extent.h => externals/jemalloc/jemalloc/internal/extent.h rename : externals/jemalloc/include/internal/hash.h => externals/jemalloc/jemalloc/internal/hash.h rename : externals/jemalloc/include/internal/huge.h => externals/jemalloc/jemalloc/internal/huge.h rename : externals/jemalloc/include/internal/jemalloc_internal.h => externals/jemalloc/jemalloc/internal/jemalloc_internal.h rename : externals/jemalloc/include/internal/jemalloc_internal.h.in => externals/jemalloc/jemalloc/internal/jemalloc_internal.h.in rename : externals/jemalloc/include/internal/mb.h => externals/jemalloc/jemalloc/internal/mb.h rename : externals/jemalloc/include/internal/mutex.h => externals/jemalloc/jemalloc/internal/mutex.h rename : externals/jemalloc/include/internal/prof.h => externals/jemalloc/jemalloc/internal/prof.h rename : externals/jemalloc/include/internal/ql.h => externals/jemalloc/jemalloc/internal/ql.h rename : externals/jemalloc/include/internal/qr.h => externals/jemalloc/jemalloc/internal/qr.h rename : externals/jemalloc/include/internal/rb.h => externals/jemalloc/jemalloc/internal/rb.h rename : externals/jemalloc/include/internal/stats.h => externals/jemalloc/jemalloc/internal/stats.h rename : externals/jemalloc/include/internal/tcache.h => externals/jemalloc/jemalloc/internal/tcache.h rename : externals/jemalloc/include/internal/totally_not_p_r_n.h => externals/jemalloc/jemalloc/internal/totally_not_p_r_n.h rename : externals/jemalloc/include/jemalloc.h => externals/jemalloc/jemalloc/jemalloc.h rename : externals/jemalloc/include/jemalloc.h.in => externals/jemalloc/jemalloc/jemalloc.h.in rename : externals/jemalloc/include/jemalloc_defs.h => externals/jemalloc/jemalloc/jemalloc_defs.h rename : externals/jemalloc/include/jemalloc_defs.h.in => externals/jemalloc/jemalloc/jemalloc_defs.h.in
90 lines
1.5 KiB
C++
90 lines
1.5 KiB
C++
/**
|
|
@file Line.cpp
|
|
|
|
Line class
|
|
|
|
@maintainer Morgan McGuire, graphics3d.com
|
|
|
|
@created 2001-06-02
|
|
@edited 2006-01-28
|
|
*/
|
|
|
|
#include "G3D/Line.h"
|
|
#include "G3D/Plane.h"
|
|
|
|
namespace G3D {
|
|
|
|
Vector3 Line::intersection(const Plane& plane) const {
|
|
float d;
|
|
Vector3 normal = plane.normal();
|
|
plane.getEquation(normal, d);
|
|
float rate = _direction.dot(normal);
|
|
|
|
if (rate == 0) {
|
|
|
|
return Vector3::inf();
|
|
|
|
} else {
|
|
float t = -(d + _point.dot(normal)) / rate;
|
|
|
|
return _point + _direction * t;
|
|
}
|
|
}
|
|
|
|
|
|
Line::Line(class BinaryInput& b) {
|
|
deserialize(b);
|
|
}
|
|
|
|
|
|
void Line::serialize(class BinaryOutput& b) const {
|
|
_point.serialize(b);
|
|
_direction.serialize(b);
|
|
}
|
|
|
|
|
|
void Line::deserialize(class BinaryInput& b) {
|
|
_point.deserialize(b);
|
|
_direction.deserialize(b);
|
|
}
|
|
|
|
|
|
Vector3 Line::closestPoint(const Vector3& pt) const {
|
|
float t = _direction.dot(pt - _point);
|
|
return _point + _direction * t;
|
|
}
|
|
|
|
|
|
Vector3 Line::point() const {
|
|
return _point;
|
|
}
|
|
|
|
|
|
Vector3 Line::direction() const {
|
|
return _direction;
|
|
}
|
|
|
|
|
|
Vector3 Line::closestPoint(const Line& B, float& minDist) const {
|
|
const Vector3& P1 = _point;
|
|
const Vector3& U1 = _direction;
|
|
|
|
Vector3 P2 = B.point();
|
|
Vector3 U2 = B.direction();
|
|
|
|
const Vector3& P21 = P2 - P1;
|
|
const Vector3& M = U2.cross(U1);
|
|
float m2 = M.length();
|
|
|
|
Vector3 R = P21.cross(M) / m2;
|
|
|
|
float t1 = R.dot(U2);
|
|
|
|
minDist = abs(P21.dot(M)) / sqrt(m2);
|
|
|
|
return P1 + t1 * U1;
|
|
}
|
|
|
|
}
|
|
|