Skip to main content
gamedev.net
🔒 Locked

Finding vector/plane intersection...

Started by AstroTurf Aug 28, 2000 at 5:23 PM 5 replies 600+ views
Original Post
AstroTurf
AstroTurf
OK, I am just totally drawing a blank, and I''m really hoping to get some help. I am creating a tile engine in D3DIM. I''ve gotten the texturing and color-key transparency working. Now, I want to be able to move the sprites according to the height of the tile that they are on. The tiles are broken into 4 triangles (N, E, S, W) to allow for a height change within the tile. I need to figure out the ''Z'' coordinate for the planes, with a given (x, Y)... I know where the sprites are supposed to go in the world, but I want to find the height so I can shrink them as they go lower, etc... I don''t know if I''ve explained it all that well, but it''s my best try. Let me know if you can help at all, or if you need more information from me. TIA!
baskuenen
baskuenen
I don''t know if the plane intersection is really what you need (I don''t understand your above explaination 100%), but you could check out my homepage tutorial: Plane Collision.

AstroTurf
AstroTurf
Well, I''ve read through your tutorials...
I''ve also found some others that say approximately the same thing. I guess I don''t understand vectro/matrix/plane math that well. Could you possible give me a ''for instance'' with a triangle and a line?
I have some images to illustrate what I''m getting at...
Typically, someone rendering a tile view in D3D would make a quad by creating 2 triangles as such......


I''ve broken this down a bit more...



I use the vertices in this order...

Vertex 0: (0, 32, 0)...
Vertex 1: (32, 32, 0)...
Vertex 2: (16, 16, 16)...
Vertex 3: (32, 0, 0)...
Vertex 4: (0, 0, 0).

Now, I have (x, y) of (16, 8)... Which is here:


Now, how do I determine the Z-coord of this point when it is in the quad?

Please be detailed, as I''m a bit slow on this subject... Thanks for your help.....

baskuenen
baskuenen
Maybe the full version of this plane algorithm is not needed here.

Have you tried calculating the distance to a point do (1-distance) and multiply with it''s height.
This is not entirely correct, but I''m a little short on time at the moment...

zedzeek
zedzeek
here is asimple method i worked out a while ago with pencil + paper and it works. btw i think plane collision was a bad choice of words

DIST == the distance between the heightmap pts posX+Z == the position of the pt u wanna find the height of

int nx=int( posX / DIST);
int nz=int( posZ / DIST);
float distsquared = DIST*DIST;
int tempx=int(posX)%DIST;
int tempz=int(posZ)%DIST;

float A = ((DIST-(tempx%DIST)) * (DIST-(tempz%DIST))) / distsquared;
float B = ((DIST-(tempx%DIST)) * (tempz%DIST)) / distsquared;
float C = ((tempx%DIST) * (tempz%DIST)) / distsquared;
float D = ((tempx%DIST) * (DIST-(tempz%DIST))) / distsquared;

float groundheight = ((terrainHeight[nx] [nz] *A)
+ (terrainHeight[nx+1][nz] *D)
+ (terrainHeight[nx+1][nz+1]*C)
+ (terrainHeight[nx] [nz+1]*B));
return groundheight;
AstroTurf
AstroTurf
Thanks guys...

I figured that it was a pretty bad title after I had already posted my question, ut I first thought I would use the collision detection stuff. I tried to edit my message, but I can''t change the title to the post... =\


Thanks for all of your help...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.