MYST3: Implement opcode 163 - Set camera FOV
This commit is contained in:
parent
52f33cac75
commit
b9fa7eeffa
8 changed files with 31 additions and 12 deletions
|
@ -152,8 +152,7 @@ void Cursor::draw() {
|
||||||
|
|
||||||
void Cursor::setVisible(bool show) {
|
void Cursor::setVisible(bool show) {
|
||||||
if (show)
|
if (show)
|
||||||
if (--_hideLevel < 0)
|
_hideLevel = MAX<int32>(0, --_hideLevel);
|
||||||
_hideLevel = 0;
|
|
||||||
else
|
else
|
||||||
_hideLevel++;
|
_hideLevel++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,11 +152,18 @@ void Renderer::setupCameraOrtho2D() {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::setupCameraPerspective(float pitch, float heading) {
|
void Renderer::setupCameraPerspective(float pitch, float heading, float fov) {
|
||||||
|
// TODO: Find a correct and exact formula for the FOV
|
||||||
|
GLfloat glFOV = 0.63 * fov; // Approximative and experimental formula
|
||||||
|
if (fov > 79.0 && fov < 81.0)
|
||||||
|
glFOV = 50.5; // Somewhat good value for fov == 80
|
||||||
|
else if (fov > 59.0 && fov < 61.0)
|
||||||
|
glFOV = 36.0; // Somewhat good value for fov == 60
|
||||||
|
|
||||||
glViewport(0, kBottomBorderHeight, kOriginalWidth, kFrameHeight);
|
glViewport(0, kBottomBorderHeight, kOriginalWidth, kFrameHeight);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(50.5, (GLfloat)kOriginalWidth / (GLfloat)kFrameHeight, 1.0, 10000.0);
|
gluPerspective(glFOV, (GLfloat)kOriginalWidth / (GLfloat)kFrameHeight, 1.0, 10000.0);
|
||||||
|
|
||||||
// Rotate the model to simulate the rotation of the camera
|
// Rotate the model to simulate the rotation of the camera
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void setupCameraOrtho2D();
|
void setupCameraOrtho2D();
|
||||||
void setupCameraPerspective(float pitch, float heading);
|
void setupCameraPerspective(float pitch, float heading, float fov);
|
||||||
|
|
||||||
Texture *createTexture(const Graphics::Surface *surface);
|
Texture *createTexture(const Graphics::Surface *surface);
|
||||||
void freeTexture(Texture *texture);
|
void freeTexture(Texture *texture);
|
||||||
|
|
|
@ -359,7 +359,8 @@ void Myst3Engine::drawFrame() {
|
||||||
if (_state->getViewType() == kCube) {
|
if (_state->getViewType() == kCube) {
|
||||||
float pitch = _state->getLookAtPitch();
|
float pitch = _state->getLookAtPitch();
|
||||||
float heading = _state->getLookAtHeading();
|
float heading = _state->getLookAtHeading();
|
||||||
_gfx->setupCameraPerspective(pitch, heading);
|
float fov = _state->getLookAtFOV();
|
||||||
|
_gfx->setupCameraPerspective(pitch, heading, fov);
|
||||||
} else {
|
} else {
|
||||||
_gfx->setupCameraOrtho2D();
|
_gfx->setupCameraOrtho2D();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,6 @@ void Scene::updateCamera(Common::Point &mouse) {
|
||||||
heading += mouse.x / 3.0f;
|
heading += mouse.x / 3.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep heading in 0..360 range
|
|
||||||
if (heading > 360.0f)
|
|
||||||
heading -= 360.0f;
|
|
||||||
else if (heading < 0.0f)
|
|
||||||
heading += 360.0f;
|
|
||||||
|
|
||||||
// Keep heading within allowed values
|
// Keep heading within allowed values
|
||||||
if (_vm->_state->isCameraLimited()) {
|
if (_vm->_state->isCameraLimited()) {
|
||||||
float minHeading = _vm->_state->getMinHeading();
|
float minHeading = _vm->_state->getMinHeading();
|
||||||
|
@ -68,6 +62,12 @@ void Scene::updateCamera(Common::Point &mouse) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep heading in 0..360 range
|
||||||
|
if (heading > 360.0f)
|
||||||
|
heading -= 360.0f;
|
||||||
|
else if (heading < 0.0f)
|
||||||
|
heading += 360.0f;
|
||||||
|
|
||||||
// Keep pitch within allowed values
|
// Keep pitch within allowed values
|
||||||
float minPitch = _vm->_state->getCameraMinPitch();
|
float minPitch = _vm->_state->getCameraMinPitch();
|
||||||
float maxPitch = _vm->_state->getCameraMaxPitch();
|
float maxPitch = _vm->_state->getCameraMaxPitch();
|
||||||
|
|
|
@ -188,6 +188,7 @@ Script::Script(Myst3Engine *vm):
|
||||||
OP_1(160, cameraLookAtVar, kVar );
|
OP_1(160, cameraLookAtVar, kVar );
|
||||||
OP_1(161, cameraGetLookAt, kVar );
|
OP_1(161, cameraGetLookAt, kVar );
|
||||||
OP_1(162, lootAtMovieStartImmediate, kEvalValue );
|
OP_1(162, lootAtMovieStartImmediate, kEvalValue );
|
||||||
|
OP_1(163, cameraSetFOV, kEvalValue );
|
||||||
OP_1(164, changeNode, kValue );
|
OP_1(164, changeNode, kValue );
|
||||||
OP_2(165, changeNodeRoom, kValue, kValue );
|
OP_2(165, changeNodeRoom, kValue, kValue );
|
||||||
OP_3(166, changeNodeRoomAge, kValue, kValue, kValue );
|
OP_3(166, changeNodeRoomAge, kValue, kValue, kValue );
|
||||||
|
@ -1835,6 +1836,14 @@ void Script::lootAtMovieStartImmediate(Context &c, const Opcode &cmd) {
|
||||||
_vm->_state->lookAt(startPitch, startHeading);
|
_vm->_state->lookAt(startPitch, startHeading);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Script::cameraSetFOV(Context &c, const Opcode &cmd) {
|
||||||
|
debugC(kDebugScript, "Opcode %d: Set camera fov %d", cmd.op, cmd.args[0]);
|
||||||
|
|
||||||
|
int32 fov = _vm->_state->valueOrVarValue(cmd.args[0]);
|
||||||
|
|
||||||
|
_vm->_state->setLookAtFOV(fov);
|
||||||
|
}
|
||||||
|
|
||||||
void Script::changeNode(Context &c, const Opcode &cmd) {
|
void Script::changeNode(Context &c, const Opcode &cmd) {
|
||||||
debugC(kDebugScript, "Opcode %d: Go to node %d", cmd.op, cmd.args[0]);
|
debugC(kDebugScript, "Opcode %d: Go to node %d", cmd.op, cmd.args[0]);
|
||||||
|
|
||||||
|
|
|
@ -238,6 +238,7 @@ private:
|
||||||
DECLARE_OPCODE(cameraLookAtVar);
|
DECLARE_OPCODE(cameraLookAtVar);
|
||||||
DECLARE_OPCODE(cameraGetLookAt);
|
DECLARE_OPCODE(cameraGetLookAt);
|
||||||
DECLARE_OPCODE(lootAtMovieStartImmediate);
|
DECLARE_OPCODE(lootAtMovieStartImmediate);
|
||||||
|
DECLARE_OPCODE(cameraSetFOV);
|
||||||
DECLARE_OPCODE(changeNode);
|
DECLARE_OPCODE(changeNode);
|
||||||
DECLARE_OPCODE(changeNodeRoom);
|
DECLARE_OPCODE(changeNodeRoom);
|
||||||
DECLARE_OPCODE(changeNodeRoomAge);
|
DECLARE_OPCODE(changeNodeRoomAge);
|
||||||
|
|
|
@ -166,6 +166,8 @@ public:
|
||||||
ViewType getViewType() { return static_cast<ViewType>(_data.currentNodeType); }
|
ViewType getViewType() { return static_cast<ViewType>(_data.currentNodeType); }
|
||||||
void setViewType(ViewType t) { _data.currentNodeType = t; }
|
void setViewType(ViewType t) { _data.currentNodeType = t; }
|
||||||
|
|
||||||
|
float getLookAtFOV() { return _data.lookatFOV; }
|
||||||
|
void setLookAtFOV(float fov) { _data.lookatFOV = fov; }
|
||||||
float getLookAtPitch() { return _data.lookatPitch; }
|
float getLookAtPitch() { return _data.lookatPitch; }
|
||||||
float getLookAtHeading() { return _data.lookatHeading; }
|
float getLookAtHeading() { return _data.lookatHeading; }
|
||||||
void lookAt(float pitch, float heading) { _data.lookatPitch = pitch; _data.lookatHeading = heading; }
|
void lookAt(float pitch, float heading) { _data.lookatPitch = pitch; _data.lookatHeading = heading; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue