Skip to main content
gamedev.net
🔒 Locked

Spherical texture mapping help

Started by neocron Oct 17, 2000 at 7:30 PM 0 replies 650+ views
Original Post
neocron
neocron
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 );
		}
    
Dave007
Dave007
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.