From 98ecb57cc60ce1c6401ac3e1f171c7adb8013155 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 7 Nov 2017 23:04:43 +0100 Subject: [PATCH] attractor physics works! --- examples/example02/Init.hs | 2 +- examples/example02/Main.hs | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/example02/Init.hs b/examples/example02/Init.hs index 5e05e08..30776e1 100644 --- a/examples/example02/Init.hs +++ b/examples/example02/Init.hs @@ -124,7 +124,7 @@ initPhysics = do disp <- newCollisionDispatcher config solver <- newSequentialImpulseConstraintSolver world <- newDiscreteDynamicsWorld disp bp solver config - setGravity world (V3 0 (-10) 0) + setGravity world (V3 0 0 0) return $ Physics bp config disp solver world initPhysicsObjects :: [V3 Float] -> IO PhysicsObjects diff --git a/examples/example02/Main.hs b/examples/example02/Main.hs index 81058b7..a351020 100644 --- a/examples/example02/Main.hs +++ b/examples/example02/Main.hs @@ -52,19 +52,20 @@ update dt = do sd <- getAffection let phys = physics sd physos = physicsObjects sd - -- mapM_ (\smallBall -> do - -- ms1 <- liftIO $ getMotionState (bodyRigidBody smallBall) - -- ms2 <- liftIO $ getMotionState (bodyRigidBody $ poBigBall physos) - -- r1 <- liftIO $ return . fmap realToFrac =<< getPosition ms1 - -- r2 <- liftIO $ return . fmap realToFrac =<< getPosition ms2 - -- let g = 0.0000000000667300 - -- m1 = bodyMass smallBall - -- m2 = bodyMass (poBigBall physos) - -- eta_sq = 0.1 ^ 2 - -- force = (g * m1 * m2 *^ (r1 - r2)) ^/ - -- (((r1 - r2) `dot` (r1 - r2)) + eta_sq) - -- liftIO $ applyCentralForce (bodyRigidBody smallBall) force - -- ) (poSmallBalls physos) + mapM_ (\smallBall -> do + ms1 <- liftIO $ getMotionState (bodyRigidBody smallBall) + ms2 <- liftIO $ getMotionState (bodyRigidBody $ poBigBall physos) + r1 <- liftIO $ return . fmap realToFrac =<< getPosition ms1 + r2 <- liftIO $ return . fmap realToFrac =<< getPosition ms2 + let g = 0.0000000000667300 + m1 = bodyMass smallBall + -- m2 = bodyMass (poBigBall physos) + m2 = 1000000000000000 + eta_sq = 0.1 ^ 2 + force = (g * m2 * m1 *^ (r2 - r1)) ^/ + ((sqrt (((r2 - r1) `dot` (r2 - r1)) + eta_sq)) ^ 3) + liftIO $ applyCentralForce (bodyRigidBody smallBall) force + ) (poSmallBalls physos) liftIO $ stepSimulation (pWorld phys) dt 10 Nothing posrots <- mapM ((\ball -> do ms <- liftIO $ getMotionState ball