[英]How to draw latitude/longitude lines on the surface of a Sphere in Unity 3D?
[英]Difficulties with modelling Latitude and Longitude on Unity3D
我在用球體建模地球並使用另一個球體作為標記來標記地球球體的緯度和經度 position 時遇到了一些麻煩。
我已將 x、y 和 z 比例設置為 635.6752,因為這是地球半徑的 1000:1 比例(以米為單位)。 我正在使用倫敦的經緯度定位。
這是代碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Earth : MonoBehaviour
{
public GameObject ObjectEarth;
public Transform ObjectMarker; // ObjectMarker object
public float radius = 635.6752f; // globe ball radius (unity units)
public float latitude = 51.5072f; // lat
public float longitude = 0.1275f; // long
// Start is called before the first frame update
void Start()
{
ObjectEarth.transform.localScale = new Vector3(radius, radius, radius);
latitude = Mathf.PI * latitude / 180;
longitude = Mathf.PI * longitude / 180;
// adjust position by radians
latitude -= 1.570795765134f; // subtract 90 degrees (in radians)
// and switch z and y (since z is forward)
float xPos = (radius) * Mathf.Sin(latitude) * Mathf.Cos(longitude);
float zPos = (radius) * Mathf.Sin(latitude) * Mathf.Sin(longitude);
float yPos = (radius) * Mathf.Cos(latitude);
// move ObjectMarker to position
ObjectMarker.position = new Vector3(xPos, yPos, zPos);
}
// Update is called once per frame
void Update()
{
}
}
這是場景視圖中的 output:
我不太清楚為什么標記object離地球表面object那么遠,理論上應該是在地球表面object。
歡迎任何幫助和建議。
謝謝!
Unity 的球體基元的基本半徑為 0.5 個單位。 因此,要使球體的半徑radius
,您需要將比例設置為該值的兩倍:
ObjectEarth.transform.localScale = 2f * radius * Vector3.one;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.