Using 2d coordinates(upper-left) with JMonkey(centered)?

So I have a set of data to build a project that I am given 2D data from(using upper-left coordinate system) and I need to convert it into 3D with JMonkey.

I am able to bring the data in fine, but what I am given is wrong. I realized this has to do with how the coordinate systems are layed out.

Also by looking at I believe Tutorial 2 (Hello Node) it says by creating a 1x1x1 box you’re creating a box 2x2x2 world units. By using the data I am given, and turning it into “World Units” will I see any nodes intersecting? From what I see it’s just a matter of these boxes growing from the center.

Does anyone have any recommendations for doing this? All of the data is 2D based.

Thanks.

What is the data? How are you displaying it? (What do you want it to look like?)

What do you mean the data is 2d?

Have you considered using a point mesh?

Sorry let me explain.

Basically I am given a 2d Schematic of something that I need to covert to 3D. In this case Depth and Height are switched, so instead of looking down into the Paper(Z) I’ll be looking into the Scene(Z).

So since I am given this 2D Schematic I am looking at it from an Upper x,y (0,0) point, instead of working everything from the middle.

I tried doing things like getting the screen size, dividing in half and trying to set up the points all based on that 2D Data, but it isnt’ working well, and it’s very crude.

So basically if my screen size is 2000 pixels and 1000 is my center, which I have a 5x5x5 I would have a 10x10x10 world unit box at the center. If I did Display - ScreenSize/2 I should be at 0,0 in the top left, but it just sends it out in my world and nothing really is fixed.

In JavaFX I believe there is something to convert 2D data to 3D.

I know FX is mostly 3D, but is there a way to convert upper left 2D data to centered 3D Data nicely?

I tried looking up PointMesh, but didn’t havr much luck, I found mesh and a bunch of subclasses, one was “ParticleMesh.”

I’m really unclear about what exactly you want, even after that explanation. Anyways, I stumbled across this post @ stackoverflow by accident some hour ago. As I’m not sure what you want, it may not be of any help, although it seems like it might

That’s cool, but not really what I need for this issue anyways :).

Again, I am given a 2D representation of data. It’s as if you were using Java Swing and creating data using x and y values only, which uses a upper-left coordinate system.

I am taking this data, and making it 3D.

I have the 3D items all placed, the only problem is that they are not placed in the correct places.

I am attributing this to the fact Open GL uses a Centered, Right-Handed Coordinate System, whereas 2D does not. I need to use the correct coordinate system, or find a way to convert it.

So again if I am using upper left @ point (0,0) and I have a box 5x5 it will be @ 5,5.

If I use Jmonkey it is centered and I get @ (0,0,0) a box that is5x5x5 will be @ X(5+ 5- )Y(5+ 5-) Z(5+ 5-) according to the tutorial which says that a 5x5x5 will be 10x10x10 “world units”

This is going to be a importer, so I am going to be grabbing a ton of 2D data, and converting it to 3D, so this is very important.

EDIT: Here is a picture of both side by side.

So basically you can see that the 3D is basically flipped from the 2D The set of 3 shows 2 with 1 inside, and the set of 2 is basically 1 inside the other with a little sticking out of the end.

I feel I have to half the size since instead of being 5 it would have to be 2.5. It seems I could just flip the entire world around 180 around X… I guess when I’m actually walking through it’s irrelevant.

When I half the height, width, and depth I get closer to the actual thing when flipped, but It’s not 100%.

<cite>@KonradZuse said:</cite> That's cool, but not really what I need for this issue anyways :).

Again, I am given a 2D representation of data. It’s as if you were using Java Swing and creating data using x and y values only, which uses a upper-left coordinate system.

I am taking this data, and making it 3D.

I have the 3D items all placed, the only problem is that they are not placed in the correct places.

I am attributing this to the fact Open GL uses a Centered, Right-Handed Coordinate System, whereas 2D does not. I need to use the correct coordinate system, or find a way to convert it.

So again if I am using upper left @ point (0,0) and I have a box 5x5 it will be @ 5,5.

If I use Jmonkey it is centered and I get @ (0,0,0) a box that is5x5x5 will be @ X(5+ 5- )Y(5+ 5-) Z(5+ 5-) according to the tutorial which says that a 5x5x5 will be 10x10x10 “world units”

The size itself seems to be, but the item placements are what matters. I most likely will have to half the size.

This is going to be a importer, so I am going to be grabbing a ton of 2D data, and converting it to 3D, so this is very important.

If people want pictures then I will post them, I believe I am explaining this simply.


Ah alright, that makes it alot clearer :slight_smile:

The sizes for the box basically mean x amount in each direction for that axis, so 5x5x5 will indeed result in a 10x10x10 cube, so you probably will have to compensate for that.

It would be nice to have some pictures or something to get a better insight in what you have to do, although as of now the following solutions seems possible to me:

Take a point to start from, substract the values you receive from that.

E.g.
[java]Vector3f startPoint = new Vector3f(0f, 10f, 0f);

//Then for all the data you can do something like:

