Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[SOLVED]3D Cursor is not moving on Y #397769
03/23/12 13:24
03/23/12 13:24
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
hi there..

i want to move a 3D Cube on X/Y position of the Mouse. For this, i use this code:
Click to reveal..
Code:
var tile_size                      =  50;
var tile_z_offset                  =   0;
var editControlMouseWheelSpeed     =   0.8;  //Empfindlichkeit/Speed für Mausraddrehung
var editControlScrollSpeedRMB      =  50;    //Speed für rechtsklick scroll
var editControlScrollSpeedBorder   =  25;    //Speed für randscroll
var editControlScrollMarginPercent =   0.15; // %
var check_mouseclick               =   0;

void clamp_all(ENTITY* obj)
{
	tile_position.x = integer(tile_position.x);
	tile_position.y = integer(tile_position.y);
	tile_position.z = integer(tile_position.z);
	tile_position.x = clamp(tile_position.x, -200,200);
	tile_position.y = clamp(tile_position.y, -200,200);
	tile_position.z = clamp(tile_position.z,    0,200);
	
	obj.x = tile_position.x * tile_size;
	obj.y = tile_position.y * tile_size;
	obj.z = tile_position.z * tile_size;
}

void draw_cursor(ENTITY* obj)
{
	// some mouse buttons are pressed
	if (mouse_right || mouse_left)
	{
		// right button is pressed
		if (mouse_right)
		{
			// adjust editor view for direct scrolling
			mouse_mode = 4;
			camera->x -= mouse_force.x * editControlScrollSpeedRMB * time_step;
			camera->y -= mouse_force.y * editControlScrollSpeedRMB * time_step;					
		}
	}
	else
	{
		// do 3d cursor placement with the mouse
		// CB: the following code calculates the tile_position for the mouse cursor
		// get 3d points and direction of line, which pierces the screen at mouse position in camera
		VECTOR v1, v2, dir;
		{
			vec_set(&v1, vector(mouse_pos.x, mouse_pos.y, 0));
			vec_set(&v2, vector(mouse_pos.x, mouse_pos.y, 99999));
			
			vec_for_screen(&v1, camera);
			vec_for_screen(&v2, camera);
			
			vec_diff(&dir, &v2, &v1);
		}
		
		var d = vec_dot(vector(0,1,0), &dir);			
		
		if (abs(d) != 0) // not parallel to plane
		{
			// get intersection point with plane
			
			VECTOR dirPlaneFrom;
			vec_diff(&dirPlaneFrom, &v1, obj.x);					
			
			var n = vec_dot(vector(0,1,0), &dirPlaneFrom);
			
			VECTOR ip;
			vec_set(&ip, &dir);
			vec_scale(&ip, -n / d);
			vec_add(&ip, &v1);
			
			// transform into tile space
			
			tile_position.x = integer((ip.x + tile_size/2) / tile_size);
			tile_position.y = integer((ip.y + tile_size/2) / tile_size);
			tile_position.z = obj->z / tile_size;					
		}
		
		// CB: the following code changes the tile_position.z (height) with the mouse wheel!
		tile_position.z += sign((int)(mickey.z * editControlMouseWheelSpeed * time_step));
		
		check_mouseclick = 0;
	}
	clamp_all(obj);
}



draw_cursor should calculate the tile positions, and clamp_all places the object (there will be more than 1 entity to place.. cause of that it´s a standalone function)

my problem:
X movement works well
Z setting by moving the Mouse Wheel - Works well, too

But the Y Position isn´t changing..

Can someone help me, please? I´ve no clue what to do :'(


Last edited by Espér; 03/23/12 14:24.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: 3D Cursor is not moving on Y [Re: Espér] #397772
03/23/12 14:02
03/23/12 14:02
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Shouldn't the normal of the plane be vector(0,0,1)? It works for me if i change it to (0,0,1) for var d and var n.

Last edited by krial057; 03/23/12 14:03.
Re: 3D Cursor is not moving on Y [Re: krial057] #397774
03/23/12 14:24
03/23/12 14:24
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
WOOOOOOHAAAAYYYY..

Thank you very much ^^
it´s working..
Sry for asking of that little change.. HeelX coded that and he´s in holiday.. but i needed this urgently ^^

thanks again


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1