Page MenuHome

BGE : Fix T43800: getScreenVect()/getScreenPosition()/modelview_matrix returns incorrect results
ClosedPublic

Authored by Porteries Tristan (panzergame) on Mar 9 2015, 10:12 PM.

Details

Summary

The getScreenVect(), getScreenPosition() and modelview_matrixmethod returns an incorrect results if called after the camera has been translated on the same frame.
The model view matrix will be update only once per frame with Cam->SetModelviewMatrix in KX_KetsjiEngine::RenderFrame.
Using GetWorldToCamera as model view matrix to get an actual view matrix even if the camera is moved.

Diff Detail

Repository
rB Blender
Branch
ge_camera_screen_vec

Event Timeline

Porteries Tristan (panzergame) retitled this revision from to BGE : fix T43800 KX_Camera.getScreenVect() returns incorrect results if called after camera has been moved on the same frame..
Porteries Tristan (panzergame) updated this object.

One concern with this patch, is that many minor motion will updates to the camera position (physics substeps for eg). will be updating the view matrix, in situations when its not needed.

If the Python API needs this,. we could have a Python method to recalculate the view matrix too.

Also, if we assume the view matrix is up to date here, we could probably remove other view matrix updates elsewhere.

@Porteries Tristan (panzergame) did you check how often this runs? (if the parent is a physics object for eg).

From the Python side of things, I don't see why we would need so many view matrix updates. We don't get Python update calls for physics ticks, so at the moment I don't think there is any Python code that would be able to access it this rapidly.

Porteries Tristan (panzergame) edited edge metadata.

Use an other way : just call function UpdateModelviewMatrix before use the modelview matrix.

Update also for python modelview matrix getter.

Thomas Szepe (hg1) requested changes to this revision.Mar 11 2015, 7:10 PM
Thomas Szepe (hg1) edited edge metadata.

This patch now not only fix KX_Camera.getScreenVect() method. Please update the title and summary.

source/gameengine/Ketsji/KX_Camera.cpp
894

UpdateModelviewMatrix() is wrong must be self->UpdateModelviewMatrix();
Please always test your code changes before uploading it.

This revision now requires changes to proceed.Mar 11 2015, 7:10 PM
Porteries Tristan (panzergame) retitled this revision from BGE : fix T43800 KX_Camera.getScreenVect() returns incorrect results if called after camera has been moved on the same frame. to BGE : fix T43800, KX_Camera.getScreenVect()/getScreenPosition()/modelview_matrix update the modelview matrix..Mar 11 2015, 7:28 PM
Porteries Tristan (panzergame) edited edge metadata.
Thomas Szepe (hg1) retitled this revision from BGE : fix T43800, KX_Camera.getScreenVect()/getScreenPosition()/modelview_matrix update the modelview matrix. to BGE : Fix T43800: getScreenVect()/getScreenPosition()/modelview_matrix returns incorrect results.
Thomas Szepe (hg1) updated this object.
Thomas Szepe (hg1) edited edge metadata.

Updating summary.

This revision is now accepted and ready to land.Mar 14 2015, 9:30 AM

Reading an attribute shouldn't change the internal state of the application. This should probably calculate a new matrix for the attribute to return.

Porteries Tristan (panzergame) edited edge metadata.

Use GetCameraToWorld instead of GetModelviewMatrix and remove UpdateModelviewMatrix function.

Campbell Barton (campbellbarton) edited edge metadata.

LGTM however the reason why it works isn't immediatly obvious.

This patch should note that GetWorldToCamera is used as the modal matrix because KX_KetsjiEngine::RenderFrame passes it to cam->SetModelviewMatrix.

Thomas Szepe (hg1) edited edge metadata.
This revision was automatically updated to reflect the committed changes.