for(Vector2f point: data) {
Vector3f point3D = new Vector3f(point.getX(), point.getY(), 0f);
Box b = new Box(startPoint.substract(point3D );
//add box to scene etc…
}[/java]

Edit

Oh wait, just realised you only need to substract from the Y value, so basically :

[java]
float startY = 0f;

//Then for all the data you can do something like:

for(Vector2f point: data) {
Vector3f location = new Vector3f(data.getX(), startY - data.getY(), 0f);
Box b = new Box(location, xSize / 2, ySize/2, zSize/2);
//add box to scene etc…
}[/java]

EDIT:
After seeing the pictures you just posted I realise what is wrong.

You are halving the sizes, but you also gotta realise it still has an offset.

Meaning, a box at origin, with 1, 1, 1 size, results in 2x2x2 cube, from -1 to 1 for each axis.
When you half the size, the location of the object is -0.5, to 0.5, meaning you still have to move it 0.5 to place it at the correct spot.

So, my example was wrong too, you have to do this I guess:
[java]
float startY = 0f;

//Then for all the data you can do something like:

for(Vector2f point: data) {
Vector3f location = new Vector3f(data.getX() + xSize / 2f, startY - (data.getY() + ySize / 2f), 0f);
Box b = new Box(location, xSize / 2f, ySize/2f, zSize/2f);
//add box to scene etc…
}[/java]

2 Likes

Wow thanks a ton!!

I basically had

[java] for(int i = 0; i < p.totalDisplays; i++)
{

    b[i] = new Box(new Vector3f((p.displayX.get(i) + p.displayWidth.get(i) /2f),p.displayY.get(i) + p.displayHeight.get(i)/2f),0f)
                               , p.displayWidth.get(i)/2f, p.displayHeight.get(i)/2f, p.displayDepth.get(i)/2f);   
    Geometry[] g = new Geometry[p.totalDisplays];
    g[i] = new Geometry("Box", b[i]);

…[/java]

[java] for(int i = 0; i < p.totalDisplays; i++)
{

    b[i] = new Box(new Vector3f((p.displayX.get(i) + p.displayWidth.get(i) /2f),startY - (p.displayY.get(i) + p.displayHeight.get(i)/2f),0f)
                               , p.displayWidth.get(i)/2f, p.displayHeight.get(i)/2f, p.displayDepth.get(i)/2f);   
    Geometry[] g = new Geometry[p.totalDisplays];
    g[i] = new Geometry("Box", b[i]);[/java] 

and a few other ways like p.displayX.get(i),y,z… but keeping the width /2.

It kept giving me the mess as shown above…

Thanks :slight_smile:

<cite>@KonradZuse said:</cite> Wow thanks a ton!!

I basically had

[java] for(int i = 0; i < p.totalDisplays; i++)
{

    b[i] = new Box(new Vector3f((p.displayX.get(i) + p.displayWidth.get(i) /2f),p.displayY.get(i) + p.displayHeight.get(i)/2f),0f)
                               , p.displayWidth.get(i)/2f, p.displayHeight.get(i)/2f, p.displayDepth.get(i)/2f);   
    Geometry[] g = new Geometry[p.totalDisplays];
    g[i] = new Geometry("Box", b[i]);

…[/java]

[java] for(int i = 0; i < p.totalDisplays; i++)
{

    b[i] = new Box(new Vector3f((p.displayX.get(i) + p.displayWidth.get(i) /2f),startY - (p.displayY.get(i) + p.displayHeight.get(i)/2f),0f)
                               , p.displayWidth.get(i)/2f, p.displayHeight.get(i)/2f, p.displayDepth.get(i)/2f);   
    Geometry[] g = new Geometry[p.totalDisplays];
    g[i] = new Geometry("Box", b[i]);[/java] 

and a few other ways like p.displayX.get(i),y,z… but keeping the width /2.

It kept giving me the mess as shown above…

Thanks :).


Ah I see, np :slight_smile: Glad it worked out

I’m also curious is there a way to create a box by points? i.e., 0,0 to 10,0 to 20,20, etc.

Yes, you can create a mesh, which zarch already mentioned i think.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes :slight_smile:
I think i’m supposed to say RTFM haha

1 Like
<cite>@reveance said:</cite> Yes, you can create a mesh, which zarch already mentioned i think.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes :slight_smile:
I think i’m supposed to say RTFM haha

Thanks for the link, I wasn’t sure what he was saying above, I said above that I only found “Particle Mesh” when searching for “Point Mesh.” But that was last night, and I was tired.

Yeah, point mesh was a red herring as I wasn’t sure what you were trying to do. Basically it lets you construct a mesh then render a sprite at each vertex of the mesh. Useful for some visualisation of data but not for what you are doing.

A custom mesh is actually fairly simple to build though so would be well worth you looking at. You can get exactly the objects you want if you construct your own mesh, you can even use the code for Box as a good starting point :slight_smile:

<cite>@zarch said:</cite> Yeah, point mesh was a red herring as I wasn't sure what you were trying to do. Basically it lets you construct a mesh then render a sprite at each vertex of the mesh. Useful for some visualisation of data but not for what you are doing.

A custom mesh is actually fairly simple to build though so would be well worth you looking at. You can get exactly the objects you want if you construct your own mesh, you can even use the code for Box as a good starting point :slight_smile:

Yeah, thanks a lot!

I realized that I had switched Depth and Height which is why I had the funky issue. and I ended up creating a nifty algorithm to create all of the walls in the first picture and giving it a depth. The Custom Mesh tutorial is extremely useful.

The only issue I ran into now is the same as with the boxes, except for right now I have a single line with 12 units of depth. I would have to basically take the second point, minus the first point and then I would assume do the same calculations as above on each set of vertices?

I’m not sure what you mean?