Sign in to follow this  
SFA

Tracing a Circular Path

Recommended Posts

I'm trying to code an iterating semi-circular path along an arbitrary surface. This path will be a guide for an inverse kinematics based walk cycle, where the foot of the creature follows the path. I've got the IK setup, I've got the physics setup, and I've sort of got the path tracing algorithm working. Take this diagram for example : Diagram There we have the 'target' for the foot (red dot). It moves in a semi circle in the x direction, and will only stop when it collides with the surface (green line). Then it will reset and next time a step is taken, it will start at that origin. So switching everything off appart from the target and landscape, you could just have a ball moving across the surface in arcs. This is the test code I've got (some of it shamelessly borrowed from these very forums):
//Update the current step


void Target::incrementStepCycle(float time)
{
if(b_stepFlag == true)   //i.e a step is being taken
        {	
	Vector3 mVelocity = CircleAnim(ticks, 60, Vector3(0,0,0),50,1.570,-1, time);
	physBody->setVelocity(mVelocity);
	ticks=ticks+1;
        }
}



//Calculate next position on circle


Vector3 Target::CircleAnim(int ticks, float period, Vector3 origin, int radius, float initial, int cw, float time)
{
float arc = cw * 6.28318f;			// arc in cw/ccw
float rop = (1.0f / period);			// reciprical of perdiod

// constant motion on a circular path
int posX = origin.x + (int)(radius * cos(initial + arc * ( (ticks * rop))));
int posY = origin.y + (int)(radius * sin(initial + arc * ( (ticks * rop))));

return Vector3(posX,posY,0);
}

Where : ticks = current frame period = total frames origin = origin of circle radius = radius of circle initial = starting point (Radians) cw = clockwise/couter clockwise time = time since last frame The problem I have is that my simulation is real-time, and therefore the circular path drawn is dependant on the frame rate. This obviously causes problems, as when a highly detailed creature is in frame the paths traced become gigantic, and when I look at a low poly part of the landscape the circular path is very small. I'm just wondering if this is the best method for doing this? If so, where would I use the time variable to make the whole thing fps-independant? The two main variables I want control over are the radius of the circle traced (i.e the length of each creature's step), and the speed by which the target moves (i.e the step size between points traced). Any help would be great. [Edited by - SFA on September 8, 2006 12:46:32 PM]

Share this post


Link to post
Share on other sites
Maybe gamedev doesn't support welsh?

More seriously, try making your post without including ANYTHING that isn't letters and numbers. Maybe the use of less than greater than, or other symbols, is screwing it up.

Share this post


Link to post
Share on other sites
Quote:
The problem I have is that my simulation is real-time, and therefore the circular path drawn is dependant on the frame rate. This obviously causes problems, as when a highly detailed creature is in frame the paths traced become gigantic, and when I look at a low poly part of the landscape the circular path is very small.


Seperate physics from rendering. The physics loop should run at a fixed frequency, and generally be ahead of the render loop in "time". When you render, you interpolate your state based off of the physics models.

If you can keep rendering as a pure output, your simulation becomes much more stable.

It is possible you are well beyond the above advice, and I simply misunderstood your problem. :)

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