Jump to content
IGNORED

Sine Wave Help


MausBoy

Recommended Posts

You'll have to precalculate the sine values and store them in your program.
Depending on what you need, either a few data tables or individual calculations for different angles may work best. You'd want not just pre-calculated trig values, but also those values multiplied by some value (as trig functions usually are.)

 

Actual trigonometry calculations are a little too slow for any practical use in bB. I thought about making a library with a set of 8.8 trig values for 0-90 degrees and interpolate for fractional values (or not...), and this would be reasolably quick to access. The problem is usually the functions are multiplied by some value, which requires a slow 16-bit multiplication loop, and just a few of these would take up all the cycles in a frame.

Link to comment
Share on other sites

Precalculated tables will be fine, not a big deal considering the limited resolution.

 

I don't think the addition of a library is necessary but then again I don't know all the ways it could be applied or how people smarter than me would use it.

Link to comment
Share on other sites

This is how I precalculated the Fireball direction/speed tables for Medieval Mayhem. The code's for REALbasic which I used for the free 2 week demo.

 

 Const PI=3.14159
 Const PALadjust = 1.2
 Const Xadjust = 1.3
 
 dim i as integer
 
 dim x(8) as integer
 dim y(8) as integer
 dim speed as double
 
 dim NTSCxHigh as string
 dim NTSCxLow as string
 dim NTSCyHigh as string
 dim NTSCyLow as string
 
 dim PALxHigh as string
 dim PALxLow as string
 dim PALyHigh as string
 dim PALyLow as string
 
 
 for i = 0 to 8
y(i) = 256 * cos(PI/180 * i * 90 / 8)
x(i) = Xadjust * 256 * sin(PI/180 *i * 90 /8)
 next i
 x(8) = Xadjust * 256 ' adjustment, it's coming out 255
 
 ntscxhigh = "NTSCxHigh"
 ntscxlow = "NTSCxLow"
 ntscyhigh = "NTSCyHigh"
 ntscylow = "NTSCyLow"
 
 palxhigh = "PALxHigh"
 palxlow = "PALxLow"
 palyhigh = "PALyHigh"
 palylow = "PALyLow"
 
 for speed = 0 to 3.5 step .5
for i = 0 to 8 
  ntscxhigh = ntscxhigh + chr(10) + "		.byte #>" + app.formatspeed(speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i)
  ntscxlow = ntscxlow + chr(10) + "		.byte #<" + app.formatspeed(speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i)
  NTSCyhigh = NTSCyhigh + chr(10) + "		.byte #>" + app.formatspeed(speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i)
  NTSCyLow = NTSCyLow + chr(10) + "		.byte #<" + app.formatspeed(speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i)
  
  PALxhigh = PALxhigh + chr(10) + "		.byte #>" + app.formatspeed(PALadjust * speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i)
  PALxlow = PALxlow + chr(10) + "		.byte #<" + app.formatspeed(PALadjust * speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i)
  PALyhigh = PALyhigh + chr(10) + "		.byte #>" + app.formatspeed(PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i)
  PALyLow = PALyLow + chr(10) + "		.byte #<" + app.formatspeed(PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i)
next i
for i = 1 to 8
  ntscxhigh = ntscxhigh + chr(10) + "		.byte #>" + app.formatspeed(speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+8)
  ntscxlow = ntscxlow + chr(10) + "		.byte #<" + app.formatspeed(speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8)
  NTSCyhigh = NTSCyhigh + chr(10) + "		.byte #>" + app.formatspeed(-speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8)
  NTSCyLow = NTSCyLow + chr(10) + "		.byte #<" + app.formatspeed(-speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8)
  
  PALxhigh = PALxhigh + chr(10) + "		.byte #>" + app.formatspeed(PALadjust * speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+8)
  PALxlow = PALxlow + chr(10) + "		.byte #<" + app.formatspeed(PALadjust * speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8)
  PALyhigh = PALyhigh + chr(10) + "		.byte #>" + app.formatspeed(-PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8)
  PALyLow = PALyLow + chr(10) + "		.byte #<" + app.formatspeed(-PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8)
next i
for i = 1 to 8
  ntscxhigh = ntscxhigh + chr(10) + "		.byte #>" + app.formatspeed(-speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i+16)
  ntscxlow = ntscxlow + chr(10) + "		.byte #<" + app.formatspeed(-speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i+16)
  NTSCyhigh = NTSCyhigh + chr(10) + "		.byte #>" + app.formatspeed(-speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16)
  NTSCyLow = NTSCyLow + chr(10) + "		.byte #<" + app.formatspeed(-speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16)
  
  PALxhigh = PALxhigh + chr(10) + "		.byte #>" + app.formatspeed(-PALadjust * speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i+16)
  PALxlow = PALxlow + chr(10) + "		.byte #<" + app.formatspeed(-PALadjust * speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i+16)
  PALyhigh = PALyhigh + chr(10) + "		.byte #>" + app.formatspeed(-PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16)
  PALyLow = PALyLow + chr(10) + "		.byte #<" + app.formatspeed(-PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16)
next i
for i = 1 to 7
  ntscxhigh = ntscxhigh + chr(10) + "		.byte #>" + app.formatspeed(-speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+24)
  ntscxlow = ntscxlow + chr(10) + "		.byte #<" + app.formatspeed(-speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24)
  NTSCyhigh = NTSCyhigh + chr(10) + "		.byte #>" + app.formatspeed(speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24)
  NTSCyLow = NTSCyLow + chr(10) + "		.byte #<" + app.formatspeed(speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24)
  
  PALxhigh = PALxhigh + chr(10) + "		.byte #>" + app.formatspeed(-PALadjust * speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+24)
  PALxlow = PALxlow + chr(10) + "		.byte #<" + app.formatspeed(-PALadjust * speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24)
  PALyhigh = PALyhigh + chr(10) + "		.byte #>" + app.formatspeed(PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24)
  PALyLow = PALyLow + chr(10) + "		.byte #<" + app.formatspeed(PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24)
next i
 next speed
 
 efvalues.text = ntscxhigh + chr(10) + chr(10)
 efvalues.text = efvalues.text + NTSCxLow + chr(10) + Chr(10)
 efvalues.text = efvalues.text + NTSCyhigh + chr(10) + Chr(10)
 efvalues.text = efvalues.text + NTSCylow + chr(10) + Chr(10)
 
 efvalues.text = efvalues.text + PALxhigh + chr(10) + chr(10)
 efvalues.text = efvalues.text + PALxLow + chr(10) + Chr(10)
 efvalues.text = efvalues.text + PALyhigh + chr(10) + Chr(10)
 efvalues.text = efvalues.text + PALylow + chr(10) + Chr(10)

 

The table's are quite large so I'm not going to include them here. Go hit my blog, download the source and look for the following

BALLxHigh
	.byte #>	0; speed: 0 direction: 0
	.byte #>	0; speed: 0 direction: 1
	.byte #>	0; speed: 0 direction: 2

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...