Archived

This topic is now archived and is closed to further replies.

Mythar

Z Buffer...

Recommended Posts

Reading the z buffer value.. Code : ddsd.dwSize := SizeOf(ddsd); if IZBuffer.Lock(nil, ddsd, DDLOCK_READONLY, 0)=DD_OK then begin try case ddsd.ddpfPixelFormat.dwRGBBitCount of // do stuff end; finally IZBuffer.Unlock(nil); end; end; What i need is the actualy Z value of a poly at any given point in the buffer. The point is when moving a "character/Camera" over a landscape, it should follow the terrain, according to the terrain-mesh. Idea is to place a camera that looks stright down at the x,y position of were the Character is standing, and then read the z value from the zbuffer, to determin the z cord. of the Character. The Camera that looks stright down, would of cuz not be showen to the player. However this meens rendering the sceen 2 times for eatch move the character dose. If any has a better idea of how to move over a terrain, let me know I first tryed to make a Map of the terrain based of all the z values. However this makes the Characters movement seem likes walking up and down staires, method simply not precise enuf. And when adding other Meshes to the sceen, like rocks etc. the z cord. simply is not good enuf.

Share this post


Link to post
Share on other sites
Just move? You can simply give a character an x- y- zposition, and whenever you load a map, you specify a starting point. Then just move!
If you landscape is not flat, and you''re afraid that the character will move through it, there are other techniques than reading the ZBuffer. You could do Collision Detection on the landscape, for instance.

.lick

Share this post


Link to post
Share on other sites
Yeah, don''t mess with the z-buffer. Thats likely to be slow and unreliable.

Instead you''re going to have to do a bit of maths. If your terrain is a regular height-field then this should be pretty easy, just take the x-z position of the character and look it up in the height-field. If its an irregular triangular mesh then you could try doing a ray-pick to determine what triangle/s your character is standing on, and get the height from them.

Share this post


Link to post
Share on other sites
First off, the terrain is not flat, but Very iregular.

The "Height Map" im currently using looks something like this :

(Sample values for the z cord, in a Grid)
100 110 150 090 ...... etc
100 120 170 080 ...... etc
etc

So if i want to know the z value in grid 1,0 i look up the values and get a square (2 polys) :

110 - 150
! !
120 - 170

This suqare is always 64x64 so I can calc the z value within the
grid.

The math i use for this is very simply and not very good as
I get the "walking up and down staries" effect, i need a
more smoth movement.
That mush for the basic terrain, but how about moving accros
rocks, tree stumps, and VERY complex meshes with so many polys
that there is no way u can make a z map of it the same way u
can with the base grid.

Collision Detection, u say, well im not sure how to do this.
But i guess to do this u would need to make a box around the
character and see how it collide with not just the terrain but
with the entire sceen, that is, outdoor meshes like trees, rocks, inside buildings etc.


Let me know if u have any ideas

[edited by - Mythar on May 3, 2003 12:22:38 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''d suggest you first perfect walking over the landscape then worry about objects.

Share this post


Link to post
Share on other sites