0
\$\begingroup\$

Let us suppose I have an array of Vector3, it contains vertices. Now I want to scale the vertices and/or change the center point of the texture (move texture relatively).

I have a Vector3 which is a new center point and I have a Vector3 which is vector for scaling along x, y and z.

How can I construct a needed matrix in Unity?

I am very new to all this, so, please, in case of any misunderstanding ask me about it.

Here is what I was able to find on my own. The problem with it, though, is that I can not infer what I need from it. I need a little bit more peculiar thing.

\$\endgroup\$
1
\$\begingroup\$

Why use a matrix for this at all?

Vector3 ScaleAndShiftVector(Vector3 v, Vector3 shift, Vector3 scale) {
    return Vector3.Scale(v, scale) + shift;
}

You could do this with a matrix,

var matrix = Matrix4x4.TRS(shift, Quaternion.identity, scale);
var transformed = matrix.MultiplyPoint3x4(v);

but that does more calculations than you need, since it's accounting for rotation too which you're not using.

\$\endgroup\$
  • \$\begingroup\$ It does not work somehow. I after modifying the vertex of the texture in this way the image does not change its size. \$\endgroup\$ – cutMeDown Jan 20 '18 at 11:08
  • \$\begingroup\$ Textures don't have vertices. Meshes do. Are you manipulating the positions of a mesh's vertices, or its texture coordinates, or something else? Show your code in your question and we can help you find the error. \$\endgroup\$ – DMGregory Jan 20 '18 at 12:37

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.