Jump to content
  • Advertisement
Sign in to follow this  
juxie

Is there a problem with my update loop?

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

Hi, Just want to make sure my logic is right. 1. get current state position and velocity
_pos = _currPos;
_vel = _currVel;

2. calculate forces using current state
_force += gravity * mass;
_force += springForce;
_force += windForce;

3. calculate velocity and attempted position
 
_attVel = _currVel + (_force / mass) * dt;
_attPos = _currPos + _attVel * dt

4. check collision detection using _attPos 5. if collision, response, put _attPos to the point of collision
 
_attPos = pointOfCollision;

6. get collision normal
normal = _attPos - spherePos;

7. calculate impulse
Vn = dot(_attVel, normal) * normal;
Vt = _attVel - Vn;
 
_attVel = Vt - 0.1f * Vn;

8. Finalize step
_currVel = _attVel;
_currPos = _attPos;

9. repeat 1 Please advise. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Why do you need step one:- To get the current position and velocity??...looking at your steps you never use these local variables anyways :) Anywhere where you have to syncronise local variables to member varaibles is generally a bad idea and can lead to bugs.

Share this post


Link to post
Share on other sites
Quote:
Original post by chipmeisterc
Why do you need step one:- To get the current position and velocity??...looking at your steps you never use these local variables anyways :) Anywhere where you have to syncronise local variables to member varaibles is generally a bad idea and can lead to bugs.


The step one is used in the calculation of spring force but it is also a member variable.
That means it is member of the class that contains currPos.
And _pos and _vel are never used to synchronise anything.

So i guess this is logic is correct?

Share this post


Link to post
Share on other sites
Quote:
Original post by chipmeisterc
surely _currentPos and _currentVel are your member variables, if so why do you need to assign these to _pos and _vel ?


I need to implement RK4 so _pos and _vel will be used as my temporary position as i move each step of RK4.

Share this post


Link to post
Share on other sites
Force should not accumulate over time.


force = gravity * mass + springForce + windForce;

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!