Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (EternallyCurious, AndrewAMD, TipmyPip, Quad), 902 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with vector math #462855
11/01/16 14:21
11/01/16 14:21
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline 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 #1

Here some pictures (in video you can see that it works from any camera angle/positions):
Quote:



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.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Help with vector math [Re: 3run] #462856
11/01/16 15:19
11/01/16 15:19
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I'd just c_trace for the first hit, then use the resulting hit distance as the factor for the mouse pos calculation:

hitDistance = c_trace... // calculate once on first click
...
vec_set(temp,mouse_dir3d); // dir, not pos!
vec_scale(temp,hitDistance);
vec_add(temp,camera.x);
=> move to temp


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Help with vector math [Re: Superku] #462858
11/01/16 15:29
11/01/16 15:29
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hey, Superku! Thank you, but this won't work sice camera will move around, thus the temp positon will move with it... If I'll grab the door and move closer to it, temp will go to the othr side of the door. Any ideas?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Expert
Kartoffel  Offline
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: Kartoffel] #462862
11/01/16 16:13
11/01/16 16:13
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Just did that, still not what I'm looking for.. Have you guys watched the video? tongue


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Help with vector math [Re: 3run] #462866
11/01/16 17:10
11/01/16 17:10
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
This is something that I want to archive at the end:
PhysicsAndMouseMotionBasedOpenables - PAMMBO (WIP)


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Serious User
Reconnoiter  Offline
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):

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: Reconnoiter] #462873
11/02/16 00:22
11/02/16 00:22
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Well, I did something similar. But it required even more checks... So I had to check for front/back PLUS left/right side as well. Then I got it to work, but I thought that it's too difficult and inaccurate (as a solution), so I decided to ask here. I thought maybe you guys will have some better/easier solutions.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Serious User
Reconnoiter  Offline
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 shocked ).

Code:
//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);
}



Code:
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.
Re: Help with vector math [Re: Reconnoiter] #462877
11/02/16 13:26
11/02/16 13:26
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I'll give it a try! Thank you man! laugh


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

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