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


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

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


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

示例1: setup

void PerspectiveProjection::setup(QVector3D position, QVector3D view, QVector3D up, qreal aspectRatio) {
	qreal hfov = qTan(m_fov * 0.5);

	m_origin = position;

	m_xVector = QVector3D::normal(up, view) * (hfov * aspectRatio * 2.0);
	m_yVector = -up.normalized() * (hfov * 2.0);

	m_corner = view.normalized() - (m_xVector * 0.5) - (m_yVector * 0.5);
}
开发者ID:falbrechtskirchinger,项目名称:librayvision,代码行数:10,代码来源:perspectiveprojection.cpp

示例2: 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

示例3: limit

QVector3D Bird::limit(QVector3D vec, float limit)
{
    QVector3D temp;
    if(vec.length() < limit)
        //if(vec.x() < limit && vec.y() < limit && vec.z() < limit )
    {
        return vec;
    }
    else
    {
        /*if(vec.x() > limit )
        {
            vec.setX(limit);
        }
        if(vec.y() > limit)
        {
            vec.setY(limit);
        }
        if(vec.z() > limit)
        {
            vec.setZ(limit);
        }*/
        temp = vec.normalized();
        //temp*= limit;
        return temp;
    }
}
开发者ID:GriffinLedingham,项目名称:Picking,代码行数:27,代码来源:bird.cpp

示例4: assert

cv::Vec3f AreaLight::getIntensity(QVector3D direction) const
{
    float c = QVector3D::dotProduct(direction.normalized(), normal.normalized()) / direction.lengthSquared() * normal.length();
    assert(!isnan(c));
    if(c < 0) c = 0;
    return c * intensity;
}
开发者ID:gidoca,项目名称:renderer,代码行数:7,代码来源:arealight.cpp

示例5: setMotionAdjustment

void Camera::setMotionAdjustment(const QVector3D& vector)
{
    Q_D(Camera);
    if (d->motionAdjustment != vector) {
        d->motionAdjustment = vector;
        if (vector.x() == 0.0f && vector.y() == 0.0f) {
            // If the vector is centered, then don't perform any rotations.
            d->motionQuaternion = QQuaternion();
        } else {
            // Determine the pan and tilt angles from the vector.
            QVector3D view = -vector.normalized();
            if (view.z() < 0.0f)
                view = -view;
            qreal xangle = asin(view.x()) * 180.0f / M_PI;
            qreal yangle = asin(-view.y()) * 180.0f / M_PI;

            // Construct the pan and tilt quaternions.
            if (qFuzzyIsNull(xangle))
                d->motionQuaternion = tilt(yangle);
            else if (qFuzzyIsNull(yangle))
                d->motionQuaternion = pan(xangle);
            else
                d->motionQuaternion = tilt(yangle) * pan(xangle);
        }
        emit viewChanged();
    }
}
开发者ID:kaltsi,项目名称:qt-mobility,代码行数:27,代码来源:camera.cpp

示例6: setDirectionalLight

    void GlobalShaderUniforms::setDirectionalLight(const QVector3D &vec)
    {
        QVector3D temp = vec.normalized();
        if ( m_vecDirectionalLight == temp )
            return;

        m_vecDirectionalLight = temp;
        m_bNeedsUpload = true;
    }
开发者ID:x6herbius,项目名称:calliper,代码行数:9,代码来源:globalshaderuniforms.cpp

示例7: init

