WFMath
1.0.1
Main Page
Namespaces
Classes
Files
File List
shape.h
1
// shape.h (A general base class for shapes)
2
//
3
// The WorldForge Project
4
// Copyright (C) 2001 The WorldForge Project
5
//
6
// This program is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
10
//
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
//
20
// For information about WorldForge and its authors, please contact
21
// the Worldforge Web Site at http://www.worldforge.org.
22
//
23
24
// Author: Ron Steinke
25
26
// This class borrows heavily from the base shape class in libCoal,
27
// plus certain intersection ideas from stage/shepherd/sylvanus
28
29
30
#ifndef WFMATH_SHAPE_H
31
#define WFMATH_SHAPE_H
32
33
#include <wfmath/vector.h>
34
#include <wfmath/point.h>
35
#include <wfmath/const.h>
36
#include <wfmath/rotmatrix.h>
37
#include <wfmath/axisbox.h>
38
#include <wfmath/ball.h>
39
#include <wfmath/intersect_decls.h>
40
41
namespace
WFMath {
42
44
55
template
<const
int
dim>
56
class
Shape
57
{
58
public
:
59
// The first things in the Shape class are the functions required
60
// by CLASS_LAYOUT for all classes
61
63
Shape
() {}
65
Shape
(
const
Shape<dim>
& s) {}
67
~
Shape
() {}
68
70
friend
std::ostream& operator<< <dim>(std::ostream& os,
const
Shape
& s);
72
friend
std::istream&
operator
>> <dim>(std::istream& is,
Shape
& s);
73
75
Shape
& operator=(
const
Shape
& a);
76
78
bool
isEqualTo
(
const
Shape
& s,
CoordType
tolerance = numeric_constants<CoordType>::epsilon())
const
;
80
bool
operator==
(
const
Shape
& s)
const
{
return
isEqualTo
(s);}
82
bool
operator!=
(
const
Shape
& s)
const
{
return
!
isEqualTo
(s);}
83
85
bool
isValid
()
const
{
return
m_valid;}
86
87
// Now we begin with the functions in the shape interface
88
89
// Descriptive characteristics
90
92
95
size_t
numCorners
()
const
;
// The number of corners, returns zero for Ball<>
97
Point<dim>
getCorner
(
size_t
i)
const
;
// Must have i >= 0 && i < numCorners()
99
Point<dim>
getCenter
()
const
;
// Returns the barycenter of the object
100
101
// Movement functions
102
104
Shape
&
shift
(
const
Vector<dim>
& v);
// Move the shape a certain distance
106
109
Shape
&
moveCornerTo
(
const
Point<dim>
& p,
size_t
corner)
110
{
return
shift
(p -
getCorner
(corner));}
112
115
Shape
&
moveCenterTo
(
const
Point<dim>
& p)
116
{
return
shift
(p -
getCenter
());}
117
118
120
123
Shape
&
rotateCorner
(
const
RotMatrix<dim>
& m,
size_t
corner)
124
{
return
rotatePoint
(m,
getCorner
(corner));}
126
129
Shape
&
rotateCenter
(
const
RotMatrix<dim>
& m)
130
{
return
rotatePoint
(m,
getCenter
());}
132
136
Shape
&
rotatePoint
(
const
RotMatrix<dim>
& m,
const
Point<dim>
& p);
137
138
// Intersection functions
139
141
AxisBox<dim>
boundingBox
()
const
;
143
Ball<dim>
boundingSphere
()
const
;
146
153
Ball<dim>
boundingSphereSloppy
()
const
;
154
156
164
friend
bool
Intersect<dim>(
Shape<dim>
& s1,
Shape<dim>
& s2,
bool
proper);
166
180
friend
bool
Contains<dim>(
Shape<dim>
& s1,
Shape<dim>
& s2,
bool
proper);
181
182
private
:
183
bool
m_valid;
184
};
185
186
//#include<wfmath/shape_funcs.h>
187
188
}
// namespace WFMath
189
190
#endif // WFMATH_SHAPE_H
Generated on Fri Jun 21 2013 17:01:12 for WFMath by
1.8.1.2