Path: chuka.playstation.co.uk!scea!hobbes From: jamin1@psu.edu (Jamin Frederick) Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: creation of tmds Date: Mon, 29 Jun 1998 21:23:40 GMT Organization: SCEA News Server Lines: 174 Message-ID: <6n904u$4sn1@scea> References: <354f8520.24963808@www.netyaroze-europe.com> <35527A2E.72F907B4@home.com> NNTP-Posting-Host: 204.240.38.127 X-Newsreader: News Xpress 2.01 In this code and others I've seen, it looks like the TMD coordinate system is the same as RSD coordinate system, i.e., 1000.0 TMD == 1000.0 RSD, etc. Now are the TMD coord numbers converted to fixed point (12-bit) when it is given to the playstation? I mean, do we have to mess around with fixed point at all, or do we just use the system of RSD and TMD (assuming they're the same), with vertices usually in the range of +-500.0 to +- 2000.0 or so? B/c there are only 3 integer bits for 12-bit fixed point, meaning you can only get at most 7.something? Jamin In article <35527A2E.72F907B4@home.com>, Tim O'Neil wrote: >Robert Swan wrote: >> >> Im desperately trying to create tmds at runtime. I got a large program >> from one person, which I tried to add to my program that didnt work. >> >> So basically I went through the tmd file format (rewriting it in the >> process) and want to start again. I was wondering if there are any of >> you out there with code that I could have a look at featuring the >> creation of tmds. It would be a great help. >> >> Thanks a lot, >> Robert Swan >> rs108@mdx.ac.uk >> http://www.netyaroze-europe.com/~middex2 > > >Ok, I am gonna try to do this from memory, as I don't have my code on >this machine... > >First off, these are the data structures I use... they correspond to the >various parts of the TMD file structure > >#define u_long unsigned long >#define u_char unsigned char > >struct ObjectHeader { > > u_long *firstVertex; > u_long numberOfVertices; > u_long *firstNormal; > u_long numberOfNormals; > u_long *firstPacket; > u_long numberOfPackets; > u_long scale; >}; > >struct GouraudTexturedTriangle {//this name is way too long... > > u_char wordsAfterConversion, wordsToFollow, flags, mode; > u_char u0, v0; > short clutPosition, > u_char u1, v1; > short textureBlock; > u_char u2, v2; > short emptyFiller; > short normal0Index, vertex0Index; > short normal1Index, vertex1Index; > short normal2Index, vertex2Index; >}; > >struct Vertex { > > short x, y, z, emptyFiller; >}; > >struct Normal { > > short x, y, z, emptyFiller; >}; > > >..... > >so whenever you want to create 10 Gouraud Textured Triangles... > >ObjectHeader object; >Vertex vertices[30]; >Normal normals[30]; >GouraudTexturedTriangle packets[10]; > >void createSomeTriangles () { > > object.firstVertex = (u_long *)vertices;//or &vertices[0]... whichever >you prefer > object.firstNormal = (u_long *)normals; > object.firstPacket = (u_long *)packets; > object.numberOfVertices = 30; > object.numberOfNormals = 30; > object.numberOfPackets = 10; > object.scale = 1; > > for (long i=0; i<10; i++) { > > GouraudTexturedTriangle &p = packet[i]; > > p.wordsAfterConversion = 0x09; //these are defaults for gt > triangles > p.wordsToFollow = 0x06; > p.flags = 0; > p.mode = 0x34; > > p.clutPosition = 0x7800; > //this represents a clut at [0,480] ... just below the > display > //buffers if you are double buffered at 320x240 > p.textureBlock = 0x85; > //this texture block represents 8-bit textures with the > bitmap > //starting on texture page 5 (at [320,0] of the frame > buffer) > // ... just to the right of the diplay buffers at > 320x240 > > p.u0 = 0; p.v0 = 0; > p.u1 = 0; p.v1 = 255; > p.u2 = 255; p.v2 = 255; > //remember that the texture coords are relative to the > top left of > //the texture page you start on, hence these texture > coordinates are > //valid for a texture going from [320,0] to [575,255] > > p.normal0Index = (3*i)+0; > p.normal1Index = (3*i)+1; > p.normal2Index = (3*i)+2; > > p.vertex0Index = (3*i)+0; > p.vertex1Index = (3*i)+1; > p.vertex2Index = (3*i)+2; > > #define setPoint(point,x1,y1,z1) \ > point.x = x1; \ > point.y = y1; \ > point.z = z1 > > setPoint (normals[(3*i)+0], 0, 0, 4096); > setPoint (normals[(3*i)+1], 0, 0, 4096); > setPoint (normals[(3*i)+2], 0, 0, 4096); > > setPoint (vertices[(3*i)+0], 0, 0, 100*i); > setPoint (vertices[(3*i)+1], 100, 0, 100*i); > setPoint (vertices[(3*i)+2], 0, 100, 100*i); > //I can't remember if the points go in CW or CCW order, > but > //it will be apparent when you execute > } > GsDOBJ2 junkObject; > GsLinkObject4 (&junkObject, (u_long *)object, 0); > //all this does is set the wordsAfterConversion part of the > first >packet > //to be the number of similar packets to follow (those of the > same >type) > //so in this example, it would be set to 9 (or was it 10?... > its not >really > //important because this function does all the work :) > > return; >} > >At this point, all you need to do is to take the tmd field of any >GsDOBJ2 >structure and point it object and everything should render fine. Whew. >If there are any errors I apologize, I just did thsi from memory and >don't >have any of my code or documentation at hand, so I might have messed up >a >type or something, but I think this is good enough to get you started.