Setting render2d to use the same coordinate system as render

I want render2d to use render’s coordinate system.
(ie. render’s (x, y, z) rather than the system it currently uses.

What’s the best way to do it? Is it to create a new display region? Or is it possible to get at the default display region?

If you mean you want render2d to be a 3-d coordinate system the same as render, then you mean you want it to have the same kind of lens. So try:

base.cam2d.node().setLens(base.cam.node().getLens())

Though I have to admit I wonder what the point of this is.

David

That’s what I have at the moment. Unfortunately, the coordinates still don’t line up.

Is there something about setting:

NodePath.setDepthTest(False)
NodePath.setDepthWrite(False)

for the node with which the camera’s associated that would cause it to use a different coordinate system?

It’s simple enough to create a function that converts between the two, but I was wondering if there was a different way of going about it.

As for why, I want a 3D layer on the bottom, with a 2D layer on top, where the labels on the 2D layer are associated with models on the 3D layer on the bottom. Using the render2d layer for the labels saves me some trouble.

Well, if you really wanted it to match up one-to-one, you would then need to reparent base.cam2d to base.camera, so that it’s in the same place as the render2d’s camera.

But still, it seems like a mistake. You haven’t made a 2-D scene graph that lines up with your 3-D scene graph–instead, you’ve made render2d into another 3-D scene graph. You might as well just parent your labels directly into the normal 3-D scene graph.

David

Thanks. I’ll try that instead.

Edit: DirectLabels still seem to use a different coordinate system.

I must be doing something wrong. The labels only display when I reparent base.cam2d to render. Additionally, cam2d displays both 2d and 3d objects, but cam only displays 3d objects. And it doesn’t seem to resolve the basic problem, which is that the 2d and 3d coordinate systems are different.

Yes, the 2-d and 3-d coordinate systems are different. They are different precisely because one of them is 2-d, and the other one is 3-d. There is no way to reconcile that. The 3-d coordinate space is inherently different from the 2-d coordinate space.

David

Cheers.

Does this mean that if I try to place objects like say, DirectLabels in 3d space that they’ll always continue to use the 2d coordinate system?

Here’s the current setup for clarification:

camera2d  = base.cam2d.getParent()
camera.setPos(0, 0, 100)
camera.setHpr(0, -90, 0)
base.setBackgroundColor(0, 0, 0)
base.disableMouse()
camera2d.reparentTo(render)

win2d = base.cam2d.node().getDisplayRegion(0)
win = base.cam.node().getDisplayRegion(0)

lens = OrthographicLens()
lens.setFilmSize(base.win.getXSize(), base.win.getYSize())
lens.setNearFar(-1000, 1000)
base.cam.node().setLens(lens)
base.cam2d.node().setLens(lens)

model = loader.loadModel("models/planet_sphere")
model.reparentTo(render)

label = DirectLabel( text = "TEXT", text_fg = (1, 1, 1, 1), pos = (0, 0, 0), parent = render, scale = 100,
frameColor = (0, 0, 0, 0) )

I’m confused because cam2d shows model and label, but cam only shows model.

My apologies. I gave you bad advice before I understood more clearly what you were trying to do. You probably shouldn’t reparent your cam2d under render, because that will make it draw everything under render too.

Still. You are setting both cameras to use an OrthographicLens, which is a 2-d lens. That makes both scene graphs into a 2-d scene graph.

You should understand that the only difference between a 2-d scene graph like render2d, and a 3-d scene graph like render, is the lens used to look at them. So if you were to set render2d to use a PerspectiveLens, you would make render2d into a 3-d scene graph (despite its name). Similarly, when you set render to use an OrthographicLens, you are making render into a 2-d scene graph (despite convention).

A 3-d scene is a world with depth and perspective, hence the PerspectiveLens. It has X, Y, Z coordinates that are measured in some kind of spatial units, like feet or centimeters (you decide what the scale is).

A 2-d scene is a world with no perspective. It uses an OrthographicLens which draws things with no perspective. It has X, Y, and Z coordinates, but the Y coordinate is generally unused. The X and Y coordinates are measured in screen units, because this is the only kind of unit that makes sense without perspective.

Does this help you to understand the different between a 2-d and a 3-d scene?

DirectLabels can be placed either in a 2-d scene or in a 3-d scene. They’re just regular flat cards; there’s nothing about them that’s inherently 2d-ish other than the fact that they’re flat. If you place them in the 3-d scene, they work like any other 3-d object; they have an X, Y, Z position and will be visible when they are in front of the camera.

David

Thanks! That explanation was very helpful.

Given what you wrote, I figured out what the problem was. The orientation of render2d/camera2d was different than the orientation of render/camera. Changing the orientation aligned the two cameras, then the labels needed to be reorientated to compensate.