Skip to content

Commit b235932

Browse files
committed
update unity project and improve variable naming in camera code
1 parent 20e8ca2 commit b235932

File tree

7 files changed

+58
-53
lines changed

7 files changed

+58
-53
lines changed

PortalsWithRenderTargets/Assembly-CSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<DebugType>full</DebugType>
2323
<Optimize>false</Optimize>
2424
<OutputPath>Temp\bin\Debug\</OutputPath>
25-
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_3_2;UNITY_2018_3;UNITY_2018;UNITY_INCLUDE_TESTS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_TEXTURE_STREAMING;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;INCLUDE_PUBNUB;ENABLE_VIDEO;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;ENABLE_RUNTIME_GI;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_NETWORK;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_CLOUD_SERVICES_IOS_NATIVE_CRASH_REPORTING;ENABLE_IOS_ON_DEMAND_RESOURCES;ENABLE_IOS_APP_SLICING;PLAYERCONNECTION_LISTENS_FIXED_PORT;DEBUGGER_LISTENS_FIXED_PORT;PLATFORM_SUPPORTS_ADS_ID;SUPPORT_ENVIRONMENT_VARIABLES;PLATFORM_SUPPORTS_PROFILER;PLATFORM_HAS_NO_SUPPORT_FOR_BUCKET_ALLOCATOR;STRICTCPP_NEW_DELETE_SIGNATURES;HAS_NEON_SKINNING;UNITY_GFX_USE_PLATFORM_VSYNC;UNITY_INPUT_SIMULATE_EVENTS;PLATFORM_ALWAYS_USES_STDOUT_FOR_LOG;ENABLE_CRUNCH_TEXTURE_COMPRESSION;UNITY_ASTC_ONLY_DECOMPRESS;SUPPORTS_GRANULAR_MODULE_REGISTRATION;ENABLE_UNITYADS_RUNTIME;UNITY_UNITYADS_API;PLATFORM_IOS;UNITY_IOS;PLATFORM_IPHONE;UNITY_IPHONE;UNITY_IPHONE_API;SUPPORT_MULTIPLE_DISPLAYS;ENABLE_VR;ENABLE_AR;UNITY_HAS_GOOGLEVR;ENABLE_SPATIALTRACKING;ENABLE_MONO;NET_4_6;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;ENABLE_VSTU;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
25+
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_4_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2018_3_5;UNITY_2018_3;UNITY_2018;UNITY_INCLUDE_TESTS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_TEXTURE_STREAMING;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;ENABLE_MANAGED_ANIMATION_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;INCLUDE_PUBNUB;ENABLE_VIDEO;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;ENABLE_RUNTIME_GI;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_NETWORK;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_CLOUD_SERVICES_IOS_NATIVE_CRASH_REPORTING;ENABLE_IOS_ON_DEMAND_RESOURCES;ENABLE_IOS_APP_SLICING;PLAYERCONNECTION_LISTENS_FIXED_PORT;DEBUGGER_LISTENS_FIXED_PORT;PLATFORM_SUPPORTS_ADS_ID;SUPPORT_ENVIRONMENT_VARIABLES;PLATFORM_SUPPORTS_PROFILER;PLATFORM_HAS_NO_SUPPORT_FOR_BUCKET_ALLOCATOR;STRICTCPP_NEW_DELETE_SIGNATURES;HAS_NEON_SKINNING;UNITY_GFX_USE_PLATFORM_VSYNC;UNITY_INPUT_SIMULATE_EVENTS;PLATFORM_ALWAYS_USES_STDOUT_FOR_LOG;ENABLE_CRUNCH_TEXTURE_COMPRESSION;UNITY_ASTC_ONLY_DECOMPRESS;SUPPORTS_GRANULAR_MODULE_REGISTRATION;ENABLE_UNITYADS_RUNTIME;UNITY_UNITYADS_API;PLATFORM_IOS;UNITY_IOS;PLATFORM_IPHONE;UNITY_IPHONE;UNITY_IPHONE_API;SUPPORT_MULTIPLE_DISPLAYS;ENABLE_VR;ENABLE_AR;UNITY_HAS_GOOGLEVR;ENABLE_SPATIALTRACKING;ENABLE_MONO;NET_4_6;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX;ENABLE_UNITY_COLLECTIONS_CHECKS;ENABLE_BURST_AOT;UNITY_TEAM_LICENSE;ENABLE_VSTU;CSHARP_7_OR_LATER;CSHARP_7_3_OR_NEWER</DefineConstants>
2626
<ErrorReport>prompt</ErrorReport>
2727
<WarningLevel>4</WarningLevel>
2828
<NoWarn>0169</NoWarn>
@@ -49,7 +49,7 @@
4949
<UnityProjectGenerator>Unity/VSTU</UnityProjectGenerator>
5050
<UnityProjectType>Game:1</UnityProjectType>
5151
<UnityBuildTarget>iOS:9</UnityBuildTarget>
52-
<UnityVersion>2018.3.2f1</UnityVersion>
52+
<UnityVersion>2018.3.5f1</UnityVersion>
5353
</PropertyGroup>
5454
<ItemGroup>
5555
<Reference Include="UnityEngine">

