Jump to content
  • Advertisement

Archived

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

AstroTurf

Finding vector/plane intersection...

This topic is 6655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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.....

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!