/// <summary> /// Transforms the mesh by the specified transform. /// </summary> /// <param name="mesh">The mesh to transform.</param> /// <param name="transform">The transformation.</param> /// <returns></returns> public static DefaultMesh Transform(this DefaultMesh mesh, Transformation3D transform) { if (transform is null) { throw new ArgumentNullException(nameof(transform)); } var matrix = transform.CalcLocalToWorldRowMajorMatrix(); var newMesh = new DefaultMesh(); newMesh.TexCoord.AddRange(mesh.TexCoord); newMesh.IDs.AddRange(mesh.IDs); foreach (var pos in mesh.Position) { var newPos = Vector3.Transform(pos, matrix); newMesh.Position.Add(newPos); } foreach (var n in mesh.Normal) { var newN = Vector3.Normalize(Vector3.TransformNormal(n, matrix)); newMesh.Normal.Add(newN); } return(newMesh); }
/// <summary> /// Initializes a new instance of the <see cref="Transformation3D"/> class. /// </summary> /// <param name="parent">The parent transformation.</param> public Transformation3D(Transformation3D parent) { Parent = parent; }
/// <summary> /// Initializes a new instance of the <see cref="Scale3D"/> class. /// </summary> /// <param name="scaleVector">The scale vector.</param> /// <param name="parent">The parent transformation</param> public Scale3D(Vector3 scaleVector, Transformation3D parent = null) : base(parent) { matrix = Matrix4x4.CreateScale(scaleVector); }
/// <summary> /// Initializes a new instance of the <see cref="Scale3D"/> class. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="z">The z.</param> /// <param name="parent">The parent transformation</param> public Scale3D(float x, float y, float z, Transformation3D parent = null) : base(parent) { matrix = Matrix4x4.CreateScale(x, y, z); }
/// <summary> /// Initializes a new instance of the <see cref="Scale3D"/> class. /// </summary> /// <param name="uniformScale">The uniform scale factor.</param> /// <param name="parent">The parent transformation</param> public Scale3D(float uniformScale, Transformation3D parent = null) : base(parent) { matrix = Matrix4x4.CreateScale(uniformScale); }
/// <summary> /// Initializes a new instance of the <see cref="Translation3D"/> class. /// </summary> /// <param name="translation">The translation vector.</param> /// <param name="parent">The parent transformation</param> public Translation3D(Vector3 translation, Transformation3D parent = null) : base(parent) { matrix = Matrix4x4.CreateTranslation(translation); }
/// <summary> /// Initializes a new instance of the <see cref="Orbit"/> class. /// </summary> /// <param name="distance">The distance to the target.</param> /// <param name="azimuth">The azimuth or heading.</param> /// <param name="elevation">The elevation or tilt.</param> /// <param name="parent">The parent transformation.</param> public Orbit(float distance = 1f, float azimuth = 0f, float elevation = 0f, Transformation3D parent = null) : base(parent) { Azimuth = azimuth; Distance = distance; Elevation = elevation; }
/// <summary> /// Initializes a new instance of the <see cref="Rotation3D"/> class. /// </summary> /// <param name="axis"></param> /// <param name="degrees">The degrees.</param> /// <param name="parent">The parent transformation</param> public Rotation3D(Axis axis, float degrees, Transformation3D parent = null) : base(parent) { Axis = axis; Degrees = degrees; }