# How many pixels per world unit?

I hope i am understandable.
What i want to do is create a transparent flat grid in my world at a certain height.
For this i think the easiest way would be to just put in a large quad and paint a repeating transparent texture on it.
But what dimensions should the texture have so i am able to predict where the gridlines appear ?
lets say i have a 100x100 area for the grid and want to draw lines every 10 world units, how large should the texture be (texture being just a square with transparent filling) ?

Or is there a better way to create such a layer grid ?

Method 1:
Would a wireframe grid not suffice? This is copy-pasted from the debugging page.
[java]
private void attachGrid(Vector3f pos, float size, ColorRGBA color){
Geometry g = new Geometry(â€świreframe gridâ€ť, new Grid(size, size, 0.2f) );
Material mat = new Material(assetManager, â€śCommon/MatDefs/Misc/Unshaded.j3mdâ€ť);
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor(â€śColorâ€ť, color);
g.setMaterial(mat);
g.center().move(pos);
rootNode.attachChild(g);
}
[/java]

Method 2:
Otherwise if you insist on using a texture, then I would do something like 50 pixels for each field, 2 pixels for each line. For 10 grids you will have 11 lines. That makes 50 * 10 + 2 * 11 = 522. Obviously can choose any relationship of widths.

Method 3:
Alternatively if it is just a repeating texture you could simply repeat the texture 10x10 times over the surface, then you only have to paint one bounded square texture. That would mean setting up a quad with texture coordinates with ranges of 0 - 10, and setting the texture wrapping mode to repeat.

Method 2 and 3 also requires messing with alpha channels in the material, so I would recommend method 1.

I need it to be also collidable with a ray, donâ€™t know if a grid you are using in method 1 will collide with a ray when i click between the grid lines without testing it.
This would be a quick solution, but i want to do a bit more with it too like making it partly transparent and adding a slight glow to it. Donâ€™t know if such a simple grid would suffice then.

For the other methods that is realy my question, when i create that texture, how many pixels does it need to cover an area of 10x10 without being streched or shrinked ?
Is it 100 pixels so that every 10 world units it repeats ? Or 50 pixels per 10 world units ?

(with world units i mean when i create a geometry the size is given as floats, so i considder those world units, meaning 10.0f = 10 world units)

I think the easist way to answer your question is just to try it out. The amount of interpolation depends on your camera distance, so it is impossible for me to answer. But basicly from your view you want a 1:1 scaling of number of pixels occupied by the quad and the texture resolution.

As for the collision detection, it is very simple to calculate yourself - it is a plane / line intersection. I can recommend Paul Bourkeâ€™s website here: Point, Line, Plane I have written it from that myself, it is only a few lines of code. Look for â€śIntersection of a plane and a lineâ€ť. This is also faster than colliding against a mesh, since your are â€śsolvingâ€ť the collision instead of â€śsearchingâ€ť for it.

1 Like

Well no, it is not dependant on the distance to the camera.
I donâ€™t mean what you actualy see in the scene/on your screen, i just meant the logical connection.
Yes if you are far away an area of 10x10 will be rendered smaller and the texture on it will also be shrinked, that doesnt change that the original texture image file used will span a certain area when drawn on a surface, no matter from where you look at it.

Maybe iâ€™m not explaining it right what i mean with it cause english is not my native language

Ok, so i try to explain:
If i remember correctly 1 pixel is usualy roughly arround 0,25mm
So a picture of 100x100 pixels covers an area of 25x25 mm or 2,5x2,5 cm.
Lets say one world unit would be 1cm, meaning 10x10 world unit area would be 10x10 cm area.
This would mean that to cover that area with a non modified texture i need a picture of 400x400 pixel, or the 100x100 scaled by 4.

As for the collision detection that realy would be a much better solution, thanks!

If it is all about predicting where the lines will run on screen, could you not just take the two corners of your quad, project them into screen space, subtract the two points to get your dimension vector. This would give you the dimensions of your quad, in pixels.

Other than that, your calculations seem correct, with the exception that I have never heard 0.25mm as being a â€śtypicalâ€ť pixel size, screens of the same size come in all kinds of resolutions after all.

Besides that, I donâ€™t think I understand your question. I cannot see how camera position and rotation will not affect your calculation. But I suspect your real question is â€śIs a pixel really 0.25mmâ€ť? I guess the answer to that is no, a pixel is pixelWidth = screenWidthPhysical / screenWidthResolution and pixelHeight = screenHeightPhysical / screenHeightResolution

But honestly, I am a bit confused.

Using the mm was just for an example.
The real question is what dimension do i need for the texture image to cover a 10x10 quad if it is painted 1:1.
Donâ€™t know how to explain it better.

But it is independant on the viewport:
Lets say my texture is a piece of paper, and my quad is a piece of cardboard, the paper will allways cover a certain area of the cardboard no matter from where i look or how far i am away.
So my quad i have the dimensions given by how large i create it inside the 3D world of jme, now the texture uses pixel as unit, just looking for the physical conversion between the two.

As an example, the grid you mentioned:
[java]Geometry g = new Geometry(â€śgridâ€ť, new Grid(10.0f, 10.0f, 0.2f) );[/java]
Now i want to put a texture on it that does not get streched or shrinked and is not repeated, what dimensions does the image file need then ?

Well your texture can be any size, there is no fixed limit, start with a low res, then increase that untill it looks sharp from normal viewing perspetives.

When texturing objects you dont sue pixels as a unit, but the abstract opengl texturecoordinats wich are 0-1 no matter how many pixels the texture has. (can extends 0 and one, so eg 0-2 means a two times repeating texture.

A normal quad in jme has

00 01
10 11
As texture coordinates for the edges.

If you want pixel level stuff thats what the GUI node is for, but thatâ€™s no use for in-world stuff.