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);
}
예제 #2
0
//==============================================================================
void FreeJoint::setSpatialVelocity(const Eigen::Vector6d& newSpatialVelocity,
                                   const Frame* relativeTo,
                                   const Frame* inCoordinatesOf)
{
  assert(nullptr != relativeTo);
  assert(nullptr != inCoordinatesOf);

  if (getChildBodyNode() == relativeTo)
  {
    dtwarn << "[FreeJoint::setSpatialVelocity] Invalid reference frame "
              "for newSpatialVelocity. It shouldn't be the child BodyNode.\n";
    return;
  }

  // Change the reference frame of "newSpatialVelocity" to the child body node
  // frame.
  Eigen::Vector6d targetRelSpatialVel = newSpatialVelocity;
  if (getChildBodyNode() != inCoordinatesOf)
  {
    targetRelSpatialVel
        = math::AdR(inCoordinatesOf->getTransform(getChildBodyNode()),
                    newSpatialVelocity);
  }

  // Compute the target relative spatial velocity from the parent body node to
  // the child body node.
  if (getChildBodyNode()->getParentFrame() != relativeTo)
  {
    if (relativeTo->isWorld())
    {
      const Eigen::Vector6d parentVelocity = math::AdInvT(
            getLocalTransform(),
            getChildBodyNode()->getParentFrame()->getSpatialVelocity());

      targetRelSpatialVel -= parentVelocity;
    }
    else
    {
      const Eigen::Vector6d parentVelocity = math::AdInvT(
            getLocalTransform(),
            getChildBodyNode()->getParentFrame()->getSpatialVelocity());
      const Eigen::Vector6d arbitraryVelocity = math::AdT(
            relativeTo->getTransform(getChildBodyNode()),
            relativeTo->getSpatialVelocity());

      targetRelSpatialVel += -parentVelocity + arbitraryVelocity;
    }
  }

  setRelativeSpatialVelocity(targetRelSpatialVel);
}
예제 #3
0
파일: view.cpp 프로젝트: hackborn/gifbox
glm::mat4 View::getGlobalTransform() const {
	glm::mat4		g(getLocalTransform());
	for (View *v=mParent; v; v=v->mParent) {
		g = v->getLocalTransform() * g;
	}
	return g;
}
예제 #4
0
void Layer::localToAncestor(const Layer* ancestor, SkMatrix* matrix) const {
    if (this == ancestor) {
        matrix->setIdentity();
        return;
    }

    getLocalTransform(matrix);

    // Fixed position layers simply use the root layer's transform.
    if (shouldInheritFromRootTransform()) {
        ASSERT(!ancestor);
        matrix->postConcat(getRootLayer()->getMatrix());
        return;
    }

    // Apply the local and child transforms for every layer between this layer
    // and ancestor.
    ASSERT(isAncestor(ancestor));
    for (const Layer* layer = this->fParent; layer != ancestor; layer = layer->fParent) {
        SkMatrix tmp;
        layer->getLocalTransform(&tmp);
        tmp.preConcat(layer->getChildrenMatrix());
        matrix->postConcat(tmp);
    }

    // If ancestor is not the root layer, apply its child transformation too.
    if (ancestor)
        matrix->postConcat(ancestor->getChildrenMatrix());
}
예제 #5
0
bool ScrollableLayerAndroid::scrollRectIntoView(const SkIRect& rect)
{
    // Apply the local transform to the rect to get it relative to the parent
    // layer.
    SkMatrix localTransform;
    getLocalTransform(&localTransform);
    SkRect transformedRect;
    transformedRect.set(rect);
    localTransform.mapRect(&transformedRect);

    // Test left before right to prioritize left alignment if transformedRect is wider than
    // visible area.
    int x = m_scrollLimits.fLeft;
    if (transformedRect.fLeft < m_scrollLimits.fLeft)
        x = transformedRect.fLeft;
    else if (transformedRect.fRight > m_scrollLimits.fRight)
        x = transformedRect.fRight - std::max(m_scrollLimits.width(), transformedRect.width());

    // Test top before bottom to prioritize top alignment if transformedRect is taller than
    // visible area.
    int y = m_scrollLimits.fTop;
    if (transformedRect.fTop < m_scrollLimits.fTop)
        y = transformedRect.fTop;
    else if (transformedRect.fBottom > m_scrollLimits.fBottom)
        y = transformedRect.fBottom - std::max(m_scrollLimits.height(), transformedRect.height());

    return scrollTo(x - getPosition().fX, y - getPosition().fY);
}
예제 #6
0
Matrix SceneNode::getGlobalTransform() const
{
    if(this->m_pParent == NULL)
    {
        return getLocalTransform();
    }
    return m_pParent->getGlobalTransform() * this->getLocalTransform();
}
예제 #7
0
//==============================================================================
void ZeroDofJoint::addChildArtInertiaImplicitTo(
    Eigen::Matrix6d& _parentArtInertia, const Eigen::Matrix6d& _childArtInertia)
{
  // Add child body's articulated inertia to parent body's articulated inertia.
  // Note that mT should be updated.
  _parentArtInertia += math::transformInertia(getLocalTransform().inverse(),
                                              _childArtInertia);
}
예제 #8
0
	void Sky::setUpTransFormation(TransformationInfo & info)
	{
		Drawable::setUpTransFormation(info);
		auto mat = m_camera->getTranslationMatrix();
		//mat.data()[13] = 0.f;
		info.m_worldMatrix = getLocalTransform();
		m_skyBoxTechnique->setVar("viewdir",info.m_worldMatrix.forward());
	}
