Archived

This topic is now archived and is closed to further replies.

Cube in a sphere

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

Well, I looke at a model for a skyBox to learn how to do texturing. At first I wasn''t going to use the skyBox in the game. My game is set in space so the bounding area is a sphere. But I was wondering if I could use the same six images and map them onto the sphere. Not quite sure how to go about doing this. For now I do not know if you can have 6 textures on 6 areas of an object. So i will try the following: I guess i will find 8 points in the sphere, thos eof the the cube that can be inscribed in the sphere such that the vertexies all are on the plane of the sphere. so something like: where x are the vertecies touching the sphere. ----*---- ---*-*--- --x---x-- -*-----*- *-------* -*-----*- --x---x-- ---*-*--- ----*---- I figure that if i have the points then i can cull the rest of the sphere and map a single texture to it. so T is where I have mapped a texture and pipe is where I have culled the part not without the texture. I could do six, one for each side of the "cube" formed; --x-|T-- -*--|-T- *---|--T -*--|-T- --x-|T-- My question then is how would i find the texture and vertext coordinates of the x''s in the top graphic;

Share this post


Link to post
Share on other sites
if the sphere is of radius r, the diagonal if of length (2*r). say, cube is of size s (from one vertex to another).

the vector between two opposite points of the cube is (s, s, s)
so the length of the diagonal of the cube is sqrt(s*s + s*s + s*s), so [s * sqrt(3)].

therefore, 2 * r = s * sqrt(3)
=> s = r * 2 / sqrt(3)

say a = s/2 (the hlaf size of the cube)

=> a = r / sqrt(3)

so, the centre of the cube is the centre of the sphere (call it C), and the vertices are C + (+/- a, +/- a, +/- a);

about the skysphere, a skybox should be enough. In space or not

since you have 6 textures for the six faces of the cube, it it straight forward to map the faces onto the cube.

for a sphere, it looks more difficult. I'm not an expert at those things, but to have a sphere that have a (roughly) evenly distributed set of vertices, you can start of with a dodecahedron (like a 20-faced dice), and subdivide the faces into 4 smaller triangles, by joining the midpoints of the edges together.

after a couple of iterations, you should get a very good approximation of a sphere. The trick is to map the original 20 triangles to a texture map, then it's just a matter of linear interpolations along the edges on the texture to map the midpoint vertices.

[edited by - oliii on March 26, 2004 7:34:55 PM]

Share this post


Link to post
Share on other sites