All pastes #2053007 Raw Edit

Patch

public text v1 · immutable
#2053007 ·published 2011-05-02 19:52 UTC
rendered paste body
diff -r 37d0955729ce src/CMakeLists.txt
--- a/src/CMakeLists.txt	Sat Apr 30 02:12:32 2011 +0300
+++ b/src/CMakeLists.txt	Mon May 02 21:36:02 2011 +0200
@@ -82,6 +82,7 @@
 set(minetest_SRCS
 	${common_SRCS}
 	clouds.cpp
+	ToolGraphics.cpp
 	clientobject.cpp
 	guiFurnaceMenu.cpp
 	guiMainMenu.cpp
diff -r 37d0955729ce src/ToolGraphics.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ToolGraphics.cpp	Mon May 02 21:36:02 2011 +0200
@@ -0,0 +1,84 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2011 sebastian-ruehl, Sebastian Ruehl <sebastian.ruehl@mni.fh-giessen.de>
+
+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
+(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.
+
+You should have received a copy of the GNU 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 "ToolGraphics.h"
+#include "constants.h"
+#include "debug.h"
+
+ToolGraphics::ToolGraphics(
+		scene::ISceneNode* parent,
+		scene::ISceneManager* mgr,
+		s32 id
+):
+	scene::ISceneNode(parent, mgr, id)
+{
+	dstream<<__FUNCTION_NAME<<std::endl;
+
+	m_material.setFlag(video::EMF_LIGHTING, false);
+	m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
+	m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
+	m_material.setFlag(video::EMF_FOG_ENABLE, false);
+	//m_material.setFlag(video::EMF_ANTI_ALIASING, true);
+	//m_material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
+
+	video::SColor c(128,230,230,255);
+	m_vertices[0] = video::S3DVertex(.1,.1,.8, 0,0,0, c, 0,1);
+	m_vertices[1] = video::S3DVertex(.3,.1,.5, 0,0,0, c, 1,1);
+	m_vertices[2] = video::S3DVertex(.3,-.1,.5, 0,0,0, c, 1,0);
+	m_vertices[3] = video::S3DVertex(.1,-.1,.8, 0,0,0, c, 0,0);
+
+	m_box.reset(m_vertices[0].Pos);
+	for (s32 i=1; i<4; ++i)
+		m_box.addInternalPoint(m_vertices[i].Pos);
+}
+
+ToolGraphics::~ToolGraphics()
+{
+	dstream<<__FUNCTION_NAME<<std::endl;
+}
+
+void ToolGraphics::OnRegisterSceneNode()
+{
+	if(IsVisible)
+	{
+		SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
+		//SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
+	}
+
+	ISceneNode::OnRegisterSceneNode();
+}
+
+void ToolGraphics::render()
+{
+	video::IVideoDriver* driver = SceneManager->getVideoDriver();
+
+	driver->setMaterial(m_material);
+	driver->setTransform(video::ETS_VIEW, AbsoluteTransformation);
+	u16 indices[] = {0,1,2,2,3,0};
+	driver->drawVertexPrimitiveList(m_vertices, 4, indices, 2,
+					video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
+	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
+}
+
+void ToolGraphics::setTool(ToolItem* toolItem)
+{
+	m_toolItem = toolItem;
+	m_material.setTexture(0, m_toolItem->getImage());
+}
diff -r 37d0955729ce src/ToolGraphics.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ToolGraphics.h	Mon May 02 21:36:02 2011 +0200
@@ -0,0 +1,74 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2011 sebastian-ruehl, Sebastian Ruehl <sebastian.ruehl@mni.fh-giessen.de>
+
+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
+(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.
+
+You should have received a copy of the GNU 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.
+*/
+
+#ifndef TOOL_GRAPHICS_HEADER
+#define TOOL_GRAPHICS_HEADER
+
+#include "common_irrlicht.h"
+#include <iostream>
+#include "inventory.h"
+
+class ToolGraphics : public scene::ISceneNode
+{
+public:
+	ToolGraphics(
+			scene::ISceneNode* parent,
+			scene::ISceneManager* mgr,
+			s32 id
+	);
+
+	~ToolGraphics();
+
+	/*
+		ISceneNode methods
+	*/
+
+	virtual void OnRegisterSceneNode();
+
+	virtual void render();
+
+	virtual const core::aabbox3d<f32>& getBoundingBox() const
+	{
+		return m_box;
+	}
+
+	virtual u32 getMaterialCount() const
+	{
+		return 1;
+	}
+
+	virtual video::SMaterial& getMaterial(u32 i)
+	{
+		return m_material;
+	}
+
+	/*
+		Other stuff
+	*/
+	void setTool(ToolItem* toolItem);
+
+private:
+	core::aabbox3d<f32> m_box;
+	video::S3DVertex m_vertices[4];
+	video::SMaterial m_material;
+	ToolItem* m_toolItem;
+};
+
+#endif
diff -r 37d0955729ce src/game.cpp
--- a/src/game.cpp	Sat Apr 30 02:12:32 2011 +0300
+++ b/src/game.cpp	Mon May 02 21:36:02 2011 +0200
@@ -28,6 +28,7 @@
 #include "materials.h"
 #include "config.h"
 #include "clouds.h"
+#include "ToolGraphics.h"
 
 /*
 	Setting this to 1 enables a special camera mode that forces
@@ -799,6 +800,11 @@
 			cloud_height, time(0));
 
 	/*
+	 * The Tool on the Screen
+	 */
+	ToolGraphics *toolGrahpics = new ToolGraphics(smgr->getRootSceneNode(), smgr, -1);
+
+	/*
 		Move into game
 	*/
 	
@@ -1533,6 +1539,7 @@
 						{
 							ToolItem *titem = (ToolItem*)item;
 							toolname = titem->getToolName();
+							toolGrahpics->setTool(titem);
 						}
 					}