Jump to content
  • Advertisement
Sign in to follow this  
Narf the Mouse

OpenGL Complete Geosphere

This topic is 2225 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

I've managed to cobble up a Geosphere creation algorithm, mostly from the OpenGL Programming Guide.

And it looks like this link wil give me the UV coordinates. However, from the sounds of it, it could be improved.

Google says maybe a cubemap might be best for geosphere/icosahedron texturing. Not quite sure how to apply a cubemap. Could hack it out on a cube pretty easy, but a geosphere? Lost. If anyone's got a ready tutorial, it would be appreciated. smile.png

And, indexing an icosahedron. Need to know how to automatically generate indices for a subdivided icosahedron - Or maybe just for a triangle subdivided in four.


float X = 0.525731112119133606F ;
float Z = 0.850650808352039932F ;
Vector3F vp ;
vertices = new Vertex[ 12 ] {
new Vertex( vp = new Vector3F( -X, 0, Z ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( X, 0, Z ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( -X, 0, -Z ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( X, 0, -Z ), vp, Vector2F.Zero ),

new Vertex( vp = new Vector3F( 0, Z, X ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( 0, Z, -X ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( 0, -Z, X ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( 0, -Z, -Z ), vp, Vector2F.Zero ),

new Vertex( vp = new Vector3F( Z, X, 0 ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( -Z, X, 0 ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( Z, -X, 0 ), vp, Vector2F.Zero ),
new Vertex( vp = new Vector3F( -Z, -X, 0 ), vp, Vector2F.Zero ),
} ;

indices = new short[ 60 ] {
1, 4, 0, 4, 9, 0, 4, 5, 9, 8, 5, 4, 1, 8, 4,
1, 10, 8, 10, 3, 8, 8, 3, 5, 3, 2, 5, 3, 7, 2,
3, 10, 7, 10, 6, 7, 6, 11, 7, 6, 0, 11, 6, 1, 0,
10, 1, 6, 11, 0, 9, 2, 11, 9, 5, 2, 9, 11, 2, 7
} ;

for (int i = 0 ; i < indices.Length ; i += 3 )
{
Vector3F one = Vector3F.Zero, two = Vector3F.Zero, normal ;
for ( int j = 0; j < 3 ; ++j )
{
one[j] =
vertices[ indices[ i + 0 ] ].VertexPosition[ j ] -
vertices[ indices[ i + 1 ] ].VertexPosition[ j ] ;
two[j] =
vertices[ indices[ i + 1 ] ].VertexPosition[ j ] -
vertices[ indices[ i + 2 ] ].VertexPosition[ j ] ;
}
normal = Vector3F.Cross( one.Normalized( ), two.Normalized( ) ) ;

vertices[ indices[ i ] ].VertexNormal = normal ;
}


Thanks.

Share this post


Link to post
Share on other sites
Advertisement
All I have left is figuring out how to calculate the UV coordinates.

Shouldn't be too hard.

Really glad I asked for help, everyone. Love the responses.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!