Jump to content
  • Advertisement
Sign in to follow this  
HackSaw220

Direction Vector to Plane Calculation

This topic is 4329 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

Hello, I have a question about calculating a direction vector based on the plane my player is standing on. I was planning on using the plane's normal and 90 degrees to that to calculate the direction vector on the plane the player is standing on. _________ <--- this planes normal is 0,1,0 ..../ .../ ../ <--- this planes normal is 0,.5,.5 ./ / How do I get the direction vector to calculate perpendicular to the planes normal? I'd like to adjust the direction vector with the vector resulting from this calulation. Should I use some algebra and find the vector based on a dot value and a vector? My rendering engine works great as long as the surface planes are flat. I tried using the cross product of a right vector and the planes normal but that didn't work to well. Player stair stepped up the smooth plane. Camera bounced up and down a bit. Is there an industry norm that I should be using? Thanks in advance for your reply. I still get a little camera bounce with this code as well and the player digs into the plane at the top of the plane. Here's a code snippet of what I have:
if (gsPlayer.playerState == PLAYER_FORWARD )
{
     gsPlayer.m_Dir.x = gcCamera.m_LookAt.x;
     gsPlayer.m_Dir.y = gcCamera.m_LookAt.y;
     gsPlayer.m_Dir.z = gcCamera.m_LookAt.z;

     gsPlayer.m_Velocity.x = VELOCITY;
     gsPlayer.m_Velocity.z = VELOCITY;

     for (x=0; x &lt; MAX_PLANE_COUNT; x++)
     {
          if (gsPlane[x].isActive == 1 )
          {
               gcCollision.PlayerToPlane(&gsPlayer, &gsPlane[x]);
          }
     }
     if ( gcCollision.dPlaneHit )
     {
          if ( (gcCollision.dot_d &lt; 0.50f) && (gcCollision.dot_d &gt; 0.00f))
          {
               // gravity change player going up a plane
               gsPlayer.m_Velocity.y = -GRAVITY;

               gsPlayer.m_Dir.x = gcCollision.dPlaneNormal.x;
               gsPlayer.m_Dir.y -= gcCollision.dPlaneNormal.y;
               gsPlayer.m_Dir.z = gcCollision.dPlaneNormal.z;
               gcMath.VectNormalize(&gsPlayer.m_Dir, &gsPlayer.m_Dir);
         }
     }

//additional plane checking for other plane collisions


One final note, there is no bounce of the camera when the forward vector of the camera is at (0,0,-1). Player just goes up the plane a little slower than when on a level plane. [Edited by - HackSaw220 on November 16, 2006 10:32:10 PM]

Share this post


Link to post
Share on other sites
Advertisement
First, use [ code ] and [ source ] tags for source code. (they do slightly different things).

Quote:
Hello, I have a question about calculating a direction vector based on the plane my player is standing on. I was planning on using the plane's normal and 90 degrees to that to calculate the direction vector on the plane the player is standing on.


There is no "the direction vector of the plane". Planes are two-dimensional.

Maybe I just don't understand what it is you are trying to do.

Share this post


Link to post
Share on other sites
I'm trying to get my player to clip properly on a plane that is sloped.
So, if you are looking straight ahead on a flat plane the plane is level.

If you are going up a hill there is a slope.

Moving forward is the direction vector so this vector's Y value (and the two others x and z ) would need to be adjusted so the player goes upward and have gravity applied at the same time so they don't go flying up into the air.

I'm just looking for a way to adjust the players direction vector parallel to the plane they are standing on along with the direction the camera is orientated.

Perhaps when I calculate the planes normal I should keep track of the two vectors I cross to get the normal? Then use those to determine a vector to adjust the players direction vector?

Did I just answer my own question? O-o

Share this post


Link to post
Share on other sites
have your tried:

(plane_normal ^ walking_direction) ^ plane_normal
or
plane_normal ^ (plane_normal ^ walking_direction)

^ is vector cross product,

I might be wrong about the order of the cross product but I seems to remember something like that works.

Share this post


Link to post
Share on other sites
Still bouncing. Using the planes y normal seems to work.

I think it's bouncing is due to the gravity stuff I'm doing. Looks like the player breaks through the plane and then get's pushed back up out of it and that gets rendered as it's happening.

Thanks for the help.

Share this post


Link to post
Share on other sites
Often enough, you can get away with moving the player in the direction he's facing, paying no attention to collisions, then apply gravity and floor-bounding afterwards to reposition him.

If the player is under the constant downwards acceleration of gravity, and is, each frame, checked against the plane by something along the lines of:
float ground_y = GroundY(player.x, player.z);
if (player.y < ground_y) player.y = ground_y
then there's no need to mess about with directional derivatives and cross-products.

Regards
Admiral

Share this post


Link to post
Share on other sites
Took an alternative approach. Little more CPU intensive but works for both flat ground planes and angled. Works real smooth too. There is a slight camera bounce when up against a wall but it's barely noticeable unless you are really looking for it. I'm merely popping the player back up out of the ground plane.


gsPlayer.m_Velocity.y = 0;
gsPlayer.m_Dir.y = 0;

int inPlane = 1;
for (x = 0; x < MAX_PLANE_COUNT; x++)
{
gsPlayer.m_Velocity.y = GRAVITY;
gsPlayer.m_Dir.y = -1.0f;

if (gsPlane[x].isActive == 1 )
{
gcCollision.PlayerToPlane(&gsPlayer, &gsPlane[x]);
if ( gcCollision.dPlaneHit )
{
while (inPlane)
{
gsPlayer.m_Dir.y = 1.0f;
gsPlayer.m_Velocity.y = 0.125f;
gcPlayer.UpdatePosition(&gsPlayer);
gcCollision.dPlaneHit = 0;
gcCollision.PlayerToPlane(&gsPlayer, &gsPlane[x]);
if (!gcCollision.dPlaneHit)
{
gsPlayer.m_Velocity.y = 0.0f;
break;
}
}
}
}
}




Now if I could just get my darn camera to work decent I'll be good to go.

Thanks for all the input. :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!