Hello,
I need to map 3D texture on a cube. I have it mapped on a sphere as follows:
const float da = PI/steps;
const float db = PI/steps;
glBegin(GL_QUADS);
for(float b = -PI/2; b < PI/2; b+=db)
for(float a = 0; a < 2*PI; a+=da){
DrawSphereVertexFunction( a, b, center, radius, tex);
DrawSphereVertexFunction( a, b+db, center,radius,tex);
DrawSphereVertexFunction( a+da, b+db, center,radius,tex);
DrawSphereVertexFunction( a+da, b, center, radius,tex);
};
glEnd();
/**************************************************************************************************************************************/
void DrawSphereVertexFunction(float a, float b, const V3f & where, float radius, Textured * t){
V3f pos(where); V3f n(cos(b)*sin(a),
cos(b)cos(a),
sin(b));
pos += nradius;
if(t){
t->SetTexture(pos);
}else{
//glColor3f(cos(b), cos(b)cos(a), cos(b)cos(a+b));
glColor3f(0.5,0.5,0.5);
};
glNormal3f(1n.x, 1n.y, 1*n.z);
glVertex3f(pos);
};
/***************************************************************************************************************************************/
Could any one help me converting and mapping the function to a cube?
Thank you in advance.