-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.py
More file actions
41 lines (40 loc) · 1.42 KB
/
Copy pathAnimation.py
File metadata and controls
41 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from Vector3D import *
from Line import *
from Triangle import *
from Plane import *
from ReadOBJ import *
import math
from Ray import *
from drawer import *
import copy
# render function
pygame.init()
def render(SceneLoaded,Scale,Light,CamDist,Fdist):
Scene=SceneLoaded
Screen= []
projection_plane= Plane(Vector(0,CamDist,0),Vector(1,0,0),Vector(0,0,1))
focalPoint=Vector(0,CamDist+Fdist,0)
#Sort by Y value all triangles (oclusion)
for triangle in Scene:
try:
tri = Triangle(triangle.v1*Scale,triangle.v2*Scale,triangle.v3*Scale)
V1=Line(tri.v1,focalPoint-tri.v1).plane_intersect(projection_plane)# Three lines from the vertices to the plane
V2=Line(tri.v2,focalPoint-tri.v2).plane_intersect(projection_plane)#
V3=Line(tri.v3,focalPoint-tri.v3).plane_intersect(projection_plane)#
if (((tri.v1 - tri.v2)*(tri.v2 - tri.v3)).dot_product(focalPoint) > 0):
tri.shade(Light)
Screen.append(Triangle(V1,V2,V3,color=tri.color))
except:
pass
draw(Screen)
LoadedScene = readOBJ("object.obj")
LoadedScene.sort( key = lambda tri: tri.centre.y)
light=-1000
render(LoadedScene,100,Vector(1000,1000,1000),1,1000)
camspeed=10
campos=1000
scale=100
for i in range(0,30):
render(LoadedScene,scale,Vector(1000,1000-light,light),campos,1000)
light+=100
pygame.event.get()