mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
127 lines
3.3 KiB
C++
127 lines
3.3 KiB
C++
// Cyphesis Online RPG Server and AI Engine
|
|
// Copyright (C) 2011 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$
|
|
|
|
#ifndef PHYSICS_SHAPE_IMPL_H
|
|
#define PHYSICS_SHAPE_IMPL_H
|
|
|
|
#include "Shape.h"
|
|
|
|
#include <Atlas/Message/Element.h>
|
|
|
|
#include <wfmath/atlasconv.h>
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
const char * MathShape<ShapeT, dim>::getType() const
|
|
{
|
|
return "unknown";
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
MathShape<ShapeT, dim>::MathShape()
|
|
{
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
MathShape<ShapeT, dim>::MathShape(const ShapeT<dim> & s) : m_shape(s)
|
|
{
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
size_t MathShape<ShapeT, dim>::size() const
|
|
{
|
|
return m_shape.numCorners();
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
bool MathShape<ShapeT, dim>::isValid() const
|
|
{
|
|
return m_shape.isValid();
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
WFMath::CoordType MathShape<ShapeT, dim>::area() const
|
|
{
|
|
return 1.;
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
WFMath::Point<3> MathShape<ShapeT, dim>::centre() const
|
|
{
|
|
WFMath::Point<2> c = m_shape.getCenter();
|
|
return WFMath::Point<3>(c.x(), c.y(), 0);
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
WFMath::AxisBox<2> MathShape<ShapeT, dim>::footprint() const
|
|
{
|
|
return WFMath::AxisBox<2>();
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
WFMath::Point<3> MathShape<ShapeT, dim>::lowCorner() const
|
|
{
|
|
return m_shape.boundingBox().lowCorner();
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
WFMath::Point<3> MathShape<ShapeT, dim>::highCorner() const
|
|
{
|
|
return m_shape.boundingBox().highCorner();
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
bool MathShape<ShapeT, dim>::intersect(const WFMath::Point<2> & p) const
|
|
{
|
|
return Intersect(m_shape, p, true);
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
void MathShape<ShapeT, dim>::scale(WFMath::CoordType)
|
|
{
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
void MathShape<ShapeT, dim>::toAtlas(Atlas::Message::MapType & data) const
|
|
{
|
|
data["type"] = getType();
|
|
size_t size = m_shape.numCorners();
|
|
if (size > 0) {
|
|
Atlas::Message::ListType points;
|
|
for (size_t i = 0; i < size; ++i) {
|
|
WFMath::Point<dim> corner = m_shape.getCorner(i);
|
|
points.push_back(corner.toAtlas());
|
|
}
|
|
data["points"] = points;
|
|
}
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
void MathShape<ShapeT, dim>::fromAtlas(const Atlas::Message::Element & data)
|
|
{
|
|
m_shape.fromAtlas(data);
|
|
}
|
|
|
|
template<template <int> class ShapeT, int dim>
|
|
void MathShape<ShapeT, dim>::stream(std::ostream & o) const
|
|
{
|
|
o << getType() << ": ";
|
|
o << m_shape;
|
|
}
|
|
|
|
#endif // PHYSICS_SHAPE_IMPL_H
|