local _commentControllerIsActive = true -- trueならコメントで操作可能 local _Maxheight = 3.0 --コメントで操作可能な最高高度 local _Minheight = 0.3 --コメントで操作可能な最低高度 function onUse(use) -- useによるVCIの有効/無効 --[[ if use == "Board" then _commentControllerIsActive = not(_commentControllerIsActive) print("Controller : "..tostring(_commentControllerIsActive)) end ]] end -- カメラのPositionを変更 function setCommentPosition(pos) if _commentControllerIsActive == false then print("コメントによるカメラ操作が無効") return end if vci.studio.HasHandiCamera() == false then print("ハンディカメラが存在しないので終了") return end local cam = vci.studio.GetHandiCamera() if (pos.y < 0.01) and (cam.GetPosition().y < _Minheight) then print("最低高度なのでコメントで制御できません") pos.y = 0 -- y を 0 にして無効 end if (pos.y > 0.01) and (cam.GetPosition().y > _Maxheight) then print("最大高度なのでコメントで制御できません") pos.y = 0 -- y を 0 にして無効 end pos = cam.GetRotation() * pos pos = pos + cam.GetPosition() cam.SetPosition(pos) --print("Cam Position : "..tostring(cam.GetPosition())) end -- カメラのRotationを変更 function setCommentRotation(rot) if _commentControllerIsActive == false then print("コメントによるカメラ操作が無効") return end if vci.studio.HasHandiCamera() == false then print("ハンディカメラが存在しないので終了") return end local cam = vci.studio.GetHandiCamera() rot = cam.GetRotation() * rot cam.SetRotation(rot) --print("Cam Position : "..tostring(cam.GetPosition())) end -- コメント受信時の処理 function onMessage(sender, name, message) -- コメント内容 print(sender["name"].."「"..message.."」") -- コメントで加算するPositionとRotation local pos = Vector3.zero local rot = Quaternion.identity -- 1回のコメントで移動する距離を変更できます 単位:メートル local movingDistance = 0.2 -- 1回のコメントで回転する角度を変更できます 単位:度 local rotationAngle = 10 -- 前 if string.find(message,"前") ~= nil or string.find(message,"まえ") ~= nil then pos.z = pos.z + movingDistance end -- 後 if string.find(message,"後") ~= nil or string.find(message,"うしろ") ~= nil then pos.z = pos.z - movingDistance end -- 上 if string.find(message,"上") ~= nil or string.find(message,"うえ") ~= nil then pos.y = pos.y + movingDistance end -- 下 if string.find(message,"下") ~= nil or string.find(message,"した") ~= nil then pos.y = pos.y - movingDistance end -- コメントに右が含まれてる if string.find(message,"右") ~= nil or string.find(message,"みぎ") ~= nil then -- 右回り の場合は回転を処理して終了 if string.find(message,"右回り") ~= nil or string.find(message,"右周り") ~= nil then rot = Quaternion.AngleAxis(rotationAngle, Vector3.up) setCommentRotation(rot) return end --右移動 pos.x = movingDistance end -- コメントに左が含まれてる if string.find(message,"左") ~= nil or string.find(message,"ひだり") ~= nil then -- 左回り の場合は回転を処理して終了 if string.find(message,"左回り") ~= nil or string.find(message,"左周り") ~= nil then rot = Quaternion.AngleAxis(-rotationAngle, Vector3.up) setCommentRotation(rot) return end --左移動 pos.x = -movingDistance end -- 位置の更新 setCommentPosition(pos) end -- コメントの受信 vci.message.On('comment', onMessage)