FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   Making a 3D object face the camera
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Making a 3D object face the camera  (Read 535 times)
narain


Making a 3D object face the camera
« on: May 5th, 2004, 2:59pm »

Okay, I have a 3D scene; I have an arbitrary number of translations, rotations and scalings; and I have a point in 3D where I want to put some text.
 
I also want the text to face the screen, no matter what. It shouldn't be in a fixed direction, because then I'd see it at an angle when I rotate around it. Rather, it should face me no matter where I look at it from, so it looks like 2D text put at the right position.
 
See, for example, http://www.worms3d.com/goodies.html?area=play&play=9. It's a tiny screenshot; you'll have to use your imagination It's just that the red and blue text stays flat facing the camera, wherever you're looking at the scene from.
 
I came up with a few ideas, but after a little thought all of them seemed unworkable.
 
I could get the screen position of the point where I want to place text, but then if I draw there, it'll first get transformed by all those translations and rotations and end up god-knows-where.
 
I could pop off the transform and know I'm drawing at the right location, but then I can't get the transform back unless I keep track of all the translations and rotations, and besides then there's going to be a lot of pushing and popping going on every frame.
 
I could just not use the built-ins and do my own matrix transformations, but that's just overkill.
 
Help!
 
toxi_
Guest
Email
Re: Making a 3D object face the camera
« Reply #1 on: May 5th, 2004, 3:56pm »

what you want is also called "billboards". there're a few docs online, which might help if you're comfortable with matrix math... eg. this one.
 
you could also do something like i've been doing in my base26 app... there i needed the 3d->2d transformed screen coordinates of every node. i needed these coords to show information when the user picked/rolled over a node. so everytime the 3d scene is rendered i'm storing the screen coordinates of each node and check if the mouse is within a certain distance.
 
Code:
//for each node...
push();
translate(xpos,ypos,zpos);
scrX=screenX(0,0,0);
scrY=screenY(0,0,0);
isMouseOver=((abs(mouseX-scrX)+abs(mouseY-scrY))<snapDistance);
pop();

then, after this 1st rendering pass, you revert back to the original transformation matrix, either by using pop() or just by calling resetMatrix() and then draw your text at the previously determined position.
 
hth!
 
narain


Re: Making a 3D object face the camera
« Reply #2 on: May 5th, 2004, 4:20pm »

Ah...
 
So first I do all the transformations and find the screen locations. In the end, after I'm through drawing everything else, I pop out of it and draw the text there.
Ingenious!
 
I think this will work. Thanks a lot!
« Last Edit: May 5th, 2004, 4:21pm by narain »  
toxi_
Guest
Email
Re: Making a 3D object face the camera
« Reply #3 on: May 5th, 2004, 4:29pm »

...and/or use glen murphy's FastText class instead as it does not care about current transformations:
 
http://bodytag.org/fasttext/
 
*btw. the base26 source contains a modified version to also overwrite the Z-buffer where text is...
 
fry


WWW
Re: Making a 3D object face the camera
« Reply #4 on: May 5th, 2004, 5:30pm »

re: fasttext.. more recent versions of processing also have textSpace(SCREEN_SPACE) (versus OBJECT_SPACE) which draws text to the screen the same way. not sure if it's as fast as glen's stuff, but it's there.
 
Pages: 1 

« Previous topic | Next topic »