From: Olavi Pulkkinen Date: Wed, 24 Mar 2010 11:01:50 +0000 (+0200) Subject: Added routedialog to read route data from file. X-Git-Tag: v0.1~10 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=d58f01b3442d74543b993d2f7ed3d8947a1542b6;p=speedfreak Added routedialog to read route data from file. --- diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index 9ae252d..b6108af 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -427,7 +427,11 @@ void CarMainWindow::regUserToServer() void CarMainWindow::on_drawRoutePushButton_clicked() { - myRoute->show(); + QString routeFile = QString("route.txt"); + if (myRoute->readRouteFromFile( routeFile) == true) + { + myRoute->show(); + } } /** diff --git a/Client/routedialog.cpp b/Client/routedialog.cpp index bc4f8c7..aa1a681 100644 --- a/Client/routedialog.cpp +++ b/Client/routedialog.cpp @@ -11,7 +11,8 @@ #include #include #include -//#include +#include +#include /* * Vector class @@ -53,81 +54,98 @@ public: }; }; -int left, top, right, bottom; // Limits in screen coordinates + +class Viewing +{ + Vector atPoint, fromPoint, up, a1, a2, a3; + qreal offsx, offsy, offsz; + qreal dval; + qreal angle; +public: + qreal getOffsx() { return offsx; }; + qreal getOffsy() { return offsx; }; + qreal getOffsz() { return offsz; }; + qreal getDval() { return dval; }; + void setAngle( qreal newA) { angle = newA; }; + void setUp( qreal newUpX, qreal newUpY, qreal newUpZ) + { + up.setX(newUpX); up.setY(newUpY); up.setZ(newUpZ); + }; + void setAtPoint( qreal newX, qreal newY, qreal newZ) + { + atPoint.setX(newX); atPoint.setY(newY); atPoint.setZ(newZ); + }; + void setFromPoint(qreal newX, qreal newY, qreal newZ) + { + fromPoint.setX(newX); fromPoint.setY(newY); fromPoint.setZ(newZ); + } + void setEye() + { + double amarkmag, tempmag; + Vector temp, dist; + + dval = cos(angle/2.0)/sin(angle/2.0); + dist = atPoint-fromPoint; + amarkmag = dist.length(); + a3 = dist/amarkmag; + + temp.crossProduct( dist, up); + tempmag = temp.length(); + a1 = temp/tempmag; + + temp.crossProduct( a1, a3); + tempmag = temp.length(); + a2 = temp/tempmag; + + offsx = -a1.getX()*fromPoint.getX() - a1.getY()*fromPoint.getY() - a1.getZ()*fromPoint.getZ(); + offsy = -a2.getX()*fromPoint.getX() - a2.getY()*fromPoint.getY() - a2.getZ()*fromPoint.getZ(); + offsz = -a3.getX()*fromPoint.getX() - a3.getY()*fromPoint.getY() - a3.getZ()*fromPoint.getZ(); + QString jono2 = QString("offsx %1 offsy %2 offsz %3").arg(offsx).arg(offsy).arg(offsz); + QMessageBox::about(0,"offs x y z", jono2); + } ; + Vector getAtPoint() { return atPoint; }; + Vector getFromPoint() { return fromPoint; }; + Vector getA1() { return a1; }; + Vector getA2() { return a2; }; + Vector getA3() { return a3; }; + Viewing () {}; +}; + qreal xmax, xmin, ymin, ymax; // Limits in world coordinates QList vertexList; // Vertecies of route -Vector atPoint, fromPoint, up, a1, a2, a3; -qreal offsx, offsy, offsz; +//Vector atPoint, fromPoint, up, a1, a2, a3; +//qreal offsx, offsy, offsz; qreal objxmin, objxmax, objymin, objymax, objzmin, objzmax; -qreal angle; -qreal a, b,c,d, dval; +//qreal angle; +qreal a, b,c,d; //, dval; #define maxof(val1,val2) ((val1>val2)?val1:val2) #define toradians( degrees) (degrees*0.017453293) #define WIDTH 1.8 -int length = 24; -int connection[30]; +int length = 34; // 24; +int connection[50]; + +void setAtPoint( Viewing *v); +void setFromPoint( Viewing *v); +//void setEye(); + +Viewing view3d; + +void dataMinMax( void); + -void setAtPoint(); -void setFromPoint(); -void setEye(); RouteDialog::RouteDialog(QWidget *parent) : QDialog(parent), ui(new Ui::RouteDialog) { ui->setupUi(this); - //left = 50; top = 50; right = 350; bottom = 200; - left = 5; top = 5; right = 395; bottom = 295; - xmin =0.0; xmax=100.0; ymin = 0.0; ymax = 20.0; - // Ruudun koko 400 x 300 - - /*vertexList.append(QVector3D(40.02, 10.02, 10.02)); - vertexList.append(QVector3D(50.01, 5.01, 10)); - vertexList.append(QVector3D(69.98, 4.98, 10)); - vertexList.append(QVector3D(80.02, 9.98, 10)); - vertexList.append(QVector3D(70.01, 15.01, 10)); - vertexList.append(QVector3D(49.99, 14.97, 10)); - vertexList.append(QVector3D(40.01, 10.01, 10.02)); -*/ - vertexList.append(Vector(0.0, 0.0, 0.0)); - vertexList.append(Vector(1.0, 1.0, 1.0)); - vertexList.append(Vector(1.0, 1.0, 0.0)); - - vertexList.append(Vector(1.0, 0.0, 0.0)); - vertexList.append(Vector(1.0, 0.0, 1.0)); - vertexList.append(Vector(0.0, 1.0, 1.0)); - - vertexList.append(Vector(0.0, 1.0, 0.0)); - vertexList.append(Vector(0.0, 0.0, 0.0)); - vertexList.append(Vector(0.0, 0.0, 1.0)); - - connection[0] = 0; - connection[1] = 1; connection[2] = 5; connection[3] = 8; connection[4] = -4; - connection[5] = 5; connection[6] = 6; connection[7] = 7; connection[8] = -8; - connection[9] = 6; connection[10] = 2; connection[11] = 3; connection[12] = -7; - connection[13] = 1; connection[14] = 4; connection[15] = 3; connection[16] = -2; - connection[17] = 8; connection[18] = 7; connection[19] = 3; connection[20] = -4; - connection[21] = 6; connection[22] = 5; connection[23] = 1; connection[24] = -2; - - fromPoint.setX( 1.0); fromPoint.setY( 0.0); fromPoint.setZ( 0.0); - atPoint.setX( 0.0); atPoint.setY( 0.0); atPoint.setZ( 0.0); - up.setX( 0.0); up.setY( 0.0); up.setZ(1.0); - - a = 400/2.; - b = 1 - a*(-1); - c = -300/2.; - d = 300 - c*(-1); - angle = toradians(60); - - setAtPoint(); - setFromPoint(); - setEye(); + left = 5; top = 5; right = 395; bottom = 195; // Limits in screen coordinates } RouteDialog::~RouteDialog() @@ -151,50 +169,167 @@ void RouteDialog::changeEvent(QEvent *e) /** * Draws route to the route dialog * @param QPaintEvent - * + */ +/* */ void RouteDialog::paintEvent(QPaintEvent *) { // 2d draw + int startx, starty; // Starting point of the route int i, maxi; qreal x1, y1, x2, y2; int scx1, scy1, scx2, scy2; + Vector v1, v2; + QPainter painter(this); - QPainter painter(this); - - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen((Qt::black),2)); - painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern)); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen((Qt::black),2)); + painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern)); - // Draw route window frsme - painter.drawLine(left,top,right,top); - painter.drawLine(right,top,right,bottom); - painter.drawLine(left,top,left,bottom); - painter.drawLine(left,bottom,right,bottom); + // Draw route window frame + /*painter.drawLine(left,top,right,top); + painter.drawLine(right,top,right,bottom); + painter.drawLine(left,top,left,bottom); + painter.drawLine(left,bottom,right,bottom); + */ - //maxi = vertexList.size(); - for (i=0; isetAtPoint( x, y, z); //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x()).arg(atPoint.y()).arg(atPoint.z()); //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x).arg(atPoint.y).arg(atPoint.z); - //QMessageBox::about(0,"At point", jono); + + /* * + test = v->getAtPoint(); + QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ()); + QMessageBox::about(0,"At point", jono); + * */ } -void setFromPoint() +void setFromPoint( Viewing *v) { + qreal x, y, z; + Vector point; + point = v->getAtPoint(); + Vector test; //fromPoint.setX( atPoint.getX() + (objxmax-objxmin)/2.0 + WIDTH*maxof((objzmax-objzmin)/2.0,(objymax-objymin)/2.0)); - fromPoint.setX(3.0); - fromPoint.setY( atPoint.getY()); - fromPoint.setZ( atPoint.getZ()); + //fromPoint.setX( + //x = 3.0; + x = point.getX() + 300; //25; + //fromPoint.setY( + y = point.getY(); + //fromPoint.setZ( + z = point.getZ(); // + 150; + v->setFromPoint(x,y,z); //QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(fromPoint.x()).arg(fromPoint.y()).arg(fromPoint.z()); //QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(fromPoint.x).arg(fromPoint.y).arg(fromPoint.z); - //QMessageBox::about(0,"From point", jono); // (1.9, 0.5, 0.5) + /* * + test = v->getFromPoint(); + QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ()); + QMessageBox::about(0,"From point", jono); // (1.9, 0.5, 0.5) + * */ } -void setEye() +/*void setEye() { double amarkmag, tempmag; Vector temp, dist; @@ -293,7 +453,7 @@ void setEye() offsz = -a3.getX()*fromPoint.getX() - a3.getY()*fromPoint.getY() - a3.getZ()*fromPoint.getZ(); //QString jono2 = QString("offsx %1 offsy %2 offsz %3").arg(offsx).arg(offsy).arg(offsz); //QMessageBox::about(0,"offs x y z", jono2); -} +}*/ #define NOEDGE 0x00 #define LEFTEDGE 0x01 @@ -404,10 +564,20 @@ void clip3d( qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2, int *xs * Transform the segment connecting the two vectors into the viewing plane. * clip3d() clips the line if needed. */ -void transformseg( Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2 ) +void transformseg( Viewing *v, Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2 ) { qreal x1, y1, z1, x2, y2, z2; + qreal offsx, offsy, offsz; + qreal dval; + Vector a1, a2, a3; + a1 = v->getA1(); + a2 = v->getA2(); + a3 = v->getA3(); + offsx = v->getOffsx(); + offsy = v->getOffsy(); + offsz = v->getOffsz(); + dval = v->getDval(); x1 = (a1.getX()*v1->getX() + a1.getY()*v1->getY() + a1.getZ()*v1->getZ() + offsx)*dval; y1 = (a2.getX()*v1->getX() + a2.getY()*v1->getY() + a2.getZ()*v1->getZ() + offsy)*dval; @@ -420,12 +590,14 @@ void transformseg( Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xs clip3d(x1,y1,z1,x2,y2,z2, xscreen1, yscreen1, xscreen2, yscreen2 ); } +/* + * + * 3D route viewing +* void RouteDialog::paintEvent(QPaintEvent *) { int i, startofside; - qreal x1, y1, x2, y2; - int scx1, scy1, scx2, scy2; - int xpc1, ypc1, xpc2, ypc2; + int xscreen1, yscreen1, xscreen2, yscreen2; Vector temp1, temp2; QPainter painter(this); @@ -440,6 +612,21 @@ void RouteDialog::paintEvent(QPaintEvent *) //painter.drawLine(left,top,left,bottom); //painter.drawLine(left,bottom,right,bottom); + i = 1; + while (i