Skip to content

Commit

Permalink
Merge pull request #136 from godardma/master
Browse files Browse the repository at this point in the history
vehicles : correcting scaling bug and added binding for python API
  • Loading branch information
SimonRohou authored Nov 6, 2024
2 parents a32e570 + 862f215 commit 54ce334
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client-api/python/vibes/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

vibes.drawPolygon([[1,1], [1,4], [5,2], [5, 1]])
vibes.setFigureProperties({'viewbox':'equal'})
vibes.drawAUV(5,3, 1, 2, color='blue[yellow]',name='auv1',LineStyle="..",LineWidth="0.3")
vibes.drawAUV(5,3,1,2, color='blue[yellow]',name='auv1',LineStyle="..",LineWidth="0.3")
vibes.drawBox(2,4,4,7,color='red[yellow]', figure='test', name='box1',LineStyle="-..",LineWidth="0.1")
vibes.drawArrow((0,0), (1,1), 0.1, color='[b]', name='arrow1')

Expand Down
20 changes: 20 additions & 0 deletions client-api/python/vibes/vibes.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,26 @@ def drawAUV(cls, cx, cy, oritentation, length, color='r', **kwargs):
}
cls._write(msg, **kwargs)

@classmethod
def drawTank(cls, cx, cy, oritentation, length, color='r', **kwargs):
"""Draw a tank centered at (cx, cy) with heading <heading> and size length
Args:
cx,cy (double): position of the tank
heading (double): heading of the vehicle in degree
lenght (double): length of the vehicle
"""
msg = {'action': 'draw',
'shape': {'type': 'vehicle_tank',
'center': [cx, cy],
'length': length,
'orientation': oritentation,
'format': color
}
}
cls._write(msg, **kwargs)

@classmethod
def drawPie(cls, center, rho, theta, color='r', use_radian=False, **kwargs):
"""Draw a Pie centered at <center> with raduis in <rho> and angle in <theta>
Expand Down
30 changes: 15 additions & 15 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,9 @@ bool VibesGraphicsVehicle::computeProjection(int dimX, int dimY)

// Set polygon shape
QPolygonF polygon;
polygon << QPointF(-1. * length, 1. * length) + centerPoint;
polygon << QPointF(+3. * length, 0. * length) + centerPoint;
polygon << QPointF(-1. * length, -1. * length) + centerPoint;
polygon << QPointF(-1., 1.) + centerPoint;
polygon << QPointF(+3., 0.) + centerPoint;
polygon << QPointF(-1., -1.) + centerPoint;


// Draw with the new properties
Expand Down Expand Up @@ -1147,24 +1147,24 @@ bool VibesGraphicsVehicleAUV::computeProjection(int dimX, int dimY)
graphics_polygon->setBrush(brush);
graphics_polygon->setTransformOriginPoint(centerPoint);
graphics_polygon->setRotation(orientation);
graphics_polygon->setScale(length / 7.); // initial vehicle's length is 4
graphics_polygon->setScale(length / 7.); // initial vehicle's length is 7
}
}
// Else draw the shape for the first time
else{
// Set body shape
{
QPolygonF body;
body << QPointF(-4. * length, 0. * length) + centerPoint;
body << QPointF(-2. * length, 1. * length) + centerPoint;
body << QPointF(2. * length, 1. * length) + centerPoint;
body << QPointF(-4., 0.) + centerPoint;
body << QPointF(-2., 1.) + centerPoint;
body << QPointF(2., 1.) + centerPoint;

for (float i = 90.; i > -90.; i -= 10.) // noise
body << QPointF((cos(i * M_PI / 180.0) + 2.) * length,
(sin(i * M_PI / 180.0) + 0.) * length) + centerPoint;
body << QPointF((cos(i * M_PI / 180.0) + 2.),
(sin(i * M_PI / 180.0) + 0.)) + centerPoint;

body << QPointF(2. * length, -1. * length) + centerPoint;
body << QPointF(-2. * length, -1. * length) + centerPoint;
body << QPointF(2., -1.) + centerPoint;
body << QPointF(-2., -1.) + centerPoint;


// Draw with the new properties
Expand All @@ -1181,10 +1181,10 @@ bool VibesGraphicsVehicleAUV::computeProjection(int dimX, int dimY)
// Set propulsion unit shape
{
QPolygonF propunit;
propunit << QPointF(-4. * length, 1 * length) + centerPoint;
propunit << QPointF(-3.25 * length, 1 * length) + centerPoint;
propunit << QPointF(-3.25 * length, -1 * length) + centerPoint;
propunit << QPointF(-4. * length, -1 * length) + centerPoint;
propunit << QPointF(-4., 1) + centerPoint;
propunit << QPointF(-3.25, 1) + centerPoint;
propunit << QPointF(-3.25, -1) + centerPoint;
propunit << QPointF(-4., -1) + centerPoint;

// Draw with the new properties
QGraphicsPolygonItem *graphics_propunit = new QGraphicsPolygonItem(propunit);
Expand Down

0 comments on commit 54ce334

Please sign in to comment.