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

Update to support rigid body that need special compound shape handling #1024

Open
wants to merge 1 commit into
base: master
from

Conversation

@danilko
Copy link

danilko commented Nov 26, 2018

Update to support rigid body that need special compound shape handling
Example include vehicle body

It is a compond rigid body, but as it is not a supported rigid body type and need special physics update (through btVehicle).

Need to modify rigidbody as aromry's physic world contacts are store using armory RigidBody list, if the ojbect is not an Armory RigidBody, then RigidBody.contacts will not get them if through they are contacted.

Following is one way vehicle body can be added as rigidbody

	function createRigidBody(mass:Float, shape:BtCompoundShapePointer):BtRigidBodyPointer {
		var localInertia = BtVector3.create(0, 0, 0);
		shape.calculateLocalInertia(mass, localInertia);

		var centerOfMassOffset = BtTransform.create();
		centerOfMassOffset.setIdentity();

		var startTransform = BtTransform.create();
		startTransform.setIdentity();
		startTransform.setOrigin(BtVector3.create(transform.loc.x, transform.loc.y, transform.loc.z));
		startTransform.setRotation(BtQuaternion.create(transform.rot.x, transform.rot.y, transform.rot.z, transform.rot.w));

		var myMotionState = BtDefaultMotionState.create(startTransform, centerOfMassOffset);
		var cInfo = BtRigidBodyConstructionInfo.create(mass, myMotionState, shape, localInertia);

		var body = BtRigidBody.create(cInfo);
		
		body.setLinearVelocity(BtVector3.create(0, 0, 0));
		body.setAngularVelocity(BtVector3.create(0, 0, 0));

		//physics.world.addRigidBody(body);

		var rigidBody = new armory.trait.physics.bullet.RigidBody(1.0, 8, 0.5, 0.0, 0.0,
						0.04, 0.1, false,
						null, null,1, false, null, false, true, body);
		rigidBody.object = this.object;
		rigidBody.init();
		
		return rigidBody.body;
	}

Instead of just return the BtRigidBody pointer, with this patch, one can then above to pass in the created rigidBody and set the object as the object itself to get the controller through the btRigidBody with benefit of Armory RigidBody and rest of integration.

One reason above is necessary is for example, if there is a damage calculation such as something is throwing at the vehicle and vehicle need rigid body to calculate the damage, or vehicle passed through the finished line physic block.

There are only few lines change, the most major block is because of intend as they are in the if statement

Result implementation can be found at
https://youtu.be/MNTmtQ_nrE4

with the time attack example.

There are other way to bypass this such as using another rigidbody on top of vehicle, but when test, it is harder to manage, and also had a conflict where the result object is still not the parent vehicle object.

…le and compond shape, but still can be used in collision maps
@danilko

This comment has been minimized.

Copy link
Author

danilko commented Nov 26, 2018

Forgot to mention, the other use cases include the need for other traits that has rigidbody (such as KineticController/StaticController(which seem like trigger option)), where they are using rigidbody, but will not have same physics update as normal RigidBody.

The other options is create a CollisonObjectTrait and extend RigidBody from there so others can also extend. However, it seem trait/extend another trait seem to cause the cast to be problematic as the PhysicWorld.getContacts seem to be mostly depend on RigidBody object. Not sure if we are able to break the API, if we can, one way is add getCollisionContacts and deprecate getContact will return CollisionObjectTriat, the rb will be col to track all collision objects (even if they are not trait rigidbody). Then the user will be responsible for upcast the collision object to RigidBody trait to find the necessary rigidbody, or use collisionobject.object.name to find target object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.