Jump to content


Photo

180 Degree Mouselook


  • Please log in to reply
7 replies to this topic

#1 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 01 May 2012 - 08:30 PM

Hello! So, I have a 3D mouselook script here...
display_w=global.resolution[global.res,0]//display_get_width();
display_h=global.resolution[global.res,1]//display_get_height();


change_x=(display_mouse_get_x()-display_w/2)/16;
change_y=(display_mouse_get_y()-display_h/2)/12;

direction-=change_x
zdirection+=change_y

display_mouse_set(display_w/2,display_h/2);

The global res array is just something I have for changing resolution in game.

But, the viewing angles are limited by the method used. the camera will move up and down, smoothly as it reaches its top angle and bottom angle.
I need to look straight up and down though, and it only goes about 45 degrees each way, not 90.
  • 0

#2 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 01 May 2012 - 08:36 PM

There's nothing "wrong" or even relevent to your problem in the script. That works as it should. The problem is with your code that actually sets the projection of the camera, specifically, d3d_set_projection(). Post that part of you code here.

I'm assuming that you haven't taken zdirection into account when setting the up vector of the camera or something.

Edited by LaLaLa, 01 May 2012 - 08:37 PM.

  • 0

#3 Samuel Venable

Samuel Venable

    GMC Member

  • Banned Users
  • 632 posts
  • Version:GM:Studio

Posted 01 May 2012 - 09:31 PM

If you'd remove this line:
direction-=change_x
It wouldn't spurise me if it started working like you wanted it to.

#4 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 3024 posts
  • Version:GM:Studio

Posted 01 May 2012 - 09:46 PM

I'm assuming that you haven't taken zdirection into account when setting the up vector of the camera or something.

Game maker lets you keep a constant up vector even when the to-vector changes (as long as they're not parallell), so I don't think that's the problem. My guess is the problem lies with how you transform the angles to a vector. It should be done something like this:
xto=cos(degtorad(direction))*cos(degtorad(zdirection))
yto=sin(degtorad(direction))*cos(degtorad(zdirection))
zto=sin(degtorad(zdirection))

  • 1

#5 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 02 May 2012 - 01:00 AM

xf=obj_character.x;       //x to look from
yf=obj_character.y;       //y to look from
zf=obj_character.z;    //z to look from

xt=xf+cos(degtorad(direction));         //x to look to (with direction)
yt=yf-sin(degtorad(direction));         //y to look to (with direction)
zt=zf-sin(degtorad(zdirection+obj_character.tilt));     //z to look to (with z direction)

d3d_set_projection_ext(xf,yf,zf,    xt,yt,zt,   0,0,1, global.fov, 16/9, 1, 3200);     //look from & to

This is my camera's projection script here.
  • 0

#6 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 710 posts
  • Version:GM:Studio

Posted 02 May 2012 - 02:40 AM

You aren't taking the z angle into account when you calculate the x and y the camera is looking to. Look at TheSnidr's code for help.
  • 1

#7 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4238 posts
  • Version:GM:Studio

Posted 02 May 2012 - 09:30 AM

xt=xf+cos(degtorad(direction));         //x to look to (with direction)
yt=yf-sin(degtorad(direction));         //y to look to (with direction)
zt=zf-tan(degtorad(zdirection));
should also do this. (It's equivalent to TheSnidr's code [if assumed that the from position is at (0,0,0)].)

You see, (xfrom,yfrom,zfrom) is the position where the camera is at; (xto,yto,zto) is the position to which it always views. Now if on the x-y-plane this position runs in a circle, then as the zdirection tends to 90 degrees, the zto coordinate must tend to infinity. The tangent function has this property, while the sine has the maximum value of 1 (thus, you'd only be able to see 45 degrees up). What TheSnidr meant by his code#, on the other hand, also changes the xto and yto coordinates, so that the (xto,yto,zto) actually runs around on a surface of a unit sphere. The tangent function introduces singularities at exactly -90 and 90, but then again at those coordinates the direction vector becomes parallel to the up-vector, in which case you see nothing (so execute zdirection = median(-89.99,zdirection,89.99) or something).

#:
Spoiler

  • 0

#8 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 02 May 2012 - 07:33 PM

Wow, that was an amazing explanation. Thanks a lot everybody, especially you guys, Tepi and TheSnidr.

Essentially all I had to do was change my Sine to a Tangent. Hah

Thanks again for the help. =]
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users