About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
Text behind objects
Author Message
Brainache Offline
Member

Post: #1
Text behind objects
Heyas...

When using the various 2D drawing funcions and D.Text, how can you have them use z-order to prevent drawing while behind objects?

example: drawing a name of a chr... and if the chr is behind a building.. dont draw the name ( or only part of the name that is visible )...

Thanks!
11-08-2011 01:12 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Text behind objects
Code:
D.textDepth(true, depth);
D.text(..);
11-08-2011 09:12 PM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #3
RE: Text behind objects
Driklyn, quick question, what value do you give depth? I'm curious if this is a better way than casting a ray against the object.

www.thinkplaystudios.com
11-09-2011 12:58 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #4
RE: Text behind objects
Never used it before, so I just tested it out real quickly. Assuming you're doing a RPG with a third-person camera, seems like Cam.dist is what you would want to use.

Or, to be more accurate since Cam.dist is the distance to Cam.at, not the distance to the text's position, you could do this:

Code:
Vec  textPos = ..; // desired position of text
Vec2 screen;

if (PosToScreen(textPos, screen))
{
   D.textDepth(true, Dist(Cam.matrix.pos, textPos));
   D.text(screen, "Hello world!");
   D.textDepth(false);
}

Setting the depth to 1 means that any mesh closer than 1 unit away will block the text. Depth is essentially the distance from the camera to the text position.
11-09-2011 04:16 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #5
RE: Text behind objects
Ok just tested this and this doesn't work as well as using a ray test to the model. There are times when the text still shows when it should be occluded because the body is already occluded (and it isn't consistent).

Thanks for your input.

www.thinkplaystudios.com
11-09-2011 05:10 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply