public Camera(Vector3 position, Quaternion rotation, float aspectRatio, float fov) { _position = position; _rotation = rotation.Normalized(); AspectRatio = aspectRatio; FoV = fov; }
public Mesh(Vector3[] vertices, Triangle[] triangles, Vector3 position, Quaternion rotation, Shader shader, ISampler normalSampler) { Vertices = vertices; _triangles = triangles; Shader = shader; Position = position; Rotation = rotation; _normalSampler = normalSampler; Init(); }
public static Quaternion LookRotation(Vector3 direction, Vector3 up) { Vector3 directionNormalized = direction.Normalized(); // Rotate around up vector Vector3 directionProjected = (directionNormalized - up * Vector3.Dot(directionNormalized, up)).Normalized(); Vector3 forwardProjected = (Vector3.Forward - up * Vector3.Dot(Vector3.Forward, up)).Normalized(); float rotationAroundUpAngleHalf = (float) Math.Acos((Vector3.Dot(directionProjected, forwardProjected))) / 2; var rotationAroundUp = new Quaternion(up * (float) Math.Sin(rotationAroundUpAngleHalf), (float) Math.Cos(rotationAroundUpAngleHalf)); // Rotate around horizontal vector Vector3 rotationAxis = Vector3.Cross(directionNormalized, directionProjected); double angleHalf = Math.Acos(Vector3.Dot(directionNormalized, directionProjected)) / 2; var rotationAroundHorizontal = new Quaternion(rotationAxis * (float) Math.Sin(angleHalf), (float) Math.Cos(angleHalf)); return rotationAroundUp * rotationAroundHorizontal; }
public Vector3 RotatedBy(Quaternion quaternion) { Vector3 t = 2 * Cross(quaternion.XYZ, this); Vector3 rotated = this + quaternion.W * t + Cross(quaternion.XYZ, t); return rotated; }