17 lines
672 B
Python
17 lines
672 B
Python
import math
|
|
from pygame.math import Vector3
|
|
|
|
def project(vector, w, h, fov, distance):
|
|
factor = math.atan(fov / 2 * math.pi / 180) / (distance + vector.z)
|
|
x = vector.x * factor * w + w / 2
|
|
y = -vector.y * factor * w + h / 2
|
|
return Vector3(x, y, vector.z)
|
|
|
|
def rotate_vertices(vertices, angle, axis):
|
|
return [v.rotate(angle, axis) for v in vertices]
|
|
def scale_vertices(vertices, s):
|
|
return [Vector3(v[0]*s[0], v[1]*s[1], v[2]*s[2]) for v in vertices]
|
|
def translate_vertices(vertices, t):
|
|
return [v + Vector3(t) for v in vertices]
|
|
def project_vertices(vertices, w, h, fov, distance):
|
|
return [project(v, w, h, fov, distance) for v in vertices] |