二维碰撞,如何传递力量?

时间:2014-06-23 12:30:14

标签: java android collections physics

我在这里有3个主要元素。 动量,质量和动量旋转。

弥撒是通过以下方式解决的:

this.mMass = (this.getHeight() + this.getWidth()) / 2.0f;

我已经创建了一个系统,可以在透明的png周围自动创建多边形并完美地检测碰撞(具有高性能),但现在我仍然坚持如何在碰撞时施加力。

我使用LibsGDX,但没有关于如何使用多边形检测碰撞以及如何在任何地方处理它们(手动不使用他们的世界)

只需要成为基本的碰撞力量,当我在网上看时,一切似乎都太复杂了!

到目前为止我所拥有的......

//Collision detection - loop though all physical objects.
    for(PhysicalObject physicalObject1 : AllPhysicalObjects)
    {
        for(PhysicalObject physicalObject2 : AllPhysicalObjects)
        {
            //Check that it's no trying to collide with it-self.
            if(physicalObject1 != physicalObject2 && physicalObject1.mIsCurrentlyPhysical)
            {
                if(Intersector.overlapConvexPolygons(physicalObject2.mPolygon, physicalObject1.mPolygon))
                {
                    //Functions.out("Class:" + eachPhysicalObject.getClass().toString());
                    //Now the fucking collision detection...
                    //Gonna be hard, but worth it when done right.

                    //Get the amount of momentum from the first physical object.
                    float physicalObject1Momentum = physicalObject1.mMomentum - physicalObject2.mMass;
                    float physicalObject2Momentum = physicalObject2.mMomentum - physicalObject2.mMass;

                    //If the momentum is negative, reverse the direction the object is going in.
                    if(physicalObject1Momentum < 0.0f)
                    {
                        //Reverse the direction of object1.
                        physicalObject1.setMomentumRotationRotation(Functions.getRotationalMaxMinStatic(180f, physicalObject1.getMomentumRotation()));
                        //Decrease the momentum of object2.


                    }
                    else
                    {
                        //Slow down the physical objects 1 momentum.
                        physicalObject1.increaseMomentum(-physicalObject1Momentum);

                        physicalObject2.increaseMomentum(physicalObject1.mMaxMomentum);
                        physicalObject2.setMomentumRotationRotation(Functions.getRotationalMaxMinStatic(180f, physicalObject1.getMomentumRotation()));
                    }



                    //Compare both momentums.



                    //Compare mass.

                }
            }
        }

    }
}

0 个答案:

没有答案