home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!xmission!not-for-mail
- From: butlerm@xmission.xmission.com (Mark David Butler)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: NormalVectors-How to compare angles?
- Date: 29 Jan 1996 22:24:48 -0700
- Organization: XMission Internet (801 539 0900)
- Message-ID: <4eka30$meh@xmission.xmission.com>
- References: <310CC190.78DF@gih.no>
- NNTP-Posting-Host: xmission.xmission.com
-
- There is absolutly no reason to calculate angles and trigonometric functions
- when you can use dot products instead.
-
- Given 3d vector points A,B,C in order such that (B-A) cross (C-A) is outward
- and L a unit vector that points toward the light source P.
-
- D = B - A
- E = C - A
-
- N = V1 cross V2
-
- Intensity = ambient_intensity + cos^2(angle between L and N) * factor
-
- now the cos(angle between L and N) = L * N / N * N so
-
- Intensity = ambient_intensity + factor * ((L*N) / (N*N))^2
- where N = (B-A) cross (C-A)
-
- You can do this with nine subtractions, twelve additions, 14 multiplications,
- and one division per polygon. You might have to throw in some
- left shifts to handle fixed point arithmetic properly.
-
- Note if A,B are 3d vectors A*B = Ax*Bx + Ay*By + Az*Bz
-
- also mag(N) * mag(N) = N*N
-
- also A cross B = [ Ay*Bz - By*Az, Az*Bx - Bz*Ax, Ax*By-Bx*Ay ]
-
- If you want to speed this up even more, precalculate N*N. It is proportional
- to the area of the polygon and (obviously) invariant under rotation.
-
-
- In article <310CC190.78DF@gih.no> you write:
- >I'm trying to do gouroud shading in assem, and I need a fast way of comparing the vectors,
- >so I can calculate the colors. Is there a faster way of doing this then using normalvectors and
- >comparing
- >them to the vector from the lightsource (angles between vectors are a shitty job to do (roots
- >and sines)
- >especially in asm).
- >I can fake it if all the surfaces are the same size, but thats not what I want to do...
- >
- >I need some serious help here.......
- >PLEASE PLEASE PLEASE PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- >
- >
- >email me or ship it here...
- >
- >e-mail:haa_jako@hig.no
-
-
- --
- Mark David Butler ( butlerm @ xmission.com )
-
- --
- Mark David Butler ( butlerm @ xmission.com )
-
-