Author Topic: LUT: Slope between 2 points  (Read 3787 times)

0 Members and 1 Guest are viewing this topic.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
LUT: Slope between 2 points
« 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.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: LUT: Slope between 2 points
« Reply #1 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.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: LUT: Slope between 2 points
« Reply #2 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

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: LUT: Slope between 2 points
« Reply #3 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.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: LUT: Slope between 2 points
« Reply #4 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.
« Last Edit: December 20, 2011, 08:27:55 pm by Hot_Dog »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: LUT: Slope between 2 points
« Reply #5 on: December 20, 2011, 08:30:35 pm »
So you are looking to see if the player can see the enemy or vica verse?

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: LUT: Slope between 2 points
« Reply #6 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.

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: LUT: Slope between 2 points
« Reply #7 on: December 20, 2011, 09:23:33 pm »
What, finding slope? Doesn't (y2-y1)/(x2-x1) find the slope?
« Last Edit: December 20, 2011, 09:24:13 pm by epic7 »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: LUT: Slope between 2 points
« Reply #8 on: December 20, 2011, 09:46:38 pm »
So just use a line-drawing algorithm with pixel-test instead of pixel-on?
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: LUT: Slope between 2 points
« Reply #9 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.