Discussion:
Draw a 2D Halo
Theo Ribeiro
2010-06-15 03:00:09 UTC
Permalink
Sup all?

I'm creating a multi-touch surface and I wanted to use OSG to draw around my markers. OSG fits perfectly to this use because of it's graph and "hierarchy" based concept.
Now, I wanted to draw a halo-like circle around the objects that will be placed over the table but I don't know how to do this. I thought on loading an image created on Photoshop or something like that, but then I wouldn't be able to mess around with it's colors or animate it.

Can anyone point me out to a tutorial on drawing 2D shapes or if so to a better solution than this one?

Thanks a lot in advance.

Theo

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=28908#28908
Tom Pearce
2010-06-15 03:21:44 UTC
Permalink
Theo,

There should be plenty of resources for learning how to create and manipulate 2D objects - it is fundamentally just like creating 3D objects, only the polygon(s) are all in a plane. You can just create a set of vertices manually to start with. If you've found the examples that deal with 3D shapes, I'd suggest starting there. If you can understand that, you're pretty much there! Maybe start with just creating spheres and see if that helps you understand. Try the plane primitives using example code if you really need more guidance... the billboard example may also give you a sense of how to create some 2D geometry.

Cheers,
Tom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=28909#28909
Theo Ribeiro
2010-06-15 06:07:52 UTC
Permalink
Post by Tom Pearce
Theo,
There should be plenty of resources for learning how to create and manipulate 2D objects - it is fundamentally just like creating 3D objects, only the polygon(s) are all in a plane. You can just create a set of vertices manually to start with. If you've found the examples that deal with 3D shapes, I'd suggest starting there. If you can understand that, you're pretty much there! Maybe start with just creating spheres and see if that helps you understand. Try the plane primitives using example code if you really need more guidance... the billboard example may also give you a sense of how to create some 2D geometry.
Cheers,
Tom
Hi Tom!

Thank you for your reply. I can see now tons of tutorials and examples around on 2D shapes. I guess I was just using the wrong keywords for my searches. Kinda embarassing... sorry about that.

Anyway, I managed to create some 2d objects but I'm still struggling with creating a 2D circle for my halo. I could draw it by adding a lot of points to an array and then drawing using the LINE_LOOP primitive. The only problem is that even though I'm using a simple circle equation (x^2 + y^2 = radius^2) and adding a LOT of points, the circle is still a little squared. Also, I'm worried about the cost of solving the math involved.
Do you think of a better way to draw it?


Again, thank you for your assistance.

Best Regards,

Theo

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=28912#28912
Jason Daly
2010-06-15 06:17:26 UTC
Permalink
Post by Theo Ribeiro
Hi Tom!
Thank you for your reply. I can see now tons of tutorials and examples around on 2D shapes. I guess I was just using the wrong keywords for my searches. Kinda embarassing... sorry about that.
Anyway, I managed to create some 2d objects but I'm still struggling with creating a 2D circle for my halo. I could draw it by adding a lot of points to an array and then drawing using the LINE_LOOP primitive. The only problem is that even though I'm using a simple circle equation (x^2 + y^2 = radius^2) and adding a LOT of points, the circle is still a little squared. Also, I'm worried about the cost of solving the math involved.
Do you think of a better way to draw it?
It's always been hard to draw a nice circle using line segments :-) On
today's graphics cards, though, I wouldn't sweat using even several
hundred vertices for a circle, if you need them. The GPU should still
be able to tear through it pretty quickly.

As far as the math goes, you only need to construct the circle at
startup time. Just create an osg::Geometry containing the vertices and
LINE_LOOP primitive set, and keep it around (using a ref_ptr) until you
need it. You can even attach it in multiple places in the scene graph
if you need more than one halo on the screen at the same time.

--"J"

Continue reading on narkive:
Loading...