Author Topic: Write the fastest 3D cube  (Read 6593 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Write the fastest 3D cube
« on: October 27, 2013, 04:10:55 pm »
Hey guys,

With TheMachine02 we made a contest about who could write the fastest 3D cube, me vs GLib ;D The rules are simple :
  • XY rotation
  • The cube must be made out of 8 dots that are always visible
  • Each dot appears on-screen as a 2*2 square
  • No ASM code, only pure Axe
  • 6 MHz only
My program reaches 56 FPS (when not moving, and 54 FPS when moving) while respecting all these conditions. I'm pretty proud ;D



And here's the source :

Quote from: Axe
:.FASTCUBE
:#ExprOn
:FnOff
:Data(‾40r,40r,‾40r)°Verts
:Data(40r,40r,‾40r)
:Data(40r,‾40r,‾40r)
:Data(‾40r,‾40r,‾40r)
:Data(‾40r,40r,40r)
:Data(40r,40r,40r)
:Data(40r,‾40r,40r)
:Data(‾40r,‾40r,40r)
:
:Buff(6)°Back
:
:L3°CosLUT
:
:L3+512°CosX+2°CosY+2°SinX+2°SinY+2°CXCY+2°CXSY+2°SXCY+2°SXSY
:
:1
:For(256)
:Select(+1,cos(r1){r1*2+°CosLUT}r)
:End
:
:0XY
:
:While 1
:Sin(X)SinX
:Cos(Y)CosY
:Sin(Y)SinY
:*SinX//128SXSY
:Cos(X)CosX*CosY//128CXCY
:‾CosX*SinY//128CXSY
:CosY*SinX//128SXCY
:
:°Verts-6
:For(8)
:{+6r2}r*CosY+(SinY*{r2+4}r)//128{°Back}r
:SXSY*{r2}r+(CosX*{r2+2}r)-(SXCY*{r2+4}r)//128{°Back+2}r
:CXSY*{r2}r+(SinX*{r2+2}r)+(CXCY*{r2+4}r)//128+192{°Back+4}r
:
:Rect({°Back}r*64//{°Back+4}r+48,{°Back+2}r*64//{°Back+4}r+32,2,)
:r2
:End
:
:DispGraphClrDraw
:getKey(3)-getKey(2)*4+YY
:getKey(4)-getKey(1)*4+XX
:EndIf getKey(15)
:Return
:
:Lbl Sin
:-64
:Lbl Cos
:{^256*2+°CosLUT}r


Generated by the BBify'r (http://clrhome.org/bbify/)

If you want to try, please do :P
« Last Edit: October 27, 2013, 04:11:21 pm by Matrefeytontias »

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Write the fastest 3D cube
« Reply #1 on: October 27, 2013, 04:18:24 pm »
wha, that is looking pretty awesome! :D

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Write the fastest 3D cube
« Reply #2 on: October 27, 2013, 06:26:52 pm »
Looks very fast indeed. :)

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Write the fastest 3D cube
« Reply #3 on: October 27, 2013, 06:28:35 pm »
Man I want to know how to do this...

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Write the fastest 3D cube
« Reply #4 on: October 27, 2013, 08:56:02 pm »
Thanks guys :)

@XiiR3CR34T10N : I only use very basic 3D here (simple usually means fast). All you have to know is the rotation matrices (I multiplied the X one by the Y one, you can find all three X, Y and Z on the internet, even on Wikipedia by searching "rotation matrix"), how to multiply a 3D point by a matrix and how to project a 3D point on a 2D screen.
For this latter, it's very simple : divide the 3D X and Y coordinates by the Z one to get the 2D coordinates. Make sure to multiply the 3D X/Y coordinates by a zoom factor to lower visual distortion. Also, remember that (0,0) must be the center of the screen, so just add 48 and 32 to the 2D X and Y coordinate resectively.