예제 #9
0
//==============================================================================
void ZeroDofJoint::addChildBiasImpulseTo(
    Eigen::Vector6d& _parentBiasImpulse,
    const Eigen::Matrix6d& /*_childArtInertia*/,
    const Eigen::Vector6d& _childBiasImpulse)
{
  // Add child body's bias force to parent body's bias impulse. Note that mT
  // should be updated.
  _parentBiasImpulse += math::dAdInvT(getLocalTransform(), _childBiasImpulse);
}
예제 #10
0
void the::camera::update()
{
    the::node::update();
    eyePosition   = getWorldPosition();
    prjMatrix     = mat4::perspective(_fov, _aspect, _zNear, _zFar);
    viewMatrix    = getLocalTransform().inverse();
    prjViewMatrix = prjMatrix * viewMatrix;
    _needUpdate = true;
}
예제 #11
0
/*! \brief Convenience function.
*
*/
void
TrackSpiralArcSpiral::setLocalEndPoint(const QPointF &endPoint)
{
    // Local to internal (Parameters are given in internal coordinates) //
    //
    //	setEndPoint(getLocalTransform().inverted().map(endPoint));
    pa_->pEnd_ = getLocalTransform().inverted().map(endPoint);
    pa_->init();
    applyParameters();
}
예제 #12
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;
    }
}
예제 #13
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();
    }
}
예제 #14
0
//==============================================================================
void ZeroDofJoint::addChildBiasForceTo(
    Eigen::Vector6d& _parentBiasForce,
    const Eigen::Matrix6d& _childArtInertia,
    const Eigen::Vector6d& _childBiasForce,
    const Eigen::Vector6d& _childPartialAcc)
{
  // Add child body's bias force to parent body's bias force. Note that mT
  // should be updated.
  _parentBiasForce += math::dAdInvT(getLocalTransform(), _childBiasForce
                                    + _childArtInertia*_childPartialAcc);
}
예제 #15
0
파일: sceneNode.cpp 프로젝트: xThaid/Xi
void SceneNode::updateWorldTransform()
{
	worldTransform_ = getLocalTransform();

	if (!isRootNode())
	{
		worldTransform_ = parentNode_->getWorldTransform() * worldTransform_;
	}

	dirty_ = false;
}
예제 #16
0
void Layer::draw(SkCanvas* canvas, SkScalar opacity) {
#if 0
    SkString str1, str2;
 //   getMatrix().toDumpString(&str1);
 //   getChildrenMatrix().toDumpString(&str2);
    SkDebugf("--- drawlayer %p opacity %g size [%g %g] pos [%g %g] matrix %s children %s\n",
             this, opacity * getOpacity(), m_size.width(), m_size.height(),
             m_position.fX, m_position.fY, str1.c_str(), str2.c_str());
#endif

    opacity = SkScalarMul(opacity, getOpacity());
    if (opacity <= 0) {
//        SkDebugf("---- abort drawing %p opacity %g\n", this, opacity);
        return;
    }

    SkAutoCanvasRestore acr(canvas, true);

    // apply our local transform
    {
        SkMatrix tmp;
        getLocalTransform(&tmp);
        if (shouldInheritFromRootTransform()) {
            // should we also apply the root's childrenMatrix?
            canvas->setMatrix(getRootLayer()->getMatrix());
        }
        canvas->concat(tmp);
    }

    onDraw(canvas, opacity);

#ifdef DEBUG_DRAW_LAYER_BOUNDS
    {
        SkRect r = SkRect::MakeSize(getSize());
        SkPaint p;
        p.setAntiAlias(true);
        p.setStyle(SkPaint::kStroke_Style);
        p.setStrokeWidth(SkIntToScalar(2));
        p.setColor(0xFFFF44DD);
        canvas->drawRect(r, p);
        canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, p);
        canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, p);
    }
