Path: chuka.playstation.co.uk!news From: robert_swan@playstation.sony.com (Robert Swan) Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: 2d sprites in a 3d world Date: Sat, 05 Dec 1998 16:08:49 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 72 Message-ID: <366959c3.522585@www.netyaroze-europe.com> References: <3659BEF7.663E@mdx.ac.uk> <3659D5B1.41EB5140@scee.sony.co.uk> NNTP-Posting-Host: pD7s13a01.client.global.net.uk X-Newsreader: Forte Free Agent 1.11/32.235 On Mon, 23 Nov 1998 21:37:53 +0000, James Russell wrote: >"Harvey.C" wrote: >> >> I'm currently writing a 3d racing game (being my first attempt at 3d), >> and I was wondering how you go about treating 2d sprites as 3d objects. >> For example, games like duke nukem 3d or vrally (with its track side >> detail). > >To put a sprite in a 3D world, you must have figured out its world coordinates. Once you've got >these, you transform them using the standard 3D transformation equations to get the X and Y screen >coordinates, and the OT priority. > >Assuming you've set your World->Screen Matrix up (as you do when you call GsSetRefView2), then you >need to do the following: > >H is your projection distance that you set with GsSetProjectionDistance(); > >extern MATRIX GsMATRIX; > >VECTOR spritePosition,transformedPosition; > >spritePosition.vx = sprite's X position in world coords >spritePosition.vy = sprite's Y position in world coords >spritePosition.vz = sprite's Z position in world coords > >ApplyMatrixLV(&GsMATRIX,&spritePosition, &transformedPosition); > >if(transformedPosition.vz >= 0) { // If less than 0, then it's behind the camera > sprite.x = transformedPosition.vx * H / transformedPosition.vz; > sprite.y = transformedPosition.vy * H / transformedPosition.vz; > priority = transformedPosition.vz >> (14 - OTLENGTH); > // Where OTLENGTH is from 1 to 14, remember > GsSortSprite(&sprite,&myOT[GsActiveBuff()], priority); >} > > >Erm.. That's all off the top of my head though - let me know if it works! > >Cheers, > >James > >-- >== James_Russell@scee.sony.co.uk +44 (171) 447-1626 >== Developer Support Engineer - Sony Computer Entertainment Europe > >C++ programmers do it with private members and public objects. Probably pointless posting this unless James goes into the office over the weekend, otherwise I'll just hassle him on Monday (that is if they will let me in past the PSX3 dev kit!) When you scale down camera-relative z-depth of an object prior to placing it into the OTable, you shift the depth to turn the 16bit depth to match the OT depth. ie, OT length 1<<10 Sort object, but shift by (16-10) = 6 With the sprite stuff with the routine you put up you shift it from a z-depth of 14, ie, OT length 1<<10 Sort 3d sprite, but shift by (14-10) = 4. Why the difference? Tis giving me a headache. btw, ve currently got some dodgy Jap schoolgirls running around the game now :) Rob