From 36bcbca9acabbc47976d3d7625ffb1c9396b8fdc Mon Sep 17 00:00:00 2001 From: Kahrl Date: Mon, 19 Sep 2011 03:01:11 +0200 Subject: Added sprite extruder --- src/camera.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'src/camera.h') diff --git a/src/camera.h b/src/camera.h index dd9f30551..08c03dd19 100644 --- a/src/camera.h +++ b/src/camera.h @@ -21,14 +21,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #define CAMERA_HEADER #include "common_irrlicht.h" +#include "inventory.h" #include "utility.h" class LocalPlayer; class MapDrawControl; +class ExtrudedSpriteSceneNode; /* Client camera class, manages the player and camera scene nodes, the viewing distance - and performs view bobbing etc. + and performs view bobbing etc. It also displays the wielded tool in front of the + first-person camera. */ class Camera { @@ -59,6 +62,12 @@ public: return m_cameranode; } + // Get wielded item scene node. + inline ExtrudedSpriteSceneNode* getWieldNode() const + { + return m_wieldnode; + } + // Get the camera position (in absolute scene coordinates). // This has view bobbing applied. inline v3f getPosition() const @@ -107,12 +116,19 @@ public: // Update settings from g_settings void updateSettings(); + // Replace the wielded item mesh + void wield(InventoryItem* item); + + // Start or stop digging animation + void setDigging(bool digging); + private: // Scene manager and nodes scene::ISceneManager* m_smgr; scene::ISceneNode* m_playernode; scene::ISceneNode* m_headnode; scene::ICameraSceneNode* m_cameranode; + ExtrudedSpriteSceneNode* m_wieldnode; // draw control MapDrawControl& m_draw_control; @@ -151,5 +167,51 @@ private: f32 m_view_bobbing_speed; }; -#endif +/* + A scene node that displays a 2D mesh extruded into the third dimension, + to add an illusion of depth. + + Since this class was created to display the wielded tool of the local + player, and only tools and items are rendered like this (but not solid + content like stone and mud, which are shown as cubes), the option to + draw a textured cube instead is provided. + */ +class ExtrudedSpriteSceneNode: public scene::ISceneNode +{ +public: + ExtrudedSpriteSceneNode( + scene::ISceneNode* parent, + scene::ISceneManager* mgr, + s32 id = -1, + const v3f& position = v3f(0,0,0), + const v3f& rotation = v3f(0,0,0), + const v3f& scale = v3f(0,0,0)); + ~ExtrudedSpriteSceneNode(); + + void setSprite(video::ITexture* texture); + void setCube(const TileSpec faces[6]); + + f32 getSpriteThickness() const { return m_thickness; } + void setSpriteThickness(f32 thickness); + + void removeSpriteFromCache(video::ITexture* texture); + + virtual const core::aabbox3d& getBoundingBox() const; + virtual void OnRegisterSceneNode(); + virtual void render(); + +private: + scene::IMeshSceneNode* m_meshnode; + f32 m_thickness; + scene::IMesh* m_cubemesh; + bool m_is_cube; + + // internal extrusion helper methods + io::path getExtrudedName(video::ITexture* texture); + scene::IAnimatedMesh* extrudeARGB(u32 width, u32 height, u8* data); + scene::IAnimatedMesh* extrude(video::ITexture* texture); + scene::IMesh* createCubeMesh(); +}; + +#endif -- cgit v1.2.3