put Vector3D and Matrix3/4 into Graphics namespace
This commit is contained in:
parent
34d97baaf3
commit
ba0576bc5e
26 changed files with 200 additions and 184 deletions
|
@ -216,5 +216,23 @@ FORCEINLINE uint32 READ_BE_UINT24(const void *ptr) {
|
||||||
return (b[0] << 16) + (b[1] << 8) + (b[2]);
|
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
|
#endif
|
||||||
|
|
|
@ -524,22 +524,6 @@
|
||||||
RelativePath="..\..\engines\grim\material.h"
|
RelativePath="..\..\engines\grim\material.h"
|
||||||
>
|
>
|
||||||
</File>
|
</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
|
<File
|
||||||
RelativePath="..\..\engines\grim\model.cpp"
|
RelativePath="..\..\engines\grim\model.cpp"
|
||||||
>
|
>
|
||||||
|
@ -612,10 +596,6 @@
|
||||||
RelativePath="..\..\engines\grim\textsplit.h"
|
RelativePath="..\..\engines\grim\textsplit.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\engines\grim\vector3d.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\engines\grim\version.cpp"
|
RelativePath="..\..\engines\grim\version.cpp"
|
||||||
>
|
>
|
||||||
|
@ -1065,6 +1045,26 @@
|
||||||
<Filter
|
<Filter
|
||||||
Name="graphics"
|
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
|
<Filter
|
||||||
Name="tinygl"
|
Name="tinygl"
|
||||||
>
|
>
|
||||||
|
|
|
@ -102,7 +102,7 @@ void Actor::turnTo(float pitch, float yaw, float roll) {
|
||||||
_turning = false;
|
_turning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::walkTo(Vector3d p) {
|
void Actor::walkTo(Graphics::Vector3d p) {
|
||||||
// For now, this is just the ignoring-boxes version (which afaict
|
// For now, this is just the ignoring-boxes version (which afaict
|
||||||
// isn't even in the original). This will eventually need a
|
// isn't even in the original). This will eventually need a
|
||||||
// following-boxes version also.
|
// following-boxes version also.
|
||||||
|
@ -135,10 +135,9 @@ void Actor::walkForward() {
|
||||||
float dist = g_grim->perSecond(_walkRate);
|
float dist = g_grim->perSecond(_walkRate);
|
||||||
float yaw_rad = _yaw * (LOCAL_PI / 180), pitch_rad = _pitch * (LOCAL_PI / 180);
|
float yaw_rad = _yaw * (LOCAL_PI / 180), pitch_rad = _pitch * (LOCAL_PI / 180);
|
||||||
//float yaw;
|
//float yaw;
|
||||||
Vector3d forwardVec(-sin(yaw_rad) * cos(pitch_rad),
|
Graphics::Vector3d forwardVec(-sin(yaw_rad) * cos(pitch_rad),
|
||||||
cos(yaw_rad) * cos(pitch_rad),
|
cos(yaw_rad) * cos(pitch_rad), sin(pitch_rad));
|
||||||
sin(pitch_rad));
|
Graphics::Vector3d destPos = _pos + forwardVec * dist;
|
||||||
Vector3d destPos = _pos + forwardVec * dist;
|
|
||||||
|
|
||||||
if (! _constrain) {
|
if (! _constrain) {
|
||||||
_pos += forwardVec * dist;
|
_pos += forwardVec * dist;
|
||||||
|
@ -163,7 +162,7 @@ void Actor::walkForward() {
|
||||||
|
|
||||||
while (currSector) {
|
while (currSector) {
|
||||||
prevSector = currSector;
|
prevSector = currSector;
|
||||||
Vector3d puckVector = currSector->projectToPuckVector(forwardVec);
|
Graphics::Vector3d puckVector = currSector->projectToPuckVector(forwardVec);
|
||||||
puckVector /= puckVector.magnitude();
|
puckVector /= puckVector.magnitude();
|
||||||
currSector->getExitInfo(_pos, puckVector, &ei);
|
currSector->getExitInfo(_pos, puckVector, &ei);
|
||||||
float exitDist = (ei.exitPoint - _pos).magnitude();
|
float exitDist = (ei.exitPoint - _pos).magnitude();
|
||||||
|
@ -201,9 +200,9 @@ void Actor::walkForward() {
|
||||||
setYaw(_yaw + turnAmt * turnDir);
|
setYaw(_yaw + turnAmt * turnDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3d Actor::puckVector() const {
|
Graphics::Vector3d Actor::puckVector() const {
|
||||||
float yaw_rad = _yaw * (LOCAL_PI / 180);
|
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);
|
Sector *sector = g_grim->currScene()->findPointSector(_pos, 0x1000);
|
||||||
if (!sector)
|
if (!sector)
|
||||||
|
@ -287,15 +286,15 @@ void Actor::turn(int dir) {
|
||||||
|
|
||||||
float Actor::angleTo(const Actor &a) const {
|
float Actor::angleTo(const Actor &a) const {
|
||||||
float yaw_rad = _yaw * (LOCAL_PI / 180);
|
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);
|
||||||
Vector3d delta = a.pos() - _pos;
|
Graphics::Vector3d delta = a.pos() - _pos;
|
||||||
delta.z() = 0;
|
delta.z() = 0;
|
||||||
|
|
||||||
return angle(forwardVec, delta) * (180 / LOCAL_PI);
|
return angle(forwardVec, delta) * (180 / LOCAL_PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Actor::yawTo(Vector3d p) const {
|
float Actor::yawTo(Graphics::Vector3d p) const {
|
||||||
Vector3d dpos = p - _pos;
|
Graphics::Vector3d dpos = p - _pos;
|
||||||
|
|
||||||
if (dpos.x() == 0 && dpos.y() == 0)
|
if (dpos.x() == 0 && dpos.y() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -518,7 +517,7 @@ void Actor::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_walking) {
|
if (_walking) {
|
||||||
Vector3d dir = _destPos - _pos;
|
Graphics::Vector3d dir = _destPos - _pos;
|
||||||
float dist = dir.magnitude();
|
float dist = dir.magnitude();
|
||||||
|
|
||||||
if (dist > 0)
|
if (dist > 0)
|
||||||
|
@ -713,7 +712,7 @@ void Actor::setActivateShadow(int shadowId, bool state) {
|
||||||
_shadowArray[shadowId].active = state;
|
_shadowArray[shadowId].active = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::setShadowPoint(Vector3d pos) {
|
void Actor::setShadowPoint(Graphics::Vector3d pos) {
|
||||||
assert(_activeShadowSlot != -1);
|
assert(_activeShadowSlot != -1);
|
||||||
|
|
||||||
_shadowArray[_activeShadowSlot].pos = pos;
|
_shadowArray[_activeShadowSlot].pos = pos;
|
||||||
|
|
|
@ -41,7 +41,7 @@ extern int g_winX1, g_winY1, g_winX2, g_winY2;
|
||||||
|
|
||||||
struct Shadow {
|
struct Shadow {
|
||||||
Common::String name;
|
Common::String name;
|
||||||
Vector3d pos;
|
Graphics::Vector3d pos;
|
||||||
SectorListType planeList;
|
SectorListType planeList;
|
||||||
byte *shadowMask;
|
byte *shadowMask;
|
||||||
bool active;
|
bool active;
|
||||||
|
@ -57,17 +57,17 @@ public:
|
||||||
|
|
||||||
void setTalkColor(const Color& c) { _talkColor = c; }
|
void setTalkColor(const Color& c) { _talkColor = c; }
|
||||||
Color talkColor() const { return _talkColor; }
|
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
|
// When the actor is walking report where the actor is going to and
|
||||||
// not the actual current position, this fixes some scene change
|
// not the actual current position, this fixes some scene change
|
||||||
// change issues with the Bone Wagon (along with other fixes)
|
// change issues with the Bone Wagon (along with other fixes)
|
||||||
Vector3d pos() const {
|
Graphics::Vector3d pos() const {
|
||||||
if (_walking)
|
if (_walking)
|
||||||
return _destPos;
|
return _destPos;
|
||||||
else
|
else
|
||||||
return _pos;
|
return _pos;
|
||||||
}
|
}
|
||||||
void walkTo(Vector3d p);
|
void walkTo(Graphics::Vector3d p);
|
||||||
void stopWalking() { _walking = false; }
|
void stopWalking() { _walking = false; }
|
||||||
bool isWalking() const;
|
bool isWalking() const;
|
||||||
void setRot(float pitch, float yaw, float roll);
|
void setRot(float pitch, float yaw, float roll);
|
||||||
|
@ -88,14 +88,14 @@ public:
|
||||||
void setLooking(bool lookingMode) { _lookingMode = lookingMode; }
|
void setLooking(bool lookingMode) { _lookingMode = lookingMode; }
|
||||||
|
|
||||||
float angleTo(const Actor &a) const;
|
float angleTo(const Actor &a) const;
|
||||||
float yawTo(Vector3d p) const;
|
float yawTo(Graphics::Vector3d p) const;
|
||||||
|
|
||||||
bool inSet(const char *name) const {
|
bool inSet(const char *name) const {
|
||||||
return _setName == name;
|
return _setName == name;
|
||||||
}
|
}
|
||||||
void walkForward();
|
void walkForward();
|
||||||
void setReflection(float angle) { _reflectionAngle = angle; }
|
void setReflection(float angle) { _reflectionAngle = angle; }
|
||||||
Vector3d puckVector() const;
|
Graphics::Vector3d puckVector() const;
|
||||||
void turn(int dir);
|
void turn(int dir);
|
||||||
|
|
||||||
void sayLine(const char *msg, const char *msgId);
|
void sayLine(const char *msg, const char *msgId);
|
||||||
|
@ -128,7 +128,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void setActiveShadow(int shadowId);
|
void setActiveShadow(int shadowId);
|
||||||
void setShadowPoint(Vector3d pos);
|
void setShadowPoint(Graphics::Vector3d pos);
|
||||||
void setShadowPlane(const char *name);
|
void setShadowPlane(const char *name);
|
||||||
void addShadowPlane(const char *name);
|
void addShadowPlane(const char *name);
|
||||||
void clearShadowPlanes();
|
void clearShadowPlanes();
|
||||||
|
@ -148,7 +148,7 @@ public:
|
||||||
void setLookAtVectorZero() {
|
void setLookAtVectorZero() {
|
||||||
_lookAtVector.set(0.f, 0.f, 0.f);
|
_lookAtVector.set(0.f, 0.f, 0.f);
|
||||||
}
|
}
|
||||||
void setLookAtVector(Vector3d vector) {
|
void setLookAtVector(Graphics::Vector3d vector) {
|
||||||
_lookAtVector = vector;
|
_lookAtVector = vector;
|
||||||
}
|
}
|
||||||
void setLookAtRate(float rate) {
|
void setLookAtRate(float rate) {
|
||||||
|
@ -163,7 +163,7 @@ private:
|
||||||
Common::String _name;
|
Common::String _name;
|
||||||
Common::String _setName; // The actual current set
|
Common::String _setName; // The actual current set
|
||||||
Color _talkColor;
|
Color _talkColor;
|
||||||
Vector3d _pos;
|
Graphics::Vector3d _pos;
|
||||||
float _pitch, _yaw, _roll;
|
float _pitch, _yaw, _roll;
|
||||||
float _walkRate, _turnRate;
|
float _walkRate, _turnRate;
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ private:
|
||||||
|
|
||||||
// Variables for walking to a point
|
// Variables for walking to a point
|
||||||
bool _walking;
|
bool _walking;
|
||||||
Vector3d _destPos;
|
Graphics::Vector3d _destPos;
|
||||||
|
|
||||||
// chores
|
// chores
|
||||||
Costume *_restCostume;
|
Costume *_restCostume;
|
||||||
|
@ -223,7 +223,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookAt
|
// lookAt
|
||||||
Vector3d _lookAtVector;
|
Graphics::Vector3d _lookAtVector;
|
||||||
float _lookAtRate;
|
float _lookAtRate;
|
||||||
|
|
||||||
int _winX1, _winY1, _winX2, _winY2;
|
int _winX1, _winY1, _winX2, _winY2;
|
||||||
|
|
|
@ -120,7 +120,7 @@ public:
|
||||||
void update();
|
void update();
|
||||||
void reset();
|
void reset();
|
||||||
void resetColormap();
|
void resetColormap();
|
||||||
void setMatrix(Matrix4 matrix) { _matrix = matrix; };
|
void setMatrix(Graphics::Matrix4 matrix) { _matrix = matrix; };
|
||||||
~ModelComponent();
|
~ModelComponent();
|
||||||
|
|
||||||
Model::HierNode *hierarchy() { return _hier; }
|
Model::HierNode *hierarchy() { return _hier; }
|
||||||
|
@ -130,7 +130,7 @@ protected:
|
||||||
Common::String _filename;
|
Common::String _filename;
|
||||||
ResPtr<Model> _obj;
|
ResPtr<Model> _obj;
|
||||||
Model::HierNode *_hier;
|
Model::HierNode *_hier;
|
||||||
Matrix4 _matrix;
|
Graphics::Matrix4 _matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainModelComponent : public ModelComponent {
|
class MainModelComponent : public ModelComponent {
|
||||||
|
@ -161,7 +161,7 @@ public:
|
||||||
void reset();
|
void reset();
|
||||||
~MeshComponent() { }
|
~MeshComponent() { }
|
||||||
|
|
||||||
void setMatrix(Matrix4 matrix) { _matrix = matrix; };
|
void setMatrix(Graphics::Matrix4 matrix) { _matrix = matrix; };
|
||||||
|
|
||||||
Model::HierNode *node() { return _node; }
|
Model::HierNode *node() { return _node; }
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ private:
|
||||||
Common::String _name;
|
Common::String _name;
|
||||||
int _num;
|
int _num;
|
||||||
Model::HierNode *_node;
|
Model::HierNode *_node;
|
||||||
Matrix4 _matrix;
|
Graphics::Matrix4 _matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
BitmapComponent::BitmapComponent(Costume::Component *parent, int parentID, const char *filename, tag32 tag) :
|
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
|
// then it will just use the existing handle
|
||||||
g_imuse->startSfx(_soundName.c_str());
|
g_imuse->startSfx(_soundName.c_str());
|
||||||
if (g_grim->currScene() && g_currentUpdatedActor) {
|
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);
|
g_grim->currScene()->setSoundPosition(_soundName.c_str(), pos);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1016,7 +1016,7 @@ void Costume::setHead(int joint1, int joint2, int joint3, float maxRoll, float m
|
||||||
_head.maxYaw = maxYaw;
|
_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._pos = pos;
|
||||||
_matrix._rot.buildFromPitchYawRoll(pitch, yaw, roll);
|
_matrix._rot.buildFromPitchYawRoll(pitch, yaw, roll);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
void update();
|
void update();
|
||||||
void setupTextures();
|
void setupTextures();
|
||||||
void draw();
|
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 {
|
class Component {
|
||||||
public:
|
public:
|
||||||
|
@ -69,7 +69,7 @@ public:
|
||||||
void setColormap(CMap *c);
|
void setColormap(CMap *c);
|
||||||
bool visible();
|
bool visible();
|
||||||
Component *parent() { return _parent; }
|
Component *parent() { return _parent; }
|
||||||
virtual void setMatrix(Matrix4) { };
|
virtual void setMatrix(Graphics::Matrix4) { };
|
||||||
virtual void init() { }
|
virtual void init() { }
|
||||||
virtual void setKey(int) { }
|
virtual void setKey(int) { }
|
||||||
virtual void setMapName(char *) { }
|
virtual void setMapName(char *) { }
|
||||||
|
@ -85,7 +85,7 @@ public:
|
||||||
int _parentID;
|
int _parentID;
|
||||||
bool _visible;
|
bool _visible;
|
||||||
Component *_parent, *_child, *_sibling;
|
Component *_parent, *_child, *_sibling;
|
||||||
Matrix4 _matrix;
|
Graphics::Matrix4 _matrix;
|
||||||
Costume *_cost;
|
Costume *_cost;
|
||||||
void setCostume(Costume *cost) { _cost = cost; }
|
void setCostume(Costume *cost) { _cost = cost; }
|
||||||
void setParent(Component *newParent);
|
void setParent(Component *newParent);
|
||||||
|
@ -150,7 +150,7 @@ private:
|
||||||
ResPtr<CMap> _cmap;
|
ResPtr<CMap> _cmap;
|
||||||
int _numChores;
|
int _numChores;
|
||||||
Chore *_chores;
|
Chore *_chores;
|
||||||
Matrix4 _matrix;
|
Graphics::Matrix4 _matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Grim
|
} // end of namespace Grim
|
||||||
|
|
|
@ -53,13 +53,13 @@ public:
|
||||||
virtual bool isHardwareAccelerated() = 0;
|
virtual bool isHardwareAccelerated() = 0;
|
||||||
|
|
||||||
virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 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 clearScreen() = 0;
|
||||||
virtual void flipBuffer() = 0;
|
virtual void flipBuffer() = 0;
|
||||||
|
|
||||||
virtual void getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, int *x2, int *y2) = 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 finishActorDraw() = 0;
|
||||||
virtual void setShadow(Shadow *shadow) = 0;
|
virtual void setShadow(Shadow *shadow) = 0;
|
||||||
virtual void drawShadowPlanes() = 0;
|
virtual void drawShadowPlanes() = 0;
|
||||||
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
virtual void set3DMode() = 0;
|
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 translateViewpoint() = 0;
|
||||||
|
|
||||||
virtual void drawHierachyNode(const Model::HierNode *node) = 0;
|
virtual void drawHierachyNode(const Model::HierNode *node) = 0;
|
||||||
|
|
|
@ -93,11 +93,11 @@ void GfxOpenGL::setupCamera(float fov, float nclip, float fclip, float roll) {
|
||||||
glRotatef(roll, 0, 0, -1);
|
glRotatef(roll, 0, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxOpenGL::positionCamera(Vector3d pos, Vector3d interest) {
|
void GfxOpenGL::positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) {
|
||||||
Vector3d up_vec(0, 0, 1);
|
Graphics::Vector3d up_vec(0, 0, 1);
|
||||||
|
|
||||||
if (pos.x() == interest.x() && pos.y() == interest.y())
|
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());
|
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;
|
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
|
// Based on GPL shadow projection example by
|
||||||
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
|
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
|
||||||
float d, c;
|
float d, c;
|
||||||
|
@ -179,7 +179,7 @@ void GfxOpenGL::getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, in
|
||||||
GLdouble winX, winY, winZ;
|
GLdouble winX, winY, winZ;
|
||||||
|
|
||||||
for (int i = 0; i < model->_numFaces; i++) {
|
for (int i = 0; i < model->_numFaces; i++) {
|
||||||
Vector3d v;
|
Graphics::Vector3d v;
|
||||||
float* pVertices;
|
float* pVertices;
|
||||||
|
|
||||||
for (int j = 0; j < model->_faces[i]._numVertices; j++) {
|
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;
|
*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);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -343,7 +343,7 @@ void GfxOpenGL::drawModelFace(const Model::Face *face, float *vertices, float *v
|
||||||
glDisable(GL_ALPHA_TEST);
|
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);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
const char *getVideoDeviceName();
|
const char *getVideoDeviceName();
|
||||||
|
|
||||||
void setupCamera(float fov, float nclip, float fclip, float roll);
|
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 clearScreen();
|
||||||
void flipBuffer();
|
void flipBuffer();
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
|
|
||||||
void getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, int *x2, int *y2);
|
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 finishActorDraw();
|
||||||
void setShadow(Shadow *shadow);
|
void setShadow(Shadow *shadow);
|
||||||
void drawShadowPlanes();
|
void drawShadowPlanes();
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
|
|
||||||
void set3DMode();
|
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 translateViewpoint();
|
||||||
|
|
||||||
void drawHierachyNode(const Model::HierNode *node);
|
void drawHierachyNode(const Model::HierNode *node);
|
||||||
|
|
|
@ -188,11 +188,11 @@ void GfxTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
|
||||||
tglRotatef(roll, 0, 0, -1);
|
tglRotatef(roll, 0, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxTinyGL::positionCamera(Vector3d pos, Vector3d interest) {
|
void GfxTinyGL::positionCamera(Graphics::Vector3d pos, Graphics::Vector3d interest) {
|
||||||
Vector3d up_vec(0, 0, 1);
|
Graphics::Vector3d up_vec(0, 0, 1);
|
||||||
|
|
||||||
if (pos.x() == interest.x() && pos.y() == interest.y())
|
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());
|
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;
|
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
|
// Based on GPL shadow projection example by
|
||||||
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
|
// (c) 2002-2003 Phaetos <phaetos@gaffga.de>
|
||||||
float d, c;
|
float d, c;
|
||||||
|
@ -276,7 +276,7 @@ void GfxTinyGL::getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, in
|
||||||
TGLfloat winX, winY, winZ;
|
TGLfloat winX, winY, winZ;
|
||||||
|
|
||||||
for (int i = 0; i < model->_numFaces; i++) {
|
for (int i = 0; i < model->_numFaces; i++) {
|
||||||
Vector3d v;
|
Graphics::Vector3d v;
|
||||||
float* pVertices;
|
float* pVertices;
|
||||||
|
|
||||||
for (int j = 0; j < model->_faces[i]._numVertices; j++) {
|
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);
|
tglEnable(TGL_TEXTURE_2D);
|
||||||
tglMatrixMode(TGL_MODELVIEW);
|
tglMatrixMode(TGL_MODELVIEW);
|
||||||
tglPushMatrix();
|
tglPushMatrix();
|
||||||
|
@ -453,7 +453,7 @@ void GfxTinyGL::drawModelFace(const Model::Face *face, float *vertices, float *v
|
||||||
tglEnd();
|
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();
|
tglPushMatrix();
|
||||||
|
|
||||||
tglTranslatef(pos.x(), pos.y(), pos.z());
|
tglTranslatef(pos.x(), pos.y(), pos.z());
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
const char *getVideoDeviceName();
|
const char *getVideoDeviceName();
|
||||||
|
|
||||||
void setupCamera(float fov, float nclip, float fclip, float roll);
|
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 clearScreen();
|
||||||
void flipBuffer();
|
void flipBuffer();
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
void getBoundingBoxPos(const Model::Mesh *model, int *x1, int *y1, int *x2, int *y2);
|
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 finishActorDraw();
|
||||||
void setShadow(Shadow *shadow);
|
void setShadow(Shadow *shadow);
|
||||||
void drawShadowPlanes();
|
void drawShadowPlanes();
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
void set3DMode();
|
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 translateViewpoint();
|
||||||
|
|
||||||
void drawHierachyNode(const Model::HierNode *node);
|
void drawHierachyNode(const Model::HierNode *node);
|
||||||
|
|
|
@ -156,11 +156,11 @@ void KeyframeAnim::animate(Model::HierNode *nodes, float time, int priority1, in
|
||||||
void KeyframeAnim::KeyframeEntry::loadBinary(const char *&data) {
|
void KeyframeAnim::KeyframeEntry::loadBinary(const char *&data) {
|
||||||
_frame = get_float(data);
|
_frame = get_float(data);
|
||||||
_flags = READ_LE_UINT32(data + 4);
|
_flags = READ_LE_UINT32(data + 4);
|
||||||
_pos = get_vector3d(data + 8);
|
_pos = Graphics::get_vector3d(data + 8);
|
||||||
_pitch = get_float(data + 20);
|
_pitch = get_float(data + 20);
|
||||||
_yaw = get_float(data + 24);
|
_yaw = get_float(data + 24);
|
||||||
_roll = get_float(data + 28);
|
_roll = get_float(data + 28);
|
||||||
_dpos = get_vector3d(data + 32);
|
_dpos = Graphics::get_vector3d(data + 32);
|
||||||
_dpitch = get_float(data + 44);
|
_dpitch = get_float(data + 44);
|
||||||
_dyaw = get_float(data + 48);
|
_dyaw = get_float(data + 48);
|
||||||
_droll = get_float(data + 52);
|
_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);
|
ts.scanString(" %f %f %f %f %f %f", 6, &dx, &dy, &dz, &dp, &dyaw, &dr);
|
||||||
_entries[which]._frame = frame;
|
_entries[which]._frame = frame;
|
||||||
_entries[which]._flags = flags;
|
_entries[which]._flags = flags;
|
||||||
_entries[which]._pos = Vector3d(x, y, z);
|
_entries[which]._pos = Graphics::Vector3d(x, y, z);
|
||||||
_entries[which]._dpos = Vector3d(dx, dy, dz);
|
_entries[which]._dpos = Graphics::Vector3d(dx, dy, dz);
|
||||||
_entries[which]._pitch = p;
|
_entries[which]._pitch = p;
|
||||||
_entries[which]._yaw = yaw;
|
_entries[which]._yaw = yaw;
|
||||||
_entries[which]._roll = r;
|
_entries[which]._roll = r;
|
||||||
|
@ -225,7 +225,7 @@ void KeyframeAnim::KeyframeNode::animate(Model::HierNode &node, float frame, int
|
||||||
}
|
}
|
||||||
|
|
||||||
float dt = frame - _entries[low]._frame;
|
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 pitch = _entries[low]._pitch + dt * _entries[low]._dpitch;
|
||||||
float yaw = _entries[low]._yaw + dt * _entries[low]._dyaw;
|
float yaw = _entries[low]._yaw + dt * _entries[low]._dyaw;
|
||||||
float roll = _entries[low]._roll + dt * _entries[low]._droll;
|
float roll = _entries[low]._roll + dt * _entries[low]._droll;
|
||||||
|
|
|
@ -57,7 +57,7 @@ private:
|
||||||
|
|
||||||
float _frame;
|
float _frame;
|
||||||
int _flags;
|
int _flags;
|
||||||
Vector3d _pos, _dpos;
|
Graphics::Vector3d _pos, _dpos;
|
||||||
float _pitch, _yaw, _roll, _dpitch, _dyaw, _droll;
|
float _pitch, _yaw, _roll, _dpitch, _dyaw, _droll;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -456,12 +456,12 @@ static void SetActorVisibility() {
|
||||||
|
|
||||||
static void PutActorAt() {
|
static void PutActorAt() {
|
||||||
Actor *act = check_actor(1);
|
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() {
|
static void GetActorPos() {
|
||||||
Actor *act = check_actor(1);
|
Actor *act = check_actor(1);
|
||||||
Vector3d pos = act->pos();
|
Graphics::Vector3d pos = act->pos();
|
||||||
// It is important to process this request for all actors,
|
// It is important to process this request for all actors,
|
||||||
// even for actors not within the active scene
|
// even for actors not within the active scene
|
||||||
lua_pushnumber(pos.x());
|
lua_pushnumber(pos.x());
|
||||||
|
@ -504,14 +504,14 @@ static void GetAngleBetweenActors() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetActorYawToPoint() {
|
static void GetActorYawToPoint() {
|
||||||
Vector3d yawVector;
|
Graphics::Vector3d yawVector;
|
||||||
|
|
||||||
Actor *act = check_actor(1);
|
Actor *act = check_actor(1);
|
||||||
lua_Object param2 = lua_getparam(2);
|
lua_Object param2 = lua_getparam(2);
|
||||||
// when this gets called by the tube-switcher guy it's sending
|
// 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
|
// only two things: an actor and a table with components x, y, z
|
||||||
if (lua_isnumber(param2)) {
|
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)) {
|
} else if (lua_istable(param2)) {
|
||||||
yawVector = tableToVector(param2);
|
yawVector = tableToVector(param2);
|
||||||
} else {
|
} else {
|
||||||
|
@ -571,7 +571,7 @@ static void SetActorReflection() {
|
||||||
|
|
||||||
static void GetActorPuckVector() {
|
static void GetActorPuckVector() {
|
||||||
Actor *act = check_actor(1);
|
Actor *act = check_actor(1);
|
||||||
Vector3d result = act->puckVector();
|
Graphics::Vector3d result = act->puckVector();
|
||||||
lua_pushnumber(result.x());
|
lua_pushnumber(result.x());
|
||||||
lua_pushnumber(result.y());
|
lua_pushnumber(result.y());
|
||||||
lua_pushnumber(result.z());
|
lua_pushnumber(result.z());
|
||||||
|
@ -579,7 +579,7 @@ static void GetActorPuckVector() {
|
||||||
|
|
||||||
static void WalkActorTo() {
|
static void WalkActorTo() {
|
||||||
Actor *act = check_actor(1);
|
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() {
|
static void IsActorMoving() {
|
||||||
|
@ -910,7 +910,7 @@ static void IsActorChoring() {
|
||||||
|
|
||||||
static void ActorLookAt() {
|
static void ActorLookAt() {
|
||||||
lua_Object x, y, z, rate;
|
lua_Object x, y, z, rate;
|
||||||
Vector3d vector;
|
Graphics::Vector3d vector;
|
||||||
Actor *act;
|
Actor *act;
|
||||||
|
|
||||||
act = check_actor(1);
|
act = check_actor(1);
|
||||||
|
@ -999,8 +999,8 @@ static void TurnActorTo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the vector pointing from the actor to the desired location
|
// Find the vector pointing from the actor to the desired location
|
||||||
Vector3d turnToVector(x, y, z);
|
Graphics::Vector3d turnToVector(x, y, z);
|
||||||
Vector3d lookVector = turnToVector - act->pos();
|
Graphics::Vector3d lookVector = turnToVector - act->pos();
|
||||||
// find the angle the requested position is around the unit circle
|
// find the angle the requested position is around the unit circle
|
||||||
yaw = lookVector.unitCircleAngle();
|
yaw = lookVector.unitCircleAngle();
|
||||||
// yaw is offset from forward by 90 degrees
|
// yaw is offset from forward by 90 degrees
|
||||||
|
@ -1034,12 +1034,12 @@ static void WalkActorVector() {
|
||||||
moveVert = luaL_check_number(4);
|
moveVert = luaL_check_number(4);
|
||||||
|
|
||||||
// Get the direction the camera is pointing
|
// 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
|
// find the angle the camera direction is around the unit circle
|
||||||
float cameraYaw = cameraVector.unitCircleAngle();
|
float cameraYaw = cameraVector.unitCircleAngle();
|
||||||
|
|
||||||
// Handle the turning
|
// 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
|
// find the angle the adjust vector is around the unit circle
|
||||||
float adjustYaw = adjustVector.unitCircleAngle();
|
float adjustYaw = adjustVector.unitCircleAngle();
|
||||||
|
|
||||||
|
@ -1070,7 +1070,7 @@ static void RotateVector() {
|
||||||
param1 = lua_getparam(1);
|
param1 = lua_getparam(1);
|
||||||
param2 = lua_getparam(2);
|
param2 = lua_getparam(2);
|
||||||
if (lua_istable(param1) && lua_istable(param2)) {
|
if (lua_istable(param1) && lua_istable(param2)) {
|
||||||
Vector3d vec1 = tableToVector(param1);
|
Graphics::Vector3d vec1 = tableToVector(param1);
|
||||||
lua_Object rotateObject = getTableValue(param2, "y");
|
lua_Object rotateObject = getTableValue(param2, "y");
|
||||||
float rotate, currAngle, newAngle;
|
float rotate, currAngle, newAngle;
|
||||||
|
|
||||||
|
@ -1079,10 +1079,10 @@ static void RotateVector() {
|
||||||
if (rotateObject == 0)
|
if (rotateObject == 0)
|
||||||
rotateObject = getIndexedTableValue(param2, 2);
|
rotateObject = getIndexedTableValue(param2, 2);
|
||||||
rotate = lua_getnumber(rotateObject);
|
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);
|
currAngle = angle(baseVector, vec1) * (180 / LOCAL_PI);
|
||||||
newAngle = (currAngle - rotate) * (LOCAL_PI / 180);
|
newAngle = (currAngle - rotate) * (LOCAL_PI / 180);
|
||||||
Vector3d vec2(sin(newAngle), cos(newAngle), 0);
|
Graphics::Vector3d vec2(sin(newAngle), cos(newAngle), 0);
|
||||||
vec2 *= vec1.magnitude();
|
vec2 *= vec1.magnitude();
|
||||||
|
|
||||||
result = lua_createtable();
|
result = lua_createtable();
|
||||||
|
@ -1240,7 +1240,7 @@ static void SetActorShadowPoint() {
|
||||||
float y = luaL_check_number(3);
|
float y = luaL_check_number(3);
|
||||||
float z = luaL_check_number(4);
|
float z = luaL_check_number(4);
|
||||||
|
|
||||||
act->setShadowPoint(Vector3d(x, y, z));
|
act->setShadowPoint(Graphics::Vector3d(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetActorShadowPlane() {
|
static void SetActorShadowPlane() {
|
||||||
|
@ -1485,7 +1485,7 @@ static void GetPointSector() {
|
||||||
yparam = lua_getparam(2);
|
yparam = lua_getparam(2);
|
||||||
zparam = lua_getparam(3);
|
zparam = lua_getparam(3);
|
||||||
if (lua_isnumber(xparam) && lua_isnumber(yparam) && lua_isnumber(zparam)) {
|
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
|
// Find the point in any available sector
|
||||||
result = g_grim->currScene()->findPointSector(point, 0xFFFF);
|
result = g_grim->currScene()->findPointSector(point, 0xFFFF);
|
||||||
|
@ -1856,7 +1856,7 @@ static void RestoreIMuse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetSoundPosition() {
|
static void SetSoundPosition() {
|
||||||
Vector3d pos;
|
Graphics::Vector3d pos;
|
||||||
int minVolume = 10;
|
int minVolume = 10;
|
||||||
int maxVolume = 127;
|
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
|
/* Obtain the x, y, and z coordinates from a LUA table
|
||||||
* and then create a Vector3d object with these values
|
* 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;
|
lua_Object xparam, yparam, zparam;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
|
@ -3802,7 +3802,7 @@ Vector3d tableToVector(lua_Object table) {
|
||||||
x = lua_getnumber(xparam);
|
x = lua_getnumber(xparam);
|
||||||
y = lua_getnumber(yparam);
|
y = lua_getnumber(yparam);
|
||||||
z = lua_getnumber(zparam);
|
z = lua_getnumber(zparam);
|
||||||
return Vector3d(x, y, z);
|
return Graphics::Vector3d(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_Object getEventHandler(const char *name) {
|
lua_Object getEventHandler(const char *name) {
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
|
|
||||||
#include "engines/grim/lua/lua.h"
|
#include "engines/grim/lua/lua.h"
|
||||||
|
|
||||||
class Vector3d;
|
namespace Graphics {
|
||||||
|
class Vector3d;
|
||||||
|
};
|
||||||
|
|
||||||
namespace Grim {
|
namespace Grim {
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ lua_Object getTableValue(lua_Object table, const char *name);
|
||||||
lua_Object getIndexedTableValue(lua_Object table, int index);
|
lua_Object getIndexedTableValue(lua_Object table, int index);
|
||||||
|
|
||||||
// make a Vector3d object from coordinate table values
|
// 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
|
// get a function stored in a table
|
||||||
lua_Object getTableFunction(lua_Object table, const char *name);
|
lua_Object getTableFunction(lua_Object table, const char *name);
|
||||||
|
|
|
@ -74,7 +74,7 @@ void Model::loadBinary(const char *data, const CMap &cmap) {
|
||||||
for (int i = 0; i < _numHierNodes; i++)
|
for (int i = 0; i < _numHierNodes; i++)
|
||||||
_rootHierNode[i].loadBinary(data, _rootHierNode, _geosets[0]);
|
_rootHierNode[i].loadBinary(data, _rootHierNode, _geosets[0]);
|
||||||
_radius = get_float(data);
|
_radius = get_float(data);
|
||||||
_insertOffset = get_vector3d(data + 40);
|
_insertOffset = Graphics::get_vector3d(data + 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
Model::~Model() {
|
Model::~Model() {
|
||||||
|
@ -160,7 +160,7 @@ int Model::Face::loadBinary(const char *&data, ResPtr<Material> *materials) {
|
||||||
int texPtr = READ_LE_UINT32(data + 28);
|
int texPtr = READ_LE_UINT32(data + 28);
|
||||||
int materialPtr = READ_LE_UINT32(data + 32);
|
int materialPtr = READ_LE_UINT32(data + 32);
|
||||||
_extraLight = get_float(data + 48);
|
_extraLight = get_float(data + 48);
|
||||||
_normal = get_vector3d(data + 64);
|
_normal = Graphics::get_vector3d(data + 64);
|
||||||
data += 76;
|
data += 76;
|
||||||
|
|
||||||
_vertices = new int[_numVertices];
|
_vertices = new int[_numVertices];
|
||||||
|
@ -206,8 +206,8 @@ void Model::HierNode::loadBinary(const char *&data, Model::HierNode *hierNodes,
|
||||||
_numChildren = READ_LE_UINT32(data + 88);
|
_numChildren = READ_LE_UINT32(data + 88);
|
||||||
int childPtr = READ_LE_UINT32(data + 92);
|
int childPtr = READ_LE_UINT32(data + 92);
|
||||||
int siblingPtr = READ_LE_UINT32(data + 96);
|
int siblingPtr = READ_LE_UINT32(data + 96);
|
||||||
_pivot = get_vector3d(data + 100);
|
_pivot = Graphics::get_vector3d(data + 100);
|
||||||
_pos = get_vector3d(data + 112);
|
_pos = Graphics::get_vector3d(data + 112);
|
||||||
_pitch = get_float(data + 124);
|
_pitch = get_float(data + 124);
|
||||||
_yaw = get_float(data + 128);
|
_yaw = get_float(data + 128);
|
||||||
_roll = get_float(data + 132);
|
_roll = get_float(data + 132);
|
||||||
|
@ -322,11 +322,11 @@ void Model::loadText(TextSplitter &ts, const CMap &cmap) {
|
||||||
_rootHierNode[num]._sibling = NULL;
|
_rootHierNode[num]._sibling = NULL;
|
||||||
|
|
||||||
_rootHierNode[num]._numChildren = numChildren;
|
_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]._pitch = pitch;
|
||||||
_rootHierNode[num]._yaw = yaw;
|
_rootHierNode[num]._yaw = yaw;
|
||||||
_rootHierNode[num]._roll = roll;
|
_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]._meshVisible = true;
|
||||||
_rootHierNode[num]._hierVisible = true;
|
_rootHierNode[num]._hierVisible = true;
|
||||||
_rootHierNode[num]._totalWeight = 1;
|
_rootHierNode[num]._totalWeight = 1;
|
||||||
|
@ -447,7 +447,7 @@ void Model::Mesh::loadText(TextSplitter &ts, ResPtr<Material> *materials) {
|
||||||
int num;
|
int num;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
ts.scanString(" %d: %f %f %f", 4, &num, &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;
|
_matrix = matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
void draw() const;
|
void draw() const;
|
||||||
void addChild(HierNode *child);
|
void addChild(HierNode *child);
|
||||||
void removeChild(HierNode *child);
|
void removeChild(HierNode *child);
|
||||||
void setMatrix(Matrix4 matrix);
|
void setMatrix(Graphics::Matrix4 matrix);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
char _name[64];
|
char _name[64];
|
||||||
|
@ -60,16 +60,16 @@ public:
|
||||||
int _flags, _type;
|
int _flags, _type;
|
||||||
int _depth, _numChildren;
|
int _depth, _numChildren;
|
||||||
HierNode *_parent, *_child, *_sibling;
|
HierNode *_parent, *_child, *_sibling;
|
||||||
Vector3d _pos, _pivot;
|
Graphics::Vector3d _pos, _pivot;
|
||||||
float _pitch, _yaw, _roll;
|
float _pitch, _yaw, _roll;
|
||||||
Vector3d _animPos;
|
Graphics::Vector3d _animPos;
|
||||||
float _animPitch, _animYaw, _animRoll;
|
float _animPitch, _animYaw, _animRoll;
|
||||||
bool _meshVisible, _hierVisible;
|
bool _meshVisible, _hierVisible;
|
||||||
int _priority, _totalWeight;
|
int _priority, _totalWeight;
|
||||||
bool _initialized;
|
bool _initialized;
|
||||||
Matrix4 _matrix;
|
Graphics::Matrix4 _matrix;
|
||||||
Matrix4 _localMatrix;
|
Graphics::Matrix4 _localMatrix;
|
||||||
Matrix4 _pivotMatrix;
|
Graphics::Matrix4 _pivotMatrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
HierNode *copyHierarchy();
|
HierNode *copyHierarchy();
|
||||||
|
@ -87,7 +87,7 @@ public:
|
||||||
float _extraLight;
|
float _extraLight;
|
||||||
int _numVertices;
|
int _numVertices;
|
||||||
int *_vertices, *_texVertices;
|
int *_vertices, *_texVertices;
|
||||||
Vector3d _normal;
|
Graphics::Vector3d _normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mesh {
|
struct Mesh {
|
||||||
|
@ -114,7 +114,7 @@ public:
|
||||||
|
|
||||||
int _numFaces;
|
int _numFaces;
|
||||||
Face *_faces;
|
Face *_faces;
|
||||||
Matrix4 _matrix;
|
Graphics::Matrix4 _matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Geoset {
|
struct Geoset {
|
||||||
|
@ -131,7 +131,7 @@ public:
|
||||||
int _numMaterials;
|
int _numMaterials;
|
||||||
char (*_materialNames)[32];
|
char (*_materialNames)[32];
|
||||||
ResPtr<Material> *_materials;
|
ResPtr<Material> *_materials;
|
||||||
Vector3d _insertOffset;
|
Graphics::Vector3d _insertOffset;
|
||||||
int _numGeosets;
|
int _numGeosets;
|
||||||
Geoset *_geosets;
|
Geoset *_geosets;
|
||||||
float _radius;
|
float _radius;
|
||||||
|
|
|
@ -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++) {
|
for (int i = 0; i < _numSectors; i++) {
|
||||||
Sector *sector = _sectors + i;
|
Sector *sector = _sectors + i;
|
||||||
if ((sector->type() & flags) && sector->visible() && sector->isPointInSector(p))
|
if ((sector->type() & flags) && sector->visible() && sector->isPointInSector(p))
|
||||||
|
@ -231,16 +231,16 @@ Sector *Scene::findPointSector(Vector3d p, int flags) {
|
||||||
return NULL;
|
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;
|
Sector *resultSect = NULL;
|
||||||
Vector3d resultPt = p;
|
Graphics::Vector3d resultPt = p;
|
||||||
float minDist = 0.0;
|
float minDist = 0.0;
|
||||||
|
|
||||||
for (int i = 0; i < _numSectors; i++) {
|
for (int i = 0; i < _numSectors; i++) {
|
||||||
Sector *sector = _sectors + i;
|
Sector *sector = _sectors + i;
|
||||||
if ((sector->type() & 0x1000) == 0 || !sector->visible())
|
if ((sector->type() & 0x1000) == 0 || !sector->visible())
|
||||||
continue;
|
continue;
|
||||||
Vector3d closestPt = sector->closestPoint(p);
|
Graphics::Vector3d closestPt = sector->closestPoint(p);
|
||||||
float thisDist = (closestPt - p).magnitude();
|
float thisDist = (closestPt - p).magnitude();
|
||||||
if (!resultSect || thisDist < minDist) {
|
if (!resultSect || thisDist < minDist) {
|
||||||
resultSect = sector;
|
resultSect = sector;
|
||||||
|
@ -272,9 +272,9 @@ ObjectState *Scene::findState(const char *filename) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::setSoundPosition(const char *soundName, Vector3d pos) {
|
void Scene::setSoundPosition(const char *soundName, Graphics::Vector3d pos) {
|
||||||
Vector3d cameraPos = _currSetup->_pos;
|
Graphics::Vector3d cameraPos = _currSetup->_pos;
|
||||||
Vector3d vector, vector2;
|
Graphics::Vector3d vector, vector2;
|
||||||
vector.set(fabs(cameraPos.x() - pos.x()), fabs(cameraPos.y() - pos.y()), fabs(cameraPos.z() - pos.z()));
|
vector.set(fabs(cameraPos.x() - pos.x()), fabs(cameraPos.y() - pos.y()), fabs(cameraPos.z() - pos.z()));
|
||||||
float distance = vector.magnitude();
|
float distance = vector.magnitude();
|
||||||
float maxDistance = 8.0f;
|
float maxDistance = 8.0f;
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
void setupLights();
|
void setupLights();
|
||||||
|
|
||||||
void setSoundPosition(const char *soundName, Vector3d pos);
|
void setSoundPosition(const char *soundName, Graphics::Vector3d pos);
|
||||||
void setSoundParameters(int minVolume, int maxVolume);
|
void setSoundParameters(int minVolume, int maxVolume);
|
||||||
void getSoundParameters(int *minVolume, int *maxVolume);
|
void getSoundParameters(int *minVolume, int *maxVolume);
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ public:
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Sector *findPointSector(Vector3d p, int flags);
|
Sector *findPointSector(Graphics::Vector3d p, int flags);
|
||||||
void findClosestSector(Vector3d p, Sector **sect, Vector3d *closestPt);
|
void findClosestSector(Graphics::Vector3d p, Sector **sect, Graphics::Vector3d *closestPt);
|
||||||
|
|
||||||
void addObjectState(ObjectState *s) {
|
void addObjectState(ObjectState *s) {
|
||||||
_states.push_back(s);
|
_states.push_back(s);
|
||||||
|
@ -105,7 +105,7 @@ public:
|
||||||
void setupCamera() const;
|
void setupCamera() const;
|
||||||
Common::String _name;
|
Common::String _name;
|
||||||
ResPtr<Bitmap> _bkgndBm, _bkgndZBm;
|
ResPtr<Bitmap> _bkgndBm, _bkgndZBm;
|
||||||
Vector3d _pos, _interest;
|
Graphics::Vector3d _pos, _interest;
|
||||||
float _roll, _fov, _nclip, _fclip;
|
float _roll, _fov, _nclip, _fclip;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public:
|
||||||
void load(TextSplitter &ts);
|
void load(TextSplitter &ts);
|
||||||
Common::String _name;
|
Common::String _name;
|
||||||
Common::String _type;
|
Common::String _type;
|
||||||
Vector3d _pos, _dir;
|
Graphics::Vector3d _pos, _dir;
|
||||||
Color _color;
|
Color _color;
|
||||||
float _intensity, _umbraangle, _penumbraangle;
|
float _intensity, _umbraangle, _penumbraangle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,7 +34,7 @@ void Sector::load(TextSplitter &ts) {
|
||||||
// float height = 12345.f; // Yaz: this is in the original code...
|
// float height = 12345.f; // Yaz: this is in the original code...
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int id = 0, i = 0;
|
int id = 0, i = 0;
|
||||||
Vector3d tempVert;
|
Graphics::Vector3d tempVert;
|
||||||
|
|
||||||
// Sector NAMES can be null, but ts isn't flexible enough
|
// Sector NAMES can be null, but ts isn't flexible enough
|
||||||
if (strlen(ts.currentLine()) > strlen(" sector"))
|
if (strlen(ts.currentLine()) > strlen(" sector"))
|
||||||
|
@ -75,7 +75,7 @@ void Sector::load(TextSplitter &ts) {
|
||||||
error("Invalid visibility spec: %s", buf);
|
error("Invalid visibility spec: %s", buf);
|
||||||
ts.scanString(" height %f", 1, &_height);
|
ts.scanString(" height %f", 1, &_height);
|
||||||
ts.scanString(" numvertices %d", 1, &_numVertices);
|
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());
|
ts.scanString(" vertices: %f %f %f", 3, &_vertices[0].x(), &_vertices[0].y(), &_vertices[0].z());
|
||||||
for (i = 1; i < _numVertices; i++)
|
for (i = 1; i < _numVertices; i++)
|
||||||
|
@ -94,7 +94,7 @@ void Sector::setVisible(bool visible) {
|
||||||
_visible = 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
|
// 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
|
// 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'
|
// 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++) {
|
for (int i = 0; i < _numVertices; i++) {
|
||||||
Vector3d edge = _vertices[i + 1] - _vertices[i];
|
Graphics::Vector3d edge = _vertices[i + 1] - _vertices[i];
|
||||||
Vector3d delta = point - _vertices[i];
|
Graphics::Vector3d delta = point - _vertices[i];
|
||||||
if (edge.x() * delta.y() < edge.y() * delta.x())
|
if (edge.x() * delta.y() < edge.y() * delta.x())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3d Sector::projectToPlane(Vector3d point) const {
|
Graphics::Vector3d Sector::projectToPlane(Graphics::Vector3d point) const {
|
||||||
if (_normal.z() == 0)
|
if (_normal.z() == 0)
|
||||||
error("Trying to walk along vertical plane");
|
error("Trying to walk along vertical plane");
|
||||||
|
|
||||||
// Formula: return p - (n . (p - v_0))/(n . k) k
|
// 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();
|
result.z() -= dot(_normal, point - _vertices[0]) / _normal.z();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3d Sector::projectToPuckVector(Vector3d v) const {
|
Graphics::Vector3d Sector::projectToPuckVector(Graphics::Vector3d v) const {
|
||||||
if (_normal.z() == 0)
|
if (_normal.z() == 0)
|
||||||
error("Trying to walk along vertical plane");
|
error("Trying to walk along vertical plane");
|
||||||
|
|
||||||
Vector3d result = v;
|
Graphics::Vector3d result = v;
|
||||||
result.z() -= dot(_normal, v) / _normal.z();
|
result.z() -= dot(_normal, v) / _normal.z();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the closest point on the walkplane to the given point
|
// 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
|
// First try to project to the plane
|
||||||
Vector3d p2 = point;
|
Graphics::Vector3d p2 = point;
|
||||||
p2 -= (dot(_normal, p2 - _vertices[0])) * _normal;
|
p2 -= (dot(_normal, p2 - _vertices[0])) * _normal;
|
||||||
if (isPointInSector(p2))
|
if (isPointInSector(p2))
|
||||||
return p2;
|
return p2;
|
||||||
|
|
||||||
// Now try to project to some edge
|
// Now try to project to some edge
|
||||||
for (int i = 0; i < _numVertices; i++) {
|
for (int i = 0; i < _numVertices; i++) {
|
||||||
Vector3d edge = _vertices[i + 1] - _vertices[i];
|
Graphics::Vector3d edge = _vertices[i + 1] - _vertices[i];
|
||||||
Vector3d delta = point - _vertices[i];
|
Graphics::Vector3d delta = point - _vertices[i];
|
||||||
float scalar = dot(delta, edge) / dot(edge, edge);
|
float scalar = dot(delta, edge) / dot(edge, edge);
|
||||||
if (scalar >= 0 && scalar <= 1 && delta.x() * edge.y() > delta.y() * edge.x())
|
if (scalar >= 0 && scalar <= 1 && delta.x() * edge.y() > delta.y() * edge.x())
|
||||||
// That last test is just whether the z-component
|
// That last test is just whether the z-component
|
||||||
|
@ -196,8 +196,7 @@ Vector3d Sector::closestPoint(Vector3d point) const {
|
||||||
return _vertices[index];
|
return _vertices[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sector::getExitInfo(Vector3d start, Vector3d dir,
|
void Sector::getExitInfo(Graphics::Vector3d start, Graphics::Vector3d dir, struct ExitInfo *result) {
|
||||||
struct ExitInfo *result) {
|
|
||||||
start = projectToPlane(start);
|
start = projectToPlane(start);
|
||||||
dir = projectToPuckVector(dir);
|
dir = projectToPuckVector(dir);
|
||||||
|
|
||||||
|
@ -209,7 +208,7 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
|
||||||
// positive z-component.
|
// positive z-component.
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < _numVertices; 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())
|
if (delta.x() * dir.y() > delta.y() * dir.x())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +217,7 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
|
||||||
// z-component.
|
// z-component.
|
||||||
while (i < _numVertices) {
|
while (i < _numVertices) {
|
||||||
i++;
|
i++;
|
||||||
Vector3d delta = _vertices[i] - start;
|
Graphics::Vector3d delta = _vertices[i] - start;
|
||||||
if (delta.x() * dir.y() <= delta.y() * dir.x())
|
if (delta.x() * dir.y() <= delta.y() * dir.x())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +225,7 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
|
||||||
result->edgeDir = _vertices[i] - _vertices[i - 1];
|
result->edgeDir = _vertices[i] - _vertices[i - 1];
|
||||||
result->angleWithEdge = angle(dir, result->edgeDir);
|
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;
|
result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) / dot(dir, edgeNormal)) * dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,24 +47,24 @@ public:
|
||||||
int id() const { return _id; }
|
int id() const { return _id; }
|
||||||
int type() const { return _type; } // FIXME: Implement type de-masking
|
int type() const { return _type; } // FIXME: Implement type de-masking
|
||||||
bool visible() const { return _visible; }
|
bool visible() const { return _visible; }
|
||||||
bool isPointInSector(Vector3d point) const;
|
bool isPointInSector(Graphics::Vector3d point) const;
|
||||||
|
|
||||||
Vector3d projectToPlane(Vector3d point) const;
|
Graphics::Vector3d projectToPlane(Graphics::Vector3d point) const;
|
||||||
Vector3d projectToPuckVector(Vector3d v) 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
|
// Interface to trace a ray to its exit from the polygon
|
||||||
struct ExitInfo {
|
struct ExitInfo {
|
||||||
Vector3d exitPoint;
|
Graphics::Vector3d exitPoint;
|
||||||
float angleWithEdge;
|
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; }
|
int getNumVertices() { return _numVertices; }
|
||||||
Vector3d *getVertices() { return _vertices; }
|
Graphics::Vector3d *getVertices() { return _vertices; }
|
||||||
Vector3d getNormal() { return _normal; }
|
Graphics::Vector3d getNormal() { return _normal; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _numVertices, _id;
|
int _numVertices, _id;
|
||||||
|
@ -72,10 +72,10 @@ private:
|
||||||
Common::String _name;
|
Common::String _name;
|
||||||
int _type;
|
int _type;
|
||||||
bool _visible;
|
bool _visible;
|
||||||
Vector3d *_vertices;
|
Graphics::Vector3d *_vertices;
|
||||||
float _height;
|
float _height;
|
||||||
|
|
||||||
Vector3d _normal;
|
Graphics::Vector3d _normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Grim
|
} // end of namespace Grim
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
#include "graphics/matrix3.h"
|
#include "graphics/matrix3.h"
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
void Matrix3::setAsIdentity() {
|
void Matrix3::setAsIdentity() {
|
||||||
_right.set(1.f, 0.f, 0.f);
|
_right.set(1.f, 0.f, 0.f);
|
||||||
_up.set(0.f, 1.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);
|
v->set(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // end of namespace Graphics
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
#include "graphics/vector3d.h"
|
#include "graphics/vector3d.h"
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
// matrix 3 is a rotation matrix
|
// matrix 3 is a rotation matrix
|
||||||
class Matrix3 {
|
class Matrix3 {
|
||||||
public:
|
public:
|
||||||
|
@ -85,5 +87,7 @@ public:
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MATRIX_HH
|
} // end of namespace Graphics
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
#include "graphics/matrix4.h"
|
#include "graphics/matrix4.h"
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
Matrix4::Matrix4() {
|
Matrix4::Matrix4() {
|
||||||
_pos.set(0.f, 0.f, 0.f);
|
_pos.set(0.f, 0.f, 0.f);
|
||||||
_rot.setAsIdentity();
|
_rot.setAsIdentity();
|
||||||
|
@ -38,3 +40,4 @@ void Matrix4::translate(float x, float y, float z) {
|
||||||
_pos += v;
|
_pos += v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // end of namespace Graphics
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
#include "graphics/matrix3.h"
|
#include "graphics/matrix3.h"
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
// matrix 4 is a rotation matrix + position
|
// matrix 4 is a rotation matrix + position
|
||||||
class Matrix4 {
|
class Matrix4 {
|
||||||
public:
|
public:
|
||||||
|
@ -59,5 +61,6 @@ public:
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MATRIX_HH
|
} // end of namespace Graphics
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
#define ENGINE_VECTOR3D_H
|
#define ENGINE_VECTOR3D_H
|
||||||
|
|
||||||
#include "common/sys.h"
|
#include "common/sys.h"
|
||||||
|
#include "common/endian.h"
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
class Vector3d {
|
class Vector3d {
|
||||||
public:
|
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();
|
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) {
|
inline Vector3d get_vector3d(const char *data) {
|
||||||
return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8));
|
return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // end of namespace Graphics
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue