All pastes #80991 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-07-07 00:48 UTC
rendered paste body
                case PhysicsShapes.Circle:

                    Vector3 Norm = new Vector3();

                    Vector3 Norm1 = new Vector3();
                    Vector3 Norm2 = new Vector3();

                    Vector3 Tang1 = new Vector3();
                    Vector3 Tang2 = new Vector3();

                    Norm = this.position - cObject.position;
                    Norm.Normalize();

                    Norm1 = (Vector3.Dot(velocity, -Norm)) * -Norm;
                    Norm2 = (Vector3.Dot(cObject.velocity, Norm)) * Norm;


                    if (Norm1.X == 0 && Norm1.Y == 0)
                        Norm1 = Norm2;
                    else if (Norm2.X == 0 && Norm2.Y == 0)
                        Norm2 = Norm1;

                    Tang1 = Norm1 - velocity;
                    Tang2 = Norm2 - cObject.velocity;

                    mVector1 = Tang2 + Norm2;
                    mVector2 = Tang1 + Norm1;

                    mVector1.Normalize();
                    mVector2.Normalize();

                    float MyVel1 = ((((mElasticCoefficient + 1) * cObject.mMass * -cObject.velocity.Length()) + (velocity.Length() * (mMass - (mElasticCoefficient * cObject.mMass)))) / (mMass + cObject.mMass));
                    float MyVel2 = ((((cObject.mElasticCoefficient + 1) * mMass * velocity.Length()) + (-cObject.velocity.Length() * (cObject.mMass - (cObject.mElasticCoefficient * mMass)))) / (mMass + cObject.mMass));

                    velocity = mVector1 * MyVel1;
                    cObject.velocity = mVector2 * MyVel2;

                    break;

            }