Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Matrefeytontias on October 27, 2013, 04:10:55 pm

Title: Write the fastest 3D cube
Post by: Matrefeytontias 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 :My program reaches 56 FPS (when not moving, and 54 FPS when moving) while respecting all these conditions. I'm pretty proud ;D

(http://img.ourl.ca//fastCube.gif)

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
:
:0→X→Y
:
:While 1
:Sin(X)→SinX
:Cos(Y)→CosY
:Sin(Y)→SinY
:*SinX//128→SXSY
:Cos(X)→CosX*CosY//128→CXCY
:‾CosX*SinY//128→CXSY
:CosY*SinX//128→SXCY
:
:°Verts-6
:For(8)
:{+6→r2}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+Y→Y
:getKey(4)-getKey(1)*4+X→X
:EndIf getKey(15)
:Return
:
:Lbl Sin
:-64
:Lbl Cos
:{^256*2+°CosLUT}r

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

If you want to try, please do :P
Title: Re: Write the fastest 3D cube
Post by: Sorunome on October 27, 2013, 04:18:24 pm
wha, that is looking pretty awesome! :D
Title: Re: Write the fastest 3D cube
Post by: DJ Omnimaga on October 27, 2013, 06:26:52 pm
Looks very fast indeed. :)
Title: Re: Write the fastest 3D cube
Post by: XiiDraco on October 27, 2013, 06:28:35 pm
Man I want to know how to do this...
Title: Re: Write the fastest 3D cube
Post by: Matrefeytontias 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 ;)
Title: Re: Write the fastest 3D cube
Post by: Spyro543 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 ;)
Title: Re: Write the fastest 3D cube
Post by: XiiDraco 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.
Title: Re: Write the fastest 3D cube
Post by: Matrefeytontias on October 27, 2013, 10:10:43 pm
@Spyro543 you're welcome :)

@XiiR3CR34T10N Well, that's kinda the point, right ? ;D
Title: Re: Write the fastest 3D cube
Post by: TheMachine02 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 :
Title: Re: Write the fastest 3D cube
Post by: Sorunome on October 28, 2013, 07:07:51 am
looking nice!/me 'd never be able to do that x.x
Title: Re: Write the fastest 3D cube
Post by: Matrefeytontias 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.
Title: Re: Write the fastest 3D cube
Post by: TheMachine02 on October 28, 2013, 01:19:04 pm
yay  :D  went to 58.0 fps and  between 54-56 (approx 55 ) when moving
Title: Re: Write the fastest 3D cube
Post by: XiiDraco on October 28, 2013, 07:10:38 pm
... What...  ???
Title: Re: Write the fastest 3D cube
Post by: Matrefeytontias on October 28, 2013, 07:23:22 pm
What what ? :P
Title: Re: Write the fastest 3D cube
Post by: XiiDraco 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...