DrawRectProjected and DrawRectFilledProjected

Issue #5 resolved
Former user created an issue

This is a feature request. Would you be willing to implement DrawRectProjected and DrawRectFilledProjected? I suspect it is not only possible but pretty straightforward considering there is already projected versions for circles and lines.

This is for https://github.com/snakelayer/gw2-raid-assist

Thanks for considering!

Comments (11)

  1. Snake Layer

    More specifically, it would take the same parameters as the existing DrawRect* methods, but with an additional rotation input.

  2. hairys

    I'm probably not the best person to ask, haha. I'm, by no means, a DirectX expert. If you, or anyone else, can copy the DrawCircleProjected and make the necessary adjustments, I suggest you submit a PR.

  3. rafzi repo owner

    No time time implement and test, but this should help:

    You would first create a vertexbuffer like vbCircle in EspDraw.cpp:InitEsp() with 5 verticies resembling a quare on the xy plane with edge length 1. It should go around once with the last vertex equal to the first. This way the impementations for non-filled and filled can be made with linestrip and trianglefan like in the circle functions. The clockwise order should not matter, because vertex culling is disabled I believe.

    Then add the proper API functions and add rotation capabilities with these as needed: D3DXMatrixRotationAxis D3DXMatrixRotationQuaternion D3DXMatrixRotationX D3DXMatrixRotationY D3DXMatrixRotationYawPitchRoll D3DXMatrixRotationZ

    To make rectangles you just provide D3DXMAtrixScaling with two different values for x and y scaling.

  4. hairys

    Apparently, ctrl+enter posts a comment...

    void GW2LIB::DrawRectFilledProjected(Vector3 pos, float x, float y, float rot, DWORD color)
    {
        const auto pDrawer = GetMain()->GetDrawer(true);
        if (pDrawer) {
            D3DXMATRIX scale, translate, rotation;
            D3DXMatrixScaling(&scale, x, y, 1);
            D3DXMatrixTranslation(&translate, pos.x, pos.y, pos.z);
            pDrawer->DrawPrimitive(vbRect, nullptr, D3DPT_TRIANGLEFAN, scale*translate, color);
        }
    }
    

    rot would be the rotation angle from ag->GetRot();

    here's the VertexBuffer:

        std::vector<hl::VERTEX_3D_COL> rectVerts = {
            {-1, -1, 0},
            {1, -1, 0},
            {1, 1, 0},
            {-1, 1, 0},
            {-1, -1, 0}
        };
    

    This all works as expected, except for rotation on the origin. Not sure what to do there.

  5. rafzi repo owner

    This depends on how much customization is required for rotation.

    A simple one would be:

    D3DXMatrixRotationZ(&rotation, angle);
    

    The order of matrix multiplications should be:

    scale*rotation*translate
    

    D3DX does matrix multiplication with inverted operators to normal mathematical notation. Means you can apply transformations sequentially: "First scale, then rotate, then translate".

  6. Log in to comment