当前位置: 首页>>代码示例>>C++>>正文


C++ QVector3D::normalize方法代码示例

本文整理汇总了C++中QVector3D::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector3D::normalize方法的具体用法?C++ QVector3D::normalize怎么用?C++ QVector3D::normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QVector3D的用法示例。


在下文中一共展示了QVector3D::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fresnelDielectric

void Material::fresnelDielectric(const QVector3D &d, const QVector3D &normal, float ni, float nt, QVector<QPair<float, QVector3D> > &rays)
{
    QVector3D n = normal;
    float ndd = QVector3D::dotProduct(n, d);
    if (ndd > -Config::Epsilon && ndd < Config::Epsilon) {
        return ;
    }
    if (ndd > 0) {
        n *= -1;
        ndd *= -1;
    }
    QVector3D r = d - 2.0f * ndd * n;
    r.normalize();

    QVector3D z = (d - ndd * n) * ni / nt;
    float z2 = z.lengthSquared();

    if (z2 >= 1.0f) {
        rays.append(QPair<float, QVector3D>(1.0f, r));
        return ;
    }

    QVector3D t = z - qSqrt(1.0f - z2) * n;
    t.normalize();

    float ndt = QVector3D::dotProduct(n, t);
    float rPar = (nt * ndd - ni * ndt) / (nt * ndd + ni * ndt);
    float rPerp = (ni * ndd - nt * ndt) / (ni * ndd + nt * ndt);
    float fr = 0.5f * (rPar * rPar + rPerp * rPerp);

    rays.append(QPair<float, QVector3D>(fr, r));
    rays.append(QPair<float, QVector3D>(1.0f - fr, t));
}
开发者ID:john1995,项目名称:raytracer,代码行数:33,代码来源:Material.cpp

示例2: mouseMoveEvent

void Window::mouseMoveEvent(QMouseEvent *event)
{
    if (!m_mouseDown) {
        m_terrain->pick(QPointF(event->localPos().x() / 1024, event->localPos().y() / 768), m_projection, m_view);
        return;
    }

    QPointF delta = event->localPos() - m_mousePos;

    QMatrix4x4 mat;
    mat.rotate(m_camera.orientation);

    QVector3D pitchAxis = QVector3D(mat(0, 0), mat(0, 1), mat(0, 2));
    pitchAxis.normalize();

    m_camera.orientation *= QQuaternion::fromAxisAndAngle(pitchAxis, perSecond(delta.y() / 200));
    m_camera.orientation.normalize();

    QVector3D yawAxis = QVector3D(mat(1, 0), mat(1, 1), mat(1, 2));
    yawAxis.normalize();

    m_camera.orientation *= QQuaternion::fromAxisAndAngle(yawAxis, perSecond(delta.x() / 200));
    m_camera.orientation.normalize();


    m_needsUpdate = true;

    m_mousePos = event->localPos();
}
开发者ID:giucam,项目名称:trainsplanet,代码行数:29,代码来源:window.cpp

示例3: updateListenerOrientation

void QAudioEngine::updateListenerOrientation()
{
    QVector3D dir = m_listenerDirection;
    QVector3D up = m_listenerUp;
    dir.normalize();
    up.normalize();
    QVector3D u = up - dir * QVector3D::dotProduct(dir, up);
    u.normalize();
    d->setListenerOrientation(dir, u);
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:10,代码来源:qaudioengine_p.cpp

示例4: moveXY

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);
}
开发者ID:asmolen,项目名称:simulator-1,代码行数:11,代码来源:camera.cpp

示例5: keyPressEvent

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();
}
开发者ID:silencious,项目名称:Quiddiards,代码行数:53,代码来源:quiddiards.cpp

示例6: keyPressEvent

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 ;
    }

}
开发者ID:velox1992,项目名称:ARProject,代码行数:52,代码来源:MyGLWidget.cpp

示例7: rotateView

