Advertisement Jump to content
Sign in to follow this  

Cube to Sphere (Need help) : Update

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

Hey gamedevers, I am currently trying to map a cube to sphere by the method described on unfortunately my maths is kind of dodgy at best and when it is saying using a unit cube from -1 to 1, is it possible to go from say -m_patchSize to m_patchSize or 0 to m_patchSize, i don't quite understand it, m_patchSize is the size of the side of a cube i am drawing. Or do i have to do it from -1 to 1 and scale it later on in the equation? Thanks for any help guys. PS. Sorry here is the code i am using. With this equation X seems to get some correct values, but Y and Z all i get is -1.#INF
Vector3 FractalMesh::SpherizePoint(Vector3 point)
	//Maths refernced from

	float x = point.getX();
	float y = point.getY();
	float z = point.getZ();
	float xPrime, yPrime, zPrime;
	float xp, yp, zp, added;
	float yzp, zxp, xyp;

	//cout << "In X: "  << x << " Y: " << y << " Z: " << z << endl;

	//Mapping the point to a sphere
	//Getting the altered X Y and Z co-ordinates

	xp = (x * x) / 2;
	yp= (y * y) / 2;
	zp = (z * z) / 2;

	yzp = ((y * y) * (z * z)) / 3;
	zxp = ((z * z) * (x * x)) / 3;
	xyp = ((x * x) * (y * y)) / 3;

	xPrime = x * (sqrt(1 - (yp - zp + yzp)));

	yPrime = y * (sqrt(1 - (zp - xp + zxp)));

	zPrime = z * (sqrt( 1 - (xp - yp + xyp)));


	return point;

UPDATE: Now i have the values working now so that it is a plane, but the offset to make it bluge out into a sphere is now my problem, i have tried passing in a radius from -1 to 1, but it doesn't quite work , it gives me a diagonal curve...sort of... [Edited by - Deftoned on August 17, 2008 2:25:15 AM]

Share this post

Link to post
Share on other sites

how I do it is actually very simple, and I did it very quickly once i worked it out. First you need a tesslated cube. Mine is made of 6 vertex grids. How the grids get into cube form does not really matter, although I would reccommend using a numerically accurate method.

Once you have the grid the point on the sphere can be computed in several ways. My algorithm works like this:

For Each Grid
For Each Point On the Grid
Compute The Vector from the Center of the Cube to the Point
normalize the vector into a variable (say norm for example)
set the spherical vertex position to be vpos = norm * sphere_radius;
next point
next grid

this method works fine for me ... in fact I don't even multiply by the sphere radius and
instead use the World Transform Matrix to set the scale when rendering. Hope this helps.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!