当前位置: 首页>>代码示例>>C#>>正文


C# Camera.ViewportPointToRay方法代码示例

本文整理汇总了C#中UnityEngine.Camera.ViewportPointToRay方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.ViewportPointToRay方法的具体用法?C# Camera.ViewportPointToRay怎么用?C# Camera.ViewportPointToRay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Camera的用法示例。


在下文中一共展示了Camera.ViewportPointToRay方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClampCamViewPos

 public void ClampCamViewPos(Camera cam)
 {
     cam.transform.position += GetClampedDelta(GetPoint(cam.ViewportPointToRay(Vector3.zero)));
     cam.transform.position += GetClampedDelta(GetPoint(cam.ViewportPointToRay(Vector2.one)));
     cam.transform.position += GetClampedDelta(GetPoint(cam.ViewportPointToRay(new Vector2(1, 0))));
     cam.transform.position += GetClampedDelta(GetPoint(cam.ViewportPointToRay(new Vector2(0, 1))));
 }
开发者ID:Nachtrind,项目名称:Fungus,代码行数:7,代码来源:ClampCamera.cs

示例2: Raycast

    bool Raycast( Camera cam, Vector2 screenPos, out RaycastHit hit )
    {
        //Ray ray = cam.ScreenPointToRay( screenPos );
		Ray ray = cam.ViewportPointToRay( new Vector2( screenPos.x / Screen.width, screenPos.y / Screen.height ) );
        bool didHit = false;

        if( RayThickness > 0 )
            didHit = Physics.SphereCast( ray, 0.5f * RayThickness, out hit, Mathf.Infinity, ~IgnoreLayerMask );
        else
            didHit = Physics.Raycast( ray, out hit, Mathf.Infinity, ~IgnoreLayerMask );

        // vizualise ray
    #if UNITY_EDITOR
        if( VisualizeRaycasts )
        {
            if( didHit )
                Debug.DrawLine( ray.origin, hit.point, Color.green, 0.5f );
            else
                Debug.DrawLine( ray.origin, ray.origin + ray.direction * 9999.0f, Color.red, 0.5f );
        }
    #endif

        return didHit;
    }
开发者ID:JulyMars,项目名称:frozen_free_fall,代码行数:24,代码来源:ScreenRaycaster.cs

示例3: RadialClipCornerRatio

 public static float RadialClipCornerRatio(Camera cam)
 {
     Ray ray = cam.ViewportPointToRay(new Vector3(0f, 0f, 0f));
     return cam.transform.InverseTransformDirection(ray.direction).z;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:5,代码来源:SunshineMath.cs

示例4: RadialClipCornerRatio

    /// <summary>
    /// Calculates the ratio between far clip at the corner of the view frustum, and at the center, assuming a radial clipping plane.
    /// </summary>
    /// <returns>
    /// The corner far clip ratio
    /// </returns>
    /// <param name='cam'>
    /// A camera.
    /// </param>
    public static float RadialClipCornerRatio(Camera cam)
    {
        //*
        var cornerRay = cam.ViewportPointToRay(new Vector3(0f, 0f, 0f));
        var localForward = cam.transform.InverseTransformDirection(cornerRay.direction);
        return localForward.z;
        //*/

        //The following should be better, since it's perfectly stable!
        //But... the math just isn't cooperating! >:/
        /*
        float vFOV = cam.fieldOfView;
        float radVFOV = vFOV * Mathf.Deg2Rad;
        float radHFOV = 2f * Mathf.Atan(Mathf.Tan(radVFOV / 2f) * cam.aspect);
        float hFOV = Mathf.Rad2Deg * radHFOV;
        return (Quaternion.Euler(vFOV * 0.5f, hFOV * -0.5f, 0f) * Vector3.forward).z;
        //*/
    }
开发者ID:DanielMetados,项目名称:Cubepass,代码行数:27,代码来源:SunshineMath.cs

示例5: getViewBoxMesh

    /// <summary>
    /// Gets a Mesh that covers the plane where the viewing frustum
    /// of the playerView camera intersects the provided terrain
    /// 
    /// Use this to construct minimaps that show where
    /// the player is viewing
    /// </summary>
    /// <param name="terrain">the terrain the player is looking at</param>
    /// <param name="playerView">the camera the player is looking through</param>
    /// <returns></returns>
    public Mesh getViewBoxMesh(Terrain terrain, Camera playerView)
    {
        Ray[] rays = new Ray[4];
        float[] hits = new float[4];
        Vector3[] points = new Vector3[4];
        Vector3[] viewPortPoints = new Vector3[4];
        viewPortPoints[0] = new Vector3(0, 0, 0);
        viewPortPoints[1] = new Vector3(1, 0, 0);
        viewPortPoints[2] = new Vector3(1, 1, 0);
        viewPortPoints[3] = new Vector3(0, 1, 0);

        int[] tris = { 0, 3, 2, 2, 1, 0 };

        for (int i = 0; i < rays.Length; i++)
        {
            rays[i] = playerView.ViewportPointToRay(viewPortPoints[i]);
            Plane p = new Plane(terrain.transform.up, terrain.transform.position);
            p.Raycast(rays[i], out hits[i]);
            if (hits[i] < 0)
            {
                float pHit;

                Ray downRay = new Ray(rays[i].GetPoint(2 * getDiagSize(terrain.collider.bounds.size)), playerView.transform.up * -1);
                p.Raycast(downRay, out pHit);
                points[i] = downRay.GetPoint(pHit);
            } else {
                points[i] = rays[i].GetPoint(hits[i]);
            }
        }

        Mesh box = new Mesh();
        box.vertices = points;
        box.triangles = tris;
        box.uv = new Vector2[4];
        box.RecalculateNormals();
        return box;
    }
开发者ID:barcharcraz,项目名称:Zenith_Imperium,代码行数:47,代码来源:Minimap.cs

示例6: CastRay

 public void CastRay(bool isMinimap, Vector3 mousePosition, Camera minimapCamera)
 {
     if (isMinimap) {
         Ray ray = minimapCamera.ViewportPointToRay(mousePosition);
         RaycastHit[] hits = Physics.RaycastAll(ray, 1000f);
         foreach (RaycastHit hit in hits) {
             if (hit.collider.gameObject.tag.Equals("Floor")) {
                 CmdSetTarget(this.gameObject, hit.point);
                 break;
             }
         }
     }
     else {
         Ray ray = Camera.main.ScreenPointToRay(mousePosition);
         RaycastHit[] hits = Physics.RaycastAll(ray);
         foreach (RaycastHit hit in hits) {
             if (hit.collider.gameObject.tag.Equals("Floor")) {
                 //Call on the client->server method to start the action.
                 CmdSetTarget(this.gameObject, hit.point);
                 break;
             }
         }
     }
 }
开发者ID:tommai78101,项目名称:Multiplier,代码行数:24,代码来源:GameUnit.cs


注:本文中的UnityEngine.Camera.ViewportPointToRay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。