PortalsWithRenderTargets/Assets/Scripts/CommonCamera.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22

3+
// Data shared by all cameras
34
[System.Serializable]
45
public class CommonCamera
56
{

PortalsWithRenderTargets/Assets/Scripts/DesktopCamera.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,53 @@ public bool CycleCamera()
1414
public (Quaternion Rotation, Vector3 Displacement) CalculateNextTransform(
1515
Vector3 right, Vector3 up, Vector3 forward)
1616
{
17-
Vector3 displacement = Vector3.zero;
18-
Quaternion rotation = Quaternion.identity;
17+
Vector3 displacementDelta = Vector3.zero;
18+
Quaternion rotationDelta = Quaternion.identity;
1919

2020
// Simple Mouse Look
2121
if (Input.GetMouseButton(1))
2222
{
23-
float xAxis = Input.GetAxis("Mouse X") * Camera.LookSpeed;
24-
float yAxis = Input.GetAxis("Mouse Y") * Camera.LookSpeed;
23+
Vector2 scaledMouseDelta =
24+
new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"))
25+
* Camera.LookSpeed;
2526

26-
Quaternion yRot = Quaternion.AngleAxis(xAxis, Vector3.up);
27-
Quaternion xRot = Quaternion.AngleAxis(-yAxis, right);
27+
Quaternion yAxisRotation = Quaternion.AngleAxis(scaledMouseDelta.x, Vector3.up);
28+
Quaternion xAxisRotation = Quaternion.AngleAxis(-scaledMouseDelta.y, right);
2829

29-
rotation = yRot * xRot;
30+
rotationDelta = yAxisRotation * xAxisRotation;
3031
}
3132

3233
// Basic Movement
3334
if (Input.GetKey(KeyCode.W))
3435
{
35-
displacement = forward * Camera.MoveSpeed * Time.deltaTime;
36+
displacementDelta = forward * Camera.MoveSpeed * Time.deltaTime;
3637
}
3738

3839
if (Input.GetKey(KeyCode.S))
3940
{
40-
displacement = -forward * Camera.MoveSpeed * Time.deltaTime;
41+
displacementDelta = -forward * Camera.MoveSpeed * Time.deltaTime;
4142
}
4243

4344
if (Input.GetKey(KeyCode.A))
4445
{
45-
displacement = -right * Camera.MoveSpeed * Time.deltaTime;
46+
displacementDelta = -right * Camera.MoveSpeed * Time.deltaTime;
4647
}
4748

4849
if (Input.GetKey(KeyCode.D))
4950
{
50-
displacement = right * Camera.MoveSpeed * Time.deltaTime;
51+
displacementDelta = right * Camera.MoveSpeed * Time.deltaTime;
5152
}
5253

5354
if (Input.GetKey(KeyCode.E))
5455
{
55-
displacement = Vector3.up * Camera.MoveSpeed * Time.deltaTime;
56+
displacementDelta = Vector3.up * Camera.MoveSpeed * Time.deltaTime;
5657
}
5758

5859
if (Input.GetKey(KeyCode.Q))
5960
{
60-
displacement = -Vector3.up * Camera.MoveSpeed * Time.deltaTime;
61+
displacementDelta = -Vector3.up * Camera.MoveSpeed * Time.deltaTime;
6162
}
6263

63-
return (rotation, displacement);
64+
return (rotationDelta, displacementDelta);
6465
}
6566
}

