aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/math
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25/math')
-rw-r--r--engines/sword25/math/geometry.cpp2
-rw-r--r--engines/sword25/math/geometry.h2
-rw-r--r--engines/sword25/math/geometry_script.cpp140
-rw-r--r--engines/sword25/math/line.h100
-rw-r--r--engines/sword25/math/polygon.cpp60
-rw-r--r--engines/sword25/math/polygon.h82
-rw-r--r--engines/sword25/math/rect.h46
-rw-r--r--engines/sword25/math/region.cpp38
-rw-r--r--engines/sword25/math/region.h76
-rw-r--r--engines/sword25/math/regionregistry.cpp4
-rw-r--r--engines/sword25/math/regionregistry.h4
-rw-r--r--engines/sword25/math/vertex.cpp8
-rw-r--r--engines/sword25/math/vertex.h76
-rw-r--r--engines/sword25/math/walkregion.cpp53
-rw-r--r--engines/sword25/math/walkregion.h34
15 files changed, 388 insertions, 337 deletions
diff --git a/engines/sword25/math/geometry.cpp b/engines/sword25/math/geometry.cpp
index f6cab4ed80..de65017c32 100644
--- a/engines/sword25/math/geometry.cpp
+++ b/engines/sword25/math/geometry.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
diff --git a/engines/sword25/math/geometry.h b/engines/sword25/math/geometry.h
index 20c7eb4b54..2ea02c8f35 100644
--- a/engines/sword25/math/geometry.h
+++ b/engines/sword25/math/geometry.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
diff --git a/engines/sword25/math/geometry_script.cpp b/engines/sword25/math/geometry_script.cpp
index aaf4c4d604..ccc73d290a 100644
--- a/engines/sword25/math/geometry_script.cpp
+++ b/engines/sword25/math/geometry_script.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -67,11 +67,9 @@ namespace Sword25 {
static void *my_checkudata(lua_State *L, int ud, const char *tname) {
int top = lua_gettop(L);
- void * p = lua_touserdata(L, ud);
- if (p != NULL) /* value is a userdata? */
- {
- if (lua_getmetatable(L, ud)) /* does it have a metatable? */
- {
+ void *p = lua_touserdata(L, ud);
+ if (p != NULL) { /* value is a userdata? */
+ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
// lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
BS_LuaBindhelper::GetMetatable(L, tname);
/* does it have the correct mt? */
@@ -89,7 +87,7 @@ static void *my_checkudata(lua_State *L, int ud, const char *tname) {
// -----------------------------------------------------------------------------
static void NewUintUserData(lua_State *L, unsigned int Value) {
- void * UserData = lua_newuserdata(L, sizeof(Value));
+ void *UserData = lua_newuserdata(L, sizeof(Value));
memcpy(UserData, &Value, sizeof(Value));
}
@@ -157,8 +155,7 @@ static void TablePolygonToPolygon(lua_State *L, BS_Polygon &Polygon) {
Vertecies.reserve(VertexCount);
// Create Vertecies
- for (int i = 0; i < VertexCount; i++)
- {
+ for (int i = 0; i < VertexCount; i++) {
// X Value
lua_rawgeti(L, -1, (i * 2) + 1);
int X = static_cast<int>(lua_tonumber(L, -1));
@@ -220,43 +217,43 @@ static unsigned int TableRegionToRegion(lua_State *L, const char *ClassName) {
int FirstElementType = lua_type(L, -1);
lua_pop(L, 1);
- switch(FirstElementType) {
- case LUA_TNUMBER: {
- BS_Polygon Polygon;
- TablePolygonToPolygon(L, Polygon);
- BS_RegionRegistry::GetInstance().ResolveHandle(RegionHandle)->Init(Polygon);
- }
- break;
-
- case LUA_TTABLE: {
- lua_rawgeti(L, -1, 1);
- BS_Polygon Polygon;
- TablePolygonToPolygon(L, Polygon);
- lua_pop(L, 1);
+ switch (FirstElementType) {
+ case LUA_TNUMBER: {
+ BS_Polygon Polygon;
+ TablePolygonToPolygon(L, Polygon);
+ BS_RegionRegistry::GetInstance().ResolveHandle(RegionHandle)->Init(Polygon);
+ }
+ break;
- int PolygonCount = luaL_getn(L, -1);
- if (PolygonCount == 1)
- BS_RegionRegistry::GetInstance().ResolveHandle(RegionHandle)->Init(Polygon);
- else {
- Common::Array<BS_Polygon> Holes;
- Holes.reserve(PolygonCount - 1);
-
- for (int i = 2; i <= PolygonCount; i++) {
- lua_rawgeti(L, -1, i);
- Holes.resize(Holes.size() + 1);
- TablePolygonToPolygon(L, Holes.back());
- lua_pop(L, 1);
- }
- BS_ASSERT((int)Holes.size() == PolygonCount - 1);
-
- BS_RegionRegistry::GetInstance().ResolveHandle(RegionHandle)->Init(Polygon, &Holes);
- }
+ case LUA_TTABLE: {
+ lua_rawgeti(L, -1, 1);
+ BS_Polygon Polygon;
+ TablePolygonToPolygon(L, Polygon);
+ lua_pop(L, 1);
+
+ int PolygonCount = luaL_getn(L, -1);
+ if (PolygonCount == 1)
+ BS_RegionRegistry::GetInstance().ResolveHandle(RegionHandle)->Init(Polygon);
+ else {
+ Common::Array<BS_Polygon> Holes;
+ Holes.reserve(PolygonCount - 1);
+
+ for (int i = 2; i <= PolygonCount; i++) {
+ lua_rawgeti(L, -1, i);
+ Holes.resize(Holes.size() + 1);
+ TablePolygonToPolygon(L, Holes.back());
+ lua_pop(L, 1);
}
- break;
+ BS_ASSERT((int)Holes.size() == PolygonCount - 1);
- default:
- luaL_error(L, "Illegal region definition.");
- return 0;
+ BS_RegionRegistry::GetInstance().ResolveHandle(RegionHandle)->Init(Polygon, &Holes);
+ }
+ }
+ break;
+
+ default:
+ luaL_error(L, "Illegal region definition.");
+ return 0;
}
#ifdef DEBUG
@@ -268,8 +265,7 @@ static unsigned int TableRegionToRegion(lua_State *L, const char *ClassName) {
// -----------------------------------------------------------------------------
-static void NewUserdataRegion(lua_State *L, const char *ClassName)
-{
+static void NewUserdataRegion(lua_State *L, const char *ClassName) {
// Region due to the Lua code to create
// Any errors that occur will be intercepted to the luaL_error
unsigned int RegionHandle = TableRegionToRegion(L, ClassName);
@@ -308,11 +304,11 @@ static const luaL_reg GEO_FUNCTIONS[] = {
// -----------------------------------------------------------------------------
-static BS_Region * CheckRegion(lua_State *L) {
+static BS_Region *CheckRegion(lua_State *L) {
// The first parameter must be of type 'userdata', and the Metatable class Geo.Region or Geo.WalkRegion
unsigned int *RegionHandlePtr;
if ((RegionHandlePtr = reinterpret_cast<unsigned int *>(my_checkudata(L, 1, REGION_CLASS_NAME))) != 0 ||
- (RegionHandlePtr = reinterpret_cast<unsigned int *>(my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) {
+ (RegionHandlePtr = reinterpret_cast<unsigned int *>(my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) {
return BS_RegionRegistry::GetInstance().ResolveHandle(*RegionHandlePtr);
} else {
luaL_argcheck(L, 0, 1, "'" REGION_CLASS_NAME "' expected");
@@ -325,7 +321,7 @@ static BS_Region * CheckRegion(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_IsValid(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
lua_pushbooleancpp(L, pR->IsValid());
@@ -335,7 +331,7 @@ static int R_IsValid(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_GetX(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
lua_pushnumber(L, pR->GetPosX());
@@ -345,7 +341,7 @@ static int R_GetX(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_GetY(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
lua_pushnumber(L, pR->GetPosY());
@@ -355,7 +351,7 @@ static int R_GetY(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_GetPos(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
BS_Vertex::VertexToLuaVertex(L, pR->GetPosition());
@@ -365,7 +361,7 @@ static int R_GetPos(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_IsPointInRegion(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
BS_Vertex Vertex;
@@ -377,7 +373,7 @@ static int R_IsPointInRegion(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_SetPos(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
BS_Vertex Vertex;
@@ -390,7 +386,7 @@ static int R_SetPos(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_SetX(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
pR->SetPosX(static_cast<int>(luaL_checknumber(L, 2)));
@@ -401,7 +397,7 @@ static int R_SetX(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_SetY(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
pR->SetPosY(static_cast<int>(luaL_checknumber(L, 2)));
@@ -432,24 +428,24 @@ static void DrawRegion(const BS_Region &Region, unsigned int Color, const BS_Ver
// -----------------------------------------------------------------------------
static int R_Draw(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
switch (lua_gettop(L)) {
- case 3: {
- BS_Vertex Offset;
- BS_Vertex::LuaVertexToVertex(L, 3, Offset);
- DrawRegion(*pR, BS_GraphicEngine::LuaColorToARGBColor(L, 2), Offset);
- }
- break;
+ case 3: {
+ BS_Vertex Offset;
+ BS_Vertex::LuaVertexToVertex(L, 3, Offset);
+ DrawRegion(*pR, BS_GraphicEngine::LuaColorToARGBColor(L, 2), Offset);
+ }
+ break;
- case 2:
- DrawRegion(*pR, BS_GraphicEngine::LuaColorToARGBColor(L, 2), BS_Vertex(0, 0));
- break;
+ case 2:
+ DrawRegion(*pR, BS_GraphicEngine::LuaColorToARGBColor(L, 2), BS_Vertex(0, 0));
+ break;
- default:
- DrawRegion(*pR, BS_RGB(255, 255, 255), BS_Vertex(0, 0));
- }
+ default:
+ DrawRegion(*pR, BS_RGB(255, 255, 255), BS_Vertex(0, 0));
+ }
return 0;
}
@@ -457,7 +453,7 @@ static int R_Draw(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_GetCentroid(lua_State *L) {
- BS_Region * RPtr = CheckRegion(L);
+ BS_Region *RPtr = CheckRegion(L);
BS_ASSERT(RPtr);
BS_Vertex::VertexToLuaVertex(L, RPtr->GetCentroid());
@@ -468,7 +464,7 @@ static int R_GetCentroid(lua_State *L) {
// -----------------------------------------------------------------------------
static int R_Delete(lua_State *L) {
- BS_Region * pR = CheckRegion(L);
+ BS_Region *pR = CheckRegion(L);
BS_ASSERT(pR);
delete pR;
return 0;
@@ -540,9 +536,9 @@ static const luaL_reg WALKREGION_METHODS[] = {
// -----------------------------------------------------------------------------
bool BS_Geometry::_RegisterScriptBindings() {
- BS_Kernel * pKernel = BS_Kernel::GetInstance();
+ BS_Kernel *pKernel = BS_Kernel::GetInstance();
BS_ASSERT(pKernel);
- BS_ScriptEngine * pScript = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
+ BS_ScriptEngine *pScript = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
BS_ASSERT(pScript);
lua_State *L = static_cast< lua_State *>(pScript->GetScriptObject());
BS_ASSERT(L);
diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h
index 86bcbd6537..5e442045f1 100644
--- a/engines/sword25/math/line.h
+++ b/engines/sword25/math/line.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -33,15 +33,15 @@
*/
/*
- BS_Line
- -------
- This class contains only static methods, which have to do with straight line
- segments. There is no real straight line segment class. Calculations will be
- used with polygons, and it is important the process of starting and selecting
- endpoints of lines is dynamic. This would prhobit a polygon from a set
- being formed by fixed line segments
-
- Autor: Malte Thiesen
+ BS_Line
+ -------
+ This class contains only static methods, which have to do with straight line
+ segments. There is no real straight line segment class. Calculations will be
+ used with polygons, and it is important the process of starting and selecting
+ endpoints of lines is dynamic. This would prhobit a polygon from a set
+ being formed by fixed line segments
+
+ Autor: Malte Thiesen
*/
#ifndef SWORD25_LINE_H
@@ -61,10 +61,10 @@ class BS_Line {
public:
/**
* Determines whether a piont is left of a line
- * @param a The start point of a line
- * @param b The end point of a line
- * @param c The test point
- * @return Returns true if the point is to the left of the line.
+ * @param a The start point of a line
+ * @param b The end point of a line
+ * @param c The test point
+ * @return Returns true if the point is to the left of the line.
* If the point is to the right of the line or on the line, false is returned.
*/
static bool IsVertexLeft(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) {
@@ -77,10 +77,10 @@ public:
/**
* Determines whether a piont is right of a line
- * @param a The start point of a line
- * @param b The end point of a line
- * @param c The test point
- * @return Returns true if the point is to the right of the line.
+ * @param a The start point of a line
+ * @param b The end point of a line
+ * @param c The test point
+ * @return Returns true if the point is to the right of the line.
* If the point is to the right of the line or on the line, false is returned.
*/
static bool IsVertexRight(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) {
@@ -93,10 +93,10 @@ public:
/**
* Determines whether a piont is on a line
- * @param a The start point of a line
- * @param b The end point of a line
- * @param c The test point
- * @return Returns true if the point is on the line, false otherwise.
+ * @param a The start point of a line
+ * @param b The end point of a line
+ * @param c The test point
+ * @return Returns true if the point is on the line, false otherwise.
*/
static bool IsVertexOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) {
return _TriangleArea2(a, b, c) == 0;
@@ -110,10 +110,10 @@ public:
/**
* Determines where a point is relative to a line.
- * @param a The start point of a line
- * @param b The end point of a line
- * @param c The test point
- * @return LEFT is returned if the point is to the left of the line.
+ * @param a The start point of a line
+ * @param b The end point of a line
+ * @param c The test point
+ * @return LEFT is returned if the point is to the left of the line.
* RIGHT is returned if the point is to the right of the line.
* ON is returned if the point is on the line.
*/
@@ -126,11 +126,11 @@ public:
/**
* Determines whether two lines intersect
- * @param a The start point of the first line
- * @param b The end point of the first line
- * @param c The start point of the second line
- * @param d The end point of the second line
- * @remark In cases where a line only touches the other, false is returned (improper intersection)
+ * @param a The start point of the first line
+ * @param b The end point of the first line
+ * @param c The start point of the second line
+ * @param d The end point of the second line
+ * @remark In cases where a line only touches the other, false is returned (improper intersection)
*/
static bool DoesIntersectProperly(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c, const BS_Vertex &d) {
VERTEX_CLASSIFICATION Class1 = ClassifyVertexToLine(a, b, c);
@@ -140,14 +140,14 @@ public:
if (Class1 == ON || Class2 == ON || Class3 == ON || Class4 == ON) return false;
- return ((Class1 == LEFT) ^ (Class2 == LEFT)) && ((Class3 == LEFT) ^ (Class4 == LEFT));
+ return ((Class1 == LEFT) ^(Class2 == LEFT)) && ((Class3 == LEFT) ^(Class4 == LEFT));
}
/**
* Determines whether a point is on a line segment
- * @param a The start point of a line
- * @param b The end point of a line
- * @param c The test point
+ * @param a The start point of a line
+ * @param b The end point of a line
+ * @param c The test point
*/
static bool IsOnLine(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) {
// The items must all be Collinear, otherwise don't bothering testing the point
@@ -156,14 +156,14 @@ public:
// If the line segment is not vertical, check on the x-axis, otherwise the y-axis
if (a.X != b.X) {
return ((a.X <= c.X) &&
- (c.X <= b.X)) ||
- ((a.X >= c.X) &&
- (c.X >= b.X));
+ (c.X <= b.X)) ||
+ ((a.X >= c.X) &&
+ (c.X >= b.X));
} else {
return ((a.Y <= c.Y) &&
- (c.Y <= b.Y)) ||
- ((a.Y >= c.Y) &&
- (c.Y >= b.Y));
+ (c.Y <= b.Y)) ||
+ ((a.Y >= c.Y) &&
+ (c.Y >= b.Y));
}
}
@@ -174,14 +174,14 @@ public:
// If the line segment is not vertical, check on the x-axis, otherwise the y-axis
if (a.X != b.X) {
return ((a.X < c.X) &&
- (c.X < b.X)) ||
- ((a.X > c.X) &&
- (c.X > b.X));
+ (c.X < b.X)) ||
+ ((a.X > c.X) &&
+ (c.X > b.X));
} else {
return ((a.Y < c.Y) &&
- (c.Y < b.Y)) ||
- ((a.Y > c.Y) &&
- (c.Y > b.Y));
+ (c.Y < b.Y)) ||
+ ((a.Y > c.Y) &&
+ (c.Y > b.Y));
}
}
@@ -189,13 +189,13 @@ private:
/**
* Return double the size of the triangle defined by the three passed points.
*
- * The result is positive if the points are arrange counterclockwise,
+ * The result is positive if the points are arrange counterclockwise,
* and negative if they are arranged counter-clockwise.
*/
static int _TriangleArea2(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) {
return a.X * b.Y - a.Y * b.X +
- a.Y * c.X - a.X * c.Y +
- b.X * c.Y - c.X * b.Y;
+ a.Y * c.X - a.X * c.Y +
+ b.X * c.Y - c.X * b.Y;
}
};
diff --git a/engines/sword25/math/polygon.cpp b/engines/sword25/math/polygon.cpp
index 6d416ea080..a972596d29 100644
--- a/engines/sword25/math/polygon.cpp
+++ b/engines/sword25/math/polygon.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -50,7 +50,7 @@ namespace Sword25 {
BS_Polygon::BS_Polygon() : VertexCount(0), Vertecies(NULL) {
}
-BS_Polygon::BS_Polygon(int VertexCount, const BS_Vertex *Vertecies) : VertexCount(0), Vertecies(NULL) {
+BS_Polygon::BS_Polygon(int VertexCount, const BS_Vertex *Vertecies) : VertexCount(0), Vertecies(NULL) {
Init(VertexCount, Vertecies);
}
@@ -142,7 +142,7 @@ int BS_Polygon::FindLRVertexIndex() const {
for (int i = 1; i < VertexCount; i++) {
if (Vertecies[i].Y > MaxY ||
- (Vertecies[i].Y == MaxY && Vertecies[i].X > MaxX)) {
+ (Vertecies[i].Y == MaxY && Vertecies[i].X > MaxX)) {
MaxX = Vertecies[i].X;
MaxY = Vertecies[i].Y;
CurIndex = i;
@@ -151,7 +151,7 @@ int BS_Polygon::FindLRVertexIndex() const {
return CurIndex;
}
-
+
return -1;
}
@@ -231,7 +231,7 @@ void BS_Polygon::ReverseVertexOrder() {
int BS_Polygon::CrossProduct(const BS_Vertex &V1, const BS_Vertex &V2, const BS_Vertex &V3) const {
return (V2.X - V1.X) * (V3.Y - V2.Y) -
- (V2.Y - V1.Y) * (V3.X - V2.X);
+ (V2.Y - V1.Y) * (V3.X - V2.X);
}
// Scalar Product
@@ -239,7 +239,7 @@ int BS_Polygon::CrossProduct(const BS_Vertex &V1, const BS_Vertex &V2, const BS_
int BS_Polygon::DotProduct(const BS_Vertex &V1, const BS_Vertex &V2, const BS_Vertex &V3) const {
return (V1.X - V2.X) * (V3.X - V2.X) +
- (V1.Y - V2.Y) * (V3.X - V2.Y);
+ (V1.Y - V2.Y) * (V3.X - V2.Y);
}
// Check for self-intersections
@@ -250,22 +250,22 @@ bool BS_Polygon::CheckForSelfIntersection() const {
/*
float AngleSum = 0.0f;
for (int i = 0; i < VertexCount; i++) {
- int j = (i + 1) % VertexCount;
- int k = (i + 2) % VertexCount;
-
- float Dot = DotProduct(Vertecies[i], Vertecies[j], Vertecies[k]);
-
- // Skalarproduct normalisieren
- float Length1 = sqrt((Vertecies[i].X - Vertecies[j].X) * (Vertecies[i].X - Vertecies[j].X) +
- (Vertecies[i].Y - Vertecies[j].Y) * (Vertecies[i].Y - Vertecies[j].Y));
- float Length2 = sqrt((Vertecies[k].X - Vertecies[j].X) * (Vertecies[k].X - Vertecies[j].X) +
- (Vertecies[k].Y - Vertecies[j].Y) * (Vertecies[k].Y - Vertecies[j].Y));
- float Norm = Length1 * Length2;
-
- if (Norm > 0.0f) {
- Dot /= Norm;
- AngleSum += acos(Dot);
- }
+ int j = (i + 1) % VertexCount;
+ int k = (i + 2) % VertexCount;
+
+ float Dot = DotProduct(Vertecies[i], Vertecies[j], Vertecies[k]);
+
+ // Skalarproduct normalisieren
+ float Length1 = sqrt((Vertecies[i].X - Vertecies[j].X) * (Vertecies[i].X - Vertecies[j].X) +
+ (Vertecies[i].Y - Vertecies[j].Y) * (Vertecies[i].Y - Vertecies[j].Y));
+ float Length2 = sqrt((Vertecies[k].X - Vertecies[j].X) * (Vertecies[k].X - Vertecies[j].X) +
+ (Vertecies[k].Y - Vertecies[j].Y) * (Vertecies[k].Y - Vertecies[j].Y));
+ float Norm = Length1 * Length2;
+
+ if (Norm > 0.0f) {
+ Dot /= Norm;
+ AngleSum += acos(Dot);
+ }
}
*/
@@ -299,7 +299,7 @@ bool BS_Polygon::IsLineInterior(const BS_Vertex &a, const BS_Vertex &b) const {
int j = (i + 1) % VertexCount;
const BS_Vertex &VS = Vertecies[i];
const BS_Vertex &VE = Vertecies[j];
-
+
// If the line intersects a line segment strictly (proper cross section) the line is not in the polygon
if (BS_Line::DoesIntersectProperly(a, b, VS, VE)) return false;
@@ -360,17 +360,17 @@ bool BS_Polygon::IsLineInCone(int StartVertexIndex, const BS_Vertex &EndVertex,
if (BS_Line::IsVertexLeftOn(PrevVertex, StartVertex, NextVertex)) {
if (IncludeEdges)
return BS_Line::IsVertexLeftOn(EndVertex, StartVertex, NextVertex) &&
- BS_Line::IsVertexLeftOn(StartVertex, EndVertex, PrevVertex);
+ BS_Line::IsVertexLeftOn(StartVertex, EndVertex, PrevVertex);
else
return BS_Line::IsVertexLeft(EndVertex, StartVertex, NextVertex) &&
- BS_Line::IsVertexLeft(StartVertex, EndVertex, PrevVertex);
+ BS_Line::IsVertexLeft(StartVertex, EndVertex, PrevVertex);
} else {
if (IncludeEdges)
return !(BS_Line::IsVertexLeft(EndVertex, StartVertex, PrevVertex) &&
- BS_Line::IsVertexLeft(StartVertex, EndVertex, NextVertex));
+ BS_Line::IsVertexLeft(StartVertex, EndVertex, NextVertex));
else
return !(BS_Line::IsVertexLeftOn(EndVertex, StartVertex, PrevVertex) &&
- BS_Line::IsVertexLeftOn(StartVertex, EndVertex, NextVertex));
+ BS_Line::IsVertexLeftOn(StartVertex, EndVertex, NextVertex));
}
}
@@ -399,15 +399,15 @@ bool BS_Polygon::IsPointInPolygon(const BS_Vertex &Point, bool EdgesBelongToPoly
if ((Term1 > 0) == (Term2 >= 0)) Rcross++;
}
- if ((EdgeStart.Y < Point.Y) != (EdgeEnd.Y < Point.Y)) {
+ if ((EdgeStart.Y < Point.Y) != (EdgeEnd.Y < Point.Y)) {
int Term1 = (EdgeStart.X - Point.X) * (EdgeEnd.Y - Point.Y) - (EdgeEnd.X - Point.X) * (EdgeStart.Y - Point.Y);
int Term2 = (EdgeEnd.Y - Point.Y) - (EdgeStart.Y - EdgeEnd.Y);
if ((Term1 < 0) == (Term2 <= 0)) Lcross++;
}
- }
+ }
// The point is on an adge, if the number of left and right intersections have the same even numbers
- if ((Rcross % 2 ) != (Lcross % 2 )) return EdgesBelongToPolygon;
+ if ((Rcross % 2) != (Lcross % 2)) return EdgesBelongToPolygon;
// The point is strictly inside the polygon if and only if the number of overlaps is odd
if ((Rcross % 2) == 1) return true;
diff --git a/engines/sword25/math/polygon.h b/engines/sword25/math/polygon.h
index d435c9746b..1621efb645 100644
--- a/engines/sword25/math/polygon.h
+++ b/engines/sword25/math/polygon.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -49,7 +49,7 @@ namespace Sword25 {
class BS_Vertex;
/**
- @brief Eine Polygonklasse.
+ @brief Eine Polygonklasse.
*/
class BS_Polygon : public BS_Persistable {
public:
@@ -72,9 +72,9 @@ public:
/**
* Creaes an object of type #BS_Polygon, and assigns Vertices to it
- * @param VertexCount The number of vertices being passed
- * @param Vertecies An array of BS_Vertex objects representing the vertices in the polygon.
- * @remark The Vertecies that define a polygon must not have any self-intersections.
+ * @param VertexCount The number of vertices being passed
+ * @param Vertecies An array of BS_Vertex objects representing the vertices in the polygon.
+ * @remark The Vertecies that define a polygon must not have any self-intersections.
* If the polygon does have self-intersections, then an empty polygon object is created.
*/
BS_Polygon(int VertexCount, const BS_Vertex *Vertecies);
@@ -90,9 +90,9 @@ public:
* The Vertices need to define a polygon must not have self-intersections.
* If a polygon already has verticies, this will re-initialise it with the new list.
*
- * @param VertexCount The number of vertices being passed
- * @param Vertecies An array of BS_Vertex objects representing the vertices in the polygon.
- * @return Returns false if the Vertecies have self-intersections. In this case,
+ * @param VertexCount The number of vertices being passed
+ * @param Vertecies An array of BS_Vertex objects representing the vertices in the polygon.
+ * @return Returns false if the Vertecies have self-intersections. In this case,
* the object is not initialised.
*/
bool Init(int VertexCount, const BS_Vertex *Vertecies);
@@ -100,51 +100,51 @@ public:
//
// ** Exploratory methods **
//
-
+
/**
* Checks whether the Vertecies of the polygon are arranged in a clockwise direction.
- * @return Returns true if the Vertecies of the polygon are arranged clockwise or co-planar.
+ * @return Returns true if the Vertecies of the polygon are arranged clockwise or co-planar.
* Returns false if the Vertecies of the polygon are arrange counter-clockwise.
- * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
+ * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
*/
bool IsCW() const;
/**
* Checks whether the Vertices of the polygon are arranged in a counter-clockwise direction.
- * @return Returns true if the Vertecies of the polygon are arranged counter-clockwise.
+ * @return Returns true if the Vertecies of the polygon are arranged counter-clockwise.
* Returns false if the Vertecies of the polygon are arranged clockwise or co-planar.
- * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
+ * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
*/
bool IsCCW() const;
/**
* Checks whether the polygon is convex.
- * @return Returns true if the polygon is convex. Returns false if the polygon is concave.
- * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
+ * @return Returns true if the polygon is convex. Returns false if the polygon is concave.
+ * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
*/
bool IsConvex() const;
- /**
+ /**
* Checks whether the polygon is concave.
- * @return Returns true if the polygon is concave. Returns false if the polygon is convex.
- * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
+ * @return Returns true if the polygon is concave. Returns false if the polygon is convex.
+ * @remark This method only returns a meaningful result if the polygon has at least three Vertecies.
*/
bool IsConcave() const;
/**
* Checks whether a point is inside the polygon
- * @param Vertex A Vertex with the co-ordinates of the point to be tested.
- * @param BorderBelongsToPolygon Specifies whether the edge of the polygon should be considered
- * @return Returns true if the point is inside the polygon, false if it is outside.
+ * @param Vertex A Vertex with the co-ordinates of the point to be tested.
+ * @param BorderBelongsToPolygon Specifies whether the edge of the polygon should be considered
+ * @return Returns true if the point is inside the polygon, false if it is outside.
*/
bool IsPointInPolygon(const BS_Vertex &Vertex, bool BorderBelongsToPolygon = true) const;
/**
* Checks whether a point is inside the polygon
- * @param X The X position of the point
- * @param Y The Y position of the point
- * @param BorderBelongsToPolygon Specifies whether the edge of the polygon should be considered
- * @return Returns true if the point is inside the polygon, false if it is outside.
+ * @param X The X position of the point
+ * @param Y The Y position of the point
+ * @param BorderBelongsToPolygon Specifies whether the edge of the polygon should be considered
+ * @return Returns true if the point is inside the polygon, false if it is outside.
*/
bool IsPointInPolygon(int X, int Y, bool BorderBelongsToPolygon = true) const;
@@ -181,7 +181,7 @@ public:
/**
* Moves the polygon.
- * @param Delta The vertex around the polygon to be moved.
+ * @param Delta The vertex around the polygon to be moved.
*/
void operator+=(const BS_Vertex &Delta);
@@ -201,7 +201,7 @@ private:
bool m_IsCW;
bool m_IsConvex;
BS_Vertex m_Centroid;
-
+
/**
* Computes the centroid of the polygon.
*/
@@ -209,24 +209,24 @@ private:
/**
* Determines how the Vertecies of the polygon are arranged.
- * @return Returns true if the Vertecies are arranged in a clockwise
+ * @return Returns true if the Vertecies are arranged in a clockwise
* direction, otherwise false.
*/
bool ComputeIsCW() const;
/**
* Determines whether the polygon is convex or concave.
- * @return Returns true if the polygon is convex, otherwise false.
+ * @return Returns true if the polygon is convex, otherwise false.
*/
bool ComputeIsConvex() const;
/**
* Calculates the cross product of three Vertecies
- * @param V1 The first Vertex
- * @param V2 The second Vertex
- * @param V3 The third Vertex
- * @return Returns the cross-product of the three vertecies
- * @todo This method would be better as a method of the BS_Vertex class
+ * @param V1 The first Vertex
+ * @param V2 The second Vertex
+ * @param V3 The third Vertex
+ * @return Returns the cross-product of the three vertecies
+ * @todo This method would be better as a method of the BS_Vertex class
*/
int CrossProduct(const BS_Vertex &V1, const BS_Vertex &V2, const BS_Vertex &V3) const;
@@ -235,17 +235,17 @@ private:
*
* The vectors are spanned by V2->V1 and V2->V3
*
- * @param V1 The first Vertex
- * @param V2 The second Vertex
- * @param V3 The third Vertex
- * @return Returns the dot product of the three Vertecies.
- * @todo This method would be better as a method of the BS_Vertex class
+ * @param V1 The first Vertex
+ * @param V2 The second Vertex
+ * @param V3 The third Vertex
+ * @return Returns the dot product of the three Vertecies.
+ * @todo This method would be better as a method of the BS_Vertex class
*/
int DotProduct(const BS_Vertex &V1, const BS_Vertex &V2, const BS_Vertex &V3) const;
/**
* Checks whether the polygon is self-intersecting
- * @return Returns true if the polygon is self-intersecting.
+ * @return Returns true if the polygon is self-intersecting.
* Returns false if the polygon is not self-intersecting.
*/
bool CheckForSelfIntersection() const;
@@ -253,7 +253,7 @@ private:
/**
* Find the vertex of the polygon that is located below the right-most point,
* and returns it's index in the vertex array.
- * @return Returns the index of the vertex at the bottom-right of the polygon.
+ * @return Returns the index of the vertex at the bottom-right of the polygon.
* Returns -1 if the vertex list is empty.
*/
int FindLRVertexIndex() const;
diff --git a/engines/sword25/math/rect.h b/engines/sword25/math/rect.h
index c2a42e85c4..e97feefe41 100644
--- a/engines/sword25/math/rect.h
+++ b/engines/sword25/math/rect.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -54,9 +54,13 @@ public:
BS_Rect(int16 w, int16 h) : Common::Rect(w, h) {}
BS_Rect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1, y1, x2, y2) {}
- void Move(int DeltaX, int DeltaY) { translate(DeltaX, DeltaY); }
+ void Move(int DeltaX, int DeltaY) {
+ translate(DeltaX, DeltaY);
+ }
- bool DoesIntersect(const BS_Rect &Rect_) const { return intersects(Rect_); }
+ bool DoesIntersect(const BS_Rect &Rect_) const {
+ return intersects(Rect_);
+ }
bool Intersect(const BS_Rect &Rect_, BS_Rect &Result) const {
Result = Rect_;
@@ -70,23 +74,41 @@ public:
Result.extend(*this);
}
- int GetWidth() const { return width(); }
+ int GetWidth() const {
+ return width();
+ }
- int GetHeight() const { return height(); }
+ int GetHeight() const {
+ return height();
+ }
- int GetArea() const { return width() * height(); }
+ int GetArea() const {
+ return width() * height();
+ }
- bool operator==(const BS_Rect &rhs) const { return equals(rhs); }
+ bool operator==(const BS_Rect &rhs) const {
+ return equals(rhs);
+ }
- bool operator!= (const BS_Rect &rhs) const { return !equals(rhs); }
+ bool operator!= (const BS_Rect &rhs) const {
+ return !equals(rhs);
+ }
- bool IsValid() const { return isValidRect(); }
+ bool IsValid() const {
+ return isValidRect();
+ }
- bool IsPointInRect(const BS_Vertex &Vertex) const { return contains(Vertex.X, Vertex.Y); }
+ bool IsPointInRect(const BS_Vertex &Vertex) const {
+ return contains(Vertex.X, Vertex.Y);
+ }
- bool IsPointInRect(int X, int Y) const { return contains(X, Y); }
+ bool IsPointInRect(int X, int Y) const {
+ return contains(X, Y);
+ }
- bool ContainsRect(const BS_Rect &OtherRect) const { return contains(OtherRect); }
+ bool ContainsRect(const BS_Rect &OtherRect) const {
+ return contains(OtherRect);
+ }
};
} // End of namespace Sword25
diff --git a/engines/sword25/math/region.cpp b/engines/sword25/math/region.cpp
index bab5381990..b967d001c5 100644
--- a/engines/sword25/math/region.cpp
+++ b/engines/sword25/math/region.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -60,18 +60,18 @@ BS_Region::BS_Region(BS_InputPersistenceBlock &Reader, unsigned int Handle) : m_
// -----------------------------------------------------------------------------
unsigned int BS_Region::Create(REGION_TYPE Type) {
- BS_Region * RegionPtr = NULL;
+ BS_Region *RegionPtr = NULL;
switch (Type) {
- case RT_REGION:
- RegionPtr = new BS_Region();
- break;
+ case RT_REGION:
+ RegionPtr = new BS_Region();
+ break;
- case RT_WALKREGION:
- RegionPtr = new BS_WalkRegion();
- break;
+ case RT_WALKREGION:
+ RegionPtr = new BS_WalkRegion();
+ break;
- default:
- BS_ASSERT(true);
+ default:
+ BS_ASSERT(true);
}
return BS_RegionRegistry::GetInstance().ResolvePtr(RegionPtr);
@@ -79,7 +79,7 @@ unsigned int BS_Region::Create(REGION_TYPE Type) {
// -----------------------------------------------------------------------------
-unsigned int BS_Region::Create(BS_InputPersistenceBlock & Reader, unsigned int Handle) {
+unsigned int BS_Region::Create(BS_InputPersistenceBlock &Reader, unsigned int Handle) {
// Read type
unsigned int Type;
Reader.Read(Type);
@@ -105,7 +105,7 @@ BS_Region::~BS_Region() {
// -----------------------------------------------------------------------------
-bool BS_Region::Init(const BS_Polygon& Contour, const Common::Array<BS_Polygon> *pHoles) {
+bool BS_Region::Init(const BS_Polygon &Contour, const Common::Array<BS_Polygon> *pHoles) {
// Reset object state
m_Valid = false;
m_Position = BS_Vertex(0, 0);
@@ -125,7 +125,7 @@ bool BS_Region::Init(const BS_Polygon& Contour, const Common::Array<BS_Polygon>
// Place the hole polygons in the following positions
if (pHoles) {
- for (unsigned int i = 0; i< pHoles->size(); ++i) {
+ for (unsigned int i = 0; i < pHoles->size(); ++i) {
m_Polygons.push_back(BS_Polygon());
m_Polygons[i + 1].Init((*pHoles)[i].VertexCount, (*pHoles)[i].Vertecies);
m_Polygons[i + 1].EnsureCWOrder();
@@ -201,7 +201,7 @@ bool BS_Region::IsPointInRegion(int X, int Y) const {
if (m_Polygons[0].IsPointInPolygon(X, Y, true)) {
// Test whether the point is in a hole
for (unsigned int i = 1; i < m_Polygons.size(); i++) {
- if (m_Polygons[i].IsPointInPolygon(X,Y, false))
+ if (m_Polygons[i].IsPointInPolygon(X, Y, false))
return false;
}
@@ -233,7 +233,7 @@ BS_Vertex BS_Region::FindClosestRegionPoint(const BS_Vertex &Point) const {
}
}
- const BS_Polygon & Polygon = m_Polygons[PolygonIdx];
+ const BS_Polygon &Polygon = m_Polygons[PolygonIdx];
BS_ASSERT(Polygon.VertexCount > 1);
@@ -303,8 +303,8 @@ BS_Vertex BS_Region::FindClosestPointOnLine(const BS_Vertex &LineStart, const BS
float Vector2Length = sqrtf(Vector2X * Vector2X + Vector2Y * Vector2Y);
Vector2X /= Vector2Length;
Vector2Y /= Vector2Length;
- float Distance = sqrtf(static_cast<float>((LineStart.X - LineEnd.X) * (LineStart.X - LineEnd.X) +
- (LineStart.Y - LineEnd.Y) * (LineStart.Y - LineEnd.Y)));
+ float Distance = sqrtf(static_cast<float>((LineStart.X - LineEnd.X) * (LineStart.X - LineEnd.X) +
+ (LineStart.Y - LineEnd.Y) * (LineStart.Y - LineEnd.Y)));
float Dot = Vector1X * Vector2X + Vector1Y * Vector2Y;
if (Dot <= 0) return LineStart;
@@ -341,7 +341,7 @@ bool BS_Region::Persist(BS_OutputPersistenceBlock &Writer) {
Writer.Write(m_Valid);
Writer.Write(m_Position.X);
Writer.Write(m_Position.Y);
-
+
Writer.Write(m_Polygons.size());
Common::Array<BS_Polygon>::iterator It = m_Polygons.begin();
while (It != m_Polygons.end()) {
@@ -385,7 +385,7 @@ BS_Vertex BS_Region::GetCentroid() const {
if (m_Polygons.size() > 0)
return m_Polygons[0].GetCentroid();
return
- BS_Vertex();
+ BS_Vertex();
}
} // End of namespace Sword25
diff --git a/engines/sword25/math/region.h b/engines/sword25/math/region.h
index 577da94fac..e3718dd1c9 100644
--- a/engines/sword25/math/region.h
+++ b/engines/sword25/math/region.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -77,11 +77,11 @@ public:
/**
* Initialises a BS_Region object
- * @param Contour A polygon indicating the outline of the region
- * @param pHoles A pointer to an array of polygons representing the hole state in the region.
+ * @param Contour A polygon indicating the outline of the region
+ * @param pHoles A pointer to an array of polygons representing the hole state in the region.
* If the region has no holes, it must be passed as NULL. The default value is NULL.
- * @return Returns true if the initialisation was successful, otherwise false.
- * @remark If the region was already initialised, the old state will be deleted.
+ * @return Returns true if the initialisation was successful, otherwise false.
+ * @remark If the region was already initialised, the old state will be deleted.
*/
virtual bool Init(const BS_Polygon &Contour, const Common::Array<BS_Polygon> *pHoles = NULL);
@@ -91,65 +91,77 @@ public:
/**
* Specifies whether the object is in a valid state
- * @return Returns true if the object is in a valid state, otherwise false.
- * @remark Invalid objects can be made valid by calling Init with a valid state.
+ * @return Returns true if the object is in a valid state, otherwise false.
+ * @remark Invalid objects can be made valid by calling Init with a valid state.
*/
- bool IsValid() const { return m_Valid; }
+ bool IsValid() const {
+ return m_Valid;
+ }
/**
* Returns the position of the region
*/
- const BS_Vertex &GetPosition() const { return m_Position; }
+ const BS_Vertex &GetPosition() const {
+ return m_Position;
+ }
/**
* Returns the X position of the region
*/
- int GetPosX() const { return m_Position.X; }
+ int GetPosX() const {
+ return m_Position.X;
+ }
/**
* Returns the Y position of the region
*/
- int GetPosY() const { return m_Position.Y; }
+ int GetPosY() const {
+ return m_Position.Y;
+ }
/**
* Indicates whether a point is inside the region
- * @param Vertex A verex with the co-ordinates of the test point
- * @return Returns true if the point is within the region, otherwise false.
+ * @param Vertex A verex with the co-ordinates of the test point
+ * @return Returns true if the point is within the region, otherwise false.
*/
bool IsPointInRegion(const BS_Vertex &Vertex) const;
/**
* Indicates whether a point is inside the region
- * @param X The X position
- * @param Y The Y position
- * @return Returns true if the point is within the region, otherwise false.
+ * @param X The X position
+ * @param Y The Y position
+ * @return Returns true if the point is within the region, otherwise false.
*/
bool IsPointInRegion(int X, int Y) const;
/**
* Returns the countour of the region
*/
- const BS_Polygon &GetContour() const { return m_Polygons[0]; }
+ const BS_Polygon &GetContour() const {
+ return m_Polygons[0];
+ }
/**
* Returns the number of polygons in the hole region
*/
- int GetHoleCount() const { return static_cast<int>(m_Polygons.size() - 1); }
+ int GetHoleCount() const {
+ return static_cast<int>(m_Polygons.size() - 1);
+ }
/**
* Returns a specific hole polygon in the region
- * @param i The number of the hole to return.
+ * @param i The number of the hole to return.
* The index must be between 0 and GetHoleCount() - 1.
- * @return Returns the desired hole polygon
+ * @return Returns the desired hole polygon
*/
inline const BS_Polygon &GetHole(unsigned int i) const;
/**
* For a point outside the region, finds the closest point inside the region
- * @param Point The point that is outside the region
- * @return Returns the point within the region which is closest
- * @remark This method does not always work with pixel accuracy.
- * One should not therefore rely on the fact that there is really no point in
+ * @param Point The point that is outside the region
+ * @return Returns the point within the region which is closest
+ * @remark This method does not always work with pixel accuracy.
+ * One should not therefore rely on the fact that there is really no point in
* the region which is closer to the given point.
*/
BS_Vertex FindClosestRegionPoint(const BS_Vertex &Point) const;
@@ -167,20 +179,20 @@ public:
/**
* Sets the position of the region
- * @param X The new X psoition of the region
- * @param Y The new Y psoition of the region
+ * @param X The new X psoition of the region
+ * @param Y The new Y psoition of the region
*/
virtual void SetPos(int X, int Y);
/**
* Sets the X position of the region
- * @param X The new X position of the region
+ * @param X The new X position of the region
*/
void SetPosX(int X);
/**
* Sets the Y position of the region
- * @param Y The new Y position of the region
+ * @param Y The new Y position of the region
*/
void SetPosY(int Y);
@@ -211,10 +223,10 @@ protected:
/**
* Find the point on a line which is closest to another point
- * @param LineStart The start of the line
- * @param LineEnd The end of the line
- * @param Point The point to be compared against
- * @return Returns the point on the line which is cloest to the passed point.
+ * @param LineStart The start of the line
+ * @param LineEnd The end of the line
+ * @param Point The point to be compared against
+ * @return Returns the point on the line which is cloest to the passed point.
*/
BS_Vertex FindClosestPointOnLine(const BS_Vertex &LineStart, const BS_Vertex &LineEnd, const BS_Vertex Point) const;
};
diff --git a/engines/sword25/math/regionregistry.cpp b/engines/sword25/math/regionregistry.cpp
index f29b92e8b7..b03d1c1152 100644
--- a/engines/sword25/math/regionregistry.cpp
+++ b/engines/sword25/math/regionregistry.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -110,7 +110,7 @@ bool BS_RegionRegistry::Unpersist(BS_InputPersistenceBlock &Reader) {
Reader.Read(RegionCount);
// Restore all the BS_Regions objects
- for (unsigned int i = 0; i < RegionCount; ++i) {
+ for (unsigned int i = 0; i < RegionCount; ++i) {
// Handle read
unsigned int Handle;
Reader.Read(Handle);
diff --git a/engines/sword25/math/regionregistry.h b/engines/sword25/math/regionregistry.h
index 3c4771df5f..9600dbbdc4 100644
--- a/engines/sword25/math/regionregistry.h
+++ b/engines/sword25/math/regionregistry.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -58,7 +58,7 @@ class BS_Region;
class BS_RegionRegistry : public BS_ObjectRegistry<BS_Region>, public BS_Persistable {
public:
- static BS_RegionRegistry & GetInstance() {
+ static BS_RegionRegistry &GetInstance() {
if (!m_InstancePtr.get()) m_InstancePtr = Common::SharedPtr<BS_RegionRegistry>(new BS_RegionRegistry());
return *m_InstancePtr.get();
}
diff --git a/engines/sword25/math/vertex.cpp b/engines/sword25/math/vertex.cpp
index ef49fd8139..575618dbb9 100644
--- a/engines/sword25/math/vertex.cpp
+++ b/engines/sword25/math/vertex.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -38,8 +38,8 @@ namespace Lua {
extern "C"
{
- #include "sword25/util/lua/lua.h"
- #include "sword25/util/lua/lauxlib.h"
+#include "sword25/util/lua/lua.h"
+#include "sword25/util/lua/lauxlib.h"
}
}
@@ -79,7 +79,7 @@ BS_Vertex &BS_Vertex::LuaVertexToVertex(lua_State *L, int StackIndex, BS_Vertex
// -----------------------------------------------------------------------------
-void BS_Vertex::VertexToLuaVertex(lua_State * L, const BS_Vertex &Vertex) {
+void BS_Vertex::VertexToLuaVertex(lua_State *L, const BS_Vertex &Vertex) {
// Create New Table
lua_newtable(L);
diff --git a/engines/sword25/math/vertex.h b/engines/sword25/math/vertex.h
index 65c179d654..b39de82fac 100644
--- a/engines/sword25/math/vertex.h
+++ b/engines/sword25/math/vertex.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -33,10 +33,10 @@
*/
/*
- BS_Vertex
- ---------
+ BS_Vertex
+ ---------
- Autor: Malte Thiesen
+ Autor: Malte Thiesen
*/
#ifndef SWORD25_VERTEX_H
@@ -63,7 +63,10 @@ namespace Sword25 {
class BS_Vertex {
public:
BS_Vertex() : X(0), Y(0) {};
- BS_Vertex(int X_, int Y_) { this->X = X_; this->Y = Y_; }
+ BS_Vertex(int X_, int Y_) {
+ this->X = X_;
+ this->Y = Y_;
+ }
int X;
int Y;
@@ -71,78 +74,93 @@ public:
/**
* Compares two Vertecies.
*/
- inline bool operator==(const BS_Vertex& rhs) const { if (X == rhs.X && Y == rhs.Y) return true; return false; }
+ inline bool operator==(const BS_Vertex &rhs) const {
+ if (X == rhs.X && Y == rhs.Y) return true;
+ return false;
+ }
/**
* Compares two Vertecies.
*/
- inline bool operator!=(const BS_Vertex& rhs) const { if (X != rhs.X || Y != rhs.Y) return true; return false; }
+ inline bool operator!=(const BS_Vertex &rhs) const {
+ if (X != rhs.X || Y != rhs.Y) return true;
+ return false;
+ }
/**
* Adds a vertex to vertex
*/
- inline void operator+=(const BS_Vertex& Delta) { X += Delta.X; Y += Delta.Y; }
+ inline void operator+=(const BS_Vertex &Delta) {
+ X += Delta.X;
+ Y += Delta.Y;
+ }
/**
* Subtracts a vertex from a vertex
*/
- inline void operator-=(const BS_Vertex& Delta) { X -= Delta.X; Y -= Delta.Y; }
+ inline void operator-=(const BS_Vertex &Delta) {
+ X -= Delta.X;
+ Y -= Delta.Y;
+ }
/**
* Adds two vertecies
*/
- inline BS_Vertex operator+(const BS_Vertex& Delta) const { return BS_Vertex(X + Delta.X, Y + Delta.Y); }
+ inline BS_Vertex operator+(const BS_Vertex &Delta) const {
+ return BS_Vertex(X + Delta.X, Y + Delta.Y);
+ }
/**
* Subtracts two vertecies
*/
- inline BS_Vertex operator-(const BS_Vertex& Delta) const { return BS_Vertex(X - Delta.X, Y - Delta.Y); }
+ inline BS_Vertex operator-(const BS_Vertex &Delta) const {
+ return BS_Vertex(X - Delta.X, Y - Delta.Y);
+ }
/**
* Calculates the square of the distance between two Vertecies.
- * @param Vertex The vertex for which the distance is to be calculated
- * @return Returns the square of the distance between itself and the passed vertex
- * @remark If only distances should be compared, this method should be used because
+ * @param Vertex The vertex for which the distance is to be calculated
+ * @return Returns the square of the distance between itself and the passed vertex
+ * @remark If only distances should be compared, this method should be used because
* it is faster than Distance()
*/
- inline int Distance2(const BS_Vertex& Vertex) const {
+ inline int Distance2(const BS_Vertex &Vertex) const {
return (X - Vertex.X) * (X - Vertex.X) + (Y - Vertex.Y) * (Y - Vertex.Y);
}
/**
* Calculates the square of the distance between two Vertecies.
- * @param Vertex The vertex for which the distance is to be calculated
- * @return Returns the square of the distance between itself and the passed vertex
- * @remark If only distances should be compared, Distance2() should be used, since it is faster.
+ * @param Vertex The vertex for which the distance is to be calculated
+ * @return Returns the square of the distance between itself and the passed vertex
+ * @remark If only distances should be compared, Distance2() should be used, since it is faster.
*/
- inline int Distance(const BS_Vertex& Vertex) const {
+ inline int Distance(const BS_Vertex &Vertex) const {
return (int)(sqrtf(static_cast<float>(Distance2(Vertex))) + 0.5);
}
/**
* Calculates the cross product of the vertex with another vertex. Here the Vertecies will be
* interpreted as vectors.
- * @param Vertex The second vertex
- * @return Returns the cross product of this vertex and the passed vertex.
+ * @param Vertex The second vertex
+ * @return Returns the cross product of this vertex and the passed vertex.
*/
- inline int ComputeCrossProduct(const BS_Vertex& Vertex) const {
+ inline int ComputeCrossProduct(const BS_Vertex &Vertex) const {
return X * Vertex.Y - Vertex.X * Y;
}
/**
* Returns the dot product of this vertex with another vertex. Here the Vertecies are interpreted as vectors.
- * @param Vertex The second vertex
- * @return Returns the dot product of this vertex and the passed vertex.
+ * @param Vertex The second vertex
+ * @return Returns the dot product of this vertex and the passed vertex.
*/
- inline int ComputeDotProduct(const BS_Vertex& Vertex) const
- {
+ inline int ComputeDotProduct(const BS_Vertex &Vertex) const {
return X * Vertex.X + Y * Vertex.Y;
}
/**
* Calculates the angle between this vertex and another vertex. Here the Vertecies are interpreted as vectors.
- * @param Vertex The second vertex
- * @return Returns the angle between this vertex and the passed vertex in radians.
+ * @param Vertex The second vertex
+ * @return Returns the angle between this vertex and the passed vertex in radians.
*/
- inline float ComputeAngle(const BS_Vertex& Vertex) const {
+ inline float ComputeAngle(const BS_Vertex &Vertex) const {
return atan2f(static_cast<float>(ComputeCrossProduct(Vertex)), static_cast<float>(ComputeDotProduct(Vertex)));
}
diff --git a/engines/sword25/math/walkregion.cpp b/engines/sword25/math/walkregion.cpp
index 70b84da3b9..0ef2958521 100644
--- a/engines/sword25/math/walkregion.cpp
+++ b/engines/sword25/math/walkregion.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -59,7 +59,7 @@ BS_WalkRegion::BS_WalkRegion() {
// -----------------------------------------------------------------------------
BS_WalkRegion::BS_WalkRegion(BS_InputPersistenceBlock &Reader, unsigned int Handle) :
- BS_Region(Reader, Handle) {
+ BS_Region(Reader, Handle) {
m_Type = RT_WALKREGION;
Unpersist(Reader);
}
@@ -91,13 +91,12 @@ bool BS_WalkRegion::QueryPath(BS_Vertex StartPoint, BS_Vertex EndPoint, BS_Path
// If the start and finish are identical, no path can be found trivially
if (StartPoint == EndPoint) return true;
- // Ensure that the start and finish are valid and find new start points if either
+ // Ensure that the start and finish are valid and find new start points if either
// are outside the polygon
if (!CheckAndPrepareStartAndEnd(StartPoint, EndPoint)) return false;
// If between the start and point a line of sight exists, then it can be returned.
- if (IsLineOfSight(StartPoint, EndPoint))
- {
+ if (IsLineOfSight(StartPoint, EndPoint)) {
Path.push_back(StartPoint);
Path.push_back(EndPoint);
return true;
@@ -114,27 +113,27 @@ struct DijkstraNode {
typedef Container::const_iterator ConstIter;
DijkstraNode() : Cost(infinity), Chosen(false) {};
- ConstIter ParentIter;
- int Cost;
- bool Chosen;
+ ConstIter ParentIter;
+ int Cost;
+ bool Chosen;
};
-static void InitDijkstraNodes(DijkstraNode::Container &DijkstraNodes, const BS_Region &Region,
- const BS_Vertex &Start, const Common::Array<BS_Vertex> &Nodes) {
+static void InitDijkstraNodes(DijkstraNode::Container &DijkstraNodes, const BS_Region &Region,
+ const BS_Vertex &Start, const Common::Array<BS_Vertex> &Nodes) {
// Allocate sufficient space in the array
DijkstraNodes.resize(Nodes.size());
// Initialise all the nodes which are visible from the starting node
DijkstraNode::Iter DijkstraIter = DijkstraNodes.begin();
- for (Common::Array<BS_Vertex>::const_iterator NodesIter = Nodes.begin();
- NodesIter != Nodes.end(); NodesIter++, DijkstraIter++) {
+ for (Common::Array<BS_Vertex>::const_iterator NodesIter = Nodes.begin();
+ NodesIter != Nodes.end(); NodesIter++, DijkstraIter++) {
(*DijkstraIter).ParentIter = DijkstraNodes.end();
- if (Region.IsLineOfSight(*NodesIter, Start)) (*DijkstraIter).Cost = (*NodesIter).Distance(Start);
+ if (Region.IsLineOfSight(*NodesIter, Start))(*DijkstraIter).Cost = (*NodesIter).Distance(Start);
}
BS_ASSERT(DijkstraIter == DijkstraNodes.end());
}
-static DijkstraNode::Iter ChooseClosestNode(DijkstraNode::Container & Nodes) {
+static DijkstraNode::Iter ChooseClosestNode(DijkstraNode::Container &Nodes) {
DijkstraNode::Iter ClosestNodeInter = Nodes.end();
int MinCost = infinity;
@@ -149,8 +148,8 @@ static DijkstraNode::Iter ChooseClosestNode(DijkstraNode::Container & Nodes) {
}
static void RelaxNodes(DijkstraNode::Container &Nodes,
- const Common::Array< Common::Array<int> > &VisibilityMatrix,
- const DijkstraNode::ConstIter &CurNodeIter) {
+ const Common::Array< Common::Array<int> > &VisibilityMatrix,
+ const DijkstraNode::ConstIter &CurNodeIter) {
// All the successors of the current node that have not been chosen will be
// inserted into the boundary node list, and the cost will be updated if
// a shorter path has been found to them.
@@ -169,10 +168,10 @@ static void RelaxNodes(DijkstraNode::Container &Nodes,
}
static void RelaxEndPoint(const BS_Vertex &CurNodePos,
- const DijkstraNode::ConstIter &CurNodeIter,
- const BS_Vertex &EndPointPos,
- DijkstraNode &EndPoint,
- const BS_Region &Region) {
+ const DijkstraNode::ConstIter &CurNodeIter,
+ const BS_Vertex &EndPointPos,
+ DijkstraNode &EndPoint,
+ const BS_Region &Region) {
if (Region.IsLineOfSight(CurNodePos, EndPointPos)) {
int TotalCost = (*CurNodeIter).Cost + CurNodePos.Distance(EndPointPos);
if (TotalCost < EndPoint.Cost) {
@@ -262,7 +261,7 @@ void BS_WalkRegion::InitNodeVector() {
// -----------------------------------------------------------------------------
void BS_WalkRegion::ComputeVisibilityMatrix() {
- // Initialise visibility matrix
+ // Initialise visibility matrix
m_VisibilityMatrix = Common::Array< Common::Array <int> >();
for (uint idx = 0; idx < m_Nodes.size(); ++idx) {
Common::Array<int> arr;
@@ -271,10 +270,10 @@ void BS_WalkRegion::ComputeVisibilityMatrix() {
m_VisibilityMatrix.push_back(arr);
}
-
+
// Calculate visibility been vertecies
for (unsigned int j = 0; j < m_Nodes.size(); ++j) {
- for (unsigned int i = j; i < m_Nodes.size(); ++i) {
+ for (unsigned int i = j; i < m_Nodes.size(); ++i) {
if (IsLineOfSight(m_Nodes[i], m_Nodes[j])) {
// There is a line of sight, so save the distance between the two
int Distance = m_Nodes[i].Distance(m_Nodes[j]);
@@ -298,8 +297,8 @@ bool BS_WalkRegion::CheckAndPrepareStartAndEnd(BS_Vertex &Start, BS_Vertex &End)
// Check to make sure the point is really in the region. If not, stop with an error
if (!IsPointInRegion(NewStart)) {
BS_LOG_ERRORLN("Constructed startpoint ((%d,%d) from (%d,%d)) is not inside the region.",
- NewStart.X, NewStart.Y,
- Start.X, Start.Y);
+ NewStart.X, NewStart.Y,
+ Start.X, Start.Y);
return false;
}
@@ -314,8 +313,8 @@ bool BS_WalkRegion::CheckAndPrepareStartAndEnd(BS_Vertex &Start, BS_Vertex &End)
// Make sure that the determined point is really within the region
if (!IsPointInRegion(NewEnd)) {
BS_LOG_ERRORLN("Constructed endpoint ((%d,%d) from (%d,%d)) is not inside the region.",
- NewEnd.X, NewEnd.Y,
- End.X, End.Y);
+ NewEnd.X, NewEnd.Y,
+ End.X, End.Y);
return false;
}
diff --git a/engines/sword25/math/walkregion.h b/engines/sword25/math/walkregion.h
index 6b06c8ed30..f23044ecef 100644
--- a/engines/sword25/math/walkregion.h
+++ b/engines/sword25/math/walkregion.h
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -73,31 +73,35 @@ public:
* may lie outside the region. Int his case, the end is chosen as the cloest point to it
* that lies within the region.
*
- * @param X1 X Co-ordinate of the start point
- * @param Y1 Y Co-ordinate of the start point
- * @param X2 X Co-ordinate of the end point
- * @param Y2 Y Co-ordinate of the end point
- * @param Path An empty BS_Path that will be set to the resulting path
- * @return Returns false if the result is invalid, otherwise returns true.
+ * @param X1 X Co-ordinate of the start point
+ * @param Y1 Y Co-ordinate of the start point
+ * @param X2 X Co-ordinate of the end point
+ * @param Y2 Y Co-ordinate of the end point
+ * @param Path An empty BS_Path that will be set to the resulting path
+ * @return Returns false if the result is invalid, otherwise returns true.
*/
- bool QueryPath(int X1, int Y1, int X2, int Y2, BS_Path &Path) {
+ bool QueryPath(int X1, int Y1, int X2, int Y2, BS_Path &Path) {
return QueryPath(BS_Vertex(X1, Y1), BS_Vertex(X2, Y2), Path);
}
/**
* Get the shortest path between two points in the region.
*
- * @param StartPoint The start point
- * @param EndPoint The end point
- * @param Path An empty BS_Path that will be set to the resulting path
- * @return Returns false if the result is invalid, otherwise returns true.
+ * @param StartPoint The start point
+ * @param EndPoint The end point
+ * @param Path An empty BS_Path that will be set to the resulting path
+ * @return Returns false if the result is invalid, otherwise returns true.
*/
- bool QueryPath(BS_Vertex StartPoint, BS_Vertex EndPoint, BS_Path & Path);
+ bool QueryPath(BS_Vertex StartPoint, BS_Vertex EndPoint, BS_Path &Path);
virtual void SetPos(int X, int Y);
- const Common::Array<BS_Vertex> &GetNodes() const { return m_Nodes; }
- const Common::Array< Common::Array<int> > &GetVisibilityMatrix() const { return m_VisibilityMatrix; }
+ const Common::Array<BS_Vertex> &GetNodes() const {
+ return m_Nodes;
+ }
+ const Common::Array< Common::Array<int> > &GetVisibilityMatrix() const {
+ return m_VisibilityMatrix;
+ }
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);