Please enable JavaScript to use RhodeCode Enterprise
Commit Description:
Refactor and cleanup.
Commit Description:
Refactor and cleanup.
using System ;
using Microsoft.Xna.Framework ;
using Microsoft.Xna.Framework.Graphics ;
namespace isometricparkfna
{
public class Camera
{
public Vector2 position ;
float _zoom ;
public static int world_width { get ; set ; }
public static int world_height { get ; set ; }
public static Vector2 display_offset { get ; set ; }
public float zoom
{
get { return _zoom ; }
set { _zoom = value ; if ( zoom < 0.1f ) _zoom = 0.1f ; } // Negative zoom will flip image
}
public Camera ()
{
this . zoom = 1.0f ;
position = Vector2 . Zero ;
}
public void Move ( Vector2 change )
{
this . position += change ;
}
public Matrix get_transformation ( GraphicsDevice graphicsDevice )
{
Viewport viewPort = graphicsDevice . Viewport ;
Matrix transformation = Matrix . CreateTranslation ( new Vector3 (- this . position . X , - this . position . Y , 0 )) *
Matrix . CreateScale ( new Vector3 ( this . zoom , this . zoom , 1 )) *
Matrix . CreateTranslation ( new Vector3 ( viewPort . Width * 0.5f , viewPort . Height * 0.5f , 0 ));
return transformation ;
}
public Vector2 world_to_screen ( Vector2 worldPosition )
{
return worldPosition - this . position + Camera . display_offset ;
}
public Vector2 screen_to_world ( Vector2 screenPosition )
{
return screenPosition + this . position - Camera . display_offset ;
}
}
}
Site-wide shortcuts
/
Use quick search box
g h
Goto home page
g g
Goto my private gists page
g G
Goto my public gists page
n r
New repository page
n g
New gist page
Repositories
g s
Goto summary page
g c
Goto changelog page
g f
Goto files page
g F
Goto files page with file search activated
g p
Goto pull requests page
g o
Goto repository settings
g O
Goto repository permissions settings