Example #1
0
void RichTextEditor::on_qaImage_triggered() {
	QPair<QByteArray, QImage> choice = g.mw->openImageFile();

	QByteArray &qba = choice.first;

	if (qba.isEmpty())
		return;

	if ((g.uiImageLength > 0) && (qba.length() > g.uiImageLength)) {
		QMessageBox::warning(this, tr("Failed to load image"), tr("Image file too large to embed in document. Please use images smaller than %1 kB.").arg(g.uiImageLength /1024));
		return;
	}

	QBuffer qb(&qba);
	qb.open(QIODevice::ReadOnly);

	QByteArray format = QImageReader::imageFormat(&qb);
	qb.close();

	qteRichText->insertHtml(Log::imageToImg(format, qba));
}
Example #2
0
int ElastomericBearing2d::getResponse(int responseID, Information &eleInfo)
{
    double kGeo1, MpDelta1, MpDelta2, MpDelta3;
    
    switch (responseID)  {
    case 1:  // global forces
        return eleInfo.setVector(this->getResistingForce());
        
    case 2:  // local forces
        theVector.Zero();
        // determine resisting forces in local system
        theVector = Tlb^qb;
        // add P-Delta moments
        kGeo1 = 0.5*qb(0);
        MpDelta1 = kGeo1*(ul(4)-ul(1));
        theVector(2) += MpDelta1;
        theVector(5) += MpDelta1;
        MpDelta2 = kGeo1*shearDistI*L*ul(2);
        theVector(2) += MpDelta2;
        theVector(5) -= MpDelta2;
        MpDelta3 = kGeo1*(1.0 - shearDistI)*L*ul(5);
        theVector(2) -= MpDelta3;
        theVector(5) += MpDelta3;
        
        return eleInfo.setVector(theVector);
        
    case 3:  // basic forces
        return eleInfo.setVector(qb);
        
    case 4:  // local displacements
        return eleInfo.setVector(ul);
        
    case 5:  // basic displacements
        return eleInfo.setVector(ub);
        
    default:
        return -1;
    }
}
Example #3
0
const Vector& TwoNodeLink::getResistingForce()
{
    // zero the residual
    theVector->Zero();
    
    // get resisting forces
    for (int i=0; i<numDir; i++)
        qb(i) = theMaterials[i]->getStress();
    
    // determine resisting forces in local system
    Vector ql(numDOF);
    ql.addMatrixTransposeVector(0.0, Tlb, qb, 1.0);
    
    // add P-Delta effects to local forces
    if (Mratio.Size() == 4)
        this->addPDeltaForces(ql);
    
    // determine resisting forces in global system    
    theVector->addMatrixTransposeVector(0.0, Tgl, ql, 1.0);
    
    return *theVector;
}
Example #4
0
/**
 * Calculates the orientation of determined by linear interpolation between
 * q1 and q2.  If alpha is 0, then q1 is returned.  If alpha is 1, then
 * q2 is returned.
 * \param q1 the "initial" orientation
 * \param q2 the "final" orientation
 * \param alpha interpolation value (0 <= alpha <= 1)
 * \return the orientation linearly interpolated between q1 and q2
 * \todo rewrite this function to avoid cancellation errors
 */
