Skip to content

Instantly share code, notes, and snippets.

@gus3inov
Last active March 20, 2021 13:21
Show Gist options
  • Save gus3inov/698c1bbacf0d503e7ddcc48b66694e8d to your computer and use it in GitHub Desktop.
Save gus3inov/698c1bbacf0d503e7ddcc48b66694e8d to your computer and use it in GitHub Desktop.
Look at implementation
import math
import numpy as np
def length(v):
return math.sqrt((v[0]*v[0])+ (v[1]*v[1]) + (v[2]*v[2]))
def normalize(v):
l = length(v)
if l != 0:
inv = 1.0 / l
return [v[0] * inv, v[1] * inv, v[2] * inv]
return [0, 0, 0]
def lookAtRH(eye, target, up):
zaxis = normalize(np.subtract(eye, target)) # The "forward" vector
xaxis = normalize(np.cross(up, zaxis)) # The "right" vector
yaxis = np.cross(zaxis, xaxis) # The "up" vector
orientation = np.array([
[xaxis[0], yaxis[0], zaxis[0], 0],
[xaxis[1], yaxis[1], zaxis[1], 0],
[xaxis[2], yaxis[2], zaxis[2], 0],
[0, 0, 0, 1],
])
translation = np.array([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[-eye[0], -eye[1], -eye[2], 1]
])
return np.matmul(translation, orientation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment