java - Bullet physics, textured sphere doesnt roll -
i trying battle way through learning java , bullet physics in 1 go. quite possible little @ once challenge.
so far, i've learned how import g3db objects, apply bullet physics them , interact them on screen using following code:
assets = new assetmanager(); assets.load("globe.g3db", model.class); assets.load("crate.g3db", model.class); assets.finishloading(); model model = assets.get("globe.g3db", model.class); modelinstance inst = new modelinstance(model); inst.transform.trn(0, 20, 0); btrigidbody body; btsphereshape sh = new btsphereshape(1); sh.calculatelocalinertia(1, new vector3(0,0,0)); body = new btrigidbody(new btrigidbody.btrigidbodyconstructioninfo(3, new btdefaultmotionstate(inst.transform), sh)); body.setuservalue(minstances.size); body.proceedtotransform(inst.transform); motionstate = new mymotionstate(); motionstate.transform = inst.transform; body.setmotionstate(motionstate); dynamicsworld.addrigidbody(body ); minstances.add(inst);
this works fine, if set above ground falls , comes rest on ground, when moves slides rather rolls. there easy fix?
to allow rolling of physical body, need calculate local inertia , provide construction info. in code you're doing right.
the method
btcollisionshape.calculatelocalinertia(float mass, vector3 inertia)
indeed calculates local inertia stores in second argument 'vector3 inertia'. no changes applied btcollisionshape
itself.
after obtaining vector of inertia need pass to
btrigidbodyconstructioninfo(float mass, btmotionstate motionstate, btcollisionshape collisionshape, vector3 localinertia)
as last argument.
the correct code should this:
btrigidbody body; btsphereshape sh = new btsphereshape(1); vector3 inertia = new vector3(0,0,0); sh.calculatelocalinertia(1, inertia); body = new btrigidbody(new btrigidbody.btrigidbodyconstructioninfo(3, new btdefaultmotionstate(inst.transform), sh, inertia));
local inertia not required perform simulation, without it, forces applied bodies treated central forces , therefore cannot affect angular speed.
Comments
Post a Comment