Target boxes for 3079

Hey all,



I want to add attacker / follower indicators for my game, like this photoshopped image:



http://i.imgur.com/ZMEOb.png



I’m trying to determine the best way to do this… what I’m thinking:


  1. Have a image with the four corners, and add it as a Picture to the guiNode
  2. Color it red/green as needed
  3. Determine the scale somehow based on how big the character is and how far away (??)
  4. Position it using the “Camera.getScreenCoordinates” function



    This seems pretty complex, and I’m not sure how to do step #3 (because the profile size will change as the character rotates, etc.) – wondering if anyone else has done this and if they have any tips.



    Thanks!

what about a BillboardControl (so it always faces you) which has a transparent quad, the size of the BoundingBox, which is set at the location of the monster.

1 Like

I would have it on the gui node so you always see it, and it doesn’t get clipped, shrink, etc.

You can take the bbox of the character and project the 8 points to screen coordinates, then build a smallest-fitting box for those translated coords and scale the red box to fit.

@Sploreg said:
I would have it on the gui node so you always see it, and it doesn't get clipped, shrink, etc.
You can take the bbox of the character and project the 8 points to screen coordinates, then build a smallest-fitting box for those translated coords and scale the red box to fit.


I could set the Billboard's setDepthTest to false, so it will always be drawn (preventing it from being clipped). Also, I would want it to shrink as the character got farther away, no?

Well you can attach it to the character then it will stick with it as you or it moves. The only thing is the texture on the billboard will get really small and may not be visible the farther away you get. And when close, it could looks pixely (is that a word?).

1 Like
@Sploreg said:
Well you can attach it to the character then it will stick with it as you or it moves. The only thing is the texture on the billboard will get really small and may not be visible the farther away you get. And when close, it could looks pixely (is that a word?).


Hrm, good point... I would like the indicator corners to stay the same size :/ I guess this needs to be done in a complex manner as you describe? :(

It’s not all that complex. You can get the 8 points of the bounding box, so then just go through each one and use cam.getScreenCoordinates() on them. Then go through all the x and y coordinates of those 2d points and find the min and max values. This will give you the screen size of the box you want to draw.

Hey guys,



Getting some weird behavior – for debugging purposes, I set everyone to have targets. I am generally using werulez’s suggestion of a quad pointed at the player.



http://i.imgur.com/hM0Ap.png



Using the translucent bucket (as shown above), it seems only 1 target shows the correct texture – everyone else is solid green. If someone else appears with a target, the previously correct target guy turns solid green and the correct target goes to the newest character. If I use the transparent bucket, I sometimes see multiple correctly textured targets, but they flicker in and out, and often disappear completely.



Here is the code I use to set the targets (FastGeometry is just a Geometry with a custom, faster SetLocalTranslation etc.):



[java]

private FastGeometry Target;

private static Texture targetTex = mainGame.getAssetManager().loadTexture(“Textures/target.png”);

private Material targetMaterial;

public boolean usingTarget;

private ColorRGBA lastTargetColor;

public void SetTargetColor(ColorRGBA clr) {

if( clr == null ) {

if( usingTarget ) Main.myApp.getRootNode().detachChild(Target);

usingTarget = false;

return;

}

if( Target == null ) {

Target = new FastGeometry(World.unitCenterQuad);

targetMaterial = new Material(mainGame.getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);

targetMaterial.getAdditionalRenderState().setDepthTest(false);

targetMaterial.setTexture(“ColorMap”, targetTex);

targetMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

Target.setQueueBucket(Bucket.Transparent);

targetMaterial.getAdditionalRenderState().setDepthWrite(false);

Target.setLocalScale((float)SizeX2, (float)SizeY1.33f, (float)SizeZ*2);

Target.setMaterial(targetMaterial);

}

if( usingTarget == false ) {

Target.setCullHint(CullHint.Always);

Main.myApp.getRootNode().attachChild(Target);

usingTarget = true;

}

if( lastTargetColor == null ||

clr.r != lastTargetColor.r ||

clr.g != lastTargetColor.g ||

clr.b != lastTargetColor.b ||

clr.a != lastTargetColor.a ) {

targetMaterial.setColor(“Color”, clr);

lastTargetColor = clr;

}

}

[/java]



I call this function like SetTargetColor(ColorRGBA.Green);



I position and rotate the target like this:



[java] if( usingTarget ) {

Vector3f myTrans = myNode.getLocalTranslation();

Target.setLocalTranslation(myTrans);

Vector3f pdiff = myTrans.subtract(Main.myWorld.Player.holdNode.getWorldTranslation());

Helpers.FastLookAt(rotator, pdiff);

Target.setLocalRotation(rotator);

Target.setCullHint(CullHint.Dynamic);

}[/java]



(Helpers.FastLookAt is just a faster Quaternion.lookAt)



Any suggestions? :frowning:

Hrm, it appears to be caused by the objects I made in blender and imported over. If I use a “new Quad(…)”, the problem doesn’t happen (but I need the quad to be centered at the center… not on an edge…

Have you tried other blend modes settings? Like BlendMode.AlphaAdditive?

Thanks for the suggestion – turned out that I didn’t create UV coordinates in blender for my centered Quad. Odd behavior, but all fixed!

cool :slight_smile: