Accuracy lack in coordinates transform

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… :confused:)
Thank you.

My guess would be that (0.5, 0.5) is probably resolving to a pixel location and that is being used for the projection. It is doubtful that there is a single pixel that is precisely where the camera’s location is in the game engine.

Interesting idea!

I assume this is the right reason. Thank you.

Actually I think it is way to much to be only a matter of pixels (and I also tried with a odd number of pixels, but without good results).

Searching a bit further I found out that the methods yield to the same results if the camera is at the origin.

EDIT: I have made a big mistake, because the transf. matrix is actually 4x4… So I cannot simply multiply it with a vector…

Ok guys, I don’t exactly know how to use camera_to_world matrix, but I found the proper function to achieve what I wanted to (find local axes of the camera): simply by considerating the camera as an object… and so there is the obj.getAxisVect(worldVect) function! And it works!