delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/03/22:43:00

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Hidden Face Removal...
Date: Thu, 3 Jul 1997 21:45:35 +0100
Organization: None
Distribution: world
Message-ID: <ul5Y9NAv9AvzEwqL@talula.demon.co.uk>
References: <5pgcv5$d68 AT news DOT compmore DOT net>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 32
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

St Denis writes:
>Can anyone help me here... I am using allegro's 3d graphic routine
>polygon3d, anyways I want to remove the faces\vertices of the polygon
>that are not visible... For example if you were facing a cube dead on
>you will see only one face, yet 6 are drawn....

This sort of question is really off topic for this group:
comp.graphics.algorithms would be a better place to ask.

But since you are here... There are two main approaches to backface
culling.

a) You can store a normal along with each polygon (a vector pointing at
right angles to the plane), transform this normal (rotate, but not
project!) along with your vertices, and then use the dot product to
compare the normal with a vector from the camera to your plane. If the
dot product returns a negative value, the polygon is visible, if it
returns zero the poly is at right angles to the view, and a positive
result means it is backfacing. Look at the polygon3d_proc() routine in
the Allegro test.c for an example of this method.

b) After projecting your polys onto the screen, you can use the cross
product to calculate a normal in screen coordinates, and test the sign
of the Z component to see if it is facing into or out of the screen.
This doesn't require storing all the normals, but means you have to
project all the vertices even if they aren't going to be used. Look at
the Allegro ex22.c, in the quad() routine, for an example.


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019