Sign in to follow this  
Dave84311

Calculating Y Position

Recommended Posts

Dave84311    154
I have a tad of an issue. I am wanting to calculate the Y position a character should have. This character needs to be able to walk on land, climb up land and go down slopes. Right now the character is being moved across a plane whereas the scenery and plane are in a static position. I can easily get the Y position of the character, but I need to get the Y position of the point where the character is over. D3DXIntersect() isn't working too great so I am looking for an alternative.

Share this post


Link to post
Share on other sites
jollyjeffers    1570
I'm in quite a hurry (it's 9pm and I'm still at work [headshake]) but to get you started you probably want to look at the plane equation (searching Wolfram's 'MathWorld' website is usually a good start).

aX + bY + cZ + d = 0 works for triangles (which are convex and coplanar) and can be rearranged accordingly. Working out the plane equation from a point and a normal vector is easy but even easier if you use D3DX. Once you have the coefficients you can plug in the known values (e.g. X and Z) and rearrange for the unknown - Y - and you're sorted.

I can move this to the 'Maths & Physics' forum if you'd like a better explanation?

hth
Jack

Share this post


Link to post
Share on other sites
Dave84311    154
Thanks for your reply.

What I mean more then anything for starters is getting the base point under my character so gravity has no effect. I understand the equations of planes e.g. Ax + By + Cz = D even to do that I would require 3 points and not being able to even get one it wouldn't help.

This is a DX question more then anything. I was pretty sure using D3DXIntersect() I could get it working because I have before; Out of no where it stopped working.


Lets say I have a plane

20 x 20 which is located at 0, 0, 0

Now I have a camera located at

-1, 0, -1

The camera should fall off the map if treated with gravity correct? How do I detect if the object is still on the map - not using bounding boxes or any of that junk because the plane can be unevenly formed or curved making the character unable of traversing upwards.

Example code would help probably most.

Thanks.,

Share this post


Link to post
Share on other sites
adriano_usp    396
Quote:
Original post by Dave84311
I have a tad of an issue. I am wanting to calculate the Y position a character should have. This character needs to be able to walk on land, climb up land and go down slopes.

Right now the character is being moved across a plane whereas the scenery and plane are in a static position. I can easily get the Y position of the character, but I need to get the Y position of the point where the character is over.

D3DXIntersect() isn't working too great so I am looking for an alternative.

If you want to use D3DXIntersect() to get the vertical distance (in world Y-axis direction) from an irregular terrain mesh, you could do something like this:


D3DXVECTOR3 vRayDir ( 0.0f, -1.0f, 0.0f ); // vertical, from top to bottom.

D3DXVECTOR3 vRayPos; // the character's center, for exemple.

BOOL Inters; // TRUE if the ray intercepts the terrain.
FLOAT pDist; // distance between vRayPos and the terrain (in vRayDir direction).

D3DXIntersect( mesh, // terrain mesh
&vRayPos,
&vRayDir,
&Inters,
NULL,
NULL,
NULL,
&pDist,
NULL,
NULL );

if ( Inters )
{
// Supposing no gravity and the character's center is 100 over the terrain. So, the character could follow the terrain surface by doing this:
centroPerson.y = centroPerson.y + (100 - pDist);
}





I hope it helps.

Share this post


Link to post
Share on other sites
Dave84311    154
Yes, I wrote something similar to that, I plugged in the characters position 0, 0, 0 when at that coordinate. However when walking no change occurred. I'm not sure if me not setting my character far above or below the map has anything to do with it. It worked before but oddly it stopped working a couple days back when adding newer components. After two days of messing with it I decided to post here.

Anyone know why it wouldn't work or where I should set it.

Share this post


Link to post
Share on other sites
Dave84311    154
I now know why it doesn't work. We imported new models for our game, the map however has only certain faces that can be checked for intersections. Now I am going to have some fun trying to find out what side does what.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this