130 lines
2.1 KiB
C#
130 lines
2.1 KiB
C#
using System;
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
using OpenTK.Graphics;
|
|
using OpenTK;
|
|
|
|
namespace org.nhengine.graphics
|
|
{
|
|
public class GLCamera
|
|
{
|
|
Vector3 vPosition; // Position der Kamera
|
|
Vector3 vDirection; // Blickrichtung der Kamera
|
|
|
|
float fDistance; // Zusätzliche Distanz der Kamera entgegen der Blickrichtung
|
|
|
|
Matrix4 mTranslation; // Matrix für Translation
|
|
Matrix4 mRotation; // Matrix für Rotation
|
|
Matrix4 mDistance; // Matrix für Rückzug entgegen der Blickrichtung
|
|
Matrix4 mProjection; // Projektionsmatrix
|
|
|
|
public GLCamera()
|
|
{
|
|
vPosition = new Vector3(0,0,0);
|
|
vDirection = Vector3.UnitZ;
|
|
fDistance = 0.0f;
|
|
|
|
mProjection = Matrix4.CreatePerspectiveFieldOfView(
|
|
MathHelper.PiOver4,
|
|
1.0f,
|
|
50.0f,
|
|
100000.0f
|
|
);
|
|
|
|
mRotation = Matrix4.Identity;
|
|
|
|
glPrepare();
|
|
}
|
|
|
|
public void setViewport(int width, int height)
|
|
{
|
|
mProjection = Matrix4.CreatePerspectiveFieldOfView(
|
|
MathHelper.PiOver4,
|
|
width / (float)height,
|
|
50.0f,
|
|
100000.0f
|
|
);
|
|
}
|
|
|
|
private void glPrepare(){
|
|
this.mTranslation = Matrix4.CreateTranslation(vPosition * -1.0f);
|
|
this.mDistance = mRotation * Matrix4.CreateTranslation(0, 0, -fDistance);
|
|
|
|
// Console.WriteLine("View Direction: {0}", vDirection);
|
|
// Console.WriteLine("Rotation Matrix: {0}", mRotation);
|
|
|
|
}
|
|
|
|
private void glUpdate(){
|
|
|
|
}
|
|
|
|
public void use(ShaderProgram sp){
|
|
glUpdate();
|
|
|
|
}
|
|
|
|
|
|
public Matrix4 MTranslation
|
|
{
|
|
get
|
|
{
|
|
return mTranslation;
|
|
}
|
|
}
|
|
|
|
public Matrix4 MRotation
|
|
{
|
|
get
|
|
{
|
|
return mRotation;
|
|
}
|
|
set {
|
|
this.mRotation = value;
|
|
}
|
|
}
|
|
|
|
public Matrix4 MDistance
|
|
{
|
|
get
|
|
{
|
|
return mDistance;
|
|
}
|
|
}
|
|
|
|
public Matrix4 MProjection
|
|
{
|
|
get
|
|
{
|
|
return mProjection;
|
|
}
|
|
}
|
|
|
|
public float Distance
|
|
{
|
|
get
|
|
{
|
|
return fDistance;
|
|
}
|
|
|
|
set
|
|
{
|
|
fDistance = value;
|
|
glPrepare();
|
|
}
|
|
}
|
|
/*
|
|
public Vector3 Direction {
|
|
get { return this.vDirection; }
|
|
set { this.vDirection = value; glPrepare(); }
|
|
}
|
|
*/
|
|
public Vector3 Position {
|
|
get { return this.vPosition; }
|
|
set { this.vPosition = value; glPrepare(); }
|
|
}
|
|
|
|
|
|
}
|
|
}
|