Home › Forums › Software Development › Split: Unity Manipulate Camera
Tagged: c++, Camera, Global Events, Tobii, Unity
- This topic has 5 replies, 5 voices, and was last updated 7 years, 8 months ago by Christian Meneses.
- AuthorPosts
- 20/02/2015 at 10:26 #2576Sai MulpuruParticipant
Hi
I am trying to design an FPS game in unity by replacing mouselook.cs script with my script, gazeLook.cs. I am able to move the first person controller camera in the X direction, but in the Y direction, it is showing NaN in rotationY.
Also I noticed that fixationPoint.GazePoint.Viewport.y is returning values greater than 1, which is not supposed to happen? as its range is 0 to 1. Code is below for gaze look function. Please let me know where I went wrong.
Thanksusing UnityEngine;
using System.Collections;
using Tobii.EyeX.Framework;/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation/// To make an FPS style character:
/// – Create a capsule.
/// – Add the MouseLook script to the capsule.
/// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// – Add FPSInputController script to the capsule
/// -> A CharacterMotor and a CharacterController component will be automatically added./// – Create a camera. Make the camera a child of the capsule. Reset it’s transform.
/// – Add a MouseLook script to the camera.
/// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
[AddComponentMenu(“Camera-Control/Gaze Look”)]
public class gazeLook : MonoBehaviour {public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;public float minimumX = -360F;
public float maximumX = 360F;public float minimumY = -60F;
public float maximumY = 60F;private EyeXHost _eyeXHost;
private IEyeXDataProvider<EyeXFixationPoint> _fixationDataProvider;
private int _fixationCount;
//private GazePointDataComponent _gazePointDataComponent;#if UNITY_EDITOR
private FixationDataMode _oldFixationDataMode;
#endif/// <summary>
/// Choice of fixation data stream to be visualized.
/// </summary>
public FixationDataMode fixationDataMode = FixationDataMode.Sensitive;float rotationY;
public void Awake()
{
_eyeXHost = EyeXHost.GetInstance();
_fixationDataProvider = _eyeXHost.GetFixationDataProvider(fixationDataMode);#if UNITY_EDITOR
_oldFixationDataMode = fixationDataMode;
#endif
}public void OnEnable()
{
_fixationDataProvider.Start();
}public void OnDisable()
{
_fixationDataProvider.Stop();
}void Update ()
{
var fixationPoint = _fixationDataProvider.Last;
float gazeX=(2f*((float)fixationPoint.GazePoint.Viewport.x-0.5f));
float gazeY=(2f*((float)fixationPoint.GazePoint.Viewport.y-0.5f));
print (“gazeZy before floating=”+fixationPoint.GazePoint.Viewport.y);if (axes == RotationAxes.MouseXAndY)
{
//float rotationX = transform.localEulerAngles.y + Input.GetAxis(“Mouse X”) * sensitivityX;
float rotationX = transform.localEulerAngles.y + gazeX * sensitivityX;//rotationY += Input.GetAxis(“Mouse Y”) * sensitivityY;
rotationY += gazeY * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{//transform.Rotate(0, Input.GetAxis(“Mouse X”) * sensitivityX, 0);
transform.Rotate(0, gazeX * sensitivityX, 0);
}
else
{
//rotationY += Input.GetAxis(“Mouse Y”) * sensitivityY;rotationY += gazeY * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
//print (“rotationY AFTER=”+rotationY);
print (“gazeY=”+gazeY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}void Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
void getGazeAxis()
{}
}25/02/2015 at 11:48 #2603AndersParticipantHi Sai,
the gaze coordinates will be outside the range [0, 1] if the gaze is outside the viewport (the human gaze doesn’t care about viewport boundaries!). You can of course clamp them if you want them to always be within range.The EyeXGazePointDataStream returns EyeXDataPoint.Invalid — where X and Y are both NaN — until the stream has been started and the first data point received from the EyeX Engine. So you need to check for invalid data before passing it into the rotation calculations.
25/02/2015 at 14:35 #2608AderynParticipantHello Sai!
I work as the community manager here at Tobii and i’m very curious about your game! Have you gotten to the point where you are able to show anything?
23/03/2017 at 15:35 #6568Christian MenesesParticipantHi guys!
I am working on an FPS game, where I try to control the camera changing the MouseLook.cs script (the same idea of Sai). I am using almost the same gazeLook script and I got the problem with the rotationY (NaN). Actually, I checked the gaze coordinates values and they are in the range [0, 1]. I think the problem comes from the line (rotationY += gazeY * sensitivityY;), if I use (rotationY = gazeY * sensitivityY;) and I don’t get the problem of NaN, but of course the game does not work properly. Do you have maybe one idea of what I ding wrong or how can I solve the problem?.
Thanks
23/03/2017 at 16:37 #6569Alex [Tobii]ParticipantHi!
It’s generally not a good idea to simply control the camera with you eyes like you do it with mouse. Instead we created a feature called Extended View that turns the camera slightly around the crosshair/aim direction when you look at the sides of the screen or turn your head. Sample scripts for this feature will be included in the upcoming Unity SDK update. I will try to send you a beta package next week.
27/03/2017 at 16:20 #6575Christian MenesesParticipantHi Alex,
Great! , the Extended View looks pretty good. Thank you very much for your help, I will be waiting for the package.
- AuthorPosts
- You must be logged in to reply to this topic.