Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Single Pointer LUT problem....
#1
Hi I am having problems with lookup tables in my game. Basically , I would want to use precalculated values instead of calculating it on the fly.

This would be tbe init code:

Code:
dim pm_sin as single ptr
dim pm_cos as single ptr
pm_sin = callocate(len(single) * 360)
pm_cos = callocate(len(single) * 360)
for i = 0 to 359
    pm_sin[i] = sin(i * 3.141593 / 180)
    pm_cos[i] = cos(i * 3.141593 / 180)
next i

Why would this fail:

Code:
dim angle as integer
angle = ( m_angle + i * (STEPSEGMENT - 2) )
if angle > 359 then angle = angle - 360
.ps_followers[i].m_x = MainEnemy.m_x + 24 + (pm_cos[ angle ] * 70)
.ps_followers[i].m_y = MainEnemy.m_y + 28 + (pm_sin[ angle ] * 60)


And this not:

Code:
dim angle as single
angle = ( m_angle + i * (STEPSEGMENT - 2) ) * 3.141593 /180
if angle > 359 then angle = angle - 360
.ps_followers[i].m_x = MainEnemy.m_x + 24 + cos(angle) * 70
.ps_followers[i].m_y = MainEnemy.m_y + 28 + sin(angle) * 60

Actually, it does not give me an error, but the effect of the two codes is a lot different. With Luts, some of the sprites "jump" off the desired position. :*(

Thanks in advance!
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#2
this is just a guess, but what happends when you make the pm_sin + pm_cos double ptrs?

I looked and the only difference between the two that I saw was that the sin() + cos() were giving a double and the pm_sin[] and the pm_cos[] were giving a single.....try it, see what happends. Big Grin

EDIT:
It could also be that your losing data when you dim the angle as an integer in the first one. Try dimming that as a single as well :wink: .
i]"But...it was so beautifully done"[/i]
Reply
#3
Make angle a single and use cint(angle) as the index to the LUT. With angle as integer the increases below 0.5 do not build up as they are rounded...
Antoni
Reply
#4
Lillo help me. Stupid mistake actually:

Code:
while angle > 359 : angle = angle - 360: wend

Thanks anyways. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)