Hello, I'm having a problem while writing my skew class.
The problem is that I dont have accuracy in my skewing, it's like time based, while I'd like to have accurate to a factor.
If I set a skewingAmmount of = 1 I'd like to see a skew at that ammount, but right now I see some random skewing.
So here's my code, and what am I doing wrong here? I suspect the Unity' class "MultiplyVector" needs to be changed.
using UnityEngine;
using System.Collections;
public class SkewMesh : MonoBehaviour
{
public float skewAmmount = 1.0f;
private MeshFilter mf;
private Vector3[] vertices;
private Matrix4x4 matrix;
private int vertLen;
private float lastSkewAmmount;
void Start ()
{
mf = transform.GetComponent<MeshFilter>();
vertLen = mf.sharedMesh.vertices.Length;
vertices = new Vector3[vertLen];
vertices = mf.sharedMesh.vertices;
}
void UpdateVert()
{
// create skew matrix
Matrix4x4 matrix = new Matrix4x4();
matrix[0,0] = 1.0f;
matrix[1,1] = 1.0f;
matrix[2,2] = 1.0f;
matrix[3,3] = 1.0f;
matrix[2,0] = Mathf.Tan(skewAmmount * Mathf.Deg2Rad);
// apply skew matrix
for(int i = 0; i < vertLen; ++i){
vertices[i] = matrix.MultiplyVector(vertices[i]);
}
mf.sharedMesh.vertices = vertices;
lastSkewAmmount = skewAmmount;
}
void FixedUpdate()
{
if(skewAmmount != lastSkewAmmount)
UpdateVert();
}
}
If there is a simpler way than using Matrix, i'd be glad to hear about it :) thanks!