Path: chuka.playstation.co.uk!news From: Robert Swan Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: 3D Terrain, Again Date: Thu, 13 Aug 1998 14:15:06 +0100 Organization: I wish! Lines: 63 Message-ID: <35D2E6DA.57E1@mdx.ac.uk> References: <6qibl4$ldg20@chuka.playstation.co.uk> NNTP-Posting-Host: nova.mdx.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01 (X11; I; SunOS 5.5 sun4u) Nathan Miller wrote: > > ...with a focus on outside uneven terrains. > Your help, again, will be greatly appreciated. Ive got some collision detection going in my game based on an uneven terrain, but you can really help yourself by limiting yourself to certain things when creating the level (for example in mine the world is basicaly a grid with each vertex raised or lowered. Then its a simple enough case to find out the height at any particular point (included code from adventure game - ) this assumes that my grid is made up of cells, each of which is 512x512 units large Also >> 9 is division by 512 (which effectively takes a coordinate in the world units, and turns it into a coordinate in cell units. u_long calculteheight(u_long tx, u_long ty) // notice only handles positive :) thats deliberate in my world { long tCornerHeight[4]; long tHeight1, tHeight2; u_long tCellX = tx>>9; u_long tCellZ = (19-ty)>>9; // 19-ty because the array holding the ground data (20,20) incidentally starts from top left corner (when viewed from overhead) but the model starts from the bottom left (when viewed from overhead) so merely -ve y value HEIGHTSTRUCT *start = (HEIGHTSTRUCT) Addressofheightarray; // HEIGHTSTRUCT in my case is an array [21][21] large (there are 20x20 cells, but a height assigned at each corner, so 21x21 for height array tCornerHeight[0] = (start[20-tCellZ][tCellX]) << 4; tCornerHeight[1] = (start[20-tCellZ][tCellX+1]) << 4; tCornerheight[2] = (start[19-tCellZ][tCellX]) << 4; tCornerHeight[3] = (start[19-tCellZ][tCellX+1]) << 4; tHeight1 = CalcHeightBetween2points(tCornerHeight[0], tCornerHeight[1], tX%512); tHeight2 = CalcHeightBetween2points(tCornerHeight[2], tCornerHeight[3], tX%512); return -CalcHeightbetween2poitns(tHeight2, tHeight1, tz%512); } long CalcHeightbetween2points(u_long tHeight1, u_long tHeight2, u_long tOffset) { u_long tHeightMultiplier = (tHeight1 * (511-tOffset) + (tHeight2 * tOffset); return (long) (theightMultiplier >> 9); } Having read through that, it does look messy I know, but does work. Basically it finds out the height at each corner of the current cell, and returns a value which is based on all four corners, weighted more heavily to those that you are closer. Its a pretty quick routine i think... Robert Swan rs108@mdx.ac.uk