Skip to content

Instantly share code, notes, and snippets.

@jampekka
Last active Jun 22, 2016
Embed
What would you like to do?
def project_to_ground(pos, camera, height=0.0):
matWorldInverse = np.array(camera['matrixWorldInverse']).reshape(4, 4).T
matWorld = np.linalg.inv(matWorldInverse)
proj = np.array(camera['projectionMatrix']).reshape(4, 4).T
origin = matWorld[:,3][:-1]
deproj = np.dot(matWorld, np.linalg.inv(proj))
direction = np.dot(deproj, (pos[0], pos[1], 0.5, 1.0))
direction = direction[:-1]/direction[-1]
direction -= origin
direction /= np.linalg.norm(direction)
landing = direction*((height - origin[1])/direction[1]) + origin
return landing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment