Hi Everyone!
Apologies for asking what may well be a super obvious question, but I was wondering how to accurately calculate the xup, yup, and zup values for the d3d_set_projection_ext() function. All of the tutorials I have watched and read have set xup, yup, and zup to (0,0,1) or (0,0,-1) respectively, which seems to work in most cases, however doesn't appear to accurately work in my current project. I'm currently working on a 3D ray cast system (which I have almost completely working, thanks to the awesome help of some people here), however the ray itself seems to act strangely at extreme pitch/zdir values (i.e when the character is looking up or down to any great degree.
Essentially, what happens is that while the pitch of the player/camera object is kept fairly close to being 'natural', everything works perfectly fine, however as you pitch the camera upwards or downwards, the ray seems to move exponentially less. When you pitch the camera as high as it will go (80 degrees currently), the ray appears as if it is casting from two thirds down the screen, rather than the middle, conversely, when you pitch the camera fully down, the ray appears as it is casting from the top third of the screen, not the centre. It's a strange occurrence that makes gameplay feel super strange!
I received some super helpful advice in a previous thread (here), and I've been trying to work things out, but I'm still totally lost, and figured I'd be best of starting a dedicated thread to try and look for some advice on where I was going wrong.
I have tried a couple of different ways of setting up my camera projections, but many of them conflict with other aspects of my game, so at the moment I'm using the following system to set up my projection:
Any help is greatly appreciated!
Have a great night!
Apologies for asking what may well be a super obvious question, but I was wondering how to accurately calculate the xup, yup, and zup values for the d3d_set_projection_ext() function. All of the tutorials I have watched and read have set xup, yup, and zup to (0,0,1) or (0,0,-1) respectively, which seems to work in most cases, however doesn't appear to accurately work in my current project. I'm currently working on a 3D ray cast system (which I have almost completely working, thanks to the awesome help of some people here), however the ray itself seems to act strangely at extreme pitch/zdir values (i.e when the character is looking up or down to any great degree.
Essentially, what happens is that while the pitch of the player/camera object is kept fairly close to being 'natural', everything works perfectly fine, however as you pitch the camera upwards or downwards, the ray seems to move exponentially less. When you pitch the camera as high as it will go (80 degrees currently), the ray appears as if it is casting from two thirds down the screen, rather than the middle, conversely, when you pitch the camera fully down, the ray appears as it is casting from the top third of the screen, not the centre. It's a strange occurrence that makes gameplay feel super strange!
I received some super helpful advice in a previous thread (here), and I've been trying to work things out, but I'm still totally lost, and figured I'd be best of starting a dedicated thread to try and look for some advice on where I was going wrong.
I have tried a couple of different ways of setting up my camera projections, but many of them conflict with other aspects of my game, so at the moment I'm using the following system to set up my projection:
GML:
///Mouse-look controls
//Calculate turning
direction -= (display_mouse_get_x() - display_get_width() / 2) * 0.125;
pitch -= (display_mouse_get_y() - display_get_height() / 2) * 0.1;
dir = direction;
//Clamp zdir
pitch = clamp(pitch, -80, 80);
zdir = pitch;
//Set xto, yto, zto
var d = degtorad(direction);
var zd = degtorad(pitch);
xto = x + cos(d) * abs(sin(zd) + sign(-pitch));
yto = y - sin(d) * abs(sin(zd) + sign(-pitch));
zto = z + height + sin(zd);
zup = z + height + sin(degtorad(zdir+90));
//Lock cursor
var center_x = display_get_width() / 2;
var center_y = display_get_height() / 2;
display_mouse_set(center_x, center_y);
Code:
///Draw camera
var w = view_wport;
var h = view_hport;
d3d_set_projection_ext(obj_player.x, obj_player.y, obj_player.z + obj_player.height - 2, obj_player.xto, obj_player.yto, obj_player.zto - 2, 0, 0, obj_player.zup, obj_player.fov, w / h, 1, 10000000);
Any help is greatly appreciated!
Have a great night!