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 / How do I control my target going aroung a matrix with the mouse?

Author
Message
Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 15th Aug 2006 16:53
I want to be able like I said to control this target around the matrix, I already make it go around the matrix, but on the right and front side when the target goes on the wrong direction. I want it to go like this:

left side to go from front to back ( this one is correct )
back side to go from left to right ( this one is correct )
right side to go from back to front ( incorrect )
front side to go right to left ( incorrect )

this is my code, you do not need extra media.



`set up
sync rate 40
sync on
autocam off
hide mouse

` make matrix
make matrix 1,160,160,30,30

`make target and color it
make object box 1,6,1,6
xrotate object 1,90
color object 1,rgb(10,10,10)

`main program
do
`get mouse position on x for left,back,right and front
posmousex#=mousex()
posmousexleft#=posmousex#
posmousexback#=posmousex#
posmousexright#=posmousex#
posmousexfront#=posmousex#

`print information on the screen
set cursor 50,250 : print "left side --->"
set cursor 510,250 : print "<--- right side"
set cursor 290,150 : print "back side"
set cursor 290,400 : print "front side"
set cursor 0,0 : print "mouse on x... ",posmousex#

`mouse bounds on x on the left side 0 - 160
if posmousexleft#<1 then posmousexleft#=1
if posmousexleft#>160 then posmousexleft#=160

`mouse bounderies on x on the back side 160 - 320
if posmousexback#<161 then posmousexback#=161
if posmousexback#>320 then posmousexback#=320

`mouse bounds on x on the right side 321-480
if posmousexright#<321 then posmousexright#=321
if posmousexright#>480 then posmousexright#=480

`mouse bounds on x on the front side 480-639
if posmousexfront#<480 then posmousexfront#=480
if posmousexfront#>639 then posmousexfront#=639

` sending if to corresponding positioning left,back,right and front
if posmousexleft#>1 and posmousexleft#<160 then gosub movingmouseonleft
if posmousexback#>161 and posmousexback#<320 then gosub movingmouseonback
if posmousexright#>321 and posmousexright#<480 then gosub movingmouseonright
if posmousexfront#>480 and posmousexfront#<639 then gosub movingmouseonfront

` positioning camera
position camera 80,100,-80
point camera 80,1,80

sync

loop

movingmouseonleft:

`positioning mouse on the left of the matrix 1-160
position object 1,1,2,posmousexleft#

return

movingmouseonback:

`positioning mouse on the back of the matrix 161-320
position object 1,posmousexback#-160,2,160

return

movingmouseonright:

`positioning mouse on the right or the matrix 321-480
position object 1,160,2,posmousexright#-320

return

movingmouseonfront:

`positioning mouse on the front of the matrix 480-639
position object 1,posmousexfront#-480,2,1

return


Thank you for your time.
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 15th Aug 2006 18:05
Please note that displaying code boxes are typed as followed:

[[/b]code]
code
[[b]
/code]

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Aug 2006 22:39
Hello Programdor,

I can tell from your code that you understand you have to set limits on how far you want the target to move on any given plane on the side of the matrix. But I think you may have made the execution a little too complicated and therefore have gotten a little confused.

Since your target isn't jumping up on the y axis, you only really have to worry about two values: x and z.

When the target is on the bottom or the top, then target is between the x limits of the matrix. At the top, the target is always at the upper z value. At the bottom it is always at the lower z value.
In all cases, y never changes.

When the target is on the left or the right, then target is between
the z limits of the matrix. At the right, the target is always the upper x value, at the left, the target is always the lower x value. In all cases y never changes.

Following, is an example of what I'm talking about. I'm able to contain all the limits and movement in one loop by only changing x and z. I use two directions on the mouse mousex() and mousey(), just for a little more direct control, but with a slight adjustment to the limits, one could just use mousex() where moving the mouse left causes the target to circle the grid clockwise, and moving it right causes it to circle the grid counter clockwise.



Enjoy your day.
Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 22nd Aug 2006 00:01
Thanks for the code Latch, I have being playing with the limits for a few days now and I can not make go around the matrix, move the mouse to right and the target goes clockwise, move the mouse to the left and the target goes counter clockwise ( I think ), I added some stuff because I wanted to move on the y coordinates. Can you help me or somebody else. Please. Thanks

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Aug 2006 04:42
Hi,

You should've played around with it some more - there's some real satisfaction when you come up with a solution!

But I'll let you in on the secret! Originally, the code I gave as an example was based on moving the mouse left and right to increase or decrease the mouse x value. This value was added to x position so the target would move left if mousex() was negative - right if mousex() was positive. We weren't circling the whole grid so the top of the matrix could be the same as the bottom.

When we want the target to circle the grid with only one mouse direction, we have to make the top opposite of the bottom. So if we moved the mouse left on the bottom, it would move the target left on the bottom, but at the top, we want the target to head right when we move the mouse left.

For the z direction, we want to get rid of the mousey() and just use mousex(). The same logic applies.

If we are still moving left with the mouse, and the target is on the left, we want the target to go up (positive z) so we have to subtract mousex() from z (two negatives make a positive!) - and whatever we do on the left side, we have to do the opposite on the right side.

If you want to switch the clockwise directions (right for clockwise, left for couter clockwise), everything is opposite.

Now you are armed with enough info to solve the routine. But if you want to peek, here's the code:



Enjoy your day.
Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 22nd Aug 2006 06:49
This is exactly what I wanted to do. I will make sure to give you credit in my game. Thanks.

Login to post a reply

Server time is: 2025-05-25 22:33:27
Your offset time is: 2025-05-25 22:33:27