Page 1 of 1

Creating a rigidBody at a point in camera space?

Posted: Thu Mar 09, 2017 10:11 pm
by jimjamjack
Hi, I can currently create a rigidBody at world space position (given a specific x, y and z).

This works fine if my bullet model is just randomly placed in the scene, but I'm now attempting to fire bullets from the end of my gun (which is attached to the gun by removing the viewMatrix multiplication in my MVP uniform, so I'm doing the same for my bullets since they need to come from the gun which can be facing any direction).

Is there a way to create a rigidBody in camera space, then move my bullet to that location?
Or maybe it's best to somehow draw the bullet in camera space, but as you move away, it remains there in world space, then simply take it's position?

I'm unsure how to approach this, so any help is appreciated. Thanks.

Re: Creating a rigidBody at a point in camera space?

Posted: Fri Mar 10, 2017 12:10 am
by drleviathan
You can slam the RigidBody transform directly, however if the body is dynamic and inactive when you do this then you should activate it:

Code: Select all

body->setWorldTransform(transform);
if (!body->isStaticOrKinematicObject() && !body->isActive()) {
    body->activate();
}

Re: Creating a rigidBody at a point in camera space?

Posted: Fri Mar 10, 2017 9:00 pm
by jimjamjack
drleviathan wrote:You can slam the RigidBody transform directly, however if the body is dynamic and inactive when you do this then you should activate it
My issue is that when defining the motionstate, I can't give it an x, y and z value for its position since my bullet model is being drawn in camera space. If I just give it some world space coordinates, like my current player position, then the rigidBody is created just fine and falls as expected. Thanks.