Jump to content
  • Advertisement
Sign in to follow this  
keyofrassilon

OpenGL Planetary Ring Geometry

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So far I have this:
float ring_coord[][3] = {0, 0, -62.4, 0, 0, -62.4, 0, 0, -43.09, 0, 0, -43.09,
			12.17, 0, -61.2, 12.17, 0, -61.2, 8.407, 0, -42.26, 8.407, 0, -42.26, 
			23.88, 0, -57.65, 23.88, 0, -57.65, 16.49, 0, -39.81, 16.49, 0, -39.81, 
			34.67, 0, -51.89, 34.67, 0, -51.89, 23.94, 0, -35.83, 23.94, 0, -35.83, 
			44.13, 0, -44.13, 44.13, 0, -44.13, 30.47, 0, -30.47, 30.47, 0, -30.47, 
			51.89, 0, -34.67, 51.89, 0, -34.67, 35.83, 0, -23.94, 35.83, 0, -23.94, 
			57.65, 0, -23.88, 57.65, 0, -23.88, 39.81, 0, -16.49, 39.81, 0, -16.49, 
			61.2, 0, -12.17, 61.2, 0, -12.17, 42.26, 0, -8.407, 42.26, 0, -8.407, 
			62.4, 0, 0, 62.4, 0, 0, 43.09, 0, 0, 43.09, 0, 0, 
			61.2, 0, 12.17, 61.2, 0, 12.17, 42.26, 0, 8.407, 42.26, 0, 8.407, 
			57.65, 0, 23.88, 57.65, 0, 23.88, 39.81, 0, 16.49, 39.81, 0, 16.49, 
			51.89, 0, 34.67, 51.89, 0, 34.67, 35.83, 0, 23.94, 35.83, 0, 23.94, 
			44.13, 0, 44.13, 44.13, 0, 44.13, 30.47, 0, 30.47, 30.47, 0, 30.47, 
			34.67, 0, 51.89, 34.67, 0, 51.89, 23.94, 0, 35.83, 23.94, 0, 35.83, 
			23.88, 0, 57.65, 23.88, 0, 57.65, 16.49, 0, 39.81, 16.49, 0, 39.81, 
			12.17, 0, 61.2, 12.17, 0, 61.2, 8.407, 0, 42.26, 8.407, 0, 42.26, 
			0, 0, 62.4, 0, 0, 62.4, 0, 0, 43.09, 0, 0, 43.09, 
			-12.17, 0, 61.2, -12.17, 0, 61.2, -8.407, 0, 42.26, -8.407, 0, 42.26, 
			-23.88, 0, 57.65, -23.88, 0, 57.65, -16.49, 0, 39.81, -16.49, 0, 39.81, 
			-34.67, 0, 51.89, -34.67, 0, 51.89, -23.94, 0, 35.83, -23.94, 0, 35.83, 
			-44.13, 0, 44.13, -44.13, 0, 44.13, -30.47, 0, 30.47, -30.47, 0, 30.47, 
			-51.89, 0, 34.67, -51.89, 0, 34.67, -35.83, 0, 23.94, -35.83, 0, 23.94, 
			-57.65, 0, 23.88, -57.65, 0, 23.88, -39.81, 0, 16.49, -39.81, 0, 16.49, 
			-61.2, 0, 12.17, -61.2, 0, 12.17, -42.26, 0, 8.407, -42.26, 0, 8.407, 
			-62.4, 0, 0, -62.4, 0, 0, -43.09, 0, 0, -43.09, 0, 0, 
          -61.2, 0, -12.17, -61.2, 0, -12.17, -42.26, 0, -8.407, -42.26, 0, -8.407, 
          -57.65, 0, -23.88, -57.65, 0, -23.88, -39.81, 0, -16.49, -39.81, 0, -16.49, 
		  -51.89, 0, -34.67, -51.89, 0, -34.67, -35.83, 0, -23.94, -35.83, 0, -23.94, 
		  -44.13, 0, -44.13, -44.13, 0, -44.13, -30.47, 0, -30.47, -30.47, 0, -30.47, 
          -34.67, 0, -51.89, -34.67, 0, -51.89, -23.94, 0, -35.83, -23.94, 0, -35.83, 
		  -23.88, 0, -57.65, -23.88, 0, -57.65, -16.49, 0, -39.81, -16.49, 0, -39.81, 
		  -12.17, 0, -61.2, -12.17, 0, -61.2, -8.407, 0, -42.26, -8.407, 0, -42.26};

