View Full Version : finding number of pixels
I am trying to implement Phong Shading algorithm. My question is how to find the exact number of pixels between two vertices since I need to find the normal for each pixel by interperlating.
Thanks a lot.
10-23-2001, 11:03 AM
Talk to your good friend Pythagourous (sp?) or even DeCartes (sp?), they'll tell you that:
# pixels = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )
Also known as the Cartesian distance or if you're talking about triangles the Pythagorean thereom.
But that's assuming you've already transformed your vertices from world space to screen space.
[This message has been edited by Screaming Lunatic (edited 10-23-2001).]
Thank you very much.
My vertices have the form (x, y, z) so I guess that they are in world coordination system. How do I transform them to screen system?
10-23-2001, 09:53 PM
Oh boy, meet Foley, VanDam, Feiner, and Hughes handy? You'll find that they can your good friends too.
Well you want to multiply your vertex on the left by the matrix below to go from world-space to view-space:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 1/d 0]
Where d is the distance from the origin to the front clipping plane. I'm assuming you want a perspective projection rather than an orthogonal projection. But for an orthogonal you just drop the z coordinate.
Now, to go from view space to screen space the matrix is a little more complicated.
Let me know if you really need the matrix for that. You should be able to do a search at google for it. But I really recommend that you get Foley, VanDam, Feiner, and Hughes.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.