-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance increase #19
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using UnityEngine; | ||
|
||
|
@@ -11,29 +11,39 @@ class SpaceNavigatorWindows : SpaceNavigator { | |
private const float TransSensScale = 0.0001f, RotSensScale = 0.0008f; | ||
|
||
// Public API | ||
public override Vector3 GetTranslation() { | ||
public override Vector3 GetTranslation() | ||
{ | ||
if (SubInstance._sensor != null && Translation == null) | ||
Translation = SubInstance._sensor.Translation; | ||
|
||
float sensitivity = Application.isPlaying ? Settings.PlayTransSens : Settings.TransSens[Settings.CurrentGear]; | ||
return (SubInstance._sensor == null ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing |
||
Vector3.zero : | ||
new Vector3( | ||
Settings.GetLock(DoF.Translation, Axis.X) ? 0 : (float)SubInstance._sensor.Translation.X, | ||
Settings.GetLock(DoF.Translation, Axis.Y) ? 0 : (float)SubInstance._sensor.Translation.Y, | ||
Settings.GetLock(DoF.Translation, Axis.Z) ? 0 : -(float)SubInstance._sensor.Translation.Z) * | ||
Settings.GetLock(DoF.Translation, Axis.X) ? 0 : (float)Translation.X, | ||
Settings.GetLock(DoF.Translation, Axis.Y) ? 0 : (float)Translation.Y, | ||
Settings.GetLock(DoF.Translation, Axis.Z) ? 0 : -(float)Translation.Z) * | ||
sensitivity * TransSensScale); | ||
} | ||
public override Quaternion GetRotation() { | ||
float sensitivity = Application.isPlaying ? Settings.PlayRotSens : Settings.RotSens; | ||
if (SubInstance._sensor != null && Rotation == null) | ||
Rotation = SubInstance._sensor.Rotation; | ||
|
||
float sensitivity = Application.isPlaying ? Settings.PlayRotSens : Settings.RotSens; | ||
return (SubInstance._sensor == null ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, testing |
||
Quaternion.identity : | ||
Quaternion.AngleAxis( | ||
(float)SubInstance._sensor.Rotation.Angle * sensitivity * RotSensScale, | ||
(float)Rotation.Angle * sensitivity * RotSensScale, | ||
new Vector3( | ||
Settings.GetLock(DoF.Rotation, Axis.X) ? 0 : -(float)SubInstance._sensor.Rotation.X, | ||
Settings.GetLock(DoF.Rotation, Axis.Y) ? 0 : -(float)SubInstance._sensor.Rotation.Y, | ||
Settings.GetLock(DoF.Rotation, Axis.Z) ? 0 : (float)SubInstance._sensor.Rotation.Z))); | ||
Settings.GetLock(DoF.Rotation, Axis.X) ? 0 : -(float)Rotation.X, | ||
Settings.GetLock(DoF.Rotation, Axis.Y) ? 0 : -(float)Rotation.Y, | ||
Settings.GetLock(DoF.Rotation, Axis.Z) ? 0 : (float)Rotation.Z))); | ||
} | ||
|
||
// Device variables | ||
private AngleAxis Rotation; | ||
private Vector3D Translation; | ||
|
||
private Sensor _sensor; | ||
private Device _device; | ||
//private Keyboard _keyboard; | ||
|
@@ -53,7 +63,7 @@ private SpaceNavigatorWindows() { | |
_device.Connect(); | ||
} | ||
catch (COMException ex) { | ||
Debug.LogError(ex.ToString()); | ||
//Debug.LogError(ex.ToString()); | ||
} | ||
} | ||
|
||
|
@@ -79,4 +89,4 @@ public override void Dispose() { | |
#endregion - IDisposable - | ||
} | ||
#endif // UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Match the indent of the rest of this method, especially since you're not using
{
}
(which I would highly recommend using).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a real-world example of why you should really use curly braces (TLDR: major security failure in Apple's SSL).
https://blog.codecentric.de/en/2014/02/curly-braces/