Hello everybody,
Today I tried some camera movement script but I got accuracy problems.
Here is my code:
import bge
import mathutils
camera = bge.logic.getCurrentScene().active_camera
print((camera.getCameraToWorld()*mathutils.Vector((0, 0, 1.0))).normalized())
print(camera.getScreenVect(0.5, 0.5))
It prints in the console the coordinates of the vector pointing in the same direction as the camera. But actually I tried two different ways to achieve that:
-through the function “getCameraToWorld”, that is with the transformation matrix
-through the function “getScreenVect(0.5, 0.5)”, which returns the vector pointing from the camera to the center of the screen.
Both ways seem to function, but lead to two slightly different results (difference of about 0.01 on each axis). For example, I got this:
<Vector (0.7304, 0.3550, 0.5835)>
<Vector (0.7167, 0.3483, 0.6041)>
(The vector from getScreenVect doesn’t need to be normalized, but I also tried it).
Has anybody an idea about the reason why this problem occurs? Is that simply a rounding error in any of the functions? Which way should I use preferabily? (I’d like you answer “the first one”, but… )
Thank you.