QUAT QUAT::slerp(const QUAT& q1, const QUAT& q2, REAL alpha)
{
  if (alpha < (REAL) 0.0 || alpha > (REAL) 1.0)
    throw std::runtime_error("Attempting to interpolate using QUAT::slerp() with t not in interval [0,1]");

  // compute q1'q2
  REAL dot = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;

  // see whether we need to use the conjugate of q2
  bool use_conj = (dot < (REAL) 0.0);

  // clip dot
  if (dot < (REAL) -1.0)
    dot = (REAL) -1.0;
  else if (dot > (REAL) 1.0)
    dot = (REAL) 1.0;

  // find the angle between the two
  REAL theta = std::acos(std::fabs(dot));
  if (theta == 0.0)
    return q1;

  // do slerp
  REAL sin1at = std::sin((1-alpha)*theta);
  REAL sinat = std::sin(alpha*theta);
  REAL sint_i = (REAL) 1.0/std::sin(theta);
  QUAT qa(q1.x*sin1at, q1.y*sin1at, q1.z*sin1at, q1.w*sin1at);
  QUAT qb(q2.x*sinat, q2.y*sinat, q2.z*sinat, q2.w*sinat);
  if (use_conj)
    qb.conjugate();
  QUAT qc = qa + qb;
  qc.x *= sint_i;
  qc.y *= sint_i;
  qc.z *= sint_i;
  qc.w *= sint_i;

  return qc;
}
Example #5
0
void ClsBaseQStateArrayView::createNullPixmap(){
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
    cout << "ClsBaseQStateArrayView::createNullPixmap()" << endl;
#endif

    QBrush   qb(Qt::yellow);
    pmGridEmpty.resize ( size().width()-2*BORDER, size().height()-2*BORDER);
    QPainter paint(&pmGridEmpty);
    pmGridEmpty.fill(this->backgroundColor());
    drawCheckerBoard(paint, -BORDER, -BORDER);
    paint.end();
//--    bitBlt(this, BORDER, BORDER, &pmGridEmpty);


    
    pmGridValues.resize ( size().width()-2*BORDER, size().height()-2*BORDER);
    QPainter paintPM(&pmGridValues);
    pmGridValues.fill(this->backgroundColor());
    drawCheckerBoard(paintPM, -BORDER, -BORDER);
//cout << __FILE__ << ":" << __LINE__ << endl;
    paintPM.end();

}
Example #6
0
QString WebViewObject::hexPack(QVariant v,QString type) {
    char buf[4];
    char size = 0;
    if("byte" == type) {
        *((unsigned char*)buf) = v.value<unsigned char>();
        size = 1;
    } else if("sbyte" == type) {
        *((signed char*)buf) = v.value<signed char>();
        size = 1;
    } else if("word" == type) {
        *((unsigned short*)buf) = v.value<unsigned short>();
        size = 2;
    } else if("sword" == type) {
        *((unsigned short*)buf) = v.value<signed short>();
        size = 2;
    } else if("float" == type) {
        *((float*)buf) = v.value<float>();
        size = 4;
    }

    QByteArray qb(buf,size);
    return qb.toHex();
}
Example #7
0
void VOIPGUIHandler::ReceivedVoipData(const RsPeerId &peer_id)
{
	std::vector<RsVOIPDataChunk> chunks ;

	if(!rsVOIP->getIncomingData(peer_id,chunks))
	{
		std::cerr << "VOIPGUIHandler::ReceivedVoipData(): No data chunks to get. Weird!" << std::endl;
		return ;
	}

	ChatDialog *di = ChatDialog::getChat(ChatId(peer_id), Settings->getChatFlags());
	if (di) {
		ChatWidget *cw = di->getChatWidget();
		if (cw) {
			const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();

			foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) 
			{
				VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;

				if (acwh) {
						for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++)
						{
							QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);

							if(chunks[chunkIndex].type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
							acwh->addAudioData(peer_id, &qb);
							else if(chunks[chunkIndex].type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
							acwh->addVideoData(peer_id, &qb);
							else
								std::cerr << "VOIPGUIHandler: Unknown data type received. type=" << chunks[chunkIndex].type << std::endl;
						}
					break;
				}
			}
		}
	} else {
int ElastomericBearingBoucWen2d::update()
{
    // get global trial displacements and velocities
    const Vector &dsp1 = theNodes[0]->getTrialDisp();
    const Vector &dsp2 = theNodes[1]->getTrialDisp();
    const Vector &vel1 = theNodes[0]->getTrialVel();
    const Vector &vel2 = theNodes[1]->getTrialVel();
    
    static Vector ug(6), ugdot(6), uldot(6), ubdot(3);
    for (int i=0; i<3; i++)  {
        ug(i)   = dsp1(i);  ugdot(i)   = vel1(i);
        ug(i+3) = dsp2(i);  ugdot(i+3) = vel2(i);
    }
    
    // transform response from the global to the local system
    ul.addMatrixVector(0.0, Tgl, ug, 1.0);
    uldot.addMatrixVector(0.0, Tgl, ugdot, 1.0);
    
    // transform response from the local to the basic system
    ub.addMatrixVector(0.0, Tlb, ul, 1.0);
    ubdot.addMatrixVector(0.0, Tlb, uldot, 1.0);
    
    // 1) get axial force and stiffness in basic x-direction
    theMaterials[0]->setTrialStrain(ub(0), ubdot(0));
    qb(0) = theMaterials[0]->getStress();
    kb(0,0) = theMaterials[0]->getTangent();
    
    // 2) calculate shear force and stiffness in basic y-direction
    // get displacement increment (trial - commited)
    double delta_ub = ub(1) - ubC(1);
    if (fabs(delta_ub) > 0.0)  {
        
        // get yield displacement
        double uy = qYield/k0;
        
        // calculate hysteretic evolution parameter z using Newton-Raphson
        int iter = 0;
        double zAbs, tmp1, f, Df, delta_z;
        do  {
            zAbs = fabs(z);
            if (zAbs == 0.0)    // check because of negative exponents
                zAbs = DBL_EPSILON;
            tmp1 = gamma + beta*sgn(z*delta_ub);
            
            // function and derivative
            f  = z - zC - delta_ub/uy*(A - pow(zAbs,eta)*tmp1);
            Df = 1.0 + delta_ub/uy*eta*pow(zAbs,eta-1.0)*sgn(z)*tmp1;
            
            // issue warning if derivative Df is zero
            if (fabs(Df) <= DBL_EPSILON)  {
                opserr << "WARNING: ElastomericBearingBoucWen2d::update() - "
                    << "zero derivative in Newton-Raphson scheme for "
                    << "hysteretic evolution parameter z.\n";
                return -1;
            }
            
            // advance one step
            delta_z = f/Df;
            z -= delta_z;
            iter++;
        } while ((fabs(delta_z) >= tol) && (iter < maxIter));
        
        // issue warning if Newton-Raphson scheme did not converge
        if (iter >= maxIter)   {
            opserr << "WARNING: ElastomericBearingBoucWen2d::update() - "
                << "did not find the hysteretic evolution parameter z after "
                << iter << " iterations and norm: " << fabs(delta_z) << endln;
            return -2;
        }
        
        // get derivative of hysteretic evolution parameter * uy
        dzdu = A - pow(fabs(z),eta)*(gamma + beta*sgn(z*delta_ub));
        // set shear force
        qb(1) = qYield*z + k2*ub(1) + k3*sgn(ub(1))*pow(fabs(ub(1)),mu);
        // set tangent stiffness
        kb(1,1) = k0*dzdu + k2 + k3*mu*pow(fabs(ub(1)),mu-1.0);
    }
    
    // 3) get moment and stiffness about basic z-direction
    theMaterials[1]->setTrialStrain(ub(2), ubdot(2));
    qb(2) = theMaterials[1]->getStress();
    kb(2,2) = theMaterials[1]->getTangent();
    
    return 0;
}
Example #9
0
int SingleFPSimple2d::update()
{
    // get global trial displacements and velocities
    const Vector &dsp1 = theNodes[0]->getTrialDisp();
    const Vector &dsp2 = theNodes[1]->getTrialDisp();
    const Vector &vel1 = theNodes[0]->getTrialVel();
    const Vector &vel2 = theNodes[1]->getTrialVel();
    
    static Vector ug(6), ugdot(6), uldot(6), ubdot(3);
    for (int i=0; i<3; i++)  {
        ug(i)   = dsp1(i);  ugdot(i)   = vel1(i);
        ug(i+3) = dsp2(i);  ugdot(i+3) = vel2(i);
    }
    
    // transform response from the global to the local system
    ul = Tgl*ug;
    uldot = Tgl*ugdot;
    
    // transform response from the local to the basic system
    ub = Tlb*ul;
    ubdot = Tlb*uldot;
    
    // get absolute velocity
    double ubdotAbs = sqrt(pow(ubdot(1)/Reff*ub(1),2) + pow(ubdot(1),2));
    
    // 1) get axial force and stiffness in basic x-direction
    double ub0Old = theMaterials[0]->getStrain();
    theMaterials[0]->setTrialStrain(ub(0),ubdot(0));
    qb(0) = theMaterials[0]->getStress();
    kb(0,0) = theMaterials[0]->getTangent();
    
    // check for uplift
    if (qb(0) >= 0.0)  {
        kb = kbInit;
        if (qb(0) > 0.0)  {
            theMaterials[0]->setTrialStrain(ub0Old,0.0);
            kb(0,0) *= DBL_EPSILON;
            kb(2,2) *= DBL_EPSILON;
            // update plastic displacement
            ubPlastic = ub(1);
        }
        qb.Zero();
        return 0;
    }
    
    // 2) calculate shear force and stiffness in basic y-direction
    int iter = 0;
    double qb1Old = 0.0;
    do  {
        // save old shear force
        qb1Old = qb(1);
        
        // get normal and friction (yield) forces
        double N = -qb(0) + qb(1)/Reff*ub(1) - qb(1)*ul(2);
        theFrnMdl->setTrial(N, ubdotAbs);
        double qYield = (theFrnMdl->getFrictionForce());
        
        // get stiffness of elastic component
        double k2 = N/Reff;
        // get initial stiffness of hysteretic component
        double k0 = qYield/uy;
        
        // get trial shear force of hysteretic component
        double qTrial = k0*(ub(1) - ubPlasticC);
        
        // compute yield criterion of hysteretic component
        double qTrialNorm = fabs(qTrial);
        double Y = qTrialNorm - qYield;
        
        // elastic step -> no updates required
        if (Y <= 0.0)  {
            // set shear force
            qb(1) = qTrial + k2*ub(1) - N*ul(2);
            // set tangent stiffness
            kb(1,1) = k0 + k2;
        }
        // plastic step -> return mapping
        else  {
            // compute consistency parameter
            double dGamma = Y/k0;
            // update plastic displacement
            ubPlastic = ubPlasticC + dGamma*qTrial/qTrialNorm;
            // set shear force
            qb(1) = qYield*qTrial/qTrialNorm + k2*ub(1) - N*ul(2);
            // set tangent stiffness
            kb(1,1) = k2;
        }
        iter++;
    } while ((fabs(qb(1)-qb1Old) >= tol) && (iter < maxIter));
    
    // issue warning if iteration did not converge
    if (iter >= maxIter)  {
        opserr << "WARNING: SingleFPSimple2d::update() - did not find the shear force after "
            << iter << " iterations and norm: " << fabs(qb(1)-qb1Old) << endln;
        return -1;
    }
    
    // 3) get moment and stiffness in basic z-direction
    theMaterials[1]->setTrialStrain(ub(2),ubdot(2));
    qb(2) = theMaterials[1]->getStress();
    kb(2,2) = theMaterials[1]->getTangent();
    
    return 0;
}
Example #10
0
void OverlayUser::updateUser() {
	if (os->bUserName && (qgpiName[0]->pixmap().isNull() || (cuUser && (qsName != cuUser->qsName)))) {
		if (cuUser)
			qsName = cuUser->qsName;

		OverlayTextLine tl(qsName, os->qfUserName);
		for (int i=0; i<4; ++i) {
			const QPixmap &pm = tl.createPixmap(SCALESIZE(UserName), os->qcUserName[i]);
			qgpiName[i]->setPixmap(pm);

			if (i == 0)
				qgpiName[0]->setPos(alignedPosition(scaledRect(os->qrfUserName, uiSize * os->fZoom), qgpiName[0]->boundingRect(), os->qaUserName));
			else
				qgpiName[i]->setPos(qgpiName[0]->pos());
		}
	}

	if (os->bChannel && (qgpiChannel->pixmap().isNull() || (cuUser && (qsChannelName != cuUser->cChannel->qsName)))) {
		if (cuUser)
			qsChannelName = cuUser->cChannel->qsName;

		const QPixmap &pm = OverlayTextLine(qsChannelName, os->qfChannel).createPixmap(SCALESIZE(Channel), os->qcChannel);
		qgpiChannel->setPixmap(pm);
		qgpiChannel->setPos(alignedPosition(scaledRect(os->qrfChannel, uiSize * os->fZoom), qgpiChannel->boundingRect(), os->qaChannel));
	}

	if (os->bAvatar && (qgpiAvatar->pixmap().isNull() || (cuUser && (qbaAvatar != cuUser->qbaTextureHash)))) {
		if (cuUser)
			qbaAvatar = cuUser->qbaTextureHash;

		QImage img;

		if (! qbaAvatar.isNull() && cuUser->qbaTexture.isEmpty()) {
			g.o->requestTexture(cuUser);
		} else if (qbaAvatar.isNull()) {
			QImageReader qir(QLatin1String("skin:default_avatar.svg"));
			QSize sz = qir.size();
			sz.scale(SCALESIZE(Avatar), Qt::KeepAspectRatio);
			qir.setScaledSize(sz);
			img = qir.read();
		} else {
			QBuffer qb(& cuUser->qbaTexture);
			qb.open(QIODevice::ReadOnly);

			QImageReader qir(&qb, cuUser->qbaTextureFormat);
			QSize sz = qir.size();
			sz.scale(SCALESIZE(Avatar), Qt::KeepAspectRatio);
			qir.setScaledSize(sz);
			img = qir.read();
		}

		qgpiAvatar->setPixmap(QPixmap::fromImage(img));
		qgpiAvatar->setPos(alignedPosition(scaledRect(os->qrfAvatar, uiSize * os->fZoom), qgpiAvatar->boundingRect(), os->qaAvatar));
	}

	qgpiAvatar->setVisible(os->bAvatar);

	if (cuUser) {
		ClientUser *self = ClientUser::get(g.uiSession);

		if (os->bMutedDeafened) {
			if (cuUser->bDeaf || cuUser->bSelfDeaf) {
				qgpiMuted->hide();
				qgpiDeafened->show();
			} else if (cuUser->bMute || cuUser->bSelfMute || cuUser->bLocalMute || cuUser->bSuppress) {
				qgpiMuted->show();
				qgpiDeafened->hide();
			} else {
				qgpiMuted->hide();
				qgpiDeafened->hide();
			}
		} else {
			qgpiMuted->hide();
			qgpiDeafened->hide();
		}

		bool samechannel = self && (self->cChannel == cuUser->cChannel);
		qgpiChannel->setVisible(os->bChannel && ! samechannel);

		tsColor = cuUser->tsState;
	} else {
		qgpiChannel->setVisible(os->bChannel && (tsColor != Settings::Passive) && (tsColor != Settings::Talking));
		qgpiMuted->setVisible(os->bChannel);
		qgpiDeafened->hide();
	}

	if (os->bUserName)
		for (int i=0;i<4;++i)
			qgpiName[i]->setVisible(i == tsColor);
	else
		for (int i=0;i<4;++i)
			qgpiName[i]->setVisible(false);

	qgpiBox->setVisible(os->bBox);

	setOpacity(os->fUser[tsColor]);
}
Example #11
0
//private
void PlatformDemoState::cacheMeshes()
{
    xy::CubeBuilder cb(100.f);
    m_meshRenderer.loadModel(MeshID::Cube, cb);

    xy::IQMBuilder ib("assets/models/mrfixit.iqm");
    m_meshRenderer.loadModel(MeshID::Fixit, ib);

    xy::IQMBuilder ib2("assets/models/platform_01.iqm");
    m_meshRenderer.loadModel(MeshID::Platform, ib2);

    xy::IQMBuilder ib3("assets/models/batcat.iqm");
    m_meshRenderer.loadModel(MeshID::Batcat, ib3);

    xy::QuadBuilder qb({ 1500.f, 550.f });
    m_meshRenderer.loadModel(MeshID::Quad, qb);

    xy::SphereBuilder sb(34.f, 6u);
    m_meshRenderer.loadModel(MeshID::Sphere, sb);

    auto& demoMaterial = m_meshRenderer.addMaterial(MatId::Demo, xy::Material::TexturedBumped, true);
    demoMaterial.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/cube_diffuse.png") });
    demoMaterial.addProperty({ "u_normalMap", m_textureResource.get("assets/images/platform/cube_normal.png") });
    demoMaterial.addProperty({ "u_maskMap", m_textureResource.get("assets/images/platform/cube_mask.png") });
    demoMaterial.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);
  
    auto& fixitMaterialBody = m_meshRenderer.addMaterial(MatId::MrFixitBody, xy::Material::TexturedSkinnedBumped, true);
    fixitMaterialBody.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/fixit/fixitBody.png") });
    fixitMaterialBody.addProperty({ "u_normalMap", m_textureResource.get("assets/images/fixit/fixitBody_normal.png") });
    fixitMaterialBody.addProperty({ "u_maskMap", m_textureResource.get("assets/images/fixit/fixitBody_mask.tga") });
    fixitMaterialBody.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);

    auto& fixitMaterialHead = m_meshRenderer.addMaterial(MatId::MrFixitHead, xy::Material::TexturedSkinnedBumped, true);
    fixitMaterialHead.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/fixit/fixitHead.png") });
    fixitMaterialHead.addProperty({ "u_normalMap", m_textureResource.get("assets/images/fixit/fixitHead_normal.png") });
    fixitMaterialHead.addProperty({ "u_maskMap", m_textureResource.get("assets/images/fixit/fixitHead_mask.png") });
    fixitMaterialHead.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);

    auto& platformMaterial01 = m_meshRenderer.addMaterial(MatId::Platform01, xy::Material::Textured, true, true);
    platformMaterial01.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/plat_01.png") });


    auto& platformMaterial04 = m_meshRenderer.addMaterial(MatId::Platform04, xy::Material::Textured, true, true);
    platformMaterial04.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/plat_04.png") });

    auto& catMat = m_meshRenderer.addMaterial(MatId::BatcatMat, xy::Material::TexturedSkinnedBumped, true);
    auto& tex = m_textureResource.get("assets/images/platform/batcat_diffuse.png");
    tex.setRepeated(true);
    catMat.addProperty({ "u_diffuseMap", tex });
    auto& tex2 = m_textureResource.get("assets/images/platform/batcat_normal.png");
    tex2.setRepeated(true);
    catMat.addProperty({ "u_normalMap", tex2 });
    auto& tex3 = m_textureResource.get("assets/images/platform/batcat_mask.png");
    tex3.setRepeated(true);
    catMat.addProperty({ "u_maskMap", tex3 });
    catMat.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);


    m_textureResource.setFallbackColour(sf::Color(230, 120, 0));
    auto& sphereMat = m_meshRenderer.addMaterial(MatId::SphereTest, xy::Material::TexturedBumped, true);
    sphereMat.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/sphere_test.png") });
    sphereMat.addProperty({ "u_normalMap", m_textureResource.get("assets/images/sphere_normal.png") });
    sphereMat.addProperty({ "u_maskMap", m_textureResource.get("I don't want a mask texture!!") });
    sphereMat.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front);

    auto& lightMaterial = m_meshRenderer.addMaterial(MatId::LightSource, xy::Material::Coloured);
    lightMaterial.addProperty({ "u_colour", sf::Color(135, 135, 80) });
    lightMaterial.addProperty({ "u_maskColour", sf::Color::Blue });

    auto light = xy::Component::create<xy::PointLight>(m_messageBus, 800.f, 500.f, sf::Color(255, 255, 100));
    light->setDepth(400.f);
    light->enableShadowCasting(true);

    auto model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus);
    model->setPosition({ 0.f, 0.f, light->getWorldPosition().z });
    model->setSubMaterial(lightMaterial, 0);

    auto entity = xy::Entity::create(m_messageBus);
    entity->setPosition(xy::DefaultSceneSize / 2.f);
    entity->setScale(0.25f, 0.25f);
    entity->addComponent(light);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::FrontFront);


    //---------------
    light = xy::Component::create<xy::PointLight>(m_messageBus, 600.f, 500.f, sf::Color(255, 255, 100));
    light->setDepth(300.f);
    light->setIntensity(2.5f);
    light->enableShadowCasting(true);

    model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus);
    model->setPosition({ 0.f, 0.f, light->getWorldPosition().z });
    model->setSubMaterial(lightMaterial, 0);

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(2000.f, 200.f);
    entity->setScale(0.35f, 0.35f);
    entity->addComponent(light);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::FrontFront);
}
Example #12
0
int ElastomericBearing2d::update()
{
    // get global trial displacements and velocities
    const Vector &dsp1 = theNodes[0]->getTrialDisp();
    const Vector &dsp2 = theNodes[1]->getTrialDisp();
    const Vector &vel1 = theNodes[0]->getTrialVel();
    const Vector &vel2 = theNodes[1]->getTrialVel();
    
    static Vector ug(6), ugdot(6), uldot(6), ubdot(3);
    for (int i=0; i<3; i++)  {
        ug(i)   = dsp1(i);  ugdot(i)   = vel1(i);
        ug(i+3) = dsp2(i);  ugdot(i+3) = vel2(i);
    }
    
    // transform response from the global to the local system
    ul = Tgl*ug;
    uldot = Tgl*ugdot;
    
    // transform response from the local to the basic system
    ub = Tlb*ul;
    ubdot = Tlb*uldot;
    
    // 1) get axial force and stiffness in basic x-direction
    theMaterials[0]->setTrialStrain(ub(0),ubdot(0));
    qb(0) = theMaterials[0]->getStress();
    kb(0,0) = theMaterials[0]->getTangent();
    
    // 2) calculate shear force and stiffness in basic y-direction
    // get trial shear force of hysteretic component
    double qTrial = k0*(ub(1) - ubPlasticC);
    
    // compute yield criterion of hysteretic component
    double qTrialNorm = fabs(qTrial);
    double Y = qTrialNorm - qYield;
    
    // elastic step -> no updates required
    if (Y <= 0.0)  {
        // set shear force
        qb(1) = qTrial + k2*ub(1);
        // set tangent stiffness
        kb(1,1) = k0 + k2;
    }
    // plastic step -> return mapping
    else  {
        // compute consistency parameter
        double dGamma = Y/k0;
        // update plastic displacement
        ubPlastic = ubPlasticC + dGamma*qTrial/qTrialNorm;
        // set shear force
        qb(1) = qYield*qTrial/qTrialNorm + k2*ub(1);
        // set tangent stiffness
        kb(1,1) = k2;
    }
    
    // 3) get moment and stiffness in basic z-direction
    theMaterials[1]->setTrialStrain(ub(2),ubdot(2));
    qb(2) = theMaterials[1]->getStress();
    kb(2,2) = theMaterials[1]->getTangent();
    
    return 0;
}
Example #13
0
EllipsoidFitter::Calibration EllipsoidFitter::calculateFit(void) const
	{
	/*********************************************************************
	First step: Fit a quadric to the point set by least-squares
	minimization based on algebraic distance.
	*********************************************************************/
	
	/* Create the least-squares system: */
	Math::Matrix a(10,10,0.0);
	
	/* Process all points: */
	for(Misc::ChunkedArray<Point>::const_iterator pIt=points.begin();pIt!=points.end();++pIt)
		{
		/* Create the point's associated linear equation: */
		double eq[10];
		eq[0]=(*pIt)[0]*(*pIt)[0];
		eq[1]=2.0*(*pIt)[0]*(*pIt)[1];
		eq[2]=2.0*(*pIt)[0]*(*pIt)[2];
		eq[3]=2.0*(*pIt)[0];
		eq[4]=(*pIt)[1]*(*pIt)[1];
		eq[5]=2.0*(*pIt)[1]*(*pIt)[2];
		eq[6]=2.0*(*pIt)[1];
		eq[7]=(*pIt)[2]*(*pIt)[2];
		eq[8]=2.0*(*pIt)[2];
		eq[9]=1.0;
		
		/* Insert the equation into the least-squares system: */
		for(unsigned int i=0;i<10;++i)
			for(unsigned int j=0;j<10;++j)
				a(i,j)+=eq[i]*eq[j];
		}
	
	/* Find the least-squares system's smallest eigenvalue: */
	std::pair<Math::Matrix,Math::Matrix> qe=a.jacobiIteration();
	unsigned int minEIndex=0;
	double minE=Math::abs(qe.second(0,0));
	for(unsigned int i=1;i<10;++i)
		{
		if(minE>Math::abs(qe.second(i,0)))
			{
			minEIndex=i;
			minE=Math::abs(qe.second(i,0));
			}
		}
	
	/* Create the quadric's defining matrices: */
	Math::Matrix qa(3,3);
	qa(0,0)=qe.first(0,minEIndex);
	qa(0,1)=qe.first(1,minEIndex);
	qa(0,2)=qe.first(2,minEIndex);
	qa(1,0)=qe.first(1,minEIndex);
	qa(1,1)=qe.first(4,minEIndex);
	qa(1,2)=qe.first(5,minEIndex);
	qa(2,0)=qe.first(2,minEIndex);
	qa(2,1)=qe.first(5,minEIndex);
	qa(2,2)=qe.first(7,minEIndex);
	Math::Matrix qb(3,1);
	qb(0)=qe.first(3,minEIndex);
	qb(1)=qe.first(6,minEIndex);
	qb(2)=qe.first(8,minEIndex);
	double qc=qe.first(9,minEIndex);
	
	/* Calculate the quadric's principal axes: */
	qe=qa.jacobiIteration();
	std::cout<<std::fixed<<std::setprecision(6);
	std::cout<<std::setw(9)<<qe.first<<std::endl;
	std::cout<<std::setw(9)<<qe.second<<std::endl<<std::endl;
	std::cout.unsetf(std::ios_base::floatfield);
	
	/* "Complete the square" to calculate the quadric's centroid and radii: */
	Math::Matrix qbp=qb.divideFullPivot(qe.first);
	Math::Matrix cp(3,1);
	for(int i=0;i<3;++i)
		cp(i)=-qbp(i)/qe.second(i);
	Math::Matrix c=qe.first*cp;
	std::cout<<"Centroid: "<<c(0)<<", "<<c(1)<<", "<<c(2)<<std::endl;
	double rhs=-qc;
	for(int i=0;i<3;++i)
		rhs+=Math::sqr(qbp(i))/qe.second(i);
	double radii[3];
	for(int i=0;i<3;++i)
		radii[i]=Math::sqrt(rhs/qe.second(i));
	std::cout<<"Radii: "<<radii[0]<<", "<<radii[1]<<", "<<radii[2]<<std::endl;
	Scalar averageRadius=Math::pow(radii[0]*radii[1]*radii[2],1.0/3.0);
	std::cout<<"Average radius: "<<averageRadius<<std::endl;
		
	/* Calculate the calibration matrix: */
	Math::Matrix ellP(4,4,1.0);
	for(int i=0;i<3;++i)
		for(int j=0;j<3;++j)
			ellP(i,j)=qe.first(i,j);
	Math::Matrix ellScale(4,4,1.0);
	for(int i=0;i<3;++i)
		ellScale(i,i)=averageRadius/radii[i];
	Math::Matrix ell=ellP;
	ell.makePrivate();
	for(int i=0;i<3;++i)
		ell(i,3)=c(i);
	Math::Matrix ellInv=ell.inverseFullPivot();
	Math::Matrix calib=ellP*ellScale*ellInv;
	std::cout<<std::fixed<<std::setprecision(6);
	std::cout<<std::setw(9)<<calib<<std::endl;
	std::cout.unsetf(std::ios_base::floatfield);
	
	/* Calculate the calibration residual: */
	double rms=0.0;
	for(Misc::ChunkedArray<Point>::const_iterator pIt=points.begin();pIt!=points.end();++pIt)
		{
		/* Calibrate the point: */
		Math::Matrix p(4,1);
		for(int i=0;i<3;++i)
			p(i)=(*pIt)[i];
		p(3)=1.0;
		Math::Matrix cp=calib*p;
		rms+=Math::sqr(Math::sqrt(Math::sqr(cp(0))+Math::sqr(cp(1))+Math::sqr(cp(2)))-averageRadius);
		}
	std::cout<<"Calibration residual: "<<Math::sqrt(rms/double(points.size()))<<std::endl;
	
	/* Create and return the calibration result: */
	Matrix result;
	for(int i=0;i<3;++i)
		for(int j=0;j<4;++j)
			result(i,j)=calib(i,j);
	return Calibration(result,averageRadius);
	}
