Text2D, Text3D in Xith3D?

Well I use billboarding all the time in Xith3D, however it only serves to make my particles elements face the camera.
Here’s what I do:


    public void updateParticleLocation(){
      viewMatrix.getColumn(0, rightVector);
      viewMatrix.getColumn(1, upVector   );

      usefulVector.sub(upVector, rightVector);
      particleCoordinates[0].scaleAdd(particleSize, usefulVector, particleLocation);

      usefulVector.add(upVector, rightVector);
      particleCoordinates[1].scaleAdd(particleSize, usefulVector, particleLocation);

      usefulVector.add(upVector, rightVector);
      usefulVector.negate();
      particleCoordinates[2].scaleAdd(particleSize, usefulVector, particleLocation);

      usefulVector.sub(rightVector, upVector);
      particleCoordinates[3].scaleAdd(particleSize, usefulVector, particleLocation);
    }

Getting billboarding to work in the program was a lot easier than I thought. Here’s a simple code sample for people like me who thought it was hard to figure out:


 Appearance billboardAppearance = new Appearance();
 billboardAppearance.setColoringAttributes(new ColoringAttributes(new Color3f(0.0f, 1.0f, 0.0f), ColoringAttributes.NICEST));
    Billboard billboard = new Billboard(Billboard.COORDINATES | Billboard.TEXTURE_COORDINATE_2, 500, 500);
    Shape3D billboardShape = new Shape3D(billboard, billboardAppearance);
    scaleGroup.addChild(billboardShape);

I haven’t textured them yet but they work great.

That would give you a single billboarded quad mate, mine on the other hand could stretch to an infinite number
^
|
pushing it a bit I know :stuck_out_tongue:

Sorry I’m late… Here is the code I currently use to display 2d text.
http://stgo.dyndns.org/com.xith3d.text.zip
See TextManager.createShape

Empty zip package?

Zip works for me, maybe he was just uploading?

Sorry. It is fixed now.
Seems I need a zip crashcourse…

Hi gpothier,

Great work with the text stuff! Thanks for making it available ;D I was I trying to use it at this momenet, but the texture of the shape appears reflected on the screen. I’m trying to fix that, but it would be cool if you could give me a hint :stuck_out_tongue:

In the FontManager class, you have the following to render the texture of a char of the string:



char theChar = aString.charAt(i);
                  int theWidth = getWidth(theChar);
                  
                  int theBaseTexCoordIndex = (theChar - 32) * 4;
                  
                  float theCurrentX = aRenderLocation.getX();
                  int theVertexIndex = aRenderLocation.getVertexIndex();

aQuadArray.setCoordinate(theCurrentX, 0, 0);
                  aQuadArray.setCoordinate(theCurrentX, itsFontHeight, 0);
                  aQuadArray.setCoordinate(theCurrentX+theWidth, itsFontHeight, 0);                  
                  aQuadArray.setCoordinate(theCurrentX+theWidth, 0, 0);
                  
aQuadArray.setTextureCoordinates(0, 
                                    theVertexIndex, 
                                              itsTextureCoordinates,
                                                    theBaseTexCoordIndex, 4);
                                                      
      
                  ..

I don’t really understand how the setTextureCoordinate method works… What’s the meaning of theBaseTexCoordIndex variable? and why the hell equals (theChar - 32) * 4 ? Sorry to be annoying to ask all these simple questions.

I’m trying to get the font work with Billboards too… Has anyone actually improved the Billboard class? I heard in the forum about people using Billboard to display labels… how did people implement that? I’m really considering using the amazing UIOverlay hack, but I fear that my already low FPS will drop a lot :frowning: