MATH: Move the math classes to their own math/ dir and Math namespace.

This commit is contained in:
Giulio Camuffo 2011-09-10 17:46:07 +02:00
parent e9267cfec5
commit 0083c8619c
42 changed files with 353 additions and 346 deletions

View file

@ -26,6 +26,7 @@ MODULES += \
video \
graphics \
audio \
math \
common \
po

View file

@ -27,8 +27,8 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#define FORBIDDEN_SYMBOL_EXCEPTION_unlink
#include "graphics/line3d.h"
#include "graphics/rect2d.h"
#include "math/line3d.h"
#include "math/rect2d.h"
#include "engines/grim/debug.h"
#include "engines/grim/actor.h"
@ -268,7 +268,7 @@ void Actor::saveState(SaveGame *savedState) const {
savedState->writeLESint32(_winY2);
savedState->writeLESint32(_path.size());
for (Common::List<Graphics::Vector3d>::const_iterator i = _path.begin(); i != _path.end(); ++i) {
for (Common::List<Math::Vector3d>::const_iterator i = _path.begin(); i != _path.end(); ++i) {
savedState->writeVector3d(*i);
}
}
@ -458,7 +458,7 @@ void Actor::setRot(float pitchParam, float yawParam, float rollParam) {
_turning = false;
}
void Actor::setPos(Graphics::Vector3d position) {
void Actor::setPos(Math::Vector3d position) {
_walking = false;
_pos = position;
@ -480,7 +480,7 @@ void Actor::turnTo(float pitchParam, float yawParam, float rollParam) {
_turning = false;
}
void Actor::walkTo(const Graphics::Vector3d &p) {
void Actor::walkTo(const Math::Vector3d &p) {
if (p == _pos)
_walking = false;
else {
@ -557,17 +557,17 @@ void Actor::walkTo(const Graphics::Vector3d &p) {
if (inClosed)
continue;
Common::List<Graphics::Line3d> bridges = sector->getBridgesTo(s);
Common::List<Math::Line3d> bridges = sector->getBridgesTo(s);
if (bridges.empty())
continue; // The sectors are not adjacent.
Graphics::Vector3d closestPoint = s->getClosestPoint(_destPos);
Graphics::Vector3d best;
Math::Vector3d closestPoint = s->getClosestPoint(_destPos);
Math::Vector3d best;
float bestDist = 1e6f;
Graphics::Line3d l(node->pos, closestPoint);
Math::Line3d l(node->pos, closestPoint);
while (!bridges.empty()) {
Graphics::Line3d bridge = bridges.back();
Graphics::Vector3d pos;
Math::Line3d bridge = bridges.back();
Math::Vector3d pos;
if (!bridge.intersectLine2d(l, &pos)) {
pos = bridge.middle();
}
@ -632,14 +632,14 @@ bool Actor::isTurning() const {
return false;
}
void Actor::moveTo(const Graphics::Vector3d &pos) {
void Actor::moveTo(const Math::Vector3d &pos) {
// This is necessary for collisions in set hl to work, since
// Manny's collision mode isn't set.
if (_collisionMode == CollisionOff) {
_collisionMode = CollisionSphere;
}
Graphics::Vector3d v = pos - _pos;
Math::Vector3d v = pos - _pos;
for (Actor::Pool::Iterator i = getPool()->getBegin(); i != getPool()->getEnd(); ++i) {
Actor *a = i->_value;
if (a != this && a->isInSet(_setName) && a->isVisible()) {
@ -655,7 +655,7 @@ void Actor::walkForward() {
float yaw_rad = _yaw * (LOCAL_PI / 180.f), pitch_rad = _pitch * (LOCAL_PI / 180.f);
//float yaw;
Graphics::Vector3d forwardVec(-sin(yaw_rad) * cos(pitch_rad),
Math::Vector3d forwardVec(-sin(yaw_rad) * cos(pitch_rad),
cos(yaw_rad) * cos(pitch_rad), sin(pitch_rad));
if (! _constrain) {
@ -681,7 +681,7 @@ void Actor::walkForward() {
while (currSector) {
prevSector = currSector;
Graphics::Vector3d puckVec = currSector->getProjectionToPuckVector(forwardVec);
Math::Vector3d puckVec = currSector->getProjectionToPuckVector(forwardVec);
puckVec /= puckVec.magnitude();
currSector->getExitInfo(_pos, puckVec, &ei);
float exitDist = (ei.exitPoint - _pos).magnitude();
@ -719,9 +719,9 @@ void Actor::walkForward() {
setYaw(_yaw + turnAmt * turnDir);
}
Graphics::Vector3d Actor::getPuckVector() const {
Math::Vector3d Actor::getPuckVector() const {
float yaw_rad = _yaw * (LOCAL_PI / 180.f);
Graphics::Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Math::Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Sector *sector = g_grim->getCurrScene()->findPointSector(_pos, Sector::WalkType);
if (!sector)
@ -812,15 +812,15 @@ void Actor::turn(int dir) {
float Actor::getYawTo(const Actor &a) const {
float yaw_rad = _yaw * (LOCAL_PI / 180.f);
Graphics::Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Graphics::Vector3d delta = a.getPos() - _pos;
Math::Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Math::Vector3d delta = a.getPos() - _pos;
delta.z() = 0;
return angle(forwardVec, delta) * (180.f / LOCAL_PI);
}
float Actor::getYawTo(Graphics::Vector3d p) const {
Graphics::Vector3d dpos = p - _pos;
float Actor::getYawTo(Math::Vector3d p) const {
Math::Vector3d dpos = p - _pos;
if (dpos.x() == 0 && dpos.y() == 0)
return 0;
@ -1042,14 +1042,14 @@ void Actor::updateWalk() {
return;
}
Graphics::Vector3d destPos = _path.back();
Math::Vector3d destPos = _path.back();
float y = getYawTo(destPos);
if (y < 0.f) {
y += 360.f;
}
turnTo(_pitch, y, _roll);
Graphics::Vector3d dir = destPos - _pos;
Math::Vector3d dir = destPos - _pos;
float dist = dir.magnitude();
if (dist > 0)
@ -1358,8 +1358,8 @@ bool Actor::shouldDrawShadow(int shadowId) {
// Don't draw a shadow if the actor is behind the shadow plane.
Sector *sector = shadow->planeList.front().sector;
Graphics::Vector3d n = sector->getNormal();
Graphics::Vector3d p = sector->getVertices()[0];
Math::Vector3d n = sector->getNormal();
Math::Vector3d p = sector->getVertices()[0];
float d = -(n.x() * p.x() + n.y() * p.y() + n.z() * p.z());
p = getPos();
@ -1393,7 +1393,7 @@ void Actor::setActivateShadow(int shadowId, bool state) {
_shadowArray[shadowId].active = state;
}
void Actor::setShadowPoint(Graphics::Vector3d p) {
void Actor::setShadowPoint(Math::Vector3d p) {
assert(_activeShadowSlot != -1);
_shadowArray[_activeShadowSlot].pos = p;
@ -1456,7 +1456,7 @@ void Actor::setCollisionScale(float scale) {
_collisionScale = scale;
}
bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
bool Actor::collidesWith(Actor *actor, Math::Vector3d *vec) const {
if (actor->_collisionMode == CollisionOff) {
return false;
}
@ -1464,8 +1464,8 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
Model *model1 = getCurrentCostume()->getModel();
Model *model2 = actor->getCurrentCostume()->getModel();
Graphics::Vector3d p1 = _pos + model1->_insertOffset;
Graphics::Vector3d p2 = actor->_pos + model2->_insertOffset;
Math::Vector3d p1 = _pos + model1->_insertOffset;
Math::Vector3d p2 = actor->_pos + model2->_insertOffset;
float size1 = model1->_radius * _collisionScale;
float size2 = model2->_radius * actor->_collisionScale;
@ -1474,12 +1474,12 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
CollisionMode mode2 = actor->_collisionMode;
if (mode1 == CollisionSphere && mode2 == CollisionSphere) {
Graphics::Vector3d pos = p1 + *vec;
Math::Vector3d pos = p1 + *vec;
float distance = (pos - p2).magnitude();
if (distance < size1 + size2) {
// Move the destination point so that its distance from the
// center of the circle is size1+size2.
Graphics::Vector3d v = pos - p2;
Math::Vector3d v = pos - p2;
v.normalize();
v *= size1 + size2;
*vec = v + p2 - p1;
@ -1491,15 +1491,15 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
warning("Collision between box and box not implemented!");
return false;
} else {
Graphics::Rect2d rect;
Math::Rect2d rect;
Graphics::Vector3d bboxPos;
Graphics::Vector3d size;
Graphics::Vector3d pos;
Graphics::Vector3d circlePos;
Math::Vector3d bboxPos;
Math::Vector3d size;
Math::Vector3d pos;
Math::Vector3d circlePos;
float yaw;
Graphics::Vector2d circle;
Math::Vector2d circle;
float radius;
if (mode1 == CollisionBox) {
@ -1524,35 +1524,35 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
radius = size1;
}
rect._topLeft = Graphics::Vector2d(bboxPos.x(), bboxPos.y() + size.y());
rect._topRight = Graphics::Vector2d(bboxPos.x() + size.x(), bboxPos.y() + size.y());
rect._bottomLeft = Graphics::Vector2d(bboxPos.x(), bboxPos.y());
rect._bottomRight = Graphics::Vector2d(bboxPos.x() + size.x(), bboxPos.y());
rect.rotateAround(Graphics::Vector2d(pos.x(), pos.y()), yaw);
rect._topLeft = Math::Vector2d(bboxPos.x(), bboxPos.y() + size.y());
rect._topRight = Math::Vector2d(bboxPos.x() + size.x(), bboxPos.y() + size.y());
rect._bottomLeft = Math::Vector2d(bboxPos.x(), bboxPos.y());
rect._bottomRight = Math::Vector2d(bboxPos.x() + size.x(), bboxPos.y());
rect.rotateAround(Math::Vector2d(pos.x(), pos.y()), yaw);
if (rect.intersectsCircle(circle, radius)) {
Graphics::Vector2d center = rect.getCenter();
Math::Vector2d center = rect.getCenter();
// Draw a line from the center of the rect to the place the character
// would go to.
Graphics::Vector2d v = circle - center;
Math::Vector2d v = circle - center;
v.normalize();
Graphics::Segment2d edge;
Math::Segment2d edge;
// That line intersects (usually) an edge
rect.getIntersection(center, v, &edge);
// Take the perpendicular of that edge
Graphics::Line2d perpendicular = edge.getPerpendicular(circle);
Math::Line2d perpendicular = edge.getPerpendicular(circle);
Graphics::Vector3d point;
Graphics::Vector2d p;
Math::Vector3d point;
Math::Vector2d p;
// If that perpendicular intersects the edge
if (edge.intersectsLine(perpendicular, &p)) {
Graphics::Vector2d direction = perpendicular.getDirection();
Math::Vector2d direction = perpendicular.getDirection();
direction.normalize();
// Move from the intersection until we are at a safe distance
Graphics::Vector2d point1(p - direction * radius);
Graphics::Vector2d point2(p + direction * radius);
Math::Vector2d point1(p - direction * radius);
Math::Vector2d point2(p + direction * radius);
if (center.getDistanceTo(point1) < center.getDistanceTo(point2)) {
point = point2.toVector3d();
@ -1561,10 +1561,10 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
}
} else { //if not we're around a corner
// Find the nearest vertex of the rect
Graphics::Vector2d vertex = rect.getTopLeft();
Math::Vector2d vertex = rect.getTopLeft();
float distance = vertex.getDistanceTo(circle);
Graphics::Vector2d other = rect.getTopRight();
Math::Vector2d other = rect.getTopRight();
float otherDist = other.getDistanceTo(circle);
if (otherDist < distance) {
distance = otherDist;
@ -1584,7 +1584,7 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
}
// and move on a circle around it
Graphics::Vector2d dst = circle - vertex;
Math::Vector2d dst = circle - vertex;
dst.normalize();
dst = dst * radius;
point = (vertex + dst).toVector3d();

View file

@ -25,7 +25,7 @@
#include "engines/grim/pool.h"
#include "engines/grim/object.h"
#include "graphics/vector3d.h"
#include "math/vector3d.h"
namespace Grim {
@ -46,7 +46,7 @@ typedef Common::List<Plane> SectorListType;
struct Shadow {
Common::String name;
Graphics::Vector3d pos;
Math::Vector3d pos;
SectorListType planeList;
byte *shadowMask;
int shadowMaskSize;
@ -121,13 +121,13 @@ public:
* @param position The position.
* @see getPos
*/
void setPos(Graphics::Vector3d position);
void setPos(Math::Vector3d position);
/**
* Returns the position of the actor on the 3D scene.
*
* @see setPos
*/
Graphics::Vector3d getPos() const { return _pos; }
Math::Vector3d getPos() const { return _pos; }
/**
* Tells the actor to go to the wanted position.
@ -138,7 +138,7 @@ public:
* @see stopWalking
* @see isWalking
*/
void walkTo(const Graphics::Vector3d &position);
void walkTo(const Math::Vector3d &position);
/**
* Stops immediately the actor's walk.
*
@ -251,7 +251,7 @@ public:
*
* @param actor The point to look at.
*/
float getYawTo(Graphics::Vector3d p) const;
float getYawTo(Math::Vector3d p) const;
/**
* Sets the actor visibility.
@ -341,7 +341,7 @@ public:
* @see walkTo
*/
void walkForward();
void moveTo(const Graphics::Vector3d &pos);
void moveTo(const Math::Vector3d &pos);
/**
* Used to tell the actor if it is running or not.
*
@ -353,7 +353,7 @@ public:
* Returns a vector representing the direction the actor
* is facing.
*/
Graphics::Vector3d getPuckVector() const;
Math::Vector3d getPuckVector() const;
/**
* Makes the actor say the given line.
@ -410,7 +410,7 @@ public:
}
void setActiveShadow(int shadowId);
void setShadowPoint(Graphics::Vector3d pos);
void setShadowPoint(Math::Vector3d pos);
void setShadowPlane(const char *name);
void addShadowPlane(const char *name);
void clearShadowPlanes();
@ -430,10 +430,10 @@ public:
void setLookAtVectorZero() {
_lookAtVector.set(0.f, 0.f, 0.f);
}
void setLookAtVector(Graphics::Vector3d vector) {
void setLookAtVector(Math::Vector3d vector) {
_lookAtVector = vector;
}
Graphics::Vector3d getLookAtVector() {
Math::Vector3d getLookAtVector() {
return _lookAtVector;
}
void setLookAtRate(float rate) {
@ -447,7 +447,7 @@ public:
void setCollisionMode(CollisionMode mode);
void setCollisionScale(float scale);
bool collidesWith(Actor *actor, Graphics::Vector3d *vec) const;
bool collidesWith(Actor *actor, Math::Vector3d *vec) const;
bool _toClean;
@ -464,7 +464,7 @@ private:
Common::String _setName; // The actual current set
PoolColor *_talkColor;
Graphics::Vector3d _pos;
Math::Vector3d _pos;
float _pitch, _yaw, _roll;
float _walkRate, _turnRate;
@ -484,7 +484,7 @@ private:
// Variables for walking to a point
bool _walking;
Graphics::Vector3d _destPos;
Math::Vector3d _destPos;
// chores
Costume *_restCostume;
@ -523,7 +523,7 @@ private:
void freeCostumeChore(Costume *toFree, Costume *&cost, int &chore);
// lookAt
Graphics::Vector3d _lookAtVector;
Math::Vector3d _lookAtVector;
float _lookAtRate;
int _winX1, _winY1, _winX2, _winY2;
@ -532,11 +532,11 @@ private:
struct PathNode {
Sector *sect;
PathNode *parent;
Graphics::Vector3d pos;
Math::Vector3d pos;
float dist;
float cost;
};
Common::List<Graphics::Vector3d> _path;
Common::List<Math::Vector3d> _path;
CollisionMode _collisionMode;
float _collisionScale;

View file

@ -241,7 +241,7 @@ void AnimManager::removeAnimation(Animation *anim) {
void AnimManager::animate(ModelNode *hier, int numNodes) {
// Apply animation to each hierarchy node separately.
for (int i = 0; i < numNodes; i++) {
Graphics::Vector3d tempPos;
Math::Vector3d tempPos;
float tempYaw = 0.0f, tempPitch = 0.0f, tempRoll = 0.0f;
float totalWeight = 0.0f;
float remainingWeight = 1.0f;

View file

@ -146,7 +146,7 @@ public:
void animate();
void reset();
void resetColormap();
void setMatrix(Graphics::Matrix4 matrix) { _matrix = matrix; };
void setMatrix(Math::Matrix4 matrix) { _matrix = matrix; };
void restoreState(SaveGame *state);
AnimManager *getAnimManager() const;
~ModelComponent();
@ -160,7 +160,7 @@ protected:
Common::String _filename;
ObjectPtr<Model> _obj;
ModelNode *_hier;
Graphics::Matrix4 _matrix;
Math::Matrix4 _matrix;
AnimManager *_animation;
Component *_prevComp;
};
@ -198,7 +198,7 @@ public:
void restoreState(SaveGame *state);
~MeshComponent() { }
void setMatrix(Graphics::Matrix4 matrix) { _matrix = matrix; };
void setMatrix(Math::Matrix4 matrix) { _matrix = matrix; };
ModelNode *getNode() { return _node; }
Model *getModel() { return _model; }
@ -208,7 +208,7 @@ private:
int _num;
Model *_model;
ModelNode *_node;
Graphics::Matrix4 _matrix;
Math::Matrix4 _matrix;
};
BitmapComponent::BitmapComponent(Costume::Component *p, int parentID, const char *filename, tag32 t) :
@ -450,7 +450,7 @@ void translateObject(ModelNode *node, bool reset) {
if (reset) {
g_driver->translateViewpointFinish();
} else {
Graphics::Vector3d animPos = node->_pos + node->_animPos;
Math::Vector3d animPos = node->_pos + node->_animPos;
float animPitch = node->_pitch + node->_animPitch;
float animYaw = node->_yaw + node->_animYaw;
float animRoll = node->_roll + node->_animRoll;
@ -847,7 +847,7 @@ void SoundComponent::setKey(int val) {
// then it will just use the existing handle
g_imuse->startSfx(_soundName.c_str());
if (g_grim->getCurrScene()) {
Graphics::Vector3d pos = _cost->getMatrix().getPosition();
Math::Vector3d pos = _cost->getMatrix().getPosition();
g_grim->getCurrScene()->setSoundPosition(_soundName.c_str(), pos);
}
break;
@ -1555,7 +1555,7 @@ void Costume::animate() {
}
}
void Costume::moveHead(bool lookingMode, const Graphics::Vector3d &lookAt, float rate) {
void Costume::moveHead(bool lookingMode, const Math::Vector3d &lookAt, float rate) {
if (_joint1Node) {
float step = g_grim->getPerSecond(rate);
float yawStep = step;
@ -1598,7 +1598,7 @@ void Costume::moveHead(bool lookingMode, const Graphics::Vector3d &lookAt, float
p->setMatrix(_matrix);
p->update();
Graphics::Vector3d v = lookAt - _joint3Node->_matrix.getPosition();
Math::Vector3d v = lookAt - _joint3Node->_matrix.getPosition();
if (v.isZero()) {
return;
}
@ -1708,12 +1708,12 @@ void Costume::setHead(int joint1, int joint2, int joint3, float maxRoll, float m
}
}
void Costume::setPosRotate(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
void Costume::setPosRotate(Math::Vector3d pos, float pitch, float yaw, float roll) {
_matrix.setPosition(pos);
_matrix.buildFromPitchYawRoll(pitch, yaw, roll);
}
Graphics::Matrix4 Costume::getMatrix() const {
Math::Matrix4 Costume::getMatrix() const {
return _matrix;
}

View file

@ -25,7 +25,7 @@
#include "common/memstream.h"
#include "graphics/matrix4.h"
#include "math/matrix4.h"
#include "engines/grim/object.h"
@ -70,15 +70,15 @@ public:
int getNumChores() const { return _numChores; }
void setHead(int joint1, int joint2, int joint3, float maxRoll, float maxPitch, float maxYaw);
void moveHead(bool lookingMode, const Graphics::Vector3d &lookAt, float rate);
void moveHead(bool lookingMode, const Math::Vector3d &lookAt, float rate);
int update(float frameTime);
void animate();
void setupTextures();
void draw();
void draw(int *x1, int *y1, int *x2, int *y2);
void setPosRotate(Graphics::Vector3d pos, float pitch, float yaw, float roll);
Graphics::Matrix4 getMatrix() const;
void setPosRotate(Math::Vector3d pos, float pitch, float yaw, float roll);
Math::Matrix4 getMatrix() const;
Costume *getPreviousCostume() const;
@ -94,7 +94,7 @@ public:
virtual void setColormap(CMap *c);
bool isVisible();
Component *getParent() { return _parent; }
virtual void setMatrix(Graphics::Matrix4) { };
virtual void setMatrix(Math::Matrix4) { };
virtual void init() { }
virtual void setKey(int) { }
virtual void setMapName(char *) { }
@ -114,7 +114,7 @@ public:
int _parentID;
bool _visible;
Component *_parent, *_child, *_sibling;
Graphics::Matrix4 _matrix;
Math::Matrix4 _matrix;
Costume *_cost;
void setCostume(Costume *cost) { _cost = cost; }
void setParent(Component *newParent);
@ -189,7 +189,7 @@ private:
int _numChores;
Chore *_chores;
Common::List<Chore*> _playingChores;
Graphics::Matrix4 _matrix;
Math::Matrix4 _matrix;
ModelNode *_joint1Node;
ModelNode *_joint2Node;
ModelNode *_joint3Node;

View file

@ -23,7 +23,7 @@
#ifndef GRIM_GFX_BASE_H
#define GRIM_GFX_BASE_H
#include "graphics/vector3d.h"
#include "math/vector3d.h"
namespace Grim {
@ -74,7 +74,7 @@ public:
virtual bool isHardwareAccelerated() = 0;
virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0;
virtual void positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) = 0;
virtual void positionCamera(Math::Vector3d pos, Math::Vector3d interest) = 0;
virtual void clearScreen() = 0;
@ -84,7 +84,7 @@ public:
virtual void flipBuffer() = 0;
virtual void getBoundingBoxPos(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) = 0;
virtual void startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll) = 0;
virtual void startActorDraw(Math::Vector3d pos, float scale, float yaw, float pitch, float roll) = 0;
virtual void finishActorDraw() = 0;
virtual void setShadow(Shadow *shadow) = 0;
virtual void drawShadowPlanes() = 0;
@ -95,7 +95,7 @@ public:
virtual void set3DMode() = 0;
virtual void translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll) = 0;
virtual void translateViewpointStart(Math::Vector3d pos, float pitch, float yaw, float roll) = 0;
virtual void translateViewpointFinish() = 0;
virtual void drawHierachyNode(const ModelNode *node, int *x1, int *y1, int *x2, int *y2) = 0;

View file

@ -174,11 +174,11 @@ void GfxOpenGL::setupCamera(float fov, float nclip, float fclip, float roll) {
glRotatef(roll, 0, 0, -1);
}
void GfxOpenGL::positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) {
Graphics::Vector3d up_vec(0, 0, 1);
void GfxOpenGL::positionCamera(Math::Vector3d pos, Math::Vector3d interest) {
Math::Vector3d up_vec(0, 0, 1);
if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Graphics::Vector3d(0, 1, 0);
up_vec = Math::Vector3d(0, 1, 0);
gluLookAt(pos.x(), pos.y(), pos.z(), interest.x(), interest.y(), interest.z(), up_vec.x(), up_vec.y(), up_vec.z());
}
@ -195,7 +195,7 @@ bool GfxOpenGL::isHardwareAccelerated() {
return true;
}
static void glShadowProjection(Graphics::Vector3d light, Graphics::Vector3d plane, Graphics::Vector3d normal, bool dontNegate) {
static void glShadowProjection(Math::Vector3d light, Math::Vector3d plane, Math::Vector3d normal, bool dontNegate) {
// Based on GPL shadow projection example by
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
float d, c;
@ -260,7 +260,7 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
GLdouble winX, winY, winZ;
for (int i = 0; i < model->_numFaces; i++) {
Graphics::Vector3d v;
Math::Vector3d v;
float* pVertices;
for (int j = 0; j < model->_faces[i]._numVertices; j++) {
@ -315,7 +315,7 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
*y2 = (int)bottom;
}
void GfxOpenGL::startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll) {
void GfxOpenGL::startActorDraw(Math::Vector3d pos, float scale, float yaw, float pitch, float roll) {
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -480,7 +480,7 @@ void GfxOpenGL::drawSprite(const Sprite *sprite) {
glPopMatrix();
}
void GfxOpenGL::translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
void GfxOpenGL::translateViewpointStart(Math::Vector3d pos, float pitch, float yaw, float roll) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -495,7 +495,7 @@ void GfxOpenGL::translateViewpointFinish() {
}
void GfxOpenGL::drawHierachyNode(const ModelNode *node, int *x1, int *y1, int *x2, int *y2) {
Graphics::Vector3d animPos = node->_pos + node->_animPos;
Math::Vector3d animPos = node->_pos + node->_animPos;
float animPitch = node->_pitch + node->_animPitch;
float animYaw = node->_yaw + node->_animYaw;
float animRoll = node->_roll + node->_animRoll;

View file

@ -52,7 +52,7 @@ public:
const char *getVideoDeviceName();
void setupCamera(float fov, float nclip, float fclip, float roll);
void positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest);
void positionCamera(Math::Vector3d pos, Math::Vector3d interest);
void clearScreen();
void flipBuffer();
@ -61,7 +61,7 @@ public:
void getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, int *y2);
void startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll);
void startActorDraw(Math::Vector3d pos, float scale, float yaw, float pitch, float roll);
void finishActorDraw();
void setShadow(Shadow *shadow);
void drawShadowPlanes();
@ -72,7 +72,7 @@ public:
void set3DMode();
void translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll);
void translateViewpointStart(Math::Vector3d pos, float pitch, float yaw, float roll);
void translateViewpointFinish();
void drawHierachyNode(const ModelNode *node, int *x1, int *y1, int *x2, int *y2);

View file

@ -198,11 +198,11 @@ void GfxTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
tglRotatef(roll, 0, 0, -1);
}
void GfxTinyGL::positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) {
Graphics::Vector3d up_vec(0, 0, 1);
void GfxTinyGL::positionCamera(Math::Vector3d pos, Math::Vector3d interest) {
Math::Vector3d up_vec(0, 0, 1);
if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Graphics::Vector3d(0, 1, 0);
up_vec = Math::Vector3d(0, 1, 0);
lookAt(pos.x(), pos.y(), pos.z(), interest.x(), interest.y(), interest.z(), up_vec.x(), up_vec.y(), up_vec.z());
}
@ -221,7 +221,7 @@ bool GfxTinyGL::isHardwareAccelerated() {
return false;
}
static void tglShadowProjection(Graphics::Vector3d light, Graphics::Vector3d plane, Graphics::Vector3d normal, bool dontNegate) {
static void tglShadowProjection(Math::Vector3d light, Math::Vector3d plane, Math::Vector3d normal, bool dontNegate) {
// Based on GPL shadow projection example by
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
float d, c;
@ -286,7 +286,7 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
TGLfloat winX, winY, winZ;
for (int i = 0; i < model->_numFaces; i++) {
Graphics::Vector3d v;
Math::Vector3d v;
float* pVertices;
for (int j = 0; j < model->_faces[i]._numVertices; j++) {
@ -356,7 +356,7 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
}*/
}
void GfxTinyGL::startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll) {
void GfxTinyGL::startActorDraw(Math::Vector3d pos, float scale, float yaw, float pitch, float roll) {
tglEnable(TGL_TEXTURE_2D);
tglMatrixMode(TGL_MODELVIEW);
tglPushMatrix();
@ -516,7 +516,7 @@ void GfxTinyGL::drawSprite(const Sprite *sprite) {
tglPopMatrix();
}
void GfxTinyGL::translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
void GfxTinyGL::translateViewpointStart(Math::Vector3d pos, float pitch, float yaw, float roll) {
tglPushMatrix();
tglTranslatef(pos.x(), pos.y(), pos.z());
@ -530,7 +530,7 @@ void GfxTinyGL::translateViewpointFinish() {
}
void GfxTinyGL::drawHierachyNode(const ModelNode *node, int *x1, int *y1, int *x2, int *y2) {
Graphics::Vector3d animPos = node->_pos + node->_animPos;
Math::Vector3d animPos = node->_pos + node->_animPos;
float animPitch = node->_pitch + node->_animPitch;
float animYaw = node->_yaw + node->_animYaw;
float animRoll = node->_roll + node->_animRoll;

View file

@ -43,7 +43,7 @@ public:
const char *getVideoDeviceName();
void setupCamera(float fov, float nclip, float fclip, float roll);
void positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest);
void positionCamera(Math::Vector3d pos, Math::Vector3d interest);
void clearScreen();
void flipBuffer();
@ -52,7 +52,7 @@ public:
void getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, int *y2);
void startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll);
void startActorDraw(Math::Vector3d pos, float scale, float yaw, float pitch, float roll);
void finishActorDraw();
void setShadow(Shadow *shadow);
void drawShadowPlanes();
@ -63,7 +63,7 @@ public:
void set3DMode();
void translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll);
void translateViewpointStart(Math::Vector3d pos, float pitch, float yaw, float roll);
void translateViewpointFinish();
void drawHierachyNode(const ModelNode *node, int *x1, int *y1, int *x2, int *y2);

View file

@ -191,11 +191,11 @@ int KeyframeAnim::getMarker(float startTime, float stopTime) const {
void KeyframeAnim::KeyframeEntry::loadBinary(const char *&data) {
_frame = get_float(data);
_flags = READ_LE_UINT32(data + 4);
_pos = Graphics::get_vector3d(data + 8);
_pos = Math::get_vector3d(data + 8);
_pitch = get_float(data + 20);
_yaw = get_float(data + 24);
_roll = get_float(data + 28);
_dpos = Graphics::get_vector3d(data + 32);
_dpos = Math::get_vector3d(data + 32);
_dpitch = get_float(data + 44);
_dyaw = get_float(data + 48);
_droll = get_float(data + 52);
@ -228,8 +228,8 @@ void KeyframeAnim::KeyframeNode::loadText(TextSplitter &ts) {
ts.scanString(" %f %f %f %f %f %f", 6, &dx, &dy, &dz, &dp, &dyaw, &dr);
_entries[which]._frame = frame;
_entries[which]._flags = (int)flags;
_entries[which]._pos = Graphics::Vector3d(x, y, z);
_entries[which]._dpos = Graphics::Vector3d(dx, dy, dz);
_entries[which]._pos = Math::Vector3d(x, y, z);
_entries[which]._dpos = Math::Vector3d(dx, dy, dz);
_entries[which]._pitch = p;
_entries[which]._yaw = yaw;
_entries[which]._roll = r;
@ -259,7 +259,7 @@ bool KeyframeAnim::KeyframeNode::animate(ModelNode &node, float frame, float fad
}
float dt = frame - _entries[low]._frame;
Graphics::Vector3d pos = _entries[low]._pos;
Math::Vector3d pos = _entries[low]._pos;
float pitch = _entries[low]._pitch;
float yaw = _entries[low]._yaw;
float roll = _entries[low]._roll;

View file

@ -23,7 +23,7 @@
#ifndef GRIM_KEYFRAME_H
#define GRIM_KEYFRAME_H
#include "graphics/vector3d.h"
#include "math/vector3d.h"
#include "engines/grim/object.h"
@ -63,7 +63,7 @@ private:
float _frame;
int _flags;
Graphics::Vector3d _pos, _dpos;
Math::Vector3d _pos, _dpos;
float _pitch, _yaw, _roll, _dpitch, _dyaw, _droll;
};

View file

@ -337,8 +337,8 @@ void L1_GetAngleBetweenVectors() {
table = lua_gettable();
float z2 = lua_getnumber(table);
Graphics::Vector3d vec1(x1, y1, z1);
Graphics::Vector3d vec2(x2, y2, z2);
Math::Vector3d vec1(x1, y1, z1);
Math::Vector3d vec2(x2, y2, z2);
vec1.normalize();
vec2.normalize();
@ -412,7 +412,7 @@ void L1_RotateVector() {
lua_Object vecObj = lua_getparam(1);
lua_Object rotObj = lua_getparam(2);
lua_Object resObj;
Graphics::Vector3d vec, rot, resVec;
Math::Vector3d vec, rot, resVec;
float x, y, z;
if (!lua_istable(vecObj) || !lua_istable(rotObj)) {
@ -442,7 +442,7 @@ void L1_RotateVector() {
z = lua_getnumber(lua_gettable());
rot.set(x, y, z);
Graphics::Matrix3 mat;
Math::Matrix3 mat;
mat.buildFromPitchYawRoll(x, y, z);
mat.transform(&vec);
@ -487,7 +487,7 @@ void L1_GetPointSector() {
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
Graphics::Vector3d point(x, y, z);
Math::Vector3d point(x, y, z);
Sector *result = g_grim->getCurrScene()->findPointSector(point, sectorType);
if (result) {
lua_pushnumber(result->getSectorId());
@ -509,7 +509,7 @@ void L1_GetActorSector() {
Actor *actor = getactor(actorObj);
Sector::SectorType sectorType = (Sector::SectorType)(int)lua_getnumber(typeObj);
Graphics::Vector3d pos = actor->getPos();
Math::Vector3d pos = actor->getPos();
Sector *result = g_grim->getCurrScene()->findPointSector(pos, sectorType);
if (result) {
lua_pushnumber(result->getSectorId());
@ -563,7 +563,7 @@ void L1_IsPointInSector() {
float x = lua_getnumber(xObj);
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
Graphics::Vector3d pos(x, y, z);
Math::Vector3d pos(x, y, z);
int numSectors = g_grim->getCurrScene()->getSectorCount();
for (int i = 0; i < numSectors; i++) {
@ -601,7 +601,7 @@ void L1_GetSectorOppositeEdge() {
if (strmatch(sector->getName(), name)) {
if (sector->getNumVertices() != 4)
warning("GetSectorOppositeEdge(): cheat box with %d (!= 4) edges!", sector->getNumVertices());
Graphics::Vector3d* vertices = sector->getVertices();
Math::Vector3d* vertices = sector->getVertices();
Sector::ExitInfo e;
sector->getExitInfo(actor->getPos(), -actor->getPuckVector(), &e);
@ -609,8 +609,8 @@ void L1_GetSectorOppositeEdge() {
e.edgeVertex -= 2;
if (e.edgeVertex < 0)
e.edgeVertex += sector->getNumVertices();
Graphics::Vector3d edge = vertices[e.edgeVertex + 1] - vertices[e.edgeVertex];
Graphics::Vector3d p = vertices[e.edgeVertex] + edge * frac;
Math::Vector3d edge = vertices[e.edgeVertex + 1] - vertices[e.edgeVertex];
Math::Vector3d p = vertices[e.edgeVertex] + edge * frac;
lua_pushnumber(p.x());
lua_pushnumber(p.y());
lua_pushnumber(p.z());
@ -761,7 +761,7 @@ void L1_GetShrinkPos() {
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
float r = lua_getnumber(rObj);
Graphics::Vector3d pos;
Math::Vector3d pos;
pos.set(x, y, z);
Sector* sector;
@ -1143,7 +1143,7 @@ void L1_SetLightPosition() {
float x = lua_getnumber(xObj);
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
Graphics::Vector3d vec(x, y, z);
Math::Vector3d vec(x, y, z);
if (lua_isnumber(lightObj)) {
int light = (int)lua_getnumber(lightObj);

View file

@ -316,7 +316,7 @@ void L1_PutActorAt() {
float x = lua_getnumber(xObj);
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
actor->setPos(Graphics::Vector3d(x, y, z));
actor->setPos(Math::Vector3d(x, y, z));
}
void L1_GetActorPos() {
@ -326,7 +326,7 @@ void L1_GetActorPos() {
return;
Actor *actor = getactor(actorObj);
Graphics::Vector3d pos = actor->getPos();
Math::Vector3d pos = actor->getPos();
lua_pushnumber(pos.x());
lua_pushnumber(pos.y());
lua_pushnumber(pos.z());
@ -395,8 +395,8 @@ void L1_GetAngleBetweenActors() {
return;
}
Graphics::Vector3d vec1 = actor1->getPuckVector();
Graphics::Vector3d vec2 = actor2->getPos();
Math::Vector3d vec1 = actor1->getPuckVector();
Math::Vector3d vec2 = actor2->getPos();
vec2 -= actor1->getPos();
vec1.z() = 0;
vec2.z() = 0;
@ -439,7 +439,7 @@ void L1_GetActorYawToPoint() {
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
Graphics::Vector3d yawVector(x, y, z);
Math::Vector3d yawVector(x, y, z);
lua_pushnumber(actor->getYawTo(yawVector));
}
@ -556,7 +556,7 @@ void L1_GetActorPuckVector() {
return;
}
Graphics::Vector3d result = actor->getPuckVector();
Math::Vector3d result = actor->getPuckVector();
if (!lua_isnil(addObj))
result += actor->getPos();
@ -578,7 +578,7 @@ void L1_WalkActorTo() {
if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
return;
Graphics::Vector3d destVec;
Math::Vector3d destVec;
Actor *actor = getactor(actorObj);
if (!lua_isnumber(xObj)) {
if (!lua_isuserdata(xObj) || lua_tag(xObj) != MKTAG('A','C','T','R'))
@ -596,7 +596,7 @@ void L1_WalkActorTo() {
float tx = lua_getnumber(txObj);
float ty = lua_getnumber(tyObj);
float tz = lua_getnumber(tzObj);
Graphics::Vector3d tVec(tx, ty, tz);
Math::Vector3d tVec(tx, ty, tz);
actor->walkTo(destVec);
}
@ -667,13 +667,13 @@ void L1_GetActorNodeLocation() {
root = root->_parent;
}
Graphics::Matrix4 matrix;
Math::Matrix4 matrix;
matrix.setPosition(actor->getPos());
matrix.buildFromPitchYawRoll(actor->getPitch(), actor->getYaw(), actor->getRoll());
root->setMatrix(matrix);
root->update();
Graphics::Vector3d pos(node->_pivotMatrix.getPosition());
Math::Vector3d pos(node->_pivotMatrix.getPosition());
lua_pushnumber(pos.x());
lua_pushnumber(pos.y());
lua_pushnumber(pos.z());
@ -1114,7 +1114,7 @@ void L1_ActorLookAt() {
else
fZ = 0.0f;
Graphics::Vector3d vector;
Math::Vector3d vector;
vector.set(fX, fY, fZ);
actor->setLookAtVector(vector);
@ -1167,8 +1167,8 @@ void L1_TurnActorTo() {
// TODO turning stuff below is not complete
// Find the vector pointing from the actor to the desired location
Graphics::Vector3d turnToVector(x, y, z);
Graphics::Vector3d lookVector = turnToVector - actor->getPos();
Math::Vector3d turnToVector(x, y, z);
Math::Vector3d lookVector = turnToVector - actor->getPos();
// find the angle the requested position is around the unit circle
float yaw = lookVector.unitCircleAngle();
// yaw is offset from forward by 90 degrees
@ -1211,8 +1211,8 @@ void L1_PointActorAt() {
// TODO turning stuff below is not complete
// Find the vector pointing from the actor to the desired location
Graphics::Vector3d turnToVector(x, y, z);
Graphics::Vector3d lookVector = turnToVector - actor->getPos();
Math::Vector3d turnToVector(x, y, z);
Math::Vector3d lookVector = turnToVector - actor->getPos();
// find the angle the requested position is around the unit circle
float yaw = lookVector.unitCircleAngle();
// yaw is offset from forward by 90 degrees
@ -1247,12 +1247,12 @@ void L1_WalkActorVector() {
moveVert = luaL_check_number(4);
// Get the direction the camera is pointing
Graphics::Vector3d cameraVector = g_grim->getCurrScene()->getCurrSetup()->_interest - g_grim->getCurrScene()->getCurrSetup()->_pos;
Math::Vector3d cameraVector = g_grim->getCurrScene()->getCurrSetup()->_interest - g_grim->getCurrScene()->getCurrSetup()->_pos;
// find the angle the camera direction is around the unit circle
float cameraYaw = cameraVector.unitCircleAngle();
// Handle the turning
Graphics::Vector3d adjustVector(moveHoriz, moveVert, 0);
Math::Vector3d adjustVector(moveHoriz, moveVert, 0);
// find the angle the adjust vector is around the unit circle
float adjustYaw = adjustVector.unitCircleAngle();
@ -1357,8 +1357,8 @@ void L1_PutActorAtInterest() {
if (!scene)
return;
Graphics::Vector3d p = scene->getCurrSetup()->_interest;
Graphics::Vector3d resultPt = p;
Math::Vector3d p = scene->getCurrSetup()->_interest;
Math::Vector3d resultPt = p;
float minDist = -1.f;
for (int i = 0; i < scene->getSectorCount(); ++i) {
@ -1366,7 +1366,7 @@ void L1_PutActorAtInterest() {
if (sector->getType() != Sector::WalkType || !sector->isVisible())
continue;
Graphics::Vector3d closestPt = sector->getClosestPoint(p);
Math::Vector3d closestPt = sector->getClosestPoint(p);
if (scene->findPointSector(closestPt, Sector::HotType))
continue;
float thisDist = (closestPt - p).magnitude();
@ -1490,7 +1490,7 @@ void L1_SetActorShadowPoint() {
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
actor->setShadowPoint(Graphics::Vector3d(x, y, z));
actor->setShadowPoint(Math::Vector3d(x, y, z));
}
void L1_SetActorShadowPlane() {

View file

@ -250,7 +250,7 @@ void L1_RestoreIMuse() {
}
void L1_SetSoundPosition() {
Graphics::Vector3d pos;
Math::Vector3d pos;
int minVolume = 10;
int maxVolume = 127;
float someParam = 0;

View file

@ -57,7 +57,7 @@ Model::Model(const Common::String &filename, const char *data, int len, CMap *cm
loadText(&ts, cmap);
}
Graphics::Vector3d max;
Math::Vector3d max;
_rootHierNode->update();
bool first = true;
@ -70,7 +70,7 @@ Model::Model(const Common::String &filename, const char *data, int len, CMap *cm
// bone wagon when approaching it from behind in set sg.
// Using the node position looks instead more realistic, but, on the
// other hand, it may not work right in all cases.
Graphics::Vector3d p = node._matrix.getPosition();
Math::Vector3d p = node._matrix.getPosition();
float x = p.x();
float y = p.y();
float z = p.z();
@ -163,7 +163,7 @@ void Model::loadBinary(const char *&data, CMap *cmap) {
_rootHierNode[i].loadBinary(data, _rootHierNode, &_geosets[0]);
}
_radius = get_float(data);
_insertOffset = Graphics::get_vector3d(data + 40);
_insertOffset = Math::get_vector3d(data + 40);
}
void Model::loadText(TextSplitter *ts, CMap *cmap) {
@ -231,11 +231,11 @@ void Model::loadText(TextSplitter *ts, CMap *cmap) {
_rootHierNode[num]._sibling = NULL;
_rootHierNode[num]._numChildren = numChildren;
_rootHierNode[num]._pos = Graphics::Vector3d(x, y, z);
_rootHierNode[num]._pos = Math::Vector3d(x, y, z);
_rootHierNode[num]._pitch = pitch;
_rootHierNode[num]._yaw = yaw;
_rootHierNode[num]._roll = roll;
_rootHierNode[num]._pivot = Graphics::Vector3d(pivotx, pivoty, pivotz);
_rootHierNode[num]._pivot = Math::Vector3d(pivotx, pivoty, pivotz);
_rootHierNode[num]._meshVisible = true;
_rootHierNode[num]._hierVisible = true;
_rootHierNode[num]._sprite = NULL;
@ -358,7 +358,7 @@ int MeshFace::loadBinary(const char *&data, Material *materials[]) {
int texPtr = READ_LE_UINT32(data + 28);
int materialPtr = READ_LE_UINT32(data + 32);
_extraLight = get_float(data + 48);
_normal = Graphics::get_vector3d(data + 64);
_normal = Math::get_vector3d(data + 64);
data += 76;
_vertices = new int[_numVertices];
@ -536,7 +536,7 @@ void Mesh::loadText(TextSplitter *ts, Material* materials[]) {
int num;
float x, y, z;
ts->scanString(" %d: %f %f %f", 4, &num, &x, &y, &z);
_faces[num]._normal = Graphics::Vector3d(x, y, z);
_faces[num]._normal = Math::Vector3d(x, y, z);
}
}
@ -595,8 +595,8 @@ void ModelNode::loadBinary(const char *&data, ModelNode *hierNodes, const Model:
_numChildren = READ_LE_UINT32(data + 88);
int childPtr = READ_LE_UINT32(data + 92);
int siblingPtr = READ_LE_UINT32(data + 96);
_pivot = Graphics::get_vector3d(data + 100);
_pos = Graphics::get_vector3d(data + 112);
_pivot = Math::get_vector3d(data + 100);
_pos = Math::get_vector3d(data + 112);
_pitch = get_float(data + 124);
_yaw = get_float(data + 128);
_roll = get_float(data + 132);
@ -651,7 +651,7 @@ void ModelNode::removeChild(ModelNode *child) {
}
}
void ModelNode::setMatrix(Graphics::Matrix4 matrix) {
void ModelNode::setMatrix(Math::Matrix4 matrix) {
_matrix = matrix;
}
@ -659,7 +659,7 @@ void ModelNode::update() {
if (!_initialized)
return;
Graphics::Vector3d animPos = _pos + _animPos;
Math::Vector3d animPos = _pos + _animPos;
float animPitch = _pitch + _animPitch;
float animYaw = _yaw + _animYaw;
float animRoll = _roll + _animRoll;

View file

@ -25,7 +25,7 @@
#include "common/memstream.h"
#include "engines/grim/object.h"
#include "graphics/matrix4.h"
#include "math/matrix4.h"
namespace Grim {
@ -38,7 +38,7 @@ class CMap;
struct Sprite {
void draw() const;
Graphics::Vector3d _pos;
Math::Vector3d _pos;
float _width;
float _height;
bool _visible;
@ -84,14 +84,14 @@ public:
char (*_materialNames)[32];
Material **_materials;
bool *_materialsShared;
Graphics::Vector3d _insertOffset;
Math::Vector3d _insertOffset;
int _numGeosets;
Geoset *_geosets;
float _radius;
int _numHierNodes;
ModelNode *_rootHierNode;
Graphics::Vector3d _bboxPos;
Graphics::Vector3d _bboxSize;
Math::Vector3d _bboxPos;
Math::Vector3d _bboxSize;
};
class MeshFace {
@ -106,7 +106,7 @@ public:
float _extraLight;
int _numVertices;
int *_vertices, *_texVertices;
Graphics::Vector3d _normal;
Math::Vector3d _normal;
};
class Mesh {
@ -134,7 +134,7 @@ public:
int _numFaces;
MeshFace *_faces;
Graphics::Matrix4 _matrix;
Math::Matrix4 _matrix;
};
class ModelNode {
@ -145,7 +145,7 @@ public:
void draw(int *x1, int *y1, int *x2, int *y2) const;
void addChild(ModelNode *child);
void removeChild(ModelNode *child);
void setMatrix(Graphics::Matrix4 matrix);
void setMatrix(Math::Matrix4 matrix);
void update();
void addSprite(Sprite *sprite);
void removeSprite(Sprite *sprite);
@ -155,15 +155,15 @@ public:
int _flags, _type;
int _depth, _numChildren;
ModelNode *_parent, *_child, *_sibling;
Graphics::Vector3d _pos, _pivot;
Math::Vector3d _pos, _pivot;
float _pitch, _yaw, _roll;
Graphics::Vector3d _animPos;
Math::Vector3d _animPos;
float _animPitch, _animYaw, _animRoll;
bool _meshVisible, _hierVisible;
bool _initialized;
Graphics::Matrix4 _matrix;
Graphics::Matrix4 _localMatrix;
Graphics::Matrix4 _pivotMatrix;
Math::Matrix4 _matrix;
Math::Matrix4 _localMatrix;
Math::Matrix4 _pivotMatrix;
Sprite* _sprite;
};

View file

@ -23,7 +23,7 @@
#include "common/endian.h"
#include "common/system.h"
#include "graphics/vector3d.h"
#include "math/vector3d.h"
#include "engines/grim/savegame.h"
#include "engines/grim/color.h"
@ -286,7 +286,7 @@ void SaveGame::writeByte(byte data) {
_sectionSize++;
}
void SaveGame::writeVector3d(const Graphics::Vector3d &vec) {
void SaveGame::writeVector3d(const Math::Vector3d &vec) {
writeFloat(vec.x());
writeFloat(vec.y());
writeFloat(vec.z());
@ -310,11 +310,11 @@ void SaveGame::writeString(const Common::String &string) {
write(string.c_str(), len);
}
Graphics::Vector3d SaveGame::readVector3d() {
Math::Vector3d SaveGame::readVector3d() {
float x = readFloat();
float y = readFloat();
float z = readFloat();
return Graphics::Vector3d(x, y, z);
return Math::Vector3d(x, y, z);
}
Grim::Color SaveGame::readColor() {

View file

@ -25,7 +25,7 @@
#include "common/savefile.h"
namespace Graphics {
namespace Math {
class Vector3d;
}
@ -59,10 +59,10 @@ public:
void writeByte(byte data);
void writeString(const Common::String &string);
void writeVector3d(const Graphics::Vector3d &vec);
void writeVector3d(const Math::Vector3d &vec);
void writeColor(const Grim::Color &color);
void writeFloat(float data);
Graphics::Vector3d readVector3d();
Math::Vector3d readVector3d();
Grim::Color readColor();
float readFloat();
Common::String readString();

View file

@ -523,7 +523,7 @@ void Scene::drawBitmaps(ObjectState::Position stage) {
}
}
Sector *Scene::findPointSector(const Graphics::Vector3d &p, Sector::SectorType type) {
Sector *Scene::findPointSector(const Math::Vector3d &p, Sector::SectorType type) {
for (int i = 0; i < _numSectors; i++) {
Sector *sector = _sectors[i];
if (sector && (sector->getType() & type) && sector->isVisible() && sector->isPointInSector(p))
@ -532,16 +532,16 @@ Sector *Scene::findPointSector(const Graphics::Vector3d &p, Sector::SectorType t
return NULL;
}
void Scene::findClosestSector(const Graphics::Vector3d &p, Sector **sect, Graphics::Vector3d *closestPoint) {
void Scene::findClosestSector(const Math::Vector3d &p, Sector **sect, Math::Vector3d *closestPoint) {
Sector *resultSect = NULL;
Graphics::Vector3d resultPt = p;
Math::Vector3d resultPt = p;
float minDist = 0.0;
for (int i = 0; i < _numSectors; i++) {
Sector *sector = _sectors[i];
if ((sector->getType() & Sector::WalkType) == 0 || !sector->isVisible())
continue;
Graphics::Vector3d closestPt = sector->getClosestPoint(p);
Math::Vector3d closestPt = sector->getClosestPoint(p);
float thisDist = (closestPt - p).magnitude();
if (!resultSect || thisDist < minDist) {
resultSect = sector;
@ -625,7 +625,7 @@ void Scene::setLightEnabled(int light, bool enabled) {
_lightsConfigured = false;
}
void Scene::setLightPosition(const char *light, const Graphics::Vector3d &pos) {
void Scene::setLightPosition(const char *light, const Math::Vector3d &pos) {
for (int i = 0; i < _numLights; ++i) {
Light &l = _lights[i];
if (l._name == light) {
@ -636,20 +636,20 @@ void Scene::setLightPosition(const char *light, const Graphics::Vector3d &pos) {
}
}
void Scene::setLightPosition(int light, const Graphics::Vector3d &pos) {
void Scene::setLightPosition(int light, const Math::Vector3d &pos) {
Light &l = _lights[light];
l._pos = pos;
_lightsConfigured = false;
}
void Scene::setSoundPosition(const char *soundName, Graphics::Vector3d pos) {
void Scene::setSoundPosition(const char *soundName, Math::Vector3d pos) {
setSoundPosition(soundName, pos, _minVolume, _maxVolume);
}
void Scene::setSoundPosition(const char *soundName, Graphics::Vector3d pos, int minVol, int maxVol) {
void Scene::setSoundPosition(const char *soundName, Math::Vector3d pos, int minVol, int maxVol) {
// TODO: The volume and pan needs to be updated when the setup changes.
Graphics::Vector3d cameraPos = _currSetup->_pos;
Graphics::Vector3d vector = pos - cameraPos;
Math::Vector3d cameraPos = _currSetup->_pos;
Math::Vector3d vector = pos - cameraPos;
float distance = vector.magnitude();
float diffVolume = maxVol - minVol;
//This 8.f is a guess, so it may need some adjusting
@ -659,18 +659,18 @@ void Scene::setSoundPosition(const char *soundName, Graphics::Vector3d pos, int
newVolume = _maxVolume;
g_imuse->setVolume(soundName, newVolume);
Graphics::Vector3d cameraVector =_currSetup->_interest - _currSetup->_pos;
Graphics::Vector3d up(0,0,1);
Graphics::Vector3d right;
Math::Vector3d cameraVector =_currSetup->_interest - _currSetup->_pos;
Math::Vector3d up(0,0,1);
Math::Vector3d right;
cameraVector.normalize();
float roll = -_currSetup->_roll * LOCAL_PI / 180.f;
float cosr = cos(roll);
// Rotate the up vector by roll.
up = up * cosr + Graphics::cross(cameraVector, up) * sin(roll) +
cameraVector * Graphics::dot(cameraVector, up) * (1 - cosr);
right = Graphics::cross(cameraVector, up);
up = up * cosr + Math::cross(cameraVector, up) * sin(roll) +
cameraVector * Math::dot(cameraVector, up) * (1 - cosr);
right = Math::cross(cameraVector, up);
right.normalize();
float angle = atan2(Graphics::dot(vector, right), Graphics::dot(vector, cameraVector));
float angle = atan2(Math::dot(vector, right), Math::dot(vector, cameraVector));
float pan = sin(angle);
g_imuse->setPan(soundName, (int)((pan + 1.f) / 2.f * 127.f + 0.5f));
}

View file

@ -61,8 +61,8 @@ public:
void setupLights();
void setSoundPosition(const char *soundName, Graphics::Vector3d pos);
void setSoundPosition(const char *soundName, Graphics::Vector3d pos, int minVol, int maxVol);
void setSoundPosition(const char *soundName, Math::Vector3d pos);
void setSoundPosition(const char *soundName, Math::Vector3d pos, int minVol, int maxVol);
void setSoundParameters(int minVolume, int maxVolume);
void getSoundParameters(int *minVolume, int *maxVolume);
@ -75,8 +75,8 @@ public:
void setLightsDirty();
void setLightIntensity(const char *light, float intensity);
void setLightIntensity(int light, float intensity);
void setLightPosition(const char *light, const Graphics::Vector3d &pos);
void setLightPosition(int light, const Graphics::Vector3d &pos);
void setLightPosition(const char *light, const Math::Vector3d &pos);
void setLightPosition(int light, const Math::Vector3d &pos);
void setLightEnabled(const char *light, bool enabled);
void setLightEnabled(int light, bool enabled);
@ -88,8 +88,8 @@ public:
Sector *getSectorBase(int id);
Sector *findPointSector(const Graphics::Vector3d &p, Sector::SectorType type);
void findClosestSector(const Graphics::Vector3d &p, Sector **sect, Graphics::Vector3d *closestPt);
Sector *findPointSector(const Math::Vector3d &p, Sector::SectorType type);
void findClosestSector(const Math::Vector3d &p, Sector **sect, Math::Vector3d *closestPt);
void shrinkBoxes(float radius);
void unshrinkBoxes();
@ -109,7 +109,7 @@ public:
void setupCamera() const;
Common::String _name;
Bitmap *_bkgndBm, *_bkgndZBm;
Graphics::Vector3d _pos, _interest;
Math::Vector3d _pos, _interest;
float _roll, _fov, _nclip, _fclip;
};
@ -149,7 +149,7 @@ public:
void loadBinary(Common::MemoryReadStream *ms);
Common::String _name;
Common::String _type;
Graphics::Vector3d _pos, _dir;
Math::Vector3d _pos, _dir;
Color _color;
float _intensity, _umbraangle, _penumbraangle;
bool _enabled;

View file

@ -77,7 +77,7 @@ bool Sector::restoreState(SaveGame *savedState) {
_name = savedState->readString();
_vertices = new Graphics::Vector3d[_numVertices + 1];
_vertices = new Math::Vector3d[_numVertices + 1];
for (int i = 0; i < _numVertices + 1; ++i) {
_vertices[i] = savedState->readVector3d();
}
@ -87,7 +87,7 @@ bool Sector::restoreState(SaveGame *savedState) {
_shrinkRadius = savedState->readFloat();
_invalid = savedState->readLESint32();
if (_shrinkRadius != 0.f && !_invalid) {
_origVertices = new Graphics::Vector3d[_numVertices + 1];
_origVertices = new Math::Vector3d[_numVertices + 1];
for (int i = 0; i < _numVertices + 1; ++i) {
_origVertices[i] = savedState->readVector3d();
}
@ -101,7 +101,7 @@ bool Sector::restoreState(SaveGame *savedState) {
void Sector::load(TextSplitter &ts) {
char buf[256];
int ident = 0, i = 0;
Graphics::Vector3d tempVert;
Math::Vector3d tempVert;
// Sector NAMES can be null, but ts isn't flexible enough
if (strlen(ts.getCurrentLine()) > strlen(" sector"))
@ -140,7 +140,7 @@ void Sector::load(TextSplitter &ts) {
error("Invalid visibility spec: %s", buf);
ts.scanString(" height %f", 1, &_height);
ts.scanString(" numvertices %d", 1, &_numVertices);
_vertices = new Graphics::Vector3d[_numVertices + 1];
_vertices = new Math::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++)
@ -157,7 +157,7 @@ void Sector::load(TextSplitter &ts) {
void Sector::loadBinary(Common::MemoryReadStream *ms) {
_numVertices = ms->readUint32LE();
_vertices = new Graphics::Vector3d[_numVertices];
_vertices = new Math::Vector3d[_numVertices];
for(int i = 0; i < _numVertices; i++) {
ms->read(_vertices[i]._coords, 12);
}
@ -191,12 +191,12 @@ void Sector::shrink(float radius) {
_shrinkRadius = radius;
if (!_origVertices) {
_origVertices = _vertices;
_vertices = new Graphics::Vector3d[_numVertices + 1];
_vertices = new Math::Vector3d[_numVertices + 1];
}
// Move each vertex inwards by the given amount.
for (int j = 0; j < _numVertices; j++) {
Graphics::Vector3d shrinkDir;
Math::Vector3d shrinkDir;
for (int k = 0; k < g_grim->getCurrScene()->getSectorCount(); k++) {
Sector *other = g_grim->getCurrScene()->getSectorBase(k);
@ -204,19 +204,19 @@ void Sector::shrink(float radius) {
continue;
for (int l = 0; l < other->_numVertices; l++) {
Graphics::Vector3d* otherVerts = other->_vertices;
Math::Vector3d* otherVerts = other->_vertices;
if (other->_origVertices)
otherVerts = other->_origVertices;
if ((otherVerts[l] - _origVertices[j]).magnitude() < 0.01f) {
Graphics::Vector3d e1 = otherVerts[l + 1] - otherVerts[l];
Graphics::Vector3d e2;
Math::Vector3d e1 = otherVerts[l + 1] - otherVerts[l];
Math::Vector3d e2;
if (l - 1 >= 0)
e2 = otherVerts[l] - otherVerts[l - 1];
else
e2 = otherVerts[l] - otherVerts[other->_numVertices - 1];
e1.normalize();
e2.normalize();
Graphics::Vector3d bisector = (e1 - e2);
Math::Vector3d bisector = (e1 - e2);
bisector.normalize();
shrinkDir += bisector;
}
@ -235,8 +235,8 @@ void Sector::shrink(float radius) {
// Make sure the sector is still convex.
for (int j = 0; j < _numVertices; j++) {
Graphics::Vector3d e1 = _vertices[j + 1] - _vertices[j];
Graphics::Vector3d e2;
Math::Vector3d e1 = _vertices[j + 1] - _vertices[j];
Math::Vector3d e2;
if (j - 1 >= 0)
e2 = _vertices[j] - _vertices[j - 1];
else
@ -265,7 +265,7 @@ void Sector::unshrink() {
}
}
bool Sector::isPointInSector(const Graphics::Vector3d &point) const {
bool Sector::isPointInSector(const Math::Vector3d &point) const {
// The algorithm: for each edge A->B, check whether the z-component
// of (B-A) x (P-A) is >= 0. Then the point is at least in the
// cylinder above&below the polygon. (This works because the polygons'
@ -306,15 +306,15 @@ bool Sector::isPointInSector(const Graphics::Vector3d &point) const {
}
for (int i = 0; i < _numVertices; i++) {
Graphics::Vector3d edge = _vertices[i + 1] - _vertices[i];
Graphics::Vector3d delta = point - _vertices[i];
Math::Vector3d edge = _vertices[i + 1] - _vertices[i];
Math::Vector3d delta = point - _vertices[i];
if (edge.x() * delta.y() < edge.y() * delta.x())
return false;
}
return true;
}
Common::List<Graphics::Line3d> Sector::getBridgesTo(Sector *sector) const {
Common::List<Math::Line3d> Sector::getBridgesTo(Sector *sector) const {
// This returns a list of "bridges", which are edges that can be travelled
// through to get to another sector. 0 bridges mean the sectors aren't
// connected.
@ -324,20 +324,20 @@ Common::List<Graphics::Line3d> Sector::getBridgesTo(Sector *sector) const {
// sector B, so we end up with a list of lines which are at the border
// of sector A and inside sector B.
Common::List<Graphics::Line3d> bridges;
Common::List<Graphics::Line3d>::iterator it;
Common::List<Math::Line3d> bridges;
Common::List<Math::Line3d>::iterator it;
for (int i = 0; i < _numVertices; i++){
bridges.push_back(Graphics::Line3d(_vertices[i], _vertices[i+1]));
bridges.push_back(Math::Line3d(_vertices[i], _vertices[i+1]));
}
Graphics::Vector3d* sectorVertices = sector->getVertices();
Math::Vector3d* sectorVertices = sector->getVertices();
for (int i = 0; i < sector->getNumVertices(); i++) {
Graphics::Vector3d pos, edge, delta_b1, delta_b2;
Graphics::Line3d line(sectorVertices[i], sectorVertices[i+1]);
Math::Vector3d pos, edge, delta_b1, delta_b2;
Math::Line3d line(sectorVertices[i], sectorVertices[i+1]);
it = bridges.begin();
while (it != bridges.end()) {
Graphics::Line3d& bridge = (*it);
Math::Line3d& bridge = (*it);
edge = line.end() - line.begin();
delta_b1 = bridge.begin() - line.begin();
delta_b2 = bridge.end() - line.begin();
@ -350,11 +350,11 @@ Common::List<Graphics::Line3d> Sector::getBridgesTo(Sector *sector) const {
continue;
} else if (b1_out) {
if (bridge.intersectLine2d(line, &pos)) {
bridge = Graphics::Line3d(pos, bridge.end());
bridge = Math::Line3d(pos, bridge.end());
}
} else if (b2_out) {
if (bridge.intersectLine2d(line, &pos)) {
bridge = Graphics::Line3d(bridge.begin(), pos);
bridge = Math::Line3d(bridge.begin(), pos);
}
}
@ -378,37 +378,37 @@ Common::List<Graphics::Line3d> Sector::getBridgesTo(Sector *sector) const {
return bridges;
}
Graphics::Vector3d Sector::getProjectionToPlane(const Graphics::Vector3d &point) const {
Math::Vector3d Sector::getProjectionToPlane(const Math::Vector3d &point) const {
if (_normal.z() == 0)
error("Trying to walk along vertical plane");
// Formula: return p - (n . (p - v_0))/(n . k) k
Graphics::Vector3d result = point;
Math::Vector3d result = point;
result.z() -= dot(_normal, point - _vertices[0]) / _normal.z();
return result;
}
Graphics::Vector3d Sector::getProjectionToPuckVector(const Graphics::Vector3d &v) const {
Math::Vector3d Sector::getProjectionToPuckVector(const Math::Vector3d &v) const {
if (_normal.z() == 0)
error("Trying to walk along vertical plane");
Graphics::Vector3d result = v;
Math::Vector3d result = v;
result.z() -= dot(_normal, v) / _normal.z();
return result;
}
// Find the closest point on the walkplane to the given point
Graphics::Vector3d Sector::getClosestPoint(const Graphics::Vector3d &point) const {
Math::Vector3d Sector::getClosestPoint(const Math::Vector3d &point) const {
// First try to project to the plane
Graphics::Vector3d p2 = point;
Math::Vector3d p2 = point;
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++) {
Graphics::Vector3d edge = _vertices[i + 1] - _vertices[i];
Graphics::Vector3d delta = point - _vertices[i];
Math::Vector3d edge = _vertices[i + 1] - _vertices[i];
Math::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
@ -430,9 +430,9 @@ Graphics::Vector3d Sector::getClosestPoint(const Graphics::Vector3d &point) cons
return _vertices[index];
}
void Sector::getExitInfo(const Graphics::Vector3d &s, const Graphics::Vector3d &dirVec, struct ExitInfo *result) const {
Graphics::Vector3d start = getProjectionToPlane(s);
Graphics::Vector3d dir = getProjectionToPuckVector(dirVec);
void Sector::getExitInfo(const Math::Vector3d &s, const Math::Vector3d &dirVec, struct ExitInfo *result) const {
Math::Vector3d start = getProjectionToPlane(s);
Math::Vector3d dir = getProjectionToPuckVector(dirVec);
// First find the edge the ray exits through: this is where
// the z-component of (v_i - start) x dir changes sign from
@ -442,7 +442,7 @@ void Sector::getExitInfo(const Graphics::Vector3d &s, const Graphics::Vector3d &
// positive z-component.
int i;
for (i = 0; i < _numVertices; i++) {
Graphics::Vector3d delta = _vertices[i] - start;
Math::Vector3d delta = _vertices[i] - start;
if (delta.x() * dir.y() > delta.y() * dir.x())
break;
}
@ -451,7 +451,7 @@ void Sector::getExitInfo(const Graphics::Vector3d &s, const Graphics::Vector3d &
// z-component.
while (i < _numVertices) {
i++;
Graphics::Vector3d delta = _vertices[i] - start;
Math::Vector3d delta = _vertices[i] - start;
if (delta.x() * dir.y() <= delta.y() * dir.x())
break;
}
@ -460,7 +460,7 @@ void Sector::getExitInfo(const Graphics::Vector3d &s, const Graphics::Vector3d &
result->angleWithEdge = angle(dir, result->edgeDir);
result->edgeVertex = i - 1;
Graphics::Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
Math::Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
float d = dot(dir, edgeNormal);
// This is 0 for the albinizod monster in the at set
if (!d)
@ -474,12 +474,12 @@ Sector &Sector::operator=(const Sector &other) {
_name = other._name;
_type = other._type;
_visible = other._visible;
_vertices = new Graphics::Vector3d[_numVertices + 1];
_vertices = new Math::Vector3d[_numVertices + 1];
for (int i = 0; i < _numVertices + 1; ++i) {
_vertices[i] = other._vertices[i];
}
if (other._origVertices) {
_origVertices = new Graphics::Vector3d[_numVertices + 1];
_origVertices = new Math::Vector3d[_numVertices + 1];
for (int i = 0; i < _numVertices + 1; ++i) {
_origVertices[i] = other._origVertices[i];
}

View file

@ -26,8 +26,8 @@
#include "common/str.h"
#include "common/list.h"
#include "graphics/vector3d.h"
#include "graphics/line3d.h"
#include "math/vector3d.h"
#include "math/line3d.h"
namespace Common {
class MemoryReadStream;
@ -66,26 +66,26 @@ public:
int getSectorId() const { return _id; }
SectorType getType() const { return _type; } // FIXME: Implement type de-masking
bool isVisible() const { return _visible && !_invalid; }
bool isPointInSector(const Graphics::Vector3d &point) const;
Common::List<Graphics::Line3d> getBridgesTo(Sector *sector) const;
bool isPointInSector(const Math::Vector3d &point) const;
Common::List<Math::Line3d> getBridgesTo(Sector *sector) const;
Graphics::Vector3d getProjectionToPlane(const Graphics::Vector3d &point) const;
Graphics::Vector3d getProjectionToPuckVector(const Graphics::Vector3d &v) const;
Math::Vector3d getProjectionToPlane(const Math::Vector3d &point) const;
Math::Vector3d getProjectionToPuckVector(const Math::Vector3d &v) const;
Graphics::Vector3d getClosestPoint(const Graphics::Vector3d &point) const;
Math::Vector3d getClosestPoint(const Math::Vector3d &point) const;
// Interface to trace a ray to its exit from the polygon
struct ExitInfo {
Graphics::Vector3d exitPoint;
Math::Vector3d exitPoint;
float angleWithEdge;
Graphics::Vector3d edgeDir;
Math::Vector3d edgeDir;
int edgeVertex;
};
void getExitInfo(const Graphics::Vector3d &start, const Graphics::Vector3d &dir, struct ExitInfo *result) const;
void getExitInfo(const Math::Vector3d &start, const Math::Vector3d &dir, struct ExitInfo *result) const;
int getNumVertices() { return _numVertices; }
Graphics::Vector3d *getVertices() { return _vertices; }
Graphics::Vector3d getNormal() { return _normal; }
Math::Vector3d *getVertices() { return _vertices; }
Math::Vector3d getNormal() { return _normal; }
Sector &operator=(const Sector &other);
bool operator==(const Sector &other) const;
@ -97,12 +97,12 @@ private:
SectorType _type;
bool _visible;
bool _invalid;
Graphics::Vector3d *_vertices;
Graphics::Vector3d *_origVertices;
Math::Vector3d *_vertices;
Math::Vector3d *_origVertices;
float _height;
float _shrinkRadius;
Graphics::Vector3d _normal;
Math::Vector3d _normal;
};
} // end of namespace Grim

View file

@ -15,13 +15,6 @@ MODULE_OBJS := \
VectorRenderer.o \
VectorRendererSpec.o \
yuv_to_rgb.o \
matrix3.o \
matrix4.o \
line3d.o \
line2d.o \
rect2d.o \
vector2d.o \
vector3d.o \
tinygl/api.o \
tinygl/arrays.o \
tinygl/clear.o \

View file

@ -22,10 +22,10 @@
* $Id$
*/
#include "graphics/line2d.h"
#include "graphics/rect2d.h"
#include "math/line2d.h"
#include "math/rect2d.h"
namespace Graphics {
namespace Math {
Line2d::Line2d() :
_a(0), _b(0), _c(0) {

View file

@ -22,12 +22,12 @@
* $Id$
*/
#ifndef GRAPHICS_LINE2D_H
#define GRAPHICS_LINE2D_H
#ifndef MATH_LINE2D_H
#define MATH_LINE2D_H
#include "graphics/vector2d.h"
#include "math/vector2d.h"
namespace Graphics {
namespace Math {
class Line2d {
public:
@ -67,7 +67,7 @@ public:
void operator=(const Segment2d &other);
private:
Graphics::Vector2d _begin, _end;
Math::Vector2d _begin, _end;
};

View file

@ -22,9 +22,9 @@
* $Id$
*/
#include "graphics/line3d.h"
#include "math/line3d.h"
namespace Graphics {
namespace Math {
Line3d::Line3d() {
@ -39,19 +39,19 @@ Line3d::Line3d(const Line3d &other) {
*this = other;
}
Graphics::Vector3d Line3d::begin() const {
Math::Vector3d Line3d::begin() const {
return _begin;
}
Graphics::Vector3d Line3d::end() const {
Math::Vector3d Line3d::end() const {
return _end;
}
Graphics::Vector3d Line3d::middle() const {
Math::Vector3d Line3d::middle() const {
return (_begin + _end) / 2.f;
}
bool Line3d::intersectLine2d(const Line3d &other, Graphics::Vector3d *pos) {
bool Line3d::intersectLine2d(const Line3d &other, Math::Vector3d *pos) {
float denom = ((other._end.y() - other._begin.y()) * (_end.x() - _begin.x())) -
((other._end.x() - other._begin.x()) * (_end.y() - _begin.y()));

View file

@ -22,15 +22,15 @@
* $Id$
*/
#ifndef GRAPHICS_LINE3D_H
#define GRAPHICS_LINE3D_H
#ifndef MATH_LINE3D_H
#define MATH_LINE3D_H
#include "common/scummsys.h"
#include "common/endian.h"
#include "graphics/vector3d.h"
#include "math/vector3d.h"
namespace Graphics {
namespace Math {
class Line3d {
public:
@ -38,19 +38,19 @@ public:
Line3d(const Vector3d &begin, const Vector3d &end);
Line3d(const Line3d &other);
Graphics::Vector3d begin() const;
Graphics::Vector3d end() const;
Graphics::Vector3d middle() const;
Math::Vector3d begin() const;
Math::Vector3d end() const;
Math::Vector3d middle() const;
bool intersectLine2d(const Line3d &other, Graphics::Vector3d *pos);
bool intersectLine2d(const Line3d &other, Math::Vector3d *pos);
void operator=(const Line3d &other);
private:
Graphics::Vector3d _begin, _end;
Math::Vector3d _begin, _end;
};
} // end of namespace Graphics
} // end of namespace Math
#endif

View file

@ -22,12 +22,12 @@
* $Id$
*/
#ifndef GRAPHICS_MATRIX_H
#define GRAPHICS_MATRIX_H
#ifndef MATH_MATRIX_H
#define MATH_MATRIX_H
#include <assert.h>
namespace Graphics {
namespace Math {
template<int rows, int cols>
class Matrix {

View file

@ -22,9 +22,9 @@
* $Id$
*/
#include "graphics/matrix3.h"
#include "math/matrix3.h"
namespace Graphics {
namespace Math {
Matrix3x3::Matrix3x3() :
Matrix(), Rotation3D(this) {
@ -54,4 +54,4 @@ float DegreeToRadian(float degrees) {
return (float)DEGTORAD(degrees);
}
} // end of namespace Graphics
} // end of namespace Math

View file

@ -22,14 +22,14 @@
* $Id$
*/
#ifndef GRAPHICS_MATRIX3_H
#define GRAPHICS_MATRIX3_H
#ifndef MATH_MATRIX3_H
#define MATH_MATRIX3_H
#include "graphics/matrix.h"
#include "graphics/transform.h"
#include "graphics/vector3d.h"
#include "math/matrix.h"
#include "math/transform.h"
#include "math/vector3d.h"
namespace Graphics {
namespace Math {
template<class T>
class Rotation3D : public Transform<T> {
@ -167,7 +167,7 @@ float Rotation3D<T>::getRoll() const {
}
} // end of namespace Graphics
} // end of namespace Math
#endif

View file

@ -22,9 +22,9 @@
* $Id$
*/
#include "graphics/matrix4.h"
#include "math/matrix4.h"
namespace Graphics {
namespace Math {
Matrix4::Matrix4() :
Matrix(), Rotation3D(this) {
@ -62,5 +62,5 @@ void Matrix4::translate(const Vector3d &vec) {
operator()(3, 2) += v.z();
}
} // end of namespace Graphics
} // end of namespace Math

View file

@ -22,12 +22,12 @@
* $Id$
*/
#ifndef GRAPHICS_MATRIX4_H
#define GRAPHICS_MATRIX4_H
#ifndef MATH_MATRIX4_H
#define MATH_MATRIX4_H
#include "graphics/matrix3.h"
#include "math/matrix3.h"
namespace Graphics {
namespace Math {
// matrix 4 is a rotation matrix + position
class Matrix4 : public Matrix<4, 4>, public Rotation3D<Matrix4> {
@ -43,6 +43,6 @@ public:
};
} // end of namespace Graphics
} // end of namespace Math
#endif

13
math/module.mk Normal file
View file

@ -0,0 +1,13 @@
MODULE := math
MODULE_OBJS := \
matrix3.o \
matrix4.o \
line3d.o \
line2d.o \
rect2d.o \
vector2d.o \
vector3d.o
# Include common rules
include $(srcdir)/rules.mk

View file

@ -24,9 +24,9 @@
#include "common/scummsys.h"
#include "graphics/rect2d.h"
#include "math/rect2d.h"
namespace Graphics {
namespace Math {
Rect2d::Rect2d() {

View file

@ -22,13 +22,13 @@
* $Id$
*/
#ifndef GRAPHICS_RECT2D_H
#define GRAPHICS_RECT2D_H
#ifndef MATH_RECT2D_H
#define MATH_RECT2D_H
#include "graphics/vector2d.h"
#include "graphics/line2d.h"
#include "math/vector2d.h"
#include "math/line2d.h"
namespace Graphics {
namespace Math {
class Segment2d;

View file

@ -22,10 +22,10 @@
* $Id$
*/
#ifndef GRAPHICS_TRANSFORM_H
#define GRAPHICS_TRANSFORM_H
#ifndef MATH_TRANSFORM_H
#define MATH_TRANSFORM_H
namespace Graphics {
namespace Math {
template<class T>
class Transform {

View file

@ -22,11 +22,11 @@
* $Id$
*/
#include "graphics/vector2d.h"
#include "math/vector2d.h"
#include "common/streamdebug.h"
namespace Graphics {
namespace Math {
Vector2d::Vector2d() :
_x(0), _y(0) {
@ -121,7 +121,7 @@ Vector3d Vector2d::toVector3d() const {
}
Common::Debug &operator<<(Common::Debug dbg, const Graphics::Vector2d &v) {
Common::Debug &operator<<(Common::Debug dbg, const Math::Vector2d &v) {
dbg.nospace() << "Vector2d(" << v.getX() << "," << v.getY() << ")";
return dbg.space();

View file

@ -22,12 +22,12 @@
* $Id$
*/
#ifndef GRAPHICS_VECTOR2D_H
#define GRAPHICS_VECTOR2D_H
#ifndef MATH_VECTOR2D_H
#define MATH_VECTOR2D_H
#include "graphics/vector3d.h"
#include "math/vector3d.h"
namespace Graphics {
namespace Math {
class Vector2d {
public:
@ -88,6 +88,6 @@ namespace Common {
class Debug;
}
Common::Debug &operator<<(Common::Debug dbg, const Graphics::Vector2d &v);
Common::Debug &operator<<(Common::Debug dbg, const Math::Vector2d &v);
#endif

View file

@ -24,9 +24,9 @@
#include "common/streamdebug.h"
#include "graphics/vector3d.h"
#include "math/vector3d.h"
Common::Debug &operator<<(Common::Debug dbg, const Graphics::Vector3d &v) {
Common::Debug &operator<<(Common::Debug dbg, const Math::Vector3d &v) {
dbg.nospace() << "Vector3d(" << v.x() << "," << v.y() << "," << v.z() << ")";
return dbg.space();

View file

@ -22,13 +22,13 @@
* $Id$
*/
#ifndef GRAPHICS_VECTOR3D_H
#define GRAPHICS_VECTOR3D_H
#ifndef MATH_VECTOR3D_H
#define MATH_VECTOR3D_H
#include "common/scummsys.h"
#include "common/endian.h"
namespace Graphics {
namespace Math {
class Vector3d {
public:
@ -183,12 +183,12 @@ inline Vector3d get_vector3d(const char *data) {
return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8));
}
} // end of namespace Graphics
} // end of namespace Math
namespace Common {
class Debug;
}
Common::Debug &operator<<(Common::Debug dbg, const Graphics::Vector3d &v);
Common::Debug &operator<<(Common::Debug dbg, const Math::Vector3d &v);
#endif