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.
Details
- Reviewers
Campbell Barton (campbellbarton) Sybren A. Stüvel (sybren) Thomas Szepe (hg1) Sergey Sharybin (sergey) Dalai Felinto (dfelinto) Inês Almeida (brita_) - Commits
- rBS465a5d29c033: BGE : Fix T43800: getScreenVect()/getScreenPosition()/modelview_matrix returns…
rB465a5d29c033: BGE : Fix T43800: getScreenVect()/getScreenPosition()/modelview_matrix returns…
Diff Detail
- Repository
- rB Blender
Event Timeline
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.
Use an other way : just call function UpdateModelviewMatrix before use the modelview matrix.
This patch now not only fix KX_Camera.getScreenVect() method. Please update the title and summary.
| source/gameengine/Ketsji/KX_Camera.cpp | ||
|---|---|---|
| 889 | UpdateModelviewMatrix() is wrong must be self->UpdateModelviewMatrix(); | |
Reading an attribute shouldn't change the internal state of the application. This should probably calculate a new matrix for the attribute to return.
Use GetCameraToWorld instead of GetModelviewMatrix and remove UpdateModelviewMatrix function.
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.