Hello,

I am trying to work on some simple object placement code for an editor, and all seems well so far, except for a weird bug causing a quick small jumping bug, where when you click on the arrow attached to the cube so you can click / hold the mouse left button down and drag, you can move the object, but depending on where you click on the arrow at, you get a up / down jumping of the object / to mouse coords:

*EDIT* *NOTE* OK, got the jumping gone, and it works really smooth and fasssst now. But only one problem now, how do I keep the object from flying off screen out into space and / or maybe slow down the moving of the mouse, so as to make the object placement more precise. I am posting the changes to the code below for you to check out, please tell me your ideas, suggestions, and any examples on how to make it better you have.

Thanks

Please see the following code:

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

ENTITY* box;
ENTITY* z_arrow;

// Here is the *NEW and IMPROVED* Function...
function ArrowEvent()
{
	VECTOR temp2;
	var startx;
	var starty;
	var changey;
	
	mouse_calm = 10;
	mouse_time = 16;
	
	if(event_type == EVENT_CLICK)
	{  	
	  startx = mouse_pos.x;
	  starty = mouse_pos.y;
	  
       while(mouse_left == 1) 
		{
					
		if (mouse_pos.y >= starty)
		  {
		  	changey = mouse_pos.y - starty;
		  	if (changey <= 1000)
		  	  {
		  	  	me.z -= changey / 2;
		  	        box.z = me.z - ((box.max_z - box.min_z)/2);
		          }
		     if (changey > 1000)
		       {
		       	me.z -= changey / 2;
		       	box.z = me.z - ((box.max_z - box.min_z)/2);
		       }
		  }
		
		if (mouse_pos.y <= starty)
		  {
		  	changey = starty - mouse_pos.y;
		  	if (changey <= 1000)
		  	  {
		  	     me.z += changey / 2;
		  	     box.z = me.z - ((box.max_z - box.min_z)/2);
		          }
		     if (changey > 1000)
		       {
		       	me.z += changey / 2;
		       	box.z = me.z - ((box.max_z - box.min_z)/2);
		       }
		  }  
		wait(1);
		}
	}
}

action Arrow()
{
	z_arrow= me;
	my.emask = ENABLE_CLICK;
        my.event = ArrowEvent;
}

void main()
{
	mouse_mode = 1;
	level_load(""); 
	ent_createlayer("skycube+6.bmp",SKY|CUBE|SHOW,1);
	mouse_range = 2000;  	
	vec_set(camera.x,vector(-160,-570,30));
	camera.pan = 31;  
	box = ent_create("box.mdl", vector(270,-350,0),NULL);
	z_arrow = ent_create("le_arrow_blue.mdl",vector(0,0,0),Arrow);
	z_arrow.scale_x = 6;
	z_arrow.scale_y = 6;
	z_arrow.scale_z = 6;
	vec_set(z_arrow.x,vector(box.x,box.y,(box.max_z - box.min_z)/2));
	
	while(1)
	{
		mouse_pos.x = mouse_cursor.x;    
		mouse_pos.y = mouse_cursor.y;
		mouse_pos.z = 30;
		wait(1);
	}
}



Thanks for helping me figure out I'm sure either a logic error, or an error in 3DGS, or in my code.

Thanks again!

StOrM

Last edited by StOrM; 02/02/10 20:49.

PKE Pain Is Reality! http://www.pkradio.net/