QVector2D SegmentGL::glhProjectf(QVector3D obj, float *modelview, float *projection, int width, int height) { //Transformation vectors float fTempo[8]; //Modelview transform fTempo[0]=modelview[0]*obj.x()+modelview[4]*obj.y()+modelview[8]*obj.z()+modelview[12]; //w is always 1 fTempo[1]=modelview[1]*obj.x()+modelview[5]*obj.y()+modelview[9]*obj.z()+modelview[13]; fTempo[2]=modelview[2]*obj.x()+modelview[6]*obj.y()+modelview[10]*obj.z()+modelview[14]; fTempo[3]=modelview[3]*obj.x()+modelview[7]*obj.y()+modelview[11]*obj.z()+modelview[15]; //Projection transform, the final row of projection matrix is always [0 0 -1 0] //so we optimize for that. fTempo[4]=projection[0]*fTempo[0]+projection[4]*fTempo[1]+projection[8]*fTempo[2]+projection[12]*fTempo[3]; fTempo[5]=projection[1]*fTempo[0]+projection[5]*fTempo[1]+projection[9]*fTempo[2]+projection[13]*fTempo[3]; fTempo[6]=projection[2]*fTempo[0]+projection[6]*fTempo[1]+projection[10]*fTempo[2]+projection[14]*fTempo[3]; fTempo[7]=-fTempo[2]; //The result normalizes between -1 and 1 // if(fTempo[7]==0.0) //The w value // return 0; fTempo[7]=1.0/fTempo[7]; //Perspective division fTempo[4]*=fTempo[7]; fTempo[5]*=fTempo[7]; fTempo[6]*=fTempo[7]; //Window coordinates //Map x, y to range 0-1 QVector2D win((fTempo[4]*0.5+0.5)*width, (fTempo[5]*0.5+0.5)*height); //This is only correct when glDepthRange(0.0, 1.0) //windowCoordinate[2]=(1.0+fTempo[6])*0.5; //Between 0 and 1 return win; }
// allow QVector3D's to be stored in a QMap inline bool operator<(const QVector3D &a, const QVector3D &b) { if (qFskCompare(a.x(), b.x())) { if (qFskCompare(a.y(), b.y())) { if (qFskCompare(a.z(), b.z())) { return false; // equal so not less-than } else { return a.z() < b.z(); } } else { return a.y() < b.y(); } } else { return a.x() < b.x(); } }
bool SelectionQuery::Intersection(const AxisAlignedBox& box, const QVector3D& ray_start, const QVector3D& ray_dir, double* result) { const QVector3D& bmin = box.Min(); const QVector3D& bmax = box.Max(); const double inv_x = 1 / ray_dir.x(); const double inv_y = 1 / ray_dir.y(); const double inv_z = 1 / ray_dir.z(); const double tx1 = (bmin.x() - ray_start.x()) * inv_x; const double tx2 = (bmax.x() - ray_start.x()) * inv_x; double tmin = std::min(tx1, tx2); double tmax = std::max(tx1, tx2); const double ty1 = (bmin.y() - ray_start.y()) * inv_y; const double ty2 = (bmax.y() - ray_start.y()) * inv_y; tmin = std::max(tmin, std::min(ty1, ty2)); tmax = std::min(tmax, std::max(ty1, ty2)); const double tz1 = (bmin.z() - ray_start.z()) * inv_z; const double tz2 = (bmax.z() - ray_start.z()) * inv_z; tmin = std::max(tmin, std::min(tz1, tz2)); tmax = std::min(tmax, std::max(tz1, tz2)); if (tmax >= tmin && tmax > 0) { *result = std::max(0.0, std::min(tmin, tmax)); return true; } return false; }
void RtSourceDataWorker::setThresholds(const QVector3D& vecThresholds) { m_lHemiVisualizationInfo[0].dThresholdX = vecThresholds.x(); m_lHemiVisualizationInfo[0].dThresholdZ = vecThresholds.z(); m_lHemiVisualizationInfo[1].dThresholdX = vecThresholds.x(); m_lHemiVisualizationInfo[1].dThresholdZ = vecThresholds.z(); }
QVector<QVector3D> SurfaceItem::vertices() const { QSize size = surface()->size(); qreal w = (m_height * size.width()) / size.height(); qreal h = m_height; QVector3D pos = m_pos + m_normal * m_depthOffset; QVector2D center(pos.x(), pos.z()); QVector3D perp = QVector3D::crossProduct(QVector3D(0, 1, 0), m_normal); QVector2D delta = w * QVector2D(perp.x(), perp.z()).normalized() / 2; qreal scale = qMin(1.0, m_time.elapsed() * 0.002); qreal top = m_pos.y() + h * 0.5 * scale; qreal bottom = m_pos.y() - h * 0.5 * scale; QVector2D left = center - delta * scale; QVector2D right = center + delta * scale; QVector3D va(left.x(), top, left.y()); QVector3D vb(right.x(), top, right.y()); QVector3D vc(right.x(), bottom, right.y()); QVector3D vd(left.x(), bottom, left.y()); QVector<QVector3D> result; result << va << vb << vc << vd; return result; }
float Ray::calcAngleSum(QVector3D q, QVector<QVector4D> p) { float m1,m2; float anglesum=0,costheta; QVector3D p1,p2; float twoPi = M_PI * 2; int n = p.size(); for (int i=0;i<n;++i) { p1.setX(p[i].x() - q.x()); p1.setY(p[i].y() - q.y()); p1.setZ(p[i].z() - q.z()); p2.setX(p[(i+1)%n].x() - q.x()); p2.setY(p[(i+1)%n].y() - q.y()); p2.setZ(p[(i+1)%n].z() - q.z()); m1 = p1.length(); m2 = p2.length(); if (m1*m2 <= 0.00001) return 0; /* We are on a node, consider this inside */ else costheta = (p1.x()*p2.x() + p1.y()*p2.y() + p1.z()*p2.z()) / (m1*m2); anglesum += acos(costheta); } return qAbs(anglesum - twoPi); }
void Maillage::Ecriture(std::string nom) { std::ofstream fichier(nom, std::ios::out | std::ios::trunc); if(fichier) { fichier << "o " << nom << std::endl; fichier << std::endl; QVector3D temp; for (int i = 0; i < geom.size(); ++i) { temp = geom.at(i); fichier << "v " << temp.x() << " " << temp.y() << " " << temp.z() << std::endl; } fichier << std::endl; for (int i = 0; i < normales.size(); ++i) { temp = normales.at(i); fichier << "vn " << temp.x() << " " << temp.y() << " " << temp.z() << std::endl; } fichier << std::endl; for (int i = 0; i < topo.size(); i+=3) { fichier << "f " << topo.at(i)+1 << " " << topo.at(i+1)+1 << " " << topo.at(i+2)+1 << std::endl; } fichier.close(); // on referme le fichier } else { std::cerr << "Erreur à l'ouverture !" << std::endl; } }
void WhittedRenderer::renderScanline(int y) { float* buffer = m_buffer + y * m_renderedWidth * 3; float aspect = (float) m_renderedWidth / m_renderedHeight; float xStep = 1.0 / (m_renderedWidth - 1); float yStep = 1.0 / (m_renderedHeight - 1); if (m_antiAliasing == None) { for (int x=0; x < m_renderedWidth; x++) { QVector3D shaded; Ray primaryRay; m_activeCamera->generateRay(primaryRay, x * xStep, y * yStep, aspect); shaded = trace(primaryRay, 0, m_shapes, m_lights); *buffer++ = shaded.x(); *buffer++ = shaded.y(); *buffer++ = shaded.z(); } } else if (m_antiAliasing == JitteredSamples) { float sampleScaler = 1.0 / m_samplesPerPixel; for (int x=0; x < m_renderedWidth; x++) { QVector3D shaded; for (int i=0; i < m_samplesPerPixel; i++) { Ray primaryRay; float xJitter = i == 0 ? 0.0 : (MathUtils::randomf() * xStep); float yJitter = i == 0 ? 0.0 : (MathUtils::randomf() * yStep); float xSample = x * xStep + xJitter; float ySample = y * yStep + yJitter; m_activeCamera->generateRay(primaryRay, xSample, ySample, aspect); shaded += trace(primaryRay, 0, m_shapes, m_lights) * sampleScaler; } *buffer++ = shaded.x(); *buffer++ = shaded.y(); *buffer++ = shaded.z(); } } }
void RotateVector(QVector3D &vec, double angledeg, QVector3D axis)//choose 1 axis of rotation at a time.. { double prevx; double prevy; double prevz; double cosval = qCos( angledeg * TO_RAD ); double sinval = qSin( angledeg * TO_RAD ); if(axis.x()) { prevx = vec.x(); prevy = vec.y(); prevz = vec.z(); vec.setY( prevy * cosval - prevz * sinval); vec.setZ( prevy * sinval + prevz * cosval); } if(axis.y()) { prevx = vec.x(); prevy = vec.y(); prevz = vec.z(); vec.setZ( prevz * cosval - prevx * sinval); vec.setX( prevz * sinval + prevx * cosval); } if(axis.z()) { prevx = vec.x(); prevy = vec.y(); prevz = vec.z(); vec.setX( prevx * cosval - prevy * sinval); vec.setY( prevx * sinval + prevy * cosval); } }
const bool AxisAlignedBoundingBox::extend(const QVector3D & vertex) { const QVector3D llf(m_llf); const QVector3D urb(m_urb); if(vertex.x() < m_llf.x()) m_llf.setX(vertex.x()); if(vertex.x() > m_urb.x()) m_urb.setX(vertex.x()); if(vertex.y() < m_llf.y()) m_llf.setY(vertex.y()); if(vertex.y() > m_urb.y()) m_urb.setY(vertex.y()); if(vertex.z() < m_llf.z()) m_llf.setZ(vertex.z()); if(vertex.z() > m_urb.z()) m_urb.setZ(vertex.z()); const bool extended(urb != m_urb && llf != m_llf); if(extended) { m_center = m_llf + (m_urb - m_llf) * .5f; m_radius = (m_urb - m_llf).length() * .5f; } return extended; }
void Camera::setRotate(const QVector3D &_vec) { QVector3D diffRotate = m_rotate - _vec; if(m_isFreeMode) { QQuaternion quaRight = QQuaternion::fromAxisAndAngle(m_right, -diffRotate.x() ); QQuaternion quaUp = QQuaternion::fromAxisAndAngle(m_up, -diffRotate.z() ); m_right = quaUp.rotatedVector(m_right); m_up = quaRight.rotatedVector(m_up); } else { QQuaternion quaRight = QQuaternion::fromAxisAndAngle(m_right, diffRotate.x()); QQuaternion quaUp = QQuaternion::fromAxisAndAngle(m_up, diffRotate.z()); QQuaternion qua = quaUp*quaRight; QVector3D rightRadiusVector = relativeRotate(m_right + m_cameraPos, qua, m_targetCamera); QVector3D upRadiusVector = relativeRotate(m_up + m_cameraPos, qua, m_targetCamera); m_cameraPos = relativeRotate(m_cameraPos, qua, m_targetCamera); m_right = (rightRadiusVector - m_cameraPos).normalized(); m_up = (upRadiusVector - m_cameraPos).normalized(); } matrixByAxisCamera(m_cameraMatrix, m_cameraPos, m_right, m_up); m_rotate = _vec; }
void Connections::calculateBounds() { for (int i = 0; i < edges.size(); i++) { Edge *aedge = edges.at(i); QVector3D afn = aedge->fn; QVector3D atn = aedge->tn; if (i==0){ max = QVector3D(afn.x(),afn.y(),afn.z()); min = QVector3D(afn.x(),afn.y(),afn.z()); } else { max.setX(qMax(afn.x(),max.x())); max.setY(qMax(afn.y(),max.y())); max.setZ(qMax(afn.z(),max.z())); min.setX(qMin(afn.x(),min.x())); min.setY(qMin(afn.y(),min.y())); min.setZ(qMin(afn.z(),min.z())); max.setX(qMax(atn.x(),max.x())); max.setY(qMax(atn.y(),max.y())); max.setZ(qMax(atn.z(),max.z())); min.setX(qMin(atn.x(),min.x())); min.setY(qMin(atn.y(),min.y())); min.setZ(qMin(atn.z(),min.z())); } } piv = -(min+max)/2; }
inline QPointF Terrain::toMapF( const QVector3D & point ) const { return QPointF( (point.x()-(float)mOffset.x()) * mToMapFactor.width(), (point.z()-(float)mOffset.z()) * mToMapFactor.height() ); }
Triangle::Triangle(QVector3D &p, QVector3D &q, QVector3D &r) { _vertices[0]<<p.x(), p.y(), p.z(); _vertices[1]<<q.x(), q.y(), q.z(); _vertices[2]<<r.x(), r.y(), p.z(); init(); }
void SSTask::drawMeshes3D( const QSizeF& mapSize ) const { QRectF boundingRect(QPointF( -mapSize.width()/2.0, -mapSize.height()/2.0), mapSize); glBegin(GL_TRIANGLES); mutex.lockForRead(); for(int i = 0; i < m_meshes_cache.size(); i++){ Triangle3D t = m_meshes_cache.at(i); if(!boundingRect.contains(t.v1.toPointF()) || !boundingRect.contains(t.v2.toPointF()) || !boundingRect.contains(t.v3.toPointF())) continue; QVector3D normal = QVector3D::crossProduct(t.v2 - t.v1, t.v3 - t.v1); if(normal.z() < 0){ t = Triangle3D(t.v3, t.v2, t.v1); normal.setZ( - normal.z()); } glNormal3d(normal.x(), normal.y(), normal.z()); glVertex3d(t.v1.x(), t.v1.y(), t.v1.z()); glVertex3d(t.v2.x(), t.v2.y(), t.v2.z()); glVertex3d(t.v3.x(), t.v3.y(), t.v3.z()); } mutex.unlock(); glEnd(); }
void RayTracer::RenderScene(Scene * scene, Camera * camera, QImage * buffer) { buffer->fill(QColor(Qt::white).rgb()); double fov = camera->GetFOV(); double fov_2 = fov / 2.0; double largestDim = std::max(camera->getXRes(), camera->getYRes()); double cameraPlaneDist = 0.5 * largestDim * tan((90 - fov_2) * DEGREE_TO_RAD); // Assumes camera location is negative // TODO: Fix this assumption QVector3D cameraPlaneLocation = QVector3D(0, 0, camera->GetZPos() + cameraPlaneDist); int y_2 = camera->getYRes() / 2; int x_2 = camera->getXRes() / 2; QVector3D cp = QVector3D(0, 0, camera->GetZPos()); for (int y = -y_2; y < y_2; ++y) { for (int x = - x_2; x < x_2; ++x) { // Compute the vector from the eye QVector3D rayDirection = QVector3D(x, y, cameraPlaneLocation.z()); QVector3D color = TraceRay(scene, cp, rayDirection, 0); buffer->setPixel(x + x_2, y + y_2, qRgb(color.x() * 255, color.y()* 255, color.z() * 255)); } } }
QVector3D rotateAroundAxis( const QVector3D input, const QVector3D axis, const double angle ){ double dis = sqrt(axis.x()*axis.x()+axis.y()*axis.y()+axis.z()*axis.z()); if( dis == 0 ){ cerr<<"!!!no axis for rotating around"<<endl; return input; } QVector3D u((double)axis.x()/dis, (double)axis.y()/dis, (double)axis.z()/dis); double a11 = cos(angle)+u.x()*u.x()*(1-cos(angle)); double a12 = u.x()*u.y()*(1-cos(angle))-u.z()*sin(angle); double a13 = u.x()*u.z()*(1-cos(angle))+u.y()*sin(angle); double a21 = u.y()*u.x()*(1-cos(angle))+u.z()*sin(angle); double a22 = cos(angle)+u.y()*u.y()*(1-cos(angle)); double a23 = u.y()*u.z()*(1-cos(angle))-u.x()*sin(angle); double a31 = u.z()*u.x()*(1-cos(angle))-u.y()*sin(angle); double a32 = u.z()*u.y()*(1-cos(angle))+u.x()*sin(angle); double a33 = cos(angle)+u.z()*u.z()*(1-cos(angle)); double x = a11*input.x()+a12*input.y()+a13*input.z(); double y = a21*input.x()+a22*input.y()+a23*input.z(); double z = a31*input.x()+a32*input.y()+a33*input.z(); QVector3D c(x, y, z); return c; }
void GLWidget::mouseMoveEvent(QMouseEvent *event) { if (!select(event)){ glLoadIdentity(); int dx = event->x() - lastPos.x(); int dy = event->y() - lastPos.y(); if (event->buttons() & Qt::LeftButton) { QMatrix4x4 mat(view[0],view[4],view[8],view[12],view[1],view[5],view[9],view[13],view[2],view[6],view[10],view[14],view[3],view[7],view[11],view[15]); QVector3D orig(0, 0, 0); QVector3D m = mat.map(orig); glTranslatef(m.x(), m.y(), m.z()); glRotatef(qSqrt(dx*dx+dy*dy)/2.0, dy, dx, 0); glTranslatef(-m.x(), -m.y(), -m.z()); } else if (event->buttons() & Qt::RightButton) { glTranslatef(dx/(float)width()*ar/scale, -dy/(float)height()/scale, 0); } lastPos = event->pos(); glPushMatrix(); glMultMatrixf(view); glGetFloatv(GL_MODELVIEW_MATRIX, view); glPopMatrix(); } updateGL(); }
inline QPoint Terrain::toMap( const QVector3D & point ) const { return QPoint( floorf( (point.x()-mOffset.x()) * mToMapFactor.width() ), floorf( (point.z()-mOffset.z()) * mToMapFactor.height() ) ); }
QVector3D Camera::screenToWorld(QVector3D vec, QMatrix4x4 modelview, QMatrix4x4 projection) { int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); float winX = vec.x(); float winY = vec.y(); winY = viewport[3] - winY; float winZ; glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); QVector4D v((winX-(float)viewport[0])/(float)viewport[2]*2.0-1.0, (winY-(float)viewport[1])/(float)viewport[3]*2.0-1.0, 0, 1); QVector4D v2((winX-(float)viewport[0])/(float)viewport[2]*2.0-1.0, (winY-(float)viewport[1])/(float)viewport[3]*2.0-1.0, 1, 1); QMatrix4x4 mat(modelview * projection); QVector4D t = v * mat.inverted(); float w = 1 / t.w(); QVector3D pt1(t.x() * w, t.y() * w, t.z() * w); t = v2 * mat.inverted(); w = 1 / t.w(); QVector3D pt2(t.x() * w, t.y() * w, t.z() * w); QVector3D out; intersects(QVector3D(1, 0, vec.z()), QVector3D(0, 1, vec.z()), QVector3D(1, 1, vec.z()), pt1, pt2, out); return out; }
/*! Returns the point at which the \a line intersects this box. The result is returned as a QResult<QVector3D> instance. When the line intersects the box at least once, a QResult<QVector3D> instance is returned where QResult::isValid() returns true; and where QResult::value() returns a QVector3D containing the intersection point. In the case where the origin point of the line lies on one of the box faces, this point is simply returned (with no floating point operations). The line might intersect at two points - as the line passes through the box - one on the near side, one on the far side; where near and far are relative to the origin point of the line. This function only returns the near intersection point. Only positive values on the line are considered, that is if \c{qreal t == line.point(intersectionPoint)} then \bold t is positive. This means that if the origin point of the line is inside the box, there is only one solution, not two. To get the other solution, simply change the sign of the lines direction vector. When the line does not intersect the box, the result returned will have a QResult::isValid() value of false. In the case of an infinite box the result reflects that with QResult::OutOfRange */ QResult<QVector3D> QBox3D::intersection(const QLine3D &line) const { if (boxtype == Null) return QResult<QVector3D>(); if (boxtype == Infinite) return QResult<QVector3D>(QResult<QVector3D>::OutOfRange); QVector3D org = line.origin(); Partition xpos, ypos, zpos; partition(org, &xpos, &ypos, &zpos); // if the lines origin lies on one of the faces, return it as the intersection if ((xpos | ypos | zpos) == (equalMin | equalMax)) return org; // Could use the line/plane intersection functions, with 6 box planes defined by // 3 normals at the min and 3 at the max. But since the planes are axis-aligned // there is a cheap optimization. If the line P + tV intersects a AA-plane with // x = c at intersection point X, then P.x + tV.x = X.x = c; and therefore // t = (c - P.x) / V.x. Here the value t is the scalar distance along V from P and // so it measures the value of the solution - see trackIntersection() above. qreal closest_t = 0.0f; QVector3D ln = line.direction(); QVector3D closest_p; for (const QVector3D *p = &maxcorner; p; p = (p == &maxcorner) ? &mincorner : 0) { if (!qIsNull(ln.x())) trackIntersection(p->x() - org.x() / ln.x(), &closest_t, &closest_p, *this, line); if (!qIsNull(ln.y())) trackIntersection(p->y() - org.y() / ln.y(), &closest_t, &closest_p, *this, line); if (!qIsNull(ln.z())) trackIntersection(p->z() - org.z() / ln.z(), &closest_t, &closest_p, *this, line); } return closest_p; }
void CPBox::update(QVector3D origin, QVector3D size) { float x0 = origin.x(); float x1 = x0 + size.x(); float y0 = origin.y(); float y1 = y0 + size.y(); float z0 = origin.z(); float z1 = z0 + size.z(); m_vertices.clear(); m_indices.clear(); m_vertices.push_back(CPPoint(QVector3D(x0, y0, z0))); m_vertices.push_back(CPPoint(QVector3D(x1, y0, z0))); m_vertices.push_back(CPPoint(QVector3D(x1, y0, z1))); m_vertices.push_back(CPPoint(QVector3D(x0, y0, z1))); m_vertices.push_back(CPPoint(QVector3D(x0, y1, z0))); m_vertices.push_back(CPPoint(QVector3D(x1, y1, z0))); m_vertices.push_back(CPPoint(QVector3D(x1, y1, z1))); m_vertices.push_back(CPPoint(QVector3D(x0, y1, z1))); m_indices = {0, 1, 2, 3, 1, 5, 6, 2, 4, 0, 3, 7, 5, 4, 7, 6}; }
QVector3D Box::max(const QVector3D &z, double m) { return QVector3D ( z.x() < m ? m : z.x(), z.y() < m ? m : z.y(), z.z() < m ? m : z.z() ); }
QVector3D Box::abs(const QVector3D &z) { return QVector3D ( z.x() < 0 ? - z.x() : z.x(), z.y() < 0 ? - z.y() : z.y(), z.z() < 0 ? - z.z() : z.z() ); }
void CCamera::setRot(QQuaternion q) { // Vector3 OldViewDir = (Vector3(Position.x, 0, Position.z) - Vector3(ViewPoint.x, 0, ViewPoint.z)); OldViewDir.normalize(); // double oldDP = Vector3(0, 1, 0) * OldViewDir; // tot = tot * q; // QVector3D t = tot.rotatedVector(QVector3D(PositionOriginal.x, PositionOriginal.y, PositionOriginal.z)); // Position = Vector3(t.x(), t.y(), t.z()); // Vector3 NewViewDir = (Vector3(Position.x, 0, Position.z) - Vector3(ViewPoint.x, 0, ViewPoint.z)); NewViewDir.normalize(); // double newDP = Vector3(0, 1, 0) * NewViewDir; // Vector3 axis = NewViewDir ^ OldViewDir; //// double angle = acos((NewViewDir * OldViewDir)); // double angle = 180 / PI * acos((NewViewDir * OldViewDir)); // if((newDP - oldDP) < 0) // angle = -angle; //// double angle = 180 / PI * acos(sqrt(NewViewDir * OldViewDir)); //// float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(QVector3D(axis.x, axis.y, axis.z), //// QVector3D(axis.x, axis.y, axis.z)))); // QQuaternion nq = QQuaternion::fromAxisAndAngle(0,1,0, angle); // totR = totR * nq; // ViewDir = (ViewPoint-Position); ViewDir.normalize(); // t = nq.rotatedVector(QVector3D(RightVector.x, RightVector.y, RightVector.z)); // //t = totR.rotatedVector(QVector3D(RightVectorOriginal.x, RightVectorOriginal.y, RightVectorOriginal.z)); // //t = tot.rotatedVector(QVector3D(1, 0, 0)); // RightVector = Vector3(t.x(), t.y(), t.z()); RightVector.normalize(); // UpVector = RightVector ^ ViewDir; UpVector.normalize(); tot = tot * q; QVector3D t = tot.rotatedVector(QVector3D(PositionOriginal.x, PositionOriginal.y, PositionOriginal.z)); Position = Vector3(t.x(), t.y(), t.z()); //t = tot.rotatedVector(QVector3D(UpVectorOriginal.x, UpVectorOriginal.y, UpVectorOriginal.z)); //t = tot.rotatedVector(QVector3D(0, 1, 0)); //UpVector = Vector3(t.x(), t.y(), t.z()); UpVector.normalize(); t = tot.rotatedVector(QVector3D(RightVectorOriginal.x, RightVectorOriginal.y, RightVectorOriginal.z)); //t = tot.rotatedVector(QVector3D(1, 0, 0)); RightVector = Vector3(t.x(), 0, t.z()); RightVector.normalize(); ViewDir = (ViewPoint-Position); ViewDir.normalize(); UpVector = RightVector ^ ViewDir; UpVector.normalize(); // qDebug() << "Dot Product: " << dpro << "\n"; // qDebug() << "ViewDir: " << ViewDir.x << " " << ViewDir.y << " " << ViewDir.z << "\n"; // qDebug() << "UpVec: " << UpVector.x << " " << UpVector.y << " " << UpVector.z << "\n"; // qDebug() << "RightVector: " << RightVector.x << " " << RightVector.y << " " << RightVector.z << endl; // qDebug() << "Axis: " << axis.x << ", " << axis.y <<", " << axis.z << "\n"; // qDebug() << "Angle: " << angle << "\n"; // qDebug() << "NewViewDir: " << NewViewDir.x << " " << NewViewDir.y << " " << NewViewDir.z << "\n"; // qDebug() << "OldViewDir: " << OldViewDir.x << " " << OldViewDir.y << " " << OldViewDir.z << "\n"; }
QVector3D QIsoSurface::_calcGradient(const QVector3D& point) { float value = _scalarField->value(point); QVector3D normal(( _scalarField->value(QVector3D(point.x() + _epsilon, point.y(), point.z()))) - value, (_scalarField->value(QVector3D(point.x(), point.y() + _epsilon, point.z()))) - value, (_scalarField->value(QVector3D(point.x(), point.y(), point.z() + _epsilon))) - value); normal.normalize(); return normal; }
static double squaredDistanceToAABB(const QVector3D& point, const AxisAlignedBox& box) { const QVector3D center = (box.Max() + box.Min()) / 2; const QVector3D half_sz = (box.Max() - box.Min()) / 2; const QVector3D vec(max(0.0, fabs(center.x() - point.x()) - half_sz.x()), max(0.0, fabs(center.y() - point.y()) - half_sz.y()), max(0.0, fabs(center.z() - point.z()) - half_sz.z())); return vec.lengthSquared(); }
void AxisAlignedBox::IncludePoint(const QVector3D& point) { min_.setX(std::min(min_.x(), point.x())); min_.setY(std::min(min_.y(), point.y())); min_.setZ(std::min(min_.z(), point.z())); max_.setX(std::max(max_.x(), point.x())); max_.setY(std::max(max_.y(), point.y())); max_.setZ(std::max(max_.z(), point.z())); }
bool EnvRoom::Inside(const QVector3D & p) const { if (p.x() > bx1 && p.x() < bx2 && p.z() > by1 && p.z() < by2) return true; else return false; }
void cData::getMinMax(QVector3D pt) { if (pt.x() > _max.x()) _max.setX(pt.x()); if (pt.x() < _min.x()) _min.setX(pt.x()); if (pt.y() > _max.y()) _max.setY(pt.y()); if (pt.y() < _min.y()) _min.setY(pt.y()); if (pt.z() > _max.z()) _max.setZ(pt.z()); if (pt.z() < _min.z()) _min.setZ(pt.z()); }