]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mesh.cpp
Add inventory right click drag and drop
[dragonfireclient.git] / src / mesh.cpp
index 1d347a09f7678cc153c786b92fdcebca7096aac6..3200d5fa6c2fd453fc44ab4bc97ca117e563e1f0 100644 (file)
@@ -1,23 +1,26 @@
 /*
-Minetest-c55
-Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #include "mesh.h"
+#include "debug.h"
+#include "log.h"
+#include <iostream>
 #include <IAnimatedMesh.h>
 #include <SAnimatedMesh.h>
 
@@ -73,9 +76,15 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
        {
                scene::IMeshBuffer *buf = new scene::SMeshBuffer();
                buf->append(vertices + 4 * i, 4, indices, 6);
+               // Set default material
+               buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+               buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+               buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+               // Add mesh buffer to mesh
                mesh->addMeshBuffer(buf);
                buf->drop();
        }
+
        scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
        mesh->drop();
        scaleMesh(anim_mesh, scale);  // also recalculates bounding box
@@ -236,6 +245,8 @@ static scene::IAnimatedMesh* extrudeARGB(u32 twidth, u32 theight, u8 *data)
                }
        }
 
+       delete[] solidity;
+
        // Add to mesh
        scene::SMesh *mesh = new scene::SMesh();
        mesh->addMeshBuffer(buf);
@@ -249,7 +260,7 @@ scene::IAnimatedMesh* createExtrudedMesh(video::ITexture *texture,
                video::IVideoDriver *driver, v3f scale)
 {
        scene::IAnimatedMesh *mesh = NULL;
-       core::dimension2d<u32> size = texture->getSize();
+       core::dimension2d<u32> size = texture->getOriginalSize();
        video::ECOLOR_FORMAT format = texture->getColorFormat();
        if (format == video::ECF_A8R8G8B8)
        {
@@ -269,17 +280,25 @@ scene::IAnimatedMesh* createExtrudedMesh(video::ITexture *texture,
 
                // img1 is in the texture's color format, convert to 8-bit ARGB
                video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, size);
-               if (img2 != NULL)
+               if (img2 == NULL)
                {
-                       img1->copyTo(img2);
                        img1->drop();
-
-                       mesh = extrudeARGB(size.Width, size.Height, (u8*) img2->lock());
-                       img2->unlock();
-                       img2->drop();
+                       return NULL;
                }
+
+               img1->copyTo(img2);
                img1->drop();
+               mesh = extrudeARGB(size.Width, size.Height, (u8*) img2->lock());
+               img2->unlock();
+               img2->drop();
        }
+
+       // Set default material
+       mesh->getMeshBuffer(0)->getMaterial().setTexture(0, texture);
+       mesh->getMeshBuffer(0)->getMaterial().setFlag(video::EMF_LIGHTING, false);
+       mesh->getMeshBuffer(0)->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+       mesh->getMeshBuffer(0)->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+
        scaleMesh(mesh, scale);  // also recalculates bounding box
        return mesh;
 }
@@ -313,6 +332,35 @@ void scaleMesh(scene::IMesh *mesh, v3f scale)
        mesh->setBoundingBox(bbox);
 }
 
+void translateMesh(scene::IMesh *mesh, v3f vec)
+{
+       if(mesh == NULL)
+               return;
+
+       core::aabbox3d<f32> bbox;
+       bbox.reset(0,0,0);
+
+       u16 mc = mesh->getMeshBufferCount();
+       for(u16 j=0; j<mc; j++)
+       {
+               scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
+               video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
+               u16 vc = buf->getVertexCount();
+               for(u16 i=0; i<vc; i++)
+               {
+                       vertices[i].Pos += vec;
+               }
+               buf->recalculateBoundingBox();
+
+               // calculate total bounding box
+               if(j == 0)
+                       bbox = buf->getBoundingBox();
+               else
+                       bbox.addInternalBox(buf->getBoundingBox());
+       }
+       mesh->setBoundingBox(bbox);
+}
+
 void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
 {
        if(mesh == NULL)