Figure out the offset for each weapon in the editor and just write it down (in an xml or textilfe for example). You can get the start position then by transforming that offset by the absolute transformation matrix of your gun node. For the end-position you have to do a line-collision (with ISceneCollisionManager::getSceneNodeAndCollisionPointFromRay) with the line starting at the offset and then probably going along the current rotation of your player node.
For drawing you have different options. I would probably use a plane (2 triangles) for drawing. But if you want it to look like in the image with the start and end having same width in 2d then there's some additional work. You could for example draw in 2d (ISceneCollisionManager has some functions to get from 3d points to 2d points on the screen). Or you could calculate the necessary width at both points. I did that recently, so maybe helps (it's not 10ß0% correct as I return a single value while width/depth should be separate and not sure if thera are better ways to calculate this):
Code: Select all
// Return how many units are needed at pos to draw a pixel in 2d (return max of width or height as I want to ensure a pixel is visible)
irr::f32 getPixelSizeAtWorldPos(const irr::core::vector3df& pos, const irr::scene::SViewFrustum* frustum, const irr::core::dimension2du& screenDim)
{
using namespace irr;
using namespace core;
using namespace scene;
vector3df nearestPointLeftPlane, nearestPointRightPlane;
frustum->planes[SViewFrustum::VF_LEFT_PLANE].getIntersectionWithLine( pos, frustum->planes[SViewFrustum::VF_LEFT_PLANE].Normal, nearestPointLeftPlane );
frustum->planes[SViewFrustum::VF_RIGHT_PLANE].getIntersectionWithLine( pos, frustum->planes[SViewFrustum::VF_RIGHT_PLANE].Normal, nearestPointRightPlane );
vector3df nearestPointTopPlane, nearestPointBottomPlane;
frustum->planes[SViewFrustum::VF_TOP_PLANE].getIntersectionWithLine( pos, frustum->planes[SViewFrustum::VF_TOP_PLANE].Normal, nearestPointTopPlane );
frustum->planes[SViewFrustum::VF_BOTTOM_PLANE].getIntersectionWithLine( pos, frustum->planes[SViewFrustum::VF_BOTTOM_PLANE].Normal, nearestPointBottomPlane );
// width of frustum at the depth of the point we're interested in
f32 frustumWidthUnits = (nearestPointRightPlane-nearestPointLeftPlane).getLength();
f32 frustumHeightUnits = (nearestPointTopPlane-nearestPointBottomPlane).getLength();
f32 unitsPixelWidth = frustumWidthUnits / (f32)screenDim.Width;
f32 unitsPixelHeight = frustumHeightUnits / (f32)screenDim.Height;
return core::max_(unitsPixelWidth, unitsPixelHeight);
}