Spherical texture mapping help

Started by
0 comments, last by neocron 23 years, 6 months ago
Hi, So I''m trying to manually map a 64x64 texture onto an arbitrary shape using spherical mapping. (Not using OGL/DX) I''m converting the unit normals (x,y,z) of each vertex in the shape to polar coordinates (1.0,phi,theta). I''m then trying to map phi and theta back into the texture. Unfortunately I can''t seem to get it right. Can anyone help?? Thanks, Karen Here''s some bad code I wrote:
    
		for( int ix=0; ix<m_nPoints; ix++ )
		{
			// Convert to polar coordinates (1.0, phi, theta)
			phi = atan2( m_rgNormal[ix].x, m_rgNormal[ix].z ) + M_PI; // Range 0..2PI


			double dist = sqrt( m_rgNormal[ix].x*m_rgNormal[ix].x + m_rgNormal[ix].z*m_rgNormal[ix].z);
			theta = atan2( m_rgNormal[ix].y, dist );

			// Now convert to u,v
			u = 64 * (phi/(2*M_PI));
			v = 64 * (theta/M_PI);

			// Set the texture coord at that point...

			m_rgTextureCoords[ix].Set( u, v );
		}
    
Advertisement
here is example using spherical texture mapping:

http://www.dev-gallery.com/programming/opengl/index.htm

Dave007
dave007@volny.cz
--------Dave[ Math Studio ] A Computer Algebra System

This topic is closed to new replies.

Advertisement