Entity	DemoScene::createPlanet(float rotSpeed, float orbitSpeed,
												glm::vec3 &pos, glm::vec3 &scale,
												std::string const &shader,
												std::string const &tex1, std::string const &tex2, std::string const &tex3,
												std::string const &tex4)
{
	auto p = createEntity();
	auto e = createEntity();
	p->addComponent<Component::GraphNode>();
	e->addComponent<Component::GraphNode>();

	e->setLocalTransform() = glm::translate(e->getLocalTransform(), pos);
	e->setLocalTransform() = glm::scale(e->getLocalTransform(), scale);

	SmartPointer<Component::MeshRenderer>	r = e->addComponent<Component::MeshRenderer>("model:ball");

	r->setShader(shader);
	r->getMaterials()[0].ambientTex = _engine.getInstance<Resources::ResourceManager>().getResource(tex1);
	r->getMaterials()[0].diffuseTex = _engine.getInstance<Resources::ResourceManager>().getResource(tex2);
	r->getMaterials()[0].specularTex = _engine.getInstance<Resources::ResourceManager>().getResource(tex3);
	r->getMaterials()[0].normalTex = _engine.getInstance<Resources::ResourceManager>().getResource(tex4);
	
	e->addComponent<Component::RotationForce>(glm::vec3(0, orbitSpeed, 0));
	p->getComponent<Component::GraphNode>()->addSon(e);
	p->addComponent<Component::RotationForce>(glm::vec3(0, rotSpeed, 0));
	return (p);
}
Exemplo n.º 2
0
void ParticleRenderable::do_draw()
{
    //Update the parent and local transform matrix to position the geometric data according to the particle's data.
    const float& pRadius = m_particle->getRadius();
    const glm::vec3& pPosition = m_particle->getPosition();
    float toRotate = m_particle->getAngle();
    glm::mat4 scale = glm::scale(glm::mat4(1.0), glm::vec3(pRadius));
    glm::mat4 translate = glm::translate(glm::mat4(1.0), glm::vec3(pPosition));
    glm::mat4 rotate = glm::rotate(glm::mat4(1.0), toRotate, glm::vec3(0,0,1));
    setLocalTransform(translate*scale*rotate);

    //Draw geometric data
    int positionLocation = m_shaderProgram->getAttributeLocation("vPosition");
    int colorLocation = m_shaderProgram->getAttributeLocation("vColor");
    int normalLocation = m_shaderProgram->getAttributeLocation("vNormal");
    int modelLocation = m_shaderProgram->getUniformLocation("modelMat");

    if (modelLocation != ShaderProgram::null_location) {
        glcheck(glUniformMatrix4fv(modelLocation, 1, GL_FALSE, glm::value_ptr(getModelMatrix())));
    }

    if (positionLocation != ShaderProgram::null_location) {
        glcheck(glEnableVertexAttribArray(positionLocation));
        glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_pBuffer));
        glcheck(glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, (void*)0));
    }

    if (colorLocation != ShaderProgram::null_location) {
        glcheck(glEnableVertexAttribArray(colorLocation));
        glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_cBuffer));
        glcheck(glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, (void*)0));
    }

    if (normalLocation != ShaderProgram::null_location) {
        glcheck(glEnableVertexAttribArray(normalLocation));
        glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_nBuffer));
        glcheck(glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, 0, (void*)0));
    }

    //Draw triangles elements
    glcheck(glDrawArrays(GL_TRIANGLES,0, m_positions.size()));

    if (positionLocation != ShaderProgram::null_location) {
        glcheck(glDisableVertexAttribArray(positionLocation));
    }
    if (colorLocation != ShaderProgram::null_location) {
        glcheck(glDisableVertexAttribArray(colorLocation));
    }
    if (normalLocation != ShaderProgram::null_location) {
        glcheck(glDisableVertexAttribArray(normalLocation));
    }
}
Exemplo n.º 3
0
TrackSpiralArcSpiral::TrackSpiralArcSpiral(TrackElementSpiral *inSpiral, TrackElementArc *arc, TrackElementSpiral *outSpiral)
    : TrackComposite()
    , inSpiral_(inSpiral)
    , arc_(arc)
    , outSpiral_(outSpiral)
    , trackSpArcSChanges_(0x0)
    , validParameters_(false)
{
    // Type //
    //
    setTrackType(TrackComponent::DTT_SPARCS);

    // Transform //
    //
    double sHeading = inSpiral_->getLocalHeading(inSpiral_->getSStart());
    setLocalTransform(inSpiral_->getLocalPoint(inSpiral_->getSStart()), sHeading);

    inSpiral_->setLocalTransform(0.0, 0.0, 0.0); // identity matrix
    arc_->setLocalTransform(getLocalTransform().inverted().map(arc_->getLocalPoint(arc_->getSStart())), arc_->getLocalHeading(arc_->getSStart()) - sHeading);
    outSpiral_->setLocalTransform(getLocalTransform().inverted().map(outSpiral_->getLocalPoint(outSpiral_->getSStart())), outSpiral_->getLocalHeading(outSpiral_->getSStart()) - sHeading);

    // Composite //
    //
    addTrackComponent(inSpiral);
    addTrackComponent(arc);
    addTrackComponent(outSpiral);

    // Parameters //
    //
    pa_ = new SpArcSParameters(outSpiral_->getLocalPoint(outSpiral_->getSEnd()), outSpiral_->getLocalHeadingRad(outSpiral_->getSEnd()), 1.0);

    pa_->setFactor(calcFactor());

    if (!pa_->isValid()) // does also initialize the parameters
    {
        validParameters_ = false;
        qDebug() << "WARNING 1004261530! Loaded TrackSpiralArcSpiral is not valid!";
    }
    else
    {
        validParameters_ = true;
    }
}
Exemplo n.º 4
0
/*!
  Informs that the particle position has been updated by the particle system.
  The QGLSceneNode is updated to move the visual representation of the particle.
*/
void LightParticle::particleUpdated()
{
    if (isActive() == true) {
        float psize = getLifeTime() * 2.0f;

        if (psize > 1.0f)
            psize = 1.0f;

        QMatrix4x4 mat;
        mat.rotate(m_Rotation[2], 0,0,1);
        mat.scale(psize);

        setLocalTransform(mat);
        setPosition(m_ParticlePos);
    }
    else {
        setPosition(QVector3D());
    }
}
Exemplo n.º 5
0
/*! \brief Convenience function.
*
*/
void
TrackSpiralArcSpiral::setLocalPointAndHeading(const QPointF &point, double hdg, bool isStart)
{
    while (hdg <= -180.0)
    {
        hdg += 360.0;
    }
    while (hdg > 180.0)
    {
        hdg -= 360.0;
    }

    if (isStart)
    {
        // Local to internal (Parameters are given in internal coordinates) //
        //
        QPointF deltaPos(getLocalTransform().inverted().map(point) /* - getPoint(getSStart())*/); // getPoint(s_) == 0 by definition
        double deltaHeading(hdg - heading());

        QTransform trafo;
        trafo.rotate(deltaHeading);

        pa_->setEndHeadingDeg(pa_->getEndHeadingRad() * 360.0 / (2.0 * M_PI) - deltaHeading);
        pa_->setEndPoint(trafo.inverted().map(pa_->pEnd_ - deltaPos));
        pa_->init();
        applyParameters();

        // Set local transform //
        //
        setLocalTransform(point, hdg);
    }
    else
    {
        // Local to internal (Parameters are given in internal coordinates) //
        //
        pa_->pEnd_ = getLocalTransform().inverted().map(point);
        pa_->headingEnd_ = (hdg - getLocalHeading(getSStart())) * 2.0 * M_PI / 360.0;

        pa_->init();
        applyParameters();
    }
}
Exemplo n.º 6
0
TrackSpiralArcSpiral::TrackSpiralArcSpiral(const QPointF &startPos, const QPointF &endPos, double startHeadingDeg, double endHeadingDeg, double factor)
    : TrackComposite()
    , inSpiral_(NULL)
    , arc_(NULL)
    , outSpiral_(NULL)
    , trackSpArcSChanges_(0x0)
    , validParameters_(false)
{
    // Type //
    //
    setTrackType(TrackComponent::DTT_SPARCS);

    // Track //
    //
    inSpiral_ = new TrackElementSpiral(0.0, 0.0, 0.0, 0.0, 49.6551724137931, 0.0, 0.003448275862068966);
    arc_ = new TrackElementArc(49.61879011646819, 1.416290576997416, 0.0856123662306776 * 360.0 / (2.0 * M_PI), 49.65517241379311, 124.3448275876508, 0.003448275862068966);
    outSpiral_ = new TrackElementSpiral(167.5020491350196, 37.88185581403775, 0.5143876337743012 * 360.0 / (2.0 * M_PI), 174, 49.6551724137931, 0.003448275862068966, 0.0);

    addTrackComponent(inSpiral_);
    addTrackComponent(arc_);
    addTrackComponent(outSpiral_);

    setLocalTransform(startPos, startHeadingDeg);

    // Parameters //
    //
    pa_ = new SpArcSParameters(outSpiral_->getLocalPoint(outSpiral_->getSEnd()), outSpiral_->getLocalHeadingRad(outSpiral_->getSEnd()), factor);
    //	pa_->setFactor(calcFactor());

    setGlobalPointAndHeading(endPos, endHeadingDeg, false);

    if (pa_->isValid())
    {
        validParameters_ = true;
    }
}
Exemplo n.º 7
0
void LegRenderable::do_draw()
{

    //Update the parent and local transform matrix to position the geometric data according to the particle's data.
    float thighAngle = 4 * 3.14 / 3.0;
    float toRotateBody = 0.5 * m_particle->getBodyAngle();

    glm::mat4 ParentTransform;
    if (m_isLeft) {
        ParentTransform = glm::scale(glm::mat4(), glm::vec3(1.5, 1.5, 1.6));
        ParentTransform = glm::translate(ParentTransform, glm::vec3(-0.4, -0.3, 2));
        ParentTransform = glm::rotate(ParentTransform, -thighAngle, glm::vec3(0, 1, 0.0));
        glm::mat4 rotate = glm::rotate(glm::mat4(1.0), 0.0f, glm::vec3(0,1,0));
        if (toRotateBody < 0) {
            rotate = glm::rotate(glm::mat4(1.0), toRotateBody, glm::vec3(0,1,0));
        }
        ParentTransform = ParentTransform * rotate;
    } else {
        ParentTransform = glm::scale(glm::mat4(), glm::vec3(1.5, 1.5, 1.6));
        ParentTransform = glm::translate(ParentTransform, glm::vec3(-0.4, 0.3, 2));
        ParentTransform = glm::rotate(ParentTransform, -thighAngle, glm::vec3(0, 1, 0.0));
        glm::mat4 rotate = glm::rotate(glm::mat4(1.0), 0.0f, glm::vec3(0,1,0));
        if (toRotateBody > 0) {
            rotate = glm::rotate(glm::mat4(1.0), -toRotateBody, glm::vec3(0,1,0));
        }
        ParentTransform = ParentTransform * rotate;
    }

    setLocalTransform(getLocalTransform());
    setParentTransform(ParentTransform);

    //Draw geometric data
    int positionLocation = m_shaderProgram->getAttributeLocation("vPosition");
    int colorLocation = m_shaderProgram->getAttributeLocation("vColor");
    int normalLocation = m_shaderProgram->getAttributeLocation("vNormal");
    int modelLocation = m_shaderProgram->getUniformLocation("modelMat");

    if (modelLocation != ShaderProgram::null_location) {
        glcheck(glUniformMatrix4fv(modelLocation, 1, GL_FALSE, glm::value_ptr(getModelMatrix())));
    }

    if (positionLocation != ShaderProgram::null_location) {
        glcheck(glEnableVertexAttribArray(positionLocation));
        glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_pBuffer));
        glcheck(glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, (void*)0));
    }

    if (colorLocation != ShaderProgram::null_location) {
        glcheck(glEnableVertexAttribArray(colorLocation));
        glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_cBuffer));
        glcheck(glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, (void*)0));
    }

    if (normalLocation != ShaderProgram::null_location) {
        glcheck(glEnableVertexAttribArray(normalLocation));
        glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_nBuffer));
        glcheck(glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, 0, (void*)0));
    }

    //Draw triangles elements
    glcheck(glDrawArrays(GL_TRIANGLES,0, m_positions.size()));

    if (positionLocation != ShaderProgram::null_location) {
        glcheck(glDisableVertexAttribArray(positionLocation));
    }
    if (colorLocation != ShaderProgram::null_location) {
        glcheck(glDisableVertexAttribArray(colorLocation));
    }
    if (normalLocation != ShaderProgram::null_location) {
        glcheck(glDisableVertexAttribArray(normalLocation));
    }
}