3D square using sin/cos ?

STOS programming section.
User avatar
exxos
Site Admin
Posts: 3461
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

3D square using sin/cos ?

Post by exxos » Sun Aug 26, 2018 10:48 am

I have this simple loop...
Capture.JPG
Capture.JPG (50.03 KiB) Viewed 211 times
Basically should have been step 90 :roll: ...

Though I can draw a nice circle just fine, but I am having trouble calculating where points would be in a square, IE, all 4 corners... I always seem to end up with either 3 or 5 points... like it will draw the first 3 corners of the square, then the 4th ends up near the start of the first one or something mad... other times I basically end up with a hex shape :roll:

The example is mess of course... Basically just adding 320 to X for center screen, 100 Y... then multiple by 150,90 for the diameter of the circle.

Really just trying to do a simple 2D spinning square here, of course I can do the rotate part it seems fine, but can't seem to plot 90deg angles with the thing...

Anyone any ideas how to do a spinning square, am I just going about it all wrong ?!
4MB STFM 1.44 FD- VELOCE+ 020 STE - 4MB STE 32MHz - STFM 16MHz - STM - MEGA ST - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - HxC - CosmosEx - Ultrasatan - various clutter

https://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.

sandord
Posts: 109
Joined: Mon Aug 13, 2018 10:08 pm
Contact:

Re: 3D square using sin/cos ?

Post by sandord » Sun Aug 26, 2018 1:09 pm

First of all, there are 360 degrees in a full circle, not 365.

Second, you need to translate degrees to radians before using them with the sin/cos functions. That basically means dividing the degrees by 360 so it becomes a range of 0..1 and then multiplying it by 2*PI so it becomes a range of 0..2PI.

And, you should use a step of 90 degrees, so you'll get all 4 corners, since 90 * 4 = 360.

Finally, you should use floating point variables (called Reals in STOS, postfixed with a #) because otherwise all your numbers are rounded down to the nearest integer. Keep in mind that working with floating points is much slower than integers on the ST. I used to generate sine tables using GFA basic and use them in assembly to quickly look up a value.
Untitled.png
Untitled.png (27.03 KiB) Viewed 202 times

sandord
Posts: 109
Joined: Mon Aug 13, 2018 10:08 pm
Contact:

Re: 3D square using sin/cos ?

Post by sandord » Sun Aug 26, 2018 8:38 pm

You know, I've never really programmed in STOS. I came about an example that used floating point calculations without the # postfix. I guess that when specifying the constants as 2.0 instead of 2 etc. the interpreter automatically changes the variable you're assigning to into a real. In that case you could omit the #.

I can't try it right now but perhaps you can ๐Ÿ˜‰

User avatar
exxos
Site Admin
Posts: 3461
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: 3D square using sin/cos ?

Post by exxos » Sun Aug 26, 2018 9:10 pm

Thanks, only just got home, see how long I can stay awake :)
4MB STFM 1.44 FD- VELOCE+ 020 STE - 4MB STE 32MHz - STFM 16MHz - STM - MEGA ST - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - HxC - CosmosEx - Ultrasatan - various clutter

https://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.

User avatar
exxos
Site Admin
Posts: 3461
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: 3D square using sin/cos ?

Post by exxos » Sun Aug 26, 2018 10:04 pm

Bow down in my spinning 2D cube greatness...


4MB STFM 1.44 FD- VELOCE+ 020 STE - 4MB STE 32MHz - STFM 16MHz - STM - MEGA ST - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - HxC - CosmosEx - Ultrasatan - various clutter

https://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.

sandord
Posts: 109
Joined: Mon Aug 13, 2018 10:08 pm
Contact:

Re: 3D square using sin/cos ?

Post by sandord » Sun Aug 26, 2018 10:11 pm

:dualthumbup:

User avatar
exxos
Site Admin
Posts: 3461
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: 3D square using sin/cos ?

Post by exxos » Sun Aug 26, 2018 10:36 pm

This is painful .... :lol:

But well, using all the most crappy methods , need to install TML :)


4MB STFM 1.44 FD- VELOCE+ 020 STE - 4MB STE 32MHz - STFM 16MHz - STM - MEGA ST - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - HxC - CosmosEx - Ultrasatan - various clutter

https://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.

sandord
Posts: 109
Joined: Mon Aug 13, 2018 10:08 pm
Contact:

Re: 3D square using sin/cos ?

Post by sandord » Sun Aug 26, 2018 10:39 pm

Well, that's terrific! Show us how you did it? ๐Ÿ˜‰๐Ÿ˜‰

User avatar
exxos
Site Admin
Posts: 3461
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: 3D square using sin/cos ?

Post by exxos » Sun Aug 26, 2018 10:47 pm

sandord wrote: โ†‘
Sun Aug 26, 2018 10:39 pm
Well, that's terrific! Show us how you did it? ๐Ÿ˜‰๐Ÿ˜‰
c6.jpg
c6.jpg (73.24 KiB) Viewed 155 times
4MB STFM 1.44 FD- VELOCE+ 020 STE - 4MB STE 32MHz - STFM 16MHz - STM - MEGA ST - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - HxC - CosmosEx - Ultrasatan - various clutter

https://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.

User avatar
exxos
Site Admin
Posts: 3461
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Re: 3D square using sin/cos ?

Post by exxos » Mon Aug 27, 2018 9:10 pm

It keep speeding up first time I tried it, but don't know why steem crashes on speed 6 all the time now.. will have to try and see if it does it on a real machine, or use the original stos version to see if there is some bug..


4MB STFM 1.44 FD- VELOCE+ 020 STE - 4MB STE 32MHz - STFM 16MHz - STM - MEGA ST - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - HxC - CosmosEx - Ultrasatan - various clutter

https://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.

Post Reply