Jump to content

[SOLVED] How to get exact width


photo

Recommended Posts

Hello everyone,

I looked into a lot of topics in the forum but I didn't find any help on my problem so I decided to post it.

I am currently trying to get a code-created ObjectText's exact width. I'm working on Unigine v2.10.

I tried using its BoundBox but I couldn't find anything close to what I need.

Do somebody know a proper way to get that width and explain it to me? It would be really appreciated. 

Thanks for your time,

Antoine

Link to comment

Hello Morbid, thank you for your answer.

I tried to use the TextWrapWidth. I'll try to be more accurate for what I need.

I need to center a text on a parent object. As the position (0,0,0) is centered with the upper left corner of the ObjectText in the content editor,

I thought I could use the text's BoundBox in order to do that, as in the editor we can clearly see the gizmo's BoundBox around the text.

So in order to be more precise I'd ask : Is there a way to get this BoundBox (visible in the editor) width and/or height values?

Or is there an easier way to get the Text centered on the parent object ? 

If you need any more information please ask me I don't know how to be more accurate.

Thanks again.

Antoine

Link to comment

Okay, I see.

We did similar thing for tooltip text in Superposition (you can download demo and all source code via SDK Browser).  Check ObjTooltip.cpp:

	BoundBox bb = obj_text->getBoundBox();
	text_width = bb.getMax().x * scale;
	text_height = -bb.getMin().y * scale;
	obj_text->setPosition(vec3(-text_width * 0.5f, 1 + text_height * 0.5f, 0));

This is not the most comfortable way to center the text but it works.

We'll see when we can revamp ObjectText.

Thanks!

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Alright this helped me a lot !

I didn't adapt it word to word I have it working this way :

BoundBox bb = _label->getBoundBox();
float label_width = bb.getMax().x * _label->getScale().x;
float label_height = -bb.getMin().y * _label->getScale().y;
_label->setPosition(Math::Vec3(label_width * 0.5f, 0, label_height * 0.5f));

I had to invert Y and Z because I needed the 'up' axis to be centered and not the North.

This way I finally get what I needed.

Thank you very much !

  • Like 1
Link to comment
  • morbid changed the title to [SOLVED] How to get exact width
×
×
  • Create New...