]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Person.cpp
Moved clothes loop to Person, got rid of globals tintr,tintg,tintb
[lugaru.git] / Source / Person.cpp
index 87aaace9662be97b5b73a8386b343df4087b94bd..330dd40fb9f0e415bd9fe9f58defb676b6ffeb82 100644 (file)
@@ -633,13 +633,6 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
             p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
             p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
             p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
-            /*
-            CrossProduct(p2-p1,p3-p1,&N);
-            CrossProduct(p0-p1,p3-p1,&temp);
-            s =  dotproduct(&temp,&N)/findLength(&N);
-            CrossProduct(p2-p1,p1-p0,&temp);
-            t = dotproduct(&temp,&N)/findLength(&N);
-            r = 1 - (s + t);*/
 
             bary.x = distsq(&p0, &p1);
             bary.y = distsq(&p0, &p2);
@@ -669,9 +662,6 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
             coordsx = skeleton.drawmodel.Triangles[whichtri].gx[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gx[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gx[2] * bary.z;
             coordsy = skeleton.drawmodel.Triangles[whichtri].gy[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gy[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gy[2] * bary.z;
 
-            //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
-            //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
-
             if (bleeding <= 0 && spurt) {
                 spurt = 0;
                 for (int i = 0; i < 3; i++) {
@@ -6543,3 +6533,64 @@ void Person::takeWeapon(int weaponId)
     weaponids[0] = weaponId;
 }
 
+void Person::addClothes()
+{
+    if (numclothes > 0) {
+        for (int i = 0; i < numclothes; i++) {
+            addClothes(i);
+        }
+        DoMipmaps();
+    }
+}
+
+bool Person::addClothes(const int& clothesId)
+{
+    LOGFUNC;
+    const char* fileName = clothes[clothesId];
+
+    GLubyte* array = &skeleton.skinText[0];
+
+    //Load Image
+    ImageRec texture;
+    bool opened = load_image(fileName, texture);
+
+    float alphanum;
+    //Is it valid?
+    if (opened) {
+        float tintr = clothestintr[clothesId];
+        float tintg = clothestintg[clothesId];
+        float tintb = clothestintb[clothesId];
+
+        if (tintr > 1) tintr = 1;
+        if (tintg > 1) tintg = 1;
+        if (tintb > 1) tintb = 1;
+
+        if (tintr < 0) tintr = 0;
+        if (tintg < 0) tintg = 0;
+        if (tintb < 0) tintb = 0;
+
+        int bytesPerPixel = texture.bpp / 8;
+
+        int tempnum = 0;
+        alphanum = 255;
+        for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
+            if (bytesPerPixel == 3)
+                alphanum = 255;
+            else if ((i + 1) % 4 == 0)
+                alphanum = texture.data[i];
+            if ((i + 1) % 4 || bytesPerPixel == 3) {
+                if ((i % 4) == 0)
+                    texture.data[i] *= tintr;
+                if ((i % 4) == 1)
+                    texture.data[i] *= tintg;
+                if ((i % 4) == 2)
+                    texture.data[i] *= tintb;
+                array[tempnum] = (float)array[tempnum] * (1 - alphanum / 255) + (float)texture.data[i] * (alphanum / 255);
+                tempnum++;
+            }
+        }
+        return 1;
+    } else {
+        return 0;
+    }
+}