示例#1
0
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();
}
示例#2
0
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();

}
示例#3
0
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;

}
示例#4
0
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;
}
示例#5
0
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;
}
示例#6
0
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();
}
示例#7
0
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;
}
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);
    }
}
示例#9
0
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 ) );
		}
	}
}
示例#10
0
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;
        }
    }
}
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
}
示例#12
0
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();
      }
示例#13
0
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;
    }
}
示例#14
0
 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);
   }
 }
springConstraint::springConstraint(massPoint *p1, massPoint *p2)
{
    QVector3D springConstraint = p1->getPos() - p2->getPos();
    this->p1 = p1;
    this->p2 = p2;

    restLength = springConstraint.length();
}
示例#16
0
/**
 * returns radiant angle in a mathematical positive sense
 * relative to another vector (default 1,0,0)
 */
qreal DynamicObject::getAngleRelativeToVector(QVector3D vec) {
	qreal numerator = QVector3D::dotProduct(m_direction, vec);
	qreal denominator = m_direction.length() * vec.length();

	int sign = QVector3D::crossProduct(m_direction, vec).z() >= 0 ? -1 : 1;

	return sign * acos(numerator / denominator);
}
示例#17
0
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    GLWidgetBase::mousePressEvent(event);

    setCursor(Qt::ClosedHandCursor);
    if (event->buttons() & Qt::RightButton) {
        setCursor(Qt::SizeAllCursor);
    }else if(event->buttons() & Qt::MiddleButton){
        setCursor(lightCursor);


    }else if((event->buttons() & Qt::LeftButton) && (keyPressed == Qt::Key_Shift) ){

        colorFBO->bind();
        glReadBuffer(GL_COLOR_ATTACHMENT1); // NormalFBO actually it contains World Space position
        vector< float > pixels( 1 * 1 * 4 );
        glReadPixels(event->pos().x(), height()-event->pos().y(), 1, 1,GL_RGBA, GL_FLOAT, &pixels[0]);
        QVector3D position = QVector3D(pixels[0],pixels[1],pixels[2]);

        // when clicked on mesh other wise it has to be skybox
        if(position.length() < 50.0){
            qDebug() << "Picked position pixel (" << event->pos().x() << " , " << height()-event->pos().y() << ") with position:" << position;
            colorFBO->bindDefault();
            QVector3D curr_pos = camera.position - camera.radius * camera.direction;
            QVector3D new_dir = (position - curr_pos);
            new_dir.normalize();
            // update new Camera position
            cameraInterpolation = 0 ; // reset camera interpolation 'clock'
            newCamera.position  = position;
            newCamera.direction = new_dir;
            newCamera.radius    =-QVector3D::dotProduct(curr_pos - position,new_dir);
            glReadBuffer(GL_BACK);
            keyPressed = (Qt::Key)0;
            newCamera.side_direction = QVector3D(newCamera.direction.z(),0,-newCamera.direction.x());
            newCamera.rotateView(0,0);
        }
        emit changeCamPositionApplied(false);

    }


    updateGL();
    // capture the pixel color if material preview is enabled
    if((event->buttons() & Qt::LeftButton) && keyPressed == KEY_SHOW_MATERIALS){

        vector< unsigned char > pixels( 1 * 1 * 4 );

        glReadPixels(event->pos().x(), height()-event->pos().y(), 1, 1,GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
        QColor color = QColor(pixels[0],pixels[1],pixels[2],pixels[3]);

        qDebug() << "Picked material pixel (" << event->pos().x() << " , " << height()-event->pos().y() << ") with color:" << color;
        emit materialColorPicked(color);

    }


}
示例#18
0
QVector3D Vector::orthoNormalize( const QVector3D & fixed, const QVector3D & v )
{
	QVector3D proj = fixed * QVector3D::dotProduct( v, fixed );
	QVector3D ortho = v - proj;
	float length = ortho.length();
	if( length <= FLT_EPSILON )
		return QVector3D();
	return ortho/length;
}
示例#19
0
void dojoChemicalSynapse::calcLength(){
    QVector3D start = Source->getCoords();
    QVector3D end = Target->getCoords();

    //Calc length
    QVector3D diff = end-start;

    Length = diff.length();
}
示例#20
0
QQuaternion rotationFromZ(const QVector3D & vect)
{
	static const QVector3D z(0.,0.,1.);
	QVector3D cross_product = QVector3D::crossProduct(z,vect);

	QQuaternion rotation = QQuaternion::fromAxisAndAngle(cross_product,
			acos(QVector3D::dotProduct(z,vect)/vect.length())*180/M_PI);
	return rotation;
}
示例#21
0
void LineSpline::calDu()
{
    this->du.clear();
    QVector3D dvt;
    float L = 0.f;
    for(unsigned int i=1; i<this->_line.size(); i++)
    {
        dvt = _line[i]-_line[i-1];
        L += dvt.length();
    }
    du.push_back(0.f);
    for(unsigned int i=1; i<this->_line.size()-1; i++)
    {
        dvt = _line[i]-_line[i-1];
        du.push_back(du[i-1]+dvt.length()/L);
    }
    du.push_back(1.f);
}
示例#22
0
文件: Bone.cpp 项目: nicoring/HCI1
void Bone::updatePointsToParent(const QVector3D &point)
{

	setLength(point.length());
	/*QVector3D test = point;
	test.setY(-test.y());*/
	Quat newRotationSum = Quaternion::between(QVector3D(0,0,1), point);
	//maybe calculate every time asked for instead of store
	m_rotationRelative = ((newRotationSum)/**(-m_baseRotation)*/).normalized();


}
示例#23
0
float Material::cookTorrance(const QVector3D &v, const QVector3D &n, const QVector3D &L, float F, float m)
{
    QVector3D vL = v + L;
    QVector3D h = vL / vL.length();
    float nh = QVector3D::dotProduct(n, h);
    float nv = QVector3D::dotProduct(n, v);
    float vh = QVector3D::dotProduct(v, h);
    float nL = QVector3D::dotProduct(n, L);
    float m2 = m * m;
    float alpha = qMin(0.999, qAcos(nh));
    float G = qMin(1.0f, qMin(2.0f * nh * nv / vh, 2.0f * nh * nL / vh));
    float D = qExp(-qPow(qTan(alpha), 2.0f) / m2) / (m2 * qPow(qCos(alpha), 4.0f));
    return qMin(24.0f, F * G * D / (4.0f * float(M_PI) * nL * nv));
}
示例#24
0
QVector3D Transformation::normalization(QVector3D a, QVector3D b, QVector3D c)
{
	QVector3D v1 = b - a;
	QVector3D v2 = c - a;

	QVector3D result = crossProduct(v1, v2);

	double length = result.length();
	result.setX(result.x() / length);
	result.setY(result.y() / length);
	result.setZ(result.z() / length);

	return result;
}
void SpringMesh::calcTorque()
{
	for (auto edge : springEdgeAngle)
	{
		HDS_HalfEdge* he = mesh->heMap[edge.first];
		HDS_HalfEdge* hef = he->flip;

		float torque;
		torque += kts * (HDS_Face::faceAngle(he->f, hef->f) - edge.second);
		torque -= ktd * (QVector3D::dotProduct(he->f->n, he->f->pre_n)
			+ QVector3D::dotProduct(hef->f->n, he->f->pre_n));
		torque *= timestep;

		QVector3D h = (hef->v->pos - he->v->pos);
		float l01 = h.length();
		h.normalize();
		QVector3D x02 = he->next->v->pos - he->v->pos;
		QVector3D x13 = hef->next->v->pos - hef->v->pos;
		QVector3D rl = (x02 * h) * h;
		QVector3D rr = (x13 * h) * h;
		float d02 = rl.length();
		float d03 = l01 - rr.length();
		rl = x02 - rl;
		rr = x13 - rr;

		QVector3D f2 = (torque * h) * he->f->pre_n / rl.length();
		QVector3D f3 = (torque * h) * hef->f->pre_n / rr.length();
		QVector3D f1 = -(d02 * f2 + d03 * f3) / l01;
		QVector3D f0 = -(f1 + f2 + f3);
		/*cout << f0.length() << ", " << f1.length() << ", "
			<< f2.length() << ", " << f3.length() << endl;*/
		he->v->in_force += f0;
		hef->v->in_force += f1;
		he->next->v->in_force += f2;
		hef->next->v->in_force += f3;
	}
}
示例#26
0
void LineSpline::bubblePointOnCurves(float s1, float s2)
{
    QVector3D p1, p2;
    p1 = this->pointOnCurves(s1);
    p2 = this->pointOnCurves(s2);
    QVector3D div = QVector3D(p1.x()-p2.x(), p1.y()-p2.y(), p1.z()-p2.z());
    float length = div.length();
    if(length < this->_distance)
        return;
    else
    {
        this->_ap.push_back(pointOnCurves((s1+s2)/2));
        bubblePointOnCurves(s1, (s1+s2)/2);
        bubblePointOnCurves((s1+s2)/2, s2);
    }
}
示例#27
0
void  PlanetElement::checkMaterialToggle(){
  QVector3D camFromPlanet = SceneData::Instance().getCurrentCamera()->position
      - planet->position;
  float camDistance = camFromPlanet.length();
  if (camDistance >= planet->outerRadius) {
    node->setMaterial(fromSpace);
    updateWaveLength();
    updateUseAttenuation();
    updateSize();
  } else {
    node->setMaterial(fromAtmosphere);
    updateWaveLength();
    updateUseAttenuation();
    updateSize();
  }
}
示例#28
0
QVector3D MathUtil::Slerp(QVector3D p1, QVector3D p2, float i)
{

    p1.normalize();
    p2.normalize();

    QVector3D c = QVector3D::crossProduct(p1, p2);
    if (c.length() < 0.001f)
        c = QVector3D(0, 1, 0);
    c.normalize();

    float angle = acosf(QVector3D::dotProduct(p1, p2));

    return GetRotatedAxis(i * angle, p1, c);

}
示例#29
0
void MathUtil::FacePosDirGL(QVector3D pos, QVector3D dir)
{

    QVector3D c = QVector3D::crossProduct(QVector3D(0, 0, 1), dir);
    if (c.length() < 0.001f)
        c = QVector3D(0, 1, 0);
    c.normalize();

    float angle = QVector3D::dotProduct(QVector3D(0, 0, 1), dir);
    angle = acosf(angle);
    angle = MathUtil::RadToDeg(angle);

    glTranslatef(pos.x(), pos.y(), pos.z());
    glRotatef(angle, c.x(), c.y(), c.z());

}
示例#30
0
cv::Vec3f AreaLight::getIntensity(const HitRecord & hit, QVector3D &direction, const Intersectable &scene, const Sample &sample) const
{
  QVector3D at = hit.getIntersectingPoint().toVector3DAffine();
  QPointF p = sample.getSample();
  QVector3D lightLocation = getLocation(p);
  direction = at - lightLocation;
  HitRecord shadowHit = scene.intersect(Ray(at, -direction.normalized(), EPSILON, direction.length() - EPSILON));

  if(shadowHit.intersects() && &shadowHit.getMaterial() != this)
  {
    return cv::Vec3f();
  }
  else
  {
      return getIntensity(direction);
  }
}