protected Object3D() { position = new Vector3(0, 0, 0); scale = 1; rotation = new Quaternion(0, 0, 1, 0); _id = IDManager.NewID; }
Quaternion(ref Quaternion copy) { data = new float[4]; data[0] = copy.data[0]; data[1] = copy.data[1]; data[2] = copy.data[2]; data[3] = copy.data[3]; }
public Matrix(Vector3 position, Quaternion rotation, float scale) { throw new NotImplementedException(); }
public Vector3 transformVector(Vector3 vec) { Vector3 vn = new Vector3(ref vec); vn.normalize(); Quaternion vecQuat = new Quaternion(); Quaternion resQuat = new Quaternion(); vecQuat.X = vn.X; vecQuat.Y = vn.Y; vecQuat.Z = vn.Z; vecQuat.W = 0.0f; resQuat = vecQuat * conjugate(); resQuat = this * resQuat; return new Vector3(resQuat.X, resQuat.Y, resQuat.Z); }
protected Vector3 getNext(float length, float angleClamp, Vector3 normal) { Vector3 rand = new Vector3((float)Util.r.NextDouble() * Util.r.NextSign(), (float)Util.r.NextDouble() * Util.r.NextSign(), (float)Util.r.NextDouble() * Util.r.NextSign()); rand = rand * length; /* Vector3 result; Vector3 axis = rand.cross(normal); float theta = (float)Math.Acos(rand.dot(normal)); theta = (theta > angleClamp) ? theta - (angleClamp * 2f) : theta; Quaternion rot = new Quaternion(theta, axis.X, axis.Y, axis.Z); result = rot.transformVector(rand); theta = (float)(Util.r.NextDouble() * Math.PI * 2); rot = new Quaternion(theta, normal.X, normal.Y, normal.Z); result = rot.transformVector(result); return result; */ Quaternion rot = new Quaternion(angleClamp, rand.X, rand.Y, rand.Z); Vector3 result = rot.transformVector(normal); return result; }