# Tracing a Circular Path

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

## 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 : 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 on other sites
Quote:
 Original post by SFA

Was that a question ?

##### Share on other sites
It posted empty for some reason. I'm trying to modify the post but it ain't working at the moment.

##### Share on other sites
maybe it's a riddle!!...humm, tough one

##### Share on other sites
EDIT : Got it to work in the end! :) A miss-placed forward slash was the culprit!

[Edited by - SFA on September 8, 2006 12:08:25 PM]

##### 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 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. :)

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013378
×