Debian Codegraph @

packages/seacas/applications/blot/shaden.f

raw
1 C Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 C NTESS, the U.S. Government retains certain rights in this software.
4 C
5 C See packages/seacas/LICENSE for details
6
7 C=======================================================================
8 SUBROUTINE SHADEN (NLNKF, LINKF1, XN, YN, ZN, NCOL, LITE, NLIT,
9 * MINCOL, KDIFF, KSPEC, SPEXP, WXMIN, WYMIN, WXMAX, WYMAX)
10 C=======================================================================
11
12 C --*** SOLIDF *** (DETOUR) Paint face
13 C -- Written by Amy Gilkey - revised 09/24/85
14 C --
15 C --SOLIDF paints the a face of the mesh.
16 C --
17 C --Parameters:
18 C -- NLNKF - IN - the number of nodes per face
19 C -- LINKF1 - IN - the connectivity for the face
20 C -- XN, YN, ZN - IN - the nodal coordinates
21 C -- NCOL - IN - the number of colors
22 C -- XLN, YLN, ZLN - IN - the light unit vector components
23 INTEGER LINKF1(NLNKF)
24 REAL XN(*), YN(*), ZN(*)
25 REAL LITE(8,*)
26 REAL KDIFF, KSPEC, SPEXP
27
28 REAL XPTS(20), YPTS(20), ZPTS(20)
29 SAVE LSTCOL
30 DATA LSTCOL /0/
31
32 C... Coordinate System:
33
34 C ^ Y
35 C |
36 C |
37 C |
38 C | X
39 C Z--------->
40
41 XMAX = -1.0e30
42 YMAX = -1.0e30
43 XMIN = 1.0e30
44 YMIN = 1.0e30
45 DO 100 ILINK = 1, NLNKF
46 XPTS(ILINK) = XN(LINKF1(ILINK))
47 YPTS(ILINK) = YN(LINKF1(ILINK))
48 ZPTS(ILINK) = ZN(LINKF1(ILINK))
49 XMAX = MAX(XMAX, XPTS(ILINK))
50 XMIN = MIN(XMIN, XPTS(ILINK))
51 YMAX = MAX(YMAX, YPTS(ILINK))
52 YMIN = MIN(YMIN, YPTS(ILINK))
53 100 CONTINUE
54
55 C ... Determine if polygon is in window.
56 IF (XMAX .LT. WXMIN .OR. XMIN .GT. WXMAX .OR.
57 * YMAX .LT. WYMIN .OR. YMIN .GT. WYMAX) RETURN
58
59 C ... Calculate surface normal
60 if (nlnkf .eq. 4) then
61 XMAG = (YPTS(3) - YPTS(1)) * (ZPTS(4) - ZPTS(2)) -
62 * (ZPTS(3) - ZPTS(1)) * (YPTS(4) - YPTS(2))
63 YMAG = (ZPTS(3) - ZPTS(1)) * (XPTS(4) - XPTS(2)) -
64 * (XPTS(3) - XPTS(1)) * (ZPTS(4) - ZPTS(2))
65 ZMAG = (XPTS(3) - XPTS(1)) * (YPTS(4) - YPTS(2)) -
66 * (YPTS(3) - YPTS(1)) * (XPTS(4) - XPTS(2))
67 else
68 C ... Newells method, "Procedural Elements for Computer Graphics", p209
69 xmag = (ypts(nlnkf) - ypts(1)) * (zpts(nlnkf) - zpts(1))
70 ymag = (zpts(nlnkf) - zpts(1)) * (xpts(nlnkf) - xpts(1))
71 zmag = (xpts(nlnkf) - xpts(1)) * (ypts(nlnkf) - ypts(1))
72 do 110 i=1, nlnkf-1
73 j = i + 1
74 xmag = xmag + (ypts(i) - ypts(j)) * (zpts(i) - zpts(j))
75 ymag = ymag + (zpts(i) - zpts(j)) * (xpts(i) - xpts(j))
76 zmag = zmag + (xpts(i) - xpts(j)) * (ypts(i) - ypts(j))
77 110 continue
78 end if
79 C ... If polygon facing away from viewer (-Z), return immediately
80 if (zmag .lt. 0) return
81 VMAG = SQRT(XMAG**2 + YMAG**2 + ZMAG**2)
82
83 C ... Normalize surface normal
84 XMAG = XMAG / VMAG
85 YMAG = YMAG / VMAG
86 ZMAG = ZMAG / VMAG
87
88 C ... Determine dot product of surface normal and light vector.
89 SMAG = 0.0
90 DO 120 I = 1, NLIT
91 SMAG = SMAG + max(0.0, (XMAG * LITE(5,I) + YMAG * LITE(6,I) +
92 * ZMAG * LITE(7,I)) * LITE(8,I))
93 120 CONTINUE
94
95 C ... Calculate Reflection Vector.
96 if (SPEXP .GT. 0.0 .and. KSPEC .GT. 0.0) then
97 RMAG = 0.0
98 DO 160 I = 1, NLIT
99 R = xmag * lite(5,i) + ymag*lite(6,i) + zmag*lite(7,i)
100 x = 2 * xmag * R - lite(5,i)
101 y = 2 * ymag * R - lite(6,i)
102 z = 2 * zmag * R - lite(7,i)
103
104 C ... Normalize Reflection Vector
105 vmag = sqrt(x**2 + y**2 + z**2)
106 x = x / vmag
107 y = y / vmag
108 z = z / vmag
109
110 C ... NOTE: Sight vector is (0,0,1),
111
112 C ... Calculate dot product of Reflect and Sight
113 C - sight = z, therefore, dot product = z
114 RMAG = RMAG + max(0.0, Z)**SPEXP * LITE(8,I)
115 160 CONTINUE
116
117 SMAG = KDIFF * SMAG + KSPEC * RMAG
118 end if
119
120 C ... Scale dot product (0 <= |smag| <= 1) to (0 < icol < ncol)
121 C If smag <= 0, set icol = 1
122 C maximum color = ncol-1
123 C minimum color = 1
124
125 if (ncol .eq. 1) then
126 icol = mincol + 1
127 else
128 ICOL = MINCOL + min(NCOL-1, max(1, NINT(SMAG * DBLE(NCOL))))
129 end if
130
131 if (lstcol .ne. icol) then
132 CALL GRCOLR (ICOL)
133 lstcol = icol
134 end if
135 CALL MPD2PG (NLNKF, XPTS, YPTS, 'S')
136 RETURN
137 END