void AwesomeCamera::rotateView(float z_angle,float x_angle){

//    rotM.setToIdentity();


    double cosPhi = cos(mouse_sens*(-z_angle)/180*M_PI);
    double sinPhi = sin(mouse_sens*(-z_angle)/180*M_PI);


    direction      = QVector3D(cosPhi*direction.x()+sinPhi*direction.z(),direction.y(),
                               cosPhi*direction.z()-sinPhi*direction.x());

    QMatrix4x4 rotMat;
    rotMat.setToIdentity();
    rotMat.rotate(mouse_sens*(-x_angle),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
    QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
    tmpVec.normalize();
    double angleTheta = QVector3D::dotProduct(tmpVec,QVector3D(0,1,0));
    if(qAbs(angleTheta) < 0.9){
        rotMat.setToIdentity();
        rotMat.rotate(mouse_sens*(-x_angle)*(1-qAbs(angleTheta)),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
        QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
        tmpVec.normalize();
        direction = tmpVec;
    }

    side_direction = QVector3D(cosPhi*side_direction.x()+sinPhi*side_direction.z(),0,
                               cosPhi*side_direction.z()-sinPhi*side_direction.x());

    updown_direction = QVector3D::crossProduct(direction,side_direction);



/*
    rot_angles[0] += mouse_sens*(z_angle);//przesuniecie X
    rot_angles[1] -= mouse_sens*(x_angle);//przesuniecie Y
    if(rot_angles[1] > 90) rot_angles[1] = 90;
    if(rot_angles[1] <-90) rot_angles[1] = -90;
//    przesuniecie do przodu
    direction = QVector3D(-sin(rot_angles[0]/180*M_PI),sin(rot_angles[1]/180*M_PI),cos(rot_angles[0]/180*M_PI));
//    przesuniece na boki
    side_direction = QVector3D(sin((rot_angles[0]+90)/180*M_PI),0,-cos((rot_angles[0]+90)/180*M_PI));
//    przesuwanie gora dol
    updown_direction = QVector3D::crossProduct(direction,side_direction);
*/

    direction.normalize();
    side_direction.normalize();
    updown_direction.normalize();

}
开发者ID:Calinou,项目名称:AwesomeBump,代码行数:51,代码来源:camera.cpp

示例8: D

cv::Vec3f BlinnMaterial::brdf(const HitRecord &hit, QVector3D direction) const
{
    QVector3D normal = hit.getSurfaceNormal();
    normal.normalize();
    QVector3D wo = -hit.getRay().getDirection().normalized();
    QVector3D wi = -direction.normalized();
    if(signum(QVector3D::dotProduct(normal, wo)) != signum(QVector3D::dotProduct(normal, wi)))
    {
        return cv::Vec3f();
    }
    if(QVector3D::dotProduct(normal, wo) < 0) normal *= -1;
    QVector3D wh = wi + wo;
    wh.normalize();
    return kd * (1 / M_PI) + ks * D(wh, normal) * G(wi, wo, normal) / (4 * QVector3D::dotProduct(wo, normal) * QVector3D::dotProduct(wi, normal));
}
开发者ID:gidoca,项目名称:renderer,代码行数:15,代码来源:blinnmaterial.cpp

示例9: meshChanged

void LightRendererFlat::meshChanged(const QVector<MeshLoader::Face> &faces){
    storedFaces.clear();

    for (MeshLoader::Face f : faces){
        Face newFace;
        for (int i = 0; i < 3; i++){
            newFace[i].position.setX(f[i].x);
            newFace[i].position.setY(f[i].y);
            newFace[i].position.setZ(f[i].z);
            newFace[i].position.setW(1.0);
            newFace[i].color.setX(f[i].r);
            newFace[i].color.setY(f[i].g);
            newFace[i].color.setZ(f[i].b);
        }

        QVector3D a = newFace[0].position.toVector3D();
        QVector3D b= newFace[1].position.toVector3D();
        QVector3D c = newFace[2].position.toVector3D();
        QVector3D normal = QVector3D::crossProduct(b - a, c - a);
        normal.normalize();
        newFace[0].normal = normal;
        newFace[1].normal = normal;
        newFace[2].normal = normal;

        storedFaces.append(newFace);
    }
}
开发者ID:marvatom,项目名称:GDV,代码行数:27,代码来源:abgabe3b.cpp

示例10: _generateMeshVertices

void SimpleRoadGraph::_generateMeshVertices(ucore::TextureManager* textureManager) {
	ucore::RenderableQuadList* renderable = new ucore::RenderableQuadList(textureManager->get("data/textures/street.jpg"));

	roadGraphEdgeIter ei, eend;
	for (boost::tie(ei, eend) = boost::edges(myRoadGraph); ei != eend; ++ei) {
		SimpleRoadGraphEdge* edge = &myRoadGraph[*ei];

		QVector3D pt1 = myRoadGraph[boost::source(*ei, myRoadGraph)].getPt();
		QVector3D pt2 = myRoadGraph[boost::target(*ei, myRoadGraph)].getPt();

		QVector3D vec = pt2 - pt1;
		vec = QVector3D(-vec.y(), vec.x(), 0.0f);
		vec.normalize();

		QVector3D p0 = pt1 + vec * edge->getWidth() / 2.0f + QVector3D(0, 0, heightAboveGround);
		QVector3D p1 = pt1 - vec * edge->getWidth() / 2.0f + QVector3D(0, 0, heightAboveGround);
		QVector3D p2 = pt2 - vec * edge->getWidth() / 2.0f + QVector3D(0, 0, heightAboveGround);
		QVector3D p3 = pt2 + vec * edge->getWidth() / 2.0f + QVector3D(0, 0, heightAboveGround);
		QVector3D normal = ucore::Util::calculateNormal(p0, p1, p2);

		//renderable2->addQuad(p0, p1, p2, p3, normal, color);
		renderable->addQuad(p0, p1, p2, p3, normal, 0, 1, 0, 1);
	}

	renderables.push_back(renderable);
}
开发者ID:gnishida,项目名称:CityDesigner,代码行数:26,代码来源:SimpleRoadGraph.cpp

示例11: CalcNormals

void utils::CalcNormals(const unsigned int* pIndices, unsigned int IndexCount,
                        VertexTex *pVertices, unsigned int VertexCount)
{
    unsigned int Index0;
    unsigned int Index1;
    unsigned int Index2;

    // Accumulate each triangle normal into each of the triangle vertices
    for (unsigned int i = 0; i < IndexCount; i += 3)
    {
        Index0 = pIndices[i];
        Index1 = pIndices[i+1];
        Index2 = pIndices[i+2];
        QVector3D v1 = pVertices[Index1].getPos() - pVertices[Index0].getPos();
        QVector3D v2 = pVertices[Index2].getPos() - pVertices[Index0].getPos();
        QVector3D Normal = QVector3D::crossProduct(v1, v2);
        Normal.normalize();

        pVertices[Index0].setNormal(pVertices[Index0].getNormal()+Normal);
        pVertices[Index1].setNormal(pVertices[Index1].getNormal()+Normal);
        pVertices[Index2].setNormal(pVertices[Index2].getNormal()+Normal);
    }

    // Normalize all the vertex normals
    for (unsigned int i = 0; i < VertexCount; i++) {
        pVertices[i].setNormal(pVertices[i].getNormal().normalized());
        qDebug() << "normal " << pVertices[i].getNormal();
    }
}
开发者ID:Imarion,项目名称:NormalMapTest,代码行数:29,代码来源:utils.cpp

示例12: ks

vector<QVector3D> LayeredHairMesh::internalForces(const vector<QVector3D> &state) const
{
	vector<QVector3D> ifs(state.size(), QVector3D());
	float ks(5), kd(2), ko(1);
	int compSize = state.size() / 2;
	float lenSeg = compSize / seg;
	for (int i = 4; i < compSize; i ++)
	{
		// Spring restriction
		QVector3D dir = state[i - 4] - state[i];
		float deltaLen = dir.length() - restLen[i];
		dir.normalize();// *deltaLen;
		QVector3D fs = ks * dir * deltaLen;
		QVector3D fd = kd *
			QVector3D::dotProduct(
			state[i - 4 + compSize] - state[i + compSize], dir) * dir;

		// Constrant to original mesh
		float segU = (1 - (float)(i / seg) / lenSeg);
		QVector3D distDir = (points[i] - state[i]) * ko;

		ifs[i] = state[i + compSize];
		ifs[i + compSize] += fs + fd - state[i + compSize] * 0.1 + distDir;
		ifs[i - 4 + compSize] -= fs + fd;
	}
	for (int i = 0; i < 4; i++)
	{
		ifs[i] = QVector3D();
		ifs[i + compSize] = QVector3D();
	}
	return ifs;
}
开发者ID:ShenyaoKe,项目名称:GeometricModeling,代码行数:32,代码来源:HairMesh.cpp

示例13: update

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);
    }
}
开发者ID:znoraka,项目名称:SexyDwarfEngine,代码行数:29,代码来源:bulletcomponent.cpp

