Skip to content
Snippets Groups Projects
Commit 12906289 authored by Marco Zimmer's avatar Marco Zimmer
Browse files

+added Lot&Pendulum-Tool +Using Math3d lib for VectorCalculus +Changed Fact...

+added Lot&Pendulum-Tool +Using Math3d lib for VectorCalculus +Changed Fact managment (unstable\!) +Misc refactoring
parent 174f8fa6
No related branches found
No related tags found
No related merge requests found
Showing
with 64482 additions and 339 deletions
fileFormatVersion: 2
guid: 710d2f3e22c5f9c46bcf1a3f11e2cbbb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using UnityEngine;
using UnityEditor;
public class LaserPointer : Editor
{
static public RaycastHit laserHit;
static public bool laserBool;
[ExecuteInEditMode]
static void Init()
{
laserBool = false;
}
void OnSceneGUI()
{
Vector3 mousePosition = Event.current.mousePosition;
Ray ray = Camera.current.ScreenPointToRay(mousePosition);
RaycastHit tempHit;
if (!(laserBool = Physics.Raycast(ray, out tempHit, Mathf.Infinity, int.MaxValue)))
return ;
laserHit = tempHit;
}
}
fileFormatVersion: 2
guid: fac7f574cbd00a44e85cdbbbc91cfe8e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

