Draw ground level grid

Started by AugTech, October 13, 2012, 01:05:04 PM

Previous topic - Next topic

AugTech

Hi.
I am trying to draw a basic grid of 100m size tiles at floor/ ground level within my scene (think '80s Tron!)
I thought the new Polyline() class would be idea for this but it doesn't get rendered at all. :) Would Polyline be the right choice for this, or should I be creating something with Plane() ? Incidentally I want to be able to switch it on and off, but I can't see a method for removing/ changing the visibility of poylines on World().

public static Polyline testPolyLine(SimpleVector origin) {
SimpleVector o = origin;

SimpleVector[] points = new SimpleVector[4];
points[0] = new SimpleVector(o.x,o.y,o.z-100);
points[1] = new SimpleVector(o.x,o.y,o.z+100);
points[2] = new SimpleVector(o.x,o.y-100,o.z);
points[3] = new SimpleVector(o.x,o.y+100,o.z);

return new Polyline(points, new RGBColor(130, 130, 130));

}

And at start-up (when a position is known)

getRenderer().getTheWorld().addPolyline( Utilities.testPolyLine( gridOrigin ) );


As a note; the java doc doesn't include the Polyline() class...

Many thanks in advance.

EgonOlsen

The javadoc does include Polyline. I've just checked the version in the distribution as well as the online version and both of them include it...!? Regarding visibility, just use the latest beta from here: http://jpct.de/download/beta/jpct_ae.jar. It adds the missing visibility feature.

I'm not sure why you don't see the Polyline...make sure that your camera has a location and direction that actually looks at the line and keep in mind that the Polyline will be affected the depth buffer, i.e. if your lines lie within your level's geometry, you are not going to see them.

AugTech

Thanks Egon.
Sorry about the Javadoc - I was looking at the desktop version!

Have now sorted (as a test) as the origin was completely wrong for the scene.

Cheers.

AugTech

This maybe more of a maths question (not my best subject!) but, given I can't use the same functions on a Polyline() as an Object3D, I thought I would still post the query...

I have direction and up vectors from my camera position which I usually supply to Object3D to ensure the objects are aligned correctly with my scene;


SimpleVector dir = new SimpleVector(
camera.frontX,
camera.frontY,
camera.frontZ
);
SimpleVector up = new SimpleVector(
camera.upX,
camera.upY,
camera.upZ);

obj.setOrientation(dir, up);


but Polyline() doesn't have the setOrientation() method. Can anyone suggest how I use these vectors with the polyline coordinates (points) to rotate the line?
Thanks in advance


EgonOlsen

Does this happen at setup- or at runtime?

AugTech


EgonOlsen

Polyline is not meant to be used for real time transformations and i somehow fail to see the point of adjusting the ground based on the cameras position... ??? Or am i getting this wrong (most likely...) ?

AugTech

Due to the coordinate systems / transforms occurring within the application (based on real-world position) the 'ground' is rotated in different planes (arbitrary x,y,z rotations), and so the camera is also rotated to view the current scene as if it were level.
Therefore, in order to place models within the scene, they also have to be rotated to align with the current camera view, for which I store the required rotations as up and direction vectors.
This all happens at runtime as the models/ objects are dynamically created from in-bound data.

There is possibly easier ways to get the same result, but the current method works well.
An alternative, possibly proffered (?), method could be to create a plane with a high level of transparency to represent the ground and add this.

Incidentally I have managed to create the grid with Polylines now by calculating the real-world coordinates and running them through the existing transformational process to world coordinates, but its a little bulky compared to starting with world coordinates and setting their direction (see screeny), although I would like to use Polylines a lot more within the scene compared to creating very thin Objects.

Hope this makes some sense!

[attachment deleted by admin]

EgonOlsen

And the models should all be in wireframe too?

AugTech

Nope - this is purely to give an indication of the ground, without actually obscuring the 'real' ground under your feet.
All models still want to be rendered as normal.

EgonOlsen

Then i don't get the problem. If the objects are normal Object3D instances, all is fine with them. The ground is a PolyLine...but i still don't get why it has to be rotated all the time. It's usually the camera that rotates, not the ground... ???

AugTech

No problem Egon, I've got an alternative method now.