Skip to content

Commit

Permalink
add homography conversion APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Sep 15, 2017
1 parent 20734e3 commit cf2e9df
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
45 changes: 42 additions & 3 deletions Assets/uHomography/Scenes/uHomography.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.4465934, g: 0.49642956, b: 0.5748249, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -387,6 +387,46 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
camera: {fileID: 1921056250}
--- !u!1 &598281487
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 598281489}
- component: {fileID: 598281488}
m_Layer: 0
m_Name: Convert Point Test
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &598281488
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 598281487}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 681abd389192d894a9c4156e4eff91cb, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &598281489
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 598281487}
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: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!21 &853359849
Material:
serializedVersion: 6
Expand Down Expand Up @@ -512,8 +552,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2a1e8ea765ed549d193c5b4495319ee4, type: 3}
m_Name:
m_EditorClassIdentifier:
showHandles: 1
toggleKey: 32
handleToggleKey: 0
layer: 31
uiCamera: {fileID: 1921056250}
shader: {fileID: 4800000, guid: c6971acbaaa734de18fa0ab8403a8dca, type: 3}
Expand Down
16 changes: 16 additions & 0 deletions Assets/uHomography/Scripts/Homography.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
material.SetFloatArray("_InvHomography", invHomography_);
Graphics.Blit(source, destination, material);
}

public Vector2 GetHomographyPosition(Vector2 pos)
{
float s = homography_[6] * pos.x + homography_[7] * pos.y + homography_[8];
float x = (homography_[0] * pos.x + homography_[1] * pos.y + homography_[2]) / s;
float y = (homography_[3] * pos.x + homography_[4] * pos.y + homography_[5]) / s;
return new Vector2(x, y);
}

public Vector2 GetInverseHomographyPosition(Vector2 pos)
{
float s = invHomography_[6] * pos.x + invHomography_[7] * pos.y + invHomography_[8];
float x = (invHomography_[0] * pos.x + invHomography_[1] * pos.y + invHomography_[2]) / s;
float y = (invHomography_[3] * pos.x + invHomography_[4] * pos.y + invHomography_[5]) / s;
return new Vector2(x, y);
}
}

}
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2017.1.0b6
m_EditorVersion: 2017.1.0b5

0 comments on commit cf2e9df

Please sign in to comment.