Example #14
0
void Font::read(const void * data, size_t size) {
  std::istringstream in(std::string(static_cast<const char*>(data), size));
//  SignedDistanceFontFile sdff;
//  sdff.read(in);

  uint8_t header[4];
  readStream(in, header);
  if (memcmp(header, "SDFF", 4)) {
    FAIL("Bad font file");
  }

  uint16_t version;
  readStream(in, version);

  // read font name
  if (version > 0x0001) {
    char c;
    readStream(in, c);
    while (c) {
      mFamily += c;
      readStream(in, c);
    }
  }

  // read font data
  readStream(in, mLeading);
  readStream(in, mAscent);
  readStream(in, mDescent);
  readStream(in, mSpaceWidth);
  mFontSize = mAscent + mDescent;

  // read metrics data
  mMetrics.clear();

  uint16_t count;
  readStream(in, count);

  for (int i = 0; i < count; ++i) {
    uint16_t charcode;
    readStream(in, charcode);
    Metrics & m = mMetrics[charcode];
    readStream(in, m.ul.x);
    readStream(in, m.ul.y);
    readStream(in, m.size.x);
    readStream(in, m.size.y);
    readStream(in, m.offset.x);
    readStream(in, m.offset.y);
    readStream(in, m.d);
    m.lr = m.ul + m.size;
  }

  // read image data
  readPngToTexture((const char *) data + in.tellg(), size - in.tellg(),
      mTexture, mTextureSize);

  std::vector<TextureVertex> vertexData;
  std::vector<GLuint> indexData;
  float texH = 0, texW = 0, texA = 0;
  int characters = 0;
  std::for_each(mMetrics.begin(), mMetrics.end(),
      [&] ( MetricsData::reference & md ) {
        uint16_t id = md.first;
        Font::Metrics & m = md.second;
        ++characters;
        GLuint index = (GLuint)vertexData.size();
        rectf bounds = getBounds(m, mFontSize);
        rectf texBounds = getTexCoords(m);

        QuadBuilder qb(bounds, texBounds);
        for (int i = 0; i < 4; ++i) {
          vertexData.push_back(qb.vertices[i]);
        }

        m.indexOffset = indexData.size();
        indexData.push_back(index + 0);
        indexData.push_back(index + 1);
        indexData.push_back(index + 2);
        indexData.push_back(index + 0);
        indexData.push_back(index + 2);
        indexData.push_back(index + 3);
      });

  gl::VertexBufferPtr vertexBuffer(new gl::VertexBuffer(vertexData));
  gl::IndexBufferPtr indexBuffer(new gl::IndexBuffer(indexData));
  mGeometry = gl::GeometryPtr(
      new gl::Geometry(vertexBuffer, indexBuffer, characters * 2,
          gl::Geometry::Flag::HAS_TEXTURE));
  mGeometry->buildVertexArray();
}
Example #15
0
void TwoNodeLink::addPDeltaStiff(Matrix &kLocal)
{
    int dirID;
    double N = 0.0;
    
    // get axial force
    for (int i=0; i<numDir; i++)  {
        if ((*dir)(i) == 0)
            N = qb(i);
    }
    
    if (N != 0.0)  {
        for (int i=0; i<numDir; i++)  {
            dirID = (*dir)(i);  // direction 0 to 5;
            
            // switch on dimensionality of element
            switch (elemType)  {
            case D2N4:
                if (dirID == 1)  {
                    double NoverL = N/L;
                    NoverL *= 1.0-Mratio(2)-Mratio(3);
                    kLocal(1,1) += NoverL;
                    kLocal(1,3) -= NoverL;
                    kLocal(3,1) -= NoverL;
                    kLocal(3,3) += NoverL;
                }
                break;
            case D2N6: 
                if (dirID == 1)  {
                    double NoverL = N/L;
                    NoverL *= 1.0-Mratio(2)-Mratio(3);
                    kLocal(1,1) += NoverL;
                    kLocal(1,4) -= NoverL;
                    kLocal(4,1) -= NoverL;
                    kLocal(4,4) += NoverL;
                }
                else if (dirID == 2)  {
                    kLocal(2,1) -= Mratio(2)*N;
                    kLocal(2,4) += Mratio(2)*N;
                    kLocal(5,1) -= Mratio(3)*N;
                    kLocal(5,4) += Mratio(3)*N;
                }
                break;
            case D3N6:
                if (dirID == 1)  {
                    double NoverL = N/L;
                    NoverL *= 1.0-Mratio(2)-Mratio(3);
                    kLocal(1,1) += NoverL;
                    kLocal(1,4) -= NoverL;
                    kLocal(4,1) -= NoverL;
                    kLocal(4,4) += NoverL;
                }
                else if (dirID == 2)  {
                    double NoverL = N/L;
                    NoverL *= 1.0-Mratio(0)-Mratio(1);
                    kLocal(2,2) += NoverL;
                    kLocal(2,5) -= NoverL;
                    kLocal(5,2) -= NoverL;
                    kLocal(5,5) += NoverL;
                }
                break;
            case D3N12:
                if (dirID == 1)  {
                    double NoverL = N/L;
                    NoverL *= 1.0-Mratio(2)-Mratio(3);
                    kLocal(1,1) += NoverL;
                    kLocal(1,7) -= NoverL;
                    kLocal(7,1) -= NoverL;
                    kLocal(7,7) += NoverL;
                }
                else if (dirID == 2)  {
                    double NoverL = N/L;
                    NoverL *= 1.0-Mratio(0)-Mratio(1);
                    kLocal(2,2) += NoverL;
                    kLocal(2,8) -= NoverL;
                    kLocal(8,2) -= NoverL;
                    kLocal(8,8) += NoverL;
                }
                else if (dirID == 4)  {
                    kLocal(4,2) += Mratio(0)*N;
                    kLocal(4,8) -= Mratio(0)*N;
                    kLocal(10,2) += Mratio(1)*N;
                    kLocal(10,8) -= Mratio(1)*N;
                }
                else if (dirID == 5)  {
                    kLocal(5,1) -= Mratio(2)*N;
                    kLocal(5,7) += Mratio(2)*N;
                    kLocal(11,1) -= Mratio(3)*N;
                    kLocal(11,7) += Mratio(3)*N;
                }
                break;
            default :
                // do nothing
                break;
            }
        }
    }
}
Example #16
0
void TwoNodeLink::addPDeltaForces(Vector &pLocal)
{
    int dirID;
    double N = 0.0;
    double deltal1 = 0.0;
    double deltal2 = 0.0;
    
    for (int i=0; i<numDir; i++)  {
        dirID = (*dir)(i);  // direction 0 to 5;
        
        // get axial force and local disp differences
        if (dirID == 0)
            N = qb(i);
        else if (dirID == 1 && numDIM > 1)
            deltal1 = ul(1+numDOF/2) - ul(1);
        else if (dirID == 2 && numDIM > 2)
            deltal2 = ul(2+numDOF/2) - ul(2);
    }
    
    if (N != 0.0 && (deltal1 != 0.0 || deltal2 != 0.0))  {
        for (int i=0; i<numDir; i++)  {
            dirID = (*dir)(i);  // direction 0 to 5;
            
            // switch on dimensionality of element
            switch (elemType)  {
            case D2N4:
                if (dirID == 1)  {
                    double VpDelta = N*deltal1/L;
                    VpDelta *= 1.0-Mratio(2)-Mratio(3);
                    pLocal(1) -= VpDelta;
                    pLocal(3) += VpDelta;
                }
                break;
            case D2N6: 
                if (dirID == 1)  {
                    double VpDelta = N*deltal1/L;
                    VpDelta *= 1.0-Mratio(2)-Mratio(3);
                    pLocal(1) -= VpDelta;
                    pLocal(4) += VpDelta;
                }
                else if (dirID == 2)  {
                    double MpDelta = N*deltal1;
                    pLocal(2) += Mratio(2)*MpDelta;
                    pLocal(5) += Mratio(3)*MpDelta;
                }
                break;
            case D3N6:
                if (dirID == 1)  {
                    double VpDelta = N*deltal1/L;
                    VpDelta *= 1.0-Mratio(2)-Mratio(3);
                    pLocal(1) -= VpDelta;
                    pLocal(4) += VpDelta;
                }
                else if (dirID == 2)  {
                    double VpDelta = N*deltal2/L;
                    VpDelta *= 1.0-Mratio(0)-Mratio(1);
                    pLocal(2) -= VpDelta;
                    pLocal(5) += VpDelta;
                }
                break;
            case D3N12:
                if (dirID == 1)  {
                    double VpDelta = N*deltal1/L;
                    VpDelta *= 1.0-Mratio(2)-Mratio(3);
                    pLocal(1) -= VpDelta;
                    pLocal(7) += VpDelta;
                }
                else if (dirID == 2)  {
                    double VpDelta = N*deltal2/L;
                    VpDelta *= 1.0-Mratio(0)-Mratio(1);
                    pLocal(2) -= VpDelta;
                    pLocal(8) += VpDelta;
                }
                else if (dirID == 4)  {
                    double MpDelta = N*deltal2;
                    pLocal(4) -= Mratio(0)*MpDelta;
                    pLocal(10) -= Mratio(1)*MpDelta;
                }
                else if (dirID == 5)  {
                    double MpDelta = N*deltal1;
                    pLocal(5) += Mratio(2)*MpDelta;
                    pLocal(11) += Mratio(3)*MpDelta;
                }
                break;
            default :
                // do nothing
                break;
            }
        }
    }
}