Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 May, 2013, 10:28:41 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: LUT: Slope between 2 points -  (Read 548 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Hot_Dog
If you can't find a cat, look for its tail.
Support Staff
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 09 May, 2013, 19:22:43
Date Registered: 28 December, 2009, 18:47:54
Location: Midland, Washington
Posts: 2940


Topic starter
Total Post Ratings: +428

View Profile
« on: 21 December, 2011, 01:50:17 »
0

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.
Logged

There are people who can speak two languages, and they are called bilingual.  There are people who speak three languages and are therefore trilingual.  Then there are people who speak one language, and these people are called Americans.

thepenguin77
z80 Assembly Master
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 21:48:33
Date Registered: 14 December, 2009, 04:21:52
Location: Purdue
Posts: 1483


Total Post Ratings: +778

View Profile
« Reply #1 on: 21 December, 2011, 02:30:05 »
0

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.
Logged

zStart v1.3.011 4-29-2013  zStart fully works on 83+BE's (except custom font)
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
Hot_Dog
If you can't find a cat, look for its tail.
Support Staff
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 09 May, 2013, 19:22:43
Date Registered: 28 December, 2009, 18:47:54
Location: Midland, Washington
Posts: 2940


Topic starter
Total Post Ratings: +428

View Profile
« Reply #2 on: 21 December, 2011, 02:36:15 »
0

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 Grin
Logged

There are people who can speak two languages, and they are called bilingual.  There are people who speak three languages and are therefore trilingual.  Then there are people who speak one language, and these people are called Americans.

Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:50:48
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #3 on: 21 December, 2011, 03:22:47 »
0

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.
Logged
Hot_Dog
If you can't find a cat, look for its tail.
Support Staff
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 09 May, 2013, 19:22:43
Date Registered: 28 December, 2009, 18:47:54
Location: Midland, Washington
Posts: 2940


Topic starter
Total Post Ratings: +428

View Profile
« Reply #4 on: 21 December, 2011, 03:27:14 »
0

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: 21 December, 2011, 03:27:55 by Hot_Dog » Logged

There are people who can speak two languages, and they are called bilingual.  There are people who speak three languages and are therefore trilingual.  Then there are people who speak one language, and these people are called Americans.

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 07:47:41
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5642


Total Post Ratings: +589

View Profile
« Reply #5 on: 21 December, 2011, 03:30:35 »
0

So you are looking to see if the player can see the enemy or vica verse?
Logged

Hot_Dog
If you can't find a cat, look for its tail.
Support Staff
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 09 May, 2013, 19:22:43
Date Registered: 28 December, 2009, 18:47:54
Location: Midland, Washington
Posts: 2940


Topic starter
Total Post Ratings: +428

View Profile
« Reply #6 on: 21 December, 2011, 03:36:40 »
0

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.
Logged

There are people who can speak two languages, and they are called bilingual.  There are people who speak three languages and are therefore trilingual.  Then there are people who speak one language, and these people are called Americans.

epic7
Chopin!
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: Today at 04:30:24
Date Registered: 22 October, 2011, 01:45:43
Location: Northeast US
Posts: 2160


Total Post Ratings: +118

View Profile
« Reply #7 on: 21 December, 2011, 04:23:33 »
0

What, finding slope? Doesn't (y2-y1)/(x2-x1) find the slope?
« Last Edit: 21 December, 2011, 04:24:13 by epic7 » Logged



Current Projects:
TitleLanguageProgressStatus
DrillMiner    C (ndless)   35%         Active
?     C (ndless)   0%        Unconfirmed

Spoiler for Programming languages I currently know:
Java (Learning in AP Comp Sci)
C (Specifically Ndless)
Unity JavaScript
LabView (For FIRST robotics)
z80 ASM (Just a little bit Tongue)
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 14 May, 2013, 10:02:35
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2735


Total Post Ratings: +373

View Profile
« Reply #8 on: 21 December, 2011, 04:46:38 »
0

So just use a line-drawing algorithm with pixel-test instead of pixel-on?
Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
Hot_Dog
If you can't find a cat, look for its tail.
Support Staff
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 09 May, 2013, 19:22:43
Date Registered: 28 December, 2009, 18:47:54
Location: Midland, Washington
Posts: 2940


Topic starter
Total Post Ratings: +428

View Profile
« Reply #9 on: 21 December, 2011, 06:18:59 »
0

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.
Logged

There are people who can speak two languages, and they are called bilingual.  There are people who speak three languages and are therefore trilingual.  Then there are people who speak one language, and these people are called Americans.

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.183 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.