diff --git a/Assets/Tests/Beam.meta b/Assets/Art.meta similarity index 67% rename from Assets/Tests/Beam.meta rename to Assets/Art.meta index 07cff06..6f99e12 100644 --- a/Assets/Tests/Beam.meta +++ b/Assets/Art.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 0fe2d64981912a545a084438d8089f68 +guid: bd865f25edf545140a9ed3797bb1b4cb folderAsset: yes -timeCreated: 1439307965 +timeCreated: 1439489157 licenseType: Free DefaultImporter: userData: diff --git a/Assets/Tests/Beam/laserPic.png b/Assets/Art/LinkBeam.png similarity index 100% rename from Assets/Tests/Beam/laserPic.png rename to Assets/Art/LinkBeam.png diff --git a/Assets/Tests/Beam/laserPic.png.meta b/Assets/Art/LinkBeam.png.meta similarity index 100% rename from Assets/Tests/Beam/laserPic.png.meta rename to Assets/Art/LinkBeam.png.meta diff --git a/Assets/Tests/Beam/Materials.meta b/Assets/Materials.meta similarity index 100% rename from Assets/Tests/Beam/Materials.meta rename to Assets/Materials.meta diff --git a/Assets/Tests/Beam/Materials/laserPic.mat b/Assets/Materials/LinkBeam.mat similarity index 99% rename from Assets/Tests/Beam/Materials/laserPic.mat rename to Assets/Materials/LinkBeam.mat index fccb428..9f291df 100644 --- a/Assets/Tests/Beam/Materials/laserPic.mat +++ b/Assets/Materials/LinkBeam.mat @@ -6,7 +6,7 @@ Material: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - m_Name: laserPic + m_Name: LinkBeam m_Shader: {fileID: 200, guid: 0000000000000000f000000000000000, type: 0} m_ShaderKeywords: m_LightmapFlags: 5 diff --git a/Assets/Tests/Beam/Materials/laserPic.mat.meta b/Assets/Materials/LinkBeam.mat.meta similarity index 100% rename from Assets/Tests/Beam/Materials/laserPic.mat.meta rename to Assets/Materials/LinkBeam.mat.meta diff --git a/Assets/Tests/Beam/FriendshipLink.prefab b/Assets/Prefabs/FriendshipLink.prefab similarity index 100% rename from Assets/Tests/Beam/FriendshipLink.prefab rename to Assets/Prefabs/FriendshipLink.prefab diff --git a/Assets/Tests/Beam/FriendshipLink.prefab.meta b/Assets/Prefabs/FriendshipLink.prefab.meta similarity index 100% rename from Assets/Tests/Beam/FriendshipLink.prefab.meta rename to Assets/Prefabs/FriendshipLink.prefab.meta diff --git a/Assets/Prefabs/NetworkingSphere.prefab b/Assets/Prefabs/NetworkingSphere.prefab new file mode 100644 index 0000000..62a7070 --- /dev/null +++ b/Assets/Prefabs/NetworkingSphere.prefab @@ -0,0 +1,109 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &182606 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 4 + m_Component: + - 4: {fileID: 433422} + - 33: {fileID: 3303090} + - 23: {fileID: 2322642} + - 114: {fileID: 11432906} + - 54: {fileID: 5423250} + m_Layer: 0 + m_Name: NetworkingSphere + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &433422 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 182606} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 5.96046448e-08, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 +--- !u!23 &2322642 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 182606} + m_Enabled: 0 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_SubsetIndices: + m_StaticBatchRoot: {fileID: 0} + m_UseLightProbes: 1 + m_ReflectionProbeUsage: 1 + m_ProbeAnchor: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_ImportantGI: 0 + m_AutoUVMaxDistance: .5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 0 +--- !u!33 &3303090 +MeshFilter: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 182606} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!54 &5423250 +Rigidbody: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 182606} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: .800000012 + m_UseGravity: 0 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 +--- !u!114 &11432906 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 182606} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0907c1567bad554c8b995de3459e517, type: 3} + m_Name: + m_EditorClassIdentifier: + LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} + PersonObj: {fileID: 11406500, guid: d4b0e683ea5ec974987ea1f6741b333c, type: 2} + NumPeople: 100 + AvgNumFriends: 10 + FriendshipLikeliness: .300000012 + SphereRadius: 7 + rotationSpeed: .699999988 + torqueForce: 1 +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 182606} + m_IsPrefabParent: 1 diff --git a/Assets/Prefabs/NetworkingSphere.prefab.meta b/Assets/Prefabs/NetworkingSphere.prefab.meta new file mode 100644 index 0000000..192f1e3 --- /dev/null +++ b/Assets/Prefabs/NetworkingSphere.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 136ea38d5deb4c9418beb879167d9b03 +timeCreated: 1439489411 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Creator.unity b/Assets/Scenes/Creator.unity index 3dfa562..a3450aa 100644 --- a/Assets/Scenes/Creator.unity +++ b/Assets/Scenes/Creator.unity @@ -197,7 +197,7 @@ MeshRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 736567784} - m_Enabled: 0 + m_Enabled: 1 m_CastShadows: 1 m_ReceiveShadows: 1 m_Materials: @@ -258,10 +258,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - PersonObj: {fileID: 11406500, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2} - NumPeople: 200 + PersonObj: {fileID: 11406500, guid: d4b0e683ea5ec974987ea1f6741b333c, type: 2} + NumPeople: 100 AvgNumFriends: 10 - FriendshipLikeliness: 1 + FriendshipLikeliness: .300000012 SphereRadius: 7 rotationSpeed: .699999988 torqueForce: .100000001 diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index 94ce1de..f9e2958 100644 --- a/Assets/Scenes/Gameplay.unity +++ b/Assets/Scenes/Gameplay.unity @@ -293,100 +293,6 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 534364716} ---- !u!1 &736567784 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 736567788} - - 33: {fileID: 736567787} - - 23: {fileID: 736567785} - - 114: {fileID: 736567789} - - 54: {fileID: 736567786} - m_Layer: 0 - m_Name: Center - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!23 &736567785 -MeshRenderer: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 736567784} - m_Enabled: 0 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_SubsetIndices: - m_StaticBatchRoot: {fileID: 0} - m_UseLightProbes: 1 - m_ReflectionProbeUsage: 1 - m_ProbeAnchor: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 1 - m_ImportantGI: 0 - m_AutoUVMaxDistance: .5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingOrder: 0 ---- !u!54 &736567786 -Rigidbody: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 736567784} - serializedVersion: 2 - m_Mass: 1 - m_Drag: 0 - m_AngularDrag: .800000012 - m_UseGravity: 0 - m_IsKinematic: 0 - m_Interpolate: 0 - m_Constraints: 0 - m_CollisionDetection: 0 ---- !u!33 &736567787 -MeshFilter: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 736567784} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &736567788 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 736567784} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 5.96046448e-08, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 ---- !u!114 &736567789 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 736567784} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d0907c1567bad554c8b995de3459e517, type: 3} - m_Name: - m_EditorClassIdentifier: - Link: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} - Person: {fileID: 11406500, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2} - PointsAmount: 400 - SphereRadius: 7 - rotationSpeed: .699999988 - torqueForce: 50 --- !u!1 &1057734534 GameObject: m_ObjectHideFlags: 0 @@ -611,3 +517,45 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 4 +--- !u!1001 &2065124246 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalPosition.x + value: 5.96046448e-08 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 433422, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} + m_IsPrefabParent: 0 diff --git a/Assets/Tests/Beam/FriendshipLink.cs b/Assets/Scripts/FriendshipLink.cs similarity index 100% rename from Assets/Tests/Beam/FriendshipLink.cs rename to Assets/Scripts/FriendshipLink.cs diff --git a/Assets/Tests/Beam/FriendshipLink.cs.meta b/Assets/Scripts/FriendshipLink.cs.meta similarity index 100% rename from Assets/Tests/Beam/FriendshipLink.cs.meta rename to Assets/Scripts/FriendshipLink.cs.meta diff --git a/Assets/Scripts/Models/LevelGenerator.cs b/Assets/Scripts/Models/LevelGenerator.cs index 13d85fe..6e8ffb3 100644 --- a/Assets/Scripts/Models/LevelGenerator.cs +++ b/Assets/Scripts/Models/LevelGenerator.cs @@ -27,6 +27,12 @@ namespace DeathBook.Model { List people = new List(numPeople); + /* Sphere uniform distribution using the spiral method with the golden angle + * ~2.39996323 rad, the golden angle (the most irrational angle) + * is used here to make sure that the sin and cos functions + * dont end up drawing clusters of points and the spirals are way + * less visible. + */ float dlong = Mathf.PI * (3 - Mathf.Sqrt(5)); //~2.39996323 float dz = (2f / numPeople) * radius; diff --git a/Assets/Scripts/NetworkingSphere.cs b/Assets/Scripts/NetworkingSphere.cs new file mode 100644 index 0000000..27825b2 --- /dev/null +++ b/Assets/Scripts/NetworkingSphere.cs @@ -0,0 +1,114 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using DeathBook.Model; + +public class NetworkingSphere : MonoBehaviour +{ + public FriendshipLink LinkObj; + public PersonTest PersonObj; + public int NumPeople = 50; + public int AvgNumFriends = 20; + public float FriendshipLikeliness = 0.4f; + public float SphereRadius = 1f; + public float rotationSpeed = 0.7f; + + public float torqueForce = 50f; + private bool dragging = false; + private Vector3 delta = new Vector3(); + private Rigidbody rb; + + private PersonTest[] peopleNodes; + //TODO private Friendship[] friendships; + private GameObject[] nodes; + + void Awake() + { + LevelGenerator lGen = new LevelGenerator(); + Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius); + + InstantiateNodes(lvl); + AssignLinks(lvl); + rb = GetComponent(); + } + + void Update() + { + Vector3 screenMousePos = Input.mousePosition; + + screenMousePos.z = transform.position.z - Camera.main.transform.position.z; + + Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(screenMousePos); + + // If the world position of the mouse is greater than the radius of the sphere, we are outside + if (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > SphereRadius + 1f) + { + transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed); + } + + //when right btn clicked, call the chnge rotation + if (Input.GetMouseButtonDown(1)) + { + dragging = true; + } + else if (Input.GetMouseButtonUp(1)) + { + dragging = false; + delta = new Vector3(); + } + + if (dragging) + { + MoveSphere(); + } + } + + void MoveSphere() + { + float deltaX = Input.GetAxis("Mouse X"); + float deltaY = Input.GetAxis("Mouse Y"); + if (deltaX == 0 && deltaY == 0) + { + delta = new Vector3(); + rb.angularVelocity *= 0.8f; + } + delta += new Vector3(deltaX, deltaY, 0); + //rigidbody.AddTorque(); + rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.deltaTime, ForceMode.Impulse); + rb.AddTorque(Vector3.right * delta.y * torqueForce * Time.deltaTime, ForceMode.Impulse); + Debug.Log(delta.x + ", " + delta.y); + + + } + + private void InstantiateNodes(Level lvl) + { + peopleNodes = new PersonTest[lvl.people.Count]; + + int ctr = 0; + foreach (Person p in lvl.people) + { + + PersonTest pInst = Instantiate(PersonObj, p.initialPosition, Quaternion.identity) as PersonTest; + + pInst.transform.parent = this.transform; + + peopleNodes[ctr++] = pInst; + } + } + + private void AssignLinks(Level lvl) + { + foreach (Friendship f in lvl.friendships) + { + FriendshipLink link = Instantiate(LinkObj) as FriendshipLink; + int id1 = f.friend1.id; + int id2 = f.friend2.id; + link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject); + + // Temporary stuff, for testing + peopleNodes[id1].AddLink(link); + peopleNodes[id2].AddLink(link); + } + } +} diff --git a/Assets/Tests/Center.cs.meta b/Assets/Scripts/NetworkingSphere.cs.meta similarity index 100% rename from Assets/Tests/Center.cs.meta rename to Assets/Scripts/NetworkingSphere.cs.meta diff --git a/Assets/Tests/Center.cs b/Assets/Tests/Center.cs deleted file mode 100644 index 22b4f5a..0000000 --- a/Assets/Tests/Center.cs +++ /dev/null @@ -1,146 +0,0 @@ -using UnityEngine; -using System.Collections; -using System.Collections.Generic; - -public class Center : MonoBehaviour -{ - - //public float fov = Camera.main.fieldOfView; - public Vector3 nextPosition; - public float moveSpeed = 0; - - public FriendshipLink Link; - public PersonTest Person; - public int PointsAmount = 50; - public float SphereRadius = 1f; - public float rotationSpeed = 0.7f; - - public float torqueForce = 50f; - private bool dragging = false; - private Vector3 delta = new Vector3(); - private Rigidbody rb; - private PersonTest[] people; - - - private GameObject[] nodes; - - void Awake() - { - InstantiateNodes(); - AssignLinks(); - rb = GetComponent(); - } - - void Update() - { - Vector3 screenMousePos = Input.mousePosition; - - screenMousePos.z = transform.position.z - Camera.main.transform.position.z; - - Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(screenMousePos); - - // If the world position of the mouse is greater than the radius of the sphere, we are outside - if (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > SphereRadius + 1f) - { - transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed); - } - - //when right btn clicked, call the chnge rotation - if (Input.GetMouseButtonDown(1)) - { - dragging = true; - } - else if (Input.GetMouseButtonUp(1)) - { - dragging = false; - delta = new Vector3(); - } - - //camera zoom - if (Input.GetAxis("Mouse ScrollWheel") != 0) - { - Debug.Log("Pressed middle click."); - //Camera.main.transform.position.z += (moveSpeed * Time.deltaTime); - //transform.position = Vector3.Lerp(transform.position, nextPosition, Time.deltaTime * moveSpeed); - //Camera.main.fieldOfView += Input.GetAxis("Mouse ScrollWheel") * 10f; - //Camera.main.transform - } - } - - void FixedUpdate() - { - if (dragging) - { - MoveSphere(); - } - } - - void MoveSphere() - { - float deltaX = Input.GetAxis("Mouse X"); - float deltaY = Input.GetAxis("Mouse Y"); - if (deltaX == 0 && deltaY == 0) - { - delta = new Vector3(); - rb.angularVelocity *= 0.8f; - } - delta += new Vector3(deltaX, deltaY, 0); - rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.fixedDeltaTime, ForceMode.Impulse); - rb.AddTorque(Vector3.right * delta.y * torqueForce * Time.fixedDeltaTime, ForceMode.Impulse); - Debug.Log(delta.x + ", " + delta.y); - - - } - - - - private void InstantiateNodes() - { - /* Sphere uniform distribution using the spiral method with the golden angle - * ~2.39996323 rad, the golden angle (the most irrational angle) - * is used here to make sure that the sin and cos functions - * dont end up drawing clusters of points and the spirals are way - * less visible. - */ - people = new PersonTest[PointsAmount]; - - float goldenAngle = Mathf.PI * (3 - Mathf.Sqrt(5)); - - float zDistance = (2f / PointsAmount) * SphereRadius; - float longitude = 0f; - float z = SphereRadius; - - for (int i = 0; i < PointsAmount; i++) - { - float r = Mathf.Sqrt(SphereRadius * SphereRadius - z * z); - - float x = Mathf.Sin(longitude) * r; - float y = Mathf.Cos(longitude) * r; - - PersonTest simon = Instantiate(Person, new Vector3(x, y, z), Quaternion.identity) as PersonTest; - - simon.transform.parent = this.transform; - - people[i] = simon; - - z -= zDistance; - longitude += goldenAngle; - } - } - - private void AssignLinks() - { - for (int i = 0; i < people.Length / 4; i++) - { - FriendshipLink link = Instantiate(Link) as FriendshipLink; - - int destinationIndex = Random.Range(people.Length / 2, people.Length - 1); - - link.AttachToObjects(people[i].gameObject, people[destinationIndex].gameObject); - - // Temporary stuff, for testing - people[i].AddLink(link); - people[destinationIndex].AddLink(link); - } - } -} diff --git a/Assets/Tests/PersonTest.cs b/Assets/Tests/PersonTest.cs index 72cfb01..9e5d4a9 100644 --- a/Assets/Tests/PersonTest.cs +++ b/Assets/Tests/PersonTest.cs @@ -21,7 +21,6 @@ public class PersonTest : MonoBehaviour void OnMouseOver() { - Debug.Log("abc"); if (!_highlighted) { _highlighted = true; diff --git a/Assets/Tests/PersonTest.prefab.meta b/Assets/Tests/PersonTest.prefab.meta index 8f2ef77..5ecbe33 100644 --- a/Assets/Tests/PersonTest.prefab.meta +++ b/Assets/Tests/PersonTest.prefab.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 646dd6566f9e1374caa3af8ad37c43d3 -timeCreated: 1439361747 +guid: d4b0e683ea5ec974987ea1f6741b333c +timeCreated: 1439489111 licenseType: Free NativeFormatImporter: userData: diff --git a/Assets/Tests/SphereSR.cs b/Assets/Tests/SphereSR.cs index 6f452fe..a3604ea 100644 --- a/Assets/Tests/SphereSR.cs +++ b/Assets/Tests/SphereSR.cs @@ -1,94 +1,88 @@ -using UnityEngine; -using System.Collections; +using UnityEngine; +using System.Collections; using System.Collections.Generic; -using DeathBook.Model; - -public class SphereSR : MonoBehaviour -{ - public FriendshipLink LinkObj; - public PersonTest PersonObj; +using DeathBook.Model; + +public class SphereSR : MonoBehaviour +{ + public FriendshipLink LinkObj; + public PersonTest PersonObj; public int NumPeople = 50; public int AvgNumFriends = 20; - public float FriendshipLikeliness = 0.4f; - public float SphereRadius = 1f; - public float rotationSpeed = 0.7f; - - public float torqueForce = 50f; - private bool dragging = false; - private Vector3 delta = new Vector3(); - private Rigidbody rb; - + public float FriendshipLikeliness = 0.4f; + public float SphereRadius = 1f; + public float rotationSpeed = 0.7f; + + public float torqueForce = 50f; + private bool dragging = false; + private Vector3 delta = new Vector3(); + private Rigidbody rb; + private PersonTest[] peopleNodes; - //TODO private Friendship[] friendships; - private GameObject[] nodes; - - void Awake() - { + //TODO private Friendship[] friendships; + private GameObject[] nodes; + + void Awake() + { LevelGenerator lGen = new LevelGenerator(); - Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius); - - InstantiateNodes(lvl); - AssignLinks(lvl); - rb = GetComponent(); - } - - void Update() - { - Vector3 screenMousePos = Input.mousePosition; - - screenMousePos.z = transform.position.z - Camera.main.transform.position.z; - - Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(screenMousePos); - - // If the world position of the mouse is greater than the radius of the sphere, we are outside - if (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > SphereRadius + 1f) - { - transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed); - } - - //when right btn clicked, call the chnge rotation - if (Input.GetMouseButtonDown(1)) - { - dragging = true; - } - else if (Input.GetMouseButtonUp(1)) - { - dragging = false; - delta = new Vector3(); - } - - if (dragging) - { - MoveSphere(); - } - } - - void MoveSphere() - { - float deltaX = Input.GetAxis("Mouse X"); - float deltaY = Input.GetAxis("Mouse Y"); - if (deltaX == 0 && deltaY == 0) - { - delta = new Vector3(); - rb.angularVelocity *= 0.8f; - } - delta += new Vector3(deltaX, deltaY, 0); - //rigidbody.AddTorque(); - rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.deltaTime, ForceMode.Impulse); - rb.AddTorque(Vector3.right * delta.y * torqueForce * Time.deltaTime, ForceMode.Impulse); - Debug.Log(delta.x + ", " + delta.y); - - - } - - private void InstantiateNodes(Level lvl) - { - /* Sphere uniform distribution using the spiral method with the golden angle - * ~2.39996323 rad, the golden angle (the most irrational angle) - * is used here to make sure that the sin and cos functions - * dont end up drawing clusters of points and the spirals are way - * less visible. - */ + Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius); + + InstantiateNodes(lvl); + AssignLinks(lvl); + rb = GetComponent(); + } + + void Update() + { + Vector3 screenMousePos = Input.mousePosition; + + screenMousePos.z = transform.position.z - Camera.main.transform.position.z; + + Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(screenMousePos); + + // If the world position of the mouse is greater than the radius of the sphere, we are outside + if (Mathf.Sqrt(worldMousePos.x * worldMousePos.x + worldMousePos.y * worldMousePos.y) > SphereRadius + 1f) + { + transform.Rotate(Vector3.one * Time.deltaTime * rotationSpeed); + } + + //when right btn clicked, call the chnge rotation + if (Input.GetMouseButtonDown(1)) + { + dragging = true; + } + else if (Input.GetMouseButtonUp(1)) + { + dragging = false; + delta = new Vector3(); + } + + if (dragging) + { + MoveSphere(); + } + } + + void MoveSphere() + { + float deltaX = Input.GetAxis("Mouse X"); + float deltaY = Input.GetAxis("Mouse Y"); + if (deltaX == 0 && deltaY == 0) + { + delta = new Vector3(); + rb.angularVelocity *= 0.8f; + } + delta += new Vector3(deltaX, deltaY, 0); + //rigidbody.AddTorque(); + rb.AddTorque(Vector3.down * delta.x * torqueForce * Time.deltaTime, ForceMode.Impulse); + rb.AddTorque(Vector3.right * delta.y * torqueForce * Time.deltaTime, ForceMode.Impulse); + Debug.Log(delta.x + ", " + delta.y); + + + } + + private void InstantiateNodes(Level lvl) + { peopleNodes = new PersonTest[lvl.people.Count]; int ctr = 0; @@ -100,10 +94,10 @@ public class SphereSR : MonoBehaviour pInst.transform.parent = this.transform; peopleNodes[ctr++] = pInst; - } - } - - private void AssignLinks(Level lvl) + } + } + + private void AssignLinks(Level lvl) { foreach (Friendship f in lvl.friendships) { @@ -111,10 +105,10 @@ public class SphereSR : MonoBehaviour int id1 = f.friend1.id; int id2 = f.friend2.id; link.AttachToObjects(peopleNodes[id1].gameObject, peopleNodes[id2].gameObject); - - // Temporary stuff, for testing - peopleNodes[id1].AddLink(link); + + // Temporary stuff, for testing + peopleNodes[id1].AddLink(link); peopleNodes[id2].AddLink(link); - } - } -} + } + } +}