{"id":1844,"date":"2020-04-25T21:08:07","date_gmt":"2020-04-25T13:08:07","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=1844"},"modified":"2021-01-19T18:40:12","modified_gmt":"2021-01-19T10:40:12","slug":"unity%e5%b8%a6%e6%97%8b%e8%bd%ac%e6%96%b9%e5%90%91%e7%9a%84%e6%91%84%e5%83%8f%e6%9c%ba%e7%a7%bb%e5%8a%a8%e5%8c%ba%e5%9f%9f%e9%99%90%e5%88%b6","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=1844","title":{"rendered":"[Unity]\u5e26\u65cb\u8f6c\u65b9\u5411\u7684\u6444\u50cf\u673a\u79fb\u52a8\u533a\u57df\u9650\u5236"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>using UnityEngine;\n\npublic class ObliqueCameraBox\n{\n    private Vector2Int mPoint0; \/\/ \u5de6\u4e0b\u89d2\n    private Vector2Int mPoint1; \/\/ \u53f3\u4e0a\u89d2\n    private int mRotation; \/\/ \u65cb\u8f6c\u503c\n\n    private float mRotationRad\n    {\n        get\n        {\n            return Mathf.Deg2Rad * mRotation;\n        }\n    }\n\n    public ObliqueCameraBox(Vector2Int point0, Vector2Int point1, int rotation)\n    {\n        mPoint0 = point0;\n        mPoint1 = point1;\n        mRotation = rotation;\n    }\n    \n    static Vector2 RotateXZ2D(Vector2 point, Vector2 center, float a)\n    {\n        float x = ( point.x - center.x ) * Mathf.Cos(a) - ( point.y - center.y ) * Mathf.Sin(a) + center.x;\n        float z = ( point.x - center.x ) * Mathf.Sin(a) + ( point.y - center.y ) * Mathf.Cos(a) + center.y;\n        return new Vector2(x, z);\n    }\n\n    public bool Limit(Vector2 input, int damping, ref Vector2 output)\n    {\n        var p = RotateXZ2D(input, mPoint0, mRotationRad );\n\n        int c = 0;\n\n        if (p.x > mPoint1.x - damping)\n        {\n            p.x = mPoint1.x - damping; \n        }\n        else if (p.x &lt; mPoint0.x + damping)\n        {\n            p.x = mPoint0.x + damping;\n        }\n        else\n        {\n            ++c;\n        }\n\n        if (p.y > mPoint1.y - damping)\n        {\n            p.y = mPoint1.y - damping;\n        }\n        else if (p.y &lt; mPoint0.y + damping)\n        {\n            p.y = mPoint0.y + damping;\n        }\n        else\n        {\n            ++c;\n        }\n\n        if (c == 2)\n        {\n            return false;\n        }\n        else\n        {\n            output = RotateXZ2D(p, mPoint0, -mRotationRad );\n            return true;\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1844"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1844"}],"version-history":[{"count":3,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1844\/revisions"}],"predecessor-version":[{"id":1847,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1844\/revisions\/1847"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}