Sign in to follow this  
Narf the Mouse

OpenGL Complete Geosphere

Recommended Posts

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

And it looks like [url="http://www.gamedev.net/topic/116312-request-for-help-texture-mapping-a-subdivided-icosahedron/"]this[/url] 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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

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.

[code]
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 ;
}
[/code]

Thanks.

Share this post


Link to post
Share on other sites
I'm not sure but perhaps this help

[url="http://iquilezles.org/www/articles/patchedsphere/patchedsphere.htm"]http://iquilezles.org/www/articles/patchedsphere/patchedsphere.htm[/url]

Share this post


Link to post
Share on other sites
[quote name='pabloreda' timestamp='1339726864' post='4949397']
I'm not sure but perhaps this help

[url="http://iquilezles.org/www/articles/patchedsphere/patchedsphere.htm"]http://iquilezles.or...tchedsphere.htm[/url]
[/quote]
Sorry, that's not a geosphere. But I think I've got it pretty well worked out. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this