Attach model to terrain

Actually yes, try )

So I’m curious to see what the output prints at line 3 8).

Press -79.69286

Press -79.75846

Press -79.89842

Press -79.96091

Press -79.54008

Press -79.116196

Press -78.74865

Press -78.36998

Press -77.95284

Press -77.48464



and so on

Yeah! My apologizes. The - confused me :D.

No problem, can you advise me how to make clones and placed them correctly in my “for”?

to me it seems, that’s you’re translating every sphere to the exast same location except the height…

I think so too, but cannot understand how to fix it

what you need to do is something like this:

[java]

Node grassContainer = new Node();

Node pivot // whatever pivot is

for (int i = 0; i<=tsize; i++){

if (terrain.getHeight(vector) > -80f && terrain.getHeight(vector) < -70f){

System.out.println("Press " + terrain.getHeight(vector));



Pivot = new Node() //or whatever this is

pivot.setLocalTranslation(terrain coordins+whatever y)





pivot.attachChild(new Geometry("y:"+i, new Sphere(50, 50, 5)));

pivot.setLocalTranslation(10,terrain.getHeight(vector),10);

pivot.setMaterial(mat);

grassContainer.attachChild(pivot)

}

}[/java]



dont copy and paste this is like pseudo typing :stuck_out_tongue:

Did you mean to attach a pseudo grass clone to the pivot node? I can’t remember, but I think geometry ( spatials ) has a method called “clone()”.

[java]

Geometry pseudoGrass = new Geometry(“y:”+i, new Sphere(50, 50, 5));

for(…) {

…

Geometry pseudoGrassClone = pseudoGrass.clone();

…

}

[/java]



Edit: WOW! You guys were fast ;P.

basically you need to specify a translation/coordinates everytime you create a new geometry, and i do it by creating a blank node and attaching it to it and a parent container.

ryuu said:
what you need to do is something like this:
[java]
Node grassContainer = new Node();
Node pivot // whatever pivot is
for (int i = 0; i&lt;=tsize; i++){
if (terrain.getHeight(vector) &gt; -80f &amp;&amp; terrain.getHeight(vector) &lt; -70f){
System.out.println(&quot;Press &quot; + terrain.getHeight(vector));

Pivot = new Node() //or whatever this is
pivot.setLocalTranslation(terrain coordins+whatever y)


pivot.attachChild(new Geometry(&quot;y:&quot;+i, new Sphere(50, 50, 5)));
pivot.setLocalTranslation(10,terrain.getHeight(vector),10);
pivot.setMaterial(mat);
grassContainer.attachChild(pivot)
}
}[/java]

dont copy and paste this is like pseudo typing :P


No, still do not work (

I got your idea, but cannot figure out how to code

the key is the:



[java]pivot.setLocalTranslation(10, terrain.getHeight(vector), 10)[/java]



shouldn’t that be:



[java]pivot.setLocalTranslation(vector.x, terrain.getHeight(vector), vector.z)[/java]



?

this correct, but pivot.setLocalTranslation(10, terrain.getHeight(vector), 10) - will reproduce a lot spheres as column, it is enough to see any result

wait are you not looping through vectors ? i.e.

[java]for(int x=0; x<100;x++){

for(int z=0; z<100;z++){

blah blah



}

}[/java]

1 Like

No I am not, cause my “for” is a simple test, it must reproduce a column of sphere

2dkot said:
this correct, but pivot.setLocalTranslation(10, terrain.getHeight(vector), 10) - will reproduce a lot spheres as column, it is enough to see any result


ok, I see.. another thought: you are attaching new spheres at the pivot's origin, then translate the pivot everytime to a new location. Try to translate the spheres themselves, an leave the pivot untranslated.

how can I do it?

[java]

for (int i = 0; i<=tsize; i++){

if (terrain.getHeight(vector) > -80f && terrain.getHeight(vector) < -70f){

System.out.println("Press " + terrain.getHeight(vector));

Geometry grass = new Geometry("y:"+i, new Sphere(50, 50, 5));

pivot.attachChild(grass);

grass.setLocalTranslation(10,terrain.getHeight(vector),10);

grass.setMaterial(mat);

}

}

[/java]

1 Like

Are you attaching that “pivotContainer” node or the “pivot” nodes to the “terrain” node or to the “rootNode” node?