Of course, the source code is here to help you ;)
« Last Edit: October 27, 2013, 08:57:22 pm by Matrefeytontias »

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Write the fastest 3D cube
« Reply #5 on: October 27, 2013, 09:54:06 pm »
For this latter, it's very simple : divide the 3D X and Y coordinates by the Z one to get the 2D coordinates. Make sure to multiply the 3D X/Y coordinates by a zoom factor to lower visual distortion. Also, remember that (0,0) must be the center of the screen, so just add 48 and 32 to the 2D X and Y coordinate resectively.
Thanks for posting that, I was wondering how 3D coordinates were turned into 2D ones ;)

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Write the fastest 3D cube
« Reply #6 on: October 27, 2013, 09:56:31 pm »
Thanks guys :)

@XiiR3CR34T10N : I only use very basic 3D here (simple usually means fast). All you have to know is the rotation matrices (I multiplied the X one by the Y one, you can find all three X, Y and Z on the internet, even on Wikipedia by searching "rotation matrix"), how to multiply a 3D point by a matrix and how to project a 3D point on a 2D screen.
For this latter, it's very simple : divide the 3D X and Y coordinates by the Z one to get the 2D coordinates. Make sure to multiply the 3D X/Y coordinates by a zoom factor to lower visual distortion. Also, remember that (0,0) must be the center of the screen, so just add 48 and 32 to the 2D X and Y coordinate resectively.

Of course, the source code is here to help you ;)
Wow, thanks actually makes so much more sense now!

The amount of things I have learned from Omnimaga is truly amazing.
« Last Edit: October 27, 2013, 09:57:07 pm by XiiR3CR34T10N »

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Write the fastest 3D cube
« Reply #7 on: October 27, 2013, 10:10:43 pm »
@Spyro543 you're welcome :)

@XiiR3CR34T10N Well, that's kinda the point, right ? ;D

Offline TheMachine02

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 452
  • Rating: +105/-0
  • me = EF99+F41A
    • View Profile
Re: Write the fastest 3D cube
« Reply #8 on: October 28, 2013, 06:52:25 am »
matref will always beat me  as I have to programm thing as functions, but I am still very close to him :

55 fps when moving
57 when not

source :  (a lot more small)

Code: [Select]
.TE
2->^^oGCamera

prgmGCORE

Data(40^^r,~40^^r,40^^r)->^^oVertices
Data(40^^r,40^^r,40^^r
Data(~40^^r,~40^^r,40^^r
Data(~40^^r,40^^r,40^^r
Data(40^^r,~40^^r,~40^^r
Data(40^^r,40^^r,~40^^r
Data(~40^^r,~40^^r,~40^^r
Data(~40^^r,40^^r,~40^^r

While 1
GInit()

^^oVertices-6

For(8)
GSpac2Scr({+6->r5}^^r,{r5+2}^^r,{r5+4}^^r
Rect(,{^^oGVertex+2}^^r,2,
r5
End

GGetkey()

DispGraphClrDraw
EndIf getKey(15)

and a little screen :
« Last Edit: October 28, 2013, 06:53:24 am by TheMachine02 »
AXE/asm programmer - unleash the power of z80 //C++//C

epic 3D things http://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Write the fastest 3D cube
« Reply #9 on: October 28, 2013, 07:07:51 am »
looking nice!
* Sorunome 'd never be able to do that x.x

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Write the fastest 3D cube
« Reply #10 on: October 28, 2013, 07:58:06 am »
I went to 58-55 FPS :P no code though, I'm not home atm, and the screenie looks the same anyway.

Offline TheMachine02

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 452
  • Rating: +105/-0
  • me = EF99+F41A
    • View Profile
Re: Write the fastest 3D cube
« Reply #11 on: October 28, 2013, 01:19:04 pm »
yay  :D  went to 58.0 fps and  between 54-56 (approx 55 ) when moving
AXE/asm programmer - unleash the power of z80 //C++//C

epic 3D things http://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Write the fastest 3D cube
« Reply #12 on: October 28, 2013, 07:10:38 pm »
... What...  ???

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Write the fastest 3D cube
« Reply #13 on: October 28, 2013, 07:23:22 pm »
What what ? :P

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Write the fastest 3D cube
« Reply #14 on: October 28, 2013, 07:25:22 pm »
What What What. Stahp

Lol

No, this is really confusing even though I get it, if that makes sense...