void localToTarget(float &x, float& y, IFlashDisplayObject* target)
	{
		if ( target == 0 ){
			//по определению
			localToGlobal(x, y);

		//Несколько частных случаев для ускорения работы (getCommonAncestor дорогой)
		}else if ( target == this ){
			return;
		}else if ( target == parent ){
			return localToParent(x, y);
		}else if ( target->getParent() == parent ){
			localToParent(x, y);
			target->parentToLocal(x, y);
		}else{
			IFlashDisplayObject* commonAncestor = getCommonAncestor(target);

			if ( !commonAncestor ){
				localToGlobal(x, y);
				target->globalToLocal(x, y);
			}else{
				IFlashDisplayObject* current = this;
				while ( current != commonAncestor ){
					current->localToParent(x, y);
					current = current->getParent();
				}
				__ancestorToLocal(x, y, current, target);
			}
		}
	};
Exemplo n.º 2
0
void EclassModelNode::updateTransform()
{
	localToParent() = Matrix4::getIdentity();
	localToParent().translateBy(_origin);

	localToParent().multiplyBy(_rotation.getMatrix4());

	EntityNode::transformChanged();
}
Exemplo n.º 3
0
void SceneObject::draw(ShaderStack *stack)
{
    bool shaderOverridden = false;
    if ( !geometry()->isEmpty() )
    {
        // If we have a shader override, push the override.
        QString shaderOverrideName = geometry()->shaderOverride();
        if ( !shaderOverrideName.isNull() )
        {
            ShaderProgram* program = resourceManager()->shader(shaderOverrideName);
            if ( program )
            {
                shaderOverridden = true;
                stack->shaderPush(program);
            }
        }
    }

    // Multiply the modelWorld matrix by our current one.
    // This updates the shader uniform too.
    // We do this even if the geometry is empty, so that the
    // transformation will apply recursively.
    // It is the caller's responsibility to manage pushing
    // and popping of the m2w matrix.
    stack->modelToWorldPostMultiply(localToParent());

    if ( !geometry()->isEmpty() )
    {
        // Upload and bind the geometry.
        geometry()->upload();
        geometry()->bindVertices(true);
        geometry()->bindIndices(true);

        // Apply the data format.
        geometry()->applyDataFormat(stack->shaderTop());

        // If we're selected, set the global colour.
        bool pushedColor = false;
        MapDocument* doc = m_pScene->document();
        if ( doc->selectedSet().contains(this) )
        {
            pushedColor = true;
            stack->globalColorPush();
            stack->globalColorSetTop(doc->selectedColor());
        }

        // Apply the texture.
        QOpenGLTexture* tex = resourceManager()->texture(geometry()->texture(0));
        tex->bind(0);

        // Draw.
        geometry()->draw();

        if ( pushedColor )
        {
            stack->globalColorPop();
        }

        // Pop the shader if we pushed one earlier.
        if ( shaderOverridden )
        {
            stack->shaderPop();
        }
    }
}