Omnimaga
Calculator Community => TI Calculators => Axe => Topic started 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 :- 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
(http://img.ourl.ca//fastCube.gif)
And here's the source :
:.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
-
wha, that is looking pretty awesome! :D
-
Looks very fast indeed. :)
-
Man I want to know how to do this...
-
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 ;)
-
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 ;)
-
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.
-
@Spyro543 you're welcome :)
@XiiR3CR34T10N Well, that's kinda the point, right ? ;D
-
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)
.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 :
-
looking nice!/me 'd never be able to do that x.x
-
I went to 58-55 FPS :P no code though, I'm not home atm, and the screenie looks the same anyway.
-
yay :D went to 58.0 fps and between 54-56 (approx 55 ) when moving
-
... What... ???
-
What what ? :P
-
What What What. Stahp
Lol
No, this is really confusing even though I get it, if that makes sense...