void GravityDemo::init() {
    Scene::Instance().addCamera(QVector3D(-3740.57, 0.225304, 2.12885),
                                QVector3D(0.987211, 0.0453626, -0.152828));

    Scene::Instance().getCurrentCamera()->farClip = 100000.0;
    Scene::Instance().getCurrentCamera()->updatePerspective();

    float sunDistance = 1.496e+8;
    float moonDistance = 356400;

    sunDistance /= 4.0;
    moonDistance /= 4.0;

    SimPlanet * moon = new SimPlanet("Earth/MoonMap_2500x1250.jpg", QVector3D(-sunDistance,0,moonDistance), 1737.1);
    moon->mass = 7.3477e+22;
    QVector3D moonDir = QVector3D(moonDistance - sunDistance, 0, 0) - moon->position;
    //    moon->velocity = 1022 * moonDir.normalized();
    moon->velocity = 30 * moonDir.normalized();
    planets.push_back(moon);

    SimPlanet * earth = new SimPlanet("earthmap1k.jpg", QVector3D(-sunDistance,0,0), 6371);
    earth->mass = 5.9736e+24;

    QVector3D earthDir = QVector3D(0, 0, -sunDistance) - earth->position;
    //    moon->velocity = 1022 * moonDir.normalized();
    earth->velocity = 3 * earthDir.normalized();

    planets.push_back(earth);

    SimPlanet * sun = new SimPlanet("Planets/sun.jpg", QVector3D(0,0,0), 6.96342e+5);
    sun->mass = 1.9891e+30;
    planets.push_back(sun);

    foreach (SimPlanet * planet, planets)
        planet->init();

    simulationTimer = new QTimer();
    connect(simulationTimer, SIGNAL(timeout()), this, SLOT(simulatePlanets()));
    simulationTimer->start(0);

    Scene::Instance().initSkyShaderSphere("spheremaps/nasa-sky.jpg");

}
开发者ID:jaccen,项目名称:liblub,代码行数:43,代码来源:gravity.cpp

示例8: uvInTriangle

/*!
    Returns true if this triangle contains \a point; false otherwise.
    To contain the \a point means that:
    \list
    \li the point lies on the same plane as the triangle, and
    \li the point
        \list
        \li lies either wholly within the triangle, or
        \li lies on one of the sides, or
        \li coincides with one of the 3 vertices
        \endlist
    \endlist

    \sa intersects()
*/
bool QTriangle3D::contains(const QVector3D &point) const
{
    // Check if the point is on the triangle's plane first.
    QVector3D normal = QVector3D::crossProduct(m_q - m_p, m_r - m_q);
    if (!qFuzzyIsNull(float(QVector3D::dotProduct(normal.normalized(), m_p - point))))
        return false;

    // Compute the barycentric co-ordinates and use them to determine
    // if the point is within the triangle.
    return uvInTriangle(uv(point));
}
开发者ID:Distrotech,项目名称:qt3d,代码行数:26,代码来源:qtriangle3d.cpp

示例9: fn

Connection::Connection( QVector3D fn, QVector3D diff, float v ) :
    fn( fn ),
    diff( diff ),
    v( v )
{
       QVector3D diffn = diff.normalized();

       r=qAbs(diffn.x());
       g=qAbs(diffn.y());
       b=qAbs(diffn.z());
}
开发者ID:dmastrovito,项目名称:braingl,代码行数:11,代码来源:connection.cpp

示例10: fromAxisAndAngle

/*!
    Creates a normalized quaternion that corresponds to rotating through
    \a angle degrees about the specified 3D \a axis.
*/
QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
{
    // Algorithm from:
    // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56
    // We normalize the result just in case the values are close
    // to zero, as suggested in the above FAQ.
    qreal a = (angle / 2.0f) * M_PI / 180.0f;
    qreal s = qSin(a);
    qreal c = qCos(a);
    QVector3D ax = axis.normalized();
    return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
}
开发者ID:phen89,项目名称:rtqt,代码行数:16,代码来源:qquaternion.cpp

示例11:

void SS3DWidget::camMoveAroundCenter(const QVector3D& tt)
{
	QVector3D xv = QVector3D::crossProduct((m_cam_center - m_cam_eye), m_cam_up).normalized();
	QVector3D yv = QVector3D::crossProduct(xv, (m_cam_center - m_cam_eye)).normalized();
	QVector3D xyTrans = xv * tt.x() + yv * tt.y();
	double r = (m_cam_eye - m_cam_center).length() * (1 - 0.1 * tt.z()) / 
		(m_cam_eye + xyTrans - m_cam_center).length();
	QVector3D new_cam_eye = (m_cam_eye + xyTrans - m_cam_center) * r + m_cam_center;
	m_cam_up = yv.normalized();

	if(!qFuzzyCompare((new_cam_eye - m_cam_center).normalized(), m_cam_up.normalized()))
		m_cam_eye = new_cam_eye;
}
开发者ID:YANG-H,项目名称:straight-skeleton,代码行数:13,代码来源:ss3dwidget.cpp

