www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: AugTech on October 13, 2012, 01:05:04 pm

Title: Draw ground level grid
Post by: AugTech on October 13, 2012, 01:05:04 pm
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().
Code: [Select]
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)
Code: [Select]
getRenderer().getTheWorld().addPolyline( Utilities.testPolyLine( gridOrigin ) );

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

Many thanks in advance.
Title: Re: Draw ground level grid
Post by: EgonOlsen on October 13, 2012, 02:34:38 pm
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 (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.
Title: Re: Draw ground level grid
Post by: AugTech on October 13, 2012, 03:17:25 pm
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.
Title: Re: Draw ground level grid
Post by: AugTech on October 14, 2012, 08:16:30 pm
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;

Code: [Select]
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

Title: Re: Draw ground level grid
Post by: EgonOlsen on October 15, 2012, 04:08:29 pm
Does this happen at setup- or at runtime?
Title: Re: Draw ground level grid
Post by: AugTech on October 15, 2012, 04:14:03 pm
At runtime
Title: Re: Draw ground level grid
Post by: EgonOlsen on October 15, 2012, 08:10:04 pm
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...) ?
Title: Re: Draw ground level grid
Post by: AugTech on October 17, 2012, 12:01:51 pm
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]
Title: Re: Draw ground level grid
Post by: EgonOlsen on October 17, 2012, 08:25:51 pm
And the models should all be in wireframe too?
Title: Re: Draw ground level grid
Post by: AugTech on October 18, 2012, 05:09:26 pm
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.
Title: Re: Draw ground level grid
Post by: EgonOlsen on October 18, 2012, 07:47:50 pm
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... ???
Title: Re: Draw ground level grid
Post by: AugTech on October 19, 2012, 10:43:53 am
No problem Egon, I've got an alternative method now.