SpiderPig Posted May 10 Share Posted May 10 Similar to the newton function here I'd like to be able to get the amount of force applied to an entity in the last physics update. Entity::GetForce() or maybe Entity::GetAppliedForce()? I want to know what direction an object is being pulled - this is not always going to be the velocity. An object can be stationary yet still have a large force acting on it. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10 Share Posted May 10 Quote This function is only effective when called from NewtonApplyForceAndTorque callback. I think this is for processing forces right before they are applied. Forces can be applied two ways: Collision Programmatic In both cases, you have control over or access to the time that force is applied. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 10 Author Share Posted May 10 I think your right. So because there are two ways forces are applied it might not be possible for you to add a function that can get the applied force in last physics step? Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10 Share Posted May 10 Why would you need that, if you already have access to that information when it happens? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 10 Author Share Posted May 10 AddForce() could be called anywhere within the program, and how would I get the force applied by collision? The Collide function in the components only has speed. I need it for finding out the direction the object is being pulled in so I can align my player controller to gravity as it falls. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted May 10 Author Share Posted May 10 This where a PhysicsUpdate() hook in the components or HOOK_PHYSICS_UPDATE would be great. It could have an argument called force. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10 Share Posted May 10 The collision includes the normal, which gives you the direction. I don't know how to get the "force" of a collision. This function does not: https://github.com/mmozeiko/Squares3D-Android/blob/dc7002d3e638a9ed0ffd090dc52168029321cec7/jni/newton/coreLibrary_200/source/newton/Newton.cpp#L2095 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted May 10 Author Share Posted May 10 Perhaps something like this for tracking Entity::AddForce at least? The total force (including collision force) can only be retrieved from with the callback like you said. I more interested in knowing what the force is that is about to be applied to the physics object by code. MyComponent { virtual void PhysicsUpdateStart(float& applied_force_this_loop){ applied_force_this_loop = 0.0f; //Do what ever you want with the force that is about to be applied. } } //Maybe it could track what is being added? Entity::AddForce(Vec3 new_force){ applied_force_this_loop += new_force } //Once the physics update has completed End_PhysicsUpdate(){ //All entiites force can be reset to zero applied_force_this_loop = 0; } PhysicsUpdateStart could even be called from the torqueandforce callback - if it's thread safe... void callbackForceAndTorque(const NewtonBody* body) { auto total_force_ready_to_apply = 0; NewtonBodyGetForce(body, total_force_ready_to_apply); auto componet = body->GetUserData(); componet->PhysicsUpdateStart(total_force_ready_to_apply); NewtonBodyAddForce(body, total_force_ready_to_apply); } Quote Link to comment Share on other sites More sharing options...
Josh Posted May 10 Share Posted May 10 The documentation above says that the function will return zero if the two bodies are in motion, because the contact is not a force but an impulse. This is getting beyond my knowledge of physics. The best approximation I can think of is to take the normal and speed * speed of the collision times the other body's mass, and that's your kinetic energy, or "force". 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.