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


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

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


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

示例1: QScriptValue

static QScriptValue scriptVGE2AddVertices(QScriptContext *context, QScriptEngine *)
{
    if(context->argumentCount() != 1 || !context->argument(0).isArray())
    {
        context->throwError("addVertices - invalid parameters");
        return QScriptValue();
    }

    int verticesCount = context->argument(0).property("length").toInt32();

    QVector<grVertex> vertices;
    vertices.resize(verticesCount);

    for(int i = 0; i < verticesCount; i++)
    {
        if(!context->argument(0).property(i).isObject())
        {
            context->throwError("addVertices - invalid parameters");
            return QScriptValue();
        }
        else
        {
            fromScriptValue_grVertex(context->argument(0).property(i), vertices[i]);
        }
    }

    for(int i = 0; i < verticesCount; i++)
    {
        for(int j = 0; j < qvGraphVertices.size(); j++)
        {
            QVector3D vecDifference = vertices[i].vecOrigin - qvGraphVertices[j].vecOrigin;
            if(vecDifference.length() < 15.0f)
            {
                context->throwError("addVertices - invalid parameters");
                return QScriptValue();
            }
        }
    }

    for(int i = 0; i < verticesCount; i++)
        for(int j = 0; j < verticesCount; j++)
            if(i != j)
            {
                QVector3D vecDifference = vertices[i].vecOrigin - vertices[j].vecOrigin;
                if(vecDifference.length() < 15.0f)
                {
                    context->throwError("addVertices - invalid parameters");
                    return QScriptValue();
                }
            }

    for(int i = 0; i < verticesCount; i++)
        qvGraphVertices.push_back(vertices[i]);

    needToRebuildRD = true;
    globalStackIsModified++;

    return QScriptValue();
}
开发者ID:Ekventor,项目名称:vge2,代码行数:59,代码来源:scriptmanager.cpp

示例2: CartesianToSphere

void MathUtil::CartesianToSphere(const QVector3D & p, float & thetadeg, float & phideg, float & r)
{

    thetadeg = MathUtil::RadToDeg(atan2f(p.z(), p.x()));
    phideg = MathUtil::RadToDeg(acosf(p.y() / p.length()));
    r = p.length();

}
开发者ID:jaxzin,项目名称:firebox,代码行数:8,代码来源:mathutil.cpp

示例3: calcMinimumAngle

float WireCreator::calcMinimumAngle(QVector3D point, QPair<QVector3D, QVector3D> box)
{
    float maxY=qMax(box.first.y(),box.second.y())+0.3f;
    if(point.length()<maxY) return 0;
    float angle=qAsin(maxY/point.length());
    return angle;

}
开发者ID:akuchinke,项目名称:wire_bender,代码行数:8,代码来源:wirecreator.cpp

示例4: qSameDirection

static inline bool qSameDirection(const QVector3D &a , const QVector3D &b)
{
    bool res = false;
    if (!a.isNull() && !b.isNull())
    {
        float dot = QVector3D::dotProduct(a, b);
        res = qFskCompare((qreal)dot, a.length() * b.length());
    }
    return res;
}
开发者ID:slavablind91,项目名称:code,代码行数:10,代码来源:qglsection.cpp

示例5: acos

std::vector<float> BresenhamRayCaster::cast(QVector3D& location, QVector3D& direction, Volume& data, QVector2D& angle)
{
	std::vector<float> samples;

	float value = 0.0;
	QVector3D current = QVector3D(location);

	//Code to compute angle out of direction vector, now implemented as Parameter of this function, due computational expenses and accuraccy
	/*
	QVector2D xz_dir = QVector2D(direction.x(), direction.z());
	double xz_angle = QVector2D().dotProduct(xz_dir.normalized(), QVector2D(0, 1));
	xz_angle = acos(xz_angle) * 57.2957549;
	*/
	
	int width = data.width();
	int height = data.height();
	int depth = data.depth();

	float factorX = cos(angle.y() * 0.0174533);
	float factorZ = sin(angle.y() * 0.0174533);

	float factorX_Y = cos(angle.x() * 0.0174533);
	float factorX_Z = sin(angle.x() * 0.0174533);

	int steps;
	if (angle.x() > 0 || angle.y() > 0) 
	{
		QVector3D a = QVector3D(data.width() * -factorZ, data.height() * direction.y(), data.depth() * -factorX);
			QVector3D b = QVector3D(location.x() * -factorZ, location.y() * direction.y(), location.z() * -factorX);
		//QVector3D a = QVector3D(data.width() * direction.x(), data.height() * factorX_Z, data.depth() * factorX_Y);
		//QVector3D b = QVector3D(location.x() * direction.x(), location.y() * factorX_Z, location.z() * factorX_Y);
		steps = (a.length() + QVector2D(a - b).length()) / direction.length(); //nicht weit genug gesampelt?
	}
	else
	{
		steps = data.depth() / direction.length();
	}

	int i = 0;
	while (i < steps)
	{
		if (current.x() < 0 || current.x() >= width ||
			current.y() < 0 || current.y() >= height ||
			current.z() < 0 || current.z() >= depth)
			samples.push_back(0);

		value = data.value((int)current.x(), (int)current.y(), (int)current.z());

		samples.push_back(value);
		current += direction;
		i++;
	}

	return samples;
}
开发者ID:tecgyver,项目名称:Vis1,代码行数:55,代码来源:BresenhamRayCaster.cpp

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

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

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

