diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2009-06-05 04:51:36 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2009-06-05 04:51:36 +0400 |
commit | 52b7c157a0c0d0bd1836be3149c683abf8bd1743 (patch) | |
tree | a250424dde82f38f8902e1eb48b767d9c615e995 /source/gameengine/Ketsji/KX_Camera.cpp | |
parent | 8154de7045db47677a367875fd619cc389f6e8d4 (diff) |
getScreenPosition, Ray and Vect fixes:
- fix for [#18867] getScreenRay error
... the Vector wasn't been added to KX_Camera origin. Therefore the Ray was always casted to the wrong coordinate when camera wasn't in [0,0,0] (where is obviously was in my tests :)
- making the input parameter compatible with Blender/BGE window coordinate system (Top-Bottom).
... that will break scripts done in 2.49. Since this feature was added only in 2.49 that fix is OK. (and the fix is ridiculous.
Note:
the input parameter is normalized. That means it runs from 0.0 to 1.0. Some users found it confusing, but it allows to make a game compatible with multiple desktop resolutions.a
Diffstat (limited to 'source/gameengine/Ketsji/KX_Camera.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_Camera.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 1d6c5f77ae5..ba4d6e22872 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -1047,8 +1047,10 @@ KX_PYMETHODDEF_DOC_O(KX_Camera, getScreenPosition, gluProject(vect[0], vect[1], vect[2], modelmatrix, projmatrix, viewport, &win[0], &win[1], &win[2]); - vect[0] = win[0] / (viewport[0] + viewport[2]); - vect[1] = win[1] / (viewport[1] + viewport[3]); + vect[0] = (win[0] - viewport[0]) / viewport[2]; + vect[1] = (win[1] - viewport[1]) / viewport[3]; + + vect[1] = 1.0 - vect[1]; //to follow Blender window coordinate system (Top-Down) PyObject* ret = PyTuple_New(2); if(ret){ @@ -1068,6 +1070,8 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, getScreenVect, if (!PyArg_ParseTuple(args,"dd:getScreenVect",&x,&y)) return NULL; + y = 1.0 - y; //to follow Blender window coordinate system (Top-Down) + MT_Vector3 vect; MT_Point3 campos, screenpos; @@ -1127,7 +1131,8 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, getScreenRay, } Py_DECREF(argValue); - dist *= -1.0; + dist = -dist; + vect += this->GetCameraLocation(); argValue = (propName?PyTuple_New(3):PyTuple_New(2)); if (argValue) { |