Initialising an array of shapes

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Initialising an array of shapes

Commissar
Been looking through the available guides and resources and haven't really found much on drawing an array of objects to a canvas (only people showing how to add single shapes).

I've got that part down, able to successfully render a sphere, however what I am looking for is a way to create a variable number of spheres from an array of objects, creating each sphere with unique initial conditions, and of course being able to update each respective position.

This part has definitely been confusing me, so any help or resources would be greatly appreciated!
Reply | Threaded
Open this post in threaded view
|

Re: Initialising an array of shapes

gouessej
Administrator
Hello

Do you use a scenegraph? Do you use VAO/VBO? Do you use the programmable pipeline?

Maybe this can help:
https://jogamp.org/cgit/jogl-demos.git/tree/src/demos/es2/RawGL2ES2demo.java?id=HEAD
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Initialising an array of shapes

Commissar
Seems I quite underestimated the requirements to setup what I'm looking for, perhaps I should've titled this "Help with JOGL"!

I've relied on Matlab for all my needs with 2D and 3D graphing, JOGL was what I first turned to for a native library to do 3D graphing.

Could I trouble you for some recommendations to where I should direct my attention?
Reply | Threaded
Open this post in threaded view
|

Re: Initialising an array of shapes

gouessej
Administrator
We all have to start somewhere, it's ok. Are you already able to draw your spheres with JOGL? I assume that you understand what a GLEventListener is.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Initialising an array of shapes

Commissar
Yes, that was easy enough thankfully
Reply | Threaded
Open this post in threaded view
|

Re: Initialising an array of shapes

gouessej
Administrator
Ok, then you'll have handle translations to set your spheres at their expected locations. If you use the fixed pipeline, you'll have to understand how the model-view matrix works (glPushMatrix, glPopMatrix, glLoadIdentity, glTranslate), you don't have to modify the vertices when you want to move a sphere, you call glPushMatrix, glTranslate and then glPopMatrix. If you use the programmable pipeline, rather use Xerxes' example I quoted earlier. If you understand the concepts, it will help both with the fixed pipeline and the programmable pipeline. Have you ever read the OpenGL red book?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Initialising an array of shapes

Martin
In reply to this post by Commissar
Hi,

This is something I implemented in Jzy3D. There is a class named DrawableVBO2 that I've used to draw arrays of triangles, spheres etc. The topic is indeed not easy since there are multiple schemes to provide vertices, normals and edges. You could either use Jzy3D to get these OpenGL stuff wrapped into an higher level API or look at my implementation.

You may find interesting to look at TestDrawableVBO2* which shows how to use them.

And as usual, this is demonstrated in Jzy3D's guide.