示例9: move

void CharacterMovement::move( float time )
{
	if( !_moving )
	{
		return;
	}

	rotateTo(_destination);
	QVector3D position = _position;
	if( _distance <= 0 /*&& transitionToStop == false*/ )
	{
		//if this node isn't the last
		if( !_moveList.empty() )
		{
			_destination = _moveList[0];
			_distance = UtilFunctions::calculateDistance( position, _destination );
			if( _distance > 0.000001f )
			{
				// compute direction vector
				rotateTo(_destination);
			}

			// delete the first node on the list
			_moveList.erase( _moveList.begin() );
		}
		else
		{
			// the player arrive to last destination
			this->stopMoving();
		}
	}

	QVector3D dir = (_direction * _speed) * time;
	if( _distance > 0.000001f )//&& animationState->getAnimationName() != "Bow" )
	{
		Ogre::Real newDistance = dir.length();
		// Update player's position
		// interpolate linearly
		if( newDistance > _distance )
		{
			position = _destination;
			_distance = 0;
		}
		else
		{
			_distance -= newDistance;
			position += dir;
		}
		_position = position;
		_node->setPosition( UtilFunctions::qVector3dToOgreVector3( _position ) );
	}
	else
	{
//		if( transitionToStop )
		{
			_position = position;
			_node->setPosition( UtilFunctions::qVector3dToOgreVector3( _position ) );
		}
	}
}
开发者ID:Cnotinfor,项目名称:TopQX_3D,代码行数:60,代码来源:CharacterMovement.cpp

示例10: updateEntityLodByDistance

void UpdateLevelOfDetailJob::updateEntityLodByDistance(Entity *entity, LevelOfDetail *lod)
{
    QMatrix4x4 viewMatrix;
    QMatrix4x4 projectionMatrix;
    if (!Render::CameraLens::viewMatrixForCamera(m_manager->renderNodesManager(), lod->camera(), viewMatrix, projectionMatrix))
        return;

    const QVector<qreal> thresholds = lod->thresholds();
    QVector3D center = lod->center();
    if (lod->hasBoundingVolumeOverride() || entity->worldBoundingVolume() == nullptr) {
        center = *entity->worldTransform() * center;
    } else {
        center = entity->worldBoundingVolume()->center();
    }

    const QVector3D tcenter = viewMatrix * center;
    const float dist = tcenter.length();
    const int n = thresholds.size();
    for (int i=0; i<n; ++i) {
        if (dist <= thresholds[i] || i == n -1) {
            m_filterValue = approxRollingAverage<30>(m_filterValue, i);
            i = qBound(0, static_cast<int>(qRound(m_filterValue)), n - 1);
            if (lod->currentIndex() != i)
                lod->setCurrentIndex(i);
            break;
        }
    }
}
开发者ID:RSATom,项目名称:Qt,代码行数:28,代码来源:updatelevelofdetailjob.cpp

示例11: calculateConstraint

