我有一个方法从文件读取坐标并使用它们在文件上写入的指定坐标上呈现GameObject,此代码如下所示:
public void ProcessText()
{
String file_name = "C:/Users/Server/Desktop/textText.txt";
try
{
ProcessCoords file = new ProcessCoords(file_name);
String[] aryLines = file.OpenFile();
int i;
for (i = 0; i < aryLines.length; i++)
{
System.out.println(aryLines[i]);
if(aryLines[i].startsWith("makeGrass:")) {
String Arguments = aryLines[i].substring(aryLines[i].indexOf(":")+1, aryLines[i].length());
String[] ArgArray = Arguments.substring(1, Arguments.length() - 2).split(" ");
this.makeGrass(Double.parseDouble(ArgArray[0]),
Double.parseDouble(ArgArray[1]),
Double.parseDouble(ArgArray[2]));
}
}
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
我的文本文件只有一行:
makeGrass:(x y z) // for example makeGrass:(1.22334 0.0 9.66678)
现在这一切都很好......但是对于一个单独的对象来说,这没有任何意义。我想要做的是从多个坐标中获得尽可能多的对象,所以我的文本文件可能如下所示:
makeGrass:(0.0 1.0 5.0)
makeGrass:(8.0 1.0 2.0)
makeGrass:(4.0 1.0 7.0)
makeGrass:(0.0 1.0 2.0)
makeGrass:(2.0 1.0 7.0)
makeGrass:(5.0 1.0 6.0)
目前我只使用代码this.makeGrass一次,并且喜欢我的草模型只放置在第一行的那些坐标处(其他行导致图形故障,它们只是放在彼此的顶部)
我的问题是我如何编写代码以便它多次给我this.makeGrass:我想在各个makeGrass坐标上渲染草模型的次数与文本文件中提供的makeGrass坐标一样多,我怎么能这样做?
感谢您的帮助!
编辑:我被要求提供更多信息..这里是:
public class Vegetation extends GameComponent
{
private Game game;
GameObject grassLeaf1 = new GameObject();
Mesh grassLeaf1mesh = new Mesh("grassLeaf1.obj");
Material grassLeaf1material = new Material
(new Texture("GrassUVTex.png"), 1, 8, new Texture("GrassUVTex_NRM.jpg"), new Texture("GrassUVTex_DISP.jpg"), 0.008f, -0.5f);
MeshRenderer grassLeaf1Renderer = new MeshRenderer(grassLeaf1mesh, grassLeaf1material);
public Vegetation(Game game)
{
this.game = game;
}
public void makeGrass(double posX, double posY, double posZ)
{
grassLeaf1.AddComponent(grassLeaf1Renderer);
grassLeaf1.GetTransform().GetPos().Set((float)posX, (float)posY, (float)posZ);
grassLeaf1.GetTransform().SetScale(new Vector3f (2, 2, 2));
grassLeaf1.GetTransform().SetRot(new Quaternion(new Vector3f(0, 1, 0), (float) Math.toRadians(0)));
game.AddObject(grassLeaf1);
}
public void ProcessText()
{
grassLeaf1.AddComponent(new SaveGrass());
grassLeaf1.AddComponent(new ObjectManipulator(4.0f));
String file_name = "C:/Users/Server/Desktop/textText.txt";
try
{
ProcessCoords file = new ProcessCoords(file_name);
String[] aryLines = file.OpenFile();
int i;
for (i = 0; i < aryLines.length; i++)
{
System.out.println(aryLines[i]);
if(aryLines[i].startsWith("makeGrass:")) {
String Arguments = aryLines[i].substring(aryLines[i].indexOf(":")+1, aryLines[i].length());
String[] ArgArray = Arguments.substring(1, Arguments.length() - 2).split(" ");
this.makeGrass(Double.parseDouble(ArgArray[0]),
Double.parseDouble(ArgArray[1]),
Double.parseDouble(ArgArray[2]));
}
}
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
}
Vegetation类处理创建草模型并从文本文件中读取它的坐标。这是文本文件:
makeGrass:(0.6 1.0 2.8)
makeGrass:(5.6 1.0 9.8)
makeGrass:(2.6 1.0 4.8)
makeGrass:(7.6 1.0 3.8)
makeGrass:(0.6 1.0 2.8)
makeGrass:(0.6 1.0 4.8)
makeGrass:(2.6 1.0 2.8)
makeGrass:(0.6 1.0 0.8)
现在这应该让我能够在不同的位置渲染8个草模型,但是当我点击跑步时我能看到的是:
草也是超级闪亮的,因为所有其他草模型也被放置在这个位置..出了点问题..答案 0 :(得分:0)
好的,我发现错误,我的草功能搞砸了,它需要像这样:
at <- c(0, 0.1, 0.15, 0.25, 0.35, 0.45)
spplot(r1, xlim=c(613190.6,2173441), ylim=c(121319.4,1774699),
col.regions=rainbow(4), colorkey=F, contour=T,
# add a small number to the colour cutoffs to prevent ties
at=at + .Machine$double.eps,
# change the labels to be "pretty". See `?format`
labels=list(labels=format(at)),
col=grey.colors(1), maxpixels=102300)
唯一奇怪的是,一旦我将代码添加到makeGrass方法中,我就丢失了我的输入法......奇怪但不是现在的问题..
我几乎完全得到了我现在想要的东西..这里是我的世界编辑的最终结果和基础。非常感谢你,你真的帮了我!
这是我的ShowOff图片:http://www.pic-upload.de/view-27752521/ShowOff.png.html
我确信我会很快回来,但此刻我知道一切,并且可以自己扩展这个世界编辑,非常感谢所有迄今为止帮助过我的人,希望我可以回复一段时间了!