void BoxGeometryComponent::draw(Matrix4 transformation) { Point4 rotated_move = rotate(myRotation) * Point4(myMove.x, myMove.y, myMove.z); //Matrix4 total_transform = transformation * translate(Vector4(rotated_move.x, rotated_move.y, rotated_move.z)) * rotate(myRotation) * scale(myScale); Matrix4 total_transform = transformation * translate(myTranslation) * rotate(myRotation) * scale(myScale); Matrix4 transform_noscale = transformation * translate(myTranslation) * rotate(myRotation); std::for_each(myTriangles.begin(), myTriangles.end(), std::bind2nd(std::ptr_fun(TransformAndDraw), total_transform)); // Draw all subcomponents. std::for_each(myComponents.begin(), myComponents.end(), [&transform_noscale](std::shared_ptr<BoxGeometryComponent> x){ x->draw(transform_noscale); }); }
/** * Apply property-based transformations to input matrix * * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 * matrix computation instead of the Skia 3x3 matrix + camera hackery. */ void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const { if (properties().getLeft() != 0 || properties().getTop() != 0) { matrix.translate(properties().getLeft(), properties().getTop()); } if (properties().getStaticMatrix()) { mat4 stat(*properties().getStaticMatrix()); matrix.multiply(stat); } else if (properties().getAnimationMatrix()) { mat4 anim(*properties().getAnimationMatrix()); matrix.multiply(anim); } bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); if (properties().hasTransformMatrix() || applyTranslationZ) { if (properties().isTransformTranslateOnly()) { matrix.translate(properties().getTranslationX(), properties().getTranslationY(), true3dTransform ? properties().getZ() : 0.0f); } else { if (!true3dTransform) { matrix.multiply(*properties().getTransformMatrix()); } else { mat4 true3dMat; true3dMat.loadTranslate( properties().getPivotX() + properties().getTranslationX(), properties().getPivotY() + properties().getTranslationY(), properties().getZ()); true3dMat.rotate(properties().getRotationX(), 1, 0, 0); true3dMat.rotate(properties().getRotationY(), 0, 1, 0); true3dMat.rotate(properties().getRotation(), 0, 0, 1); true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); matrix.multiply(true3dMat); } } } }