#endif

    int count = countChildren();
    if (count > 0) {
        canvas->concat(getChildrenMatrix());
        for (int i = 0; i < count; i++) {
            getChild(i)->draw(canvas, opacity);
        }
    }
}
예제 #17
0
	Matrix4x4  SceneNode::getWorldTransfrom()
	{
		Matrix4x4 local = getLocalTransform();
		Matrix4x4 world = local;

		if(m_parentNode)
		{
			world = local * m_parentNode->getWorldTransfrom();
		}

		return world;
	}
예제 #18
0
파일: view.cpp 프로젝트: hackborn/gifbox
void View::draw(const kt::view::DrawParams &p) {
	if (isHidden()) return;

	ci::gl::ScopedModelMatrix	smm;
	auto ctx = ci::gl::context();
	ctx->getModelMatrixStack().back() *= getLocalTransform();

	onDraw(p);
	for (auto& it : mChildren) {
		if (it) it->draw(p);
	}
}
예제 #19
0
	void Object::xform( bool beAllInstance )
	{
		Matrix4 const& trans = getLocalTransform();

		MeshIterator iter = getElements();
		for ( ; iter.haveMore() ; iter.next() )
		{
			MeshBase* mesh = iter.get()->getMesh();
			iter.get()->getUnit().mesh = mesh->xform( trans , beAllInstance );
		}

		mLocalTrans.setIdentity();
	}
예제 #20
0
/**
 * Draws this game object and its children.
 *
 * @date       2015-02-25
 *
 * @revisions  2015-04-03
 *             This method now caches the transformations
 *             that are passed down the hierarchy system
 *
 *             2015-04-05
 *             This method now supports the overridable drawChildren() method
 *             in addition to the already available overridable draw() method
 *
 * @designer   Melvin Loho
 *
 * @programmer Melvin Loho
 *
 * @param      renderer The renderer
 * @param      states   The render states
 */
