mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
88 lines
2.2 KiB
C++
88 lines
2.2 KiB
C++
// Cyphesis Online RPG Server and AI Engine
|
|
// Copyright (C) 2000,2001 Alistair Riddoch
|
|
//
|
|
// 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.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
// Remember kids, it takes 7 times longer to call mag() than to call relMag(),
|
|
// so if you are comparing vector magnitudes, always use relMag().
|
|
|
|
#include "Vector3D.h"
|
|
|
|
#include <wfmath/vector.h>
|
|
#include <wfmath/point.h>
|
|
|
|
static inline WFMath::CoordType sqr(WFMath::CoordType x)
|
|
{
|
|
return x * x;
|
|
}
|
|
|
|
WFMath::CoordType squareDistance(const Point3D & u, const Point3D & v)
|
|
{
|
|
return (sqr(u.x() - v.x()) + sqr(u.y() - v.y()) + sqr(u.z() - v.z()));
|
|
}
|
|
|
|
void addToEntity(const Point3D & p, std::vector<double> & vd)
|
|
{
|
|
vd.resize(3);
|
|
vd[0] = p[0];
|
|
vd[1] = p[1];
|
|
vd[2] = p[2];
|
|
}
|
|
|
|
void addToEntity(const Vector3D & v, std::vector<double> & vd)
|
|
{
|
|
vd.resize(3);
|
|
vd[0] = v[0];
|
|
vd[1] = v[1];
|
|
vd[2] = v[2];
|
|
}
|
|
|
|
template <typename FloatT>
|
|
int fromStdVector(Point3D & p, const std::vector<FloatT> & vf)
|
|
{
|
|
if (vf.size() != 3) {
|
|
return -1;
|
|
}
|
|
p[0] = vf[0];
|
|
p[1] = vf[1];
|
|
p[2] = vf[2];
|
|
p.setValid();
|
|
return 0;
|
|
}
|
|
|
|
template
|
|
int fromStdVector<double>(Point3D & p, const std::vector<double> & vf);
|
|
|
|
template <typename FloatT>
|
|
int fromStdVector(Vector3D & v, const std::vector<FloatT> & vf)
|
|
{
|
|
if (vf.size() != 3) {
|
|
return -1;
|
|
}
|
|
v[0] = vf[0];
|
|
v[1] = vf[1];
|
|
v[2] = vf[2];
|
|
v.setValid();
|
|
return 0;
|
|
}
|
|
|
|
template
|
|
int fromStdVector<double>(Vector3D & v, const std::vector<double> & vf);
|
|
|
|
WFMath::CoordType sqrMag(const Point3D & p)
|
|
{
|
|
return p.x() * p.x() + p.y() * p.y() + p.z() * p.z();
|
|
}
|