void TerrainView::paintEvent(QPaintEvent *e) { Q_D(TerrainView); auto size = this->size(); SceneDefinition def; def.cameraDir = QVector3D(std::cos(d->yaw_) * std::cos(d->pitch_), std::sin(d->yaw_) * std::cos(d->pitch_), std::sin(d->pitch_)); def.eye = d->centerPos_ - def.cameraDir; def.viewWidth = size.width() / d->scale_; def.viewHeight = size.height() / d->scale_; auto img = d->render(size, def); QPainter painter(this); painter.drawImage(0, 0, img); if (d->viewOptions.axises) { QPointF axisPos(40, size.height() - 50); QPointF axisX(d->rightVector.x(), d->upVector.x()); QPointF axisY(d->rightVector.y(), d->upVector.y()); QPointF axisZ(d->rightVector.z(), d->upVector.z()); float axisLen = 18.f; auto drawText = [&](QString text, QPointF origin, QPointF dir) { dir *= 1.f / std::sqrt(dir.x() * dir.x() + dir.y() * dir.y()); origin += dir * 12.f; QRectF r(origin.x() - 100.f, origin.y() - 100.f, 200.f, 200.f); QTextOption opt; opt.setAlignment(Qt::AlignCenter); painter.drawText(r, text, opt); }; painter.setPen(qRgb(0, 0, 255)); painter.drawLine(axisPos, axisPos + axisZ * axisLen); drawText("Z", axisPos + axisZ * axisLen, axisZ); painter.setPen(qRgb(255, 0, 0)); painter.drawLine(axisPos, axisPos + axisX * axisLen); drawText("X", axisPos + axisX * axisLen, axisX); painter.setPen(qRgb(0, 255, 0)); painter.drawLine(axisPos, axisPos + axisY * axisLen); drawText("Y", axisPos + axisY * axisLen, axisY); } emit clientPaint(e); }
bool Cylinder::Interpolate(const MiscLib::Vector< Cylinder > &cylinders, const MiscLib::Vector< float > &weights, Cylinder *ic) { Vec3f axisPos(0, 0, 0); Vec3f axisDir(0, 0, 0); float r = 0; for(size_t i = 0; i < cylinders.size(); ++i) { axisPos += weights[i] * cylinders[i].AxisPosition(); axisDir += weights[i] * cylinders[i].AxisDirection(); r += weights[i] * cylinders[i].Radius(); } axisDir.normalize(); return ic->Init(axisDir, axisPos, r); }