EMI: Gfx::startActorDraw() accepts a quaternion

This commit is contained in:
Dries Harnie 2012-07-07 20:33:33 +02:00
parent 932b64fda8
commit 6334cc0290
9 changed files with 30 additions and 38 deletions

View File

@ -1279,6 +1279,14 @@ bool Actor::updateTalk(uint frameTime) {
return false;
}
Math::Quaternion Actor::getRotationQuat() const {
if (g_grim->getGameType() == GType_MONKEY4) {
return Math::Quaternion::fromEuler(_yaw, _pitch, _roll);
} else {
return Math::Quaternion::fromEuler(_pitch, _roll, -_yaw);
}
}
void Actor::draw() {
for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) {
Costume *c = *i;
@ -1297,6 +1305,7 @@ void Actor::draw() {
// FIXME: if isAttached(), factor in the joint & actor rotation as well.
Math::Vector3d absPos = getWorldPos();
const Math::Quaternion rot = getRotationQuat();
if (!_costumeStack.empty()) {
g_grim->getCurrSet()->setupLights(absPos);
@ -1308,7 +1317,7 @@ void Actor::draw() {
g_driver->setShadowMode();
if (g_driver->isHardwareAccelerated())
g_driver->drawShadowPlanes();
g_driver->startActorDraw(absPos, _scale, _yaw, _pitch, _roll, _inOverworld, _alphaMode != AlphaOff ? _globalAlpha : 1.f);
g_driver->startActorDraw(absPos, _scale, rot, _inOverworld, _alphaMode != AlphaOff ? _globalAlpha : 1.f);
costume->draw();
g_driver->finishActorDraw();
g_driver->clearShadowMode();
@ -1318,7 +1327,7 @@ void Actor::draw() {
bool isShadowCostume = costume->getFilename().equals("fx/dumbshadow.cos");
if (!isShadowCostume || (isShadowCostume && _costumeStack.size() > 1 && _shadowActive)) {
// normal draw actor
g_driver->startActorDraw(absPos, _scale, _yaw, _pitch, _roll, _inOverworld, _alphaMode != AlphaOff ? _globalAlpha : 1.f);
g_driver->startActorDraw(absPos, _scale, rot, _inOverworld, _alphaMode != AlphaOff ? _globalAlpha : 1.f);
costume->draw();
g_driver->finishActorDraw();
}
@ -1329,7 +1338,7 @@ void Actor::draw() {
x1 = y1 = 1000;
x2 = y2 = -1000;
if (!_costumeStack.empty()) {
g_driver->startActorDraw(absPos, _scale, _yaw, _pitch, _roll, _inOverworld, 1.f);
g_driver->startActorDraw(absPos, _scale, rot, _inOverworld, 1.f);
_costumeStack.back()->getBoundingBox(&x1, &y1, &x2, &y2);
g_driver->finishActorDraw();
}

View File

@ -28,6 +28,7 @@
#include "engines/grim/color.h"
#include "math/vector3d.h"
#include "math/angle.h"
#include "math/quat.h"
namespace Grim {
@ -469,6 +470,7 @@ public:
Math::Vector3d getWorldPos() const;
void attachToActor(Actor *other, const char *joint);
void detach();
Math::Quaternion getRotationQuat() const;
void setInOverworld(bool inOverworld) { _inOverworld = inOverworld; }
bool isInOverworld() { return _inOverworld; }

View File

@ -113,9 +113,8 @@ public:
virtual void flipBuffer() = 0;
virtual void getBoundingBoxPos(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) = 0;
virtual void startActorDraw(const Math::Vector3d &pos, float scale, const Math::Angle &yaw,
const Math::Angle &pitch, const Math::Angle &roll, const bool inOverworld,
const float alpha) = 0;
virtual void startActorDraw(const Math::Vector3d &pos, float scale, const Math::Quaternion &quat,
const bool inOverworld, const float alpha) = 0;
virtual void finishActorDraw() = 0;
virtual void setShadow(Shadow *shadow) = 0;

View File

@ -371,9 +371,8 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
*y2 = (int)bottom;
}
void GfxOpenGL::startActorDraw(const Math::Vector3d &pos, float scale, const Math::Angle &yaw,
const Math::Angle &pitch, const Math::Angle &roll, const bool inOverworld,
const float alpha) {
void GfxOpenGL::startActorDraw(const Math::Vector3d &pos, float scale, const Math::Quaternion &quat,
const bool inOverworld, const float alpha) {
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@ -421,14 +420,7 @@ void GfxOpenGL::startActorDraw(const Math::Vector3d &pos, float scale, const Mat
glMultMatrixf(worldRot.getData());
glScalef(scale, scale, scale);
if (g_grim->getGameType() == GType_MONKEY4) {
Math::Matrix4 charRot = Math::Quaternion::fromEuler(yaw, pitch, roll).toMatrix();
glMultMatrixf(charRot.getData());
} else {
glRotatef(yaw.getDegrees(), 0, 0, 1);
glRotatef(pitch.getDegrees(), 1, 0, 0);
glRotatef(roll.getDegrees(), 0, 1, 0);
}
glMultMatrixf(quat.toMatrix().getData());
}
}

View File

@ -61,9 +61,8 @@ public:
void getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, int *y2);
void startActorDraw(const Math::Vector3d &pos, float scale, const Math::Angle &yaw,
const Math::Angle &pitch, const Math::Angle &roll, const bool inOverworld,
const float alpha);
void startActorDraw(const Math::Vector3d &pos, float scale, const Math::Quaternion &quat,
const bool inOverworld, const float alpha);
void finishActorDraw();
void setShadow(Shadow *shadow);
void drawShadowPlanes();

View File

@ -465,9 +465,8 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
}*/
}
void GfxTinyGL::startActorDraw(const Math::Vector3d &pos, float scale, const Math::Angle &yaw,
const Math::Angle &pitch, const Math::Angle &roll, const bool inOverworld,
const float alpha) {
void GfxTinyGL::startActorDraw(const Math::Vector3d &pos, float scale, const Math::Quaternion &quat,
const bool inOverworld, const float alpha) {
tglEnable(TGL_TEXTURE_2D);
tglMatrixMode(TGL_PROJECTION);
tglPushMatrix();
@ -514,14 +513,7 @@ void GfxTinyGL::startActorDraw(const Math::Vector3d &pos, float scale, const Mat
tglMultMatrixf(worldRot.getData());
tglScalef(scale, scale, scale);
if (g_grim->getGameType() == GType_MONKEY4) {
Math::Matrix4 charRot = Math::Quaternion::fromEuler(yaw, pitch, roll).toMatrix();
tglMultMatrixf(charRot.getData());
} else {
tglRotatef(yaw.getDegrees(), 0, 0, 1);
tglRotatef(pitch.getDegrees(), 1, 0, 0);
tglRotatef(roll.getDegrees(), 0, 1, 0);
}
tglMultMatrixf(quat.toMatrix().getData());
}
}

View File

@ -53,9 +53,8 @@ public:
void getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2, int *y2);
void startActorDraw(const Math::Vector3d &pos, float scale, const Math::Angle &yaw,
const Math::Angle &pitch, const Math::Angle &roll, const bool inOverworld,
const float alpha);
void startActorDraw(const Math::Vector3d &pos, float scale, const Math::Quaternion &quat,
const bool inOverworld, const float alpha);
void finishActorDraw();
void setShadow(Shadow *shadow);
void drawShadowPlanes();

View File

@ -73,7 +73,7 @@ Quaternion Quaternion::slerpQuat(const Quaternion& to, const float t) {
return dst;
}
void Quaternion::toMatrix(Matrix4 &dst) {
void Quaternion::toMatrix(Matrix4 &dst) const {
float two_xx = x() * (x() + x());
float two_xy = x() * (y() + y());
float two_xz = x() * (z() + z());
@ -96,7 +96,7 @@ void Quaternion::toMatrix(Matrix4 &dst) {
dst.setData(newMat);
}
Matrix4 Quaternion::toMatrix() {
Matrix4 Quaternion::toMatrix() const {
Matrix4 dst;
toMatrix(dst);
return dst;

View File

@ -50,8 +50,8 @@ public:
Quaternion(const Quaternion &q) : Vector4d(q.x(), q.y(), q.z(), q.w()) {}
Quaternion(const Vector4d &vec) : Vector4d(vec.x(), vec.y(), vec.z(), vec.w()) {}
Matrix4 toMatrix();
void toMatrix(Matrix4 &dst);
Matrix4 toMatrix() const;
void toMatrix(Matrix4 &dst) const;
/**
* Slerps between this quaternion and to by factor t
* @param to the quaternion to slerp between