]> git.tdb.fi Git - libs/gl.git/commitdiff
Rename CUT to CROP in GeometryBuilder
authorMikko Rasa <tdb@tdb.fi>
Sun, 6 Mar 2011 01:01:00 +0000 (01:01 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 6 Mar 2011 01:01:00 +0000 (01:01 +0000)
Fix capsule texture coordinates
Use adjust_texture_scale in capsule and box builders

source/box.cpp
source/capsule.cpp
source/geometrybuilder.cpp
source/geometrybuilder.h

index 21d5f33f984ebfbbcb0411b3dcfa0148c3fe38c3..5347ccc7da411c847d0c5df13ce4cd27984fbde3 100644 (file)
@@ -55,13 +55,7 @@ void BoxBuilder::build_face(PrimitiveBuilder &builder, const Vector3 &o, const V
 
        float u_size = 1;
        float v_size = 1;
-       if(tex_fit!=STRETCH)
-       {
-               if((l1<l2)==(tex_fit==CUT))
-                       u_size = l1/l2;
-               else
-                       v_size = l2/l1;
-       }
+       adjust_texture_scale(u_size, v_size, l1, l2);
 
        builder.begin(TRIANGLE_STRIP);
        builder.texcoord(0, v_size);
index e4c93ae78bdbd43c85426b21048d264551867645..9ea19326c7075cde8468097f3c6cdfd942a0e116 100644 (file)
@@ -31,15 +31,7 @@ void CapsuleBuilder::build(PrimitiveBuilder &builder) const
 {
        float u_scale = 1.0/segments;
        float v_scale = 1/(length+radius*M_PI);
-       if(tex_fit!=STRETCH)
-       {
-               float l1 = radius*M_PI*2;
-               float l2 = length+radius*M_PI;
-               if((l1<l2)==(tex_fit==CUT))
-                       u_scale *= l1/l2;
-               else
-                       v_scale *= l2/l1;
-       }
+       adjust_texture_scale(u_scale, v_scale, radius*M_PI*2, length+radius*M_PI);
 
        builder.normal(0, 0, -1);
        builder.texcoord(0.5, 0);
@@ -47,7 +39,7 @@ void CapsuleBuilder::build(PrimitiveBuilder &builder) const
        for(unsigned i=1; i<rings; ++i)
        {
                float cz = length*(i>rings/2 ? 0.5 : -0.5);
-               float v = (i*radius*M_PI/rings+(i>rings/2 ? length : 0))*v_scale;
+               float v = ((i>rings/2 ? i-1 : i)*radius*M_PI/(rings-1)+(i>rings/2 ? length : 0))*v_scale;
                float ra = (i>rings/2 ? i-1 : i)*M_PI/(rings-1);
                float rc = cos(ra);
                float rs = sin(ra);
index 018ea44718d880f2d4c18d99ebe95adf8f120e55..6ed52ed2e85244f470efd495c3ace6cd719f1024 100644 (file)
@@ -39,7 +39,7 @@ void GeometryBuilder::adjust_texture_scale(float &u_scale, float &v_scale, float
 {
        if(tex_fit!=STRETCH)
        {
-               if((width<height)==(tex_fit==CUT))
+               if((width<height)==(tex_fit==CROP))
                        u_scale *= width/height;
                else
                        v_scale *= height/width;
index 2e5a79faa06096c6ca6a129409b1df4909eb11b9..e1c877dfbc5fd06f76abbc4103362bf3fb079ca6 100644 (file)
@@ -20,7 +20,7 @@ public:
        enum TextureFit
        {
                STRETCH,
-               CUT,
+               CROP,
                WRAP
        };