AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Collision of two line (https://forums.alliedmods.net/showthread.php?t=188184)

dFF 06-23-2012 12:14

Collision of two line
 
1 Attachment(s)
How to check if the red line collison the blue square / is inside of blue square.
Blue square created in player spawn origin.
I have this datas value for red line:
PHP Code:

new Float:fStart// contain the start origin of RED LINE
new Float:fEnd// contain tha end origin of RED LINE

// I tried to calculate when red line is inside of  blue square
new Float:fTest]
fTest] = fStart] * fEnd] / fStart] - fEnd]
fTest] = fStart] * fEnd] / fStart] - fEnd]
fTest] = fStart] * fEnd] / fStart] - fEnd]
// but doesn't wok! 

http://forums.alliedmods.net/attachm...1&d=1340468059

Neeeeeeeeeel.- 06-23-2012 22:14

Re: Collision of two line
 
If you are talking about tracelines... you should read this.

dFF 06-24-2012 05:42

Re: Collision of two line
 
Too bad :(
I found a math calculation http://local.wasp.uwa.edu.au/~pbourk...try/planeline/ , but my knowledge is poor :(.

Exolent[jNr] 06-24-2012 05:49

Re: Collision of two line
 
xs_plane_rayintersect()

dFF 06-25-2012 10:15

Re: Collision of two line
 
Exolent when you have time, can you write an example or tutorial ? Thank you!

Exolent[jNr] 06-25-2012 10:35

Re: Collision of two line
 
The blue box is your plane. You can create the plane variable by using 3 points of that box.

Code:
new Float:plane[4]; xs_plane_3p(plane, box_point1, box_point2, box_point3);

Then you need the start position of the line and the direction it goes.
If all you have is 2 points, then you need to calculate the direction.

Code:
new Float:line_direction[3]; xs_vec_sub(line_point2, line_point1, line_direction);

Finally, apply variables to check if the line intersects the plane.
Code:
new Float:intersection[3]; if( xs_plane_rayintersect(plane, line_point1, line_direction, intersection) ) {     // Line intersects the plane at "intersection" point }

dFF 06-25-2012 16:56

Re: Collision of two line
 
Thank you Exolent ! You are the man :mrgreen:.


All times are GMT -4. The time now is 06:06.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.