format "_" in names,
format code a bit
This commit is contained in:
parent
06935dace4
commit
39a4b54d30
50 changed files with 1817 additions and 1862 deletions
|
@ -41,54 +41,52 @@ void Sector::load0(TextSplitter &ts, char *name, int id) {
|
|||
float height = 12345.f; // Yaz: this is in the original code...
|
||||
Vector3d tempVert;
|
||||
|
||||
name_ = name;
|
||||
id_ = id;
|
||||
_name = name;
|
||||
_id = id;
|
||||
ts.scanString(" type %256s", 1, buf);
|
||||
|
||||
// Flags used in function at 4A66C0 (buildWalkPlane)
|
||||
|
||||
if (strstr(buf, "walk"))
|
||||
type_ = 0x1000;
|
||||
_type = 0x1000;
|
||||
|
||||
else if (strstr(buf, "funnel"))
|
||||
type_ = 0x1100;
|
||||
_type = 0x1100;
|
||||
else if (strstr(buf, "camera"))
|
||||
type_ = 0x2000;
|
||||
_type = 0x2000;
|
||||
else if (strstr(buf, "special"))
|
||||
type_ = 0x4000;
|
||||
_type = 0x4000;
|
||||
else if (strstr(buf, "chernobyl"))
|
||||
type_ = 0x8000;
|
||||
_type = 0x8000;
|
||||
else
|
||||
error("Unknown sector type '%s' in room setup", buf);
|
||||
|
||||
ts.scanString(" default visibility %256s", 1, buf);
|
||||
if (strcmp(buf, "visible") == 0)
|
||||
visible_ = true;
|
||||
_visible = true;
|
||||
else if (strcmp(buf, "invisible") == 0)
|
||||
visible_ = false;
|
||||
_visible = false;
|
||||
else
|
||||
error("Invalid visibility spec: %s\n", buf);
|
||||
ts.scanString(" height %f", 1, &height_);
|
||||
ts.scanString(" numvertices %d", 1, &numVertices_);
|
||||
vertices_ = new Vector3d[numVertices_ + 1];
|
||||
ts.scanString(" height %f", 1, &_height);
|
||||
ts.scanString(" numvertices %d", 1, &_numVertices);
|
||||
_vertices = new Vector3d[_numVertices + 1];
|
||||
|
||||
ts.scanString(" vertices: %f %f %f", 3, &vertices_[0].x(), &vertices_[0].y(),
|
||||
&vertices_[0].z());
|
||||
for (i=1;i<numVertices_;i++)
|
||||
ts.scanString(" %f %f %f", 3, &vertices_[i].x(), &vertices_[i].y(), &vertices_[i].z());
|
||||
ts.scanString(" vertices: %f %f %f", 3, &_vertices[0].x(), &_vertices[0].y(), &_vertices[0].z());
|
||||
for (i = 1; i < _numVertices; i++)
|
||||
ts.scanString(" %f %f %f", 3, &_vertices[i].x(), &_vertices[i].y(), &_vertices[i].z());
|
||||
|
||||
// Repeat the last vertex for convenience
|
||||
vertices_[numVertices_] = vertices_[0];
|
||||
_vertices[_numVertices] = _vertices[0];
|
||||
|
||||
normal_ = cross(vertices_[1] - vertices_[0],
|
||||
vertices_[numVertices_ - 1] - vertices_[0]);
|
||||
float length = normal_.magnitude();
|
||||
_normal = cross(_vertices[1] - _vertices[0], _vertices[_numVertices - 1] - _vertices[0]);
|
||||
float length = _normal.magnitude();
|
||||
if (length > 0)
|
||||
normal_ /= length;
|
||||
_normal /= length;
|
||||
}
|
||||
|
||||
void Sector::setVisible(bool visible) {
|
||||
visible_ = visible;
|
||||
_visible = visible;
|
||||
}
|
||||
|
||||
bool Sector::isPointInSector(Vector3d point) const {
|
||||
|
@ -101,9 +99,9 @@ bool Sector::isPointInSector(Vector3d point) const {
|
|||
// (I don't know whether the box height actually has to be considered;
|
||||
// if not then this will be fine as is.)
|
||||
|
||||
for (int i = 0; i < numVertices_; i++) {
|
||||
Vector3d edge = vertices_[i+1] - vertices_[i];
|
||||
Vector3d delta = point - vertices_[i];
|
||||
for (int i = 0; i < _numVertices; i++) {
|
||||
Vector3d edge = _vertices[i + 1] - _vertices[i];
|
||||
Vector3d delta = point - _vertices[i];
|
||||
if (edge.x() * delta.y() < edge.y() * delta.x())
|
||||
return false;
|
||||
}
|
||||
|
@ -111,21 +109,21 @@ bool Sector::isPointInSector(Vector3d point) const {
|
|||
}
|
||||
|
||||
Vector3d Sector::projectToPlane(Vector3d point) const {
|
||||
if (normal_.z() == 0)
|
||||
if (_normal.z() == 0)
|
||||
error("Trying to walk along vertical plane\n");
|
||||
|
||||
// Formula: return p - (n . (p - v_0))/(n . k) k
|
||||
Vector3d result = point;
|
||||
result.z() -= dot(normal_, point - vertices_[0]) / normal_.z();
|
||||
result.z() -= dot(_normal, point - _vertices[0]) / _normal.z();
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector3d Sector::projectToPuckVector(Vector3d v) const {
|
||||
if (normal_.z() == 0)
|
||||
if (_normal.z() == 0)
|
||||
error("Trying to walk along vertical plane\n");
|
||||
|
||||
Vector3d result = v;
|
||||
result.z() -= dot(normal_, v) / normal_.z();
|
||||
result.z() -= dot(_normal, v) / _normal.z();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -133,32 +131,32 @@ Vector3d Sector::projectToPuckVector(Vector3d v) const {
|
|||
Vector3d Sector::closestPoint(Vector3d point) const {
|
||||
// First try to project to the plane
|
||||
Vector3d p2 = point;
|
||||
p2 -= (dot(normal_, p2 - vertices_[0])) * normal_;
|
||||
p2 -= (dot(_normal, p2 - _vertices[0])) * _normal;
|
||||
if (isPointInSector(p2))
|
||||
return p2;
|
||||
|
||||
// Now try to project to some edge
|
||||
for (int i = 0; i < numVertices_; i++) {
|
||||
Vector3d edge = vertices_[i + 1] - vertices_[i];
|
||||
Vector3d delta = point - vertices_[i];
|
||||
for (int i = 0; i < _numVertices; i++) {
|
||||
Vector3d edge = _vertices[i + 1] - _vertices[i];
|
||||
Vector3d delta = point - _vertices[i];
|
||||
float scalar = dot(delta, edge) / dot(edge, edge);
|
||||
if (scalar >= 0 && scalar <= 1 &&
|
||||
delta.x() * edge.y() > delta.y() * edge.x())
|
||||
// That last test is just whether the z-component
|
||||
// of delta cross edge is positive; we don't
|
||||
// want to return opposite edges.
|
||||
return vertices_[i] + scalar * edge;
|
||||
return _vertices[i] + scalar * edge;
|
||||
}
|
||||
|
||||
// Otherwise, just find the closest vertex
|
||||
float minDist = (point - vertices_[0]).magnitude();
|
||||
float minDist = (point - _vertices[0]).magnitude();
|
||||
int index = 0;
|
||||
for (int i = 1; i < numVertices_; i++) {
|
||||
float currDist = (point - vertices_[i]).magnitude();
|
||||
for (int i = 1; i < _numVertices; i++) {
|
||||
float currDist = (point - _vertices[i]).magnitude();
|
||||
if (currDist < minDist) {
|
||||
minDist = currDist;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
return vertices_[index];
|
||||
return _vertices[index];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue