Path: chuka.playstation.co.uk!news From: Kev Newsgroups: scee.yaroze.programming.3d_graphics Subject: Calculating Normals Date: Thu, 29 May 1997 12:55:50 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 60 Message-ID: <338D6EC6.7EC3@geocities.com> NNTP-Posting-Host: mango.ferndown.ate.slb.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.3 sun4m) Hi, OK, I've finally got around to really playing with the Yaroze and I like it. I designing my own 3D world system (wow! original!) and I'm starting off with the basics... I'm having a problem calculating normals for TMDVERTs for use in my own custom GPU primitives. This is the routine I'm using the calculate the normals for a triangle, I'm a bit confused as it doesn't produce the correct results (when compared to the normals produced by RSDTOOL for the same triangles): /* calculate normal for flat shaded triangle IN: ptr to TriPoly structure */ void CalculateNormal(TriPoly *ptr) { // functions used int GetSizeOfVector(TMDVERT *); void ScaleVectorToUnit(TMDVERT *); // temp storage TMDNORM normal; // convert vectors to unit vectors ScaleVectorToUnit(&(ptr->vert[0])); ScaleVectorToUnit(&(ptr->vert[1])); ScaleVectorToUnit(&(ptr->vert[2])); // calc normal normal.nx = (ptr->vert[1].vy - ptr->vert[0].vy) * (ptr->vert[0].vz - ptr->vert[2].vz) - (ptr->vert[1].vz - ptr->vert[0].vz) * (ptr->vert[0].vy - ptr->vert[2].vy); normal.ny = (ptr->vert[1].vz - ptr->vert[0].vz) * (ptr->vert[0].vx - ptr->vert[2].vx) - (ptr->vert[1].vx - ptr->vert[0].vx) * (ptr->vert[0].vz - ptr->vert[2].vz); normal.nz = (ptr->vert[1].vx - ptr->vert[0].vx) * (ptr->vert[0].vy - ptr->vert[2].vy) - (ptr->vert[1].vy - ptr->vert[0].vy) * (ptr->vert[0].vx - ptr->vert[2].vx); ... } The normal produced by this routine is quite different from that the correct normal. Am I using the right method??? I'm sure the ScaleVectorToUnit function and GetSizeOfVector functions are OK as they are from Sony code anyway. Can anyone help? Cheers, Kev. -- http://www.geocities.com/SiliconValley/Pines/7428