Nametag coordinates.

For people working on the C++ code.
Post Reply
agrecascino
New member
Posts: 4
Joined: Sun Aug 21, 2016 17:17
GitHub: agrecascino
IRC: agrecascino

Nametag coordinates.

by agrecascino » Post

When getting the coordinates of a name tag’s parent node, they seem to be somehow transformed, and I can't figure out how.

I noticed this, when messing around with drawing transparent name tags based on distance, the name tags would occasionally disappear. I started printing the nametags when they weren’t' being drawn, but the player was still loaded.

I then noticed that the nametag coordinate seems to be completely wrong.

Code: Select all

2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618When getting the coordinates of a name tag’s parent node, they seem to be somehow transformed, and I can't figure out how.

I noticed this, when messing around with drawing transparent name tags based on distance, the name tags would occasionally disappear. I started printing the nametags when they weren’t' being drawn, but the player was still loaded.

I then noticed that the nametag coordinate seems to be completely wrong.
[code]
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:45: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:45: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
2016-08-21 15:25:46: WARNING[Main]: Player pos 729.280396 35.000000 518.195618
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039
This player is exactly where I am, and yet the coordinate is thousands of nodes off.
So my question is, what's going on here.
2016-08-21 15:25:46: WARNING[Main]: Tag pos 2435.250000 25.000002 4728.290039[/code]
This player is exactly where I am, and yet the coordinate is thousands of nodes off.
So my question is, what's going on here.

kaen
New member
Posts: 9
Joined: Sun Aug 14, 2016 18:07

Re: Nametag coordinates.

by kaen » Post

EDIT: Oops, didn't see the forum section. I'll get out of here :)
Last edited by kaen on Sun Aug 21, 2016 22:39, edited 1 time in total.

agrecascino
New member
Posts: 4
Joined: Sun Aug 21, 2016 17:17
GitHub: agrecascino
IRC: agrecascino

Re: Nametag coordinates.

by agrecascino » Post

kaen wrote:Hi, it would help a lot if you posted the relevant code so we can see exactly what you're doing.

It sounds like you're taking the `offset` attribute of a waypoint hud element, but I'm doing some inference there.

In that case, you should be aware that there are three position-like attributes for a waypoint element. They are position, offset, and world_pos. From lua_api.txt:
The `position` field is used for all element types.

To account for differing resolutions, the position coordinates are the percentage
of the screen, ranging in value from `0` to `1`.

The `offset` field specifies a pixel offset from the position. Contrary to position,
the offset is not scaled to screen size. This allows for some precisely-positioned
items in the HUD.

...

* `world_pos`: World position of the waypoint.
To me it looks like you are referencing `offset` which would give you a position in screen coords with a presumably meaningless (or empty?) z value. It sounds like you want world_pos.

Sorry if I'm way off base

Code: Select all

void Camera::drawNametags()
{
	core::matrix4 trans = m_cameranode->getProjectionMatrix();
	trans *= m_cameranode->getViewMatrix();

	for (std::list<Nametag *>::const_iterator
			i = m_nametags.begin();
			i != m_nametags.end(); ++i) {
		Nametag *nametag = *i;
		if (nametag->nametag_color.getAlpha() == 0) {
			// Enforce hiding nametag,
			// because if freetype is enabled, a grey
			// shadow can remain.
			continue;
		}
		v3f pos = nametag->parent_node->getPosition() + v3f(0.0, 1.1 * BS, 0.0);
		f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f };
		trans.multiplyWith1x4Matrix(transformed_pos);
		if (transformed_pos[3] > 0) {
			core::dimension2d<u32> textsize =
				g_fontengine->getFont()->getDimension(
				utf8_to_wide(nametag->nametag_text).c_str());
			f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f :
				core::reciprocal(transformed_pos[3]);
			v2u32 screensize = m_driver->getScreenSize();
			v2s32 screen_pos;
			screen_pos.X = screensize.X *
				(0.5 * transformed_pos[0] * zDiv + 0.5) - textsize.Width / 2;
			screen_pos.Y = screensize.Y *
				(0.5 - transformed_pos[1] * zDiv * 0.5) - textsize.Height / 2;
			core::rect<s32> size(0, 0, textsize.Width, textsize.Height);
            float distval = abs(m_playernode->getPosition().X/10 - nametag->parent_node->getAbsolutePosition().X/10) + abs(m_playernode->getPosition().Z/10 - nametag->parent_node->getAbsolutePosition().Z/10) + abs(m_playernode->getPosition().Y/10 - nametag->parent_node->getAbsolutePosition().Y/10);
            //distval = 252542342342;
            if(nametag->rangemode_on && (distval < 128) )
            {
                nametag->nametag_color.setAlpha((1 - distval/128.0)*255.0);
            }
            else if(nametag->rangemode_on)
            {

                    g_logger.log(LL_WARNING,std::string("Player pos " + std::to_string(m_playernode->getPosition().X) + " " + std::to_string(m_playernode->getPosition().Y) + " " + std::to_string(m_playernode->getPosition().Z)));
                    g_logger.log(LL_WARNING,std::string("Tag pos " + std::to_string(nametag->parent_node->getAbsolutePosition().X) + " " + std::to_string(nametag->parent_node->getAbsolutePosition().Y) + " " + std::to_string(nametag->parent_node->getAbsolutePosition().Z)));
                    return;
            }

            g_fontengine->getFont()->draw(utf8_to_wide(nametag->nametag_text).c_str(),
                    size + screen_pos, nametag->nametag_color);

		}
	}
}
It's c++ rendering code, in camera.cpp

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Nametag coordinates.

