4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VCIAdvent Calendar 2019

Day 4

VCIで親子関係っぽい振る舞いをさせてみる(位置と回転

Last updated at Posted at 2019-12-04

#概要
https://qiita.com/120byte/private/b9e5a50db09bcdf9c9c0
があんまりだったので、もう一つ案を考えてみました。

#動作

#実装
image.png
image.png※CubeA~Bは同じ
image.png※Cube1~3は同じ

local current = ""

function updateAll()
    SetTransform("CubeA", "Cube1")
    SetTransform("CubeB", "Cube2")
    SetTransform("CubeC", "Cube3")
end

function SetTransform(targetName, markerName)
    local target = vci.assets.GetSubItem(targetName)
    local marker = vci.assets.GetSubItem(markerName)
    if current == markerName then
        target.SetPosition(marker.GetPosition())
        target.SetRotation(marker.GetRotation())
    else
        marker.SetPosition(target.GetPosition())
        marker.SetRotation(target.GetRotation())
    end
end

function onGrab(target)
    current = target
end

function onUngrab(target)
    current = ""
end

#捕捉
親子関係を持つオブジェクトと、掴んで操作するためのオブジェクトを分けて作ります。親子関係を持つオブジェクトはVCISubItemを付けていません。掴んで操作するオブジェクトを掴んでいるかどうかで、親子オブジェクトと掴みオブジェクト間の位置と回転の取得と設定を入れ替えます。

#蛇足
大きさはlocalしかないため一癖あり、用途的にも思い浮かばなかったので諦めてしまいました。(親子関係の大きさから計算すれば合うかな……?

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?