Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Hot_Dog on December 20, 2011, 06:50:17 pm

Title: LUT: Slope between 2 points
Post by: Hot_Dog on December 20, 2011, 06:50:17 pm
For Elimination, let's say I have a playerX and a playerY, and an EnemyX and an EnemyY.  I'm wanting to do something similar to a Bresenham line, but to do that I need to know the slope between the two locations, of the player and the enemy.  I'm assuming a LUT is my best bet, where the LUT will have values for rise and run.  That is, go up/down this many times, and left/right this many times. 

How do I go about implementing this?  What I need to know is given (PlayerX, PlayerY) and (EnemyX, EnemyY), what do I need to do to find the correct value in the LUT?  I want my LUT to have no more than 64 sets of rise over run.
Title: Re: LUT: Slope between 2 points
Post by: thepenguin77 on December 20, 2011, 07:30:05 pm
I'm not sure I exactly understand what exactly you are trying to do, but why couldn't you just divide your Y's by your X's. That's what you do in math and division is relatively quick. If you need decimal places, you can just tack on an extra byte to your Y values and your final result will have 1 extra byte of decimals.
Title: Re: LUT: Slope between 2 points
Post by: Hot_Dog on December 20, 2011, 07:36:15 pm
I'm not sure I exactly understand what exactly you are trying to do, but why couldn't you just divide your Y's by your X's. That's what you do in math and division is relatively quick. If you need decimal places, you can just tack on an extra byte to your Y values and your final result will have 1 extra byte of decimals.

It is relatively quick, but I was hoping for something slightly faster.  Still, I guess I don't have to be 100% optimized ;D
Title: Re: LUT: Slope between 2 points
Post by: Runer112 on December 20, 2011, 08:22:47 pm
What exactly do you need the slope for? Because line drawing algorithms, for instance, don't actually need a numerical slope value. They just use dy and dx as-is without having to divide one by the other.
Title: Re: LUT: Slope between 2 points
Post by: Hot_Dog on December 20, 2011, 08:27:14 pm
What exactly do you need the slope for? Because line drawing algorithms, for instance, don't actually need a numerical slope value. They just use dy and dx as-is without having to divide one by the other.

I'm not really dividing dy and dx, I need to find dy and dx.  (y2-y1) / (x2-x1) The slope is used to start at the enemy, and travel little by little to the player to see if there's a wall in the way.
Title: Re: LUT: Slope between 2 points
Post by: Builderboy on December 20, 2011, 08:30:35 pm
So you are looking to see if the player can see the enemy or vica verse?
Title: Re: LUT: Slope between 2 points
Post by: Hot_Dog on December 20, 2011, 08:36:40 pm
So you are looking to see if the player can see the enemy or vica verse?

Yes, or more importantly, if an enemy can fire a shot without it being blocked by a wall. 

I apologize for not being too clear on this topic.  Let's say that the slope between the enemy and the player is 2/1.  The enemy is at (100, 100), and the player is at (103, 106).  So the calculator checks (101, 102).  Is there a wall?  No.  Check (102, 104).  Is there a wall?  YES!  So the enemy cannot harm the player.
Title: Re: LUT: Slope between 2 points
Post by: epic7 on December 20, 2011, 09:23:33 pm
What, finding slope? Doesn't (y2-y1)/(x2-x1) find the slope?
Title: Re: LUT: Slope between 2 points
Post by: calc84maniac on December 20, 2011, 09:46:38 pm
So just use a line-drawing algorithm with pixel-test instead of pixel-on?
Title: Re: LUT: Slope between 2 points
Post by: Hot_Dog on December 20, 2011, 11:18:59 pm
So just use a line-drawing algorithm with pixel-test instead of pixel-on?

The game engine is not built that way.  I'm really sorry that I have been confusing.  I would start over and explain from the beginning, except that I like thepenguin77's suggestion for division, so I'm going to use that.