budnhead/GLCamera.cs

87 lines
1.5 KiB
C#

using System;
using OpenTK.Graphics.OpenGL;
using OpenTK.Graphics;
using OpenTK;
namespace nhengine
{
public class GLCamera
{
Matrix4 position,
projection,
rotation,
lookat;
Matrix4 result;
float arc_z,
arc_x;
float distance;
public GLCamera()
{
lookat = Matrix4.CreateTranslation(1600, 1600, 0);
distance = 2500.0f;
projection = Matrix4.CreatePerspectiveFieldOfView(
MathHelper.PiOver4,
1.6f,
0.5f,
100000.0f
);
rotation = Matrix4.CreateScale(1.0f);
setup();
}
public void setViewport(int width,int height){
projection = Matrix4.CreatePerspectiveFieldOfView(
MathHelper.PiOver4,
width / (float)height,
0.5f,
100000.0f
);
}
public Matrix4 Rotation {
get { return this.rotation; }
}
public float ArcZ
{
get { return this.arc_z; }
set { this.arc_z = value; }
}
public float ArcX
{
get { return this.arc_x; }
set { this.arc_x = value; }
}
public float Distance {
get { return this.distance; }
set { this.distance = value; }
}
public void setup(){
rotation = Matrix4.CreateRotationZ(this.arc_z) * Matrix4.CreateRotationX(this.arc_x);
position = Matrix4.CreateTranslation(0, 0, distance);
result = Matrix4.Identity;
result *= lookat.Inverted();
result *= rotation;
// result *= Matrix4.CreateRotationZ(this.arc_z);
// result *= Matrix4.CreateRotationX(this.arc_x);
result *= position.Inverted();
result *= projection;
}
public Matrix4 Matrix {
get { return this.result; }
}
}
}