Rotate convex hull around the origin of its input data

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
speciesUnknown
Posts: 20
Joined: Mon Aug 01, 2011 12:31 am

Rotate convex hull around the origin of its input data

Post by speciesUnknown »

Hi,

I have two convex hulls, both of which are created from data which is also used to render the turning part and the barrel part on a turret. I have correctly positioned and rotated the visible version of the turret and barrel, but I can't correctly position the physics parts.

What happens is that they always rotate around their center of mass, rather than rotating around their original origin, which is understandable, but I need to create the illusion that they are rotating around their original origins.

The center point of the renderable version has been explicitly set, so that I can rotate different parts of the model around an arbitrary point, e.g. rotating a cannon barrel around a point at the far end. I cannot use the centre of mass instead, because then I wont be able to correctly animate the model - the arbitrary origin points are staying as they are.

Here is the code I am using to set the position of the renderable and phyics bodies; the renderable body is correctly positioned, and I am now trying to derive the position of the physics body from the position of the renderable. The physics bodies are kinematic bodies with no solver states set on them.

Code: Select all

		public void repositionChildren()
		{
			// update position of renderable meshes
			turret_renderable.rotation = this.TargetRotation;
			barrel_renderable.rotation = this.TargetElevation;

			// barrel renderable is relative to turret renderable
			barrel_renderable.setOffset(Matrix.CreateTranslation(this.BarrelOffset) * turret_renderable.getPosition());


			// update position of turret detector volumes
			this.turret_hull.WorldTransform = 
				this.turret_renderable.createLocalTransform() 
				* turret_renderable.offsetFromRoot 
				* this.Position;

			this.barrel_hull.WorldTransform = 
				this.barrel_renderable.createLocalTransform() 
				* barrel_renderable.offsetFromRoot 
				* this.Position;
		}
I've seen similar problems solved before by changing where the editor puts the origin of each body part, but that is unacceptable here, I need arbitrary origins to correctly animate the model.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rotate convex hull around the origin of its input data

Post by Norbo »

Compute the offset between the render origin and the center of mass in 'configuration space' (i.e. the space in which you set stuff up). That local offset is then transformed by the rendered orientation before being added to the world render position. The sum is the location at which the entity's center of mass should be. The entity's orientation is just the rendered orientation again, assuming they were aligned in configuration space.

In other words,

Code: Select all

entity.Position = Vector3.Transform(localOffset, renderOrientation) + renderPosition; //Equivalent to transforming by render world transform
entity.Orientation = renderOrientation;
speciesUnknown
Posts: 20
Joined: Mon Aug 01, 2011 12:31 am

Re: Rotate convex hull around the origin of its input data

Post by speciesUnknown »

Thanks, this is an approach I didnt yet think of. I'll try to make this work.
speciesUnknown
Posts: 20
Joined: Mon Aug 01, 2011 12:31 am

Re: Rotate convex hull around the origin of its input data

Post by speciesUnknown »

woohoo! Ahem. excuse me...

It works for the turret, in all positions of rotation and with the whole vehicle moving around. Tomorrow, I'll have a crack at the slightly more complex barrel, which is relative to the turret and has an even more eccentric point of origin(one end).

Norbo, thanks for the help, so far your assistance has been invaluable for my project.
Post Reply