Jump to content
  • Advertisement
Sign in to follow this  
dehseth

Spherical Mapping

This topic is 3831 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 guys, I am new in game developing.. I am currently using C++ and DirectX 9 SDK.. I have been reading tutorials till now. I just wanna make a basic sphere (which is easy to do) and map this sphere a rectangular image (in this case earth map). Well I do a lil search and find out that spherical mapping is not that easy. I belive UV transform suits well for my case and I found this UV transform equation which is not working really: tv = acosf(pos.z/radius) / D3DX_PI; if (pos.y >= 0) tu = acosf(pos.x/(radius * sinf(D3DX_PI*(tv)))) / (2* D3DX_PI); else tu = (D3DX_PI + acosf(pos.x/(radius * sinf(D3DX_PI*(tv))))) / (2 * D3DX_PI); I have got a loop surrounding this code, which loop on vertices. Can anybody give me a better solution? A function a new formula to do this transform and show a smooth mapped sphere? Thank you everyone!

Share this post


Link to post
Share on other sites
Advertisement
Perhaps this is an alternative:


grid = new float**[nGrids];
norm = new float**[nGrids];
for (int i=0;i<nGrids;i++){
grid = new float*[nGrids];
norm = new float*[nGrids];
for (int j=0;j<nGrids;j++){
grid[j] = new float[3];
norm[j] = new float[3];
for (int k=0;k<3;k++){
grid[j][k] = 0.0;
norm[j][k] = 0.0;
}
}
}

for (int i=0;i<nGrids;i++){
for (int j=0;j<nGrids;j++){
u = (float)i/(float)(nGrids-1)*2.0*M_PI;
v = (float)j/(float)(nGrids-1)*M_PI;
r = 1.0;

grid[j][0] = r*cos(u)*sin(v);
grid[j][1] = r*sin(u)*sin(v);
grid[j][2] = cos(v);
}
}

for (int i=0;i<nGrids;i++){
grid[0][0] = grid[nGrids-1][0];
grid[0][1] = grid[nGrids-1][1];
grid[0][2] = grid[nGrids-1][2];
}

for (int i=0;i<nGrids-1;i++){
for (int j=0;j<nGrids-1;j++){
v0[0] = grid[j][0] - grid[i+1][j][0];
v0[1] = grid[j][1] - grid[i+1][j][1];
v0[2] = grid[j][2] - grid[i+1][j][2];
v1[0] = grid[i+1][j+1][0] - grid[i+1][j][0];
v1[1] = grid[i+1][j+1][1] - grid[i+1][j][1];
v1[2] = grid[i+1][j+1][2] - grid[i+1][j][2];

//Selfmade functions
X_Cross(v1,v0,n);
X_Normalize(n);

norm[j][0] = -n[0];
norm[j][1] = -n[1];
norm[j][2] = -n[2];
}
}

//OpenGL stuff
listID = glGenLists(1);
glNewList(listID,GL_COMPILE);
for (int i=0;i<nGrids-1;i++){
glBegin(GL_QUAD_STRIP);
for (int j=0;j<nGrids;j++){

s0 = 1.0/(float)nGrids*(float)i;
s1 = 1.0/(float)nGrids*(float)i+1.0/(float)nGrids;
t0 = 1.0/(float)nGrids*(float)j;

glNormal3f(norm [j][0],norm [j][1],norm [j][2]);
glTexCoord2f(s0,t0);
glVertex3f(grid [j][0],grid [j][1],grid [j][2]);
glTexCoord2f(s1,t0);
glVertex3f(grid[i+1][j][0],grid[i+1][j][1],grid[i+1][j][2]);
}
glEnd();
}
glEndList();

delete [] grid;
delete [] norm;
delete [] noise_mat;





Cheers

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.

GameDev.net 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!