質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

2回答

2076閲覧

foveのサンプルをいじって片目だけ視線追跡させたい。

ehuronkon35

総合スコア33

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

1クリップ

投稿2018/10/04 07:47

編集2018/10/05 06:22

foveのサンプルをいじって片目だけ視線追跡させたい。

FOVEが提供しているサンプルコードは現段階では両目が視線追跡されている状況です。

それを片目だけ視線を追跡するようにするにはコードをどう変えればいいですか。
右目、左目、どちらでも構いません。

C#

1コード 2using UnityEngine; 3using System.Collections; 4 5public class FOVE3DCursor : MonoBehaviour 6{ 7 public enum LeftOrRight 8 { 9 Left, 10 Right 11 } 12 13 [SerializeField] 14 public LeftOrRight whichEye; 15 public FoveInterfaceBase foveInterface; 16 17 // Use this for initialization 18 void Start () { 19 } 20 21 // Latepdate ensures that the object doesn't lag behind the user's head motion 22 void Update() { 23 FoveInterfaceBase.EyeRays rays = foveInterface.GetGazeRays(); 24 25 Ray r = whichEye == LeftOrRight.Left ? rays.left : rays.right; 26 27 RaycastHit hit; 28 Physics.Raycast(r, out hit, Mathf.Infinity); 29 if (hit.point != Vector3.zero) // Vector3 is non-nullable; comparing to null is always false 30 { 31 transform.position = hit.point; 32 } 33 else 34 { 35 transform.position = r.GetPoint(3.0f); 36 } 37 } 38} 39

C#

1コード 2using UnityEngine; 3using System; 4using System.Collections.Generic; 5using System.Runtime.Remoting.Messaging; 6using Fove.Managed; 7 8[RequireComponent(typeof(Camera))] 9[AddComponentMenu("")] // hide FoveEyeCamera from mono behaviour menus to discourage people adding it by hand 10public class FoveEyeCamera : MonoBehaviour { 11 12 [SerializeField] 13 public EFVR_Eye whichEye = EFVR_Eye.Left; 14 15 [SerializeField] 16 public bool suppressProjectionUpdates = true; 17 18 [SerializeField] 19 [Range(0.1f, 4f)] 20 public float resolutionScale = 1.4f; 21 public int antiAliasing = 1; 22 23 private float _lastScale; 24 private int _lastAA; 25 26 private FVRHeadset _headset = null; 27 private Camera _cam = null; 28 private FVRCompositor _compositor; 29 public FoveInterfaceBase foveInterfaceBase; 30 31 private SFVR_CompositorLayerSubmitInfo _layerSubmitInfo; 32 33 private static bool couldUseNewMatrices; 34 private static Matrix4x4 leftProjectionMatrix; 35 private static Matrix4x4 rightProjectionMatrix; 36 37 private class FoveCameraPair 38 { 39 public SFVR_CompositorLayer layer; 40 41 public FoveEyeCamera left; 42 public FoveEyeCamera right; 43 44 // Private so nobody can make one this way 45 private FoveCameraPair() {} 46 47 public FoveCameraPair(FVRCompositor compositor, FoveInterfaceBase xface) 48 { 49 left = null; 50 right = null; 51 52 var createInfo = new SFVR_CompositorLayerCreateInfo 53 { 54 alphaMode = EFVR_AlphaMode.Auto, 55 disableDistortion = xface.DistortionDisabled, 56 disableTimewarp = xface.TimewarpDisabled, 57 disableFading = xface.FadingDisabled, 58 type = xface.LayerType 59 }; 60 61 var err = compositor.CreateLayer(createInfo, out layer); 62 if (err != EFVR_ErrorCode.None) 63 { 64 Debug.LogError("[FOVE] Error getting layer: " + err); 65 } 66 67 Debug.Log("[FOVE] Layer requested no distortion? " + createInfo.disableDistortion); 68 } 69 70 public void SetCamera(EFVR_Eye whichEye, FoveEyeCamera cam) 71 { 72 switch (whichEye) 73 { 74 case EFVR_Eye.Left: 75 left = cam; 76 break; 77 case EFVR_Eye.Right: 78 right = cam; 79 break; 80 } 81 } 82 83 public bool CanUseCamera(EFVR_Eye whichEye, FoveEyeCamera cam) 84 { 85 switch (whichEye) 86 { 87 case EFVR_Eye.Left: 88 return left == null || left == cam; 89 case EFVR_Eye.Right: 90 return right == null || right == cam; 91 } 92 93 return false; 94 } 95 } 96 97 private static List<FoveCameraPair> _layerCameraPairs = new List<FoveCameraPair>(); 98 99 private static FoveCameraPair GetNextLayerPair(EFVR_Eye whichEye, FoveEyeCamera cam) 100 { 101 if (whichEye != EFVR_Eye.Left && whichEye != EFVR_Eye.Right) 102 return null; 103 104 foreach (var pair in _layerCameraPairs) 105 { 106 if (pair.CanUseCamera(whichEye, cam)) 107 return pair; 108 } 109 110 var p = new FoveCameraPair(cam._compositor, cam.foveInterfaceBase); 111 _layerCameraPairs.Add(p); 112 113 return p; 114 } 115 116 public FVRCompositor Compositor 117 { 118 set 119 { 120 _compositor = value; 121 } 122 } 123 124 private static bool _isProjectionErrorFree; 125 126 private void UpdateProjectionMatrix() 127 { 128 // Get the projection matrix from the FOVE SDK and apply it to the camera 129 if (!_isProjectionErrorFree || couldUseNewMatrices) 130 { 131 SFVR_Matrix44 fove_mx_left, fove_mx_right; 132 var err = _headset.GetProjectionMatricesRH(_cam.nearClipPlane, _cam.farClipPlane, out fove_mx_left, 133 out fove_mx_right); 134 if (err != EFVR_ErrorCode.None) 135 { 136 _isProjectionErrorFree = false; 137 } 138 else 139 { 140 _isProjectionErrorFree = true; 141 leftProjectionMatrix = FoveUnityUtils.GetUnityMx(fove_mx_left); 142 rightProjectionMatrix = FoveUnityUtils.GetUnityMx(fove_mx_right); 143 144 couldUseNewMatrices = false; 145 } 146 } 147 148 switch (whichEye) 149 { 150 case EFVR_Eye.Left: 151 _cam.projectionMatrix = leftProjectionMatrix; 152 break; 153 case EFVR_Eye.Right: 154 _cam.projectionMatrix = rightProjectionMatrix; 155 break; 156 default: 157 Debug.Log("Fove eye camera not set to left or right"); 158 break; 159 } 160 161 } 162 163 private void SetSubmitBounds(ref SFVR_CompositorLayerEyeSubmitInfo info) 164 { 165 info.bounds.left = 0.0f; 166 info.bounds.bottom = 0.0f; 167 info.bounds.right = 1.0f; 168 info.bounds.top = 1.0f; 169 } 170 171 void Start() { 172 _headset = FoveInterfaceBase.GetFVRHeadset(); 173 174 _lastScale = resolutionScale; 175 _lastAA = antiAliasing; 176 177 FoveCameraPair myPair = GetNextLayerPair(whichEye, this); 178 myPair.SetCamera(whichEye, this); 179 SFVR_CompositorLayer layer = myPair.layer; 180 SFVR_Vec2i res = layer.idealResolutionPerEye; 181 182 var rt = new RenderTexture((int)(res.x * resolutionScale), (int)(res.y * resolutionScale), 24); 183 rt.antiAliasing = antiAliasing; 184 185 _cam = gameObject.GetComponent<Camera>(); 186 _cam.targetTexture = rt; 187 _cam.enabled = false; 188 189 switch (whichEye) 190 { 191 case EFVR_Eye.Left: 192 SetSubmitBounds(ref _layerSubmitInfo.left); 193 _layerSubmitInfo.left.texInfo.colorSpace = EFVR_ColorSpace.Linear; 194 break; 195 case EFVR_Eye.Right: 196 SetSubmitBounds(ref _layerSubmitInfo.right); 197 _layerSubmitInfo.left.texInfo.colorSpace = EFVR_ColorSpace.Linear; 198 break; 199 } 200 201 _layerSubmitInfo.layerId = myPair.layer.layerId; 202 } 203 204 void Update() 205 { 206 // For live updating of resolution scale and antialiasing settings 207 const float tolerance = 0.0001f; 208 if (Math.Abs(resolutionScale - _lastScale) > tolerance || antiAliasing != _lastAA) 209 { 210 var rt = new RenderTexture((int)(1280 * resolutionScale), (int)(1440 * resolutionScale), 24); 211 rt.antiAliasing = antiAliasing; 212 213 _cam.targetTexture.Release(); 214 _cam.targetTexture = rt; 215 216 _lastScale = resolutionScale; 217 _lastAA = antiAliasing; 218 } 219 } 220 221 void OnPreCull() { 222 UpdateProjectionMatrix(); 223 } 224 225 void OnRenderImage(RenderTexture source, RenderTexture destination) 226 { 227 Graphics.Blit(source, destination); 228 229 if (_compositor == null) 230 return; 231 232 IntPtr texPtr = source.GetNativeTexturePtr(); 233 if (texPtr != IntPtr.Zero) 234 { 235 _layerSubmitInfo.pose = FoveInterface.GetLastPose(); 236 switch (whichEye) 237 { 238 case EFVR_Eye.Left: 239 _layerSubmitInfo.left.texInfo.pTexture = texPtr; 240 _layerSubmitInfo.right.texInfo.pTexture = IntPtr.Zero; 241 break; 242 case EFVR_Eye.Right: 243 _layerSubmitInfo.left.texInfo.pTexture = IntPtr.Zero; 244 _layerSubmitInfo.right.texInfo.pTexture = texPtr; 245 break; 246 default: 247 Debug.LogError("[FOVE] Camera set to " + whichEye + " which isn't supported."); 248 return; 249 } 250 251 var result = _compositor.Submit(ref _layerSubmitInfo); 252 if (result != EFVR_ErrorCode.None) 253 { 254 Debug.LogWarning("[FOVE] Submit returned unexpected " + result); 255 } 256 257 GL.Flush(); 258 } 259 else 260 { 261 Debug.LogWarning("RenderTexture native pointer is null; cannot submit null texture pointers."); 262 } 263 264 if (!suppressProjectionUpdates) 265 { 266 couldUseNewMatrices = true; 267 } 268 } 269} 270

よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2018/10/04 07:53

回答いらい依頼いただきましたが、全く専門外なので期待には応えられません(私の登録タグ参照)。他に専門知識をお持ちのかたはたくさんいるかと思いますのでそちらに回していただけたらと。
guest

回答2

0

片目のオブジェクトをオフにすらば良いだけでした。すいません。

投稿2020/04/23 04:29

suguru_sato

総合スコア23

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

片目のカーソルオブジェクトのチェックを外すのはどうでしょうか?

投稿2019/01/31 04:45

suguru_sato

総合スコア23

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問