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 / RTS camera control, with mouse wheel zoom ?

Author
Message
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 23rd Dec 2004 03:34
Hello, I would like to know how I would create a RTS style camera system, that allows you to move the camera using the arrow keys, and zoom in and out using the mouse wheel.

Thank you.

Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd Dec 2004 04:29
I'm not giving you code, but some helpful ideas instead:

Make a x# and z# variable.
Position the camera using those 2 variables.
Now increase / decrease the value of those variables when the user presses on the arrowkeys, or when the mouse is near the edge of the screen.

When you detect mousewheel movement ( mousez() ) just use move camera to move the camera.
Because your game is a RTS, the camera is always pointed to the terrain, so it will work

Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 23rd Dec 2004 04:48 Edited at: 23rd Dec 2004 05:00
Thanks, everything is working except for the mouse wheel, I don't know how to use the mousez in a command. How would I check to see if it is being scrolled up or down? And how would I put that into an if-then statement?

Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 23rd Dec 2004 06:21
The mousez command works the same as the mousex and mousey command except that is goes by the scroll wheel instead of the x and y pixels across the screen.

Crazy Donut Productions, Current Project: Project Starbuks
Sony stole our name!
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Dec 2004 06:45


mousemovez() only seems to give out -120 and 120.
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 23rd Dec 2004 07:30
I still don't understand what your doing up there. I want to check if the mouse wheel is being scrolled up or down, and move the camera forward or backwards accordingly. Here is my code so far....



Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 23rd Dec 2004 12:20
Here's the mousewheel zoom.



I suggest using 'set camera fov' for zooming instead of 'move camera'.

You have to compare the current value of mousemovez() with the last value of mousemovez() and see if it is greater or less. Print the value of MouseZNow and MouseZLast and you'll see why.


I spelled "disappointment" wrong. Pahintulutan ang di-inaasahang nakakahiyang pagkakamaling dulot ng kamangmangan. Have at you.
Wolfee
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 23rd Dec 2004 19:06
I've got a scroll source, but it zooms with the up and down buttons, and it scrolls with the mouse
Wolfee
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 23rd Dec 2004 19:06
I've got a scroll source, but it zooms with the up and down buttons, and it scrolls with the mouse
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Dec 2004 22:22
You didn't have to post it twice

CURRENT PROJECT: Chaos Hizzle Demo
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 23rd Dec 2004 22:36
I don't think he meant to.

Realms Of Tutopia: Rise Of Evil
http://www.freewebs.com/elbsoftware/index.htm
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 24th Dec 2004 00:04
Quote: " Here's the mousewheel zoom.

+ Code Snippet

sync on
sync rate 0
hide mouse
autocam off

make object sphere 1,16
position object 1,0,0,32

MouseZLast = 0
MouseZNow = 0
`DBC Default camera FOV
FOV# = 3.14/2.905

while escapekey() = 0
set cursor 0,0

MouseZNow = mousemovez()
if MouseZNow <> MouseZLast
if MouseZNow > MouseZLast
`Mousewheel down, zoom out
FOV# = FOV# - 0.02
else
if MouseZNow < MouseZLast
`Mousewheel up, zoom in
FOV# = FOV# + 0.02
endif
endif

`zoom out
if FOV# > 2.905 then FOV# = 2.905
`zoom in
if FOV# < 0.314 then FOV# = 0.314
MouseZLast = MouseZNow
`set the FOV for zooming
set camera fov FOV#

endif
sync
endwhile



I suggest using 'set camera fov' for zooming instead of 'move camera'.

You have to compare the current value of mousemovez() with the last value of mousemovez() and see if it is greater or less. Print the value of MouseZNow and MouseZLast and you'll see why.
"


Ok thanks, your code worked, but I found that the Fov commands were stretching objects, so I changed it to a simple move camera command. However, I have encountered a problem. I can now scroll in and out with the mouse, but I can no longer move the camera left, right, up, or down. Any ideas why? Here is my code.....



Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 24th Dec 2004 00:41
Something like this works well:



Just put the functions in another file, then include it and just call Camera() every loop.
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 24th Dec 2004 02:17 Edited at: 24th Dec 2004 02:19
Ok, but how do I include and call it?

sorry, I'm new to external functions like this.

Oh, and can anybody figure out why the code I gave in my last post, doesn't let you move the camera around? It stopped working as soon as I added zooming.

Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 24th Dec 2004 02:29
You don't need to have them in a separate file, it's just a bit cleaner.

Just C + P the example it posted.

As you can see you just need to say Camera every loop. It really couldn't be easier.
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 24th Dec 2004 03:35
Hmm, I'm afraid that it isn't doing what I had hoped. Is there anyway to fix my original code, to make that work? Because as I had it, it zoomed, but would not move the camera with the arrow keys.

Thanks anyway though.

Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.

Login to post a reply

Server time is: 2025-05-24 08:17:30
Your offset time is: 2025-05-24 08:17:30