Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btTransform operator* on btVector3 missing from IDL // cannot applyForce local/relative to btRigidBody #277

Closed
ricksterhd123 opened this issue Sep 7, 2019 · 5 comments

Comments

@ricksterhd123
Copy link

ricksterhd123 commented Sep 7, 2019

Been trying to applyForce relative to a rigidbody, if anyone has any ideas how I may do this then please let me know. Anyway, after trying to follow the solution from this ancient forum post: https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=2366 I've found this:

btVector3 relativeForce = btVector3(0,10,0);
btTransform* boxTrans;
boxRigidBody->getMotionState()->getWroldTransform(boxTrans);
btVector3 correctedForce = (boxTrans * relativeForce) - boxTrans.getOrigin();
boxRigidBody->applyCentralForce(correctedForce);

If you look in
https://pybullet.org/Bullet/BulletFull/classbtTransform.html
then you see that
btVector3 operator* (const btVector3 &x) const
is needed to achieve it, however i cannot find this definition in the IDL anywhere.

Please could someone look into fixing this? Does anyone have an alternative solution, I just don't want to waste time migrating to another physics library...

@ricksterhd123
Copy link
Author

For anyone looking how to apply a force local/relative to btRigidBody in ammo.js, here's how:
let transform = new Ammo.btTransform();
body.getMotionState().getWorldTransform(transform);
let relativeForce = new Ammo.btVector3(0,0, 1000);
let relativeTransform = new Ammo.btTransform();
relativeTransform.setOrigin(relativeForce);
let relativeForce = (transform.op_mul(relativeTransform)).getOrigin();
body.applyForce(relativeForce, transform.getOrigin());

Set the relativeForce which is a btVector3 into a btTransform using btTransform.setOrigin, then use op_mul and retrieve the resulting btVector3 using btTransform.getOrigin

I'm now going to close the issue, I hope people will find this if anyone has the same trouble I did.

@marlonicus
Copy link

marlonicus commented Jul 17, 2020

Thanks @ricksterhd123! Exactly the problem I was struggling with... And thank you again for leaving a breadcrumb to this page on a 10-year-old thread, the internet needs more heroes like you 👏

@kmindspark
Copy link

Same here! Thanks @ricksterhd123

@AndreyNesterenko2020
Copy link

If you are using three JS, just do:
var temporaryEuler = new THREE.Vector3(1,0,0).applyQuaternion(objThree.quaternion); objAmmo.setLinearVelocity(new Ammo.btVector3(temporaryEuler.x, temporaryEuler.y, temporaryEuler.z));
Where objAmmo is the ammo object and objThree is the three js object.
The above code will make the object go forward. @ricksterhd123

@dataexcess
Copy link

@ricksterhd123 solution is not working for me. Seems I can only use setLinearVelocity. Which is not what I want, because then gravity is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants