Solved

Rendering a functionally defined solid in OpenGL

Posted on 2004-08-06
4
837 Views
Last Modified: 2013-12-06
Me again!

OK, OpenGL is all polygons and vertexes .. no nice smoothies. I have had a look at the docs on gluCylinder, gluDisk etc which seem to be based on  a general quadric (3D quadratic equation) but the implementation of those is probably nasty and somewhere deep in GLUT.

Q1 (an aside). Why only those limited forms of quadric ?? The general form of ax**2+by**2+cZ**2 + eXY+fXZ+gYZ should be capable of producing interesting forms (ellipsoids??)

Q2. This is the general problem. Suppose I have a solid defined by a simple functional form.
For x in -3..+3,
yupper = 1+sin(x), Ylower = 1-cos(x),
z= sqrt(abs(x))

Well, maybe that is not well expressed, but the idea is for a wiggly tube parallel to the x axis, whose cross section in the z direction varies as x.

More generally, I have a function that will return a set of x,y and z values that lie on the surface of the solid. (If it was a sphere, then we would know that x**2+y**2+z**2=C, but let us not assume that knowledge .. suppose we simply have a set of points that we know lie on a surface).

How do I get OpenGL to render this solid?

Am I talking about triangulation here? I came across

http://www.schorsch.com/rayfront/manual/generators.html#triangulate

Is this what I need and want and does OpenGL do it?

Or maybe this has something to do with a mesh .. anyone care to explain exactly what that is and how OpenGL uses it?

The above relates to having a black box function that returns 3D points on the surface of a solid, and I want to know how to render that solid.

If you DO know the mathematics eg tubey at
http://astronomy.swin.edu.au/~pbourke/surfaces/tubey/
which uses
-3 x8 - 3 y8 - 2*z8
+ 5 x4 y2 z2 + 3 x2 y4 z2
- 4 (x3 + y3 + z3 + 1) + (x + y + z + 1)4 + 1 = 0
how then do we go about it?

(I guess knots .. eg http://www.cecm.sfu.ca/~scharein/sepicts/ have mathematical descriptions too).

I had a look at
http://astronomy.swin.edu.au/~pbourke/opengl/superellipsoid/
and that seems to calculate the entire surface using triangle strips, but it is not clear to me that this is a generally applicable method.

Paul Bourke's BLOB
http://astronomy.swin.edu.au/~pbourke/surfaces/blob/blob.pov
has POVRAY code (below), which is short and sweet - is there an OpenGL "equivalent"

Thanks for any enlightenment

#include "metals.inc"

#declare RR = 4;

#switch (clock)
#case (0)
   #declare VP = <-RR,0,0>;
   #break
#case (1)
   #declare VP = <0,-RR,0>;
   #break
#case (2)
   #declare VP = <0,0,-RR>;
   #break
#case (3)
   #declare VP = <-0.7*RR,-0.7*RR,0>;
   #break
#case (4)
   #declare VP = <0,-0.7*RR,-0.7*RR>;
   #break
#case (5)
   #declare VP = <-0.7*RR,0,-0.7*RR>;
   #break
#case (6)
   #declare VP = <-0.7*RR,-0.7*RR,-0.7*RR>;
   #break
#end

camera {
   location VP
   up y
   right x
   angle 60
   sky <0,0,1>
   look_at <0,0,0>
}

light_source {
  <-15,0,0>
  color rgb <1,0.5,0.5>
}
light_source {
  <0,-15,0>
  color rgb <0.5,1.0,0.5>
light_source {
  <0,0,-15>
  color rgb <0.5,0.5,1.0>
}

isosurface {
   function {
      x*x + y*y + z*z + sin(4*x) + sin(4*y) + sin(4*z) - 1
   }
   contained_by {
      sphere { <0,0,0>, 4 }
   }
   threshold 0
   accuracy 0.01
   max_gradient 25
   open
   texture { T_Silver_5C }
}



0
Comment
Question by:Mutley2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
davebytes earned 500 total points
ID: 11743427
OpenGL and other rendering methods don't actually understand functional solids.  It is only through extensions (GLUT, etc.) that add such functionality.  No math, no surfaces, just vertices.

GL and D3D, and frankly the hardware accelerators, work only with vertices and triangles when it comes down to it.  So, you need to generate a triangular mesh for your solid in order to render it using hardware/GL.

So, Yes, you are talking about triangulation of the solid.  There are TONS of triangulators out there, or if you know your procedural definition you can probably write your own pretty easily.  Also, the GLUT source code is all open and available, as are many other similar systems, for you to quickly base off of.

-d
0
 

Author Comment

by:Mutley2003
ID: 11750815
hmm, OK. I would have thought that it is a difficult problem to optimally divide a (functional) solid into triangles. Like a 3D tessellation/ Voronoi/ Dealunay type problem.
I will do some more research, unless anyone has a magic answer <g>

0
 
LVL 17

Expert Comment

by:davebytes
ID: 11755012
There's no 'magic answer', but there is certainly example code ALL over the internet (including the site you noted) that detail different triangulation methods.  http://www.dlc.fi/~dkpa/  is a good site to start as it has a bunch of further links out -- however, it deals more with landscapes.

What you really want to look at are things like bezier-surface triangulators (the 3D Studio Max SDK, which should be free to sign up and download, shows how they do theirs), or other solid dissections.

The basic approach is to iterate over whatever variables you have (say x and y), with a given increment step for each, building vertices along the way (and triangles from the vertices) by plugging the current values into your equation and getting the resulting final reference (z) to make a 3D coordinate.  Obviously, the more complex the surface equation, the more tricky it gets to generate vertices.

Beziers for instance you actually iterate over u/v along the bezier, and from those generate x/y/z locations.  So long as you don't have a horribly complex bezier, or too low an increment/subdivision step, you do pretty well in triangular representation.

-d
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question