I have a non-flat surface that I want to draw a line on top of (following the contour of the surface).
In other words, I have 2D coordinates for the line (x,y), and I want to project the line onto a 3D surface (x,y,z). Does anyone know how I can go about doing this?
There are many ways, depending on what API you are using. There are ways to transform a 2d line to a 3d surface mathematically, but this is usually messy to implement and also usually relatively CPU intensive (better to use the GPU).
Your best bet is probably to render the line to a texture and place that texture on the surface. You might accomplish this with multitexturing or multiple passes and blending.
There might be other ways as well, but render-to-texture is the most flexible AFAIK. Again, it also depends a lot on what API you use, since different techniques work better in different environments.
Thanks a lot for the reply. I am using OpenGl - do you know what is the best way using this API?
Also, is there any other method available besides rendering to a texture that you could point me to? I am unsure how I would do this mathematically, so any help would be appreciated.
Thanks!
Last edited by aninnag; March 30th, 2006 at 02:42 PM.
In OpenGL, the best way is probably to render to a texture. There are different ways to do it, but the easiest is to use glCopyTexImage. Search for that phrase on google and you'll find plenty of detailed tutorials to help you through. glCopyTexImage can unfortunately be rather slow, so if speed is of critical importance you might want to use frame-buffer objects instead (FBO's), but that's a lot more complicated. My advice is to use glCopyTexImage and later switch to FBO's if your application turns out to be too slow.
The mathematical way is probably going to be very messy unless your surface can be expressed as a three-dimensional function, which is probably not the case. If you have, for example, a grid of deformed quads, I'm afraid your problem is a bit tougher than I can give any solid advice on straight away (other than the render to texture solution).
Bookmarks