aboutsummaryrefslogtreecommitdiff
path: root/demo/sgi/gl_panel/flying/objectdef.py
blob: 02a95130ab0d6282f0ab31908adbd04375a2ee6c (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from math import *
from objdict import *
from gl import *

FUZZY = 0.00001

# first try - brute force method (ala M.Overmars...)

def makespinobject (smooth,rot,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) :
	object = []
	dth = 2.0 * pi / float (rot)
	for i in range (0, n) :
		for j in range (0, rot) :
			th = dth * float (j)
			#
			if smooth = 1:
				a1 = th
				a2 =th+dth
			else :
				a1 = th + dth / 2.0
				a2 = th + dth / 2.0
			#
			v0 = (x1[i]*sin(th),x1[i]*cos(th),z1[i])
			n0 = (nx1[i]*sin(a1),nx1[i]*cos(a1),nz1[i])
			#
			v1 = (x1[i]*sin(th+dth),x1[i]*cos(th+dth),z1[i])
			n1 = (nx1[i]*sin(a2), nx1[i]*cos(a2), nz1[i])
			#
			v2 = (x2[i]*sin(th+dth),x2[i]*cos(th+dth),z2[i])
			n2 = (nx2[i]*sin(a2), nx2[i]*cos(a2), nz2[i])
			#
			v3 = (x2[i]*sin(th), x2[i]*cos(th), z2[i])
			n3 = (nx2[i]*sin(a1), nx2[i]*cos(a1), nz2[i])
			#
			patch = ((v0,n0), (v1,n1), (v2,n2), (v3,n3))
			#patch = ((n0,v0), (n1,v1), (n2,v2), (n3,v3))
			#
			if x1[i] < FUZZY :
				patch = patch[1:]
			#
			object.append (patch)
	#
	return object

def makesphere (n):
	asin = []
	acos = []
	for i in range (0, n-1):
		asin.append (sin((pi/float (n))*(1.0+float (i))))
		acos.append(cos((pi/float (n))*(1.0+float (i))))
	#
	x1 = [0.0] + asin
	z1 = [1.0] + acos
	nx1 = [0.0] + asin
	nz1 = [1.0] + acos
	#
	x2 = asin + [0.0]
	z2 = acos + [-1.0]
	nx2 = asin + [0.0]
	nz2 = acos + [-1.0]
	#
	return makespinobject (1,2*n,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2)

def makecylinder(n) :
	x1 =  [0.0, 1.0, 1.0]
	nx1 = [0.0, 1.0, 0.0]
	z1 =  [1.0, 1.0, -1.0]
	nz1 =  [1.0, 0.0, -1.0]
	#
	z2 =  [1.0, -1.0, -1.0]
	nz2 =  [1.0, 0.0, -1.0]
	x2 =  [1.0, 1.0, 0.0]
	nx2 = [0.0, 1.0, 0.0]
	#
	return makespinobject(1,2*n,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2)

def makecone(n) :
	x1 =  [0.0, 1.0, 1.0]
	nx1 = [2.0/sqrt(5.0), 0.0, 0.0]
	z1 =  [1.0, -1.0, -1.0]
	nz1 = [1.0/sqrt(5.0), -1.0, -1.0]
	#
	x2 =  [1.0, 0.0, 0.0]
	nx2 = [2.0/sqrt(5.0), 0.0, 0.0]
	nz2 = [1.0/sqrt(5.0), -1.0, -1.0]
	z2 = [-1.0, -1.0, -1.0]
	#
	return makespinobject(1,2*n,2,x1,z1,nx1,nz1,x2,z2,nx2,nz2)

def makecube() :
	x1 =  [0.0, sqrt(2.0), sqrt (2.0)]
	nx1 = [0.0, 1.0, 0.0]
	z1 =  [1.0, 1.0, -1.0]
	nz1 = [1.0, 0.0, -1.0]
	#
	x2 =  [sqrt(2.0), sqrt(2.0), 0.0]
	nx2 = [0.0, 1.0, 0.0]
	z2 =  [1.0, -1.0, -1.0]
	nz2 = [1.0, 0.0, -1.0]
	#
	return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2)


def makepyramid() :
	x1 =  [0.0, sqrt(2.0), 0.0]
	nx1 = [2.0 / sqrt(5.0), 0.0, 0.0]
	z1 =  [1.0, -1.0, 0.0]
	nz1 = [1.0 / sqrt(5.0), -1.0, 0.0]
	#
	x2 =  [sqrt(2.0), 0.0, 0.0]
	nx2 = [2.0 / sqrt(5.0), 0.0, 0.0]
	z2 =  [-1.0, -1.0, -1.0]
	nz2 = [1.0/sqrt(5.0), -1.0, 0.0]
	#
	return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2)

def makeobjects () :
	cube = makecube()
	sphere = makesphere (6)
	cylinder = makecylinder (6)
	cone = makecone (6)
	pyramid = makepyramid ()
	#
	odict = {}
	odict ['cube'] = cube
	odict ['pyramid'] = pyramid
	odict ['sphere'] = sphere
	odict ['cylinder'] = cylinder
	odict ['cone'] = cone
	odict ['diamond'] = cube
	odict ['disk'] = sphere
	#
	return odict


renderfuncs = [bgnpolygon, endpolygon]

def putFunc (funcs) :
	renderfuncs [:] = funcs

def drawobject (obj) :
	#
	for patch in obj :
		renderfuncs[0] ()
		vnarray (patch)
		renderfuncs[1] ()