OpenGLのモデル行列を絶対値に回転させるメソッドが必要な場合があります。そこにあるほとんどのrotate()メソッドは、現在の行列に新しい回転を掛けて、現在のメソッドに回転を追加します。古い回転を維持せずに、モデル行列をある値に回転させる必要があります。私が現在していることは、現在のマトリックスを破壊してアイデンティティにすることです。次に、前に設定したスケール変数に基づいて、最初からスケールを計算します。次に、クォータニオンから取得した回転行列を乗算し、最終的には再度変換します。
そのようなタスクには計算が多すぎるように私には見えます。スケールと平行移動の部分をそのままにして、行列の回転をリセットするより短い方法はありますか?これが私の現在のメソッド(Java)です:
public void rotateTo3( float xr,float yr,float zr) {
Quaternion xrotQ= Glm.angleAxis( (xr),Vec3.X_AXIS);
Quaternion yrotQ= Glm.angleAxis( (yr),Vec3.Y_AXIS);
Quaternion zrotQ= Glm.angleAxis( (zr),Vec3.Z_AXIS);
xrotQ= Glm.normalize(xrotQ);
yrotQ= Glm.normalize(yrotQ);
zrotQ= Glm.normalize(zrotQ);
Quaternion acumQuat=new Quaternion();
acumQuat= Quaternion.mul(xrotQ,yrotQ);
acumQuat= Quaternion.mul(acumQuat,zrotQ);
Mat4 rotMat=new Mat4(1);
rotMat=Glm.matCast(acumQuat);
_model = new Mat4(1);
scaleTo(_scaleX, _scaleY, _scaleZ);//reconstruct scale
_model = Glm.translate(_model, new Vec3(_pivot.x, _pivot.y, 0));
_model=rotMat.mul(_model); ///add new rotation
_model = Glm.translate(_model, new Vec3(-_pivot.x, -_pivot.y, 0));
translateTo(_x, _y, _z);//reconstruct translation
}