Sign in to follow this  
MARS_999

How to calculate polyhedra in realtime...

Recommended Posts

I would like to start off with a tetrahedron or if there is a simpler shape and morph into a complete sphere shape based on a level the player has attained...

 

Is there some math formula I can use to calculate the shapes in real time to calculate the vertex and normals for each vertex on the shape?

 

or better yet is there a lib out there that has this already that I can use....

 

C++ and OpenGL will be used BTW if that matters...

 

Thanks!

Edited by MARS_999

Share this post


Link to post
Share on other sites

Nah, you can start with a tetrahedron if you want. The algorithm is the same (splt each face into 4 triangles and extrude the points so they lie on the sphere), just the starting mesh is different.

 

EDIT: I see you want to gradually morph into a sphere though, doing a complete iteration in 1 go is going to be way too fast (i.e. it will increase number of faces by a factor of 4 each iteration).

 

You should be able to do that by adding a single new vertex each iteration... pick the midpoint of a random edge (that is currently at the lowest subdivision level, i.e. don't subdivide an already subdivided edge until all edges are subdivided the same amount), triangulate the adjoining faces with the new vertex in them, and extrude that vertex onto the sphere surface. Obviously there is a lot of hand waving and vagueness going on here which will probably be quite tricky to implement ;)

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites

There may be an easier way to do it by building a spring system (start with springs forming a tetrahedron) and add an extra spring in the middle of a random face joined to the face vertices (or edge midpoints), pushing the springs apart so they are as far apart as possible and on the surface of a sphere. Then you could animate it to make it look like a nice smooth morph.

 

I'm not too good at physics stuff though...

Share this post


Link to post
Share on other sites

Have a look at this, I think it is what you want!  Basically I make a tetrahedron of tiles and then split each one along the longest side and project the new corners onto the surface of the shape (in this case a sphere, but it could be anything).  The algorithm stops when the side length of the triangles gets less than a pre-defined setting.  The meat of it is in SplitTile and SearchforSurface (these work on the body object to tell it what its new tiles are). I then inflate the sphere to get the bouncing effect, but you wouldn't do this so you don't need to worry about what happens next.

 

I am looking for work so if anyone sees this and likes it, give me a shout.  I am a native English speaking database person in real life.  Farting round with games and physics is for fun. From poking around on here it seems like a heartbreaking way to make a living! accounts@moonsch.com

 

Steal away, all my work apart from the bits I have acknowledged, please acknowledge me in return.

 

www.moonsch.com/games/nonrigid/nonrigid.htm

Share this post


Link to post
Share on other sites

Personally, I'd just make five levels, corresponding to the five Platonic solids.  It's kind of cool that there are only five; to me, it seems to lend them additional importance.

 

I like the subdivision stuff too, but my (totally subjective / aesthetic) opinion is that it's more useful for approximating spheres.

Share this post


Link to post
Share on other sites

Personally, I'd just make five levels, corresponding to the five Platonic solids.  It's kind of cool that there are only five; to me, it seems to lend them additional importance.

 

I like the subdivision stuff too, but my (totally subjective / aesthetic) opinion is that it's more useful for approximating spheres.

 but I need to move from a lower level basic shape like a triangle 3 sides to infinite amount....

Share this post


Link to post
Share on other sites

Had another think about this.

 

Forget about infinite numbers of vertices, unless the doodah is gigantinormous on screen it's going to just look like a sphere after you reach a certain number of verts, so pick a maximum number first (64 sounds like a good amount for starters).

 

Then I'd do it with morphs, i.e. create your 64 vertex sphere model and morph it down to a tetrahedron (also with 64 vertices, however they all occupy one of the same 4 points). Just pick 2 adjacent distinct vertices and collapse them to the same point (this is easy to animate as well), then use some algorithm to try and make the distinct points as far away as possible from each other on the surface of a sphere. It's easy to morph models with the same number of vertices, it's just a linear interpolation of the 2 meshes (meshes must have the same indices).

 

You may wish to play around with a 3d modelling program to produce your intermediate shapes and just bake in the morph targets, I feel that would be better than just collapsing random vertices.

 

My only niggling concern with this method is if it produces non-planar polygons as faces. You may be better off using a wireframe representation if that is the case.

 

Well that's my 3rd suggestion and the one I like best.

 

EDIT: actually you may be better with 48 or 96 vertices as a starting amount since you can make a sphere with that number of vertices by subdiving the faces of an icosahedron (since an icosahedron has 12 verts, and each subdivision doubles the number of vertices).

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites

The internet is slow here so I won't post any links, cause I do any searches... It's annoying being out of country. Anyways, from a technical standpoint..., you can create a sphere using n points if you look for "distributing points on a sphere" - there seems to be a formula based on minimizing electrostatic repulsion which looks pretty good. Then you can convert those points to a mesh using a triangulation purposes.

 

This is probably way overkill for any practical purposes - but just for you to know for intellectual purposes. =)

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