Pick weapon by moving the mouse on a panel

Posted By: PadMalcom

Pick weapon by moving the mouse on a panel - 09/13/11 08:44

Hi, topic sounds simpler than it is.

When I click right and hold the mouse pressed a panel opens:


Now, depending on the mouse position, an area on this panel should be selected. Even if the mouse is not on the panel but in the top cone, the left cone, the bottom cone or the right cone.

When I release the right mouse button the appropriate weapon should be selected.

Does anybody know a nice algorithm to map the mouse position to a panel area?

Thanks!

Posted By: bart_the_13th

Re: Pick weapon by moving the mouse on a panel - 09/13/11 10:20

Just calculate the angle from the center of the screen to the mouse position.
Posted By: Slin

Re: Pick weapon by moving the mouse on a panel - 09/13/11 10:29

Alternatively, use two HNFs...
Posted By: PadMalcom

Re: Pick weapon by moving the mouse on a panel - 09/13/11 10:55

2 nice ideas, thanks a lot! laugh
Posted By: Anonymous

Re: Pick weapon by moving the mouse on a panel - 09/13/11 11:35

maybe, but dont hate me if its total bullshit just writting my thoughts, maybe you lay a invisible image over the whole screen and fill them with 4 diffent colors as cones.
Then maybe its possible to detect over which of the colors the mouse is moving?!
Similar to colormap for terrains...but different.
Again, maybe its total crap what i say... laugh
Posted By: PadMalcom

Re: Pick weapon by moving the mouse on a panel - 09/13/11 12:15

The idea is good, but I think the performance is not wink The way you propose needs memory for 4 more images instead of a 2 line vector calculation as proposed by bart. But thank you for thinking laugh
Posted By: MrGuest

Re: Pick weapon by moving the mouse on a panel - 09/13/11 12:26

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

void main(){
	
	wait(1);
	
	mouse_mode = 4;
	
	PANEL* pnl = pan_create("", 1);
	pnl.bmap = bmap_createblack(128, 128, 32);
	bmap_fill(pnl.bmap, COLOR_GREEN, 100);
	pnl.pos_x = 128; pnl.pos_y = 128;
	pnl.center_x = 64; pnl.center_y = 64;
	set(pnl, SHOW);
	
	var x, y, at, dx, dy;
	while(1){
		
		x = mouse_pos.x - 64 - pnl.pos_x;
		y = mouse_pos.y - 64 - pnl.pos_y;
		at = atan2v(x, y);
		
		if(mouse_panel){
			
			//determines the distance
			dx = mouse_pos.x - (pnl.pos_x + 64);
			dy = mouse_pos.y - (pnl.pos_y + 64);
			if(sqrt(dx*dx + dy*dy) <= 64){
				
				//determines the angle
				if((at > -135) && (at <= -45)){
					DEBUG_VAR(4, 20);
				}else if((at > -45) && (at <= 45)){
					DEBUG_VAR(3, 20);
				}else if((at > 45) && (at <= 135)){
					DEBUG_VAR(2, 20);
				}else{
					DEBUG_VAR(1, 20);
				}
				
			}
		}
		wait(1);
	}
}


© 2024 lite-C Forums