PortalsWithRenderTargets/Assets/Scripts/MobileCamera.cs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@ public bool CycleCamera()
2424
return taps == 3;
2525
}
2626

27-
public (Quaternion Rotation, Vector3 Displacement) CalculateNextTransform(
28-
Vector3 right, Vector3 up, Vector3 forward)
27+
public (Quaternion Rotation, Vector3 Displacement)
28+
CalculateNextTransform(Vector3 right, Vector3 up, Vector3 forward)
2929
{
30-
Vector3 displacement = Vector3.zero;
31-
Quaternion rotation = Quaternion.identity;
30+
// Zero displacement and rotation deltas
31+
Vector3 displacementDelta = Vector3.zero;
32+
Quaternion rotationDelta = Quaternion.identity;
3233

3334
// Free look
3435
if (Input.touchCount == 1)
3536
{
3637
Touch touch = Input.GetTouch(0);
3738

38-
Vector2 delta = touch.deltaPosition * Camera.LookSpeed;
39-
Quaternion yRot = Quaternion.AngleAxis(delta.x, Vector3.up);
40-
Quaternion xRot = Quaternion.AngleAxis(-delta.y, right);
41-
42-
rotation = yRot * xRot;
39+
Vector2 scaledTouchDelta = touch.deltaPosition * Camera.LookSpeed;
40+
Quaternion yAxisRotation = Quaternion.AngleAxis(scaledTouchDelta.x, Vector3.up);
41+
Quaternion xAxisRotation = Quaternion.AngleAxis(-scaledTouchDelta.y, right);
4342

43+
rotationDelta = yAxisRotation * xAxisRotation;
4444
Moving = Moving || touch.tapCount == 2;
45+
4546
if (Moving)
4647
{
47-
displacement = forward * Camera.MoveSpeed * Time.deltaTime;
48+
displacementDelta = forward * Camera.MoveSpeed * Time.deltaTime;
4849
}
4950
}
5051
// Panning + Zooming
@@ -54,46 +55,48 @@ public bool CycleCamera()
5455
Touch touch1 = Input.GetTouch(1);
5556

5657
// Get the sign of each touch in both x and y
57-
float sx0 = Mathf.Sign(touch0.deltaPosition.x);
58-
float sy0 = Mathf.Sign(touch0.deltaPosition.y);
59-
float sx1 = Mathf.Sign(touch1.deltaPosition.x);
60-
float sy1 = Mathf.Sign(touch1.deltaPosition.y);
58+
Vector2 touch0DeltaSign = new Vector2(
59+
Mathf.Sign(touch0.deltaPosition.x), Mathf.Sign(touch0.deltaPosition.y));
60+
Vector2 touch1DeltaSign = new Vector2(
61+
Mathf.Sign(touch1.deltaPosition.x), Mathf.Sign(touch1.deltaPosition.y));
62+
63+
// Sum the signs of the x and y input of both touches
64+
Vector2 twoTouchDeltaSign = touch0DeltaSign + touch1DeltaSign;
65+
// If the directions are opposite, zero the input, otherwise choose sign (-1 or +1)
66+
Vector2 finalTwoTouchDeltaSign = new Vector2(
67+
Mathf.Abs(twoTouchDeltaSign.x) > 0.0f ? Mathf.Sign(twoTouchDeltaSign.x) : 0.0f,
68+
Mathf.Abs(twoTouchDeltaSign.y) > 0.0f ? Mathf.Sign(twoTouchDeltaSign.y) : 0.0f);
6169

6270
// Find the min absolute movement in x and y
63-
float x = Mathf.Min(
64-
Mathf.Abs(touch0.deltaPosition.x), Mathf.Abs(touch1.deltaPosition.x));
65-
float y = Mathf.Min(
66-
Mathf.Abs(touch0.deltaPosition.y), Mathf.Abs(touch1.deltaPosition.y));
67-
68-
// Sum the signs of the x and y input, if the directions are opposite,
69-
// zero the input, otherwise choose sign (-1 or +1)
70-
float sx = Mathf.Abs(sx0 + sx1) > 0.0f ? Mathf.Sign(sx0 + sx1) : 0.0f;
71-
float sy = Mathf.Abs(sy0 + sy1) > 0.0f ? Mathf.Sign(sy0 + sy1) : 0.0f;
71+
Vector2 minTouchDelta = new Vector2(
72+
Mathf.Min(Mathf.Abs(touch0.deltaPosition.x), Mathf.Abs(touch1.deltaPosition.x)),
73+
Mathf.Min(Mathf.Abs(touch0.deltaPosition.y), Mathf.Abs(touch1.deltaPosition.y)));
7274

7375
// Pan in camera space (both touches must move in the same direction)
74-
Vector2 delta = new Vector2(x * sx, y * sy);
75-
displacement = ((right * delta.x) + (up * delta.y)) * PanSpeed;
76+
Vector2 finalInputDelta = minTouchDelta * finalTwoTouchDeltaSign;
77+
displacementDelta = ((right * finalInputDelta.x) + (up * finalInputDelta.y)) * PanSpeed;
7678

7779
// Pinch/Zoom Reference - https://unity3d.com/learn/tutorials/topics/mobile-touch/pinch-zoom
80+
{
81+
// Find the position in the previous frame of each touch.
82+
Vector2 touch0PrevPos = touch0.position - touch0.deltaPosition;
83+
Vector2 touch1PrevPos = touch1.position - touch1.deltaPosition;
7884

79-
// Find the position in the previous frame of each touch.
80-
Vector2 touch0PrevPos = touch0.position - touch0.deltaPosition;
81-
Vector2 touch1PrevPos = touch1.position - touch1.deltaPosition;
82-
83-
// Find the magnitude of the vector (the distance) between the touches in each frame.
84-
float prevTouchDeltaMag = (touch0PrevPos - touch1PrevPos).magnitude;
85-
float touchDeltaMag = (touch0.position - touch1.position).magnitude;
85+
// Find the magnitude of the vector (the distance) between the touches in each frame.
86+
float prevTouchDeltaMag = (touch0PrevPos - touch1PrevPos).magnitude;
87+
float touchDeltaMag = (touch0.position - touch1.position).magnitude;
8688

87-
// Find the difference in the distances between each frame.
88-
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
89+
// Find the difference in the distances between each frame.
90+
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
8991

90-
displacement -= forward * deltaMagnitudeDiff * ZoomSpeed;
92+
displacementDelta -= forward * deltaMagnitudeDiff * ZoomSpeed;
93+
}
9194
}
9295
else
9396
{
9497
Moving = false;
9598
}
9699

97-
return (rotation, displacement);
100+
return (rotationDelta, displacementDelta);
98101
}
99102
}
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
m_EditorVersion: 2018.3.2f1
1+
m_EditorVersion: 2018.3.5f1
Binary file not shown.

0 commit comments

Comments
 (0)