Skip to content

Commit

Permalink
Fix something
Browse files Browse the repository at this point in the history
  • Loading branch information
nkjzm committed Dec 6, 2018
1 parent 758f9c3 commit ec9e1aa
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 22 deletions.
17 changes: 8 additions & 9 deletions Assets/Mirror/Prefabs/Mirror.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1225834672576956}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 3, z: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4981011086907182}
Expand All @@ -117,8 +117,8 @@ Transform:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1628054057058380}
m_LocalRotation: {x: -0, y: -1, z: 0, w: 0}
m_LocalPosition: {x: -0, y: 0, z: 4}
m_LocalRotation: {x: -0, y: -0.9922779, z: 0.124034725, w: 0}
m_LocalPosition: {x: -0, y: 0.46716645, z: 7.8141885}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4981011086907182}
Expand Down Expand Up @@ -156,9 +156,9 @@ Transform:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1330953538898226}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0.062137436, y: -0, z: -0, w: 0.9980676}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: -4, y: 4, z: 1}
m_LocalScale: {x: -4.24807, y: 4.24807, z: 1}
m_Children:
- {fileID: 4535456954800578}
- {fileID: 4667065784059862}
Expand All @@ -185,9 +185,9 @@ Camera:
y: 0
width: 1
height: 1
near clip plane: 3.6
near clip plane: 7.256032
far clip plane: 1000
field of view: 53.130104
field of view: 29.51887
orthographic: 0
orthographic size: 5
m_Depth: 0
Expand Down Expand Up @@ -365,8 +365,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
TargetCamera: {fileID: 0}
EnabledTargetCamera: 1
EnabledRotation: 1
ReflectionCamera: {fileID: 20009079643964914}
Specular: {fileID: 4981011086907182}
Frame: {fileID: 4780043427284432}
Size: 4
Size: 3
212 changes: 208 additions & 4 deletions Assets/Mirror/Scenes/Mirror.unity
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Camera:
y: 0
width: 1
height: 1
near clip plane: 0.3
near clip plane: 0.02
far clip plane: 1000
field of view: 60
orthographic: 0
Expand All @@ -185,7 +185,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 3635023}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 3, z: -3}
m_LocalPosition: {x: 0, y: 3, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
Expand All @@ -204,11 +204,11 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4248715444833294, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalPosition.y
value: 3
value: 2
objectReference: {fileID: 0}
- target: {fileID: 4248715444833294, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalPosition.z
value: 1
value: 3
objectReference: {fileID: 0}
- target: {fileID: 4248715444833294, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalRotation.x
Expand All @@ -235,9 +235,209 @@ Prefab:
propertyPath: TargetCamera
value:
objectReference: {fileID: 3635025}
- target: {fileID: 20009079643964914, guid: bb1afbc56e3d84f4aa78e285f35c087a,
type: 2}
propertyPath: field of view
value: 29.51887
objectReference: {fileID: 0}
- target: {fileID: 4981011086907182, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalScale.x
value: -4.24807
objectReference: {fileID: 0}
- target: {fileID: 4981011086907182, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalScale.y
value: 4.24807
objectReference: {fileID: 0}
- target: {fileID: 4780043427284432, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalScale.x
value: 4
objectReference: {fileID: 0}
- target: {fileID: 4780043427284432, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalScale.y
value: 4
objectReference: {fileID: 0}
- target: {fileID: 4535456954800578, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
propertyPath: m_LocalPosition.y
value: 0.46716645
objectReference: {fileID: 0}
- target: {fileID: 114013932157294128, guid: bb1afbc56e3d84f4aa78e285f35c087a,
type: 2}
propertyPath: Size
value: 4
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bb1afbc56e3d84f4aa78e285f35c087a, type: 2}
m_IsPrefabAsset: 0
--- !u!1 &613552265
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 613552269}
- component: {fileID: 613552268}
- component: {fileID: 613552267}
- component: {fileID: 613552266}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &613552266
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613552265}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &613552267
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613552265}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 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
--- !u!33 &613552268
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613552265}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &613552269
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 613552265}
m_LocalRotation: {x: 0, y: 0.2588191, z: 0, w: 0.9659258}
m_LocalPosition: {x: -1.1099999, y: 0.8, z: 1.2800001}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 30, z: 0}
--- !u!1 &1021197461
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1021197465}
- component: {fileID: 1021197464}
- component: {fileID: 1021197463}
- component: {fileID: 1021197462}
m_Layer: 0
m_Name: Cube (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &1021197462
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1021197461}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1021197463
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1021197461}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 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
--- !u!33 &1021197464
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1021197461}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1021197465
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1021197461}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.85, y: 0.8, z: 1.39}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1152150505
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -351,6 +551,10 @@ Prefab:
propertyPath: m_StaticEditorFlags
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 100000, guid: 33a5c7c3db9b74c89abbb8b375d9c93f, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 33a5c7c3db9b74c89abbb8b375d9c93f, type: 3}
m_IsPrefabAsset: 0
15 changes: 6 additions & 9 deletions Assets/Mirror/Scripts/Mirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class Mirror : MonoBehaviour
[SerializeField]
bool EnabledTargetCamera = false;
[SerializeField]
bool EnabledRotation = false;
[SerializeField]
Camera ReflectionCamera = null;
[SerializeField]
Transform Specular = null;
Expand Down Expand Up @@ -76,28 +74,27 @@ void UpdateMirror()
if (TrackingCamera == null) { return; }

// カメラから鏡面へのベクトル
var diff = Specular.position - TrackingCamera.transform.position;
var diff = transform.position - TrackingCamera.transform.position;
// 鏡面の垂直ベクトル
var normal = transform.forward;
// 鏡面からの反射ベクトル
var reflection = diff + 2 * (Vector3.Dot(-diff, normal)) * normal;
// 鏡面座標に反転させた反射ベクトルを加算する
ReflectionCamera.transform.position = Specular.position - reflection;
ReflectionCamera.transform.position = transform.position - reflection;
// 鏡面の方向に向ける
ReflectionCamera.transform.LookAt(Specular.position);
ReflectionCamera.transform.LookAt(transform.position);
// カメラ設定の更新
var distance = Vector3.Distance(Specular.position, ReflectionCamera.transform.position);
var distance = Vector3.Distance(transform.position, ReflectionCamera.transform.position);
ReflectionCamera.nearClipPlane = distance * 0.9f;

// 鏡面をカメラ方向に向ける
Specular.rotation = !EnabledRotation ? Quaternion.identity
: Quaternion.LookRotation(Specular.position - TrackingCamera.transform.position);
Specular.rotation = Quaternion.LookRotation(Specular.position - TrackingCamera.transform.position);

// フレームのサイズを更新
Frame.localScale = new Vector3(Size, Size, 1);
// 鏡面のサイズを調整
var angle = Vector3.Angle(-transform.forward, ReflectionCamera.transform.forward);
var specularSize = Size + Mathf.Sin(angle * Mathf.Deg2Rad);
var specularSize = Size + Mathf.Sin(angle * Mathf.Deg2Rad) * 2;
Specular.localScale = new Vector3(-specularSize, specularSize, 1);

// 焦点距離と表示したい鏡面サイズから画角(FOV)を計算する
Expand Down

0 comments on commit ec9e1aa

Please sign in to comment.