Hi!
Im a student currently busy writing a simple r-type clone and i was wondering if there is a way to create a transformation matrix that creates a depth illusion (stuff in the back appears smaller and moves slower when moving the camera).
I managed to achieve this effect by setting the view and projection property of a base effect and passing it on to the spritebatch.begin method.
public class Camera
{
private Matrix View()
{
var p = new Plane(new Vector3(0, 1, 0), 1);
return Matrix.CreateLookAt(_position, _position + Vector3.Forward, Vector3.Up)
* Matrix.CreateReflection§* Matrix.CreateRotationZ(_rotation * (float)Math.PI/180);
}
private Matrix GetProjection()
{
return Matrix.CreatePerspectiveFieldOfView((float) (FieldOfView * Math.PI/180f), AspectRatio, ZNearPlane, ZFarPlane);
}
public Matrix GetTransformationMatrix()
{
return Matrix.CreateTranslation(-_position) * GetProjection();
}
public BasicEffect GetCameraEffect()
{
_spriteEffect.View = View();
_spriteEffect.Projection = GetProjection();
return _spriteEffect;
}
}
But apperently it has the drawback that it is impossible to tint/fade textures by changing the color that is passed into the spritebatch.draw method.
Example of the desired effect
I tried the same thing by ditching the baseeffect and using the GetTransformationMatrix Method instead but so far i had no luck
Hopefully it is not that much of a rookie mistake that i just failed to look up properly.
Anyway thank you for your time and i’m looking forward for your advice.