1 registered members (Akow),
1,403
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
mouse coordinates
#277069
07/07/09 15:46
07/07/09 15:46
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
The question is: how can I make the cursor appear in the center of the screen after loading the level, so that its new central coordinates become the initial position of the mouse? And how can I make limits for the cursor movement on the screen? Maybe I've explained my problem a bit confusingly, so a would mention the Counter-Strike game to clarify it: When I launch the game I can move cursor anywhere I want... when I start a new level my cursor stands on its place if I don't move it with my mouse.... But when the level is loaded the cursor goes to its new position in the center of the window, and when I move the mouse the cursor starts its movement from its new location.... Thank you in advance.
Last edited by BastovBros; 07/07/09 15:47.
a generator of dull questions
|
|
|
Re: mouse coordinates
[Re: Espér]
#277072
07/07/09 16:13
07/07/09 16:13
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
Thanks, emmm... almost, but how to make the cursor movable then? it's placed in the 0,0,0 position and stands there all the time...
Last edited by BastovBros; 07/07/09 16:13.
a generator of dull questions
|
|
|
Re: mouse coordinates
[Re: BastovBros]
#277074
07/07/09 16:20
07/07/09 16:20
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
Expert
|
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
if you call it in a while loop, this is not working ^^ my idea:
var setcursor = 1;
...
while(1)
{
if(setcursor == 1)
{
vec_set(mouse_cursor, vector(0,0,0));
vec_set(mouse_pos, mouse_cursor);
setcursor = 0;
}
else
{
vec_set(mouse_pos, mouse_cursor);
}
wait(1);
}
(not tested) just set setcursor to 1 for centering the mouse.
Last edited by Espér; 07/07/09 16:21.
|
|
|
Re: mouse coordinates
[Re: VeT]
#277089
07/07/09 18:00
07/07/09 18:00
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
>to Vet lol, you should have written the solution to your question so that I figure out the solution to mine. Maybe I would not create my thread then... Hu-Gu, Brat!!.... sorry for my Cyrillic accent >to Espér Thx for a second try Hope it's gonna help....
Last edited by BastovBros; 07/07/09 18:03.
a generator of dull questions
|
|
|
Re: mouse coordinates
[Re: BastovBros]
#277344
07/08/09 21:25
07/08/09 21:25
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
another question related to mouse movement: I would like to trap my mouse pointer in the center of the screen, but in a circle field. I've found a code in one AUM and it works fine: // trap the mouse in an area that has 200x100 pixels and is located in the center of the screen var area_x = 200; var area_y = 100; BMAP* pointer_tga = "pointer.tga"; function mouse_startup() { VECTOR temp1_pos, temp2_pos; mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); temp1_pos.x = (screen_size.x - area_x) / 2; temp2_pos.x = (screen_size.x + area_x) / 2; mouse_pos.x = clamp(mouse_pos.x, temp1_pos.x, temp2_pos.x); temp1_pos.y = (screen_size.y - area_y) / 2; temp2_pos.y = (screen_size.y + area_y) / 2; mouse_pos.y = clamp(mouse_pos.y, temp1_pos.y, temp2_pos.y); wait(1); } }
though it keeps the mouse in a rectangular field..... Any idea to keep the mouse in a circle field? I have been trying to write a code myself, but with no successful result Thanks in advance.
a generator of dull questions
|
|
|
Re: mouse coordinates
[Re: BastovBros]
#277347
07/08/09 21:32
07/08/09 21:32
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
//Hu-Gu, Brat!!.... sorry for my Cyrillic accent No problems, as you see, i'm from Ukraine too //Any idea to keep the mouse in a circle field? First idea - is to calculate distance between center point (center of the circle) and maximum cursor distance (point on the radius of the circle)
|
|
|
Re: mouse coordinates
[Re: BastovBros]
#277354
07/08/09 22:22
07/08/09 22:22
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
replace:
var area_x = 200;
var area_y = 100;
[...]
VECTOR temp1_pos, temp2_pos;
[...]
vec_set(mouse_pos, mouse_cursor);
temp1_pos.x = (screen_size.x - area_x) / 2;
temp2_pos.x = (screen_size.x + area_x) / 2;
mouse_pos.x = clamp(mouse_pos.x, temp1_pos.x, temp2_pos.x);
temp1_pos.y = (screen_size.y - area_y) / 2;
temp2_pos.y = (screen_size.y + area_y) / 2;
mouse_pos.y = clamp(mouse_pos.y, temp1_pos.y, temp2_pos.y);
by:
var radius = 80; //a circle of radius 100
[...]
VECTOR temp1_pos, temp2_pos;
[...]
vec_set(temp1_pos, mouse_cursor); //set temp1_pos to mouse_cursor coordinates
//set temp2_pos to middle of the screen
temp2_pos.x = screen_size.x/2;
temp2_pos.y = screen_size.y/2;
temp2_pos.z = 0; //don't forget this!! .z wont be at 0 initially, will turn in awkward values at vec_dist)
//mouse is outside circle
if( vec_dist( temp1_pos, temp2_pos ) > radius ) {
//compute new position on the circle
vec_diff(temp1_pos, temp1_pos, temp2_pos); //direction from temp2 to temp1
vec_normalize(temp1_pos, radius); //normalize to the radius
vec_add( temp1_pos, temp2_pos ); //add from screen center
vec_set( mouse_pos, temp1_pos );
}
else {
vec_set( mouse_pos, temp1_pos );
}
Last edited by Joozey; 07/09/09 12:52.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: mouse coordinates
[Re: Joozey]
#277443
07/09/09 10:08
07/09/09 10:08
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
>to Vet I've already had this idea, but my programming skills are to bad to write the code properly... >to Joozey THANKS A LOT!!!! this code is awesome! much simplier than mine (which in addition didn't work at all). I've learned a new function for me - vec_normilize
a generator of dull questions
|
|
|
|