Endless camera movement with the mouse visible

Blitz3D Forums/Blitz3D Beginners Area/Endless camera movement with the mouse visible

fox95871(Posted 2009) [#1]
Hi, can someone please show me how I can make this so when you drag to the end of the screen, the camera doesn't stop just because the mouse can't go any further? I'm not looking for the mouse hidden and repeatedly returning to 320,240 like it's usually done, I want the mouse to be visibly at the edge of the screen and the camera still able to be moved more and more.

http://www.mediafire.com/?hqgqtjve7s2fts4


Guy Fawkes(Posted 2009) [#2]
hes got a point..


Warner(Posted 2009) [#3]
Yes, well, if we're talking fullscreen here, you might want to consider using a 'fake' mouse. The fake mouse is limited to the screen, and the real mouse is kept into the center of the screen.
If this is about windowed mode, you might notice that the mouse is capable of leaving the screen, even when you try to prevent it. Also, if the mouse does leave the screen, there is allways the desktop limits.
graphics 800,600,0,2

repeat
 if mousex() < 20 then movemouse 20, mousey()
 if mousey() < 20 then movemouse mousex(), 20
 if mousex() > 780 then movemouse 780, mousey()
 if mousey() > 580 then movemouse mousex(), 580
until keyhit(1)
end


This is out of my head, not sure if it works like this:



Guy Fawkes(Posted 2009) [#4]
heres a fix.

it works in both 2d and 3d.

AND it works

for ALL graphics mode.

regardless

Graphics3D 800,600,0,2
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
MouseXSpeed()
MouseYSpeed()
HidePointer
Repeat
  Cls
If KeyDown(57)
ShowPointer
Else
HidePointer
EndIf
  mx = mx + MouseXSpeed()
  my = my + MouseYSpeed()
  MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  If mx > GraphicsWidth() Then mx = GraphicsWidth()
  If my > GraphicsHeight() Then my = GraphicsHeight()
  If mx < 0 Then mx = 0
  If my < 0 Then my = 0
  Text mx, my, "+", 1, 1
  UpdateWorld
  RenderWorld
Text 10,10, "Press & hold / let go of spacekey to show/hide mouse"
  Flip
Until KeyHit(1)


~DS~


Flemmonk(Posted 2009) [#5]
That code is no good because if the window looses focus then I cant use my operating system.


Ross C(Posted 2009) [#6]
Warners idea will work, only if your holding in the mouse to drag. That way, when you let the mouse go, the mouse control will return to normal. Only issue i see, is if the mouse goes off the blitz screen, and mousex/y only captures the last known co-ord inside the blitz window.


_PJ_(Posted 2009) [#7]
You could try substituting in a 'duplicate' for the mouse coords, you may require more than one call depending on speed of the program else the duplicate may lag some.

Global MsX
Global MsY

Const PointerWidth=20
Const PointerHeight=20
; You may need some modification to these, especially if using a handle-centred pointer.

Global GWidth=GraphicsWidth()
Global GHeight=GraphicsHeight()

;. . .
Function UpdateMouse()
If RectsOverlapRectsOverlap (MouseX(),MouseY(),PointerWidth Shl True,PointerHeight Shl True,PointerWidth,PointerHeight,GWidth-(PointerWidth),(GWidth-PointerHeight))
MsX=MouseX()
MsY=MouseY()
Else
MsX=GWidth
MsY=GHeight
End Function


This way, if the mouse is off the blitz window, you can still use MsX and MsY coords for scrolling, without moving the actual pointer and disrupting access to the rest of the desktop. However, when checking for mouseclicks within the game, just use normal MouseX / MouseY
:)


fox95871(Posted 2009) [#8]
Lots to try, thank you. I'll get back to you all in a few days with hopefully the finished exe of this.


_PJ_(Posted 2009) [#9]
Good luck :)


fox95871(Posted 2009) [#10]
Could someone please help me with this by altering my actual code? I really appreciate all the examples, they do work, but it doesn't really help me when the biggest problem is getting it to work with my preexisting code:



If you download the media from my first post and run this now, you'll see that the mouse graphic itself behaves exactly how I want it to, it can be moved to the edges of the screen, and there it stops, even if you keep dragging. Unfortunately the camera does too, I want that to keep going! I think the solution must have something to do with making the camera following mouse2s readings, but I don't know. Please help. And please alter and repost my actual code, isn't that a lot easier than writing up a whole new example anyway? I never got that :)

Oh! I just noticed mode three works! I need the other to to do exactly that when you drag passed the edge of the screen. Look for Gias code in MoveCamera.


WERDNA(Posted 2009) [#11]
Just downloaded your media and code fox.

I'll see what I can do when I get a chance.

WERDNA


fox95871(Posted 2009) [#12]
Good, I thought no one would reply because it's summer. Means nothing to me, all the more reason to stay inside I say.


WERDNA(Posted 2009) [#13]
I've been pretty busy with robo attack.
Haven't had much time to look at this.

In 2 or 3 days I'll be done with robo attack, and then I can see what
I can do with this.

If I have time, I'll try before then, but robo attack is really keeping me
busy :)


fox95871(Posted 2009) [#14]
No problem. Glad to hear you're occupied.


WERDNA(Posted 2009) [#15]
I had a go at getting this to work.

Its a bit confusing, but I might, with a little more time, be able to
make this work.

Don't count on it though. Have a back up plan if I can't :)

WERDNA


fox95871(Posted 2009) [#16]
I wonder sometimes if theres's some things like this that Blitz3D just can't do. I doubt it though. Hope someone can help.


WERDNA(Posted 2009) [#17]
Blitz3D can do this with the right coding.

I still haven't figured it out, but you might get somewhere by running
a check to see if the mouse is at the edge of the screen and then
moving the camera a bit differently than normal if it is.
(If MouseX() = 0 then do something for instance)

I was able to make it move how you want when I wasn't
holding down the mouse button, but as soon as I pressed the mouse
button down, all my code became null :(

My guess is, that you are using the MouseDown and MouseHit commands
too much. Using these, and keyhit commands too much can really mess
things up sometimes, and should be avoided when possible.

For instance, instead of saying


This would probably work better.


You should try rewriting your code, to make its function clearer.

Other than that though, your program really is quite good!
You have certainly come a long way in Blitz3D, very very quickly!

So just keep up the good work, and NEVER get discouraged.

Good luck to you!

WERDNA


fox95871(Posted 2009) [#18]
Thanks! Well, I'm pretty disciplined when it comes to awesomeness like making your own videogames. In this case though, I have to prioritize instead. There's too much else about my engine that needs work first. If someone can fix this though while I'm doing that, that'd be great. I'll just keep it here for that. Calling all geniuses!


Bobysait(Posted 2009) [#19]
what you can do is to not clamp the mouse on the screen, but just make the screen become infinite.

If mousedown(1)
 Mx=MouseX()
 My=MouseY()
 if Mx>Graphicswidth()-20 Then Mx=20 : MouseXSpeed()
 if Mx<20 Then Mx=Graphicswidth()-20 : MouseXSpeed()
 if My>Graphicsheight()-20 Then My=20 : MouseYSpeed()
 if My<20 My=GraphicsHeight()-20 : MouseYSpeed()
 MoveMouse Mx,My
Endif


Now you can rotate the camera forever ( while mouse is down ) and no need to center the pointer on the screen


fox95871(Posted 2009) [#20]
How would I work that into my code? I'm still quite a beginner. Could you put the whole thing up in a codebox?


Bobysait(Posted 2009) [#21]
It's just a simple code to wrap the mouse when it goes on the border of the screen.

You might want to integrate it by yourself.

Just test
if MouseX() is < BorderSize Then, move the mouse at other border of the screen
Use any value you want for BorderSize, it's just the width of the border you want for the limits of the screen.

Do the same for each borders, and move the mouse according to the wrap.

I'm still quite a beginner. 

For sure, you 'll learn more if you try to do it by yourself :)


fox95871(Posted 2009) [#22]
Ha ha, okay whatever! You got me thinking about it in a different way though. Sending the mouse over to the opposite side of the screen... hmm. To see a "ghost" download this:

(Link removed. Please see post 27.)

The idea is, when the real mouse stops at the right edge, the ghost mouse then goes to the left side to start a new life - or afterlife - where it collects more numbers that the other mouse can't. Those additional numbers then go direct to the camera data, allowing it to exceed the usual 640 limit. In theory. I still need help getting it to actually do that. But I think it'll work then. I've set it all up, but I think at label .c7854 is where I'm having the biggest problem. I can't seem to get the ghost mouse to start it's new life so it's the one using MouseX(). Please help with my ghost problem!


WERDNA(Posted 2009) [#23]
I'll download this later today fox when I get a chance, and see what I
can do.

WERDNA


WERDNA(Posted 2009) [#24]
I just downloaded your file fox, and my anti virus Nod32 quarantined it!

I know you wouldn't purposefully upload a virus, and perhaps my Nod32
simply thinks there's a problem when there's not, but I suggest you
scan it to make sure a virus hasn't snuck in somehow.

It says the reason it was quarantined was because its possibly a
win32/virut.NBP virus.

WERDNA


fox95871(Posted 2009) [#25]
No idea what it's about, but I can't get it til Tuesday, then bring it home, see what's wrong with it, and upload it again Wednesday. I wouldn't intentionally upload a virus, but then again I wouldn't know how to make one!


WERDNA(Posted 2009) [#26]
Its ok!

I'll try downloading again on wednesday.

who knows, maybe my anti-virus just through up a false alarm :)

Good luck with your program fox!

WERDNA


fox95871(Posted 2009) [#27]
Okay, I took out the exe so now it's just the media files and a bb. I don't know much about anitvirus software, but I figured maybe it just didn't like the exe being there. Let me know if it gets quarantined again.

http://www.mediafire.com/?qjme06i9qq80glg


WERDNA(Posted 2009) [#28]
Ok, Downloading now.

EDIT;
It didn't quarantine it this time :)
My guess would be that my anti-virus was just being fussy.

I'll see what I can do with it!

WERDNA


WERDNA(Posted 2009) [#29]
Fixed your code fox!

Change the following piece of code from this,




To this



Its not perfect mind you, since the mousespeed is always the same
once you hit the edge of the screen, but this should be easy to fix :)

Its funny that it took so long, when all it really needed was 2 lines of
code. I thought this was a complex problem, and I think most of the
others who looked at your code thought so to. So we spent our time
thinking up complex ways to fix this using ghost mice and several
other methods, and all it took were 2 little lines of code :D

Just goes to show you, the easiest solution, is often times the best one.

Have fun, and good luck!

WERDNA


fox95871(Posted 2009) [#30]
Looking forward to trying it as always! Thanks Werdna. Just let me know if you ever need any art for your game so I can return the favor.


skidracer(Posted 2009) [#31]
here's my feeble attempt, seems to work nice in windowed and fullscreen

screenwidth=640
screenheight=480

Graphics screenwidth,screenheight
SetBuffer BackBuffer()

Global gridx
Global gridxspeed#

MoveMouse screenwidth/2,screenheight/2
ShowPointer 

While Not KeyHit(1)	; escape quits
	
	xf#=(MouseX()-screenwidth*0.5)/screenwidth
	
	xf=xf*xf*xf*20 ; xf is distance of mouse from center of screen
	
	gridxspeed=0.80*gridxspeed+xf ; speed has drag of 80% to slow it down

	gridx=gridx+gridxspeed
	
	Cls
	
	x=(gridx And 31)-32

	While x<screenwidth
		Rect x,0,2,screenheight,False
		x=x+32
	Wend	

VWait 	
	Flip
Wend




WERDNA(Posted 2009) [#32]
Hey thanks fox!

I really appreciate the offer :D

I had no idea you were an artist.
What kind of artwork do you do?

@skidracer Just tried out your code. I think its pretty cool!

WERDNA


fox95871(Posted 2009) [#33]
Oh nothing, just stuff like... this!

http://www.youtube.com/watch?v=wef2nch4M5k

I usually can't contribute much cause I'm so new to programming, that's why I always offer my art instead for all the great help.


skidracer(Posted 2009) [#34]
@skidracer Just tried out your code. I think its pretty cool!


Thanks WERDNA!

I think for vertical y calculation, mousey should translate directly to camera pitch maybe with a bit of smoothing. I think tracking moving objects in 3D would be kind of cool with this combination.


WERDNA(Posted 2009) [#35]
Oiks!

Thats impressive stuff fox!

Love the clouds :)
You haven't played Myst by any chance have you?

This looks kind of like something you would see there, but a whole lot
better.(And Myst is well known for the impressive visuals)


I think tracking moving objects in 3D would be kind of cool with this combination.


Indeed skidracer! I think it would be very cool.

Once I have a bit of free time, I think I'll do some camera experiments
of my own.

WERDNA


A51M15X(Posted 2009) [#36]
just stick this in your loop

MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

and put hidepointer() at the start of your program.