[Scummvm-git-logs] scummvm master -> 090daab51992498981f270e9da694ea533c517b7
aquadran
noreply at scummvm.org
Sun Jun 5 20:12:58 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
090daab519 GRIM: Implemented Lua V1 'WorldToScreen' opcode
Commit: 090daab51992498981f270e9da694ea533c517b7
https://github.com/scummvm/scummvm/commit/090daab51992498981f270e9da694ea533c517b7
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2022-06-05T22:12:54+02:00
Commit Message:
GRIM: Implemented Lua V1 'WorldToScreen' opcode
Changed paths:
engines/grim/lua_v1.cpp
diff --git a/engines/grim/lua_v1.cpp b/engines/grim/lua_v1.cpp
index 25e6aac29d0..f8ddac30018 100644
--- a/engines/grim/lua_v1.cpp
+++ b/engines/grim/lua_v1.cpp
@@ -399,6 +399,28 @@ void Lua_V1::RotateVector() {
lua_pushobject(resObj);
}
+void Lua_V1::WorldToScreen() {
+ lua_Object worldX = lua_getparam(1);
+ lua_Object worldY = lua_getparam(2);
+ lua_Object worldZ = lua_getparam(3);
+ if (!lua_isnumber(worldX) || !lua_isnumber(worldY) || !lua_isnumber(worldZ)) {
+ return;
+ }
+ Math::Vector4d worldVec(lua_getnumber(worldX), lua_getnumber(worldY), lua_getnumber(worldZ), 1.0f);
+ Math::Matrix4 projModelView = g_driver->getProjection() * g_driver->getModelView();
+ Math::Vector4d screenPos = projModelView * worldVec;
+ screenPos /= screenPos.w();
+ float winX = (1 + screenPos.x()) / 2.0f * g_driver->getScreenWidth();
+ float winY = g_driver->getScreenHeight() - (1 + screenPos.y()) / 2.0f * g_driver->getScreenHeight();
+ if (winX >= 0 && winX < g_driver->getScreenWidth() && winY >= 0 && winY < g_driver->getScreenHeight()) {
+ lua_pushnumber(winX);
+ lua_pushnumber(winY);
+ } else {
+ lua_pushnil();
+ lua_pushnil();
+ }
+}
+
void Lua_V1::FileFindDispose() {
g_grim->_listFiles.clear();
g_grim->_listFilesIter = nullptr;
@@ -772,10 +794,6 @@ void Lua_V1::GetCameraPosition() {
warning("Stub function: GetCameraPosition");
}
-void Lua_V1::WorldToScreen() {
- warning("Stub function: WorldToScreen");
-}
-
#define STUB_FUNC(name) void name() {}
// Stub functions not used in games
More information about the Scummvm-git-logs
mailing list