a question about mouse movement

Posted By: not_me

a question about mouse movement - 08/19/09 04:23

I've got a bit of an odd question...and im not sure if its possible, but here goes. Is it possible to restrict the mouses movement to an axis in space(i.e. mouse can only move along the x,y axis in space) is it possible? or is there a way to place a(xy or xz) grid(possibly a model) in space and have the mouse select points on the grid(s)?

[EDIT]: or maybe track the mouses position on a model of a grid...perhaps..
Posted By: DJBMASTER

Re: a question about mouse movement - 08/19/09 07:30

Code:
mouse_mode = 1 // or 2
while (1) // move it over the screen
{  
mouse_pos.x = mouse_cursor.x;
wait(1);
}


This will lock the mouse to the mouse to the x-axis only.

I just wrote this little snippet which snaps the mouse to a grid. Change the "snap_amount" variable to change the grid size...

Code:
#include <acknex.h>
#include <default.c>

BMAP* arrow = "arrow.pcx";

void main()
{
	
	mouse_map = arrow;
	mouse_mode = 2;
	
	int snap_amount = 25;
	double ux = 0.0;
	double uy = 0.0;
	
	wait(1);
	while (1) // move it over the screen
	{  
		ux = mouse_cursor.x / snap_amount;
		uy = mouse_cursor.y / snap_amount;
		
		mouse_pos.x = (integer(ux)*snap_amount);
		mouse_pos.y = (integer(uy)*snap_amount);
		
		//draw grid
		var i=0; var j=0;
		for(i=0; i<screen_size.x; i+=snap_amount)
		{
			draw_line(vector(i,0,0),vector(255,0,0),100);
			draw_line(vector(i,screen_size.y,0),vector(255,0,0),100);
			draw_line(vector(i,0,0),NULL,100);
		}
		for(j=0; j<screen_size.y; j+=snap_amount)
		{
			draw_line(vector(0,j,0),vector(255,0,0),100);
			draw_line(vector(screen_size.x,j,0),vector(255,0,0),100);
			draw_line(vector(0,j,0),NULL,100);
		}
		wait(1);
	}
}



Snapping to a 3D grid requires a little more thought because you will have to trace from the camera but i think that "mouse_dir3d" will help a lot. I'll have a go and post my results if i can get it to work.

DJB.
Posted By: not_me

Re: a question about mouse movement - 08/26/09 05:33

sry for the late response. i havent been able to login to the forums lately...it was kinda wierd, but thankyou for the snippet. You wouldnt happen to know how to make the grid into a 3d grid would you?

Or perhaps display a grid ingame kinda the way the MED 3d viewport does...
Posted By: not_me

Re: a question about mouse movement - 08/26/09 06:36

*bump* why is it that whenever i place an object in game space it flies upward infinitely? Im making an rts and whenever an object moves off of a plane that i defined as the level it flies upward infinitely...can anyone explain to me how to counter this?
© 2024 lite-C Forums