void BGO::drawSceneGraph(Renderer& renderer, sf::RenderStates states) const
{
	// Draw self
	draw(renderer, states);

	// Combine transforms (caller's + mine)
	states.transform *= getLocalTransform();

	// cache global transform
	m_globaltrans = states.transform;

	// Draw children
	if (!m_ignoringChildren) drawChildren(renderer, states);
}
예제 #21
0
/*! \brief Convenience function.
*
*/
void
TrackSpiralArcSpiral::setLocalStartPoint(const QPointF &startPoint)
{
    // Local to internal (Parameters are given in internal coordinates) //
    //
    QPointF deltaPos(getLocalTransform().inverted().map(startPoint) /* - getPoint(getSStart())*/); // getPoint(s_) == 0 by definition
    //setEndPoint(pa_->pEnd_ - deltaPos);
    pa_->pEnd_ = pa_->pEnd_ - deltaPos;
    pa_->init();
    applyParameters();

    // Set local translation //
    //
    setLocalTranslation(startPoint);
}
예제 #22
0
void Transform::update( float delta )
{
	if( !externalTransform )
		transform = getLocalTransform();

	if( requiresBoundingVolumeUpdate() )
		updateBoundingVolume();

	if( wasChanged )
	{
		onTransformed();
		setChanged(false);
	}

	//externalTransform = false;
}
예제 #23
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));
    }
}
예제 #24
0
glm::mat4 GameObject::getWorldTransform()
{
	if ( parent ) return  parent->getWorldTransform() * getLocalTransform();
	else return getLocalTransform();
}
예제 #25
0
//==============================================================================
void FreeJoint::setSpatialAcceleration(
    const Eigen::Vector6d& newSpatialAcceleration,
    const Frame* relativeTo,
    const Frame* inCoordinatesOf)
{
  assert(nullptr != relativeTo);
  assert(nullptr != inCoordinatesOf);

  if (getChildBodyNode() == relativeTo)
  {
    dtwarn << "[FreeJoint::setSpatialAcceleration] Invalid reference "
           << "frame for newSpatialAcceleration. It shouldn't be the child "
           << "BodyNode.\n";
    return;
  }

  // Change the reference frame of "newSpatialAcceleration" to the child body
  // node frame.
  Eigen::Vector6d targetRelSpatialAcc = newSpatialAcceleration;
  if (getChildBodyNode() != inCoordinatesOf)
  {
    targetRelSpatialAcc
        = math::AdR(inCoordinatesOf->getTransform(getChildBodyNode()),
                    newSpatialAcceleration);
  }

  // Compute the target relative spatial acceleration from the parent body node
  // to the child body node.
  if (getChildBodyNode()->getParentFrame() != relativeTo)
  {
    if (relativeTo->isWorld())
    {
      const Eigen::Vector6d parentAcceleration
          = math::AdInvT(
            getLocalTransform(),
            getChildBodyNode()->getParentFrame()->getSpatialAcceleration())
            + math::ad(getChildBodyNode()->getSpatialVelocity(),
                       getLocalJacobianStatic() * getVelocitiesStatic());

      targetRelSpatialAcc -= parentAcceleration;
    }
    else
    {
      const Eigen::Vector6d parentAcceleration
          = math::AdInvT(
            getLocalTransform(),
            getChildBodyNode()->getParentFrame()->getSpatialAcceleration())
            + math::ad(getChildBodyNode()->getSpatialVelocity(),
                       getLocalJacobianStatic() * getVelocitiesStatic());
      const Eigen::Vector6d arbitraryAcceleration =
          math::AdT(relativeTo->getTransform(getChildBodyNode()),
                    relativeTo->getSpatialAcceleration())
          - math::ad(getChildBodyNode()->getSpatialVelocity(),
                     math::AdT(relativeTo->getTransform(getChildBodyNode()),
                               relativeTo->getSpatialVelocity()));

      targetRelSpatialAcc += -parentAcceleration + arbitraryAcceleration;
    }
  }

  setRelativeSpatialAcceleration(targetRelSpatialAcc);
}
예제 #26
0
파일: Joint.cpp 프로젝트: jeffeb3/dart
//==============================================================================
void Joint::applyGLTransform(renderer::RenderInterface* _ri)
{
  _ri->transform(getLocalTransform());
}
예제 #27
0
Ogre::Matrix4 Node::getWorldTransform() const
{
    if(parent != NULL)
        return parent->getWorldTransform() * getLocalTransform();
    return getLocalTransform();
}