gpt4 book ai didi

带有自定义 3D 图形库的 c++ - 在条件之间使用或运算符编写 while 循环

转载 作者:行者123 更新时间:2023-11-28 04:03:55 30 4
gpt4 key购买 nike

我正在尝试编写一个循环代码块,该代码块在 C++ 中询问以下内容

while object A, or B or C or D == X, Y, Z (coords)

如果 A 满足条件,将对象 A 向东移动。

如果 B 满足条件,将对象 B 向东移动。

等等,

我已经预先将每个对象坐标设置为一个字符串,所以我只需要将它们与控件进行比较,目前,我只是发生了一个无法识别哪个对象 正在触发它。

读取坐标和移动对象的代码在一个特定的库中,我的导师建议使用数组和 while 循环来实现这一点,但即使花了几个小时研究它我也不确定如何去做。

我有 unity 和 unreal engine 的背景,所以像这样简单的事情让我头疼,因为我只想在点上使用条件,而不是对每个对象使用react。

我对 C# 很陌生,所以请尽量保持解决方案简单,谢谢!

编辑:这是我目前正在使用的代码

//Load strings at the start of the game
```string bblocal = (ballblue->GetLocalX, ballblue->GetLocalY, ballblue->GetLocalZ);
string bilocal = (ballindigo->GetLocalX,ballbindigo->GetLocalY, ballindigo->GetLocalZ);
string bvlocal = (ballviolet->GetLocalX,ballviolet->GetLocalY, ballviolet->GetLocalZ);
string bflocal = (ballfawn->GetLocalX,ballfawn->GetLocalY, ballfawn->GetLocalZ);

string bb = bblocal;
string bi = bilocal;
string bv = bvlocal;
string bf = bflocal;```

//For each tick, check the following
```while (bb || bi || bv || vf == (-50, 10, 50)
{
//Turn blue and move it to next point
if blue
{
ballblue->MoveX (0);
ballblue->MoveZ (100);
ballblue->RotateX (-50);
ballblue->RotateZ (50);
}
//Turn Indigo and move it to next point
//Turn Violet and move it to next point
//Turn Fawn and move it to next point

}

最佳答案

对于给定的类点,如:

public class Point
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}

你有定义点早午餐:

var A = new Point{X=1, Y=0, Z=0};
var B = new Point{X=0, Y=1, Z=0};
var C = new Point{X=0, Y=0, Z=1};
// Etc

还有一个用来比较它们的引用点。列出所有你必须检查的点在一个数组中。

var referencePoint = new Point{X=0, Y=0, Z=1};
var pointsToCheck = new []{A, B, C};

为这个数组的每个元素做你的验证。您可以通过变量访问该点。

foreach(var p in pointsToCheck){

// Would be nice If Point add IEquatable<Point> with Equals gethashcode
if( p.X == referencePoint.X
&& p.Y == referencePoint.Y
&& p.Z == referencePoint.Z
)
{
//Do something!
p.X ++;
// Break; // if only the first must be moved.
}
}

直接用 LinQ 查询它们

pointsToCheck.Where( p => p.X == referencePoint.X
&& p.Y == referencePoint.Y
&& p.Z == referencePoint.Z) ;

如果你有一个“角”数组,你在其中指向位置,你将需要 IEquatable。

var currentCornerIndex = Array.IndexOf(cornersList, CurrentPoint);
//Will return the next corner:
// if it's the last corner return the first
// if not a corner return the first.
var nextCornerIndex = (currentCornerIndex + 1) % cornersList.Length;
var nextCorner = cornersList[nextCornerIndex];

关于带有自定义 3D 图形库的 c++ - 在条件之间使用或运算符编写 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59065601/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com