|
3 registered members (AndrewAMD, Grant, valino),
3,361
guests, and 13
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
[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
OP
Expert
|
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:
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.
|
|
|
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
krial057
Member
|
Member
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.
|
|
|
|