/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see .
*
*/
#include "twp/twp.h"
#include "twp/object.h"
#include "twp/room.h"
#include "twp/lighting.h"
#include "twp/walkboxnode.h"
namespace Twp {
WalkboxNode::WalkboxNode() : Node("Walkbox") {
_zOrder = -1000;
_mode = WalkboxMode::None;
}
void WalkboxNode::drawCore(const Math::Matrix4 &trsf) {
if (g_twp->_room) {
Color white;
Color red(1.f, 0.f, 0.f);
Color green(0.f, 1.f, 0.f);
Color yellow(1.f, 1.f, 0.f);
Common::Array walkboxes = g_twp->_room ? g_twp->_room->_pathFinder.getWalkboxes() : Common::Array();
switch (_mode) {
case WalkboxMode::All: {
Math::Matrix4 transf;
// cancel camera pos
Math::Vector2d pos = g_twp->getGfx().cameraPos();
transf.translate(Math::Vector3d(-pos.getX(), -pos.getY(), 0.f));
for (uint i = 0; i < walkboxes.size(); i++) {
const Walkbox &wb = walkboxes[i];
const Color color = wb.isVisible() ? green : red;
Common::Array vertices;
const Common::Array &points = wb.getPoints();
for (uint j = 0; j < points.size(); j++) {
Vector2i pInt = points[j];
Math::Vector2d p = (Math::Vector2d)pInt;
vertices.push_back(Vertex((Math::Vector2d)p, color));
Math::Matrix4 t(transf);
p -= Math::Vector2d(1.f, 1.f);
t.translate(Math::Vector3d(p.getX(), p.getY(), 0.f));
}
g_twp->getGfx().drawLinesLoop(vertices.data(), vertices.size(), transf);
}
} break;
case WalkboxMode::Merged: {
Math::Matrix4 transf;
Math::Vector2d pos = g_twp->getGfx().cameraPos();
// cancel camera pos
transf.translate(Math::Vector3d(-pos.getX(), -pos.getY(), 0.f));
for (uint i = 0; i < walkboxes.size(); i++) {
const Walkbox &wb = walkboxes[i];
const Color color = i == 0 ? green : red;
Common::Array vertices;
const Common::Array &points = wb.getPoints();
for (uint j = 0; j < points.size(); j++) {
Vector2i pInt = points[j];
Math::Vector2d p = (Math::Vector2d)pInt;
vertices.push_back(Vertex(p, color));
Math::Matrix4 t(transf);
p -= Math::Vector2d(1.f, 1.f);
t.translate(Math::Vector3d(p.getX(), p.getY(), 0.f));
// if (wb.concave(j) == (i == 0))
// g_twp->getGfx().drawQuad(Math::Vector2d(3.f, 3.f), yellow, t);
}
g_twp->getGfx().drawLinesLoop(vertices.data(), vertices.size(), transf);
}
} break;
default:
break;
}
}
}
PathNode::PathNode() : Node("Path") {
_zOrder = -1000;
}
Math::Vector2d PathNode::fixPos(const Math::Vector2d &pos) {
for (size_t i = 0; i < g_twp->_room->_mergedPolygon.size(); i++) {
Walkbox &wb = g_twp->_room->_mergedPolygon[i];
if (!wb.isVisible() && wb.contains(pos)) {
return wb.getClosestPointOnEdge(pos);
}
}
// for wb in gEngine.room.mergedPolygon:
// if wb.visible and not wb.contains(pos):
// return wb.getClosestPointOnEdge(pos)
return pos;
}
void PathNode::drawCore(const Math::Matrix4 &trsf) {
if (!g_twp->_room)
return;
const Color green(0.f, 1.f, 0.f);
const Color red(1.f, 0.f, 0.f);
const Color yellow(1.f, 1.f, 0.f);
const Color blue(0.f, 0.f, 1.f);
const Common::SharedPtr