Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: zero44 on May 31, 2011, 07:17:12 am

Title: TI 3D modeller
Post by: zero44 on May 31, 2011, 07:17:12 am
Yesterday and this morning I made a 3D modeller in Axe.
It can zoom (1~15), and make a horizontal rotation from 0 to 359°.
It's not very fast, a complete rotation of a 13-pixel object takes 16 seconds !
(yeah, it's objects pixel per pixel, but I'm working on lines)

Code:
Spoiler For code:
.VIEW3D

[hex code->GDB1
zeros(3*•->GDB0
for(I,0,3*•-1
{GDB1+I}->{GDB1+I}
End
0->X->G->I
1->Z
12->L
Repeat getkey(15)
sub(DRW
DispGraphClrDraw
If getkey(25)
G+1^2->G
Pause 300
End
If getkey(2)
X-1->X
If X>360:359->X
End:End
If getkey(3)
X+1^360->X
End
If Z>1 and getkey(50)
Z-1->Z:End
If Z<15 and getkey(49)
Z+1->Z:End
End
Return

.LBLs

Lbl DRW
X->r4
For(I,0,L
3*I+GDB0->A
3*I+GDB1->B
For(r3,0,2
{B+r3}*Z-(128*Z)+128->{A+r3}
End
sub(XYZ,A,r4
Pxl-On(S+48,T+32
End
Return

Lbl XYZ
r1->r3:r2->r4
{r3}-128->r6
{r3+2}-128->r5
{r3+1}-128->r2

cos(r4*10/14)*r6+(sin(r4*10/14)*r5)/128->r1
r1->S
r2->T
Return

Enjoy !  :hyper:

Hex code: write the XYZ place of a pixel. [808080] is the zero. ( the center of screen is the middle of var: 128)
To have a little tower, write: [808080808180808280] and add [808081] for an eventual hall  :P

• is the number of points, for the moment you have to do equations with it, and write results directly in source code ( this stage is dangerous for Ram, so don't make mistake while adding numbers. But you've got a calc, no ?  ;D
Title: Re: TI 3D modeller
Post by: aeTIos on May 31, 2011, 09:46:07 am
Hm, cool. Are you going to add oncalc drawing soon? And please post the source code as an 8xp.
Title: Re: TI 3D modeller
Post by: zero44 on May 31, 2011, 11:01:52 am
I have no usb cable anymore, and I'm trying to do lines; just before vertical rotation.
If someone can say me how to convert xyz point + xy rotation to a xy point ... It'll be great better for the project.
Title: Re: TI 3D modeller
Post by: Munchor on May 31, 2011, 02:08:45 pm
I have no usb cable anymore, and I'm trying to do lines; just before vertical rotation.
If someone can say me how to convert xyz point + xy rotation to a xy point ... It'll be great better for the project.

You can use SourceCoder or TokenIDE to tokenize that code :)

Either way, I'd love a screenshot when you can.
Title: Re: TI 3D modeller
Post by: SirCmpwn on May 31, 2011, 02:33:07 pm
What method of 3D is this?  Full perspective?  It looks like much less source code than I'd expect.
Title: Re: TI 3D modeller
Post by: z80man on May 31, 2011, 02:36:18 pm
So is this dots or is it polygons. I would recommend using polygons as they are faster to render. And I agree with Sir on that it is much less code than I expected.
Title: Re: TI 3D modeller
Post by: ben_g on May 31, 2011, 02:45:12 pm
If someone can say me how to convert xyz point + xy rotation to a xy point ... It'll be great better for the project.

here is some GML code for converting a 3d point to a 2d point onscreen. It's just handling variables, so if you've ever programmed before(in any language), you should understand the code.
It's based on floating points, so it might be a bit difficulty to port.
the code to convert 3d to 2d returns a number between -1 and 1 for the x and y variables.
If you don't understand the 3d therms, just ask me.
I'm also porting this code to asm for my 3d engine

the code (GML version) has been fully tested and no bugs were found
Spoiler For the GML code:
call this to initialise the 'camera'. It handles most of the slow and complicated math so that this should only be calculated once every frame.
Code: [Select]
global.d3dto2d_xfrom = argument0;
global.d3dto2d_yfrom = argument1;
global.d3dto2d_zfrom = argument2;

global.d3dto2d_xto = argument3-global.d3dto2d_xfrom;
global.d3dto2d_yto = argument4-global.d3dto2d_yfrom;
global.d3dto2d_zto = argument5-global.d3dto2d_zfrom;
d = sqrt(global.d3dto2d_xto*global.d3dto2d_xto+global.d3dto2d_yto*global.d3dto2d_yto+global.d3dto2d_zto*global.d3dto2d_zto);
global.d3dto2d_xto /= d;
global.d3dto2d_yto /= d;
global.d3dto2d_zto /= d;

global.d3dto2d_xup = argument6;
global.d3dto2d_yup = argument7;
global.d3dto2d_zup = argument8;
d = global.d3dto2d_xup*global.d3dto2d_xto+global.d3dto2d_yup*global.d3dto2d_yto+global.d3dto2d_zup*global.d3dto2d_zto;
global.d3dto2d_xup -= d*global.d3dto2d_xto;
global.d3dto2d_yup -= d*global.d3dto2d_yto;
global.d3dto2d_zup -= d*global.d3dto2d_zto;
d = tan(degtorad(argument9)/2)*sqrt(global.d3dto2d_xup*global.d3dto2d_xup+global.d3dto2d_yup*global.d3dto2d_yup+global.d3dto2d_zup*global.d3dto2d_zup);
global.d3dto2d_xup /= d;
global.d3dto2d_yup /= d;
global.d3dto2d_zup /= d;

global.d3dto2d_xcross = (global.d3dto2d_yup*global.d3dto2d_zto-global.d3dto2d_zup*global.d3dto2d_yto)/argument10;
global.d3dto2d_ycross = (global.d3dto2d_zup*global.d3dto2d_xto-global.d3dto2d_xup*global.d3dto2d_zto)/argument10;
global.d3dto2d_zcross = (global.d3dto2d_xup*global.d3dto2d_yto-global.d3dto2d_yup*global.d3dto2d_xto)/argument10;

global.d3dto2d_znear = argument11;
global.d3dto2d_zfar = argument12;
call this to convert a 3d point to a 2d point
Code: [Select]
var xx,yy,zz,d;
xx = argument0-global.d3dto2d_xfrom;
yy = argument1-global.d3dto2d_yfrom;
zz = argument2-global.d3dto2d_zfrom;
d= xx*global.d3dto2d_xto+yy*global.d3dto2d_yto+zz*global.d3dto2d_zto;
if (d<global.d3dto2d_znear or d>global.d3dto2d_zfar){ return 0}else{
global.xx = (xx*global.d3dto2d_xcross+yy*global.d3dto2d_ycross+zz*global.d3dto2d_zcross)/d;
global.yy = (xx*global.d3dto2d_xup+yy*global.d3dto2d_yup+zz*global.d3dto2d_zup)/d;
}
return 1;
Title: Re: TI 3D modeller
Post by: zero44 on May 31, 2011, 03:11:26 pm
I didn't understood all what you said.

I made a horizontal rotation, and now if there's X points, it's possible to draw X lines.
I tried a cube, it works, but Blender is faster. ^^
Title: Re: TI 3D modeller
Post by: DJ Omnimaga on May 31, 2011, 03:14:26 pm
Sounds interesting, I would like to see screenshots.
Title: Re: TI 3D modeller
Post by: ben_g on May 31, 2011, 03:16:57 pm
what's the part you don't understand?
The upper script handles the 'camera', and the lower script calculates the 2D coordinates of a 3D point.

Or do you just not know how to port those scripts to axe?
Title: Re: TI 3D modeller
Post by: ben_g on May 31, 2011, 04:34:41 pm
I've just tested it on my calc, AND NOW MAH SCREEN DISPLAYS UPSIDE-DOWN (and it also turned the contrast all the way up)
Title: Re: TI 3D modeller
Post by: Munchor on May 31, 2011, 05:58:39 pm
I've just tested it on my calc, AND NOW MAH SCREEN DISPLAYS UPSIDE-DOWN (and it also turned the contrast all the way up)

Woah, really? But outside the program?
Title: Re: TI 3D modeller
Post by: ztrumpet on May 31, 2011, 06:13:08 pm
I've just tested it on my calc, AND NOW MAH SCREEN DISPLAYS UPSIDE-DOWN (and it also turned the contrast all the way up)
This topic should help you get it back to normal: http://ourl.ca/6348
Good luck. :)
Title: Re: TI 3D modeller
Post by: ben_g on June 01, 2011, 12:32:50 pm
thanks for the link, ztrumpet

It's nothing about the program itself, it was my own dam fault. I executed the compiled version as a basic program :banghead:
Title: Re: TI 3D modeller
Post by: zero44 on June 01, 2011, 12:40:34 pm
I forget something : it's a beta version ...  :-\
Sorry ben_g for your screen, I hope you'll can have it normally.
The only bug I had was a Ram Cleared.

I give you the last version :
AxeLib7 is the library (see my sig) needed
Axe3Dbdd is the objects hexa BDD
Axe3D is the program you've to compile
View3D is the compiled program

to change objects :
go into bdd, put out the hex code of the comment :
theres, in a second comment, some numbers : &,$,# and * (for example)
Put them here :
'Zeros(& ...
'For(I,0,$ ...
'#→L
'*→K

and re-compile Axe3D

Enjoy !  :hyper: (but this time, be careful cause it may bug ...  :-\ )


EDIT: forgot the most important : now after xyz, in a point, you've to put another number : it's the numero of another point, and if it's not null, you'll have a line.
And in GDB7, put two point's numeros and you'll have a line too.
Title: Re: TI 3D modeller
Post by: ben_g on June 01, 2011, 12:51:15 pm
Sorry ben_g for your screen, I hope you'll can have it normally.
The only bug I had was a Ram Cleared.

I got the ram cleared message upside down, but it's already fixed. I just had to pull a battery to solve it.
Title: Re: TI 3D modeller
Post by: zero44 on June 07, 2011, 12:07:40 pm
...
So I made a virus ? ^^

Now we can choose the position of the center, and there's a beautiful little icon to close =)
Title: Re: TI 3D modeller
Post by: DJ Omnimaga on June 08, 2011, 01:19:41 am
Hmm Zero44 your files in http://www.omnimaga.org/index.php?action=dlattach;topic=8731.0;attach=7984 are corrupted. All of them are 0 bytes in size. Could you re-upload them? (Maybe in zip/rar)
Title: Re: TI 3D modeller
Post by: zero44 on June 08, 2011, 09:36:13 am
ok, wait some minuts.
zipped.  :hyper:
Title: Re: TI 3D modeller
Post by: DJ Omnimaga on June 08, 2011, 03:07:06 pm
Ok I made a screenshot. It seems fine so far, although the 3D is kinda messed up sometimes when rotating or zooming in D:
Title: Re: TI 3D modeller
Post by: Spyro543 on June 08, 2011, 05:50:12 pm
That is just cool. Yeah, I see the shape likes to stretch oddly. But it's still a work in progress, and it's very cool. ;D
Title: Re: TI 3D modeller
Post by: aeTIos on June 20, 2011, 09:29:28 am
it looks cool. too bad that its orthographic (but you might add perspective later)