Path: chuka.playstation.co.uk!news From: "Harvey.C" Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: 2d sprites in a 3d world Date: Sun, 29 Nov 1998 08:39:21 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 60 Message-ID: <36610839.30F5@mdx.ac.uk> Reply-To: hc054@mdx.ac.uk NNTP-Posting-Host: stu-dialup9.mdx.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.04Gold (Win95; I) >> 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 Hi all. I managed to get this code working, and sure enough I got my sprite on the screen with the correct x,y position and depth priority. However, it positions the sprite relative to the camera, not the world. For example, my game uses a chase cam for the car (using the super field). When I display the sprite at say 0,0,5000 it will position it in front of the of the camera regardless of the position or direction of the camera! How would I go about modifying the above code so that a sprite can be positioned and drawn in the world like other 3d objects? -- Regards | E-mail: hc054@mdx.ac.uk Harvey | ICQ: 4269478