gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfxgfx
 
Members, please note that our guidelines are located here.
 
gfx gfx
gfx
484586 Posts in 28410 Topics by 2464 Members - Latest Member: austinrobert July 10, 2020, 06:25:33 PM
*
gfx* Home | Help | Calendar | Login | Register | gfx
gfx
The Gaming Universe  |  The Archives  |  Archived Projects  |  Open Zelda  |  OZ Help (Moderator: red_team316)  |  Check 5 points in a line
gfx
gfxgfx
 

Author Topic: Check 5 points in a line  (Read 1028 times)

Offline KingOfHumans

  • Messiah
  • ******
  • Posts: 17,866
    • View Profile
Check 5 points in a line
« on: April 25, 2011, 03:15:45 PM »
My MaskCheck function was working decent until I noticed that I slid around corners for 8x8 sprites. So when trying to push a book shelf that was against a wall, I kept sliding past. This is because I was only checking three coordinates, but I need to actually check five for smooth sliding. For some reason, none of my formulas worked for 5.

Now here is a visual of what it will look like.

North/South
. . . . .

East/West
.
.
.
.
.

Northeast
. . .
    .
    .

Southeast
    .
    .
. . .

Sure you can figure out what northwest and southwest will look like. Here's my current code.

Code: [Select]
//----------------------------------------
// Name: MaskCheck()
//----------------------------------------
public MaskCheck(x,y,width,height,angle)
{
new dist = max(width,height);
new ang = floatround(floatdiv(float(angle), 45.00)) * 45;
new chk[5] = {0,23,45,68,90};
new point[5];
new string[20];
/*for(new n; n < 3; n++)
{
new float: fx = float(dist) * Cos(ang - 45 + (45 * n));
new float: fy = float(dist) * Sin(ang - 45 + (45 * n));
point[n] = DCheckMask(clamp(floatround((x + (width / 2)) - fx),x + (width / 5),x + width - (width / 5)),clamp(floatround((y + (height / 2)) - fy),y + (height / 5),y + height - (height / 5)),true);
}
return min(min(point[0], point[1]), point[2]);
*/
for(new n; n < 5; n++)
{
new fx = floatround(float(dist) * Cos((ang - 45 + chk[n])));
new fy = floatround(float(dist) * Sin((ang - 45 + chk[n])));
point[n] = DCheckMask(clamp((x + (width / 2)) - fx,x + (width / 5),x + width - (width / 5)),clamp((y + (height / 2)) - fy,y + (height / 5),y + height - (height / 5)),true);
}
return min(min(min(point[0], point[1]), min(point[2], point[3])),point[4]);
}

DCheckMask is just CheckMask with a PutSprite line. This draws a dot for where it 's checking. For some reason it only shows 3 dots.

Offline Khatuni

  • Executive
  • ***
  • Posts: 1,007
    • View Profile
Check 5 points in a line
« Reply #1 on: April 26, 2011, 10:08:08 AM »
The code looks ok, though I don't see why you're treating fx/fy differently in the 5 coordinates method.
I'd say, output the coordinates of each point and see if they are correct.

Offline KingOfHumans

  • Messiah
  • ******
  • Posts: 17,866
    • View Profile
Re: Check 5 points in a line
« Reply #2 on: April 26, 2011, 05:03:10 PM »
What do you mean differently? The two formulas are the same. The only difference is in the second formula it would require to round the 2nd and 4th value, so I just used an array instead.
I'll try outputting the mask data, because the fx/fy outputted 5 variables but rounded(circle wise). That's why I used clamp after all so the points can't go past a certain point.

edit:
Mask
123
133
Mask
123
133
Mask
123
128
Mask
123
123
Mask
123
123

This is for east.
It's outputting 5 points but looks like the  height is wrong for some reason.
Maybe fx/fy won't work in this case.
« Last Edit: April 26, 2011, 07:32:20 PM by KingOfHumans »

Offline KingOfHumans

  • Messiah
  • ******
  • Posts: 17,866
    • View Profile
Re: Check 5 points in a line
« Reply #3 on: April 28, 2011, 05:22:54 PM »
Got it working for north, east, south, and west by adjusting the two angle checks.
Code: [Select]
//----------------------------------------
// Name: MaskCheck()
//----------------------------------------
public MaskCheck(x,y,width,height,angle)
{
new dist = max(width,height);
new ang = floatround(floatdiv(float(angle), 45.00)) * 45;
new chk[5] = {0,35,45,55,90};
new point[5];
for(new n; n < 5; n++)
{
new fx = floatround(float(dist) * Cos(((ang - 45 + chk[n])%360)));
new fy = floatround(float(dist) * Sin((ang - 45 + chk[n])%360));
point[n] = DCheckMask(clamp((x + (width / 2)) - fx,x + (width / 5),x + width - (width / 5)),clamp((y + (height / 2)) - fy,y + (height / 5),y + height - (height / 5)),true);
}
return min(min(min(point[0], point[1]), min(point[2], point[3])),point[4]);
}
The second and third code might need a little adjusting based on the size, but it's a start.
I can't get corners to work with this method, so will probably need to use a different formula that checks two angles, and checks 3 points and 2 points.

The Gaming Universe  |  The Archives  |  Archived Projects  |  Open Zelda  |  OZ Help (Moderator: red_team316)  |  Check 5 points in a line
 

gfxgfx
gfx
SMF 2.0.17 | SMF © 2019, Simple Machines Page created in 0.152 seconds with 22 queries.
Helios Multi © Bloc
gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!