void springConstraint::calculateConstraint()
{
    QVector3D springConstraint = p2->getPos() - p1->getPos(); //springConstraint vector from p1 to p2
    float currLength = springConstraint.length(); //current springConstraint length
    QVector3D constrainVector = (springConstraint*(1 - restLength/currLength))/2; //bring both p1 and p2 back towards each other by one half (each) the constrain vector

        //it appears better to caclulate this AFTER all constraints have been individually calculated
        /*if(p1->allowMove && p1->updated == false)
        {
            QVector3D velocityVector = p1->pos-p1->old_pos;
            QVector3D temp = p1->pos;
            //initial position = initial position + (directional acceleration from force * timestep) + velocity damped by damping constant
            p1->pos = p1->pos + p1->accel*timestep + ((1.0-damping)*velocityVector) ;
            p1->old_pos = temp;
            //instanataneous acceleration has been used, reset to 0
            p1->accel = QVector3D(0,0,0);
            p1->updated=true;
        }

        if(p2->allowMove&& p2->updated==false)
        {
            QVector3D velocityVector = p2->pos-p2->old_pos;
            QVector3D temp = p2->pos;
            //initial position = initial position + (directional acceleration from force * timestep) + velocity damped by damping constant
            p2->pos = p2->pos + p2->accel*timestep + ((1.0-damping)*(velocityVector));
            p2->old_pos = temp;
            //instanataneous acceleration has been used, reset to 0
            p2->accel = QVector3D(0,0,0);
            p2->updated=true;
        }*/

    p1->offsetPosition(constrainVector); //send p1 out towards p2
    p2->offsetPosition(-constrainVector); //pull p2 back towards p1
}
开发者ID:GriffinLedingham,项目名称:ClothSimulation,代码行数:34,代码来源:springConstraint.cpp

示例12: drawNodes

void SceneGraph::drawNodes(DirectionNode * viewPoint) {
  QMap <qreal, Node*> transparentNodes;

//  QVector3D terrainPositon(SceneData::Instance().getCurrentCamera()->position.x(),-50,SceneData::Instance().getCurrentCamera()->position.z());
//  sceneNodes["terrain"]->setPosition(terrainPositon);

//  SceneData::Instance().updateLightBuffer();

  //TODO: Multiple lights
    foreach(Node * node, sceneNodes) {
        if(!node->transparent) {
          node->setView(viewPoint);
          setShadowCoords(node, viewPoint);
          SceneData::Instance().getShadowLight()->bindShaderUpdate(node->getMaterial()->getShaderProgram());
          node->draw();
        } else {
          QVector3D distance = node->getCenter() - SceneData::Instance().getCurrentCamera()->position;
          transparentNodes.insert(distance.length(), node);
        }
    }
    if (transparentNodes.size() > 0) {
      glEnable(GL_BLEND);
      QList<qreal> transparentKeys = transparentNodes.keys();
      qSort(transparentKeys.begin(), transparentKeys.end(), qGreater<qreal>());

      foreach(qreal transparentKey, transparentKeys) {
        Node * node = transparentNodes[transparentKey];
        node->setView(viewPoint);
//        setShadowCoords(node, viewPoint);
//        SceneData::Instance().getShadowLight()->bindShaderUpdate(
//            node->getMaterial()->getShaderProgram());
        node->draw();
      }
开发者ID:tapio,项目名称:liblub,代码行数:33,代码来源:SceneGraph.cpp

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

示例14: updateTesselation

 void TerrainTesselation::updateTesselation(){
   QVector3D camFromPlanet = SceneData::Instance().getCurrentCamera()->position - planet->position;
   float camDistance = camFromPlanet.length();

   while (camDistance < 11.01){
     SceneData::Instance().getCurrentCamera()->position += SceneData::Instance().getCurrentCamera()->position.normalized() *  0.01;
     SceneData::Instance().getCurrentCamera()->update();
   }
   int maxTess = 60;
   float tessStartDistance = 8;
   float scale = maxTess - (camDistance - tessStartDistance);

//   std::stringstream tess;
//   tess << "Tess " << int(scale);
//   GUI::Instance().updateText("tess",tess.str());
//
//   std::stringstream dist;
//   dist << "Dist " << camDistance;
//   GUI::Instance().updateText("dist",dist.str());

   if (scale > 1){
     terrainMat->getShaderProgram()->use();
     terrainMat->getShaderProgram()->setUniform("TessLevelInner",scale);
     terrainMat->getShaderProgram()->setUniform("TessLevelOuter",scale);
   }
 }
开发者ID:martinruenz,项目名称:liblub,代码行数:26,代码来源:TerrainTesselation.cpp

示例15:

springConstraint::springConstraint(massPoint *p1, massPoint *p2)
{
    QVector3D springConstraint = p1->getPos() - p2->getPos();
    this->p1 = p1;
    this->p2 = p2;

    restLength = springConstraint.length();
}
开发者ID:GriffinLedingham,项目名称:ClothSimulation,代码行数:8,代码来源:springConstraint.cpp


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