Skip to main content

Billboards, Text2D vs. Java 2D Text

3 replies [Last post]
jarodrussell
Offline
Joined: 2010-05-19

Hey,

I'd like to add text to my 3D objects in the scene. I experimented with Billboard Behavior, Text2D and Text3D, but it's not looking good. I don't want the text to get smaller when the camera or the object moves away, for example.

So I figured I might add the text in the postRender() method using .drawString(String text, int xPos, int yPos).

My problem is that I don't know how to position the 2d text on the screen.

Picking translates between the (x,y) position on the 2D screen to a Pickray in 3D space, and if the Pickray hits an object or a point something happens. How can I reverse that? I know the 3D point, now how can I find out the correct 2D pixel location so that I can draw the text there?

Thanks in advance,
Jarod

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ralphld
Offline
Joined: 2010-08-02

You can also use a MultiTransformGroup to put text at a fixed distance from the camera so that it moves with the view. Take a look at:

http://minitraff.cvs.sourceforge.net/viewvc/minitraff/Testing/DHUD3D.jav...

and follow the "viewT" TransformGroup, I hope my code isn't too unclear..

The text stays in the upper left corner no matter what the view does.

You can see the finished program at:

http://minitraff.sourceforge.net/

Let me know if you have questions.
HTH
Ralph

Renoir Sewjee

Hi Jarod,

Take a look at the attached file.

Regards,
Renoir

On 18/08/2010 16:47, java3d-interest@javadesktop.org wrote:
> Hey,
>
> I'd like to add text to my 3D objects in the scene. I experimented with Billboard Behavior, Text2D and Text3D, but it's not looking good. I don't want the text to get smaller when the camera or the object moves away. I don't want the text to look pixelated.
>
> So I figured I might add the text in the [b]postRender()[/b] method using .drawString(String text, int xPos, int yPos).
>
> My problem is that I don't know how to position the 2d text on the screen.
>
> Picking translates between the (x,y) position on the 2D screen to a Pickray in 3D space, and if the Pickray hits an object or a point something happens. How can I reverse that? I know the 3D point, now how can I find out the correct 2D pixel location so that I can draw the text there?
>
> Thanks in advance,
> Jarod
> [Message sent by forum member 'jarodrussell']
>
> http://forums.java.net/jive/thread.jspa?messageID=480485
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
> For additional commands, e-mail: interest-help@java3d.dev.java.net
>
[TrackingPixelLocation.java]
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

jarodrussell
Offline
Joined: 2010-05-19

Thank you, that was very helpful!

> Hi Jarod,
>
> Take a look at the attached file.
>
> Regards,
> Renoir