hunk ./Physics/Hpysics/Utils.hs 164 +matScale :: FloatType -> Mat33 -> Mat33 +matScale l + (Mat33 + a11 a12 a13 + a21 a22 a23 + a31 a32 a33) + = + (Mat33 + (l*a11) (l*a12) (l*a13) + (l*a21) (l*a22) (l*a23) + (l*a31) (l*a32) (l*a33)) hunk ./Physics/Hpysics/Body.hs 5 - , getMass, getInertia, getRestitution, getShape + , getMass, getInertia, getRestitution, getShape, getPhantomBody hunk ./Physics/Hpysics/Body.hs 24 - } | StaticBody { shape :: !Shape } + } + | StaticBody + { shape :: !Shape + -- phantomBody is dynamic body which has the same shape and large mass and + -- moment of inertia. It's (for now) used for collision response + , phantomBody :: !Body + } hunk ./Physics/Hpysics/Body.hs 33 -isStatic (StaticBody _) = True +isStatic (StaticBody {}) = True hunk ./Physics/Hpysics/Body.hs 37 -mkStaticBody :: Shape -> Body -mkStaticBody s = StaticBody $ constructBoundingSphere s - +mkStaticBody :: FloatType -> Shape -> Body +mkStaticBody rest s = StaticBody + { shape = constructBoundingSphere s + , phantomBody = DynamicBody + { mass = 1e09 + , inertia = 1e09 `matScale` unit33 + , restitution = rest + , position = zeroVector + , rotation = unitVec4 + , linearVelocity = zeroVector + , angularVelocity = zeroVector + , shape = s + } + } hunk ./Physics/Hpysics/Body.hs 90 +getPhantomBody :: Body -> Body +getPhantomBody = phantomBody hunk ./Physics/Hpysics/Collision.hs 41 - | isStatic b2 = error "Not implemented" - {- - let - v1 = linearVelocity b1 - vRel = neg v1 - vRelNormScalar = vRel <.> normal - vRelNorm = vRelNormScalar `scale` normal - vRelNormNew = 2 `scale` vRelNorm - in if vRelNormScalar <= 0 - then zeroVector -- separating contact - else vRelNormNew - -} + | isStatic b2 = applyCollisionImpulse b1 (getPhantomBody b2, Just contact) hunk ./vis.hs 208 - mkStaticBody $ translatePoly (Vec 0 (-0.1) 0) $ rect 1 0.1 1 - , setPosition (Vec 0 1 0) $ mkDynamicBody 1 0 (cube 0.2) + mkStaticBody 0.2 $ translatePoly (Vec 0 (-0.1) 0) $ rect 1 0.1 1 + , setPosition (Vec (-1) 1 0) $ setLinearVelocity (Vec 1 (-0.4) 0) $ mkDynamicBody 10 1 (cube 0.2) hunk ./vis.hs 222 -nsteps = 2 -world = world9 +nsteps = 10 +world = world8