Path: chuka.playstation.co.uk!news From: Craig Graham Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: Calculating RSD Normal Format Date: Thu, 07 May 1998 15:31:23 +0100 Organization: Intelligent Research Lines: 132 Message-ID: <3551C5BB.29D42D2A@hinge.mistral.co.uk> References: <3551A5F6.A71F93A@clara.net> NNTP-Posting-Host: 194.131.235.3 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; I) Ian Thompson wrote: > Hi, > > I am in the process of writing an MAX ASC to RSD convertor for the yaroze. I have I recomend you do ASE instead as it has more info about the model(like, texturing and animation). > completed most of the conversion vertices, polygons and textures > etc. I am having trouble with the calculation of the Normal section of the PLY file for the RSD. I have the vertices and the polygon references to > the vertices. I have tried the calculate the normal section but without success (Random shading on all the polygons). > > I have these questions; > > How do you calculate the Normal section based on the Vertices and Polygon section. > Is it a different calculation for guroud (Spelling?!?) and flat shaded polygons. > > Any help will be appreciated. > > Ian Thompson Here's a couple of fragments from my RsdAnim program (Keyframe animatorfor RSD / MIMe). Basically, to calculate the vertex normals for a gourard shaded poly, for each vertex you sum the normal vectors of all faces that include that vertex. For flat shaded poly's it's easier, you just use the normal of the face. Normal==CrossProduct() of any two vectors in the poly. (remember to chose the right two vectors, get them the wrong way round and all your normals will be inverted relative to the actual way the poly is drawn). eg. Vector1==VERTEX2 - VERTEX1 Vector2==VERTEX3 - VERTEX1 One thing to note is that you must unify the normal vector to be a unit vector (length == 1). ie. x*x+y*y+z*z==1 Anyway, here's some c++ code fragments that should help a bit..... Craig. void CPsxRSD::RecalculateVertexNormalsForGourardFaces(void) { int v; int p; int n; unsigned int nv,tv,lv; unsigned int nv_id,tv_id,lv_id; int fcnt; Vertex vc1,vc2; n_norm=n_vert; // Reset Vertex Normals for(n=0; n1; ds=Distance()) { ds1=(double)1/ds; Scale(ds1); } } Vertex Vertex::CrossProduct(Vertex v) { Vertex vr(y*v.z - z*v.y,z*v.x - x*v.z,x*v.y - y*v.x,flags); return vr; } void Vertex::Scale(double scale) { x*=scale; y*=scale; z*=scale; }