Raised This Month: $51 Target: $400
 12% 

Solved Line僕ine intersection


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-04-2019 , 11:30   Re: Line僕ine intersection
Reply With Quote #11

Quote:
Originally Posted by Natsheh View Post
I think you got a point or I should do floatround?
Well, simply rounding the values will give you a tolerance of ア0.5 units. Doing it with the arbitrary tolerance allows you to make it more or less sensitive than that.
__________________
fysiks is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-05-2019 , 09:13   Re: Line僕ine intersection
Reply With Quote #12

I don't exactly need this way, what I need is detect the touch between two env_beam entities, I thought intersect was what I needed but it seems a lot complex.


Anyway, it only output true now.


Code:
public task_beam()
{
	new Float:b1_start_pos[3], Float:b1_end_pos[3];
	new Float:b2_start_pos[3], Float:b2_end_pos[3];

	Beam_GetStartPos(g_beam1, b1_start_pos);
	Beam_GetEndPos(g_beam1, b1_end_pos);

	Beam_GetStartPos(g_beam2, b2_start_pos);
	Beam_GetEndPos(g_beam2, b2_end_pos);

	new ret = DoesVectorsIntersect(b1_start_pos, b1_end_pos, b2_start_pos, b2_end_pos)
	if (ret == INTERSECT_3D)
		client_print(0, print_center, "intersect = TRUE");
	else
		client_print(0, print_center, "intersect = FALSE");

	server_print("A, init{%f, %f, %f}, end{%f, %f, %f}", b1_start_pos[0], b1_start_pos[1], b1_start_pos[2], b1_end_pos[0], b1_end_pos[1], b1_end_pos[2])
	server_print("B, init{%f, %f, %f}, end{%f, %f, %f}", b2_start_pos[0], b2_start_pos[1], b2_start_pos[2], b2_end_pos[0], b2_end_pos[1], b2_end_pos[2])
	server_print("Return value, %d", ret)
}

DoesVectorsIntersect(const Float:fV1Init[3], const Float:fV1Final[3], const Float:fV2Init[3], const Float:fV2Final[3], Float:tolerance=1.0, Float:fPoint[3]={0.0, 0.0, 0.0})
{
    new Float:fFactorV1[3], Float:fFactorV2[3], g_return;
    
    for(new Float:X, Float:YV1, Float:YV2, i; i < 3; i++)
    {
          fFactorV1[i] = (fV1Final[DIMENSIONS[i][0]] - fV1Init[DIMENSIONS[i][0]]) / (fV1Final[DIMENSIONS[i][1]] - fV1Init[DIMENSIONS[i][1]]);
          fFactorV2[i] = (fV2Final[DIMENSIONS[i][0]] - fV2Init[DIMENSIONS[i][0]]) / (fV2Final[DIMENSIONS[i][1]] - fV2Init[DIMENSIONS[i][1]]);
          
          X = ((fV2Final[DIMENSIONS[i][0]] - fV1Final[DIMENSIONS[i][0]]) + (fFactorV2[i] * fV2Final[DIMENSIONS[i][1]]) - (fFactorV1[i] * fV1Final[DIMENSIONS[i][1]])) / (fFactorV2[i] - fFactorV1[i]);
          YV1 = (fFactorV1[i] * (fV1Final[DIMENSIONS[i][1]] - X) + fV1Final[DIMENSIONS[i][0]]);
          YV2 = (fFactorV2[i] * (fV2Final[DIMENSIONS[i][1]] - X) + fV2Final[DIMENSIONS[i][0]]);
          if( YV1 == YV2 || ((YV1 - tolerance) <= YV2 <= (YV1 + tolerance)) || ((YV2 - tolerance) <= YV1 <= (YV2 + tolerance)) )
           {
                   fPoint[DIMENSIONS[i][1]] = X;
                   switch( i )
                   {
                          case 0: g_return |= INTERSECT_YX;
                          case 2: g_return |= INTERSECT_XZ;
                          case 1: g_return |= INTERSECT_ZY;
                   }
           }

           
    }
    return g_return;
}
debug:
Code:
A, init{-450.867889, 2570.177246, 164.031250}, end{-92.027336, 2574.887207, 164.031250
B, init{-92.523963, 2483.333984, 164.031250}, end{-449.984649, 2485.209960, 164.031250
Return value, 7
__________________









Last edited by CrazY.; 07-05-2019 at 09:21.
CrazY. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-05-2019 , 10:31   Re: Line僕ine intersection
Reply With Quote #13

This should return either INTERSECT_XZ or INTERSECT_ZY seems there is a wrong order in calculation.

This is strange I'll do some testing and come with feedback but what you suggested you can't check if env_beam hits with tracelines or entity collisions.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-05-2019 at 10:45.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
anderpp
Junior Member
Join Date: Feb 2018
Old 07-05-2019 , 15:57   Re: Line僕ine intersection
Reply With Quote #14

yeah ;d


I explain to you, MP. Solved.
anderpp is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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