// here we update translations, scaling and rotations protected virtual void ApplyMatrix() { if (this.noMatrix) { return; } #if __SHARPDX__ Matrix4 m = Matrix4.Translation(-this.pivot.X, -this.pivot.Y, 0) * Matrix4.Scaling(this.scale.X, this.scale.Y, 1) * Matrix4.RotationZ(this.rotation) * Matrix4.Translation(this.position.X, this.position.Y, 0); #else // WARNING !!! OpenTK uses row-major while OpenGL uses column-major Matrix4 m = Matrix4.CreateTranslation(-this.pivot.X, -this.pivot.Y, 0) * #if !__MOBILE__ Matrix4.CreateScale(this.scale.X, this.scale.Y, 1) * #else Matrix4.Scale(this.scale.X, this.scale.Y, 1) * #endif Matrix4.CreateRotationZ(this.rotation) * // here we do not re-add the pivot, so translation is pivot based too Matrix4.CreateTranslation(this.position.X, this.position.Y, 0); #endif Matrix4 projectionMatrix = Window.Current.ProjectionMatrix; if (this.Camera != null) { m *= this.Camera.Matrix(); if (this.Camera.HasProjection) { projectionMatrix = this.Camera.ProjectionMatrix(); } } else if (Window.Current.CurrentCamera != null) { m *= Window.Current.CurrentCamera.Matrix(); if (Window.Current.CurrentCamera.HasProjection) { projectionMatrix = Window.Current.CurrentCamera.ProjectionMatrix(); } } Matrix4 mvp = m * projectionMatrix; #if __SHARPDX__ // transpose the matrix for DirectX mvp.Transpose(); #endif // pass the matrix to the shader this.shader.SetUniform("mvp", mvp); }