├── .gitignore ├── LICENSE ├── README.md ├── build.cake ├── build.ps1 ├── build.sh ├── doc └── sample.gif ├── nuget ├── Package.Sources.nuspec └── Package.nuspec ├── src ├── Transform.Samples.Portable │ ├── Entities │ │ └── Arm.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Sample.cs │ ├── Transform.Samples.Portable.csproj │ └── packages.config ├── Transform.Samples.iOS │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Entitlements.plist │ ├── Info.plist │ ├── LaunchScreen.storyboard │ ├── Main.cs │ ├── Transform.Samples.iOS.csproj │ └── packages.config ├── Transform.sln └── Transform │ ├── Acceleration2D.cs │ ├── Ease.cs │ ├── Extensions.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Transform.csproj │ ├── Transform2D.cs │ ├── Tweening │ ├── Delay.cs │ ├── ITween.cs │ ├── Parallel.cs │ ├── Repeat.cs │ ├── Sequence.cs │ └── Tween2D.cs │ ├── Velocity2D.cs │ └── packages.config └── tools └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | tools/** 279 | !tools/packages.config 280 | build/** 281 | 282 | # Telerik's JustMock configuration file 283 | *.jmconfig 284 | 285 | # BizTalk build output 286 | *.btp.cs 287 | *.btm.cs 288 | *.odx.cs 289 | *.xsd.cs 290 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Aloïs Deniel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Transform 2 | 3 | [![NuGet](https://img.shields.io/nuget/v/Transform.svg?label=NuGet)](https://www.nuget.org/packages/Transform/) [![Donate](https://img.shields.io/badge/donate-paypal-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ZJZKXPPGBKKAY&lc=US&item_name=GitHub&item_number=0000001¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted) 4 | 5 | ![sample](doc/sample.gif) 6 | 7 | Base Monogame objects for managing relative transforms. 8 | 9 | 10 | ## Quickstart 11 | 12 | ```csharp 13 | // Hierarchy 14 | this.arm.Transform.Position = new Vector2(this.GraphicsDevice.Viewport.Width / 2, this.GraphicsDevice.Viewport.Height / 2); 15 | 16 | this.arm2.Transform.Position = new Vector2(this.arm.Length, 0); 17 | this.arm2.Transform.Parent = this.arm.Transform; 18 | 19 | this.arm3.Transform.Position = new Vector2(this.arm2.Length, 0); 20 | this.arm3.Transform.Parent = this.arm2.Transform; 21 | 22 | // Animation 23 | this.tween = new Tween2D(TimeSpan.FromSeconds(5), this.arm.Transform, new Transform2D() 24 | { 25 | Rotation = 5, 26 | Position = this.arm.Transform.Position, 27 | Scale = new Vector2(2,2), 28 | }, Ease.ElasticInOut); 29 | 30 | this.velocity2 = new Velocity2D(arm2.Transform) 31 | { 32 | Rotation = 2f, 33 | Position = Vector2.UnitX * -2f, 34 | }; 35 | 36 | this.velocity3 = new Velocity2D(arm3.Transform) 37 | { 38 | Rotation = -3.5f, 39 | }; 40 | ``` 41 | 42 | ## Usage 43 | 44 | ### Transform2D 45 | 46 | Represents a 2 dimensions transformation. A transform could be attached to another transform by setting its `Parent` property. The relative `Position`, `Scale`, `Rotation` could be used to update each component of the transform (relative to the parent transform if set, else absolute position). The effective absolute output world components can be accessed through `AbsolutePosition`, `AbsoluteScale`, `AbsoluteRotation`. 47 | 48 | ### Velocity2D 49 | 50 | Represents a transform linear velocity following `Position`, `Scale`, `Rotation` independant components. 51 | 52 | ### Acceleration2D 53 | 54 | Represents a velocity linear acceleration following `Position`, `Scale`, `Rotation` independant components. 55 | 56 | ### ITween 57 | 58 | Represents an animation. 59 | 60 | #### Tween2D 61 | 62 | Tweens a value between two given transform, in a given amount of time, and with a given curve function. 63 | 64 | #### Sequence 65 | 66 | Chains several `ITween` to create complex animations. 67 | 68 | #### Parallel 69 | 70 | Runs a given set of `ITween` in parallel until all are finished. 71 | 72 | #### Delay 73 | 74 | Waits the given amount of time. 75 | 76 | ## Contributions 77 | 78 | Contributions are welcome! If you find a bug please report it and if you want a feature please report it. 79 | 80 | If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request. 81 | 82 | ## License 83 | 84 | MIT © [Aloïs Deniel](http://aloisdeniel.github.io) -------------------------------------------------------------------------------- /build.cake: -------------------------------------------------------------------------------- 1 | #addin "Cake.Git" 2 | 3 | var args = new 4 | { 5 | OutputDirectory = Argument("output", "build"), 6 | Target = Argument("target", "Default"), 7 | RepositoryPath = Argument("repositoryPath", "."), 8 | AddCommitToDescription = Argument("addCommitToDescription", true), 9 | Configuration = Argument("configuration", "Release"), 10 | Version = Argument("packageVersion"), 11 | Nuget = new 12 | { 13 | Source = Argument("nugetSource", "https://www.nuget.org/api/v2/package"), 14 | ApiKey = Argument("nugetApiKey", ""), 15 | }, 16 | }; 17 | 18 | var buildDirectory = MakeAbsolute(Directory(args.OutputDirectory)); 19 | 20 | Task("Tools.PrintArguments").Does(() => 21 | { 22 | Information($"Arguments:"); 23 | Information($" * Target: {args.Target}"); 24 | Information($" * AddCommitToDescription: {args.AddCommitToDescription}"); 25 | Information($" * OutputDirectory: {args.OutputDirectory}"); 26 | Information($" * Configuration: {args.Configuration}"); 27 | Information($" * Version: {args.Version}"); 28 | Information($" * RepositoryPath: {args.RepositoryPath}"); 29 | Information($" * NugetApiKey: <*>"); 30 | }); 31 | 32 | Task("Tools.Clean").Does(() => 33 | { 34 | CleanDirectories(args.OutputDirectory); 35 | CleanDirectories("./**/bin"); 36 | CleanDirectories("./**/obj"); 37 | }); 38 | 39 | Task("Build.Solutions") 40 | .IsDependentOn("Tools.Clean") 41 | .Does(() => 42 | { 43 | var slnFiles = GetFiles("**/*.sln"); 44 | foreach(var sln in slnFiles) 45 | { 46 | NuGetRestore(sln); 47 | MSBuild(sln, c => 48 | { 49 | c.Configuration = args.Configuration; 50 | c.MSBuildPlatform = Cake.Common.Tools.MSBuild.MSBuildPlatform.x86; 51 | }); 52 | } 53 | }); 54 | 55 | Task("Nuget.Pack.Sources") 56 | .IsDependentOn("Build.Solutions") 57 | .Does(() => 58 | { 59 | var sourceFiles = GetFiles("src/Transform/**/*.cs"); 60 | 61 | var content = new System.Text.StringBuilder(); 62 | 63 | content.AppendLine("// INCLUDED FILE, DO NOT MODIFY IT"); 64 | content.AppendLine("// (from nuget package 'Transform.Sources')\n\n"); 65 | 66 | foreach(var source in sourceFiles) 67 | { 68 | var path = MakeAbsolute(source).FullPath; 69 | if(System.IO.Path.GetFileName(path) != "AssemblyInfo.cs") 70 | { 71 | Information($"Appending {source}"); 72 | var sourceContent = System.IO.File.ReadAllText(path); 73 | content.AppendLine(sourceContent); 74 | } 75 | } 76 | 77 | var output = (Directory(buildDirectory.FullPath) + File("Transform.cs")).Path; 78 | System.IO.File.WriteAllText(output.ToString(), content.ToString()); 79 | }); 80 | 81 | Task("Nuget.Pack") 82 | .IsDependentOn("Build.Solutions") 83 | .IsDependentOn("Nuget.Pack.Sources") 84 | .Does(() => 85 | { 86 | if(!DirectoryExists(buildDirectory.FullPath)) 87 | { 88 | CreateDirectory(buildDirectory.FullPath); 89 | } 90 | 91 | var nuspecFiles = GetFiles("nuget/**/*.nuspec"); 92 | foreach(var nuspec in nuspecFiles) 93 | { 94 | var wd = MakeAbsolute(nuspec).GetDirectory(); 95 | var settings = new NuGetPackSettings 96 | { 97 | Version = args.Version, 98 | OutputDirectory = buildDirectory.FullPath, 99 | BasePath = wd, 100 | }; 101 | 102 | if(args.AddCommitToDescription) 103 | { 104 | // Extract description from nuspec and concat current commit hash and datetime 105 | var description = XmlPeek(nuspec, $"/package/metadata/description"); 106 | var lastCommit = GitLogTip(args.RepositoryPath); 107 | description = $"{description}\n\nCommit : {lastCommit.Sha}, {lastCommit.Author?.When}"; 108 | Information($"Updated package description : {description}"); 109 | settings.Description = description; 110 | } 111 | 112 | NuGetPack(nuspec, settings); 113 | } 114 | }); 115 | 116 | Task("Nuget.Push") 117 | .IsDependentOn("Tools.PrintArguments") 118 | .IsDependentOn("Nuget.Pack") 119 | .Does(() => 120 | { 121 | if(string.IsNullOrEmpty(args.Nuget.ApiKey)) 122 | { 123 | throw new ArgumentException("Missing 'nugetApiKey' arguments"); 124 | } 125 | 126 | var packages = GetFiles($"**/*.{args.Version}.nupkg"); 127 | NuGetPush(packages, new NuGetPushSettings 128 | { 129 | Source = args.Nuget.Source, 130 | ApiKey = args.Nuget.ApiKey, 131 | }); 132 | }); 133 | 134 | Task("Default") 135 | .IsDependentOn("Tools.PrintArguments") 136 | .IsDependentOn("Nuget.Pack"); 137 | 138 | RunTarget(args.Target); -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # This is the Cake bootstrapper script for PowerShell. 3 | # This file was downloaded from https://github.com/cake-build/resources 4 | # Feel free to change this file to fit your needs. 5 | ########################################################################## 6 | 7 | <# 8 | 9 | .SYNOPSIS 10 | This is a Powershell script to bootstrap a Cake build. 11 | 12 | .DESCRIPTION 13 | This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) 14 | and execute your Cake build script with the parameters you provide. 15 | 16 | .PARAMETER Script 17 | The build script to execute. 18 | .PARAMETER Target 19 | The build script target to run. 20 | .PARAMETER Configuration 21 | The build configuration to use. 22 | .PARAMETER Verbosity 23 | Specifies the amount of information to be displayed. 24 | .PARAMETER ShowDescription 25 | Shows description about tasks. 26 | .PARAMETER DryRun 27 | Performs a dry run. 28 | .PARAMETER Experimental 29 | Uses the nightly builds of the Roslyn script engine. 30 | .PARAMETER Mono 31 | Uses the Mono Compiler rather than the Roslyn script engine. 32 | .PARAMETER SkipToolPackageRestore 33 | Skips restoring of packages. 34 | .PARAMETER ScriptArgs 35 | Remaining arguments are added here. 36 | 37 | .LINK 38 | https://cakebuild.net 39 | 40 | #> 41 | 42 | [CmdletBinding()] 43 | Param( 44 | [string]$Script = "build.cake", 45 | [string]$Target, 46 | [string]$Configuration, 47 | [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] 48 | [string]$Verbosity, 49 | [switch]$ShowDescription, 50 | [Alias("WhatIf", "Noop")] 51 | [switch]$DryRun, 52 | [switch]$Experimental, 53 | [switch]$Mono, 54 | [switch]$SkipToolPackageRestore, 55 | [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] 56 | [string[]]$ScriptArgs 57 | ) 58 | 59 | [Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null 60 | function MD5HashFile([string] $filePath) 61 | { 62 | if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) 63 | { 64 | return $null 65 | } 66 | 67 | [System.IO.Stream] $file = $null; 68 | [System.Security.Cryptography.MD5] $md5 = $null; 69 | try 70 | { 71 | $md5 = [System.Security.Cryptography.MD5]::Create() 72 | $file = [System.IO.File]::OpenRead($filePath) 73 | return [System.BitConverter]::ToString($md5.ComputeHash($file)) 74 | } 75 | finally 76 | { 77 | if ($file -ne $null) 78 | { 79 | $file.Dispose() 80 | } 81 | } 82 | } 83 | 84 | function GetProxyEnabledWebClient 85 | { 86 | $wc = New-Object System.Net.WebClient 87 | $proxy = [System.Net.WebRequest]::GetSystemWebProxy() 88 | $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials 89 | $wc.Proxy = $proxy 90 | return $wc 91 | } 92 | 93 | Write-Host "Preparing to run build script..." 94 | 95 | if(!$PSScriptRoot){ 96 | $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent 97 | } 98 | 99 | $TOOLS_DIR = Join-Path $PSScriptRoot "tools" 100 | $ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" 101 | $MODULES_DIR = Join-Path $TOOLS_DIR "Modules" 102 | $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" 103 | $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" 104 | $NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" 105 | $PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" 106 | $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" 107 | $ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" 108 | $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" 109 | 110 | # Make sure tools folder exists 111 | if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { 112 | Write-Verbose -Message "Creating tools directory..." 113 | New-Item -Path $TOOLS_DIR -Type directory | out-null 114 | } 115 | 116 | # Make sure that packages.config exist. 117 | if (!(Test-Path $PACKAGES_CONFIG)) { 118 | Write-Verbose -Message "Downloading packages.config..." 119 | try { 120 | $wc = GetProxyEnabledWebClient 121 | $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { 122 | Throw "Could not download packages.config." 123 | } 124 | } 125 | 126 | # Try find NuGet.exe in path if not exists 127 | if (!(Test-Path $NUGET_EXE)) { 128 | Write-Verbose -Message "Trying to find nuget.exe in PATH..." 129 | $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } 130 | $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 131 | if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { 132 | Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." 133 | $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName 134 | } 135 | } 136 | 137 | # Try download NuGet.exe if not exists 138 | if (!(Test-Path $NUGET_EXE)) { 139 | Write-Verbose -Message "Downloading NuGet.exe..." 140 | try { 141 | $wc = GetProxyEnabledWebClient 142 | $wc.DownloadFile($NUGET_URL, $NUGET_EXE) 143 | } catch { 144 | Throw "Could not download NuGet.exe." 145 | } 146 | } 147 | 148 | # Save nuget.exe path to environment to be available to child processed 149 | $ENV:NUGET_EXE = $NUGET_EXE 150 | 151 | # Restore tools from NuGet? 152 | if(-Not $SkipToolPackageRestore.IsPresent) { 153 | Push-Location 154 | Set-Location $TOOLS_DIR 155 | 156 | # Check for changes in packages.config and remove installed tools if true. 157 | [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) 158 | if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or 159 | ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { 160 | Write-Verbose -Message "Missing or changed package.config hash..." 161 | Remove-Item * -Recurse -Exclude packages.config,nuget.exe 162 | } 163 | 164 | Write-Verbose -Message "Restoring tools from NuGet..." 165 | $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" 166 | 167 | if ($LASTEXITCODE -ne 0) { 168 | Throw "An error occured while restoring NuGet tools." 169 | } 170 | else 171 | { 172 | $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" 173 | } 174 | Write-Verbose -Message ($NuGetOutput | out-string) 175 | 176 | Pop-Location 177 | } 178 | 179 | # Restore addins from NuGet 180 | if (Test-Path $ADDINS_PACKAGES_CONFIG) { 181 | Push-Location 182 | Set-Location $ADDINS_DIR 183 | 184 | Write-Verbose -Message "Restoring addins from NuGet..." 185 | $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" 186 | 187 | if ($LASTEXITCODE -ne 0) { 188 | Throw "An error occured while restoring NuGet addins." 189 | } 190 | 191 | Write-Verbose -Message ($NuGetOutput | out-string) 192 | 193 | Pop-Location 194 | } 195 | 196 | # Restore modules from NuGet 197 | if (Test-Path $MODULES_PACKAGES_CONFIG) { 198 | Push-Location 199 | Set-Location $MODULES_DIR 200 | 201 | Write-Verbose -Message "Restoring modules from NuGet..." 202 | $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" 203 | 204 | if ($LASTEXITCODE -ne 0) { 205 | Throw "An error occured while restoring NuGet modules." 206 | } 207 | 208 | Write-Verbose -Message ($NuGetOutput | out-string) 209 | 210 | Pop-Location 211 | } 212 | 213 | # Make sure that Cake has been installed. 214 | if (!(Test-Path $CAKE_EXE)) { 215 | Throw "Could not find Cake.exe at $CAKE_EXE" 216 | } 217 | 218 | 219 | 220 | # Build Cake arguments 221 | $cakeArguments = @("$Script"); 222 | if ($Target) { $cakeArguments += "-target=$Target" } 223 | if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } 224 | if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } 225 | if ($ShowDescription) { $cakeArguments += "-showdescription" } 226 | if ($DryRun) { $cakeArguments += "-dryrun" } 227 | if ($Experimental) { $cakeArguments += "-experimental" } 228 | if ($Mono) { $cakeArguments += "-mono" } 229 | $cakeArguments += $ScriptArgs 230 | 231 | # Start Cake 232 | Write-Host "Running build script..." 233 | &$CAKE_EXE $cakeArguments 234 | exit $LASTEXITCODE 235 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ########################################################################## 4 | # This is the Cake bootstrapper script for Linux and OS X. 5 | # This file was downloaded from https://github.com/cake-build/resources 6 | # Feel free to change this file to fit your needs. 7 | ########################################################################## 8 | 9 | # Define directories. 10 | SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 11 | TOOLS_DIR=$SCRIPT_DIR/tools 12 | ADDINS_DIR=$TOOLS_DIR/Addins 13 | MODULES_DIR=$TOOLS_DIR/Modules 14 | NUGET_EXE=$TOOLS_DIR/nuget.exe 15 | CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe 16 | PACKAGES_CONFIG=$TOOLS_DIR/packages.config 17 | PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum 18 | ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config 19 | MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config 20 | 21 | # Define md5sum or md5 depending on Linux/OSX 22 | MD5_EXE= 23 | if [[ "$(uname -s)" == "Darwin" ]]; then 24 | MD5_EXE="md5 -r" 25 | else 26 | MD5_EXE="md5sum" 27 | fi 28 | 29 | # Define default arguments. 30 | SCRIPT="build.cake" 31 | CAKE_ARGUMENTS=() 32 | 33 | # Parse arguments. 34 | for i in "$@"; do 35 | case $1 in 36 | -s|--script) SCRIPT="$2"; shift ;; 37 | --) shift; CAKE_ARGUMENTS+=("$@"); break ;; 38 | *) CAKE_ARGUMENTS+=("$1") ;; 39 | esac 40 | shift 41 | done 42 | 43 | # Make sure the tools folder exist. 44 | if [ ! -d "$TOOLS_DIR" ]; then 45 | mkdir "$TOOLS_DIR" 46 | fi 47 | 48 | # Make sure that packages.config exist. 49 | if [ ! -f "$TOOLS_DIR/packages.config" ]; then 50 | echo "Downloading packages.config..." 51 | curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages 52 | if [ $? -ne 0 ]; then 53 | echo "An error occured while downloading packages.config." 54 | exit 1 55 | fi 56 | fi 57 | 58 | # Download NuGet if it does not exist. 59 | if [ ! -f "$NUGET_EXE" ]; then 60 | echo "Downloading NuGet..." 61 | curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe 62 | if [ $? -ne 0 ]; then 63 | echo "An error occured while downloading nuget.exe." 64 | exit 1 65 | fi 66 | fi 67 | 68 | # Restore tools from NuGet. 69 | pushd "$TOOLS_DIR" >/dev/null 70 | if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then 71 | find . -type d ! -name . | xargs rm -rf 72 | fi 73 | 74 | mono "$NUGET_EXE" install -ExcludeVersion 75 | if [ $? -ne 0 ]; then 76 | echo "Could not restore NuGet tools." 77 | exit 1 78 | fi 79 | 80 | $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5" 81 | 82 | popd >/dev/null 83 | 84 | # Restore addins from NuGet. 85 | if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then 86 | pushd "$ADDINS_DIR" >/dev/null 87 | 88 | mono "$NUGET_EXE" install -ExcludeVersion 89 | if [ $? -ne 0 ]; then 90 | echo "Could not restore NuGet addins." 91 | exit 1 92 | fi 93 | 94 | popd >/dev/null 95 | fi 96 | 97 | # Restore modules from NuGet. 98 | if [ -f "$MODULES_PACKAGES_CONFIG" ]; then 99 | pushd "$MODULES_DIR" >/dev/null 100 | 101 | mono "$NUGET_EXE" install -ExcludeVersion 102 | if [ $? -ne 0 ]; then 103 | echo "Could not restore NuGet modules." 104 | exit 1 105 | fi 106 | 107 | popd >/dev/null 108 | fi 109 | 110 | # Make sure that Cake has been installed. 111 | if [ ! -f "$CAKE_EXE" ]; then 112 | echo "Could not find Cake.exe at '$CAKE_EXE'." 113 | exit 1 114 | fi 115 | 116 | # Start Cake 117 | exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}" 118 | -------------------------------------------------------------------------------- /doc/sample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/Transform/9fba4493abcb8b6d0f7d3392f7641ab914c91c48/doc/sample.gif -------------------------------------------------------------------------------- /nuget/Package.Sources.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Transform.Sources 5 | $version$ 6 | Transform for Monogame (Sources) 7 | Aloïs DENIEL 8 | Aloïs DENIEL 9 | https://github.com/aloisdeniel/Transform/blob/master/LICENSE 10 | https://github.com/aloisdeniel/Transform/ 11 | https://raw.githubusercontent.com/aloisdeniel/Transform/master/doc/logo.png 12 | false 13 | Base Monogame objects for managing relative transforms. 14 | Base Monogame objects for managing relative transforms. 15 | mongogame, transform, matrix 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /nuget/Package.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Transform 5 | $version$ 6 | Transform for Monogame 7 | Aloïs DENIEL 8 | Aloïs DENIEL 9 | https://github.com/aloisdeniel/Transform/blob/master/LICENSE 10 | https://github.com/aloisdeniel/Transform/ 11 | https://raw.githubusercontent.com/aloisdeniel/Transform/master/doc/logo.png 12 | false 13 | Base Monogame objects for managing relative transforms. 14 | Base Monogame objects for managing relative transforms. 15 | mongogame, transform, matrix 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/Transform.Samples.Portable/Entities/Arm.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | namespace Transform.Samples.Portable 6 | { 7 | public class Arm 8 | { 9 | public Arm(float length) 10 | { 11 | this.Length = length; 12 | } 13 | 14 | public float Length { get; } 15 | 16 | private List children = new List(); 17 | 18 | public Color Color { get; set; } = Color.White; 19 | 20 | public Transform2D Transform { get; } = new Transform2D(); 21 | 22 | public Arm CreateArm(float length, Color color) 23 | { 24 | var arm = new Arm(length); 25 | arm.Color = color; 26 | arm.Transform.Position = new Vector2(this.Length, 0); 27 | arm.Transform.Parent = this.Transform; 28 | this.children.Add(arm); 29 | return arm; 30 | } 31 | 32 | private static Texture2D pixel; 33 | 34 | public static void LoadContent(GraphicsDevice device) 35 | { 36 | if(pixel == null) 37 | { 38 | pixel = new Texture2D(device, 1, 1); 39 | pixel.SetData(new[] { Color.White }); 40 | } 41 | } 42 | 43 | public void Draw(SpriteBatch sb) 44 | { 45 | var dest = new Rectangle((int)this.Transform.AbsolutePosition.X, (int)this.Transform.AbsolutePosition.Y - 5, (int)this.Length, 10); 46 | sb.Draw(texture: pixel, position: new Vector2(dest.X, dest.Y), sourceRectangle: pixel.Bounds, rotation: this.Transform.AbsoluteRotation, scale: this.Transform.AbsoluteScale * new Vector2(dest.Width, dest.Height), color: this.Color); 47 | 48 | foreach (var child in this.children) 49 | { 50 | child.Draw(sb); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Transform.Samples.Portable/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("Transform.Samples.Portable")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("${AuthorCopyright}")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | -------------------------------------------------------------------------------- /src/Transform.Samples.Portable/Sample.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using System; 4 | 5 | namespace Transform.Samples.Portable 6 | { 7 | public class Sample : Game 8 | { 9 | GraphicsDeviceManager graphics; 10 | SpriteBatch spriteBatch; 11 | 12 | public Sample() 13 | { 14 | graphics = new GraphicsDeviceManager(this); 15 | Content.RootDirectory = "Content"; 16 | 17 | #if !__MOBILE__ 18 | 19 | graphics.PreferredBackBufferWidth = 1400; 20 | graphics.PreferredBackBufferHeight = 800; 21 | #endif 22 | } 23 | 24 | protected override void LoadContent() 25 | { 26 | // Create a new SpriteBatch, which can be used to draw textures. 27 | spriteBatch = new SpriteBatch(GraphicsDevice); 28 | Arm.LoadContent(this.GraphicsDevice); 29 | 30 | } 31 | 32 | private Arm arm; 33 | 34 | private Velocity2D velocity2, velocity3; 35 | 36 | private ITween tween; 37 | 38 | protected override void Initialize() 39 | { 40 | base.Initialize(); 41 | 42 | this.arm = new Arm(100); 43 | var arm2 = this.arm.CreateArm(50, Color.Red); 44 | var arm3 = arm2.CreateArm(30, Color.Blue); 45 | 46 | this.arm.Transform.Position = new Vector2(this.GraphicsDevice.Viewport.Width / 2, this.GraphicsDevice.Viewport.Height / 2); 47 | 48 | var t1 = new Tween2D(TimeSpan.FromSeconds(5), this.arm.Transform, new Transform2D() 49 | { 50 | Rotation = 5, 51 | Position = this.arm.Transform.Position, 52 | Scale = new Vector2(2, 2), 53 | }, Ease.ElasticInOut); 54 | 55 | this.tween = new Repeat(new Sequence(new Delay(TimeSpan.FromSeconds(3)), t1)); 56 | 57 | this.velocity2 = new Velocity2D(arm2.Transform) 58 | { 59 | Rotation = 2f, 60 | Position = Vector2.UnitX * -2f, 61 | }; 62 | 63 | this.velocity3 = new Velocity2D(arm3.Transform) 64 | { 65 | Rotation = -3.5f, 66 | }; 67 | } 68 | 69 | protected override void Update(GameTime gameTime) 70 | { 71 | this.tween.Update(gameTime); 72 | this.velocity2.Update(gameTime); 73 | this.velocity3.Update(gameTime); 74 | 75 | base.Update(gameTime); 76 | } 77 | 78 | protected override void Draw(GameTime gameTime) 79 | { 80 | graphics.GraphicsDevice.Clear(Color.CornflowerBlue); 81 | 82 | this.spriteBatch.Begin(); 83 | this.arm.Draw(this.spriteBatch); 84 | this.spriteBatch.End(); 85 | 86 | base.Draw(gameTime); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Transform.Samples.Portable/Transform.Samples.Portable.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287} 7 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | true 9 | Library 10 | Transform.Samples.Portable 11 | Transform.Samples.Portable 12 | v4.5 13 | Profile111 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug 20 | DEBUG; 21 | prompt 22 | 4 23 | 24 | 25 | true 26 | bin\Release 27 | prompt 28 | 4 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {82743BE1-3404-483C-A670-FEB88FFB6517} 38 | Transform 39 | 40 | 41 | 42 | 43 | ..\packages\MonoGame.Framework.Portable.3.6.0.1625\lib\portable-net45+win8+wpa81\MonoGame.Framework.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/Transform.Samples.Portable/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | }, 93 | { 94 | "size" : "24x24", 95 | "idiom" : "watch", 96 | "scale" : "2x", 97 | "role" : "notificationCenter", 98 | "subtype" : "38mm" 99 | }, 100 | { 101 | "size" : "27.5x27.5", 102 | "idiom" : "watch", 103 | "scale" : "2x", 104 | "role" : "notificationCenter", 105 | "subtype" : "42mm" 106 | }, 107 | { 108 | "size" : "29x29", 109 | "idiom" : "watch", 110 | "role" : "companionSettings", 111 | "scale" : "2x" 112 | }, 113 | { 114 | "size" : "29x29", 115 | "idiom" : "watch", 116 | "role" : "companionSettings", 117 | "scale" : "3x" 118 | }, 119 | { 120 | "size" : "40x40", 121 | "idiom" : "watch", 122 | "scale" : "2x", 123 | "role" : "appLauncher", 124 | "subtype" : "38mm" 125 | }, 126 | { 127 | "size" : "44x44", 128 | "idiom" : "watch", 129 | "scale" : "2x", 130 | "role" : "longLook", 131 | "subtype" : "42mm" 132 | }, 133 | { 134 | "size" : "86x86", 135 | "idiom" : "watch", 136 | "scale" : "2x", 137 | "role" : "quickLook", 138 | "subtype" : "38mm" 139 | }, 140 | { 141 | "size" : "98x98", 142 | "idiom" : "watch", 143 | "scale" : "2x", 144 | "role" : "quickLook", 145 | "subtype" : "42mm" 146 | }, 147 | { 148 | "idiom" : "mac", 149 | "size" : "16x16", 150 | "scale" : "1x" 151 | }, 152 | { 153 | "idiom" : "mac", 154 | "size" : "16x16", 155 | "scale" : "2x" 156 | }, 157 | { 158 | "idiom" : "mac", 159 | "size" : "32x32", 160 | "scale" : "1x" 161 | }, 162 | { 163 | "idiom" : "mac", 164 | "size" : "32x32", 165 | "scale" : "2x" 166 | }, 167 | { 168 | "idiom" : "mac", 169 | "size" : "128x128", 170 | "scale" : "1x" 171 | }, 172 | { 173 | "idiom" : "mac", 174 | "size" : "128x128", 175 | "scale" : "2x" 176 | }, 177 | { 178 | "idiom" : "mac", 179 | "size" : "256x256", 180 | "scale" : "1x" 181 | }, 182 | { 183 | "idiom" : "mac", 184 | "size" : "256x256", 185 | "scale" : "2x" 186 | }, 187 | { 188 | "idiom" : "mac", 189 | "size" : "512x512", 190 | "scale" : "1x" 191 | }, 192 | { 193 | "idiom" : "mac", 194 | "size" : "512x512", 195 | "scale" : "2x" 196 | } 197 | ], 198 | "info" : { 199 | "version" : 1, 200 | "author" : "xcode" 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | Transform.Samples.iOS 7 | CFBundleIdentifier 8 | com.Transform-Samples-iOS 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 11.0 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UILaunchStoryboardName 23 | LaunchScreen 24 | UIRequiredDeviceCapabilities 25 | 26 | armv7 27 | 28 | UISupportedInterfaceOrientations 29 | 30 | UIInterfaceOrientationPortrait 31 | UIInterfaceOrientationPortraitUpsideDown 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | XSAppIconAssets 36 | Assets.xcassets/AppIcon.appiconset 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | #region Using Statements 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | #if MONOMAC 6 | using MonoMac.AppKit; 7 | using MonoMac.Foundation; 8 | #elif __IOS__ || __TVOS__ 9 | using Foundation; 10 | using UIKit; 11 | using Transform.Samples.Portable; 12 | #endif 13 | #endregion 14 | 15 | namespace Meetup.Demo.Ecs.iOS 16 | { 17 | #if __IOS__ || __TVOS__ 18 | [Register("AppDelegate")] 19 | class Program : UIApplicationDelegate 20 | #else 21 | static class Program 22 | #endif 23 | { 24 | private static Sample game; 25 | 26 | internal static void RunGame() 27 | { 28 | game = new Sample(); 29 | game.Run(); 30 | #if !__IOS__ && !__TVOS__ 31 | game.Dispose(); 32 | #endif 33 | } 34 | 35 | /// 36 | /// The main entry point for the application. 37 | /// 38 | #if !MONOMAC && !__IOS__ && !__TVOS__ 39 | [STAThread] 40 | #endif 41 | static void Main(string[] args) 42 | { 43 | #if MONOMAC 44 | NSApplication.Init (); 45 | 46 | using (var p = new NSAutoreleasePool ()) { 47 | NSApplication.SharedApplication.Delegate = new AppDelegate(); 48 | NSApplication.Main(args); 49 | } 50 | #elif __IOS__ || __TVOS__ 51 | UIApplication.Main(args, null, "AppDelegate"); 52 | #else 53 | RunGame(); 54 | #endif 55 | } 56 | 57 | #if __IOS__ || __TVOS__ 58 | public override void FinishedLaunching(UIApplication app) 59 | { 60 | RunGame(); 61 | } 62 | #endif 63 | } 64 | 65 | #if MONOMAC 66 | class AppDelegate : NSApplicationDelegate 67 | { 68 | public override void FinishedLaunching (MonoMac.Foundation.NSObject notification) 69 | { 70 | AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs a) => { 71 | if (a.Name.StartsWith("MonoMac")) { 72 | return typeof(MonoMac.AppKit.AppKitFramework).Assembly; 73 | } 74 | return null; 75 | }; 76 | Program.RunGame(); 77 | } 78 | 79 | public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender) 80 | { 81 | return true; 82 | } 83 | } 84 | #endif 85 | } 86 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/Transform.Samples.iOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2} 7 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Exe 9 | Transform.Samples.iOS 10 | Transform.Samples.iOS 11 | Resources 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\iPhoneSimulator\Debug 18 | DEBUG;ENABLE_TEST_CLOUD; 19 | prompt 20 | 4 21 | iPhone Developer 22 | true 23 | true 24 | true 25 | 61588 26 | None 27 | x86_64 28 | HttpClientHandler 29 | false 30 | 31 | 32 | pdbonly 33 | true 34 | bin\iPhone\Release 35 | 36 | prompt 37 | 4 38 | iPhone Developer 39 | true 40 | Entitlements.plist 41 | SdkOnly 42 | ARM64 43 | HttpClientHandler 44 | 45 | 46 | pdbonly 47 | true 48 | bin\iPhoneSimulator\Release 49 | 50 | prompt 51 | 4 52 | iPhone Developer 53 | true 54 | None 55 | x86_64 56 | HttpClientHandler 57 | 58 | 59 | true 60 | full 61 | false 62 | bin\iPhone\Debug 63 | DEBUG;ENABLE_TEST_CLOUD; 64 | prompt 65 | 4 66 | iPhone Developer 67 | true 68 | true 69 | true 70 | true 71 | true 72 | Entitlements.plist 73 | 18135 74 | SdkOnly 75 | ARM64 76 | HttpClientHandler 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | ..\packages\MonoGame.Framework.iOS.3.6.0.1625\lib\XamariniOS\MonoGame.Framework.dll 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | {82743BE1-3404-483C-A670-FEB88FFB6517} 108 | Transform 109 | 110 | 111 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287} 112 | Transform.Samples.Portable 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/Transform.Samples.iOS/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/Transform.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transform", "Transform\Transform.csproj", "{82743BE1-3404-483C-A670-FEB88FFB6517}" 5 | EndProject 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{772F7193-85A8-4672-8A0C-6F9E99604B4D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transform.Samples.Portable", "Transform.Samples.Portable\Transform.Samples.Portable.csproj", "{AA29AFF6-AF21-49D3-BC05-9F23E24B7287}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transform.Samples.iOS", "Transform.Samples.iOS\Transform.Samples.iOS.csproj", "{2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 17 | Release|iPhone = Release|iPhone 18 | Release|iPhoneSimulator = Release|iPhoneSimulator 19 | Debug|iPhone = Debug|iPhone 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 27 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 28 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Release|iPhone.ActiveCfg = Release|Any CPU 29 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Release|iPhone.Build.0 = Release|Any CPU 30 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 31 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 32 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Debug|iPhone.ActiveCfg = Debug|Any CPU 33 | {82743BE1-3404-483C-A670-FEB88FFB6517}.Debug|iPhone.Build.0 = Debug|Any CPU 34 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 38 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 39 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Release|iPhone.ActiveCfg = Release|Any CPU 40 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 41 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Debug|iPhone.ActiveCfg = Debug|Any CPU 42 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287}.Debug|iPhone.Build.0 = Debug|Any CPU 43 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator 44 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator 45 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Release|Any CPU.ActiveCfg = Release|iPhone 46 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 47 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 48 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Release|iPhone.ActiveCfg = Release|iPhone 49 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 50 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Debug|iPhone.ActiveCfg = Debug|iPhone 51 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2}.Debug|iPhone.Build.0 = Debug|iPhone 52 | EndGlobalSection 53 | GlobalSection(NestedProjects) = preSolution 54 | {AA29AFF6-AF21-49D3-BC05-9F23E24B7287} = {772F7193-85A8-4672-8A0C-6F9E99604B4D} 55 | {2ECA00F3-F388-41DD-800F-04FE9A0A1CA2} = {772F7193-85A8-4672-8A0C-6F9E99604B4D} 56 | EndGlobalSection 57 | EndGlobal 58 | -------------------------------------------------------------------------------- /src/Transform/Acceleration2D.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class Acceleration2D 7 | { 8 | public Acceleration2D(Velocity2D velocity) 9 | { 10 | this.Velocity = velocity ?? throw new ArgumentException(nameof(velocity)); 11 | } 12 | 13 | public Transform2D Transform => this.Velocity.Transform; 14 | 15 | public Velocity2D Velocity { get; } 16 | 17 | public Vector2 Position { get; set; } 18 | 19 | public Vector2 Scale { get; set; } 20 | 21 | public float Rotation { get; set; } 22 | 23 | public void Update(GameTime time) 24 | { 25 | var delta = (float)time.ElapsedGameTime.TotalSeconds; 26 | this.Velocity.Position += this.Position * delta; 27 | this.Velocity.Scale += this.Scale * delta; 28 | this.Velocity.Rotation += this.Rotation * delta; 29 | 30 | this.Velocity.Update(time); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Transform/Ease.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | 5 | public enum Ease 6 | { 7 | InOut, 8 | In, 9 | Out, 10 | ElasticIn, 11 | ElasticOut, 12 | ElasticInOut, 13 | } 14 | 15 | public static class EaseFunctions 16 | { 17 | private static readonly float PI_2 = (float)(Math.PI / 2); 18 | 19 | public static float In(float t) => t * t; 20 | 21 | public static float Out(float t) => t * (2 - t); 22 | 23 | public static float InOut(float t) => t < 0.5f ? 2 * t * t : -1 + (4 - 2 * t) * t; 24 | 25 | public static float ElasticIn(float t) => (float)(Math.Sin(13 * PI_2 * t) * Math.Pow(2, 10 * (t - 1))); 26 | 27 | public static float ElasticOut(float t) => (float)(Math.Sin(-13 * PI_2 * (t + 1)) * Math.Pow(2, -10 * t) + 1); 28 | 29 | public static float ElasticInOut(float t) 30 | { 31 | if (t < 0.5f) 32 | { 33 | return (float)(0.5 * Math.Sin(13 * PI_2 * (2 * t)) * Math.Pow(2, 10 * ((2 * t) - 1))); 34 | } 35 | return (float)(0.5 * (Math.Sin(-13 * PI_2 * ((2 * t - 1) + 1)) * Math.Pow(2, -10 * (2 * t - 1)) + 2)); 36 | } 37 | 38 | public static Func Get(Ease ease) 39 | { 40 | switch (ease) 41 | { 42 | case Ease.In: return In; 43 | case Ease.Out: return Out; 44 | case Ease.InOut: return InOut; 45 | case Ease.ElasticIn: return ElasticIn; 46 | case Ease.ElasticOut: return ElasticOut; 47 | case Ease.ElasticInOut: return ElasticInOut; 48 | } 49 | 50 | throw new NotSupportedException(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Transform/Extensions.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using Microsoft.Xna.Framework; 4 | 5 | public static class Extensions 6 | { 7 | public static Transform2D ToTransform(this Vector2 position) 8 | { 9 | return new Transform2D() 10 | { 11 | Position = position, 12 | }; 13 | } 14 | 15 | public static Velocity2D WithVelocity(this Transform2D transform) 16 | { 17 | return new Velocity2D(transform); 18 | } 19 | 20 | public static Acceleration2D WithAcceleration(this Velocity2D velocity) 21 | { 22 | return new Acceleration2D(velocity); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Transform/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("Transform")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("${AuthorCopyright}")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | -------------------------------------------------------------------------------- /src/Transform/Transform.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {82743BE1-3404-483C-A670-FEB88FFB6517} 7 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | true 9 | Library 10 | Transform 11 | Transform 12 | v4.5 13 | Profile111 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug 20 | DEBUG; 21 | prompt 22 | 4 23 | 24 | 25 | true 26 | bin\Release 27 | prompt 28 | 4 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | ..\packages\MonoGame.Framework.Portable.3.6.0.1625\lib\portable-net45+win8+wpa81\MonoGame.Framework.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/Transform/Transform2D.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using Microsoft.Xna.Framework; 4 | using System.Collections.Generic; 5 | 6 | public class Transform2D 7 | { 8 | #region Constructors 9 | 10 | public Transform2D() 11 | { 12 | this.Position = Vector2.Zero; 13 | this.Rotation = 0; 14 | this.Scale = Vector2.One; 15 | } 16 | 17 | #endregion 18 | 19 | #region Fields 20 | 21 | private Transform2D parent; 22 | 23 | private List children = new List(); 24 | 25 | private Matrix absolute, invertAbsolute, local; 26 | 27 | private float localRotation, absoluteRotation; 28 | 29 | private Vector2 localScale, absoluteScale, localPosition, absolutePosition; 30 | 31 | private bool needsAbsoluteUpdate = true, needsLocalUpdate = true; 32 | 33 | #endregion 34 | 35 | #region Properties 36 | 37 | /// 38 | /// Gets or sets the parent transform. 39 | /// 40 | /// The parent. 41 | public Transform2D Parent 42 | { 43 | get => this.parent; 44 | set 45 | { 46 | if(this.parent != value) 47 | { 48 | if (this.parent != null) 49 | this.parent.children.Remove(this); 50 | 51 | this.parent = value; 52 | 53 | if (this.parent != null) 54 | this.parent.children.Add(this); 55 | 56 | this.SetNeedsAbsoluteUpdate(); 57 | } 58 | } 59 | } 60 | 61 | /// 62 | /// Gets all the children transform. 63 | /// 64 | /// The children. 65 | public IEnumerable Children => this.children; 66 | 67 | /// 68 | /// Gets the absolute rotation. 69 | /// 70 | /// The absolute rotation. 71 | public float AbsoluteRotation => this.UpdateAbsoluteAndGet(ref this.absoluteRotation); 72 | 73 | /// 74 | /// Gets the absolute scale. 75 | /// 76 | /// The absolute scale. 77 | public Vector2 AbsoluteScale => this.UpdateAbsoluteAndGet(ref this.absoluteScale); 78 | 79 | /// 80 | /// Gets the absolute position. 81 | /// 82 | /// The absolute position. 83 | public Vector2 AbsolutePosition => this.UpdateAbsoluteAndGet(ref this.absolutePosition); 84 | 85 | /// 86 | /// Gets or sets the rotation (relative to the parent, absolute if no parent). 87 | /// 88 | /// The rotation. 89 | public float Rotation 90 | { 91 | get => this.localRotation; 92 | set 93 | { 94 | if (this.localRotation != value) 95 | { 96 | this.localRotation = value; 97 | this.SetNeedsLocalUpdate(); 98 | } 99 | } 100 | } 101 | 102 | /// 103 | /// Gets or sets the position (relative to the parent, absolute if no parent). 104 | /// 105 | /// The position. 106 | public Vector2 Position 107 | { 108 | get => this.localPosition; 109 | set 110 | { 111 | if(this.localPosition != value) 112 | { 113 | this.localPosition = value; 114 | this.SetNeedsLocalUpdate(); 115 | } 116 | } 117 | } 118 | 119 | /// 120 | /// Gets or sets the scale (relative to the parent, absolute if no parent). 121 | /// 122 | /// The scale. 123 | public Vector2 Scale 124 | { 125 | get => this.localScale; 126 | set 127 | { 128 | if (this.localScale != value) 129 | { 130 | this.localScale = value; 131 | this.SetNeedsLocalUpdate(); 132 | } 133 | } 134 | } 135 | 136 | /// 137 | /// Gets the matrix representing the local transform. 138 | /// 139 | /// The relative matrix. 140 | public Matrix Local => this.UpdateLocalAndGet(ref this.absolute); 141 | 142 | /// 143 | /// Gets the matrix representing the absolute transform. 144 | /// 145 | /// The absolute matrix. 146 | public Matrix Absolute => this.UpdateAbsoluteAndGet(ref this.absolute); 147 | 148 | /// 149 | /// Gets the matrix representing the invert of the absolute transform. 150 | /// 151 | /// The absolute matrix. 152 | public Matrix InvertAbsolute => this.UpdateAbsoluteAndGet(ref this.invertAbsolute); 153 | 154 | #endregion 155 | 156 | #region Methods 157 | 158 | public void ToLocalPosition(ref Vector2 absolute, out Vector2 local) 159 | { 160 | Vector2.Transform(ref absolute, ref this.invertAbsolute, out local); 161 | } 162 | 163 | public void ToAbsolutePosition(ref Vector2 local, out Vector2 absolute) 164 | { 165 | Vector2.Transform(ref local, ref this.absolute, out absolute); 166 | } 167 | 168 | public Vector2 ToLocalPosition(Vector2 absolute) 169 | { 170 | Vector2 result; 171 | ToLocalPosition(ref absolute, out result); 172 | return result; 173 | } 174 | 175 | public Vector2 ToAbsolutePosition(Vector2 local) 176 | { 177 | Vector2 result; 178 | ToAbsolutePosition(ref local, out result); 179 | return result; 180 | } 181 | 182 | private void SetNeedsLocalUpdate() 183 | { 184 | this.needsLocalUpdate = true; 185 | this.SetNeedsAbsoluteUpdate(); 186 | } 187 | 188 | private void SetNeedsAbsoluteUpdate() 189 | { 190 | this.needsAbsoluteUpdate = true; 191 | 192 | foreach (var child in this.children) 193 | { 194 | child.SetNeedsAbsoluteUpdate(); 195 | } 196 | } 197 | 198 | private void UpdateLocal() 199 | { 200 | var result = Matrix.CreateScale(this.Scale.X, this.Scale.Y, 1); 201 | result *= Matrix.CreateRotationZ(this.Rotation); 202 | result *= Matrix.CreateTranslation(this.Position.X, this.Position.Y, 0); 203 | this.local = result; 204 | 205 | this.needsLocalUpdate = false; 206 | } 207 | 208 | private void UpdateAbsolute() 209 | { 210 | if (this.Parent == null) 211 | { 212 | this.absolute = this.local; 213 | this.absoluteScale = this.localScale; 214 | this.absoluteRotation = this.localRotation; 215 | this.absolutePosition = this.localPosition; 216 | } 217 | else 218 | { 219 | var parentAbsolute = this.Parent.Absolute; 220 | Matrix.Multiply(ref this.local, ref parentAbsolute, out this.absolute); 221 | this.absoluteScale = this.Parent.AbsoluteScale * this.Scale; 222 | this.absoluteRotation = this.Parent.AbsoluteRotation + this.Rotation; 223 | this.absolutePosition = Vector2.Zero; 224 | this.ToAbsolutePosition(ref this.absolutePosition, out this.absolutePosition); 225 | } 226 | 227 | Matrix.Invert(ref this.absolute, out this.invertAbsolute); 228 | 229 | this.needsAbsoluteUpdate = false; 230 | } 231 | 232 | private T UpdateLocalAndGet(ref T field) 233 | { 234 | if (this.needsLocalUpdate) 235 | { 236 | this.UpdateLocal(); 237 | } 238 | 239 | return field; 240 | } 241 | 242 | private T UpdateAbsoluteAndGet(ref T field) 243 | { 244 | if (this.needsLocalUpdate) 245 | { 246 | this.UpdateLocal(); 247 | } 248 | 249 | if (this.needsAbsoluteUpdate) 250 | { 251 | this.UpdateAbsolute(); 252 | } 253 | 254 | return field; 255 | } 256 | 257 | #endregion 258 | 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /src/Transform/Tweening/Delay.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class Delay : ITween 7 | { 8 | public Delay(TimeSpan duration) 9 | { 10 | this.Duration = duration; 11 | } 12 | 13 | public TimeSpan Time { get; private set; } 14 | 15 | public TimeSpan Duration { get; } 16 | 17 | public bool IsFinished { get; private set; } 18 | 19 | public void Reset() 20 | { 21 | this.IsFinished = false; 22 | this.Time = TimeSpan.Zero; 23 | } 24 | 25 | public bool Update(GameTime time) 26 | { 27 | if (!this.IsFinished) 28 | { 29 | var delta = (float)time.ElapsedGameTime.TotalSeconds; 30 | this.Time += time.ElapsedGameTime; 31 | this.IsFinished = (this.Time >= this.Duration); 32 | } 33 | 34 | return this.IsFinished; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Transform/Tweening/ITween.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using Microsoft.Xna.Framework; 5 | 6 | public interface ITween 7 | { 8 | TimeSpan Time { get; } 9 | 10 | TimeSpan Duration { get; } 11 | 12 | bool IsFinished { get; } 13 | 14 | void Reset(); 15 | 16 | bool Update(GameTime time); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Transform/Tweening/Parallel.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using System.Linq; 5 | using Microsoft.Xna.Framework; 6 | 7 | public class Parallel : ITween 8 | { 9 | public Parallel(params ITween[] tweens) 10 | { 11 | this.tweens = tweens.ToArray(); 12 | } 13 | 14 | private ITween[] tweens; 15 | 16 | public TimeSpan Time => this.tweens.Max(x => x.Time); 17 | 18 | public TimeSpan Duration => this.tweens.Max(x => x.Duration); 19 | 20 | public bool IsFinished => this.tweens.All(x => x.IsFinished); 21 | 22 | public void Reset() 23 | { 24 | foreach (var tween in this.tweens) 25 | { 26 | tween.Reset(); 27 | } 28 | } 29 | 30 | 31 | public bool Update(GameTime time) 32 | { 33 | foreach (var tween in this.tweens) 34 | { 35 | if(!tween.IsFinished) 36 | { 37 | tween.Update(time); 38 | } 39 | } 40 | 41 | return this.IsFinished; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Transform/Tweening/Repeat.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class Repeat : ITween 7 | { 8 | public Repeat(ITween tween, int times = -1) 9 | { 10 | this.tween = tween; 11 | this.RepeatTimes = times; 12 | } 13 | 14 | #region Fields 15 | 16 | private ITween tween; 17 | 18 | private int current; 19 | 20 | #endregion 21 | 22 | public TimeSpan Time { get; set; } 23 | 24 | public int RepeatTimes { get; } 25 | 26 | public TimeSpan Duration => TimeSpan.MaxValue; 27 | 28 | public bool IsFinished => RepeatTimes > 0 && current >= RepeatTimes; 29 | 30 | public void Reset() 31 | { 32 | current = 0; 33 | tween.Reset(); 34 | } 35 | 36 | public bool Update(GameTime time) 37 | { 38 | var isFinished = this.IsFinished; 39 | if (!isFinished) 40 | { 41 | if(tween.Update(time)) 42 | { 43 | current++; 44 | 45 | isFinished = this.IsFinished; 46 | if(!isFinished) 47 | { 48 | tween.Reset(); 49 | } 50 | } 51 | 52 | } 53 | 54 | return isFinished; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Transform/Tweening/Sequence.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using System.Linq; 5 | using Microsoft.Xna.Framework; 6 | 7 | public class Sequence : ITween 8 | { 9 | public Sequence(params ITween[] tweens) 10 | { 11 | this.tweens = tweens.ToArray(); 12 | } 13 | 14 | private ITween[] tweens; 15 | 16 | public TimeSpan Time 17 | { 18 | get 19 | { 20 | var result = TimeSpan.Zero; 21 | 22 | for (int i = 0; i < this.tweens.Length; i++) 23 | { 24 | var tween = this.tweens[i]; 25 | 26 | if(i == current) 27 | return result + tween.Time; 28 | 29 | result += tween.Duration; 30 | } 31 | 32 | return result; 33 | } 34 | } 35 | 36 | public TimeSpan Duration => new TimeSpan(tweens.Sum(x => x.Duration.Ticks)); 37 | 38 | public bool IsFinished { get; private set; } 39 | 40 | public void Reset() 41 | { 42 | foreach (var tween in this.tweens) 43 | { 44 | tween.Reset(); 45 | } 46 | 47 | this.current = 0; 48 | this.IsFinished = false; 49 | } 50 | 51 | private int current; 52 | 53 | public bool Update(GameTime time) 54 | { 55 | if (!this.IsFinished) 56 | { 57 | var tween = this.tweens[current]; 58 | 59 | if(tween.Update(time)) 60 | { 61 | current++; 62 | } 63 | this.IsFinished = current >= tweens.Length; 64 | } 65 | 66 | return this.IsFinished; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Transform/Tweening/Tween2D.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class Tween2D : ITween 7 | { 8 | public Tween2D(TimeSpan duration, Transform2D transform, Transform2D to, Ease ease) 9 | : this(duration, transform, new Transform2D() 10 | { 11 | Position = transform.Position, 12 | Rotation = transform.Rotation, 13 | Scale = transform.Scale, 14 | }, to, EaseFunctions.Get(ease)) 15 | { 16 | } 17 | 18 | public Tween2D(TimeSpan duration, Transform2D transform, Transform2D from, Transform2D to, Ease ease) 19 | :this(duration, transform, from, to, EaseFunctions.Get(ease)) 20 | { 21 | } 22 | 23 | public Tween2D(TimeSpan duration, Transform2D transform, Transform2D from, Transform2D to, Func ease) 24 | { 25 | this.Duration = duration; 26 | this.Transform = transform; 27 | this.From = from; 28 | this.To = to; 29 | this.Ease = Ease; 30 | this.easeFunction = ease; 31 | } 32 | 33 | private Func easeFunction; 34 | 35 | public TimeSpan Time { get; private set; } 36 | 37 | public TimeSpan Duration { get; } 38 | 39 | public Transform2D Transform { get; } 40 | 41 | public Transform2D From { get; } 42 | 43 | public Transform2D To { get; } 44 | 45 | public bool IsRevert { get; } 46 | 47 | public Ease Ease { get; } 48 | 49 | public bool IsFinished { get; private set; } 50 | 51 | public void Reset() 52 | { 53 | this.IsFinished = false; 54 | this.Time = TimeSpan.Zero; 55 | 56 | Transform.Position = From.Position; 57 | Transform.Scale = From.Scale; 58 | Transform.Rotation = From.Rotation; 59 | } 60 | 61 | public bool Update(GameTime time) 62 | { 63 | if(!this.IsFinished) 64 | { 65 | var delta = (float)time.ElapsedGameTime.TotalSeconds; 66 | 67 | this.Time += time.ElapsedGameTime; 68 | 69 | var t = Math.Max(0, Math.Min(1, (float)(this.Time.TotalMilliseconds / this.Duration.TotalMilliseconds))); 70 | 71 | var amount = easeFunction(t); 72 | 73 | Transform.Position = From.Position + (To.Position - From.Position) * amount; 74 | Transform.Scale = From.Scale + (To.Scale - From.Scale) * amount; 75 | Transform.Rotation = From.Rotation + (To.Rotation - From.Rotation) * amount; 76 | 77 | this.IsFinished = (t >= 1); 78 | } 79 | 80 | return this.IsFinished; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Transform/Velocity2D.cs: -------------------------------------------------------------------------------- 1 | namespace Transform 2 | { 3 | using System; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class Velocity2D 7 | { 8 | public Velocity2D(Transform2D transform) 9 | { 10 | this.Transform = transform ?? throw new ArgumentException(nameof(transform)); 11 | } 12 | 13 | public Transform2D Transform { get; } 14 | 15 | public Vector2 Position { get; set; } 16 | 17 | public Vector2 Scale { get; set; } 18 | 19 | public float Rotation { get; set; } 20 | 21 | public void Update(GameTime time) 22 | { 23 | var delta = (float)time.ElapsedGameTime.TotalSeconds; 24 | this.Transform.Position += this.Position * delta; 25 | this.Transform.Scale += this.Scale * delta; 26 | this.Transform.Rotation += this.Rotation * delta; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Transform/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /tools/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | --------------------------------------------------------------------------------