-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2f64d
commit 890ea5e
Showing
14 changed files
with
562 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ Library/* | |
Logs/* | ||
Temp/* | ||
obj/* | ||
SampleBuilds/* | ||
UserSettings/* | ||
.vsconfig | ||
*.csproj | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using UnityEngine; | ||
|
||
public class CameraControl : MonoBehaviour | ||
{ | ||
[SerializeField, Range(0.001f, 2.0f)] | ||
float scrollSpeed = 0.5f; | ||
|
||
[SerializeField, Range(0.001f, 2.0f)] | ||
float dragSpeed = 0.1f; | ||
|
||
[SerializeField, Range(0.001f, 2.0f)] | ||
float keySpeed = 0.2f; | ||
|
||
private Vector3 _pos; | ||
private Vector3 _dir; | ||
private Vector3 _right = Vector3.right; | ||
private float _yaw = 90.0f; | ||
private float _pitch = 0.0f; | ||
|
||
private bool _mouseDown = false; | ||
private Vector3 _mousePos = Vector3.zero; | ||
|
||
private void OnEnable() | ||
{ | ||
_pos = transform.position; | ||
_dir = Vector3.forward; | ||
UpdateCamera(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
bool updated = false; | ||
// check for scroll | ||
float scroll = Input.GetAxis("Mouse ScrollWheel"); | ||
if(scroll > 0.0f) | ||
{ | ||
_pos += _dir * scrollSpeed; | ||
updated = true; | ||
} | ||
else if(scroll < 0.0f) | ||
{ | ||
_pos -= _dir * scrollSpeed; | ||
updated = true; | ||
} | ||
if(Input.GetMouseButtonDown(0)) | ||
{ | ||
_mouseDown = true; | ||
_mousePos = Input.mousePosition; | ||
} | ||
// check for click and drag | ||
if (Input.GetMouseButtonUp(0)) _mouseDown = false; | ||
if(_mouseDown) | ||
{ | ||
Vector3 mousePos = Input.mousePosition; | ||
Vector3 delta = mousePos - _mousePos; | ||
_mousePos = mousePos; | ||
_yaw += delta.x * dragSpeed; | ||
_pitch += -delta.y * dragSpeed; | ||
_pitch = Mathf.Clamp(_pitch, -89.9f, 89.9f); | ||
UpdateDir(); | ||
updated = true; | ||
} | ||
// check for key controls | ||
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) | ||
{ | ||
_pos += _right * keySpeed; | ||
updated = true; | ||
} | ||
if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) | ||
{ | ||
_pos -= _right * keySpeed; | ||
updated = true; | ||
} | ||
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) | ||
{ | ||
_pos += _dir * keySpeed; | ||
updated = true; | ||
} | ||
if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) | ||
{ | ||
_pos -= _dir * keySpeed; | ||
updated = true; | ||
} | ||
if (updated) UpdateCamera(); | ||
} | ||
|
||
private void UpdateDir() | ||
{ | ||
_dir.x = Mathf.Cos(Mathf.Deg2Rad * _yaw) * Mathf.Cos(Mathf.Deg2Rad * _pitch); | ||
_dir.y = Mathf.Sin(Mathf.Deg2Rad * _pitch); | ||
_dir.z = Mathf.Sin(Mathf.Deg2Rad * _yaw) * Mathf.Cos(Mathf.Deg2Rad * _pitch); | ||
_dir = Vector3.Normalize(_dir); | ||
_right = Vector3.Normalize(Vector3.Cross(_dir, Vector3.up)); | ||
} | ||
|
||
private void UpdateCamera() | ||
{ | ||
transform.position = _pos; | ||
transform.LookAt(_pos + _dir); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using UnityEngine; | ||
|
||
public struct Sphere | ||
{ | ||
public Vector3 Position; | ||
public float Radius; | ||
public Vector3 Emission; | ||
public float Smoothness; | ||
public Vector3 Albedo; | ||
public Vector3 Specular; | ||
public static readonly int Size = 56; // structure size | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.