put Vector3D and Matrix3/4 into Graphics namespace

This commit is contained in:
Pawel Kolodziejski 2009-05-25 12:13:35 +00:00
parent 34d97baaf3
commit ba0576bc5e
26 changed files with 200 additions and 184 deletions

View file

@ -216,5 +216,23 @@ FORCEINLINE uint32 READ_BE_UINT24(const void *ptr) {
return (b[0] << 16) + (b[1] << 8) + (b[2]);
}
#if defined(SYSTEM_BIG_ENDIAN)
inline float get_float(const char *data) {
const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
unsigned char fdata[4];
fdata[0] = udata[3];
fdata[1] = udata[2];
fdata[2] = udata[1];
fdata[3] = udata[0];
return *(reinterpret_cast<const float *>(fdata));
}
#else
inline float get_float(const char *data) {
return *(reinterpret_cast<const float *>(data));
}
#endif
#endif

View file

@ -524,22 +524,6 @@
RelativePath="..\..\engines\grim\material.h"
>
</File>
<File
RelativePath="..\..\engines\grim\matrix3.cpp"
>
</File>
<File
RelativePath="..\..\engines\grim\matrix3.h"
>
</File>
<File
RelativePath="..\..\engines\grim\matrix4.cpp"
>
</File>
<File
RelativePath="..\..\engines\grim\matrix4.h"
>
</File>
<File
RelativePath="..\..\engines\grim\model.cpp"
>
@ -612,10 +596,6 @@
RelativePath="..\..\engines\grim\textsplit.h"
>
</File>
<File
RelativePath="..\..\engines\grim\vector3d.h"
>
</File>
<File
RelativePath="..\..\engines\grim\version.cpp"
>
@ -1065,6 +1045,26 @@
<Filter
Name="graphics"
>
<File
RelativePath="..\..\graphics\matrix3.cpp"
>
</File>
<File
RelativePath="..\..\graphics\matrix3.h"
>
</File>
<File
RelativePath="..\..\graphics\matrix4.cpp"
>
</File>
<File
RelativePath="..\..\graphics\matrix4.h"
>
</File>
<File
RelativePath="..\..\graphics\vector3d.h"
>
</File>
<Filter
Name="tinygl"
>

View file

