Guilherme Duarte
Guilherme Duarte

Reputation: 3441

How to change the center of a 3D WPF object

I'm struggling with the best way of changing the center point of a 3D object (Model3DGroup) in WPF.

I've exported a model from SketchUp and everything is fine, but the centers got off position, causing me trouble in rotating the objects. Now I need to make some rotations around each object own center and have no idea on how to do it...

Any suggestions would be appreciated.

Thanks

Using Jackson Pope suggestion, I used the code below to get the center point of an object:

var bounds = this.My3DObject.Bounds;

var x = bounds.X + (bounds.SizeX / 2);
var y = bounds.Y + (bounds.SizeY / 2);
var z = bounds.Z + (bounds.SizeZ / 2);

var centerPoint = new Point3D(x, y, z);

Meanwhile I'll try find a better solution to try and move all the points to the desired offset...

Upvotes: 0

Views: 2277

Answers (1)

Jackson Pope
Jackson Pope

Reputation: 14660

To rotate an object around it's centre you need to first translate it so that its centre is at the origin. Then rotate it (and then potentially translate it back to its original position).

Find the minimum and maximum extent of the object, calculate its centre = min + (max-min)/2. Translate by (-centreX, -centreY, -centreZ), rotate and then translate by (centreX, centreY, centreZ).

Upvotes: 2

Related Questions