mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 13:29:54 +00:00
fov
This commit is contained in:
parent
790d9137b3
commit
ec8427770a
3 changed files with 32 additions and 18 deletions
|
|
@ -224,7 +224,7 @@ DEF_GRA_PROP_B(Frameskip)
|
|||
_rb_define_module_function(module, prop_name_s "=", graphics##Set##PropName); \
|
||||
}
|
||||
|
||||
static VALUE graphicsWindowMoved(VALUE self){
|
||||
static VALUE graphicsWindowMoved(VALUE){
|
||||
RUBY_CONNECTION
|
||||
conn->connection = shState->windowSignals.moved.Connect([conn](int x, int y){
|
||||
shState->rubyDispatcher().invoke([conn, x, y]{
|
||||
|
|
@ -239,7 +239,7 @@ static VALUE graphicsWindowMoved(VALUE self){
|
|||
return TypedData_Wrap_Struct(rb_cRubyConnection, &rubyConnection_type, conn);
|
||||
}
|
||||
|
||||
static VALUE graphicsWindowResized(VALUE self){
|
||||
static VALUE graphicsWindowResized(VALUE){
|
||||
RUBY_CONNECTION
|
||||
conn->connection = shState->windowSignals.resized.Connect([conn](int w, int h){
|
||||
shState->rubyDispatcher().invoke([conn, w, h]{
|
||||
|
|
@ -254,7 +254,7 @@ static VALUE graphicsWindowResized(VALUE self){
|
|||
return TypedData_Wrap_Struct(rb_cRubyConnection, &rubyConnection_type, conn);
|
||||
}
|
||||
|
||||
static VALUE graphicsViewportResized(VALUE self){
|
||||
static VALUE graphicsViewportResized(VALUE){
|
||||
RUBY_CONNECTION
|
||||
conn->connection = shState->graphicsSignals.resized.Connect([conn](int w, int h){
|
||||
//shState->rubyDispatcher().invoke([conn, w, h]{
|
||||
|
|
@ -269,6 +269,15 @@ static VALUE graphicsViewportResized(VALUE self){
|
|||
return TypedData_Wrap_Struct(rb_cRubyConnection, &rubyConnection_type, conn);
|
||||
}
|
||||
|
||||
static VALUE graphicsGetFOV(VALUE) {
|
||||
return DBL2NUM(shState->graphics().globalFov);
|
||||
}
|
||||
|
||||
static VALUE graphicsSetFOV(VALUE, VALUE fov) {
|
||||
shState->graphics().globalFov = NUM2DBL(fov);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void graphicsBindingInit(){
|
||||
VALUE module = rb_define_module("Graphics");
|
||||
|
||||
|
|
@ -278,6 +287,10 @@ void graphicsBindingInit(){
|
|||
rb_define_module_function(module, "window_resized", RUBY_METHOD_FUNC(graphicsWindowResized), 0);
|
||||
rb_define_module_function(module, "viewport_resized", RUBY_METHOD_FUNC(graphicsViewportResized), 0);
|
||||
|
||||
|
||||
rb_define_module_function(module, "fov", RUBY_METHOD_FUNC(graphicsGetFOV), 0);
|
||||
rb_define_module_function(module, "fov=", RUBY_METHOD_FUNC(graphicsSetFOV), 1);
|
||||
|
||||
// Functions
|
||||
_rb_define_module_function(module, "x", graphicsPosX);
|
||||
_rb_define_module_function(module, "y", graphicsPosY);
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ public:
|
|||
DECL_ATTR( Smooth, bool )
|
||||
DECL_ATTR( Frameskip, bool )
|
||||
|
||||
float globalFov = 70;
|
||||
|
||||
/* <internal> */
|
||||
Scene *getScreen() const;
|
||||
/* Repaint screen with static image until exitCond
|
||||
|
|
|
|||
|
|
@ -243,23 +243,22 @@ void ShaderBase::applyPerspectiveProj()
|
|||
const float width = (float)vp.w;
|
||||
const float height = (float)vp.h;
|
||||
|
||||
const float cameraDistance = 1000.0f;
|
||||
const float camDist = (height * 0.5f) / SDL_tan(shState->graphics().globalFov * PI / 360.0f);
|
||||
|
||||
const float nearPlane = 1.0f;
|
||||
const float nearPlane = 0.01f;
|
||||
const float farPlane = 10000.0f;
|
||||
|
||||
const float sx = 2.0f * cameraDistance / width;
|
||||
const float sy = 2.0f * cameraDistance / height;
|
||||
const float sx = 2.0f * camDist / width;
|
||||
const float sy = 2.0f * camDist / height;
|
||||
|
||||
const float A = -(farPlane + nearPlane) / (farPlane - nearPlane);
|
||||
|
||||
const float B = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
|
||||
const float A = (farPlane + nearPlane) / (farPlane - nearPlane);
|
||||
const float B = (2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
|
||||
|
||||
GLfloat mat[16] = {
|
||||
sx, 0, 0, 0,
|
||||
0, sy, 0, 0,
|
||||
0, 0, A, -1,
|
||||
-cameraDistance, -cameraDistance, B, cameraDistance
|
||||
0, 0, -A, -1,
|
||||
-camDist, -camDist, A * camDist - B, camDist
|
||||
};
|
||||
|
||||
gl.UniformMatrix4fv(projMat.u_mat, 1, GL_FALSE, mat);
|
||||
|
|
|
|||
Loading…
Reference in a new issue