hello,
i have a box and i set orientation but it roate around center point
how to set orientation from other point(ex: first point )
var box = new Box(new Vector3(0, 2f, 3), 2f, 0.2f, 0.2f, 0);
box.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)Math.PI / 6);
thanks
Set Orientation from other point
Re: Set Orientation from other point
Hi,
one possible solution is to translate your object first, rotate it and then translate it back.
If you do this, your object will be rotated around the "translated origin".
For example: You have a 2x2 sized cube and want it to rotate around a specific vertex. The center point would be (x: 0, y: 0, z: 0). One of the 8 vertices has the coordinates (x: 1, y: 1, z: 1).
Your rotation Matrix could be:
It is helpful to write a static method for this.
I hope I could help you.
EDIT: The "Box" class has a WorldTransform-property you can use.
one possible solution is to translate your object first, rotate it and then translate it back.
If you do this, your object will be rotated around the "translated origin".
For example: You have a 2x2 sized cube and want it to rotate around a specific vertex. The center point would be (x: 0, y: 0, z: 0). One of the 8 vertices has the coordinates (x: 1, y: 1, z: 1).
Your rotation Matrix could be:
Code: Select all
Matrix rotationMatrix = Matrix.CreateTranslation(1, 1, 1) * Matrix.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2) * Matrix.CreateTranslation(-1, -1, -1);
I hope I could help you.
EDIT: The "Box" class has a WorldTransform-property you can use.
Code: Select all
Box box = new Box(new Vector3(0, 0, 0), 2, 2, 2, 0);
box.WorldTransform = rotationMatrix;
-
- Posts: 12
- Joined: Sat Oct 13, 2018 1:40 am
Re: Set Orientation from other point
Hello,
thanks for help
this is my code:
but it is not success
thanks for help
this is my code:
Code: Select all
var box = new Box(new Vector3(1, 2f, 3), 2f, 0.2f, 0.2f, 0);
var position = new Vector( 0, 0, 3.1f);
var t = box.Position - position;
var t2 = -t;
Matrix.CreateTranslation(ref t, out var tran1);
var orientation = Matrix.CreateFromAxisAngle(Vector3.Backward, MathHelper.PiOver4);
Matrix.CreateTranslation(ref t2, out var tran2);
box.WorldTransform = tran1 * orientation * tran2;
Re: Set Orientation from other point
If you want to rotate an object that is offset from the origin of rotation, you need to rotate the offset.
More robustly, if you have the offset stored in the local space of the body ahead of time, you don't need to recalculate the offset over and over:
Code: Select all
offset = previousCenterOfBody - centerOfRotation
rotatedOffset = offset * rotation
newCenterOfBody = centerOfRotation + rotatedOffset
newOrientation = orientation * rotation
Code: Select all
newOrientation = orientation * rotation
worldOffset = localOffset * newOrientation
newCenterOfBody = centerOfRotation + worldOffset
-
- Posts: 12
- Joined: Sat Oct 13, 2018 1:40 am
Re: Set Orientation from other point
hello,
i maybe see the problem.
Orientation is rotate entity around lines( ex: x axis, y axis, AB line, .. )
Rotate function by use AngularVelocity will rotate entity around center point. So to Rotate entity around wiff offset point, can i use entity.CollisionInformation.LocalPosition? if it is true, so i understood the problem
i maybe see the problem.
Orientation is rotate entity around lines( ex: x axis, y axis, AB line, .. )
Rotate function by use AngularVelocity will rotate entity around center point. So to Rotate entity around wiff offset point, can i use entity.CollisionInformation.LocalPosition? if it is true, so i understood the problem
Re: Set Orientation from other point
The LocalPosition serves as a local offset from the center of mass to the center of the collision shape. In other words,
So yes, that can be used to make the collision shape rotate around a point that is not the same as the center of the collision shape. Entities always rotate around their center of mass, which is what the entity.Position property refers to.
Code: Select all
collisionShapeLocation = LocalPosition * entity.Orientation + entity.Position