From f31b0a3361c0c39b9f6f6ee440b93293690bbe02 Mon Sep 17 00:00:00 2001 From: JacobF Date: Wed, 7 Sep 2011 10:56:04 -0400 Subject: Display which tool the player is holding And some simple animation when trying to dig... --- src/game.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index dc3ed2456..86f1939c3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -956,7 +956,10 @@ void the_game( v3f(BS*100, BS*2, BS*100), // Look from v3f(BS*100+1, BS*2, BS*100), // Look to -1 // Camera ID - ); + ); + + // Do this so children rotate accordingly (tool) + camera->bindTargetAndRotation(true); if(camera == NULL) { @@ -972,6 +975,44 @@ void the_game( f32 camera_yaw = 0; // "right/left" f32 camera_pitch = 0; // "up/down" + /* + Tool + */ + + v3f tool_wield_position(0.6, -0.6, 1.0); + v3f tool_wield_rotation(-25, 180, -25); + float tool_wield_animation = 0.0; + scene::IMeshSceneNode *tool_wield; + { + scene::SMesh *mesh = new scene::SMesh(); + scene::IMeshBuffer *buf = new scene::SMeshBuffer(); + video::SColor c(255,255,255,255); + video::S3DVertex vertices[4] = + { + video::S3DVertex(-0.5,0,0, 0,0,0, c, 0,1), + video::S3DVertex(0.5,0,0, 0,0,0, c, 1,1), + video::S3DVertex(0.5,0.5,0, 0,0,0, c, 1,0), + video::S3DVertex(-0.5,0.5,0, 0,0,0, c, 0,0), + }; + u16 indices[] = {0,1,2,2,3,0}; + buf->append(vertices, 4, indices, 6); + // Set 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 to mesh + mesh->addMeshBuffer(buf); + buf->drop(); + + tool_wield = smgr->addMeshSceneNode(mesh, camera); + mesh->drop(); + } + tool_wield->setVisible(false); + tool_wield->setPosition(tool_wield_position); + tool_wield->setRotation(tool_wield_rotation); + + client.setPlayerWield(tool_wield); + /* Clouds */ @@ -1920,6 +1961,7 @@ void the_game( } } + if(input->getRightClicked()) { std::cout<getLeftState()) + // Tool animation loops 0.0 - 1.0 + tool_wield_animation = fmod(tool_wield_animation + dtime * 3.0, 1.0); + else + // Return tool to holding position if not digging + tool_wield_animation /= 1.5; + } // selected_object == NULL input->resetLeftClicked(); @@ -2103,6 +2153,14 @@ void the_game( ); } + /* + Animate tool + */ + { + tool_wield->setRotation(tool_wield_rotation - sin(tool_wield_animation * PI) * 40.0); + tool_wield->setPosition(tool_wield_position - sin(tool_wield_animation * PI) / 3.0); + } + /* Update gui stuff (0ms) -- cgit v1.2.3