canvas - Backface removal for Perspective Projection -


i'm working on 3d exercise, , have implemented backface removal technique works orthographic projection , need change support other projections well.

what did far :

  1. for each polygon loop vertices
  2. perform transitions , projections calculations
  3. calculate surface normal newell's method
  4. draw polygon if vector direction < 0

as said works orthographic projection , i'm struggling other projections. please great

by way have seen explanation here somewhere didn't understand : "..the usual approach, used in actual 3d hardware, first of transformation (including projection), check whether resulting 2d triangle counterclockwise or clockwise wound, , keep or discard based on condition". maybe how can explain resulting 2d triangle ?

i'm using html5 canvas , js.

this approach in 3d hardware calls graphic pipeline. doesn't matter type of projections use, transformed 2d triangle , backface culling test performed.

function triangle (a, b, c) {     this.pointa = a;     this.pointb = b;     this.pointc = c; }  triangle.prototype.isbackface = function () {     var ax = this.pointa.getprojectedx() - this.pointb.getprojectedx();     var ay = this.pointa.getprojectedy() - this.pointb.getprojectedy();     var bx = this.pointa.getprojectedx() - this.pointc.getprojectedx();     var = this.pointa.getprojectedy() - this.pointc.getprojectedy();     var cz = ax * - ay * bx;     return cz < 0; };  // before drawing triangle call isbackface method. method check // either triangle counterclockwise or clockwise after  // projections. triangle.prototype.draw = function (context) {     if (this.isbackface()) {         return;     }     this._draw(); }; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -