OBJ メッシュの全頂点にスケール→回転→平行移動を適用し再初期化する。 変換順序: v_new = R(rotation) * (v_old * scale) + offset 回転は度単位で x→y→z の順に外因性 (extrinsic) 回転を適用する。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_type), | intent(inout) | :: | mesh |
変換対象の三角形メッシュ。 |
||
| real(kind=dp), | intent(in) | :: | scale |
一様スケーリング係数。 |
||
| real(kind=dp), | intent(in) | :: | rotation_deg(3) | |||
| real(kind=dp), | intent(in) | :: | offset(3) |
subroutine apply_obj_transform(mesh, scale, rotation_deg, offset) type(mesh_type), intent(inout) :: mesh real(dp), intent(in) :: scale real(dp), intent(in) :: rotation_deg(3) real(dp), intent(in) :: offset(3) real(dp), parameter :: deg2rad = acos(-1.0d0)/180.0d0 real(dp) :: rx, ry, rz, cx, sx, cy, sy, cz, sz real(dp) :: R(3, 3), v(3) real(dp), allocatable :: tv0(:, :), tv1(:, :), tv2(:, :) integer(i32) :: i, n rx = rotation_deg(1)*deg2rad ry = rotation_deg(2)*deg2rad rz = rotation_deg(3)*deg2rad cx = cos(rx); sx = sin(rx) cy = cos(ry); sy = sin(ry) cz = cos(rz); sz = sin(rz) ! R = Rz * Ry * Rx (extrinsic x→y→z) R(1, 1) = cy*cz; R(1, 2) = sx*sy*cz - cx*sz; R(1, 3) = cx*sy*cz + sx*sz R(2, 1) = cy*sz; R(2, 2) = sx*sy*sz + cx*cz; R(2, 3) = cx*sy*sz - sx*cz R(3, 1) = -sy; R(3, 2) = sx*cy; R(3, 3) = cx*cy n = mesh%nelem allocate (tv0(3, n), tv1(3, n), tv2(3, n)) do i = 1, n v = mesh%v0(:, i)*scale tv0(:, i) = matmul(R, v) + offset v = mesh%v1(:, i)*scale tv1(:, i) = matmul(R, v) + offset v = mesh%v2(:, i)*scale tv2(:, i) = matmul(R, v) + offset end do call init_mesh(mesh, tv0, tv1, tv2) end subroutine apply_obj_transform