Sign in to follow this  
juxie

Is there a problem with my update loop?

Recommended Posts

juxie    122
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
chipmeisterc    268
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
juxie    122
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
juxie    122
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

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