示例#1
0
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);
	}
}
示例#2
0
/**
* @brief: Get polygon axis aligned bounding box
* @return: The dimensions of the AABB 
**/
QVector3D Polygon3D::getLoopAABB(Loop3D &pin, QVector3D &minCorner, QVector3D &maxCorner)
{
	maxCorner = QVector3D(-FLT_MAX, -FLT_MAX, -FLT_MAX);
	minCorner = QVector3D( FLT_MAX,  FLT_MAX,  FLT_MAX);

	QVector3D curPt;

	for(int i=0; i<pin.size(); ++i){
		curPt = pin.at(i);
		if( curPt.x() > maxCorner.x() ){
			maxCorner.setX(curPt.x());
		}
		if( curPt.y() > maxCorner.y() ){
			maxCorner.setY(curPt.y());
		}
		if( curPt.z() > maxCorner.z() ){
			maxCorner.setZ(curPt.z());
		}
		//------------
		if( curPt.x() < minCorner.x() ){
			minCorner.setX(curPt.x());
		}
		if( curPt.y() < minCorner.y() ){
			minCorner.setY(curPt.y());
		}
		if( curPt.z() < minCorner.z() ){
			minCorner.setZ(curPt.z());
		}
	}
	return QVector3D(maxCorner - minCorner);
}//
示例#3
0
void myCam::aktivatePlaymode(QVector3D kugelWhite, int abstand)
{
    this->activePlaymode = true;
    this->distanz = abstand;
    this->kugelWhite = kugelWhite;

    QVector3D position;
    position.setX(kugelWhite.x());
    position.setY(kugelWhite.y());
    position.setZ(kugelWhite.z());
    if(position.x()==0 && position.y()==0 && position.z() == 0)
    {
        position.setZ(-1);
    }
    position.normalize();
    position.setX(position.x()*abstand + kugelWhite.x());
    position.setY(8);
    position.setZ(position.z()*abstand + kugelWhite.z());
    //this->viewMatrix.setToIdentity();
    //this->viewMatrix.lookAt(position,kugelWhite,QVector3D(0,1,0));
    this->queueAnimation(position,kugelWhite,100);
    position = position-kugelWhite;

    if(position.x()>0 && position.z()>0)
    {
        this->angleY = atan(position.z()/position.x())*180/3.1415926-90;
    }
    else if(position.x()<0 && position.z()>0)
    {
        this->angleY = atan(-position.x()/position.z())*180/3.1415926;
    }
    else if(position.x()<0 && position.z()<0)
    {
        this->angleY = atan(position.z()/position.x())*180/3.1415926+90;
    }
    else if(position.x()>0 && position.z()<0)
    {
        this->angleY = atan(position.x()/-position.z())*180/3.1415926+180;
    }
    else if(position.x() == 0)
    {
        if(position.z()>0)
            this->angleY = 0;
        else
            this->angleY = 180;
    }
    else if(position.z() == 0)
    {
        if(position.x()>0)
            this->angleY = 270;
        else
            this->angleY = 90;
    }
    this->angleX = 15;
    this->camRotate(0,0);
    this->freeCameramode = false;
}
示例#4
0
void QScatterDataProxyPrivate::limitValues(QVector3D &minValues, QVector3D &maxValues,
                                           QAbstract3DAxis *axisX, QAbstract3DAxis *axisY,
                                           QAbstract3DAxis *axisZ) const
{
    if (m_dataArray->isEmpty())
        return;

    const QVector3D &firstPos = m_dataArray->at(0).position();

    float minX = firstPos.x();
    float maxX = minX;
    float minY = firstPos.y();
    float maxY = minY;
    float minZ = firstPos.z();
    float maxZ = minZ;

    if (m_dataArray->size() > 1) {
        for (int i = 1; i < m_dataArray->size(); i++) {
            const QVector3D &pos = m_dataArray->at(i).position();

            float value = pos.x();
            if (qIsNaN(value) || qIsInf(value))
                continue;
            if (isValidValue(minX, value, axisX))
                minX = value;
            if (maxX < value)
                maxX = value;

            value = pos.y();
            if (qIsNaN(value) || qIsInf(value))
                continue;
            if (isValidValue(minY, value, axisY))
                minY = value;
            if (maxY < value)
                maxY = value;

            value = pos.z();
            if (qIsNaN(value) || qIsInf(value))
                continue;
            if (isValidValue(minZ, value, axisZ))
                minZ = value;
            if (maxZ < value)
                maxZ = value;
        }
    }

    minValues.setX(minX);
    minValues.setY(minY);
    minValues.setZ(minZ);

    maxValues.setX(maxX);
    maxValues.setY(maxY);
    maxValues.setZ(maxZ);
}
void FsSurfaceTreeItem::onSurfaceTranslationYChanged(float fTransY)
{
    QVector3D position = m_pRenderable3DEntity->position();
    position.setY(fTransY);
    m_pRenderable3DEntity->setPosition(position);
    m_pRenderable3DEntityNormals->setPosition(position);
}
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);
    }
}
示例#7
0
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);
    }
}
示例#8
0
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() );
}
示例#9
0
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;
}
示例#10
0
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())));
}
示例#11
0
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;

}
示例#12
0
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;
}
示例#13
0
/**
 * @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");
            }
        }
    }
}
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();
}
示例#15
0
void nodeDock::centreNode( AEntity *ent ) // places the node in the centre of the view
{
    nodeEntity *node( ent->castTo<nodeEntity*>() );

    if( node )
    {
        connect( node, SIGNAL(requestNetworkRedraw()), mScene, SLOT(update()), Qt::UniqueConnection );
        if( qFuzzyCompare( node->property("nodeEntity/pos")->toVector3D(), QVector3D( 0, 0, 0 ) ) )
        {
            // set pos to centre of screen
            QPointF pos;
            pos.setX(mView->rect().width()/2);
            pos.setY(mView->rect().height()/2);

            // get transformation matrix and invert it (viewMatrix moves the scene, so invert to move to view)
            QTransform viewMatrix = mView->getTransform();
            viewMatrix = viewMatrix.inverted();

            // map point to matrix
            pos = viewMatrix.map(pos);

            // set position
            QVector3D vectPos;
            vectPos.setX(pos.x());
            vectPos.setY(pos.y());
            node->property("nodeEntity/pos") = vectPos;
        }
        //Rebuild gui from here, rather than direct signal so only rebuild on NODE added, not just any entity
        rebuildGui();
    }
}
示例#16
0
文件: cube.cpp 项目: heroboec/cube2
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;
}
示例#17
0
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());
}
示例#18
0
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);
}
示例#19
0
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();
}
示例#21
0
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;
}
示例#22
0
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();
}
示例#23
0
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) );

}
示例#24
0
/**
* @brief: Merge consecutive vertices that are within a distance threshold to each other
**/
int Polygon3D::cleanLoop(Loop3D &pin, Loop3D &pout, float threshold=1.0f)
{	
	float thresholdSq = threshold*threshold;

	if(pin.size()<3){
		return 1;
	}

	boost::geometry::ring_type<Polygon3D>::type bg_pin;
	boost::geometry::ring_type<Polygon3D>::type bg_pout;
	boost::geometry::assign(bg_pin, pin);
	boost::geometry::correct(bg_pin);
	boost::geometry::simplify(bg_pin, bg_pout, threshold);

	//strategy::simplify::douglas_peucker

	//copy points back
	QVector3D tmpPt;
	for(size_t i=0; i< bg_pout.size(); ++i){						
		tmpPt.setX( bg_pout[i].x() );
		tmpPt.setY( bg_pout[i].y() );
		pout.push_back(tmpPt);						
	}

	//remove last point
	if( (pout[0] - pout[pout.size()-1]).lengthSquared() < thresholdSq ){
		pout.pop_back();				
	}

	//clean angles
	int next, prev;
	QVector3D cur_prev, cur_next;
	float ang;
	float angleThreshold = 0.01f;
	for(size_t i=0; i<pout.size(); ++i){
		next = (i+1)%pout.size();
		prev = (i-1+pout.size())%pout.size();
		cur_prev = pout[prev]-pout[i];
		cur_next = pout[next]-pout[i];

		ang = angleBetweenVectors(cur_prev, cur_next);
		if( (fabs(ang) < angleThreshold) 
			|| (fabs(ang - 3.14159265f ) < angleThreshold)
			|| (!(ang==ang) ) )
		{
			//std::cout << ang << " ";
			pout.erase(pout.begin() + i);
			--i;
		}
	}


	return 0;
}//
示例#25
0
void Box::bend(QVector3D v, float maxAngle)
{
    float heightY = m_overallObjectDimensions.y();
    float rad = (heightY / 2 + v.y()) / heightY * DEGREE_TO_RAD(maxAngle);
    float y = v.y();

    v.setY(cos(rad) * v.y() - sin(rad) * v.x());
    v.setX(sin(rad) * y + cos(rad) * v.x());
	
    glVertex3fv(&v[0]);
}
示例#26
0
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;
}
示例#27
0
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 ;
    }

}
bool AM3DCoordinatedSystemControl::affectedByMotionsInY() const
{
	QVector3D testStartPrimePosition(0,0,0);
	QVector3D testGlobalPosition = primeAxisToGlobal(testStartPrimePosition);

	testGlobalPosition.setY(1);
	QVector3D testEndPrimePosition = globalAxisToPrime(testGlobalPosition);

	double thisAxisStartPosition = designatedAxisValue(testStartPrimePosition);
	double thisAxisEndPosition = designatedAxisValue(testEndPrimePosition);

	return (qAbs(thisAxisStartPosition - thisAxisEndPosition) > 0.001);
}
示例#29
0
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]);
}
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);
    }
}