UWBMarker.cpp 1.68 KB
Newer Older
flashingx's avatar
flashingx committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//    Marker for the Crazyflie flying with UWB.
//
//    Copyright (C) 2018
//			Yvan Bosshard			byvan		@ee.ethz.ch
//			Michael Rogenmoser		michaero	@ee.ethz.ch
//			Tiago Salzmann			tiagos		@ee.ethz.ch
//	  
//	  Adapted from centerMarker of Angel Romero.
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

tiagos's avatar
tiagos committed
23
24
#include <stdio.h>

flashingx's avatar
flashingx committed
25
26
#include "UWBMarker.h"

tiagos's avatar
tiagos committed
27
28
29
30
31
32
33
UWBMarker::UWBMarker(const UWBAnchor* const anchor, QString filename, QGraphicsItem* parent) : QGraphicsSvgItem(filename)
{
	updateMarker(anchor);
	m_width = ANCHOR_WIDTH;
	m_height = ANCHOR_HEIGHT;
}

flashingx's avatar
flashingx committed
34
UWBMarker::~UWBMarker(){}
tiagos's avatar
tiagos committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

void UWBMarker::updateMarker(const UWBAnchor* const anchor)
{
	m_x = anchor->x /10;
	m_y = anchor->y /10;
	m_z = anchor->z /10;

	this->setPos(m_x * FROM_METERS_TO_UNITS, -m_y * FROM_METERS_TO_UNITS);
	this->setOpacity(ANCHOR_OPACITY);
}

QRectF UWBMarker::boundingRect() const
{
    return QRectF(-m_width/2, -m_height/2, m_width, m_height);
}

void UWBMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    this->renderer()->render(painter,this->boundingRect());
}