示例12: setForward

void QGLXCamera::setForward(QVector3D dir)
{
    m_direction = dir.normalized();

    m_verticalAngle = asin(m_direction.y());
    m_horizontalAngle = acos(m_direction.z() / cos(m_verticalAngle));

    m_right = QVector3D(
        sin(m_horizontalAngle - M_PI/2.0),
        0,
        cos(m_horizontalAngle - M_PI/2.0)
    ).normalized();
    m_compileViewMatrix();
}
开发者ID:alexander-jones,项目名称:NCV,代码行数:14,代码来源:qglxcamera.cpp

示例13: mouseMoveEvent

void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
	if ((event->buttons() & Qt::RightButton) && dragging) {
		double xtrans = (event->pos().x() - lastPoint.x()) / 1000.0;
		double ytrans = -(event->pos().y() - lastPoint.y()) / 1000.0; //Qt y-coord is inverted
		QVector4D trans(xtrans, ytrans, 0, 1);
		QVector4D worldTrans = trans * camera->getCameraMatrix();
		if(cameraActive) {
            this->camera->setpointOfInterest(scene->getMainBoat()->getPosition());
			this->camera->translate(-worldTrans.x(), -worldTrans.y(), -worldTrans.z());

			updateGL();
		} else {
			emit translate(worldTrans.x(), worldTrans.y(), worldTrans.z());
		}
	}

//	if ((event->buttons() & Qt::LeftButton) && dragging) {
		//Here we implement the trackball. Sample two points on the sphere and
		//calculate their angle to use as the rotation.

		//normalize to intervals [-1,1]
		double lastx = clampUnit(lastPoint.x() / (this->size().width() / 2.0) - 1.0);
		double lasty = clampUnit(-(lastPoint.y() / (this->size().height() / 2.0) - 1.0));

		double newx = clampUnit(event->pos().x() / (this->size().width() / 2.0) - 1.0);
		double newy = clampUnit(-(event->pos().y() / (this->size().height() / 2.0) - 1.0));

		//Project the two points into the sphere (or the hyperbolic plane)
		QVector3D v1(lastx, lasty, z(lastx, lasty));
		v1.normalize();
		QVector3D v2(newx, newy, z(newx, newy));
		v2.normalize();

		//Determine the normal of the generated plane through the center of the sphere
		QVector3D normal = QVector3D::crossProduct(v1, v2);
		double theta = acos(QVector3D::dotProduct(v1, v2)) / 3.0;

		//angle/2.0, because the quats double cover SO(3)
		QQuaternion newRot = QQuaternion(cos(theta/2.0), sin(theta/2.0) * normal.normalized());
		QQuaternion cameraQuat = M4toQuat(camera->getCameraMatrix());
		QQuaternion worldQuat = cameraQuat.conjugate() * newRot * cameraQuat;
		if(cameraActive) {
			this->camera->rotate(newRot);
			updateGL();
		} else {
			emit rotate(&worldQuat);
		}
//	}
}
开发者ID:TheSlothExperience,项目名称:SheepBattleBoats,代码行数:50,代码来源:glwidget.cpp

示例14: 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

示例15: pointInDirection

void GLGameModel::pointInDirection(QVector3D d)
{
    if(d.isNull())
    {
        setAngleY(0.0);
        return;
    }

    // roate the object to point in direction
    // we only rotate in the x-z plane
    float cos_y = d.normalized().z();
    setAngleY(360.0 * qAcos(cos_y) / (2*M_PI));

    //qDebug() << "pointing to" << d << "with angles" << angleX << angleY << angleZ;
}
开发者ID:rku,项目名称:Settleboard,代码行数:15,代码来源:GLGameModel.cpp


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