-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.py
73 lines (58 loc) · 1.98 KB
/
display.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
from math import *
import cv2
from point import *
from light import light
from player import player
from surface import surface
me = player()
li = light()
res = me.ppdist*2
img = np.zeros((res,res,3), np.uint8)
mytri = surface('tri', point(0,10,0), point(10,20,0), point(0,30,10))
k = cv2.waitKey(10) & 0xFF
norm = cross( sub(mytri.p2, mytri.p1), sub(mytri.p3, mytri.p1) )
mnorm = norm.mod()
while(k != 27):
img = np.zeros((res,res,3), np.uint8)
n1 = add(mytri.p1,me.position)
n2 = add(mytri.p2,me.position)
n3 = add(mytri.p3,me.position)
n1.project(me.ppdist)
n2.project(me.ppdist)
n3.project(me.ppdist)
n1 = me.findfinal(n1)
n2 = me.findfinal(n2)
n3 = me.findfinal(n3)
cv2.circle(img,(int(res/2+n1.x),int(res/2-n1.z)),2,(0,255,0),-1)
cv2.circle(img,(int(res/2+n2.x),int(res/2-n2.z)),2,(0,255,0),-1)
cv2.circle(img,(int(res/2+n3.x),int(res/2-n3.z)),2,(0,255,0),-1)
cn = 40
for x in range(0,cn):
for y in range(0,cn):
if x + y > cn:
continue
#n = add(me.position, add( add( mul(sub(mytri.p2, mytri.p1), x*1.0/cn), mul(sub(mytri.p3, mytri.p1), y*1.0/cn) ), mytri.p1 ) )
#tolight = sub( li.pos, n )
#cos1 = dot(norm, tolight) / (tolight.mod() * mnorm)
#cos2 = dot(n , norm) / (n.mod() * mnorm)
#col = 255/( abs(cos1-cos2) +1)
#n.project(me.ppdist)
col = 255
n = add( n1, add( mul( sub(n2,n1), x*1.0/cn ), mul( sub(n3,n1), y*1.0/cn ) ) )
cv2.circle(img,(int(res/2+n.x),int(res/2-n.z)),4,(col,col,col),-1)
cv2.imshow("My Window", img)
k = cv2.waitKey(10) & 0xFF
moveIter = 0.1
if k == 97:
me.move(-moveIter,90,0)
elif k == 100:
me.move(moveIter,90,0)
elif k == 119:
me.move(moveIter,90,90)
elif k == 115:
me.move(-moveIter,90,90)
elif k == 105:
me.move(moveIter,0,90)
elif k == 107:
me.move(-moveIter,0,90)