@ -102,7 +102,7 @@ void Actor::turnTo(float pitch, float yaw, float roll) {
_turning = false;
}
void Actor::walkTo(Vector3d p) {
void Actor::walkTo(Graphics::Vector3d p) {
// For now, this is just the ignoring-boxes version (which afaict
// isn't even in the original). This will eventually need a
// following-boxes version also.
@ -135,10 +135,9 @@ void Actor::walkForward() {
float dist = g_grim->perSecond(_walkRate);
float yaw_rad = _yaw * (LOCAL_PI / 180), pitch_rad = _pitch * (LOCAL_PI / 180);
//float yaw;
Vector3d forwardVec(-sin(yaw_rad) * cos(pitch_rad),
cos(yaw_rad) * cos(pitch_rad),
sin(pitch_rad));
Vector3d destPos = _pos + forwardVec * dist;
Graphics::Vector3d forwardVec(-sin(yaw_rad) * cos(pitch_rad),
cos(yaw_rad) * cos(pitch_rad), sin(pitch_rad));
Graphics::Vector3d destPos = _pos + forwardVec * dist;
if (! _constrain) {
_pos += forwardVec * dist;
@ -163,7 +162,7 @@ void Actor::walkForward() {
while (currSector) {
prevSector = currSector;
Vector3d puckVector = currSector->projectToPuckVector(forwardVec);
Graphics::Vector3d puckVector = currSector->projectToPuckVector(forwardVec);
puckVector /= puckVector.magnitude();
currSector->getExitInfo(_pos, puckVector, &ei);
float exitDist = (ei.exitPoint - _pos).magnitude();
@ -201,9 +200,9 @@ void Actor::walkForward() {
setYaw(_yaw + turnAmt * turnDir);
}
Vector3d Actor::puckVector() const {
Graphics::Vector3d Actor::puckVector() const {
float yaw_rad = _yaw * (LOCAL_PI / 180);
Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Graphics::Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Sector *sector = g_grim->currScene()->findPointSector(_pos, 0x1000);
if (!sector)
@ -287,15 +286,15 @@ void Actor::turn(int dir) {
float Actor::angleTo(const Actor &a) const {
float yaw_rad = _yaw * (LOCAL_PI / 180);
Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Vector3d delta = a.pos() - _pos;
Graphics::Vector3d forwardVec(-sin(yaw_rad), cos(yaw_rad), 0);
Graphics::Vector3d delta = a.pos() - _pos;
delta.z() = 0;
return angle(forwardVec, delta) * (180 / LOCAL_PI);
}
float Actor::yawTo(Vector3d p) const {
Vector3d dpos = p - _pos;
float Actor::yawTo(Graphics::Vector3d p) const {
Graphics::Vector3d dpos = p - _pos;
if (dpos.x() == 0 && dpos.y() == 0)
return 0;
@ -518,7 +517,7 @@ void Actor::update() {
}
if (_walking) {
Vector3d dir = _destPos - _pos;
Graphics::Vector3d dir = _destPos - _pos;
float dist = dir.magnitude();
if (dist > 0)
@ -713,7 +712,7 @@ void Actor::setActivateShadow(int shadowId, bool state) {
_shadowArray[shadowId].active = state;
}
void Actor::setShadowPoint(Vector3d pos) {
void Actor::setShadowPoint(Graphics::Vector3d pos) {
assert(_activeShadowSlot != -1);
_shadowArray[_activeShadowSlot].pos = pos;

View file

@ -41,7 +41,7 @@ extern int g_winX1, g_winY1, g_winX2, g_winY2;
struct Shadow {
Common::String name;
Vector3d pos;
Graphics::Vector3d pos;
SectorListType planeList;
byte *shadowMask;
bool active;
@ -57,17 +57,17 @@ public:
void setTalkColor(const Color& c) { _talkColor = c; }
Color talkColor() const { return _talkColor; }
void setPos(Vector3d pos) { _pos = pos; }
void setPos(Graphics::Vector3d pos) { _pos = pos; }
// When the actor is walking report where the actor is going to and
// not the actual current position, this fixes some scene change
// change issues with the Bone Wagon (along with other fixes)
Vector3d pos() const {
Graphics::Vector3d pos() const {
if (_walking)
return _destPos;
else
return _pos;
}
void walkTo(Vector3d p);
void walkTo(Graphics::Vector3d p);
void stopWalking() { _walking = false; }
bool isWalking() const;
void setRot(float pitch, float yaw, float roll);
@ -88,14 +88,14 @@ public:
void setLooking(bool lookingMode) { _lookingMode = lookingMode; }
float angleTo(const Actor &a) const;
float yawTo(Vector3d p) const;
float yawTo(Graphics::Vector3d p) const;
bool inSet(const char *name) const {
return _setName == name;
}
void walkForward();
void setReflection(float angle) { _reflectionAngle = angle; }
Vector3d puckVector() const;
Graphics::Vector3d puckVector() const;
void turn(int dir);
void sayLine(const char *msg, const char *msgId);
@ -128,7 +128,7 @@ public:
}
void setActiveShadow(int shadowId);
void setShadowPoint(Vector3d pos);
void setShadowPoint(Graphics::Vector3d pos);
void setShadowPlane(const char *name);
void addShadowPlane(const char *name);
void clearShadowPlanes();
@ -148,7 +148,7 @@ public:
void setLookAtVectorZero() {
_lookAtVector.set(0.f, 0.f, 0.f);
}
void setLookAtVector(Vector3d vector) {
void setLookAtVector(Graphics::Vector3d vector) {
_lookAtVector = vector;
}
void setLookAtRate(float rate) {
@ -163,7 +163,7 @@ private:
Common::String _name;
Common::String _setName; // The actual current set
Color _talkColor;
Vector3d _pos;
Graphics::Vector3d _pos;
float _pitch, _yaw, _roll;
float _walkRate, _turnRate;
@ -181,7 +181,7 @@ private:
// Variables for walking to a point
bool _walking;
Vector3d _destPos;
Graphics::Vector3d _destPos;
// chores
Costume *_restCostume;
@ -223,7 +223,7 @@ private:
}
// lookAt
Vector3d _lookAtVector;
Graphics::Vector3d _lookAtVector;
float _lookAtRate;
int _winX1, _winY1, _winX2, _winY2;

View file

@ -120,7 +120,7 @@ public:
void update();
void reset();
void resetColormap();
void setMatrix(Matrix4 matrix) { _matrix = matrix; };
void setMatrix(Graphics::Matrix4 matrix) { _matrix = matrix; };
~ModelComponent();
Model::HierNode *hierarchy() { return _hier; }
@ -130,7 +130,7 @@ protected:
Common::String _filename;
ResPtr<Model> _obj;
Model::HierNode *_hier;
Matrix4 _matrix;
Graphics::Matrix4 _matrix;
};
class MainModelComponent : public ModelComponent {
@ -161,7 +161,7 @@ public:
void reset();
~MeshComponent() { }
void setMatrix(Matrix4 matrix) { _matrix = matrix; };
void setMatrix(Graphics::Matrix4 matrix) { _matrix = matrix; };
Model::HierNode *node() { return _node; }
@ -169,7 +169,7 @@ private:
Common::String _name;
int _num;
Model::HierNode *_node;
Matrix4 _matrix;
Graphics::Matrix4 _matrix;
};
BitmapComponent::BitmapComponent(Costume::Component *parent, int parentID, const char *filename, tag32 tag) :
@ -606,7 +606,7 @@ void SoundComponent::setKey(int val) {
// then it will just use the existing handle
g_imuse->startSfx(_soundName.c_str());
if (g_grim->currScene() && g_currentUpdatedActor) {
Vector3d pos = g_currentUpdatedActor->pos();
Graphics::Vector3d pos = g_currentUpdatedActor->pos();
g_grim->currScene()->setSoundPosition(_soundName.c_str(), pos);
}
break;
@ -1016,7 +1016,7 @@ void Costume::setHead(int joint1, int joint2, int joint3, float maxRoll, float m
_head.maxYaw = maxYaw;
}
void Costume::setPosRotate(Vector3d pos, float pitch, float yaw, float roll) {
void Costume::setPosRotate(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
_matrix._pos = pos;
_matrix._rot.buildFromPitchYawRoll(pitch, yaw, roll);
}

View file

@ -58,7 +58,7 @@ public:
void update();
void setupTextures();
void draw();
void setPosRotate(Vector3d pos, float pitch, float yaw, float roll);
void setPosRotate(Graphics::Vector3d pos, float pitch, float yaw, float roll);
class Component {
public:
@ -69,7 +69,7 @@ public:
void setColormap(CMap *c);
bool visible();
Component *parent() { return _parent; }
virtual void setMatrix(Matrix4) { };
virtual void setMatrix(Graphics::Matrix4) { };
virtual void init() { }
virtual void setKey(int) { }
virtual void setMapName(char *) { }
@ -85,7 +85,7 @@ public:
int _parentID;
bool _visible;
Component *_parent, *_child, *_sibling;
Matrix4 _matrix;
Graphics::Matrix4 _matrix;
Costume *_cost;
void setCostume(Costume *cost) { _cost = cost; }
void setParent(Component *newParent);
@ -150,7 +150,7 @@ private:
ResPtr<CMap> _cmap;
int _numChores;
Chore *_chores;
Matrix4 _matrix;
Graphics::Matrix4 _matrix;
};
} // end of namespace Grim

View file

@ -53,13 +53,13 @@ public:
virtual bool isHardwareAccelerated() = 0;
virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0;
virtual void positionCamera(Vector3d pos, Vector3d interest) = 0;
virtual void positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) = 0;
virtual void clearScreen() = 0;
virtual void flipBuffer() = 0;
virtual void getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, int *x2, int *y2) = 0;
virtual void startActorDraw(Vector3d pos, float yaw, float pitch, float roll) = 0;
virtual void startActorDraw(Graphics::Vector3d pos, float yaw, float pitch, float roll) = 0;
virtual void finishActorDraw() = 0;
virtual void setShadow(Shadow *shadow) = 0;
virtual void drawShadowPlanes() = 0;
@ -69,7 +69,7 @@ public:
virtual void set3DMode() = 0;
virtual void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) = 0;
virtual void translateViewpoint(Graphics::Vector3d pos, float pitch, float yaw, float roll) = 0;
virtual void translateViewpoint() = 0;
virtual void drawHierachyNode(const Model::HierNode *node) = 0;

View file

@ -93,11 +93,11 @@ void GfxOpenGL::setupCamera(float fov, float nclip, float fclip, float roll) {
glRotatef(roll, 0, 0, -1);
}
void GfxOpenGL::positionCamera(Vector3d pos, Vector3d interest) {
Vector3d up_vec(0, 0, 1);
void GfxOpenGL::positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) {
Graphics::Vector3d up_vec(0, 0, 1);
if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Vector3d(0, 1, 0);
up_vec = Graphics::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());
}
@ -114,7 +114,7 @@ bool GfxOpenGL::isHardwareAccelerated() {
return true;
}
static void glShadowProjection(Vector3d light, Vector3d plane, Vector3d normal, bool dontNegate) {
static void glShadowProjection(Graphics::Vector3d light, Graphics::Vector3d plane, Graphics::Vector3d normal, bool dontNegate) {
// Based on GPL shadow projection example by
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
float d, c;
@ -179,7 +179,7 @@ void GfxOpenGL::getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, in
GLdouble winX, winY, winZ;
for (int i = 0; i < model->_numFaces; i++) {
Vector3d v;
Graphics::Vector3d v;
float* pVertices;
for (int j = 0; j < model->_faces[i]._numVertices; j++) {
@ -234,7 +234,7 @@ void GfxOpenGL::getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, in
*y2 = (int)bottom;
}
void GfxOpenGL::startActorDraw(Vector3d pos, float yaw, float pitch, float roll) {
void GfxOpenGL::startActorDraw(Graphics::Vector3d pos, float yaw, float pitch, float roll) {
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -343,7 +343,7 @@ void GfxOpenGL::drawModelFace(const Model::Face *face, float *vertices, float *v
glDisable(GL_ALPHA_TEST);
}
void GfxOpenGL::translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) {
void GfxOpenGL::translateViewpoint(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

View file

@ -49,7 +49,7 @@ public:
const char *getVideoDeviceName();
void setupCamera(float fov, float nclip, float fclip, float roll);
void positionCamera(Vector3d pos, Vector3d interest);
void positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest);
void clearScreen();
void flipBuffer();
@ -58,7 +58,7 @@ public:
void getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, int *x2, int *y2);
void startActorDraw(Vector3d pos, float yaw, float pitch, float roll);
void startActorDraw(Graphics::Vector3d pos, float yaw, float pitch, float roll);
void finishActorDraw();
void setShadow(Shadow *shadow);
void drawShadowPlanes();
@ -68,7 +68,7 @@ public:
void set3DMode();
void translateViewpoint(Vector3d pos, float pitch, float yaw, float roll);
void translateViewpoint(Graphics::Vector3d pos, float pitch, float yaw, float roll);
void translateViewpoint();
void drawHierachyNode(const Model::HierNode *node);

View file

@ -188,11 +188,11 @@ void GfxTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
tglRotatef(roll, 0, 0, -1);
}
void GfxTinyGL::positionCamera(Vector3d pos, Vector3d interest) {
Vector3d up_vec(0, 0, 1);
void GfxTinyGL::positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) {
Graphics::Vector3d up_vec(0, 0, 1);
if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Vector3d(0, 1, 0);
up_vec = Graphics::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());
}
@ -211,7 +211,7 @@ bool GfxTinyGL::isHardwareAccelerated() {
return false;
}
static void tglShadowProjection(Vector3d light, Vector3d plane, Vector3d normal, bool dontNegate) {
static void tglShadowProjection(Graphics::Vector3d light, Graphics::Vector3d plane, Graphics::Vector3d normal, bool dontNegate) {
// Based on GPL shadow projection example by
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
float d, c;
@ -276,7 +276,7 @@ void GfxTinyGL::getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, in
TGLfloat winX, winY, winZ;
for (int i = 0; i < model->_numFaces; i++) {
Vector3d v;
Graphics::Vector3d v;
float* pVertices;
for (int j = 0; j < model->_faces[i]._numVertices; j++) {
@ -346,7 +346,7 @@ void GfxTinyGL::getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, in
}*/
}
void GfxTinyGL::startActorDraw(Vector3d pos, float yaw, float pitch, float roll) {
void GfxTinyGL::startActorDraw(Graphics::Vector3d pos, float yaw, float pitch, float roll) {
tglEnable(TGL_TEXTURE_2D);
tglMatrixMode(TGL_MODELVIEW);
tglPushMatrix();
@ -453,7 +453,7 @@ void GfxTinyGL::drawModelFace(const Model::Face *face, float *vertices, float *v
tglEnd();
}
void GfxTinyGL::translateViewpoint(Vector3d pos, float pitch, float yaw, float roll) {
void GfxTinyGL::translateViewpoint(Graphics::Vector3d pos, float pitch, float yaw, float roll) {
tglPushMatrix();
tglTranslatef(pos.x(), pos.y(), pos.z());

View file

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

View file

@ -156,11 +156,11 @@ void KeyframeAnim::animate(Model::HierNode *nodes, float time, int priority1, in
void KeyframeAnim::KeyframeEntry::loadBinary(const char *&data) {
_frame = get_float(data);
_flags = READ_LE_UINT32(data + 4);
_pos = get_vector3d(data + 8);
_pos = Graphics::get_vector3d(data + 8);
_pitch = get_float(data + 20);
_yaw = get_float(data + 24);
_roll = get_float(data + 28);
_dpos = get_vector3d(data + 32);
_dpos = Graphics::get_vector3d(data + 32);
_dpitch = get_float(data + 44);
_dyaw = get_float(data + 48);
_droll = get_float(data + 52);
@ -192,8 +192,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 = flags;
_entries[which]._pos = Vector3d(x, y, z);
_entries[which]._dpos = Vector3d(dx, dy, dz);
_entries[which]._pos = Graphics::Vector3d(x, y, z);
_entries[which]._dpos = Graphics::Vector3d(dx, dy, dz);
_entries[which]._pitch = p;
_entries[which]._yaw = yaw;
_entries[which]._roll = r;
@ -225,7 +225,7 @@ void KeyframeAnim::KeyframeNode::animate(Model::HierNode &node, float frame, int
}
float dt = frame - _entries[low]._frame;
Vector3d pos = _entries[low]._pos + dt * _entries[low]._dpos;
Graphics::Vector3d pos = _entries[low]._pos + dt * _entries[low]._dpos;
float pitch = _entries[low]._pitch + dt * _entries[low]._dpitch;
float yaw = _entries[low]._yaw + dt * _entries[low]._dyaw;
float roll = _entries[low]._roll + dt * _entries[low]._droll;

View file

@ -57,7 +57,7 @@ private:
float _frame;
int _flags;
Vector3d _pos, _dpos;
Graphics::Vector3d _pos, _dpos;
float _pitch, _yaw, _roll, _dpitch, _dyaw, _droll;
};

View file

@ -456,12 +456,12 @@ static void SetActorVisibility() {
static void PutActorAt() {
Actor *act = check_actor(1);
act->setPos(Vector3d(luaL_check_number(2), luaL_check_number(3), luaL_check_number(4)));
act->setPos(Graphics::Vector3d(luaL_check_number(2), luaL_check_number(3), luaL_check_number(4)));
}
static void GetActorPos() {
Actor *act = check_actor(1);
Vector3d pos = act->pos();
Graphics::Vector3d pos = act->pos();
// It is important to process this request for all actors,
// even for actors not within the active scene
lua_pushnumber(pos.x());
@ -504,14 +504,14 @@ static void GetAngleBetweenActors() {
}
static void GetActorYawToPoint() {
Vector3d yawVector;
Graphics::Vector3d yawVector;
Actor *act = check_actor(1);
lua_Object param2 = lua_getparam(2);
// when this gets called by the tube-switcher guy it's sending
// only two things: an actor and a table with components x, y, z
if (lua_isnumber(param2)) {
yawVector = Vector3d(luaL_check_number(2), luaL_check_number(3), luaL_check_number(4));
yawVector = Graphics::Vector3d(luaL_check_number(2), luaL_check_number(3), luaL_check_number(4));
} else if (lua_istable(param2)) {
yawVector = tableToVector(param2);
} else {
@ -571,7 +571,7 @@ static void SetActorReflection() {
static void GetActorPuckVector() {
Actor *act = check_actor(1);
Vector3d result = act->puckVector();
Graphics::Vector3d result = act->puckVector();
lua_pushnumber(result.x());
lua_pushnumber(result.y());
lua_pushnumber(result.z());
@ -579,7 +579,7 @@ static void GetActorPuckVector() {
static void WalkActorTo() {
Actor *act = check_actor(1);
act->walkTo(Vector3d(luaL_check_number(2), luaL_check_number(3), luaL_check_number(4)));
act->walkTo(Graphics::Vector3d(luaL_check_number(2), luaL_check_number(3), luaL_check_number(4)));
}
static void IsActorMoving() {
@ -910,7 +910,7 @@ static void IsActorChoring() {
static void ActorLookAt() {
lua_Object x, y, z, rate;
Vector3d vector;
Graphics::Vector3d vector;
Actor *act;
act = check_actor(1);
@ -999,8 +999,8 @@ static void TurnActorTo() {
}
// Find the vector pointing from the actor to the desired location
Vector3d turnToVector(x, y, z);
Vector3d lookVector = turnToVector - act->pos();
Graphics::Vector3d turnToVector(x, y, z);
Graphics::Vector3d lookVector = turnToVector - act->pos();
// find the angle the requested position is around the unit circle
yaw = lookVector.unitCircleAngle();
// yaw is offset from forward by 90 degrees
@ -1034,12 +1034,12 @@ static void WalkActorVector() {
moveVert = luaL_check_number(4);
// Get the direction the camera is pointing
Vector3d cameraVector = g_grim->currScene()->_currSetup->_interest - g_grim->currScene()->_currSetup->_pos;
Graphics::Vector3d cameraVector = g_grim->currScene()->_currSetup->_interest - g_grim->currScene()->_currSetup->_pos;
// find the angle the camera direction is around the unit circle
float cameraYaw = cameraVector.unitCircleAngle();
// Handle the turning
Vector3d adjustVector(moveHoriz, moveVert, 0);
Graphics::Vector3d adjustVector(moveHoriz, moveVert, 0);
// find the angle the adjust vector is around the unit circle
float adjustYaw = adjustVector.unitCircleAngle();
@ -1070,7 +1070,7 @@ static void RotateVector() {
param1 = lua_getparam(1);
param2 = lua_getparam(2);
if (lua_istable(param1) && lua_istable(param2)) {
Vector3d vec1 = tableToVector(param1);
Graphics::Vector3d vec1 = tableToVector(param1);
lua_Object rotateObject = getTableValue(param2, "y");
float rotate, currAngle, newAngle;
@ -1079,10 +1079,10 @@ static void RotateVector() {
if (rotateObject == 0)
rotateObject = getIndexedTableValue(param2, 2);
rotate = lua_getnumber(rotateObject);
Vector3d baseVector(sin(0.0f), cos(0.0f), 0);
Graphics::Vector3d baseVector(sin(0.0f), cos(0.0f), 0);
currAngle = angle(baseVector, vec1) * (180 / LOCAL_PI);
newAngle = (currAngle - rotate) * (LOCAL_PI / 180);
Vector3d vec2(sin(newAngle), cos(newAngle), 0);
Graphics::Vector3d vec2(sin(newAngle), cos(newAngle), 0);
vec2 *= vec1.magnitude();
result = lua_createtable();
@ -1240,7 +1240,7 @@ static void SetActorShadowPoint() {
float y = luaL_check_number(3);
float z = luaL_check_number(4);
act->setShadowPoint(Vector3d(x, y, z));
act->setShadowPoint(Graphics::Vector3d(x, y, z));
}
static void SetActorShadowPlane() {
@ -1485,7 +1485,7 @@ static void GetPointSector() {
yparam = lua_getparam(2);
zparam = lua_getparam(3);
if (lua_isnumber(xparam) && lua_isnumber(yparam) && lua_isnumber(zparam)) {
Vector3d point(x, y, z);
Graphics::Vector3d point(x, y, z);
// Find the point in any available sector
result = g_grim->currScene()->findPointSector(point, 0xFFFF);
@ -1856,7 +1856,7 @@ static void RestoreIMuse() {
}
static void SetSoundPosition() {
Vector3d pos;
Graphics::Vector3d pos;
int minVolume = 10;
int maxVolume = 127;
@ -3786,7 +3786,7 @@ void setTableValue(lua_Object table, const char *name, lua_Object newvalue) {
/* Obtain the x, y, and z coordinates from a LUA table
* and then create a Vector3d object with these values
*/
Vector3d tableToVector(lua_Object table) {
Graphics::Vector3d tableToVector(lua_Object table) {
lua_Object xparam, yparam, zparam;
float x, y, z;
@ -3802,7 +3802,7 @@ Vector3d tableToVector(lua_Object table) {
x = lua_getnumber(xparam);
y = lua_getnumber(yparam);
z = lua_getnumber(zparam);
return Vector3d(x, y, z);
return Graphics::Vector3d(x, y, z);
}
lua_Object getEventHandler(const char *name) {

View file

@ -28,7 +28,9 @@
#include "engines/grim/lua/lua.h"
class Vector3d;
namespace Graphics {
class Vector3d;
};
namespace Grim {
@ -57,7 +59,7 @@ lua_Object getTableValue(lua_Object table, const char *name);
lua_Object getIndexedTableValue(lua_Object table, int index);
// make a Vector3d object from coordinate table values
Vector3d tableToVector(lua_Object table);
Graphics::Vector3d tableToVector(lua_Object table);
// get a function stored in a table
lua_Object getTableFunction(lua_Object table, const char *name);

View file

@ -74,7 +74,7 @@ void Model::loadBinary(const char *data, const CMap &cmap) {
for (int i = 0; i < _numHierNodes; i++)
_rootHierNode[i].loadBinary(data, _rootHierNode, _geosets[0]);
_radius = get_float(data);
_insertOffset = get_vector3d(data + 40);
_insertOffset = Graphics::get_vector3d(data + 40);
}
Model::~Model() {
@ -160,7 +160,7 @@ int Model::Face::loadBinary(const char *&data, ResPtr<Material> *materials) {
int texPtr = READ_LE_UINT32(data + 28);
int materialPtr = READ_LE_UINT32(data + 32);
_extraLight = get_float(data + 48);
_normal = get_vector3d(data + 64);
_normal = Graphics::get_vector3d(data + 64);
data += 76;
_vertices = new int[_numVertices];
@ -206,8 +206,8 @@ void Model::HierNode::loadBinary(const char *&data, Model::HierNode *hierNodes,
_numChildren = READ_LE_UINT32(data + 88);
int childPtr = READ_LE_UINT32(data + 92);
int siblingPtr = READ_LE_UINT32(data + 96);
_pivot = get_vector3d(data + 100);
_pos = get_vector3d(data + 112);
_pivot = Graphics::get_vector3d(data + 100);
_pos = Graphics::get_vector3d(data + 112);
_pitch = get_float(data + 124);
_yaw = get_float(data + 128);
_roll = get_float(data + 132);
@ -322,11 +322,11 @@ void Model::loadText(TextSplitter &ts, const CMap &cmap) {
_rootHierNode[num]._sibling = NULL;
_rootHierNode[num]._numChildren = numChildren;
_rootHierNode[num]._pos = Vector3d(x, y, z);
_rootHierNode[num]._pos = Graphics::Vector3d(x, y, z);
_rootHierNode[num]._pitch = pitch;
_rootHierNode[num]._yaw = yaw;
_rootHierNode[num]._roll = roll;
_rootHierNode[num]._pivot = Vector3d(pivotx, pivoty, pivotz);
_rootHierNode[num]._pivot = Graphics::Vector3d(pivotx, pivoty, pivotz);
_rootHierNode[num]._meshVisible = true;
_rootHierNode[num]._hierVisible = true;
_rootHierNode[num]._totalWeight = 1;
@ -447,7 +447,7 @@ void Model::Mesh::loadText(TextSplitter &ts, ResPtr<Material> *materials) {
int num;
float x, y, z;
ts.scanString(" %d: %f %f %f", 4, &num, &x, &y, &z);
_faces[num]._normal = Vector3d(x, y, z);
_faces[num]._normal = Graphics::Vector3d(x, y, z);
}
}
@ -473,7 +473,7 @@ void Model::HierNode::removeChild(HierNode *child) {
}
}
void Model::HierNode::setMatrix(Matrix4 matrix) {
void Model::HierNode::setMatrix(Graphics::Matrix4 matrix) {
_matrix = matrix;
}

View file

@ -52,7 +52,7 @@ public:
void draw() const;
void addChild(HierNode *child);
void removeChild(HierNode *child);
void setMatrix(Matrix4 matrix);
void setMatrix(Graphics::Matrix4 matrix);
void update();
char _name[64];
@ -60,16 +60,16 @@ public:
int _flags, _type;
int _depth, _numChildren;
HierNode *_parent, *_child, *_sibling;
Vector3d _pos, _pivot;
Graphics::Vector3d _pos, _pivot;
float _pitch, _yaw, _roll;
Vector3d _animPos;
Graphics::Vector3d _animPos;
float _animPitch, _animYaw, _animRoll;
bool _meshVisible, _hierVisible;
int _priority, _totalWeight;
bool _initialized;
Matrix4 _matrix;
Matrix4 _localMatrix;
Matrix4 _pivotMatrix;
Graphics::Matrix4 _matrix;
Graphics::Matrix4 _localMatrix;
Graphics::Matrix4 _pivotMatrix;
};
HierNode *copyHierarchy();
@ -87,7 +87,7 @@ public:
float _extraLight;
int _numVertices;
int *_vertices, *_texVertices;
Vector3d _normal;
Graphics::Vector3d _normal;
};
struct Mesh {
@ -114,7 +114,7 @@ public:
int _numFaces;
Face *_faces;
Matrix4 _matrix;
Graphics::Matrix4 _matrix;
};
struct Geoset {
@ -131,7 +131,7 @@ public:
int _numMaterials;
char (*_materialNames)[32];
ResPtr<Material> *_materials;
Vector3d _insertOffset;
Graphics::Vector3d _insertOffset;
int _numGeosets;
Geoset *_geosets;
float _radius;

View file

@ -222,7 +222,7 @@ void Scene::drawBitmaps(ObjectState::Position stage) {
}
}
Sector *Scene::findPointSector(Vector3d p, int flags) {
Sector *Scene::findPointSector(Graphics::Vector3d p, int flags) {
for (int i = 0; i < _numSectors; i++) {
Sector *sector = _sectors + i;
if ((sector->type() & flags) && sector->visible() && sector->isPointInSector(p))
@ -231,16 +231,16 @@ Sector *Scene::findPointSector(Vector3d p, int flags) {
return NULL;
}
void Scene::findClosestSector(Vector3d p, Sector **sect, Vector3d *closestPt) {
void Scene::findClosestSector(Graphics::Vector3d p, Sector **sect, Graphics::Vector3d *closestPt) {
Sector *resultSect = NULL;
Vector3d resultPt = p;
Graphics::Vector3d resultPt = p;
float minDist = 0.0;
for (int i = 0; i < _numSectors; i++) {
Sector *sector = _sectors + i;
if ((sector->type() & 0x1000) == 0 || !sector->visible())
continue;
Vector3d closestPt = sector->closestPoint(p);
Graphics::Vector3d closestPt = sector->closestPoint(p);
float thisDist = (closestPt - p).magnitude();
if (!resultSect || thisDist < minDist) {
resultSect = sector;
@ -272,9 +272,9 @@ ObjectState *Scene::findState(const char *filename) {
return NULL;
}
void Scene::setSoundPosition(const char *soundName, Vector3d pos) {
Vector3d cameraPos = _currSetup->_pos;
Vector3d vector, vector2;
void Scene::setSoundPosition(const char *soundName, Graphics::Vector3d pos) {
Graphics::Vector3d cameraPos = _currSetup->_pos;
Graphics::Vector3d vector, vector2;
vector.set(fabs(cameraPos.x() - pos.x()), fabs(cameraPos.y() - pos.y()), fabs(cameraPos.z() - pos.z()));
float distance = vector.magnitude();
float maxDistance = 8.0f;

View file

@ -61,7 +61,7 @@ public:
void setupLights();
void setSoundPosition(const char *soundName, Vector3d pos);
void setSoundPosition(const char *soundName, Graphics::Vector3d pos);
void setSoundParameters(int minVolume, int maxVolume);
void getSoundParameters(int *minVolume, int *maxVolume);
@ -84,8 +84,8 @@ public:
else
return NULL;
}
Sector *findPointSector(Vector3d p, int flags);
void findClosestSector(Vector3d p, Sector **sect, Vector3d *closestPt);
Sector *findPointSector(Graphics::Vector3d p, int flags);
void findClosestSector(Graphics::Vector3d p, Sector **sect, Graphics::Vector3d *closestPt);
void addObjectState(ObjectState *s) {
_states.push_back(s);
@ -105,7 +105,7 @@ public:
void setupCamera() const;
Common::String _name;
ResPtr<Bitmap> _bkgndBm, _bkgndZBm;
Vector3d _pos, _interest;
Graphics::Vector3d _pos, _interest;
float _roll, _fov, _nclip, _fclip;
};
@ -113,7 +113,7 @@ public:
void load(TextSplitter &ts);
Common::String _name;
Common::String _type;
Vector3d _pos, _dir;
Graphics::Vector3d _pos, _dir;
Color _color;
float _intensity, _umbraangle, _penumbraangle;
};

View file

@ -34,7 +34,7 @@ void Sector::load(TextSplitter &ts) {
// float height = 12345.f; // Yaz: this is in the original code...
char buf[256];
int id = 0, i = 0;
Vector3d tempVert;
Graphics::Vector3d tempVert;
// Sector NAMES can be null, but ts isn't flexible enough
if (strlen(ts.currentLine()) > strlen(" sector"))
@ -75,7 +75,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 Vector3d[_numVertices + 1];
_vertices = new Graphics::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++)
@ -94,7 +94,7 @@ void Sector::setVisible(bool visible) {
_visible = visible;
}
bool Sector::isPointInSector(Vector3d point) const {
bool Sector::isPointInSector(Graphics::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'
@ -136,45 +136,45 @@ bool Sector::isPointInSector(Vector3d point) const {
}
for (int i = 0; i < _numVertices; i++) {
Vector3d edge = _vertices[i + 1] - _vertices[i];
Vector3d delta = point - _vertices[i];
Graphics::Vector3d edge = _vertices[i + 1] - _vertices[i];
Graphics::Vector3d delta = point - _vertices[i];
if (edge.x() * delta.y() < edge.y() * delta.x())
return false;
}
return true;
}
Vector3d Sector::projectToPlane(Vector3d point) const {
Graphics::Vector3d Sector::projectToPlane(Graphics::Vector3d point) const {
if (_normal.z() == 0)
error("Trying to walk along vertical plane");
// Formula: return p - (n . (p - v_0))/(n . k) k
Vector3d result = point;
Graphics::Vector3d result = point;
result.z() -= dot(_normal, point - _vertices[0]) / _normal.z();
return result;
}
Vector3d Sector::projectToPuckVector(Vector3d v) const {
Graphics::Vector3d Sector::projectToPuckVector(Graphics::Vector3d v) const {
if (_normal.z() == 0)
error("Trying to walk along vertical plane");
Vector3d result = v;
Graphics::Vector3d result = v;
result.z() -= dot(_normal, v) / _normal.z();
return result;
}
// Find the closest point on the walkplane to the given point
Vector3d Sector::closestPoint(Vector3d point) const {
Graphics::Vector3d Sector::closestPoint(Graphics::Vector3d point) const {
// First try to project to the plane
Vector3d p2 = point;
Graphics::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++) {
Vector3d edge = _vertices[i + 1] - _vertices[i];
Vector3d delta = point - _vertices[i];
Graphics::Vector3d edge = _vertices[i + 1] - _vertices[i];
Graphics::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
@ -196,8 +196,7 @@ Vector3d Sector::closestPoint(Vector3d point) const {
return _vertices[index];
}
void Sector::getExitInfo(Vector3d start, Vector3d dir,
struct ExitInfo *result) {
void Sector::getExitInfo(Graphics::Vector3d start, Graphics::Vector3d dir, struct ExitInfo *result) {
start = projectToPlane(start);
dir = projectToPuckVector(dir);
@ -209,7 +208,7 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
// positive z-component.
int i;
for (i = 0; i < _numVertices; i++) {
Vector3d delta = _vertices[i] - start;
Graphics::Vector3d delta = _vertices[i] - start;
if (delta.x() * dir.y() > delta.y() * dir.x())
break;
}
@ -218,7 +217,7 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
// z-component.
while (i < _numVertices) {
i++;
Vector3d delta = _vertices[i] - start;
Graphics::Vector3d delta = _vertices[i] - start;
if (delta.x() * dir.y() <= delta.y() * dir.x())
break;
}
@ -226,7 +225,7 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
result->edgeDir = _vertices[i] - _vertices[i - 1];
result->angleWithEdge = angle(dir, result->edgeDir);
Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
Graphics::Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) / dot(dir, edgeNormal)) * dir;
}

View file

@ -47,24 +47,24 @@ public:
int id() const { return _id; }
int type() const { return _type; } // FIXME: Implement type de-masking
bool visible() const { return _visible; }
bool isPointInSector(Vector3d point) const;
bool isPointInSector(Graphics::Vector3d point) const;
Vector3d projectToPlane(Vector3d point) const;
Vector3d projectToPuckVector(Vector3d v) const;
Graphics::Vector3d projectToPlane(Graphics::Vector3d point) const;
Graphics::Vector3d projectToPuckVector(Graphics::Vector3d v) const;
Vector3d closestPoint(Vector3d point) const;
Graphics::Vector3d closestPoint(Graphics::Vector3d point) const;
// Interface to trace a ray to its exit from the polygon
struct ExitInfo {
Vector3d exitPoint;
Graphics::Vector3d exitPoint;
float angleWithEdge;
Vector3d edgeDir;
Graphics::Vector3d edgeDir;
};
void getExitInfo(Vector3d start, Vector3d dir, struct ExitInfo *result);
void getExitInfo(Graphics::Vector3d start, Graphics::Vector3d dir, struct ExitInfo *result);
int getNumVertices() { return _numVertices; }
Vector3d *getVertices() { return _vertices; }
Vector3d getNormal() { return _normal; }
Graphics::Vector3d *getVertices() { return _vertices; }
Graphics::Vector3d getNormal() { return _normal; }
private:
int _numVertices, _id;
@ -72,10 +72,10 @@ private:
Common::String _name;
int _type;
bool _visible;
Vector3d *_vertices;
Graphics::Vector3d *_vertices;
float _height;
Vector3d _normal;
Graphics::Vector3d _normal;
};
} // end of namespace Grim

View file

@ -25,6 +25,8 @@
#include "graphics/matrix3.h"
namespace Graphics {
void Matrix3::setAsIdentity() {
_right.set(1.f, 0.f, 0.f);
_up.set(0.f, 1.f, 0.f);
@ -184,3 +186,4 @@ void Matrix3::transform(Vector3d* v) {
v->set(x, y, z);
}
} // end of namespace Graphics

View file

@ -28,6 +28,8 @@
#include "graphics/vector3d.h"
namespace Graphics {
// matrix 3 is a rotation matrix
class Matrix3 {
public:
@ -85,5 +87,7 @@ public:
private:
};
#endif // MATRIX_HH
} // end of namespace Graphics
#endif

View file

@ -25,6 +25,8 @@
#include "graphics/matrix4.h"
namespace Graphics {
Matrix4::Matrix4() {
_pos.set(0.f, 0.f, 0.f);
_rot.setAsIdentity();
@ -38,3 +40,4 @@ void Matrix4::translate(float x, float y, float z) {
_pos += v;
}
} // end of namespace Graphics

View file

@ -28,6 +28,8 @@
#include "graphics/matrix3.h"
namespace Graphics {
// matrix 4 is a rotation matrix + position
class Matrix4 {
public:
@ -59,5 +61,6 @@ public:
private:
};
#endif // MATRIX_HH
} // end of namespace Graphics
#endif

View file

@ -27,6 +27,9 @@
#define ENGINE_VECTOR3D_H
#include "common/sys.h"
#include "common/endian.h"
namespace Graphics {
class Vector3d {
public:
@ -168,28 +171,10 @@ inline bool operator ==(const Vector3d& v1, const Vector3d& v2) {
return v1.x() == v2.x() && v1.y() == v2.y() && v1.z() == v2.z();
}
#if defined(SYSTEM_BIG_ENDIAN)
inline float get_float(const char *data) {
const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
unsigned char fdata[4];
fdata[0] = udata[3];
fdata[1] = udata[2];
fdata[2] = udata[1];
fdata[3] = udata[0];
return *(reinterpret_cast<const float *>(fdata));
}
#else
inline float get_float(const char *data) {
return *(reinterpret_cast<const float *>(data));
}
#endif
inline Vector3d get_vector3d(const char *data) {
return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8));
}
} // end of namespace Graphics
#endif