示例14: align

QVector3D Bird::align(QVector<Bird> birds)
{
    float neighbordist = 50;
    QVector3D sum = QVector3D(0,0,0);
    int count = 0;
    QVector<Bird>::iterator bird;
    for(bird = birds.begin(); bird != birds.end(); bird++)
    {
        float d = (position - (*bird).position).length();
        if ((d > 0) && (d < neighbordist)) {
            sum+= (*bird).velocity;
            count++;
        }
    }
    if (count > 0)
    {
        sum /= (float)count;
        sum.normalize();
        sum *= maxvelocity;
        QVector3D steer = sum-velocity;
        limit(steer,maxforce);
        return steer;
    }
    else
    {
        return QVector3D(0,0,0);
    }
}
开发者ID:GriffinLedingham,项目名称:Picking,代码行数:28,代码来源:bird.cpp

示例15: addFace

void SphericalCalculator::addFace(std::vector<Face> &faces,const Point &a,const Point &b,const Point &c)
{
    Face f;
    f.x[0][0]=a.x[0];
    f.x[0][1]=a.x[1];
    f.x[0][2]=a.x[2];

    f.x[1][0]=b.x[0];
    f.x[1][1]=b.x[1];
    f.x[1][2]=b.x[2];

    f.x[2][0]=c.x[0];
    f.x[2][1]=c.x[1];
    f.x[2][2]=c.x[2];

    QVector3D aa(f.x[0][0],f.x[0][1],f.x[0][2]);
    QVector3D bb(f.x[1][0],f.x[1][1],f.x[1][2]);
    QVector3D cc(f.x[2][0],f.x[2][1],f.x[2][2]);

    QVector3D nv;
    nv=-QVector3D::crossProduct(bb-aa,cc-aa);
    nv.normalize();
    f.n[0]=nv.x();
    f.n[1]=nv.y();
    f.n[2]=nv.z();
    
     faces.push_back(f);
    
}
开发者ID:bkubicek,项目名称:sphericalator,代码行数:29,代码来源:sphericalcalculator.cpp


注:本文中的QVector3D::normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。