|
Help with vector math
#462855
11/01/16 14:21
11/01/16 14:21
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Can any one help me with some vector math? I'm trying to archive mouse detection, like on this video: Door Test #1Here some pictures (in video you can see that it works from any camera angle/positions): In order to move the door, I'm planing to use ROPE hinge, I need start and end positions for it. Start is going to be the hit position of the trace (interacton trace/mouse trace?), but how do I calculate that mouse position in the world? Tried mouse_pos3d, but I couldn't get it to work correctly. Greets! Edit: to make things clear... I do have working example with c_trace, mouse_pos3d and mouse_dir3d, but it's not what I wanted to archive.. What I need is exactly the same thing as on the video (I'm not sure, but probably they did not use any rays/traces), I just can't think of it, how to get position of the mouse in 3d world like that?
Last edited by 3run; 11/01/16 14:56.
|
|
|
Re: Help with vector math
[Re: 3run]
#462860
11/01/16 15:39
11/01/16 15:39
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
you could recalculate the hit distance by using the distance between the camera and the initial click position on the door (you have to rotate this point with the door)
POTATO-MAN saves the day! - Random
|
|
|
Re: Help with vector math
[Re: 3run]
#462869
11/01/16 19:51
11/01/16 19:51
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Hmm dont know if this is accurate enough for you but I would do first something like this and maybe it helps to build upon / as a start (pseudo code):
//do a trace or check mouse_ent
ANGLE angle;
vec_to_angle(angle, vec_diff(NULL, door.x, actor.x));
var tmp = ang(angle.pan);
//front
if (tmp >= -90 && tmp <= 90) {
...=is front...
}
else {
...=is back...
}
//notice that I did it very rough here, you could add more steps between
//use mouse_force.y and possible x for movement (store in vector)
//with some exponential formula if mouse is moved very fast
//rotate that vector when needed if at the back of the door
//use that vector for some physx rotate force function or physx ent rotate (if registered as PH_CHAR)
// or movement function if it is for drawers
Last edited by Reconnoiter; 11/01/16 19:54.
|
|
|
Re: Help with vector math
[Re: 3run]
#462876
11/02/16 11:02
11/02/16 11:02
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
How about each frame get the 3d position of the cursor (its Not by trace, see code below) and vec_to_angle with between cursor point and door. And finally do something like storing mouse_force in a vector vec_rotate it with result out of vec_to_angle (or whatever, I am not so good at that part ).
//Credit to Superku iirc
VECTOR PosCursor_vec;
function SetPosMouseCursor() {//stores result in a global vector called PosCursor_vec
var f;
vec_set(PosCursor_vec, mouse_dir3d);
vec_scale(PosCursor_vec, 10); // depending on the camera height it can be beneficial to scale the dir vector for increased accuracy (because of the limited accuracy of var)
if (PosCursor_vec.z == 0) PosCursor_vec.z = 0.01;
f = -mouse_pos3d.z / PosCursor_vec.z;
vec_scale(PosCursor_vec, f);
vec_add(PosCursor_vec, mouse_pos3d);
}
function .....door.... () {
...
while....
SetPosMouseCursor();
draw_point3d(PosCursor_vec, COLOR_GREEN, 100, 5);
ANGLE angle;
vec_to_angle(angle, vec_diff(NULL, my.x, PosCursor_vec));
var tmp = ang(angle.pan);
if (mouse_left) { //you will probably want to change this part to something more sensical
VECTOR _vforce;
vec_set(_vforce, vec_rotate(vector(mouse_force.y * time_step*20, mouse_force.x * time_step*20, 0), vector(tmp, 0, 0)));
vec_add(_pan, _vforce);
}
pXent_rotate(my, nullvector, vector(_pan.pan, 0, 0));
}
Note place your door at 0 z or similar, otherwise you will have to expand/change the SetPosMouseCursor function a bit.
Last edited by Reconnoiter; 11/02/16 11:04.
|
|
|
|