Sign in to follow this  
SFA

Projecting a Curve along a Vector

Recommended Posts

I'm currently writing a procedural walking system, where the path of each 'step' is governed by a target point which represents the ideal position of the foot, with inverse kinematics configuring the rest of the bones in the leg as the afformentioned foot traces the path of the target. If you look at the diagram below, the top shows the path of the target along a flat surface, where (a) is the start point, (b) is the end point and the height and distance of the 'step' being (h) and (d) respectively. My code currently looks like this:

Actor::takeTestStep()
{
   float stepResolution = 150.0;     //amount of frames in the curve
   float stepLength = 30.0;          //length of step
   float stepHeight = 30.0;          //height of step

   float prev_x = tween.x;
   float prev_y = tween.y;

   Vector3 forward = V2CV(Brain[0].GetForward());	//get forward vector of creature

   tween = bezier_stride.evaluatePoint(stride_frame / stepResolution);

   sph_pathPosition.mSphereNode->translate((tween.x - prev_x) * stepLength * forward.x, (tween.y - prev_y) * stepHeight * (1-forward.y), (tween.x - prev_x) * stepLength * forward.z);       //translate target sphere

   if(stride_frame < stepResolution)
	stride_frame++;
}





Which is fine, as long as the creature is moving across a flat surface. The algorithm simply projects a curve along the forward vector of the creature, with height stepHeight and distance stepLength. The problem is that this doesn't work when the creature's up vector isn't parallel to the ground's normal vector i.e the creature isn't on a flat surface. What I want to happen is similar to the second diagram - the curve remains the same, just rotated. What currently happens (due to the 2D nature of the algorithm) is that the curve gets distorted. Can I extend this algorithm so that the curve is always the same, just rotated - or am I going about this in the wrong way?

Share this post


Link to post
Share on other sites
hi. could you be more specific about how your curve is distorting? Maybe a new picture or something? I cannot try to tell you what the problem is if i don't see the wrong result.

Share this post


Link to post
Share on other sites
I haven't got access to my code at the moment, so I can't draw a corresponding diagram of the distortion. I'll try and explain it:

tween = bezier_stride.evaluatePoint(stride_frame / stepResolution);

The bezier evaluator returns the (0,1) x and y component of a pre-defined curve based on the current frame / number of frames. So if the pre-defined curve is similar to the first diagram, you'd get:


-------------
[i]bezier_stride.evaluatePoint(1 / 150) = 0,0 (i.e the start of the curve)

and

[i]bezier_stride.evaluatePoint(150 / 150) = 0,1 (i.e the end of the curve)

So plotted across all values, you get a 2D curve.
-------------


So we have code that describes the stride path of the creature's feet. What I want to do is combine this curve with the creature's forward vector, so that when it takes a step its along its current trajectory. For flat surfaces, this works fine - the Y component of the forward vector is always 1, whilst X and Z describe the direction across the plane in which the path will occur.

However, when I introduce a non-flat surface (rolling hills for example), the Y component of the forward vector is not 1. For example, lets say the forward vector is

Vector3(0,0.5,0)

So in other words the creature is on a slope.

If we look at the corresponding equation I currently use, it simply doesn't work. Something is missing, or its just inadequate.

mSphereNode->translate((tween.x - prev_x) * stepLength * forward.x, (tween.y - prev_y) * stepHeight * (forward.y), (tween.x - prev_x) * stepLength * forward.z); //translate target sphere

So whilst I want to get the result I see in the second diagram, its not going to happen I don't think by using this method.

Share this post


Link to post
Share on other sites
Quote:
Original post by SFA

However, when I introduce a non-flat surface (rolling hills for example), the Y component of the forward vector is not 1. For example, lets say the forward vector is

Vector3(0,0.5,0)



First thing, you are not using a normalized vector for the forward vector. If you say that its a forward vector, when moving on a flat plane, the forward.y component should be always 0, not 1. Or am I missing something?

so when you have your sphere on a slope, then the forward.y != 0, so when is that happening, you have to compute the angle between the slope and the ground, and just rotate the computed tween values with the computed angle around an axis orthogonal to your forward vector. After the values are rotated, then you can ignore forward.y and just compute the rest for x and z coordinates. If I've been unclear, please ask me more :D. hope it helps.

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