制作一个等距顶点的球体 [英] Make a sphere with equidistant vertices

查看:25
本文介绍了制作一个等距顶点的球体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了检查碰撞,我正在尝试制作一个球形的射线爆发,但是根据每条射线击中的内容或位置会发生特定的相互作用.因此,为什么我使用光线而不是更简单的东西,例如 OverlapSphere.

我正在寻找如何制作球体的原因是因为我可以对我的光线使用相同的数学方法,让它们到达球体所在位置的顶点.但是我能找到的每一种制作球体的方法都使线条靠近极点,这是有道理的,因为它很容易做到.但正如你想象的那样,它对我当前的项目没有那么有用.

TL;DR:如何制作具有等距顶点的球体?如果它不是完美等距的就很好,它只需要非常接近.如果发生这种情况,如果您能给出差异有多大,以及在哪里(如果适用),那就太好了.

额外说明:我看过

要在 Unity 中调出这样的球体,只需执行以下操作:

然后您可以立即访问顶点,如您所知

Mesh mesh = GetComponent().mesh;Vector3[] vv = mesh.vertices;int kVerts=vv.Lengthfor (int i=0; i

请注意,您可以轻松检查球体的哪一部分"他们通过(例如)检查他们离你的城市"有多远;(或其他)或只是检查(例如)z 值以查看它们位于哪个半球......等等.


此外...

请注意.关于您想要这样做的总体原因:

<块引用>

但是根据每条光线击中的内容或位置会发生特定的交互

请注意,使用 PhysX 做到这一点再简单不过了.(Unity 中完全内置的游戏物理.)确实,我从来没有在不做一些特定"操作的情况下查看碰撞.取决于它击中的位置!"

例如,您可以通过 http://docs 获取联系人所在的点.unity3d.com/ScriptReference/RaycastHit-point.html

值得注意的是,在休闲编程中写出接近 PhysX 性能的东西是绝对不可想象的.

我希望这能让事情变得更简单!

I'm trying to make a spherical burst of rays for the purpose of checking collision, but having specific interactions happen based upon what or where each ray hit. Hence why I'm using rays rather then something simpler such as OverlapSphere.

The reason I'm looking for how to make a sphere is because I can use the same math for my rays, by having them go to the vertices of where the sphere would be. But every way I can find for making a sphere has the lines get closer the near to the poles, which makes sense, as its pretty easy to do. But as you can imagine, its not that useful for my current project.

TL;DR: How do I make a sphere with equidistant vertices? If its not perfectly equidistant its fine, it just needs to pretty close. If this happens, it would be great if you could give how much the difference would be, and where, if applicable.

Extra notes: I've looked at this and this, but the math is way over my head, so what I've been looking for might've just been staring me in the face this whole time.

解决方案

Are you aware that the sphere given to you by Unity is in fact designed

with this exact goal in mind?

ie, the entire raison d'etre of the sphere built-in to Unity is that the points are fairly smoothly space ...... roughly equidistant, as you phrase it.

To bring up such a sphere in Unity, just do this:

You can then instantly get access to the verts, as you know

Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vv = mesh.vertices;
int kVerts=vv.Length
for (int i=0; i<kVerts; ++i)
  Debug.Log ... vv[i] 

Note you can easily check "which part of the sphere" they are on by (for example) checking how far they are from your "cities" (or whatever) or just check (for example) the z values to see which hemisphere they are in .. et cetera.


Furthermore...

Please note. Regarding your overall reason for wanting to do this:

but having specific interactions happen based upon what or where each ray hit

Note that it could not be easier to do this using PhysX. (The completely built-in game physics in Unity.) Indeed, I have never, ever, looked at a collision without doing something "specific" depending on "where it hit!"

You can for example get the point where the contact was with http://docs.unity3d.com/ScriptReference/RaycastHit-point.html

It's worth noting it is absolutely inconceivable one could write something approaching the performance of PhysX in casual programming.

I hope this makes things easier!

这篇关于制作一个等距顶点的球体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