ScummVM API documentation
Polygon.h
1
/* ScummVM - Graphic Adventure Engine
2
*
3
* ScummVM is the legal property of its developers, whose names
4
* are too numerous to list here. Please refer to the COPYRIGHT
5
* file distributed with this source distribution.
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*
20
*/
21
22
/*
23
* This code is based on the CRAB engine
24
*
25
* Copyright (c) Arvind Raja Yadav
26
*
27
* Licensed under MIT
28
*
29
*/
30
31
#ifndef CRAB_POLYGON_H
32
#define CRAB_POLYGON_H
33
34
#include "crab/Rectangle.h"
35
#include "crab/vectors.h"
36
37
namespace
Crab {
38
39
//------------------------------------------------------------------------
40
// Purpose: The result of a collision
41
//------------------------------------------------------------------------
42
struct
PolygonCollisionResult
{
43
// Are the Polygons currently intersecting?
44
bool
_intersect;
45
46
// The translation to apply to polygon A to push the polygons apart
47
// Also known as the minimum translation vector
48
Vector2f
_mtv;
49
50
PolygonCollisionResult
() {
51
_intersect =
false
;
52
}
53
};
54
55
//------------------------------------------------------------------------
56
// Purpose: A simple 2D Polygon class
57
//------------------------------------------------------------------------
58
class
Polygon2D
{
59
void
addPoint(
const
Vector2f
&ref,
const
Common::String
&x,
const
Common::String
&y,
Vector2f
&min,
Vector2f
&max);
60
61
public
:
62
// A list of all points
63
Common::Array<Vector2f>
_point;
64
65
// A list of all edges
66
Common::Array<Vector2f>
_edge;
67
68
Polygon2D
() {}
69
Polygon2D
(rapidxml::xml_node<char> *node,
Rect
&bounds) {
70
load(node, bounds);
71
}
72
73
// Returns the approximate axis aligned bounding box of the polygon
74
void
load(rapidxml::xml_node<char> *node,
Rect
&bounds);
75
76
void
setEdge();
77
78
Vector2f
center()
const
;
79
void
offset(
const
float
&x,
const
float
&y);
80
void
offset(
const
Vector2f
&v) {
81
offset(v.x, v.y);
82
}
83
84
// Check if Polygon2D A is going to collide with Polygon2D B for the given velocity
85
// PolyA is this polygon
86
PolygonCollisionResult
collide(
const
Polygon2D
&polyB)
const
;
87
88
// Code for collision with a rectangle
89
PolygonCollisionResult
collide(
const
Rect
&rect)
const
;
90
91
// Find if a point is inside this polygon
92
bool
contains(
const
float
&x,
const
float
&y);
93
94
// Calculate the projection of a polygon on an axis and returns it as a [min, max] interval
95
void
project(
const
Vector2f
&axis,
float
&min,
float
&max)
const
;
96
97
void
draw(
const
int
&xOffset = 0,
const
int
&yOffset = 0,
98
const
uint8 &r = 0,
const
uint8 &g = 0,
const
uint8 &b = 0.0f,
const
uint8 &a = 255);
99
};
100
101
}
// End of namespace Crab
102
103
#endif
// CRAB_POLYGON_H
Common::Array
Definition:
array.h:52
Common::String
Definition:
str.h:59
Crab::Polygon2D
Definition:
Polygon.h:58
Crab::Vector2D< float >
Crab::PolygonCollisionResult
Definition:
Polygon.h:42
Crab::Rect
Definition:
Rectangle.h:42
engines
crab
Polygon.h
Generated on Mon Nov 23 2026 09:15:19 for ScummVM API documentation by
1.9.4