Advertisement

splitting polygons - colours and texture corrdinates

Started by June 20, 2003 10:42 AM
1 comment, last by Hybrid666 21 years, 8 months ago
hi, iv managed to get together a function to split a convex polygon, but im having trouble calculating the new colours and texture coordinates for the new points, any ideas? the code i currently have is: //compute intersection point of line //from ptA to ptB with the partition. VECTOR3D v = ptB - ptA; double sect = - partition.distance(ptA) / (partition.normal().dotProduct(v)); VERTEX3D add(ptA.x + (v.x * sect), ptA.y + (v.y * sect), ptA.z + (v.z * sect)); //set the colour add.colour4ub((ptB.r * sect) + (ptA.r * (1-sect)), (ptB.g * sect) + (ptA.g * (1-sect)), (ptB.b * sect) + (ptA.b * (1-sect)), (ptB.a * sect) + (ptA.a * (1-sect))); //set texture coords add.coords((ptB.u * sect) + (ptA.u * (1-sect)), (ptB.v * sect) + (ptA.v * (1-sect))); **PLANE3D::distance(VERTEX3D &) returns the distance a point is from the plane** **the calculations for the new VERTEX3D work fine, iv tested this and it''s all good, its just the colours and the tex coords.. that code so nearly works, its painful, but the texture moves a little bit, depending on where the split occurs, also im about 50% sure that the colour calculations are right, cos visually they seem to work, but would be grateful for a second opinion, thanks in advance, hybrid :D
cmon people! help!

its just a case of calculating the new coordinate/colour based on the values of the two points on the line being tested (ptA -> ptB) and calculate the new value based on how far along the line the intersection occurs... which is ''sect'' no?
Advertisement
Your code looks fine, if you say the positional and colour interpolation is working, I see no reason why the texturing shouldn''t. Perhaps it''s to do with the drawing code rather than this clipping code?

This topic is closed to new replies.

Advertisement