- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Unity 4.6 开发一个项目。我想知道是否有一种简单的方法来以编程方式设置顶点位置。目前我的代码看起来像这样 (C#):
public void createPoints(float x, float y, float z) {
point [0] = new Vector3 (x, y, z);
point [1] = new Vector3 (x, y, -z);
point [2] = new Vector3 (x, -y, z);
point [3] = new Vector3 (x, -y, -z);
point [4] = new Vector3 (-x, y, z);
point [5] = new Vector3 (-x, y, -z);
point [6] = new Vector3 (-x, -y, z);
point [7] = new Vector3 (-x, -y, -z);
}
其中 x、y 和 z 是预定值,点是 Vector3[]
(数组)。棱镜的中心点为 0,0,0
(Unity 中的 Vector3(0,0,0)
)。
例如,使用以下值:
生成的点应该如下(顺序无关紧要):
我的问题:有没有一种方法可以生成这些点而无需对其中的值进行实际硬编码?
我当前所需解决方案的代码是:
public void createPoints(float originalX, float originalY, float originalZ) {
for (int i = 0; i < 8; i++) { //8 vertices exist of a rectangular prism
point [i] = new Vector3 (x, y, z);
}
}
如何更改此代码以生成这些正负点?我的猜测是 x、y 和 z 的正负值之间的某种交替,使用 i
的模数或 i
除以其他整数的舍入,但是我无法全神贯注。 C# 或 UnityScript 都可以。
换句话说,在 for 循环的每次迭代中,x = -x
,对于每个 something y = -y
,对于每个 something z = -z
.
非常感谢对此的任何帮助。
最佳答案
我会为此使用 linq
var alt = new[] { 1, -1 };
var result = ( from i in alt
from j in alt
from k in alt
select new Vector3(i * 1, j * 2, k * 3)
).ToList();
关于c# - 从顶点位置以编程方式创建 3D 棱镜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29054420/
假设我有一对转换函数 string2int :: String -> Maybe Int int2string :: Int -> String 我可以使用光学很容易地表示这些。 stringIntP
在使用镜头时,我偶尔需要在光学链中进行一些基本的文本解析。在我处理的一个 API 中,有一个像这样的 JSON 字段: "timespent": "0.25", 由于它被错误地编码为字符串而不是数字,
我开始学习 OpenGL 并将其与 SFML 2.1 一起使用以获取窗口、加载图像等。但是我遇到了简单棱镜的问题。面部部分透明,看起来很糟糕:/我正在看教程,但我不知道我的代码有什么问题......你
我正在使用 Unity 4.6 开发一个项目。我想知道是否有一种简单的方法来以编程方式设置顶点位置。目前我的代码看起来像这样 (C#): public void createPoints(float
我正在使用 Prism并且它适用于 CSS: p { color: red } 但我不能让它为 html 工作: red text 我有两个问题: 表示为标签,而不是文本,但我可以将其替换为 <
只需阅读精彩的“Lens/Aeson Traversals/Prisms" 文章并拥有一个实际应用程序。给定以下匿名 JSON 结构,我将如何棱镜出一个集合而不是特定值? {"Locations" :
我正在尝试在多对多表(引用自身)上使用 prisma 这样的一行将有子孙 我可以毫无问题地获取所有行,但我正在努力了解如何在可读的 JSON 中排序数据,这将阻止在前端进行解析 预期输出如下:返回的
我正在 Unity 中创建一个 2D sprite 游戏,这是一个 3D 游戏开发环境。我已将对象的所有平移限制在 XY 平面上,并将旋转限制在 Z 轴上。 我的问题是用于检测对象之间碰撞的网格必须仍
我正在尝试在多对多表(引用自身)上使用 prisma 这样的一行将有子孙 我可以毫无问题地获取所有行,但我正在努力了解如何在可读的 JSON 中排序数据,这将阻止在前端进行解析 预期输出如下:返回的
我有两个表 User 和 Post 由自定义的多对多表链接,例如: model User { id Int @id @default(autoincrement()
我有一个包含三个矩阵的列表a和一个具有三个高度(任何正实数)的向量h。这些矩阵形成三角形,即棱柱的底面。我想添加向量h的信息来构造棱镜。 我创建了一个以 2D 形式绘制图形的函数 (pplot)。如何
这个在跟我玩,我似乎无法弄明白 - 我需要一些外部帮助,兄弟们! 我想要一个没有标题、最小化、最大化和关闭按钮的弹出窗口,因为我们想自己设置样式并在弹出窗口的屏幕上添加自定义关闭按钮。 所以我通过这些
我正在扩展 Prism使用自定义语言,我想突出显示类型(int、float、bool)。 我想匹配不以点或 : 符号开头的字符串。 我已经尝试过单独使用正则表达式但无法使其工作,所以我可能必须使用 P
我是一名优秀的程序员,十分优秀!