Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 01 October 2012 - 06:41 AM
Posted 02 October 2012 - 05:50 AM
Posted 02 October 2012 - 06:33 AM
private void CollidingE(Vertex m, Vertex v1, Vertex v2, Vector2 cv) //cv = Collision Vector { if (v1.active == false && v2.active == false) { m.pos += cv * fraction; return; } float t; if (Math.Abs(v1.pos.X - v2.pos.X) > Math.Abs(v1.pos.Y - v2.pos.Y)) { t = (m.pos.X - cv.X - v1.pos.X) / (v2.pos.X - v1.pos.X); } else { t = (m.pos.Y - cv.Y - v1.pos.Y) / (v2.pos.Y - v1.pos.Y); } float lambda = 1.0f / (t * t + (1 - t) * (1 - t)); Vector2 v1pos = v1.pos; Vector2 v2pos = v2.pos; Vector2 mpos = m.pos; if (m.active == true) { if (v1.active == true && v2.active == true) { v1pos -= cv * ((1 - t) * lambda / 2.0f) * fraction; v2pos -= cv * (t * lambda / 2.0f) * fraction; } else if (v1.active == false && v2.active == true) { v2pos -= cv * (t * lambda) * fraction; } else if (v1.active == true && v2.active == false) { v1pos -= cv * ((1 - t) * lambda) * fraction; } mpos += cv * fraction; } else { if (v1.active == true && v2.active == true) { v1pos -= cv * ((1 - t) * lambda) * fraction; v2pos -= cv * (t * lambda) * fraction; } else if (v1.active == false && v2.active == true) { v2pos -= cv * (t * lambda * 2) * fraction; } else if (v1.active == true && v2.active == false) { v1pos -= cv * ((1 - t) * lambda * 2) * fraction; } } v1.pos = v1pos; v2.pos = v2pos; m.pos = mpos; }
private void UpdateVertices(List<Vertex> list) { Vector2 tmp; foreach (Vertex v in list) { Vector2 pos = v.pos; Vector2 oldpos = v.oldpos; Vector2 deltapos = v.deltapos; if (v.type == Vertex.NORMAL) { deltapos.X = 0; deltapos.Y = v.mass; deltapos -= (pos - oldpos) * 0.0001f;//0.0001f * (pos - oldpos); tmp = pos; pos += pos - oldpos + deltapos; oldpos = tmp; } else if (v.type == Vertex.TRAIN) { deltapos.X = 0; deltapos.Y = v.mass; deltapos -= 0.05f * (pos - oldpos); tmp = pos; pos += pos - oldpos + deltapos; oldpos = tmp; } else { pos = oldpos; } v.pos = pos; v.oldpos = oldpos; v.deltapos = deltapos; } }
Posted 02 October 2012 - 07:19 AM
{ v1pos -= cv * ((1 - t) * lambda / 2.0f) * fraction; v2pos -= cv * (t * lambda / 2.0f) * fraction; }Must be m/2 too:
mpos += cv * fraction/2,0f;
tmp = pos; pos += (pos - oldpos)* 0.9999f+(0,v.mass); oldpos = tmp;
Posted 02 October 2012 - 08:13 AM
Posted 02 October 2012 - 01:50 PM
if (v1.active == true && v2.active == true) { v1pos -= cv * ((1 - t) * lambda / 2.0f) * fraction; // (1-t)/2 v2pos -= cv * (t * lambda / 2.0f) * fraction; // t/2 ( t+(1-t))/2=1/2 half energy for edge } else if (v1.active == false && v2.active == true) { v2pos -= cv * (t * lambda/2.0f) * fraction; //half energy for edge } else if (v1.active == true && v2.active == false) { v1pos -= cv * ((1 - t) * lambda/2.0f) * fraction; //half energy } mpos += cv * fraction/2.0f; // if half energy for edge so must leav half energy to m
//redistribute energy to objects with different mass float c=1/(obj1.invmass+obj2.invmass); obj1.vec -= obj1.invmass*c/2*collision_vector; obj2.vec += obj1.invmass*c/2*collision_vector; //invmas=1/mass;
Edited by serumas, 02 October 2012 - 01:56 PM.
Posted 02 October 2012 - 03:31 PM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.