using System.Collections;
using UnityEngine;
using UnityEditor;
/* ############################
* ## Show Size Editor Addon ##
* ## This script reports ##
* ## the size of a object ##
* ## in x,y and z axis'. ##
* ## All work by Eric5h5 ##
* ##forum.unity3d.com/threa ##
* ## ds/object-size.19991 ##
* ## C# conversion and warn ##
* ##ing fix by Nsomnia of ##
* ## BlenderTek.com and last##
* ## function by justinlloyd##
* ############################ */
class ShowSize : EditorWindow
{
[MenuItem("Window/ShowSize")]
static void Init()
{
// Get existing open window or if none, make a new one:
//Next line replaces old statment causing a warning in Unity 4.6 used to be "ShowSize sizeWindow = new ShowSize();"
ShowSize sizeWindow = ScriptableObject.CreateInstance(typeof(ShowSize)) as ShowSize;
sizeWindow.autoRepaintOnSceneChange = true;
sizeWindow.Show();
}
void OnGUI()
{
if (Selection.activeGameObject != null)
{
GameObject thisObject = Selection.activeObject as GameObject;
if (thisObject == null)
{
return;
}
MeshFilter mf = thisObject.GetComponent(typeof(MeshFilter)) as MeshFilter;
if (mf == null)
{ return; }
Mesh mesh = mf.sharedMesh;
if (mesh == null)
{ return; }
Vector3 size = mesh.bounds.size;
Vector3 scale = thisObject.transform.localScale;
GUILayout.Label("Size\n X: " + size.x * scale.x + "\n Y: " + size.y * scale.y + "\n Z: " + size.z * scale.z + "");
}
if (!LaserPointer.laserBool)
return;
RaycastHit laserHit = LaserPointer.laserHit;
GUILayout.Label("Laser Pointer:\n " + laserHit.transform.position.ToString() + "\n\n");
}
void Update()
{
Repaint();
}
}
fileFormatVersion: 2
guid: db001aa03cd8fd3409b8667cdc6958dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -12,7 +12,7 @@ GameObject: ...@@ -12,7 +12,7 @@ GameObject:
- component: {fileID: 2222111361403691372} - component: {fileID: 2222111361403691372}
- component: {fileID: 2222111361402594220} - component: {fileID: 2222111361402594220}
- component: {fileID: 6601886996393371248} - component: {fileID: 6601886996393371248}
m_Layer: 0 m_Layer: 15
m_Name: Tree_01 m_Name: Tree_01
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
...@@ -29,7 +29,8 @@ Transform: ...@@ -29,7 +29,8 @@ Transform:
m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalRotation: {x: 0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children:
- {fileID: 3984837096562236602}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -55,6 +56,7 @@ MeshRenderer: ...@@ -55,6 +56,7 @@ MeshRenderer:
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
...@@ -66,6 +68,7 @@ MeshRenderer: ...@@ -66,6 +68,7 @@ MeshRenderer:
m_ProbeAnchor: {fileID: 0} m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1 m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0 m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0 m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0 m_ImportantGI: 0
...@@ -88,7 +91,100 @@ MeshCollider: ...@@ -88,7 +91,100 @@ MeshCollider:
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 0 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 4
m_Convex: 0 m_Convex: 0
m_CookingOptions: 14 m_CookingOptions: 30
m_Mesh: {fileID: 4300000, guid: 6c7eaede4efc960409fb9ef2dfb77f29, type: 3} m_Mesh: {fileID: 4300000, guid: 6c7eaede4efc960409fb9ef2dfb77f29, type: 3}
--- !u!1 &4150715447553002155
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3984837096562236602}
- component: {fileID: 7455726115425455088}
- component: {fileID: 933372636075482527}
- component: {fileID: 539717056228735193}
m_Layer: 0
m_Name: TopSnapZone
m_TagString: SnapZone
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3984837096562236602
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4150715447553002155}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.078, y: 5.557, z: 0.682}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2222111361405018444}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!135 &7455726115425455088
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4150715447553002155}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &933372636075482527
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4150715447553002155}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &539717056228735193
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4150715447553002155}
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: e3750cc498409144f8fd06ac559355b8, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
...@@ -12,7 +12,7 @@ GameObject: ...@@ -12,7 +12,7 @@ GameObject:
- component: {fileID: 4661435515761518820} - component: {fileID: 4661435515761518820}
- component: {fileID: 4661435515760519716} - component: {fileID: 4661435515760519716}
- component: {fileID: 1232560684170311422} - component: {fileID: 1232560684170311422}
m_Layer: 0 m_Layer: 15
m_Name: Tree_02 m_Name: Tree_02
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
...@@ -29,7 +29,8 @@ Transform: ...@@ -29,7 +29,8 @@ Transform:
m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} m_LocalRotation: {x: 0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children:
- {fileID: 945775986148446862}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -55,6 +56,7 @@ MeshRenderer: ...@@ -55,6 +56,7 @@ MeshRenderer:
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
...@@ -66,6 +68,7 @@ MeshRenderer: ...@@ -66,6 +68,7 @@ MeshRenderer:
m_ProbeAnchor: {fileID: 0} m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1 m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0 m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0 m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0 m_ImportantGI: 0
...@@ -88,7 +91,100 @@ MeshCollider: ...@@ -88,7 +91,100 @@ MeshCollider:
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 0 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 4
m_Convex: 0 m_Convex: 0
m_CookingOptions: 14 m_CookingOptions: 30
m_Mesh: {fileID: 4300000, guid: 4471b1f7f824e4d44887e1364c6fc61a, type: 3} m_Mesh: {fileID: 4300000, guid: 4471b1f7f824e4d44887e1364c6fc61a, type: 3}
--- !u!1 &5974816098015535063
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 945775986148446862}
- component: {fileID: 2264167205531249358}
- component: {fileID: 4646352123586789184}
- component: {fileID: 6011793418505273338}
m_Layer: 16
m_Name: TopSnapZone
m_TagString: SnapZone
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &945775986148446862
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5974816098015535063}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.043, y: 4.199, z: 0.012}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_Children: []
m_Father: {fileID: 4661435515762813124}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!135 &2264167205531249358
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5974816098015535063}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &4646352123586789184
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5974816098015535063}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6011793418505273338
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5974816098015535063}
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: e3750cc498409144f8fd06ac559355b8, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
...@@ -343,10 +343,6 @@ MonoBehaviour: ...@@ -343,10 +343,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a6b9fc46f5bfe6b4eb4adf01e6b65bac, type: 3} m_Script: {fileID: 11500000, guid: a6b9fc46f5bfe6b4eb4adf01e6b65bac, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
meshRendererToChange: {fileID: 4008433908760336842}
animationStartColor: {r: 0.98039216, g: 0.99215686, b: 0.03137255, a: 1}
animationEndColor: {r: 1, g: 0.52156866, b: 0.007843138, a: 1}
animateDuration: 5
--- !u!1 &6378548342073962023 --- !u!1 &6378548342073962023
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -35,6 +35,7 @@ Transform: ...@@ -35,6 +35,7 @@ Transform:
- {fileID: 338274751687282010} - {fileID: 338274751687282010}
- {fileID: 5939570736350582895} - {fileID: 5939570736350582895}
- {fileID: 206589483256967431} - {fileID: 206589483256967431}
- {fileID: 1897634834899172406}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
...@@ -123,10 +124,6 @@ MonoBehaviour: ...@@ -123,10 +124,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a6b9fc46f5bfe6b4eb4adf01e6b65bac, type: 3} m_Script: {fileID: 11500000, guid: a6b9fc46f5bfe6b4eb4adf01e6b65bac, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
meshRendererToChange: {fileID: 1075046474335495899}
animationStartColor: {r: 0.98039216, g: 0.99215686, b: 0.03137255, a: 1}
animationEndColor: {r: 1, g: 0.52156866, b: 0.007843138, a: 1}
animateDuration: 5
--- !u!1 &942938646191423391 --- !u!1 &942938646191423391
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -346,6 +343,50 @@ MonoBehaviour: ...@@ -346,6 +343,50 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Cam: {fileID: 0} Cam: {fileID: 0}
--- !u!1 &3501726312507320707
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1897634834899172406}
- component: {fileID: 2282314938058693146}
m_Layer: 10
m_Name: Sphere_Snap
m_TagString: SnapZone
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &1897634834899172406
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3501726312507320707}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 7110486964728869325}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!135 &2282314938058693146
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3501726312507320707}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &7522635739010457072 --- !u!1 &7522635739010457072
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
This diff is collapsed.
fileFormatVersion: 2
guid: d8bb1056a00f4744eb285ed21840b6ce
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
...@@ -48,7 +48,9 @@ public string format(float t) ...@@ -48,7 +48,9 @@ public string format(float t)
public abstract GameObject instantiateDisplay(GameObject prefab, Transform transform); public abstract GameObject instantiateDisplay(GameObject prefab, Transform transform);
public abstract override bool Equals(System.Object obj); public abstract bool Equivalent(Fact f2);
public abstract bool Equivalent(Fact f1, Fact f2);
public abstract override int GetHashCode(); public abstract override int GetHashCode();
...@@ -58,9 +60,73 @@ public static string getLetter(int Id) ...@@ -58,9 +60,73 @@ public static string getLetter(int Id)
} }
} }
public abstract class DirectedFact : Fact public abstract class FactWrappedCRTP<T>: Fact where T: FactWrappedCRTP<T>
{
public override bool Equivalent(Fact f2)
{
return Equivalent(this, f2);
}
public override bool Equivalent(Fact f1, Fact f2)
{
return EquivalentWrapped((T)f1, (T)f2);
}
protected abstract bool EquivalentWrapped(T f1, T f2);
}
public abstract class AbstractLineFact: FactWrappedCRTP<AbstractLineFact>
{
//Id's of the 2 Point-Facts that are connected
public int Pid1, Pid2;
// normalized Direction from Pid1 to Pid2
public Vector3 Dir;
//only for temporary Use of LineFacts.
public AbstractLineFact() { }
//public AbstractLineFact(int i, int pid1, int pid2);
public AbstractLineFact(int pid1, int pid2, string backendURI)
{
this.Pid1 = pid1;
this.Pid2 = pid2;
PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact;
PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact;
this.Dir = (pf2.Point - pf1.Point).normalized;
this.backendURI = backendURI;
}
public override bool hasDependentFacts()
{
return true;
}
public override int[] getDependentFactIds()
{ {
public DirectedFact flippedFact; return new int[] { Pid1, Pid2 };
}
public override int GetHashCode()
{
return this.Pid1 ^ this.Pid2;
}
}
public abstract class AbstractLineFactWrappedCRTP<T>: AbstractLineFact where T: AbstractLineFactWrappedCRTP<T>
{
//only for temporary Use of LineFacts.
public AbstractLineFactWrappedCRTP() { }
public AbstractLineFactWrappedCRTP (int pid1, int pid2, string backendURI) : base(pid1, pid2, backendURI) { }
protected override bool EquivalentWrapped(AbstractLineFact f1, AbstractLineFact f2)
{
return EquivalentWrapped((T)f1, (T)f2);
}
protected abstract bool EquivalentWrapped(T f1, T f2);
} }
public class AddFactResponse public class AddFactResponse
...@@ -101,7 +167,7 @@ public static AddFactResponse sendAdd(string path, string body) ...@@ -101,7 +167,7 @@ public static AddFactResponse sendAdd(string path, string body)
} }
//I am not sure if we ever need to attach these to an object, so one script for all for now... //I am not sure if we ever need to attach these to an object, so one script for all for now...
public class PointFact : Fact public class PointFact : FactWrappedCRTP<PointFact>
{ {
public Vector3 Point; public Vector3 Point;
public Vector3 Normal; public Vector3 Normal;
...@@ -169,34 +235,21 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans ...@@ -169,34 +235,21 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
obj.GetComponent<FactWrapper>().fact = this; obj.GetComponent<FactWrapper>().fact = this;
return obj; return obj;
} }
public override int GetHashCode()
public override bool Equals(System.Object obj)
{
//Check for null and compare run-time types.
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{
return false;
}
else
{ {
PointFact p = (PointFact)obj; return this.Point.GetHashCode() ^ this.Normal.GetHashCode();
return this.Point.Equals(p.Point) && this.Normal.Equals(p.Normal);
}
} }
public override int GetHashCode() protected override bool EquivalentWrapped(PointFact f1, PointFact f2)
{ {
return this.Point.GetHashCode() ^ this.Normal.GetHashCode(); return f1.Point == f2.Point;
} }
} }
public class LineFact : DirectedFact public class LineFact : AbstractLineFactWrappedCRTP<LineFact>
{ {
//Id's of the 2 Point-Facts that are connected public LineFact(int pid1, int pid2, string backendURI) : base(pid1, pid2, backendURI) { }
public int Pid1, Pid2;
//only for temporary Use of LineFacts.
public LineFact() { }
public LineFact(int i, int pid1, int pid2) public LineFact(int i, int pid1, int pid2)
{ {
...@@ -205,6 +258,7 @@ public LineFact(int i, int pid1, int pid2) ...@@ -205,6 +258,7 @@ public LineFact(int i, int pid1, int pid2)
this.Pid2 = pid2; this.Pid2 = pid2;
PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact; PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact;
PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact; PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact;
this.Dir = (pf2.Point - pf1.Point).normalized;
//Label is currently set to Fact.setId //Label is currently set to Fact.setId
//Set Label to StringConcatenation of Points //Set Label to StringConcatenation of Points
...@@ -234,13 +288,6 @@ public LineFact(int i, int pid1, int pid2) ...@@ -234,13 +288,6 @@ public LineFact(int i, int pid1, int pid2)
Debug.Log(this.backendURI); Debug.Log(this.backendURI);
} }
public LineFact(int Pid1, int Pid2, string backendURI)
{
this.Pid1 = Pid1;
this.Pid2 = Pid2;
this.backendURI = backendURI;
}
public static LineFact parseFact(Scroll.ScrollFact fact) public static LineFact parseFact(Scroll.ScrollFact fact)
{ {
String uri = fact.@ref.uri; String uri = fact.@ref.uri;
...@@ -259,16 +306,6 @@ public static LineFact parseFact(Scroll.ScrollFact fact) ...@@ -259,16 +306,6 @@ public static LineFact parseFact(Scroll.ScrollFact fact)
} }
} }
public override Boolean hasDependentFacts()
{
return true;
}
public override int[] getDependentFactIds()
{
return new int[] { Pid1, Pid2 };
}
public override GameObject instantiateDisplay(GameObject prefab, Transform transform) public override GameObject instantiateDisplay(GameObject prefab, Transform transform)
{ {
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
...@@ -278,33 +315,25 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans ...@@ -278,33 +315,25 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
return obj; return obj;
} }
public override bool Equals(System.Object obj) protected override bool EquivalentWrapped(LineFact f1, LineFact f2)
{
//Check for null and compare run-time types.
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{ {
return false; if ((f1.Pid1 == f2.Pid1 && f1.Pid2 == f2.Pid2))// ||
} //(f1.Pid1 == f2.Pid2 && f1.Pid2 == f2.Pid1))
else return true;
{
LineFact l = (LineFact)obj;
return this.Pid1.Equals(l.Pid1) && this.Pid2.Equals(l.Pid2);
}
}
public override int GetHashCode() PointFact p1f1 = (PointFact)CommunicationEvents.Facts[f1.Pid1];
{ PointFact p2f1 = (PointFact)CommunicationEvents.Facts[f1.Pid2];
return this.Pid1 ^ this.Pid2; PointFact p1f2 = (PointFact)CommunicationEvents.Facts[f2.Pid1];
PointFact p2f2 = (PointFact)CommunicationEvents.Facts[f2.Pid2];
return (p1f1.Equivalent(p1f2) && p2f1.Equivalent(p2f2))
;//|| (p1f1.Equivalent(p2f2) && p2f1.Equivalent(p1f2));
} }
} }
public class RayFact : Fact public class RayFact : AbstractLineFactWrappedCRTP<RayFact>
{ {
//Id's of the 2 Point-Facts that are connected RayFact(int pid1, int pid2, string backendURI) : base(pid1, pid2, backendURI) { }
public int Pid1, Pid2;
//only for temporary Use of LineFacts.
public RayFact() { }
public RayFact(int i, int pid1, int pid2) public RayFact(int i, int pid1, int pid2)
{ {
...@@ -313,6 +342,8 @@ public RayFact(int i, int pid1, int pid2) ...@@ -313,6 +342,8 @@ public RayFact(int i, int pid1, int pid2)
this.Pid2 = pid2; this.Pid2 = pid2;
PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact; PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact;
PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact; PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact;
this.Dir = (pf2.Point - pf1.Point).normalized;
string p1URI = pf1.backendURI; string p1URI = pf1.backendURI;
string p2URI = pf2.backendURI; string p2URI = pf2.backendURI;
...@@ -335,13 +366,6 @@ public RayFact(int i, int pid1, int pid2) ...@@ -335,13 +366,6 @@ public RayFact(int i, int pid1, int pid2)
Debug.Log(this.backendURI); Debug.Log(this.backendURI);
} }
public RayFact(int pid1, int pid2, string uri)
{
this.Pid1 = pid1;
this.Pid2 = pid2;
this.backendURI = uri;
}
public static RayFact parseFact(Scroll.ScrollFact fact) public static RayFact parseFact(Scroll.ScrollFact fact)
{ {
String uri = fact.@ref.uri; String uri = fact.@ref.uri;
...@@ -367,16 +391,6 @@ public static RayFact parseFact(Scroll.ScrollFact fact) ...@@ -367,16 +391,6 @@ public static RayFact parseFact(Scroll.ScrollFact fact)
} }
} }
public override Boolean hasDependentFacts()
{
return true;
}
public override int[] getDependentFactIds()
{
return new int[] { Pid1, Pid2 };
}
public override GameObject instantiateDisplay(GameObject prefab, Transform transform) { public override GameObject instantiateDisplay(GameObject prefab, Transform transform) {
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform); var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(this.Id); obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(this.Id);
...@@ -385,28 +399,19 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans ...@@ -385,28 +399,19 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
return obj; return obj;
} }
public override bool Equals(System.Object obj) protected override bool EquivalentWrapped(RayFact f1, RayFact f2)
{
//Check for null and compare run-time types.
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{ {
if (f1.Dir != f2.Dir && f1.Dir != -f2.Dir)
return false; return false;
}
else
{
RayFact r = (RayFact)obj;
return this.Pid1.Equals(r.Pid1) && this.Pid2.Equals(r.Pid2);
}
}
public override int GetHashCode() PointFact p1f1 = (PointFact)CommunicationEvents.Facts[f1.Pid1];
{ PointFact p1f2 = (PointFact)CommunicationEvents.Facts[f2.Pid1];
return this.Pid1 ^ this.Pid2;
return Math3d.IsPointApproximatelyOnLine(p1f1.Point, f1.Dir, p1f2.Point);
} }
} }
public class OnLineFact : FactWrappedCRTP<OnLineFact>
public class OnLineFact : Fact
{ {
//Id's of the Point and the Line it's on //Id's of the Point and the Line it's on
public int Pid, Rid; public int Pid, Rid;
...@@ -492,28 +497,26 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans ...@@ -492,28 +497,26 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
return obj; return obj;
} }
public override bool Equals(System.Object obj) public override int GetHashCode()
{
//Check for null and compare run-time types.
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{
return false;
}
else
{ {
OnLineFact o = (OnLineFact)obj; return this.Pid ^ this.Rid;
return this.Pid.Equals(o.Pid) && this.Rid.Equals(o.Rid);
}
} }
public override int GetHashCode() protected override bool EquivalentWrapped(OnLineFact f1, OnLineFact f2)
{ {
return this.Pid ^ this.Rid; if (f1.Pid == f2.Pid && f1.Rid == f2.Rid)
return true;
PointFact pf1 = (PointFact)CommunicationEvents.Facts[f1.Pid];
RayFact rf1 = (RayFact)CommunicationEvents.Facts[f1.Rid];
PointFact pf2 = (PointFact)CommunicationEvents.Facts[f2.Pid];
RayFact rf2 = (RayFact)CommunicationEvents.Facts[f2.Rid];
return pf1.Equivalent(pf2) && rf1.Equivalent(rf2);
} }
} }
public class AngleFact : FactWrappedCRTP<AngleFact>
public class AngleFact : DirectedFact
{ {
//Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is //Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is
public int Pid1, Pid2, Pid3; public int Pid1, Pid2, Pid3;
...@@ -684,23 +687,26 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans ...@@ -684,23 +687,26 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans
return obj; return obj;
} }
public override bool Equals(System.Object obj) public override int GetHashCode()
{
//Check for null and compare run-time types.
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{
return false;
}
else
{ {
AngleFact a = (AngleFact)obj; return this.Pid1 ^ this.Pid2 ^ this.Pid3;
return this.Pid1.Equals(a.Pid1) && this.Pid2.Equals(a.Pid2) && this.Pid3.Equals(a.Pid3);
}
} }
public override int GetHashCode() protected override bool EquivalentWrapped(AngleFact f1, AngleFact f2)
{ {
return this.Pid1 ^ this.Pid2 ^ this.Pid3; if ((f1.Pid1 == f2.Pid1 && f1.Pid2 == f2.Pid2 && f1.Pid3 == f2.Pid3))// ||
//(f1.Pid1 == f2.Pid3 && f1.Pid2 == f2.Pid2 && f1.Pid3 == f2.Pid1))
return true;
PointFact p1f1 = (PointFact)CommunicationEvents.Facts[f1.Pid1];
PointFact p2f1 = (PointFact)CommunicationEvents.Facts[f1.Pid2];
PointFact p3f1 = (PointFact)CommunicationEvents.Facts[f1.Pid3];
PointFact p1f2 = (PointFact)CommunicationEvents.Facts[f2.Pid1];
PointFact p2f2 = (PointFact)CommunicationEvents.Facts[f2.Pid2];
PointFact p3f2 = (PointFact)CommunicationEvents.Facts[f2.Pid3];
return (p1f1.Equivalent(p1f2) && p2f1.Equivalent(p2f2) && p3f1.Equivalent(p3f2))
;//|| (p1f1.Equivalent(p3f2) && p2f1.Equivalent(p2f2) && p1f1.Equivalent(p3f2));
} }
} }
......
...@@ -10,111 +10,111 @@ public class FactManager : MonoBehaviour ...@@ -10,111 +10,111 @@ public class FactManager : MonoBehaviour
private List<int> NextEmpties = new List<int>(); private List<int> NextEmpties = new List<int>();
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
// CommunicationEvents.SnapEvent.AddListener(Rocket);
//We dont want to have this here anymore... //We dont want to have this here anymore...
//CommunicationEvents.RemoveFactEvent.AddListener(DeleteFact); //CommunicationEvents.RemoveFactEvent.AddListener(DeleteFact);
NextEmpties.Add(0); NextEmpties.Add(0);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
} }
//TODO: change the return find.... public static bool findFact(Fact search, out Fact found)
public PointFact AddPointFact(RaycastHit hit, int id) {
foreach (Fact f in CommunicationEvents.Facts)
{
if (f.GetType() == search.GetType() && f.Equivalent(search))
{ {
Facts.Insert(id, new PointFact(id, hit.point, hit.normal)); found = f;
return Facts.Find(x => x.Id == id) as PointFact; return true;
}
} }
public LineFact AddLineFact(int pid1, int pid2, int id) found = search;
return false;
}
public static void addFact(int id, Fact fact)
{ {
Facts.Insert(id, new LineFact(id, pid1, pid2)); CommunicationEvents.Facts.Insert(id, fact);
//TODO (alt): insert in MMT if needed here/ on Invoke()
//TODO: remove Inovkes() elsewhere
CommunicationEvents.AddFactEvent.Invoke(fact);
}
return Facts.Find(x => x.Id == id) as LineFact; public static Fact AddFactIfNotFound(int id, Fact fact, out bool exists)
{
if (exists = findFact(fact, out Fact res))
{
//TODO: del 'fact' in MMT (alt.: s.TODO in addFact)
return res;
} }
public List<Fact> AddRayFact(int pid1, int pid2, int id) else
{ {
Facts.Insert(id, new RayFact(id, pid1, pid2)); addFact(id, fact);
return fact;
var oLid1 = GetFirstEmptyID(); }
Facts.Insert(oLid1, new OnLineFact(oLid1, pid1, id)); }
var oLid2 = GetFirstEmptyID();
Facts.Insert(oLid2, new OnLineFact(oLid2, pid2, id));
var p1 = Facts.Find(x => x.Id == pid1);
var p2 = Facts.Find(x => x.Id == pid2);
Vector3 dir = p2.Representation.transform.position - p1.Representation.transform.position;
public PointFact AddPointFact(RaycastHit hit, int id)
{
return (PointFact) AddFactIfNotFound(id, new PointFact(id, hit.point, hit.normal), out bool obsolete);
}
// Bit shift the index of the layer Point to get a bit mask public PointFact AddPointFact(int id, Vector3 point, Vector3 normal)
int layerMask = 1 << LayerMask.NameToLayer("Point"); {
// This casts rays only against colliders in layer 8 return (PointFact) AddFactIfNotFound(id, new PointFact(id, point, normal), out bool obsolete);
}
public OnLineFact AddOnLineFact(int pid, int lid, int id)
{
return (OnLineFact)AddFactIfNotFound(id, new OnLineFact(id, pid, lid), out bool obsolete);
}
RaycastHit[] hits; public LineFact AddLineFact(int pid1, int pid2, int id)
hits = Physics.RaycastAll(p1.Representation.transform.position - dir * 1000, dir, Mathf.Infinity, layerMask); {
return (LineFact)AddFactIfNotFound(id, new LineFact(id, pid1, pid2), out bool obsolete);
}
Debug.Log(hits.Length + " hits"); public RayFact AddRayFact(int pid1, int pid2, int id)
for (int i = 0; i < hits.Length; i++)
{ {
RaycastHit hit = hits[i]; RayFact rayFact = (RayFact)AddFactIfNotFound(id, new RayFact(id, pid1, pid2), out bool exists);
if (exists)
return rayFact;
bool exists = false; //Add all PointFacts on Ray as OnLineFacts
PointFact rayP1 = (PointFact)Facts[rayFact.Pid1];
int layerMask = LayerMask.GetMask("Point");
RaycastHit[] hitsA = Physics.RaycastAll(rayP1.Point, rayFact.Dir, Mathf.Infinity, layerMask);
RaycastHit[] hitsB = Physics.RaycastAll(rayP1.Point, -rayFact.Dir, Mathf.Infinity, layerMask);
foreach (Fact fact in Facts) void AddHitIfOnLine(RaycastHit hit)
{
if (typeof(OnLineFact).IsInstanceOfType(fact))
{ {
OnLineFact oLFact = (OnLineFact)fact; if (Math3d.IsPointApproximatelyOnLine(rayP1.Point, rayFact.Dir, hit.transform.position))
if ((oLFact.Rid == id && oLFact.Pid == hit.transform.gameObject.GetComponent<FactObject>().Id))
{ {
exists = true; AddOnLineFact(hit.transform.gameObject.GetComponent<FactObject>().Id, rayFact.Id, GetFirstEmptyID());
break;
}
} }
} }
foreach (RaycastHit hit in hitsA)
AddHitIfOnLine(hit);
if (!exists) foreach (RaycastHit hit in hitsB)
{ AddHitIfOnLine(hit);
var anotherOLid = GetFirstEmptyID();
var olF = new OnLineFact(anotherOLid, hit.transform.gameObject.GetComponent<FactObject>().Id, id);
Facts.Insert(anotherOLid, olF);
}
} return rayFact;
List<Fact> returnedFacts = new List<Fact>();
returnedFacts.Add(Facts.Find(x => x.Id == id) as RayFact);
returnedFacts.Add(Facts.Find(x => x.Id == oLid1) as OnLineFact);
returnedFacts.Add(Facts.Find(x => x.Id == oLid2) as OnLineFact);
return returnedFacts;
} }
public AngleFact AddAngleFact(int pid1, int pid2, int pid3, int id) public AngleFact AddAngleFact(int pid1, int pid2, int pid3, int id)
{ {
Facts.Insert(id, new AngleFact(id, pid1, pid2, pid3)); return (AngleFact)AddFactIfNotFound(id, new AngleFact(id, pid1, pid2, pid3), out bool obsolete);
return Facts.Find(x => x.Id == id) as AngleFact;
} }
public void DeleteFact(Fact fact) public void DeleteFact(Fact fact)
...@@ -129,13 +129,6 @@ public void DeleteFact(Fact fact) ...@@ -129,13 +129,6 @@ public void DeleteFact(Fact fact)
public int GetFirstEmptyID() public int GetFirstEmptyID()
{ {
/* for (int i = 0; i < Facts.Length; ++i)
{
if (Facts[i] == "")
return i;
}
return Facts.Length - 1;*/
NextEmpties.Sort(); NextEmpties.Sort();
int id = NextEmpties[0]; int id = NextEmpties[0];
...@@ -146,79 +139,5 @@ public int GetFirstEmptyID() ...@@ -146,79 +139,5 @@ public int GetFirstEmptyID()
Debug.Log("place fact at " + id); Debug.Log("place fact at " + id);
return id; return id;
}
public Boolean factAlreadyExists(int[] ids)
{
if (GadgetManager.activeGadget.GetType() == typeof(Tape)) {
foreach (Fact fact in Facts)
{
if (typeof(LineFact).IsInstanceOfType(fact))
{
LineFact line = (LineFact)fact;
if (line.Pid1 == ids[0] && line.Pid2 == ids[1])
{
return true;
}
}
}
return false;
}
else if (GadgetManager.activeGadget.GetType() == typeof(AngleTool))
{
foreach (Fact fact in Facts)
{
if (typeof(AngleFact).IsInstanceOfType(fact))
{
AngleFact angle = (AngleFact)fact;
if (angle.Pid1 == ids[0] && angle.Pid2 == ids[1] && angle.Pid3 == ids[2])
{
return true;
} }
} }
}
return false;
}
else
return false;
}
/*
//automatic 90 degree angle construction
public void Rocket(RaycastHit hit)
{
int idA, idB, idC;
//usual point
idA = this.GetFirstEmptyID();
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit, idA));
//second point
idB = this.GetFirstEmptyID();
var shiftedHit = hit;
var playerPos = Camera.main.transform.position;
playerPos.y = hit.point.y;
shiftedHit.point = playerPos;
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(shiftedHit, idB));
//third point with unknown height
idC = this.GetFirstEmptyID();
var skyHit = hit;
skyHit.point += Vector3.up * 20;
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(skyHit, idC));
//lines
CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(idA, idB, this.GetFirstEmptyID()));
//lines
CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(idA, idC, this.GetFirstEmptyID()));
//90degree angle
CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB, idA, idC, GetFirstEmptyID()));
}
*/
}
...@@ -54,9 +54,7 @@ public override void OnHit(RaycastHit hit) ...@@ -54,9 +54,7 @@ public override void OnHit(RaycastHit hit)
//Check if new Point is equal to one of the previous points -> if true -> cancel //Check if new Point is equal to one of the previous points -> if true -> cancel
if (!(this.angleModeFirstPointSelected.Id == tempFact.Id || this.angleModeSecondPointSelected.Id == tempFact.Id)) if (!(this.angleModeFirstPointSelected.Id == tempFact.Id || this.angleModeSecondPointSelected.Id == tempFact.Id))
{ {
//Check if exactly the same angle already exists FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).Id, ((PointFact)this.angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id, FactManager.GetFirstEmptyID());
if (!FactManager.factAlreadyExists(new int[] { ((PointFact)this.angleModeFirstPointSelected).Id, ((PointFact)this.angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id }))
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).Id, ((PointFact)this.angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id, FactManager.GetFirstEmptyID()));
} }
ResetGadget(); ResetGadget();
......
...@@ -38,20 +38,11 @@ public override void OnHit(RaycastHit hit) ...@@ -38,20 +38,11 @@ public override void OnHit(RaycastHit hit)
{ {
Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id]; Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id];
//we can only reach points that are lower than that with the measuring tape
if (/*ActiveToolMode == ToolMode.CreateLineMode && */tempFact.Representation.transform.position.y > 2.5f)
return;
//If first point was already selected AND second point != first point //If first point was already selected AND second point != first point
if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.Id != tempFact.Id) if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.Id != tempFact.Id)
{ {
//Create LineFact //Create LineFact
//Check if exactly the same line/distance already exists FactManager.AddRayFact(this.LineModeFirstPointSelected.Id, tempFact.Id, FactManager.GetFirstEmptyID());
if (!FactManager.factAlreadyExists(new int[] { this.LineModeFirstPointSelected.Id, tempFact.Id }))
{
List<Fact> returnedFacts = FactManager.AddRayFact(this.LineModeFirstPointSelected.Id, tempFact.Id, FactManager.GetFirstEmptyID());
returnedFacts.ForEach(CommunicationEvents.AddFactEvent.Invoke);
}
this.ResetGadget(); this.ResetGadget();
} }
...@@ -63,21 +54,7 @@ public override void OnHit(RaycastHit hit) ...@@ -63,21 +54,7 @@ public override void OnHit(RaycastHit hit)
this.ActivateLineDrawing(); this.ActivateLineDrawing();
} }
} }
/*
//if we want to spawn a new point
else if (Input.GetKey(KeyCode.LeftShift))
{
if (this.TapeModeIsFirstPointSelected)
{
this.DeactivateLineDrawing();
SmallRocket(hit, this.TapeModeFirstPointSelected.Id);
this.ResetGadget();
}
}
*/
//if we hit the top snap zone //if we hit the top snap zone
else if (hit.transform.gameObject.tag == "SnapZone") else if (hit.transform.gameObject.tag == "SnapZone")
{ {
...@@ -91,15 +68,16 @@ public override void OnHit(RaycastHit hit) ...@@ -91,15 +68,16 @@ public override void OnHit(RaycastHit hit)
int idA = downHit.transform.gameObject.GetComponent<FactObject>().Id; int idA = downHit.transform.gameObject.GetComponent<FactObject>().Id;
int idB = this.LineModeFirstPointSelected.Id; int idB = this.LineModeFirstPointSelected.Id;
int idC = FactManager.GetFirstEmptyID(); int idC = FactManager.GetFirstEmptyID();
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddPointFact(hit, idC)); FactManager.AddPointFact(hit, idC);
this.DeactivateLineDrawing(); this.DeactivateLineDrawing();
//Create LineFact //Create LineFact
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddAngleFact(idA, idB, idC, FactManager.GetFirstEmptyID())); FactManager.AddAngleFact(idA, idB, idC, FactManager.GetFirstEmptyID());
this.LineModeIsFirstPointSelected = false; this.LineModeIsFirstPointSelected = false;
this.LineModeFirstPointSelected = null; this.LineModeFirstPointSelected = null;
} }
} }
} }
//If no Point was hit //If no Point was hit
else else
{ {
...@@ -113,27 +91,6 @@ public override void OnHit(RaycastHit hit) ...@@ -113,27 +91,6 @@ public override void OnHit(RaycastHit hit)
} }
} }
/*
//Creating 90-degree Angles
public void SmallRocket(RaycastHit hit, int idA)
{
//enable collider to measure angle to the treetop
int idB = this.GetFirstEmptyID();
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddPointFact(hit, idB));
Facts[idB].Representation.GetComponentInChildren<Collider>().enabled = true;
//third point with unknown height
int idC = FactManager.GetFirstEmptyID();
var skyHit = hit;
skyHit.point = (Facts[idA] as PointFact).Point + Vector3.up * 20;
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddPointFact(skyHit, idC));
//lines
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddLineFact(idA, idB, this.GetFirstEmptyID()));
//lines
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddLineFact(idA, idC, this.GetFirstEmptyID()));
//90degree angle
CommunicationEvents.AddFactEvent.Invoke(FactManager.AddAngleFact(idB, idA, idC, GetFirstEmptyID()));
}*/
void Update() void Update()
{ {
if (!this.isActiveAndEnabled) return; if (!this.isActiveAndEnabled) return;
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CommunicationEvents;
public class LotTool : Gadget
//constructs a Perpendicular between a Line and a Point
{
//Variables for LineMode distinction
private bool LotModeIsPointSelected = false;
private bool LotModeIsLineSelected = false;
private AbstractLineFact LotModeLineSelected = null;
private PointFact LotModeIntersectionPoint = null;
private PointFact LotModeLinePointA = null;
private RaycastHit LotModeLineHit;
//Attributes for simulating the drawing of a line
private bool lineDrawingActivated;
public WorldCursor Cursor;
public LineRenderer lineRenderer;
private List<Vector3> linePositions = new List<Vector3>();
public Material linePreviewMaterial;
void Awake()
{
if (FactManager == null) FactManager = GameObject.FindObjectOfType<FactManager>();
CommunicationEvents.TriggerEvent.AddListener(OnHit);
if (this.Cursor == null) this.Cursor = GameObject.FindObjectOfType<WorldCursor>();
this.UiName = "Lot Mode";
}
//Initialize Gadget when enabled AND activated
void OnEnable()
{
this.Cursor.setLayerMask(~this.ignoreLayerMask.value);
this.ResetGadget();
}
void OnDisable()
{
this.ResetGadget();
}
public override void OnHit(RaycastHit hit)
{
void CreateRayAndAngles(int pidIntersectionPoint, int pidLotPoint)
{
FactManager.AddRayFact(pidIntersectionPoint, pidLotPoint, FactManager.GetFirstEmptyID());
//TODO: create at all? / for all points on basline?
FactManager.AddAngleFact(
this.LotModeLineSelected.Pid1 == pidIntersectionPoint ? this.LotModeLineSelected.Pid2 : this.LotModeLineSelected.Pid1,
pidIntersectionPoint, pidLotPoint, FactManager.GetFirstEmptyID());
}
if (!this.isActiveAndEnabled) return;
//If LotPoint is on baseLine
if (this.LotModeIsPointSelected && (hit.transform.gameObject.layer == LayerMask.NameToLayer("Default") || hit.transform.gameObject.layer == LayerMask.NameToLayer("Tree")))
{
var pidLotPoint = FactManager.GetFirstEmptyID();
Vector3 LotPoint = Math3d.ProjectPointOnLine(hit.point, this.LotModeLineSelected.Dir, this.LotModeIntersectionPoint.Point);
//TODO: which normal?
FactManager.AddPointFact(pidLotPoint, LotPoint, hit.normal);
CreateRayAndAngles(this.LotModeIntersectionPoint.Id, pidLotPoint);
this.ResetGadget();
}
//If baseline already selected and point selected
else if (this.LotModeIsLineSelected && !this.LotModeIsPointSelected && hit.transform.gameObject.layer == LayerMask.NameToLayer("Point"))
{
PointFact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id] as PointFact;
Vector3 intersectionPoint = Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, tempFact.Point);
if (intersectionPoint == tempFact.Point) // Vector3.operator== tests for almost Equal()
{ //TempFact is on baseLine
this.LotModeIsPointSelected = true;
this.LotModeIntersectionPoint = tempFact;
return;
}
//TODO: test Facts existance
//add Facts
var intersectionId = FactManager.GetFirstEmptyID();
FactManager.AddPointFact(intersectionId, intersectionPoint, this.LotModeLineHit.normal);
if(this.LotModeLineSelected is RayFact) //Add OnLineFact only on Ray not Line
FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.Id, FactManager.GetFirstEmptyID());
CreateRayAndAngles(intersectionId, tempFact.Id);
this.ResetGadget();
}
//If nothing yet selected
else if (!this.LotModeIsLineSelected
&& (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray")
|| hit.transform.gameObject.layer == LayerMask.NameToLayer("Line")))
{
Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id];
//Activate LineDrawing for preview
this.LotModeIsLineSelected = true;
this.LotModeLineSelected = tempFact as AbstractLineFact;
this.LotModeLinePointA = (PointFact)CommunicationEvents.Facts[this.LotModeLineSelected.Pid1];
this.LotModeLineHit = hit;
this.ActivateLineDrawing();
}
//unexpected usage
else
{
if (this.LotModeIsLineSelected)
{
//Deactivate LineDrawing and first point selection
this.ResetGadget();
}
}
}
void Update()
{
if (!this.isActiveAndEnabled)
return;
if (this.lineDrawingActivated)
UpdateLineDrawing();
}
private void ResetGadget()
{
this.LotModeIsLineSelected = false;
this.LotModeLineSelected = null;
this.LotModeLinePointA = null;
this.LotModeIsPointSelected = false;
this.LotModeIntersectionPoint = null;
//TODO? reset?
//this.LotModeLineHit;
DeactivateLineDrawing();
}
private void ActivateLineDrawing()
{
this.lineRenderer.positionCount = 3;
this.lineRenderer.material = this.linePreviewMaterial;
lineRenderer.startWidth = 0.095f;
lineRenderer.endWidth = 0.095f;
//Set LineDrawing activated
this.lineDrawingActivated = true;
//start at curser
linePositions.Add(this.Cursor.transform.position);
//Project curser perpendicular on Line for intersection-point
linePositions.Add(Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, this.linePositions[0]));
//end at Point on the line (i.c.o. projection beeing outside a finite line)
linePositions.Add(Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, this.LotModeLineHit.point));
this.lineRenderer.SetPosition(0, linePositions[0]);
this.lineRenderer.SetPosition(1, linePositions[1]);
this.lineRenderer.SetPosition(2, linePositions[2]);
}
//Updates the points of the Lines when baseLine was selected in LineMode
private void UpdateLineDrawing()
{
if (this.LotModeIsPointSelected)
{
this.linePositions[1] = this.LotModeIntersectionPoint.Point;
this.linePositions[0] = Math3d.ProjectPointOnLine(this.Cursor.transform.position, this.LotModeLineSelected.Dir, this.linePositions[1]);
}
else
{
this.linePositions[0] = this.Cursor.transform.position;
this.linePositions[1] = Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, this.linePositions[0]);
}
this.lineRenderer.SetPosition(0, this.linePositions[0]);
this.lineRenderer.SetPosition(1, this.linePositions[1]);
}
//Deactivate LineDrawing so that no Line gets drawn when Cursor changes
private void DeactivateLineDrawing()
{
this.lineRenderer.positionCount = 0;
this.linePositions = new List<Vector3>();
this.lineDrawingActivated = false;
}
}
fileFormatVersion: 2
guid: 92de1d7563c51184695029faaac9d01d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CommunicationEvents;
public class Pendulum : Gadget
//Acts as a Pendulum starting at a Point
{
//Attributes for simulating the drawing of a line
private bool lineDrawingActivated;
public LayerMask LayerPendulumHits;
public WorldCursor Cursor;
public LineRenderer lineRenderer;
private List<Vector3> linePositions = new List<Vector3>();
public Material linePreviewMaterial;
void Awake()
{
if (FactManager == null) FactManager = GameObject.FindObjectOfType<FactManager>();
CommunicationEvents.TriggerEvent.AddListener(OnHit);
if (this.Cursor == null) this.Cursor = GameObject.FindObjectOfType<WorldCursor>();
this.UiName = "Pendulum";
}
void OnEnable()
{
this.Cursor.setLayerMask(~this.ignoreLayerMask.value);
this.ResetGadget();
ActivateLineDrawing();
}
void OnDisable()
{
this.ResetGadget();
}
public override void OnHit(RaycastHit hit)
{
if (!this.isActiveAndEnabled) return;
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point"))
{
PointFact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id] as PointFact;
//Raycast downwoard
RaycastHit ground;
if(Physics.Raycast(tempFact.Point, Vector3.down, out ground, Mathf.Infinity, this.LayerPendulumHits.value))
{
var pid = FactManager.GetFirstEmptyID();
FactManager.AddPointFact(ground, pid);
}
}
}
void Update()
{
if (!this.isActiveAndEnabled)
return;
if (this.lineDrawingActivated)
UpdateLineDrawing();
}
private void ResetGadget()
{
DeactivateLineDrawing();
}
private void ActivateLineDrawing()
{
this.lineRenderer.positionCount = 2;
this.lineRenderer.material = this.linePreviewMaterial;
lineRenderer.startWidth = 0.095f;
lineRenderer.endWidth = 0.095f;
//Set LineDrawing activated
this.lineDrawingActivated = true;
//initiate linePositions-Array
linePositions.Add(this.Cursor.transform.position);
linePositions.Add(this.Cursor.transform.position);
UpdateLineDrawing();
}
//Updates the points of the Lines when baseLine was selected in LineMode
private void UpdateLineDrawing()
{
this.linePositions[0] = this.Cursor.transform.position;
//Raycast downwoard
RaycastHit ground;
if (Physics.Raycast(this.linePositions[0], Vector3.down, out ground, Mathf.Infinity, this.LayerPendulumHits.value))
this.linePositions[1] = ground.point;
else
this.linePositions[1] = this.linePositions[0];
this.lineRenderer.SetPosition(0, this.linePositions[0]);
this.lineRenderer.SetPosition(1, this.linePositions[1]);
}
//Deactivate LineDrawing so that no Line gets drawn when Cursor changes
private void DeactivateLineDrawing()
{
this.lineRenderer.positionCount = 0;
this.linePositions = new List<Vector3>();
this.lineDrawingActivated = false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment