Jump to content

  • Log In with Google      Sign In   
  • Create Account

umen242

Member Since 03 Aug 2008
Offline Last Active Yesterday, 01:50 AM

Posts I've Made

In Topic: How to detect diamond shape collision detection , if object is inside the dia...

21 September 2016 - 09:53 AM

yes i notice it sometimes above 1 and sometimes below ... 
wow .. it is not consist .. 


In Topic: How to detect diamond shape collision detection , if object is inside the dia...

21 September 2016 - 09:30 AM

Ok i think i got this working with your fix 
Thanks allot 


Also Question while searching about the subject how about checking if point inside triangle using one of those methods here ?
http://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle


In Topic: How to detect diamond shape collision detection , if object is inside the dia...

21 September 2016 - 09:16 AM

sorry i misunderstand this wired python syntax ...
so how should this:

return 1 - xfrac + yfrac <= 1

look like on simple C code ?


In Topic: How to detect diamond shape collision detection , if object is inside the dia...

21 September 2016 - 12:14 AM

Im trying to implement it now , say didn't you meant  Inside calculation for rectangles 2 and 3 ?
as it substract from 1 first ?

 
i have test case im working on on some cases it works in some it doesn't see what i mean : 

based on your code example i did : 
 

bool game::insideOfTri(float left, float top, float right,
float bottom, float dotx, float doty, bool type)
{
if (left < right && bottom < top)
{
float xsize = right - left;
float ysize = top - bottom;


float dot_lcl_x = dotx - left;
float dot_lcl_y = doty - bottom;
float dot_lcl_x_f = dot_lcl_x / xsize;
float dot_lcl_y_f = dot_lcl_y / ysize;
float result = 0;
if (type)
{
result = 1 - (dot_lcl_x_f + dot_lcl_y_f);
}
else
{
result = (dot_lcl_x_f + dot_lcl_y_f);
}
if (result >= 1)
{
return true;
}
return false;
}

using this function :

where parameters are : 

left : 160.0

right :201.0

top:330.5

bottom:310.0

dotx:160.0

doty:315.0

 

the result of dot_lcl_x is : 0 which is true

the result of dot_lcl_y is 5 which is true 

and the expected return from the function is true .
but if i continue the calculation in the function 

dot_lcl_x_f is 0

and 

dot_lcl_y_f is 0.24

so no matter which calculations 

if it :
result = 1 - (dot_lcl_x_f + dot_lcl_y_f);

or 

result = (dot_lcl_x_f + dot_lcl_y_f);

will give false . which is wrong 

so when i calculating rectangle number 2 it gives me false 
when i calculating rectangle number 1 the calculation is right and it gives me true .
so as you can see the problem is that dotx:160.0 - left : 160.0 = 0 , so it never be above 1 
 

detbluedot.png

In Topic: How to detect diamond shape collision detection , if object is inside the dia...

20 September 2016 - 01:19 PM

@Alberth
Thanks allot ! yo uare helping me allot and i feel i getting there . 
Few Things i dont understand .

1. what do you mean :  

pick the rectangle that matches w.r.t to diagonal line

 

what is : "w.r.t" ? 
 

2. as i have the points calculated , do i need to set the and calculate the point inside the triangle part of the rectangle ; from world space to local space 
what i mean is see the picture  :
 

calcdot.png

There is local space of the blue dot , do i need to convert it to local space so it will be relative to its one of the 4 rectangles? 

so each time it will be calculated from the rectangles X.Y coordinates ? 
and not from the world space ( screen ) coordinates ?

 

im alittle bit confuse here .. what is the proper way to calculate it . 


PARTNERS