コード例 #1
0
    public static void MouseToRay(float fX, float fY, Camera camera, out Vector3 kOrigin, out Vector3 kDirection)
    {
        float fUnitizedX = (fX / Screen.width) * 2.0f - 1.0f;
        float fUnitizedY = ((Screen.height - fY) / Screen.height) * 2.0f - 1.0f;

        UnFrustum frustum = GetCameraFrustum(camera);

        fUnitizedX *= frustum.right;
        fUnitizedY *= frustum.top;

        Matrix4x4 kRotation = camera.transform.localToWorldMatrix;

        Vector3 kLook, kLookUp, kLookRight;

        kLook      = kRotation.GetColumn(0);
        kLookUp    = kRotation.GetColumn(1);
        kLookRight = kRotation.GetColumn(2);

        if (frustum.ortho)
        {
            kOrigin    = camera.transform.position + kLookRight * fUnitizedX + kLookUp * fUnitizedY;
            kDirection = kLook;
        }
        else
        {
            kOrigin    = camera.transform.position;
            kDirection = kLook + kLookUp * fUnitizedY + kLookRight * fUnitizedX;
            kDirection.Normalize();
        }
    }
コード例 #2
0
ファイル: UnGfxWrap.cs プロジェクト: atom-chen/shisanshui-1
 static int GetCameraFrustum(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Camera arg0 = (UnityEngine.Camera)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.Camera));
         UnFrustum          o    = UnGfx.GetCameraFrustum(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }