#OBB Rotation matrix issue

16 messages · Page 1 of 1 (latest)

hot drum
#

because if I rotate the three boxes to the float direction of the body this happens:

#

what I want to do is that when I rotate these three boxes, they keep them in the same corner as the chest like this:

hot drum
hardy jungle
#

rotate centers around common point (zero ?)

#

what you have is what you would get if you rotated each box around its own center

#

if oobThing.applyMatrix4 does that, then you want to use offset^-1 * rotation * offset matrix

#

where offset is translation matrix between the origin and box center

hot drum
hot drum
# hardy jungle what you have is what you would get if you rotated each box around its own cente...

and i didnt quite understand what you meant by that, English is not my main language, I'm using the translator for that, let's go by part

https://threejs.org/docs/#examples/en/math/OBB

https://github.com/mrdoob/three.js/blob/master/examples/jsm/math/OBB.js # line 337

oobThing.applyMatrix4 > applymatrix4 just applies the rotation of the obb matrix3 to an angle based on the ''obb'' center and its scale

GitHub

JavaScript 3D Library. Contribute to mrdoob/three.js development by creating an account on GitHub.

#

https://threejs.org/docs/#api/en/math/Matrix4

Euler euler = Euler.setFromVector3(bodyDirection);
Vector3 bottomCenter = new Vector3(center.x, min.y, center.z)

Matrix4 transform = new Matrix4();
transform.makeRotationFromEuler(euler);

obb.applyMatrix4(transform)```

Matrix4 obbMatrix = obb.matrix;
obbMatrix // apply position inverse
// multiply rotation
// multiply matrix 
> do you mean that??

hardy jungle
#

i mean m1 = new MAtrix4().makeTranslation(centers x, y z)
m2 = yourRotationMatrix
m3 = m1.clone().invert()
then transform = m1.multiply(m2).multiply(m3)

#

or 3-2-1 order, one of these

hot drum
#

alr ty u só much

hot drum
#
        Box3 leftFeet = new Box3(bottomCenter.clone().add(-.234375f, 0, .1171875f), 

        OBB obbLeftFeet = new OBB(leftFeet.center(), leftFeet.halfSize(), Matrix3.Identify);
        Matrix4 obbLeftFeetPosition = new Matrix4().makeTranslation(leftFeet.center());

        Matrix4 transformLeft = obbLeftFeetPosition.clone().
                                                    invert()
                                                    .multiply(rotation)                                              .multiply(obbLeftFeetPosition);
                    
                //obbLeftFeetPosition.clone().multiply(rotation).multiply(obbLeftFeetPosition.invert());
        
        obbRightFeet.applyMatrix4(transformLeft);
        
        obbLeftFeet.mesh();```

well, i tried to do that what you said is it didn't work very well, first the box is not moving with the rotation of the body, and rotating based on its direction

> if oobThing.applyMatrix4 does that, then you want to use offset^-1 * rotation * offset matrix

> m1 = new Matrix4().makeTranslation(centers x, y z)

lets see if I really did this right, ''makeTranslation(center x, y, ) do you mean do you mean to use the center of the obb or the player's body?
or you mean __offset translation matrix between the origin and box center__

@hardy jungle **obs in this case, he really is moving to the side, but the problem is that sometimes he exceeds the middle distance and is a little more forward or does not turn towards the body**
hardy jungle
#

use the center of the obb
yes

but like, I was just throwing ideas around, if that did not work you need to try something else

hot drum