Drawing a Spherical Mesh
|
01-20-2014, 08:07 PM
(This post was last modified: 01-20-2014 08:11 PM by jgreenb2.)
Post: #1
|
|||
|
|||
Drawing a Spherical Mesh
Wondering if any of you who are graphics whizzes on the Prime know how to implement a spherical mesh generator?
I tried to make a PPL version of the classical icosahedron mesh but the depth of recursion appears to flummox the prime. Here's the original OpenGL/C version that can be found in the redbook and other places: Code: // I'm assuming that the glNormal3fv calls can be converted to TRIANGLE calls on the Prime (although shading doesn't appear to be supported). But the program never gets that far -- it hangs somewhere in the drawtri recursion for values of "div" > 2 or 3. Converted to PPL the equivalent of the above code would be Code:
It seems likely that I've botched the TRIANGLE command since I've never used it but, again, things seem to go bad before that point. BTW, the above is only a fragment. If you want to try it you'll need to embed it in a more complete program like Han's Graph3D. Suggestions welcome. Or is this just beyond what we can expect the Prime to do at this point? |
|||
01-20-2014, 09:47 PM
Post: #2
|
|||
|
|||
RE: Drawing a Spherical Mesh
You can always insert a debug() statement into your program to determine if the HP Prime fails after a certain number of recursions.
Code: if div<4 then debug(); end; You can also insert a debug() statement right after the triangle command and then abort the program. Then, at the command line, type: Code: blit_p(G0,G1); freeze; This will allow you to see if your code is drawing each triangle like you want. You can even skip debugging and just put: Code: blit_p(G0,G1); WAIT(-1); to see it draw each individual triangle (press a key to continue). Graph 3D | QPI | SolveSys |
|||
01-20-2014, 09:58 PM
(This post was last modified: 01-20-2014 10:03 PM by jgreenb2.)
Post: #3
|
|||
|
|||
RE: Drawing a Spherical Mesh
Han,
Thanks. I've actually done most of those things. I'll try some of your other suggestions. However, the drawing isn't the issue (it may not be right) -- the recursion itself seems to get lost after a short while and the program hangs. Given the limited debugging environment on the Prime, I haven't been able to make much more progress. The real questions are these:
Simple tail recursion -- like a factorial -- appear to work without issue. But when div is large the Prime stack appears to lose its place and drawSphere won't terminate. |
|||
01-20-2014, 10:27 PM
(This post was last modified: 01-20-2014 10:31 PM by cyrille de brébisson.)
Post: #4
|
|||
|
|||
RE: Drawing a Spherical Mesh
Hello,
A couple of problems in your code... First, your coordinates are in cartesian coordinates, from -1 to 1... you should use triangle instead of triangle_p. Make sure that you set the xmin/xmax, ymin, ymax to -1, 1, -1, 1 if you want to see something... ndiv=12 correspond to a HUGE number of triangles. put it to 6 or so to get started and debug... it does work with 12, but takes a LOT of time... Code:
If it still does not work, it might be due to confusion on the triangle inputs with the other forms (for full 3D drawing). Since my version of the app is later than the one that you have, I do not remember exactly how it was before... you could try a form along the lines of: triangle(x1, y1, z2, x2, y2, z2, x3, y3, z3, c1, c2, c3); Cyrille |
|||
01-21-2014, 12:15 AM
(This post was last modified: 01-21-2014 12:16 AM by jgreenb2.)
Post: #5
|
|||
|
|||
RE: Drawing a Spherical Mesh
Cyrille,
You're right on both counts...thanks. Also, I realized I wasn't scaling the vertices by the radius -- that didn't help either. The next step is to accumulate all the vertices into a matrix and execute a single TRIANGLE call with a transformation matrix, z-plane and perspective transform. We'll see how that goes BTW...TRIANGLE appears to always fill the triangles(?) I'd like to actually draw a mesh (edges, but no fill). Is this possible? |
|||
01-21-2014, 01:08 AM
Post: #6
|
|||
|
|||
RE: Drawing a Spherical Mesh
Quote:BTW...TRIANGLE appears to always fill the triangles(?) I'd like to actually draw a mesh (edges, but no fill). Is this possible?Draw each vertice using LINE. 3 LINEs for each TRIANGLE if you don't avoid duplicates. Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
01-23-2014, 10:11 PM
Post: #7
|
|||
|
|||
RE: Drawing a Spherical Mesh
Put this instead of your TRIANGLE command
Code: LINE(aa(1),aa(2),bb(1),bb(2),rgb(128+aa(1)*128,128+aa(2)*128,128+aa(3)*128)); I did it because the TRIANCLE make a flat convex thing on screen. MY changed TRIANGLE Code: triangle ({aa(1),aa(2),rgb(128+aa(1)*128,128+aa(2)*128,128+aa(3)*128),aa(3)},{bb(1),bb(2),rgb(128+bb(1)*128,128+bb(2)*128,128+bb(3)*128),bb(3)},{cc(1),cc(2),rgb(128+cc(1)*128,128+cc(2)*128,128+cc(3)*128),cc(3)}); Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)