DrawRectProjected and DrawRectFilledProjected
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)
-
-
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.
-
- removed responsible
-
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.
-
Here's what I have so far:
-
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.
-
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".
-
Ah, didn't realize order was important. That was it, thanks rafzi.
-
@@snakelayer wish granted: 900d2d1
-
- changed status to resolved
-
Thank you!
- Log in to comment
More specifically, it would take the same parameters as the existing DrawRect* methods, but with an additional rotation input.