Ok, this is the place that''s actually the most confusing for me.
1) Does
LargestAxis()
return max(max(v.x, v.y), v.z); where return codes for v.x, v.y and v.z are 0, 1, 2, respectively?
2) What if the normal = (0, -1, 0) in get_plane_vec() and v = (0, 1, 0)? The dot product is then (0, 0, 0) and Normalize() crashes trying to return sqrt(0)! What should I do in that case?
3) Could you possibly elaborate on this bit of code a little:
TVector3f v = TVector3f(1, 0, 0); if(LargestAxis(pNormal) == 0) v = TVector3f(0, 1, 0);
What is v in this case? Why are you presuming it to be (1, 0, 0) and possibly (0, 1, 0), but never (0, 0, 1) ?
Regarding the other piece of code (which is, in fact, placed in a "chronologically" incorrect order - my bad), that''s where I''m calculating the texture coordinates. It seems kind of logical, but is obviously wrong. I''ll try and explain it a little (to the best of my abilities):
//first calculate the distance of the light source to the plane. //This is used to determine whether the light should be //applied to this specific polygon, and if so, how "bright" it needs to be float distance = fabs(p.DistanceToPlane(pSource)); //depending on the distance of the light source from the polygon, //the lighmap is either larger or smaller - calculate the //scale value. When the light source is on the plane, the lighmap //is scaled by 1 float scale = 1.0f / (pRadius + distance * 2.5); //h and v are shorthand for the values calculated in the other //piece of code TVector3f h = p.VecHorizontal; TVector3f v = p.VecVertical; //find the intersection point of the light source on the plane; //the second argument should to be the light''s direction. //I''m not at all sure about the second argument, though... TVector3f pNearest = p.RayIntersection(pSource, p.Normal()); /// ... /// //next we find the nearest vertex to the intersection point TVector3f VerNear = *p.Corners[2] - pNearest; //calculate the texture coords - this I don''t really understand... glTexCoord2f(VecDotProduct(&VerNear, &(h * scale)) + .5f, VecDotProduct(&VerNear, &(v * scale)) + .5f); //draw the vertex glVertex3fv(*p.Corners[2]);
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared