For a particular object and a particular camera, I wish to convert each vertex into camera space, perform some maths on it and convert it back.
Specifically I need to convert the vertex first into world space, and then into camera space.
v_world = obj.matrix_world * v.co v_cam = cam.matrix_world.invert() * v_world
Which I could tidy up by doing:
# first create matrix that goes from object-space to camera-space ob_to_cam = obj.matrix_world * cam.matrix_world.invert() for v in ob.vertices: v_cam = ob_to_cam * v.co v_cam_out = my_maths_processing(v_cam) v.co = ob_to_cam.invert() * v_cam_out
Is this correct? Is there a tidier way?
This link http://blenderartists.org/forum/archive/index.php/t-246525.html gives:
M1 = Cam.worldTransform # camera 4x4 transform matrix M2 = Obj.worldTransform # object matrix M = M1.inverted()*M2 # conventions valid for blender 2.62
There is another suggestion on the same page, to use:
But I'm unfamiliar with 'bge' -- blender game object. Should I be using this object?