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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2000-2005 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
// $Id: Location.h,v 1.67 2007-12-02 23:49:05 alriddoch Exp $
#ifndef MODULES_LOCATION_H
#define MODULES_LOCATION_H
#include "physics/Vector3D.h"
#include "physics/BBox.h"
#include "physics/Quaternion.h"
#include <Atlas/Message/Element.h>
#include <Atlas/Objects/ObjectsFwd.h>
#include <sigc++/trackable.h>
class LocatedEntity;
class Location : virtual public sigc::trackable {
private:
bool m_simple;
bool m_solid;
double m_timeStamp;
float m_boxSize; // Diagonal length across box
float m_squareBoxSize;
float m_radius; // Radius of bounding sphere of box
float m_squareRadius;
public:
LocatedEntity * m_loc;
Point3D m_pos; // Coords relative to m_loc entity
Vector3D m_velocity; // Veclociy vector, relative to m_loc entity.
Vector3D m_acceleration; // Acceleration vector, relative to m_loc entity.
Quaternion m_orientation;
Vector3D m_angular; // Angular velocity vector.
BBox m_bBox;
Location();
explicit Location(LocatedEntity * rf);
explicit Location(LocatedEntity * rf,
const Point3D & pos);
explicit Location(LocatedEntity * rf,
const Point3D & pos,
const Vector3D & velocity);
const float boxSize() const { return m_boxSize; }
const float squareBoxSize() const { return m_squareBoxSize; }
const float radius() const { return m_radius; }
const float squareRadius() const { return m_squareRadius; }
const Point3D & pos() const { return m_pos; }
const Vector3D & velocity() const { return m_velocity; }
const Vector3D & acceleration() const { return m_acceleration; }
const Quaternion & orientation() const { return m_orientation; }
const Vector3D & angular() const { return m_angular; }
const BBox & bBox() const { return m_bBox; }
bool isValid() const {
return ((m_loc != NULL) && m_pos.isValid());
}
bool isSimple() const {
return m_simple;
}
void setSimple(bool c = true) {
m_simple = c;
}
bool isSolid() const {
return m_solid;
}
void setSolid(bool s = true) {
m_solid = s;
}
const double & timeStamp() const {
return m_timeStamp;
}
void update(const double & time) {
m_timeStamp = time;
}
void setBBox(const BBox & b) {
m_bBox = b;
modifyBBox();
}
void addToMessage(Atlas::Message::MapType & ent) const;
void addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const;
const Atlas::Objects::Root asEntity() const;
int readFromEntity(const Atlas::Objects::Entity::RootEntity & ent);
void modifyBBox();
friend std::ostream & operator<<(std::ostream& s, Location& v);
};
const Vector3D distanceTo(const Location & self, const Location & other);
const Point3D relativePos(const Location & self, const Location & other);
const float squareDistance(const Location & self, const Location & other);
const float squareHorizontalDistance(const Location & self,
const Location & other);
inline const float distance(const Location & self, const Location & other)
{
return sqrt(squareDistance(self, other));
}
#endif // MODULES_LOCATION_H
|