void ring(double x, double y, double z) {
	int i;
	Vector3f n;
	Vector3f vec[4];

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	
	gl_BindMaterial2D( white_mat, NO_BLEND);
	gl_AmbientColor( white_mat );
	gl_DiffuseColor( white_mat );
	gl_SpecularColor( white_mat );
	gl_EmissiveColor( white_mat );
	gl_Shine( 0.0 );

	glPushMatrix();
	glTranslated(x,y,z);
	glBegin( GL_QUADS );
	for(i=0; i<8; i+=4) {
		vec[0].x = ring_coord[0];
		vec[0].y = ring_coord[1];
		vec[0].z = ring_coord[2];

		vec[1].x = ring_coord[i+1][0];
		vec[1].y = ring_coord[i+1][1];
		vec[1].z = ring_coord[i+1][2];

		vec[2].x = ring_coord[i+2][0];
		vec[2].y = ring_coord[i+2][1];
		vec[2].z = ring_coord[i+2][2];

		vec[3].x = ring_coord[i+3][0];
		vec[3].y = ring_coord[i+3][1];
		vec[3].z = ring_coord[i+3][2];

		n = makeNormalCoord(vec[0],vec[1],vec[2]);
		glNormal3f(n.x, n.y, n.z);
		glVertex3f(vec[0].x,vec[0].y,vec[0].z);
		glVertex3f(vec[1].x,vec[1].y,vec[1].z);
		glVertex3f(vec[2].x,vec[2].y,vec[2].z);
		glVertex3f(vec[3].x,vec[3].y,vec[3].z);
	}
	glEnd();
	glPopMatrix();
	//glFlush();
	glEnable(GL_LIGHTING);
}

I pulled the coordinates out of a WRL file so my guess is thier garbage and incompatable with OpenGL due to the fact nothing draws whatsoever not even a screwed up geometry...so I need to be pointed in the right direction of where I can find SOURCECODE for a ring preferrably one that I can specify how many sides it has like in 3d studio max... btw this was taken from 3d studio's tube shape exported as a wrl file...I grabbed the coordinates from there thinking it would work...

Share this post


Link to post
Share on other sites
Advertisement
If you want planetary rings, a tube shape isn't really the way to go about it. What you want is a series of concentric circles, with increasing radius, made up of the same number of vertices. To generate a circle, just do this:


#define TWOPI 6.28318

void generateRing (Vector3 centre, float radius, int nPoints, Vector3 *points)
{
for (int i = 0; i < nPoints; i ++)
{
points.x = centre.x + sin (i * TWOPI / nPoints) * radius;
points.z = centre.z + cos (i * TWOPI / nPoints) * radius;
points.y = centre.y;
}
}






Then, to draw, something like this:



void drawRings (int nRings, int nRingPoints)
{
Vector3 *inner = new Vector3[nRingPoints];
Vector3 *outer = new Vector3[nRingPoints];
unsigned char innerColour[3], outerColour[3];

glDisable (GL_LIGHTING);
glBegin (GL_QUADS);

float radius = 100.0f;
Vector3 centre (0, 0, 0);

for (int j = 0; j < 3; j ++)
innerColour[j] = rand () & 0xff;

for (int i = 0; i < nRings; i ++)
{
inner = generateRing (centre, radius, nRingPoints);
outer = generateRing (centre, radius + 10.0f, nRingPoints);

for (j = 0; j < 3; j ++)
outerColour = rand () & 0xff;

for (j = 0; j < nRingPoints - 1; j ++)
{
glColor3ubv (innerColour);
glVertex3f (inner[j].x, inner[j].y, inner[j].z);
glVertex3f (inner[j + 1].x, inner[j + 1].y, inner[j + 1].z);
glColour3ubv (outerColour);
glVertex3f (outer[j + 1].x, outer[j + 1].y, outer[j + 1].z);
glVertex3f (outer[j].x, outer[j].y, outer[j].z);
}

glColor3ubv (innerColour);
glVertex3f (inner[nRingPoints - 1].x, inner[nRingPoints - 1].y, inner[nRingPoints - 1].z);
glVertex3f (inner[0].x, inner[0].y, inner[0].z);
glColour3ubv (outerColour);
glVertex3f (outer[0].x, outer[0].y, outer[0].z);
glVertex3f (outer[nRingPoints - 1].x, outer[nRingPoints - 1].y, outer[nRingPoints - 1].z);

radius += 10.0f;
for (j = 0; j < 3; j ++)
innerColour = outerColour;
}
glEnd ();
}







Off my head, so there may be typos.

[Edited by - Ajare on October 8, 2004 4:16:17 PM]

Share this post


