Advertisement

Pogo stick physics ... again

Started by July 04, 2004 03:33 AM
22 comments, last by Luke Miklos 20 years, 4 months ago
edit: Check out the edit!

I checked the time-dependance code and it looks just like what you posted, except I didn't use temp variables. I stuck the calculation where you hade the temp variable. Here's the code (note: for some reason I call the guy's velocity vector heading. Must be too much Star Trek)
net_force.x = spring_force.x + surface_force.x + gravity_force.x;		net_force.y = spring_force.y + surface_force.y + gravity_force.y;		net_force.z = spring_force.z + surface_force.z + gravity_force.z;		net_force.find_magnitude();		//vector A;		acceleration.x = net_force.x / MASS;		acceleration.y = net_force.y / MASS;		acceleration.z = net_force.z / MASS;		acceleration.find_magnitude();		heading.x += acceleration.x * i;		heading.y += acceleration.y * i;		heading.z += acceleration.z * i;		heading.find_magnitude();		position.x += heading.x * i;		position.y += heading.y * i;		position.z += heading.z * i;


I know I'm going at this bass-ackward, but I needed to keep rotation code to a minimum, so that I would be working with a standard position on an uneven ground, test subject and control subject. I do like your idea, so I'll implement that once I get rotational motion in place.

So, you said that the spring system was all off. I set it up like this:
1. test for collision
2. if collision, get the surface normal of the ground
3. calculate force and direction spring exerts on mass-spring
4. calculate force that ground exerts on spring-mass
5. Add gravity, spring force, and ground force

If there is no collision, there is no ground force. When there is a collision, the force of the spring is calcuated by using the last position and the current velocity to figure out how much the spring compresses. Then, the center of the spring-mass is moved to that point. Notice that I don't do anything about the spring's "foot", I just consider it a certain distance from the center of the body and move according to the compression of that spring.

While typing that last sentence, I just thought about something. Maybe I'm forgetting to "remember" the last amount of compression the spring experiences, so that each frame it starts at no compression. I'll check my code again for that. I'll go do that now.

edit: Well, I changed that so it did fix some stuff. It now bounces more naturally. The code now says
if(collision){     //blah}else{     spring_compression = 0;}spring_compression += spring_compression_ratio * heading.magnitude;		spring_force.x = b.x * SPRING_CONSTANT * spring_compression;		spring_force.y = b.y * SPRING_CONSTANT * spring_compression;		spring_force.z = b.z * SPRING_CONSTANT * spring_compression;		spring_force.find_magnitude();


Wow, now I feel like I'm actually getting somewhere! It kinda works! It compiles, ship it! :)

[Edited by - DuncanBojangles on July 6, 2004 1:38:16 AM]
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
hey duncan,

your looping is wrong:

inside your loop, you are using "i" as your small amount of time, that is NOT what I said to do, look what "i" does in your code:

float small_amount_of_time = elapsed_time / 5; //I'm sorry, but the variable name was too good not to use. for(float i = 0; i < elapsed_time; i += small_amount_of_time){..   //you use "i" to multiply..}


when it should be like this:

float elapsedTime = timeSinceLastFrame();int numIterations = 5;float smallAmountOfTime = elapsedTime / numIterations; for(int i = 0; i < numIterations; i ++){..   //use "smallAmountOfTime" to multiply..}
Whatsoever you do, do it heartily as to the Lord, and not unto men.
Advertisement
Okay, I changed that little bit of stupidity :) , but now for some reason the simulation runs amazingly s l o w. And I'm getting segmentation faults, probably because of declaring variables inside of my loop. (I usually don't do that, I don't know why I did this time :( ) I'll check my code for weird timing errors, but I kept my units in SI, so the values should be correct.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
are you sure the code is running slow (few amount of frames per second) or is it just that you are feeding your physics model smaller amounts of time now & the motion is "slower" but accurate? just increase your speed factor by lets say... 5 or 10 & see what happens :)
That's not the way to fix this problem. All of my units are standard SI, so by scaling the value of time, my values are incorrect and the calculations are based on an incorrect value. I just got back from a vacation, so I'm going to be checking out my program again.

edit: Checked it quickly and found this error:
                surface_force.x = -(c.x * net_force.x);		surface_force.y = -(c.y * net_force.y);		surface_force.z = -(c.z * net_force.z);		surface_force.find_magnitude();


which should have been

                surface_force.x = (c.x * net_force.magnitude);		surface_force.y = (c.y * net_force.magnitude);		surface_force.z = (c.z * net_force.magnitude);		surface_force.find_magnitude();


This now solves one problem. He bounces in the right direction upon contact with the ground! I hadn't noticed this earlier, but now that it is corrected it feels a little better.

[Edited by - DuncanBojangles on July 11, 2004 9:58:05 PM]
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
bump



:) I've been workin' on it and came up with this little bit. Impulse is equal to the change in momentum, right? So Force_of_impulse = MASS * (velocity_2 - velocity_1) .
  surface_force.x = (c.x * (MASS * (heading.x - old_heading.x)));surface_force.y = (c.y * (MASS * (heading.y - old_heading.y)));surface_force.z = (c.z * (MASS * (heading.z - old_heading.z)));surface_force.find_magnitude();

This kinda works! c.* is the surface normal. Am I heading in the right direction, or am I completely off base?
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
Advertisement
what the heck is heading.x heading.y & heading.z ????

you should be using the forces to calculate the new acceleration/velocity/position, NOT THE OTHER WAY AROUND!!!!!

Anonymous Poster:
If you only looked at the previous post, then you'll have no idea what's going on. I am trying to find the impulse when the pogo stick comes in contact with the ground. Impulse is defined as the change in momentum, and momentum is defined as mass * velocity. I'm calling velocity "heading", so if you don't like it, I don't care. Using these definitions, this is the resulting equation:
impulse_force = mass * (velocity_now - velocity_then)

If what you mean is that I should be using the forces in the impulse equation, then the equation would look like this (force = mass * acceleration)
impulse_force = mass * time * (acceleration_now - acceleration_old)

But you can see that change in acceleration * time is just change in velocity.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
ok, then what is exactly is the impulse force needed for? I can't think of a darn thing... & no I didn't read just the last post.
I was using the impulse force to figure out how to move the guy once he has collided with the ground. Since the momentum of the ground does not change, and according to the law of conservation of momentum, I get the impulse, which describes the force the guy experiences when he collides with the ground. If you know of a better way to find the force acting upon the guy when he collides with the ground, do tell. So far I can find the force of gravity and the force the spring of the pogo stick exerts on the guy, but I'm having trouble getting the force the ground exerts on the guy right. So if you can help, please help. I'm pretty much stuck.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.

This topic is closed to new replies.

Advertisement