Jump to content
  • Advertisement


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


Texture Mapping Functions - S.O.S

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

Hello everybody. I have the following problem: Given a wrl object, I must define a function like the following in order to texturize the object : void Planar_Mapping(float size,float x,float y,float z,float v1[3],float v2[3]) { float u,t; u=x*v1[0]+y*v1[1]+z*v1[2]; t=x*v2[0]+y*v2[1]+z*v2[2]; glTexCoord2f(u/size,t/size); } void Mapping_Function(float x,float y,float z,int plane) { float vx[3],vy[3],vz[3]; vx[0]=1; vx[1]=0; vx[2]=0; vy[0]=0; vy[1]=1; vy[2]=0; vz[0]=0; vz[1]=0; vz[2]=1; switch (plane) { case 0: Planar_Mapping(100,x,y,z,vx,vy);break; case 1: Planar_Mapping(100,x,y,z,vy,vz);break; case 2: Planar_Mapping(100,x,y,z,vx,vz);break; } glVertex3f(x,y,z); } The above functions implement the box mapping. This works fine in my project but I must also implement spherical, cylindrical and shrink mapping the same way... Can anyone help me? I''m desperate because I''m a graphics rookie! Thanks anyway!

Share this post

Link to post
Share on other sites
Here's some pseudocode for sphere mapping:

UTile, VTile = How many times the texture should tile along the respective axis. These are floats.
Centre, NormalOffset, Vertices are all Vectors with (X, Y, Z) components.

// Calculate centre point of the object you're applying the

// texture map to. I use the midpoint of the bounding box's

// diagonal for this. Midpoint is calculated as ((A + B) / 2)

Centre = MidPoint(BoundBox.Min, BoundBox.Max);

// Now go through all the vertices in your object and assign

// their texture coordinates

for (int i = 0; i < NumVertices; i++)
// Calculate a normal offset for the current point and its

// relation to the object's centre.

NormalOffset = Normalize(Vertices[i] - Centre);

// Now the fun stuff - the texture map coordinates

TexU = (Asin(NormalOffset.X) / PI + 0.5) * UTile;
TexV = (Asin(NormalOffset.Y) / PI + 0.5) * VTile;

// Now you decide what to do with TexU and TexV.


Asin is an arcsin or inverse sin function.

Cylindrical mapping is implemented the same way, except your TexV coordinate (or TexU, depending on what you want) is calculated using a planar function, which you already know.

I don't know how to do the shrink mapping.

Hope that helps

[edited by - Tri on November 5, 2002 6:59:07 PM]

Share this post

Link to post
Share on other sites

  • 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!