Skip to content

Commit 622b097

Browse files
committed
add thickness to line primitive
1 parent 551c5e9 commit 622b097

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

Source/Lua/LuaBindingsPrimitives.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ LuaBindingRegisterFunctionDefinitionForType(PrimitiveLuaBindings, GraphicalPrimi
1111
LuaBindingRegisterFunctionDefinitionForType(PrimitiveLuaBindings, LinePrimitive) {
1212
return luabind::class_<LinePrimitive, GraphicalPrimitive>("LinePrimitive")
1313

14-
.def(luabind::constructor<int, const Vector&, const Vector&, unsigned char>());
14+
.def(luabind::constructor<int, const Vector&, const Vector&, unsigned char>())
15+
.def(luabind::constructor<int, const Vector&, const Vector&, float, unsigned char>());
1516
}
1617

1718
LuaBindingRegisterFunctionDefinitionForType(PrimitiveLuaBindings, ArcPrimitive) {

Source/Managers/PrimitiveMan.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,7 @@ void PrimitiveMan::SchedulePrimitivesForBlendedDrawing(DrawBlendMode blendMode,
7171
}
7272

7373
void PrimitiveMan::DrawLinePrimitive(int player, const Vector& startPos, const Vector& endPos, unsigned char color, int thickness) {
74-
if (thickness > 1) {
75-
Vector dirVector = g_SceneMan.ShortestDistance(startPos, endPos, g_SceneMan.SceneWrapsX()).SetMagnitude(static_cast<float>(thickness - 1) / 2.0F).Perpendicularize();
76-
Vector pointA = startPos + dirVector;
77-
Vector pointB = startPos - dirVector;
78-
Vector pointC = endPos + dirVector;
79-
Vector pointD = endPos - dirVector;
80-
81-
DrawTriangleFillPrimitive(player, pointA, pointB, pointC, color);
82-
DrawTriangleFillPrimitive(player, pointC, pointD, pointB, color);
83-
} else {
84-
SchedulePrimitive(std::make_unique<LinePrimitive>(player, startPos, endPos, color));
85-
}
74+
SchedulePrimitive(std::make_unique<LinePrimitive>(player, startPos, endPos, thickness, color));
8675
}
8776

8877
void PrimitiveMan::DrawArcPrimitive(const Vector& centerPos, float startAngle, float endAngle, int radius, unsigned char color) {

Source/System/GraphicalPrimitive.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ Vector GraphicalPrimitive::WrapCoordinates(Vector targetPos, const Vector& scene
5151
}
5252

5353
void LinePrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
54+
DrawLineV(targetPos + Vector(-30, -30), targetPos + Vector(30,30), {53, 0, 0, 255});
55+
DrawLineV(targetPos + Vector(30, -30), targetPos + Vector(-30,30), {53, 0, 0, 255});
5456
Vector drawStart = WrapCoordinates(targetPos, m_StartPos);
5557
Vector drawEnd = WrapCoordinates(targetPos, m_EndPos);
56-
DrawLine(drawStart.GetFloorIntX(), drawStart.GetFloorIntY(), drawEnd.GetFloorIntX(), drawEnd.GetFloorIntY(), {m_Color, 0, 0, 255});
58+
DrawLineEx(drawStart, drawEnd, m_Thickness, {m_Color, 0, 0, 255});
5759
}
5860

5961
void ArcPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {

Source/System/GraphicalPrimitive.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ namespace RTE {
7777
public:
7878
GraphicalPrimitiveOverrideMethods;
7979

80+
float m_Thickness{1.0f};
81+
8082
/// Constructor method for LinePrimitive object.
8183
/// @param player Player screen to draw this primitive on.
8284
/// @param startPos Start position of the primitive.
@@ -87,6 +89,20 @@ namespace RTE {
8789
m_EndPos = endPos;
8890
m_Color = color;
8991
m_Player = player;
92+
m_Thickness = 1;
93+
}
94+
/// Constructor method for LinePrimitive object.
95+
/// @param player Player screen to draw this primitive on.
96+
/// @param startPos Start position of the primitive.
97+
/// @param end End position of the primitive.
98+
/// @param thickness Thickness of the line.
99+
/// @param color Color to draw this primitive with.
100+
LinePrimitive(int player, const Vector& startPos, const Vector& endPos, float thickness, unsigned char color) {
101+
m_StartPos = startPos;
102+
m_EndPos = endPos;
103+
m_Color = color;
104+
m_Player = player;
105+
m_Thickness = thickness;
90106
}
91107

92108
private:

0 commit comments

Comments
 (0)