by paramat » Post

You know there are multpile co-ordinate systems? The fundamental and finest system has a unit 1/10th the size of a node, many Minetest co-ordinates are in this system.
Your printed tag and player co-ords may be in different co-ordinate systems.

My guess as to why they don't correspond is that we use a 'camera offset' that shifts the world every time the player moves more than 200 nodes from the centre, this is to reduce visual glitches.
https://github.com/minetest/minetest/co ... d821f34b51

One of your printed coordinate types may be in non-offset co-ordinates. Perhaps you could test this guess by printing out again but when all players and tags have not moved more than 200 nodes from world centre.

kahrl
Member
Posts: 236
Joined: Fri Sep 02, 2011 07:51
Location: Rös̓̇chenhof

Re: Nametag coordinates.

by kahrl » Post

I was about to write that I'm guessing that the camera offset is the problem. But paramat ninja'd me ;-)

If you want to see a method that does something with nametags while taking camera offset into account, look at Mapper::updateActiveMarkers() in minimap.cpp. In particular note the line

Code: Select all

                v3s16 pos = floatToInt(nametag->parent_node->getPosition() +
                        intToFloat(client->getCamera()->getOffset(), BS), BS);

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Nametag coordinates.

by paramat » Post

I found this commit which deals with nametags and camera offset https://github.com/minetest/minetest/co ... 57b79f3140

agrecascino
New member
Posts: 4
Joined: Sun Aug 21, 2016 17:17
GitHub: agrecascino
IRC: agrecascino

Re: Nametag coordinates.

by agrecascino » Post

paramat wrote:You know there are multpile co-ordinate systems? The fundamental and finest system has a unit 1/10th the size of a node, many Minetest co-ordinates are in this system.
Your printed tag and player co-ords may be in different co-ordinate systems.

My guess as to why they don't correspond is that we use a 'camera offset' that shifts the world every time the player moves more than 200 nodes from the centre, this is to reduce visual glitches.
https://github.com/minetest/minetest/co ... d821f34b51

One of your printed coordinate types may be in non-offset co-ordinates. Perhaps you could test this guess by printing out again but when all players and tags have not moved more than 200 nodes from world centre.
Is this done to prevent rendering issues from floating point inaccuracy?

agrecascino
New member
Posts: 4
Joined: Sun Aug 21, 2016 17:17
GitHub: agrecascino
IRC: agrecascino

Re: Nametag coordinates.

by agrecascino » Post

paramat wrote:You know there are multpile co-ordinate systems? The fundamental and finest system has a unit 1/10th the size of a node, many Minetest co-ordinates are in this system.
Your printed tag and player co-ords may be in different co-ordinate systems.

My guess as to why they don't correspond is that we use a 'camera offset' that shifts the world every time the player moves more than 200 nodes from the centre, this is to reduce visual glitches.
https://github.com/minetest/minetest/co ... d821f34b51

One of your printed coordinate types may be in non-offset co-ordinates. Perhaps you could test this guess by printing out again but when all players and tags have not moved more than 200 nodes from world centre.

Code: Select all

float distval = sqrt(pow((m_cameranode->getPosition().X/10.0 - (m_camera_offset.X/10.0 + nametag->parent_node->getPosition().X/10.0)),2) + pow((m_cameranode->getPosition().Y/10 - (m_camera_offset.Y/10 + nametag->parent_node->getPosition().Y/10)),2) + pow((m_cameranode->getPosition().Z/10 - (m_camera_offset.Z/10 + nametag->parent_node->getPosition().Z/10)),2));
How is my math wrong?

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Nametag coordinates.

by paramat » Post

> Is this done to prevent rendering issues from floating point inaccuracy?

I think so.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests