Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: Tim O'Neil Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: creation of tmds Date: Thu, 07 May 1998 23:21:18 -0400 Organization: @Home Network Member Lines: 149 Message-ID: <35527A2E.72F907B4@home.com> References: <354f8520.24963808@www.netyaroze-europe.com> NNTP-Posting-Host: cr785161-a.rchrd1.on.wave.home.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.02 [en]C-AtHome0402 (Win95; U) 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.