Link to post
Share on other sites
i'd make a texture with transparency, and draw a quad.
Or alternatively make 1d texture with colors depending to radius, and then do something like
glBegin(GL_TRIANGLE_STRIP);
for(int n=0;n<256;n++){
gl3f(or*sin(n*2*pi/256.0),or*cos(n*2*pi/256.0),0);
glTexCoord1f(0.0);
glVertex3f(ir*sin(n*2*pi/256.0),ir*cos(n*2*pi/256.0),0);
glTexCoord1f(1.0);
glVertex3f(or*sin(n*2*pi/256.0),or*cos(n*2*pi/256.0),0);
}
glEnd();
where ir it's inner radius, or is outer radius, ring is in xy plane .
(and build that into list for faster redrawing)

Share this post


Link to post
Share on other sites
That's a very easy, and certainly very quick way of doing it, but you'd need a *huge* texture map, considering that this has to be done on a planetary scale.

Share this post


Link to post
Share on other sites
It's all relative. Something on a planetary *scale*. The textures do not have to be huge, but you do have to be clever about how these are portrayed. ie. Viewed from a typical orbital position it would probably perform well and look good, but moving in close could generate fillrate problems. Post a screenie when your done!

Share this post


Link to post
Share on other sites
Quote:
Original post by Ajare
That's a very easy, and certainly very quick way of doing it, but you'd need a *huge* texture map, considering that this has to be done on a planetary scale.

0:"big textured quad" != "huge texture size". Texture may have resolution of 1024x1024, and may be be scaled to... say, 180k x 180k lightyears,if you like. (it's size of galaxy)
1 lightyear it's about 9467020800000000m .

1:You can use 1D texture to save mem.

and, as about fillrate, it's in any case can't be worse than filling entire screen once. Even cheap cards such as geForce FX 5200 can fill screen in roundly 0.001 sec .

and2 , if you want it to look good at different scales you need to do it procedurally in PS or do some tricky lod schemes, and i guess OP will not do it now.

Share this post


Link to post
Share on other sites
Whoa i didnt expect all these responses...Thanks!
Yeah I used a simple quad and got past this hurl...then approached another wall...I dumped the WRL crap and moved to another format ASE which I hear is supposed to be real easy to figure out and well it loked easy enough but I suspect I dont know all the little secrets and hidden rules that do not get mentioned in any of the 1000 posts Ive scanned through in these forums...or possibly I overlooked something...dunno...

Anyways I tied to read the vertices from a simple ase as a test and I think either I am reading them wrong or MAX is screwed in exporting them right...

As a test I exported:

*MESH {
*TIMEVALUE 0
*MESH_NUMVERTEX 8
*MESH_NUMFACES 12
*MESH_VERTEX_LIST {
*MESH_VERTEX 0 0.0000 -32.7798 0.0000
*MESH_VERTEX 1 18.5239 -32.7798 0.0000
*MESH_VERTEX 2 0.0000 0.0000 0.0000
*MESH_VERTEX 3 18.5239 0.0000 0.0000
*MESH_VERTEX 4 0.0000 -32.7798 30.0000
*MESH_VERTEX 5 18.5239 -32.7798 30.0000
*MESH_VERTEX 6 0.0000 0.0000 30.0000
*MESH_VERTEX 7 18.5239 0.0000 30.0000
[/xource]

and coverted it to a float as such:

float box[8][3] = {0.0000, -32.7798, 0.0000,
18.5239, -32.7798, 0.0000,
0.0000, 0.0000, 0.0000,
18.5239, 0.0000, 0.0000,
0.0000, -32.7798, 30.0000,
18.5239, -32.7798, 30.0000,
0.0000, 0.0000, 30.0000,
18.5239, 0.0000, 30.0000};



and drew it like so:

void asteroid(float size, double x, double y, double z) {
int i;
Vector3f n;
float vec[10][3];

glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);

gl_BindMaterial2D( white_mat, NO_BLEND);
gl_AmbientColor( white_mat );
gl_DiffuseColor( white_mat );
gl_SpecularColor( white_mat );
gl_EmissiveColor( white_mat );
gl_Shine( 0.0 );

glPushMatrix();
glTranslated(x,y,z);
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, box);
glDrawArrays(GL_QUADS, 0, 8);
glDisableClientState (GL_VERTEX_ARRAY);
glPopMatrix();
//glFlush();
glEnable(GL_LIGHTING);
}



using GL_TRIANGLES or GL_WHATEVER gives me 1000% NOT a box!...I mean wtf this is supposed to me simple right? You read in the data and convert it to a format that OpenGL can read and draw it...If its more complex than that f'it Ill use a library...if its my code then what in the world do I use to properly display the data in an ase file? This gets frustrating when I KNOW it looks simple and it takes me longer than a century to add 2+2...Must be lack of sleep *rolls eyes*

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!