Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / lil ittybitty mouse cam code angle prob.

Author
Message
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 7th Apr 2005 04:25
here the camera look code I use, could someone modify it so you can't look further up or down for like 45 degreees.
I've tried everything I know, but I didn't fix it.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 7th Apr 2005 10:57 Edited at: 7th Apr 2005 16:15
Link102,

I have attached to this post a short segment of code for you, in which will fix your problem. In it is two variables. rotx# stores a calculated angle, used along with mousemovey(), and rotlimit is an integer variable playing the role of Boolean, used to 'lock' and 'free' your camera's ability to rotate along it's X axis.

In short, if rotlimit = 0 then rotx# = wrapvalue(rotx# + mousemovey()) creates a degree of angle of the X axis of your camera, if so-be rotlimit is equal to 0. This is the 'lock' and 'free' line of code. Next, is the camera 'locker', that if rotx# becomes less than 315o(up) or greater than 45o(down), then rotlimit is given the value of 1, disabling the first line of code, and either locking rotx#'s value to 315o or 45o.

Notice how I have included that if rotx# is less than 315o and greater than 200o. Also, if rotx# is greater than 45o and less than 160o. This is because we are not judging values on a number line. Rather, we are judging them in angles. Therefore, if rotx# is less than 315o, it is also technically greater than 45o. In angles, and in this case, you are calculating between all positive numbers. So, for the 'lock' codes to work, we have to place another limit that is less than 315o, but also greater than 45o, and vise-versa. 315o is always greater than 45o and 45o is always less than 315o.

Finnally, for the code which 'frees' the camera to rotate about the X axis. Simply, if the angle is 'locked' down, but the mouse moves upwards on it's y axis, then rotlimit is given the value of 0. The same method is used if the camera is 'locked' up, except the opposite. Thus, enabling the first line of code to be executed.

+NanoBrain+
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 8th Apr 2005 02:52
ok, I comppletly understand your code, but why soesn't it work?
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 8th Apr 2005 07:26
I´m sorry for the double post, but all of a sudden my code don´t work and I can´t edit my posts

so here´s the modified code:
`camera mouse control

if rotlimit=0 then rotx#=mousemovex()
roty#=mousemovey()

`if rotlimit=0 then rotx#=wrapvalue(rotx#+mousemovey())

if rotx#<315 and rotx#>200
rotx#=315
rotlimit=1
endif

if rotx#>45 and rotx#<160
rotx#=45
rotlimit=1
endif

if rotx#=315 and mousemovey()>0 then rotlimit=0
if rotx#=45 and mousemovey()<0 then rotlimit=0

xangle#=camera angle x()
yangle#=camera angle y()

xangle#=wrapvalue(xangle#+roty#)
yangle#=wrapvalue(yangle#+rotx#)

rotate camera xangle#,yangle#,0
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 10th Apr 2005 13:37 Edited at: 10th Apr 2005 13:48
Link102,

First, there is no need for this line of code:
, and you need to remove if rotlimit=0 then rotx#=mousemovex() and keep `if rotlimit=0 then rotx#=wrapvalue(rotx#+mousemovey()), but without the ` symbol.

Now, notice that you have two variables using the same mouse move command. There is rotx# and roty# which both feed from the same hole. rotx# is 'meant' to be for the camera's x amount of rotation, and roty# for it's y amount of rotation. Therefore, they cannot both be recieving the mouse's y movement. So, change roty#=mousemovey() to roty# = wrapvalue(roty# + mousemovex()). I've changed mousemovey() to mousemovex(). Wrapvalue is very important if so-be that an angle will go over 360o or under 0o. Also, I have added ...(roty# + mousemovex()), because without it you will never be able to rotate more than a few degrees.

Mousemove returns a negative or a positive number, depending on the direction of the movement. On the Y dimension, moving your mouse up will create a negative value, and down will return a posiive value. Same for the X dimension:left a negative and right a positive. So, do the math here.

Lastly, change rotate camera xangle#,yangle#,0 to rotate camera rotx#,roty#,0, because rotx# and roty# are the variables which should now be holding the correct information for your camera to rotate correctly.

In conclusion, the code you have added disfunctioned the entire result. On top of this, you included code(the first lines of code I mentioned) that were cumbersome and not needed. Stick to the code I originally sufficed you(
), without adding any extras, and your rotation will be fine.

When in a rut with your code, which is not acting as should, run through your code, line by line, creating a mental animation of a certain scenario ran by your code. This is a great method which helps me, at least, to figure what might be wrong in my program.

+NanoBrain+
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 11th Apr 2005 05:47
Yay it works now thank you, now I can continue to exeriment with my own les flare code (based on camera angle's), but first, friction and gravity phisics

BTW: I'm creating a FPS, it's aready 138 lines long

Quote: "When in a rut with your code, which is not acting as should, run through your code, line by line, creating a mental animation of a certain scenario ran by your code. This is a great method which helps me, at least, to figure what might be wrong in my program."


Yup I always do that too, but I got confused by the fact that some of the x's and y's were swaped.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 13th Apr 2005 08:34
Link102,

It's always a great feeling inside to conquer a tough problem in programming. I'm glad you came to a conclusion.

+NanoBrain+

Login to post a reply

Server time is: 2025-05-23 08:13:55
Your offset time is: 2025-05-23 08:13:55