void Quiddiards::keyPressEvent(QKeyEvent *event){ switch (event->key()) { case Qt::Key_F2: actStart(); break; case Qt::Key_P: actPause(); break; case Qt::Key_Escape: case Qt::Key_Q: close(); break; case Qt::Key_Space: case Qt::Key_Enter: case Qt::Key_Return: break; case Qt::Key_W:{ /* forward cueball */ QVector3D n = -eye; n.setZ(0); n.normalize(); n += cueball.getVelocity(); if (n.length() > cueball.getSpeed()){ n = cueball.getSpeed()*n.normalized(); } cueball.setVelocity(n); break; } case Qt::Key_A: phi += 10; break; case Qt::Key_S:{ QVector3D n = eye; n.setZ(0); n.normalize(); n += cueball.getVelocity(); if (n.length() > cueball.getSpeed()){ n = cueball.getSpeed()*n.normalized(); } cueball.setVelocity(n); break; } case Qt::Key_D: phi -= 10; break; case Qt::Key_Tab: //camera = CAMERA((camera + 1) % 2); break; default: return; } update(); }
void Particles::calculatePorosity() { int N = particles.size()/100; if (N==0) return; int cnt = 1; calculateBoundingBox(); float l = (boundsMax - boundsMin).length()/135.0; qDebug() << "l = " << l; for (int i=0;i<N;i++) { QVector3D p; p.setX(Util::floatRandom(boundsMin.x(), boundsMax.x())); p.setY(Util::floatRandom(boundsMin.y(), boundsMax.y())); p.setZ(Util::floatRandom(boundsMin.z(), boundsMax.z())); for (int j=0;j<particles.size();j++) { if ((particles[j]->getPos() - p).lengthSquared()<l*l) { cnt++; j=particles.size(); break; } } if (rand()%100>=99) qDebug() << cnt / (float)i; } m_calculatedPorosity = (float)cnt/(float)N; // qDebug() << m_calculatedPorosity << " " << N << " / " << cnt; }
void FsSurfaceTreeItem::onSurfaceTranslationZChanged(float fTransZ) { QVector3D position = m_pRenderable3DEntity->position(); position.setZ(fTransZ); m_pRenderable3DEntity->setPosition(position); m_pRenderable3DEntityNormals->setPosition(position); }
void Qt3DGeometryTab::computeBoundingVolume(const Qt3DGeometryAttributeData &vertexAttr, const QByteArray &bufferData) { m_boundingVolume = BoundingVolume(); QVector3D v; for (unsigned int i = 0; i < vertexAttr.count; ++i) { const char *c = bufferData.constData() + vertexAttr.byteOffset + i * vertexAttr.byteStride; switch (vertexAttr.vertexBaseType) { case Qt3DRender::QAttribute::Float: { // cppcheck-suppress invalidPointerCast auto f = reinterpret_cast<const float *>(c); v.setX(*f); ++f; v.setY(*f); ++f; v.setZ(*f); break; } default: qWarning() << "Vertex type" << vertexAttr.vertexBaseType << "not implemented yet"; return; } m_boundingVolume.addPoint(v); } }
void BulletComponent::update(float delta) { EnemyComponent *enemy = target->getComponent<EnemyComponent>(); if(enemy != nullptr) { destination = target->getPosition(); } QVector3D dir = -(this->getEntity()->getPosition() - destination); if(dir.length() < 10) { if(enemy != nullptr) { enemy->takeDamage(damage); QVector3D v = getEntity()->getPosition(); v.setX(v.x() / 768); v.setY(v.y() / 624); v.setZ(0); FMODManager::getInstance()->setCurrentEvent("event:/hit"); FMODManager::getInstance()->setEventInstancePosition(v); FMODManager::getInstance()->setEventInstanceVolume(0.4); FMODManager::getInstance()->setParameterValue("pitch", 0.3 + (qrand() % 200) * 0.001); FMODManager::getInstance()->startEventInstance(); } this->getEntity()->release(); } else { dir.normalize(); this->getEntity()->setPosition(this->getEntity()->getPosition() + dir * speed * delta); } }
static bool qCalculateNormal(int i, int j, int k, QGeometryData &p, QVector3D *vec = 0) { QVector3D norm; QVector3D *n = &norm; if (vec) n = vec; bool nullTriangle = false; *n = QVector3D::crossProduct(p.vertexAt(j) - p.vertexAt(i), p.vertexAt(k) - p.vertexAt(j)); if (qFskIsNull(n->x())) n->setX(0.0f); if (qFskIsNull(n->y())) n->setY(0.0f); if (qFskIsNull(n->z())) n->setZ(0.0f); if (n->isNull()) { nullTriangle = true; } else { setNormals(i, j, k, p, *n); } return nullTriangle; }
void Transform::SetMember(QVector3D& member,const QVariant& data) { QList<QVariant> dataList(data.toList()); member.setX( dataList[0].toFloat() ); member.setY( dataList[1].toFloat() ); member.setZ( dataList[2].toFloat() ); }
DisplayWindow *FourierDCT::invert(ComplexArray *ca, QString title, QImage::Format format, QWidget *p) { int w = ca->shape()[1]; int h = ca->shape()[2]; perform(ca, true); ColorParser cp(format); QImage result(w, h, format); result.fill(Qt::black); if (format == QImage::Format_Indexed8) { QVector<QRgb> colors; colors.reserve(256); for (int i = 0; i < 256; i++) { colors << qRgb(i, i, i); } result.setColorTable(colors); } for (unsigned int i = 1; i < ca->shape()[0]; i += 2) { qreal min = 0; qreal max = 0; for (unsigned int j = 0; j < ca->shape()[1]; j++) { for (unsigned int k = 0; k < ca->shape()[2]; k++) { Complex c = (*ca)[i][j][k]; qreal real = c.real(); if (real > max) { max = real; } else if (real < min) { min = real; } } } for (unsigned int j = 0; j < ca->shape()[1]; j++) { for (unsigned int k = 0; k < ca->shape()[2]; k++) { Complex c = (*ca)[i][j][k]; qreal p = (c.real() - min) / (max - min) * 255.0; { QVector3D oldPixel = cp.pixel(k, j, result); QVector3D newPixel; switch (i / 2) { case 0: newPixel.setX(p); break; case 1: newPixel.setY(p); break; case 2: newPixel.setZ(p); break; default: break; } cp.setPixel(k, j, result, cp.merge(oldPixel, newPixel)); } } } } result = result.rgbSwapped(); PhotoWindow *pw = new PhotoWindow(result, title + ", IFDCT", p); return pw; }
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(); }
DisplayWindow *ContrastFilter::apply(QString windowBaseName) { QImage result(mImg.size(), mFormat); if (mFormat == QImage::Format_Indexed8 || mFormat == QImage::Format_Mono) { result.setColorTable(mImg.colorTable()); } ColorParser cp(mFormat); float c = std::tan((float)mValue / 100.0f); qDebug() << "contrast:" << c; QVector<int> lut; lut.reserve(256); for (int i = 0; i < 256; i++) { lut << qBound(0, (int)(c * (i - 127) + 127), 255); } for (int x = 0; x < mImg.width(); x++) { for (int y = 0; y < mImg.height(); y++) { QVector3D colorVec = cp.pixel(x, y, mImg); colorVec.setX(lut.at((int)colorVec.x())); colorVec.setY(lut.at((int)colorVec.y())); colorVec.setZ(lut.at((int)colorVec.z())); cp.setPixel(x, y, result, colorVec); } } // parent's parent should be MainWindow return new PhotoWindow(result, windowBaseName + ", " + name(), q_check_ptr(qobject_cast<QWidget *>(parent()->parent()))); }
HeightmapWidget::HeightmapWidget(QWidget *parent) : QGLWidget(parent) { // Load heightmap QImage img = QImage(":/heightmap.png"); vertices_by_x = img.width(); vertices_by_z = img.height(); quads_by_x = vertices_by_x - 1; quads_by_z = vertices_by_z - 1; QVector3D vertice; for(int z = 0; z < vertices_by_z; ++z) { for(int x = 0; x < vertices_by_x; ++x) { QRgb color = img.pixel(x, z); vertice.setX((MAP_SIZE * x / vertices_by_x) - MAP_SIZE / 2); vertice.setY(2.0 * qGray(color) / 255); vertice.setZ((MAP_SIZE * z / vertices_by_z) - MAP_SIZE / 2); m_vertices.push_back(vertice); } } // Timer settings connect(&timer, SIGNAL(timeout()), this, SLOT(updateGL())); timer.start(20); frame_count = 0; last_count = 0; last_time = QTime::currentTime(); }
/** * @brief GameWindow::initTrees, Lorsque le fichier binaire est vide, initialise les arbres des différentes saisons pour la fenêtre. */ void GameWindow::initTrees() { tree = new GameObject**[FileManager::NB_TERRAIN]; tree[Saison::PRINTEMPS] = new GameObject*[NB_ARBRES]; tree[Saison::ETE] = new GameObject*[NB_ARBRES]; tree[Saison::AUTOMNE] = new GameObject*[NB_ARBRES]; tree[Saison::HIVER] = new GameObject*[NB_ARBRES]; for(unsigned int j = 0 ; j < FileManager::NB_TERRAIN ; j++){ for(unsigned int i = 0 ; i < NB_ARBRES ; i++){ QVector3D pos; int rand_x, rand_y, id; rand_x = rand() % nb_vertex_width; rand_y = rand() % nb_vertex_height; id = rand_y * nb_vertex_width + rand_x; pos.setX(p[id].x); pos.setY(p[id].y); pos.setZ(p[id].z); if(j == Saison::PRINTEMPS){ tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/island_tree.ply"); }else if(j == Saison::ETE){ tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/summertree.ply"); }else if(j == Saison::AUTOMNE){ tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/autumntree.ply"); }else if(j == Saison::HIVER){ tree[j][i] = new GameObject(pos, QVector3D(0.f,0.f,0.f), QVector3D(0.1f,0.1f,0.1f), ":/wintertree.ply"); } } } }
QVector3D& cube::createVectorByPoint(PointDDD& a,PointDDD& b) { QVector3D *tmp = new QVector3D(); tmp->setX(b.getX() - a.getX()); tmp->setY(b.getY() - a.getY()); tmp->setZ(b.getZ() - a.getZ()); return *tmp; }
/*! Zooms in (moves) closer to an object. \param sceneNode Object sceneNode \param time Time (milliseconds) that takes to move to the new position */ void Camera::zoomInToObject(Ogre::SceneNode* sceneNode, float time) { if (_zoomOffTimerId != 0) { killTimer(_zoomOffTimerId); } QVector3D nodePos = UtilFunctions::ogreVector3ToQVector3d(sceneNode->getPosition()); QVector3D direction = _position - nodePos; direction.normalize(); QVector3D position = nodePos/* + direction * 1000*/; position.setY(nodePos.y() + 450); position.setZ(nodePos.z() + 800); QVector3D targetPos = nodePos; targetPos.setZ(position.z() - 1000); this->moveTo(position, targetPos, time); }
void Vizkit3DWidget::getCameraView(QVector3D& lookAtPos, QVector3D& eyePos, QVector3D& upVector) { osg::Vec3d eye, lookAt, up; osgViewer::View *view = getView(0); assert(view); view->getCamera()->getViewMatrixAsLookAt(eye, lookAt, up); eyePos.setX(eye.x()); eyePos.setY(eye.y()); eyePos.setZ(eye.z()); lookAtPos.setX(lookAt.x()); lookAtPos.setY(lookAt.y()); lookAtPos.setZ(lookAt.z()); upVector.setX(up.x()); upVector.setY(up.y()); upVector.setZ(up.z()); }
void EditCameraDialog::setCamPos(EditCameraDialog::Dim d, float amt){ QVector3D pos = parent->getCameraPos(); switch(d) { case X: pos.setX(amt); break; case Y: pos.setY(amt); break; case Z: pos.setZ(amt); break; } parent->setCameraPos(pos); }
QVector3D vector(QVector3D vPoint1, QVector3D vPoint2) { QVector3D vVector; vVector.setX(vPoint1.x() - vPoint2.x()); vVector.setY(vPoint1.y() - vPoint2.y()); vVector.setZ(vPoint1.z() - vPoint2.z()); return vVector; }
void ViewportViewPerspective::initializeViewport(const QVector3D& surfmin, const QVector3D& surfmax, int width, int height) { // add margin to max/min QVector3D diff = 0.01 * _margin * (surfmax - surfmin); QVector3D min = surfmin - diff; QVector3D max = surfmax + diff; // calculate the midpoint of the bounding box, which is used as the center of the // model for rotating the model _midpoint = 0.5 * (min + max); QVector3D panpoint = _midpoint; panpoint.setX(panpoint.x() + _panX); panpoint.setY(panpoint.y() + _panY); panpoint.setZ(panpoint.z() + _panZ); // calculate the distance of the camera to the center of the model, following from // the field of view from the camera float dist = sqrt((max.y() - min.y()) * (max.y() - min.y()) + (max.z() - min.z()) * (max.z() - min.z())); if (dist == 0) dist = 1E-2f; if (atan(_field_of_view) != 0) { _distance = 1.5 * dist / atan(_field_of_view); if (_distance > 1E5) _distance = 1E5; } else _distance = 1E5; // build the vertex transformation matrix from the perspective // and the angle, elevation float aspect_ratio = 1.0; if (height != 0) aspect_ratio = width / static_cast<float>(height); _proj = QMatrix4x4(); // create projection _proj.perspective(RadToDeg(_field_of_view) / _zoom, aspect_ratio, 0.1f, 40.0f); // find the camera location QMatrix4x4 model; model.translate(_panX, _panY, _panZ); model.rotate(-_elevation, 1, 0, 0); model.rotate(_angle, 0, 0, 1); _camera_location = model.map(QVector3D(max.x() + _distance, 0, 0)); // view matrix QMatrix4x4 view; view.lookAt(_camera_location, panpoint, QVector3D(0,0,1)); _view = view; finishSetup(); }
QVector3D Transformation::crossProduct(QVector3D a, QVector3D b) { QVector3D result = QVector3D(); result.setX(a.y()*b.z() - b.y()*a.z()); result.setY(a.x()*b.z() - b.x()*a.z()); result.setZ(a.x()*b.y() - b.x()*a.y()); return result; }
void CCamera::updateCameraWhenInGlobeLinkage() { QVector3D earthPoint; // camera location in global coordinate system camLon = camGlobeOrbitAzim; camLat = camGlobeOrbitElev; camAlt = camGlobeOrbitRad; camX = camGlobeX; camY = camGlobeY; camZ = camGlobeZ; // get camera position vector (QVector3D) camPosition.setX(camX); camPosition.setY(camY); camPosition.setZ(camZ); camPerspectiveX = camGlobeX; camPerspectiveY = camGlobeY; camPerspectiveZ = camGlobeZ; if (camMode==CAM_MODE_ORBIT) { camPerspectiveLookAtX = 0.0; camPerspectiveLookAtY = 0.0; camPerspectiveLookAtZ = 0.0; } else { camPerspectiveLookAtX = camPerspectiveX + camGlobeFreeDirX*1000000.0; camPerspectiveLookAtY = camPerspectiveY + camGlobeFreeDirY*1000000.0; camPerspectiveLookAtZ = camPerspectiveZ + camGlobeFreeDirZ*1000000.0; } // get looking direction vector camLookingDirectionNormal.setX(camPerspectiveLookAtX - camGlobeX); camLookingDirectionNormal.setY(camPerspectiveLookAtY - camGlobeY); camLookingDirectionNormal.setZ(camPerspectiveLookAtZ - camGlobeZ); camLookingDirectionNormal.normalize(); // distance to earth point earthPoint.setX(earthPointX); earthPoint.setY(earthPointY); earthPoint.setZ(earthPointZ); camDistanceToEarthPoint = (camPosition-earthPoint).length(); // camera altidute relative to earth surface camAltGround = camAlt - CONST_EARTH_RADIUS; // camera velocity in free look (depends on altitude) if (camVelFromAlt) { camVel = camAltGround/10.0; if (camVel<0.0) camVel *= -1.0; } emit SIGNALupdateFovAndCamVel(camFOV, camVel); emit SIGNALupdateCameraInfo(camLon, camLat, camAltGround, camDistanceToEarthPoint); updateCameraZBuffer(); }
void Camera::moveXY(QPoint p) { QVector3D v = step_; v.setZ(0.0); v.normalize(); pos_ += v*(p.ry()*0.003f); v[0] = step_[1]; v[1] = -step_[0]; v.normalize(); pos_ -= v*(p.rx()*0.003f); }
void MathUtil::NormSphereToCartesian(const float thetadeg, const float phideg, QVector3D & p) { const float thetarad = MathUtil::DegToRad(thetadeg); const float phirad= MathUtil::DegToRad(phideg); p.setX( sinf(phirad) * cosf(thetarad) ); p.setY( cosf(phirad) ); p.setZ( sinf(phirad) * sinf(thetarad) ); }
void ModelInterface::initialize(const aiScene* scene) { QVector<QVector3D> vertices; QVector<QVector3D> _bones; /// Vertices for(int i = 0; i < scene->mNumMeshes; ++i) { for(int j = 0; j < scene->mMeshes[i]->mNumVertices; ++j) vertices.append(QVector3D(scene->mMeshes[i]->mVertices[j].x, scene->mMeshes[i]->mVertices[j].y, scene->mMeshes[i]->mVertices[j].z)); } // find min and max QVector3D minVertex; QVector3D maxVertex; for(int i = 0; i < vertices.count(); ++i) { if(vertices[i].x() < minVertex.x()) // min X minVertex.setX(vertices[i].x()); if(vertices[i].y() < minVertex.y()) // min Y minVertex.setY(vertices[i].y()); if(vertices[i].z() < minVertex.z()) // min Z minVertex.setZ(vertices[i].z()); if(vertices[i].x() > maxVertex.x()) // max X maxVertex.setX(vertices[i].x()); if(vertices[i].y() > maxVertex.y()) // max Y maxVertex.setY(vertices[i].y()); if(vertices[i].z() > maxVertex.z()) // max Z maxVertex.setZ(vertices[i].z()); } header.boundingBoxMin = minVertex; header.boundingBoxMax = maxVertex; header.center = (maxVertex + minVertex) / 2; }
void MyGLWidget::keyPressEvent(QKeyEvent *event) { GLfloat cameraSpeed = 1.0f ; QVector3D cross ; bool changedFront = false ; switch ( event->key()) { case Qt::Key_W : cameraPos += cameraSpeed * cameraFront ; break ; case Qt:: Key_S : cameraPos -= cameraSpeed * cameraFront ; break ; case Qt::Key_A : cross = cross.crossProduct(cameraFront , cameraUp) ; cross.normalize(); cameraPos -= cross * cameraSpeed ; break ; case Qt::Key_D : cross = cross.crossProduct(cameraFront , cameraUp) ; cross.normalize(); cameraPos += cross * cameraSpeed ; break ; case Qt::Key_Up : pitch += 1 ; changedFront = true ; break ; case Qt::Key_Down : pitch -= 1 ; changedFront = true ; break ; case Qt::Key_Left : yaw -= 1 ; changedFront = true ; break ; case Qt::Key_Right : yaw += 1 ; changedFront = true ; break ; case Qt::Key_P : paused = !paused ; break ; case Qt::Key_R : cameraPos = QVector3D(0.0f, 0.0f, 3.0f); cameraFront = QVector3D(0.0f, 0.0f, -1.0f); cameraUp = QVector3D(0.0f, 1.0f, 0.0f); break ; default : QGLWidget::keyPressEvent(event) ; } if (changedFront) { QVector3D front; front.setX ( cos(pitch*(M_PI/180)) * cos(yaw*(M_PI/180)) ); front.setY ( sin(pitch*(M_PI/180) ) ); front.setZ ( cos(pitch*(M_PI/180)) * sin(yaw*(M_PI/180)) ); front.normalize(); cameraFront = front ; } }
void Camera::calcCameraAxis() { QVector3D dir = (m_targetCamera - m_cameraPos).normalized(); QVector3D up; if(dir.x() != 0. || dir.y() != 0.) up.setZ( 1.0 ); else up.setX( -1.0 );// Special case: looking straight up or down z axis m_right = QVector3D::crossProduct(dir, up).normalized(); m_up = QVector3D::crossProduct(m_right, dir).normalized(); }
void Box::mold(QVector3D v, float moldPlateau) { float x = fabs(v.x()); float z = fabs(v.z()); float rad = INVERT(moldPlateau * (m_overallObjectDimensions.y() / 2 +((sqrt(x) * sqrt(z)) + atan2(180, 180) / PI) )/m_overallObjectDimensions.y()); v.setX(v.x() * rad); v.setZ(v.z() * rad); glVertex3fv(&v[0]); }
void HalfEdgeStructure::calculatePerFaceNormals() { HalfEdgeStructure::t_faces::iterator i = m_faces.begin(); const HalfEdgeStructure::t_faces::const_iterator iEnd = m_faces.end(); for(; i != iEnd; ++i) { // calc face normal // TODO QVector3D *v0 = i->he->vertex; QVector3D *v1 = i->he->next->vertex; QVector3D *v2 = i->he->prev->vertex; QVector3D a; a.setX(v1->x() - v0->x()); a.setY(v1->y() - v0->y()); a.setZ(v1->z() - v0->z()); QVector3D b; b.setX(v2->x() - v0->x()); b.setY(v2->y() - v0->y()); b.setZ(v2->z() - v0->z()); i->normal = QVector3D::normal(a, b); } }
// maps the specified mouse position to the sphere defined // with center and radius. the resulting vector lies on the // surface of the sphere. QVector3D ArcBall::map_sphere( int x, int y ) { float tmpx = ( x * m_adjust_width ) - 1.0; float tmpy = 1.0 - ( y * m_adjust_height ); float length = ( tmpx * tmpx ) + ( tmpy * tmpy ); QVector3D bm; if ( length > 1.0 ) { float norm = 1.0 / sqrt( length ); bm.setX( tmpx * norm ); bm.setY( tmpy * norm ); bm.setZ( 0.0 ); } else { bm.setX( tmpx ); bm.setY( tmpy ); bm.setZ( sqrt( 1.0 - length ) ); } return bm; }
void ImuData::pollImu() { while(imu_->IMURead()) { RTIMU_DATA imuData = imu_->getIMUData(); if(pressure_) pressure_->pressureRead(imuData); QVector3D p; p.setX(imuData.fusionPose.x()*180.0/M_PI); p.setY(imuData.fusionPose.y()*180.0/M_PI); p.setZ(imuData.fusionPose.z()*180.0/M_PI); setPose(p); } }
void Box::twist(QVector3D v, float maxAngle) { float rad = - (m_overallObjectDimensions.y() / 2 + v.y())/m_overallObjectDimensions.y() * DEGREE_TO_RAD(maxAngle); float x = (cos(rad) * v.x()) - (sin(rad) * v.z()); float y = (sin(rad) * v.x()) + (cos(rad) * v.z()); v.setX(x); v.setZ(y); v.setY(v.y()); glVertex3fv(&v[0]); }