* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: 3D rendering of simple objects in TI-BASIC  (Read 623 times)

0 Members and 1 Guest are viewing this topic.

Offline _iPhoenix_

  • Full User
  • Join Date: Mar 2017
  • Location:
  • Posts: 482
  • Post Rating Ratio: +10/-1
  • █████ ▼ ♪ Best music ♫
    • @dj_iPhoenix
    • @UCytgMNPxAMDsxjimvxHf01w
    • @the-legend-of-iphoenix
  • Gender: Male
3D rendering of simple objects in TI-BASIC
« on: May 15, 2017, 08:25:56 pm »
*This is for the CE* (At least, I programmed it for and on the CE)


I've been working on this little sub-project (It's part of a larger thing), but have hit a roadblock. I need to be able to fill in the sides with a single color, and I need it to be somewhat fast. It should also cover up the edges that should be on the back. I'm thinking to use flood fill, but that is not exactly a fast way of doing it. I split the code into several programs for ease-of-development.


Sets the current object being drawn to a cube.
prgmOBJCUBE
Code: [Select]
Ans->|LTEMP
|LTEMP(1->A
|LTEMP(2->B
|LTEMP(3->C
|LTEMP(4->W
|LTEMP(5->H
|LTEMP(6->D
[[(A),(B),(C)][(A),(B),(C+D)][(A),(B+H),(C)][(A),(B+H),(C+D)][(A+W),(B),(C)][(A+W),(B),(C+D)][(A+W),(B+H),(C)][(A+W),(B+H),(C+D)]]->[A]
[[1,2][2,4][4,3][3,1][5,6][6,8][8,7][7,5][1,5][2,6][3,7][4,8]]->[B]


Sets the current object to a triangular prism
prgmOBJTRIP
Code: [Select]
Ans->|LTEMP
|LTEMP(1->A
|LTEMP(2->B
|LTEMP(3->C
|LTEMP(4->W
|LTEMP(5->H
|LTEMP(6->D
[[(A),(B),(C)][(A+W),(B),(C)][(A+W),(B),(C+D)][(A),(B),(C+D)][(A+W/2),(B+H),(C+D/2)]]->[A]
[[1,2][2,3][3,4][4,1][1,5][2,5][3,5][4,5]]->[B]


Sets the current object to a tetrahedron
prgmOBJTETR
Code: [Select]
Ans->|LTEMP
|LTEMP(1->A
|LTEMP(2->B
|LTEMP(3->C
|LTEMP(4->W
|LTEMP(5->H
|LTEMP(6->D
[[(A),(B),(C)][(A+W/2),(B),(C+D)][(A+W),(B),(C)][(A+W/2),(B+H),(C+D/2)]]->[A]
[[1,2][2,3][3,1][1,4][2,4][3,4]]->[B]


Lets you move independently of the object.
prgmMOVE
Code: [Select]
Ans->A
(A=0)-(A=2)->B
Xmin+B->Xmin
Xmax+B->Xmax
(A=1)-(A=3)->B
Ymin+B->Ymin
Ymax+B->Ymax


Scaling, used for ‘movement’ on the z axis.
prgmSCALE3D
Code: [Select]
Ans->theta
dim([A]->L1
For(A,1,L1(1
For(B,1,L1(2
theta*[A](A,B->[A](A,B
End
End


Translates the object, but interferes with rotation.
prgmTRANSL8
Code: [Select]
Ans->L1
L1(1->Z
dim([A]->L2
L2(1->T
For(A,1,T
[A](A,Z)+L1(2->[A](A,Z
End


Draws the object.
prgmDRAW3D
Code: [Select]
dim([B]->L1
For(E,1,L1(1
Line([A]([B](E,1),1),[A]([B](E,1),2),[A]([B](E,2),1),[A]([B](E,2),2),1,Black,1
End


Helpful info:
[A] is the list of Vertices, and B (the matrix, screw you, bbcode..) is the list of edges. A ‘1’ in  would correspond to the first row/vertex, a ‘2’ for the second, and so on.

Rotates, in 3 dimensions.
prgmROTATE:
[/b]
Code: [Select]
Ans->L1
Ans(2->theta
sin(theta->A
cos(theta->B
dim([A]->L2
For(N,1,L2(1
[A](N,1->I
[A](N,2->J
[A](N,3->K
If 0=L1(1
Then
JB-KA->[A](N,2
KB+JA->[A](N,3
Else
If 1=L1(1
Then
IB-KA->[A](N,1
KB+IA->[A](N,3
Else
If 2=L1(1
Then
IB-JA->[A](N,1
JB+IA->[A](N,2
End
End
End
End


Renders, and lets you interact:
prgmRENDER3D
Code: [Select]
Disp "DIM. OF OBJECT:
Input "X: ",A
Input "Y: ",B
Input "Z: ",C


Input "OFFSETX: ",S
Input "OFFSETY: ",T
Input "OFFSETZ: ",U
ClrDraw:BackgroundOff
0->|N
//change object type by appending "CUBE", "TRIP", or "TETR" to the following line.
{S,T,U,A,B,C:prgmOBJ
prgmDRAW3D
Pause
ClrDraw
Repeat 0
Repeat Ans
getKey
End
Ans->F
//too lazy to optimize this, shouldn’t really affect speed.
If F=73:Then
{0,pi/16:prgmROTATE:Else
If F=93:Then
{0,~pi/16:prgmROTATE:Else
If F=82:Then
{1,pi/16:prgmROTATE:Else
If F=84:Then
{1,~pi/16:prgmROTATE
End
End
End
End
If sum(F={43,52,54,63
Then
1(F=43)+2(F=52)+0(F=54)+3(F=63):prgmMOVE
End
If sum(F={21,31
Then
.8
If F=21
Ans^^-1
prgmSCALE3D
End
ClrDraw
prgmDRAW3D
End



Renders and slowly rotates the object (I’m really inspired by gLib's screenshots)
prgmROTATE3D
Code: [Select]
Disp "DIM. OF OBJECT:
Input "X: ",A
Input "Y: ",B
Input "Z: ",C


Input "OFFSETX: ",S
Input "OFFSETY: ",T
Input "OFFSETZ: ",U
ClrDraw:BackgroundOff
//change object type by appending "CUBE", "TRIP", or "TETR" to the following line.
{S,T,U,A,B,C:prgmOBJ
prgmDRAW3D
Pause
For(Z,0,1
{Z,pi/16:prgmROTATE
End
Repeat 0
{1,pi/64:prgmROTATE
ClrDraw
prgmDRAW3D
End



With my luck, I missed a program, but I need help :(


Most of the changes would be in DRAW3D, presumably, as that is where everything (so far) is drawn.


Controls (for RENDER3D):


Use the numberpad to rotate. 8 and 2 rotate on the ‘y’ axis, 4 and 6 rotate on the ‘x’ axis.
Use [2nd] to zoom in, [alpha] to zoom out (move closer and further)
Use [prgm] to move up, [sin] to move left, [tan] to move right, and [)] to move down.


I think that’s it.
EDIT: No it isn't.
Instructions to run:
Press these exact buttons:
[zoom][6][zoom][5][prgm]
Then you can run the program (either RENDER3D or ROTATE3D). Be sure to change prgmOBJ to the selected shape before running!
« Last Edit: May 15, 2017, 08:55:26 pm by _iPhoenix_ »


  • Calculators owned: A sentient TI-84+ CE, TI-85
  • Consoles, mobile devices and vintage computers owned: TI-99/4a home computer
Help me with a project by voting here! Thanks!

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me

Offline TheMachine02

  • Full User
  • Join Date: Dec 2014
  • Location:
  • Posts: 356
  • Post Rating Ratio: +14/-0
Re: 3D rendering of simple objects in TI-BASIC
« Reply #1 on: May 18, 2017, 08:59:28 am »
What you want to do is most likely triangle rasterisation. You can work with quadrilateral too but it is slighty harder. You'll two thing based on your program. First implement triangle support :it shouldnt be too hard. The algorithm to fill the triangle is based off the general idea to calculate new x endpoint and startpoint at each y coordinate. What is Nice is that you can compute by how much x coordinate vary when incrementing y by one and only deal with addition in inner loop. Drawing is a simple hline with whatever color you want (lightning ? :p)

Offline _iPhoenix_

  • Full User
  • Join Date: Mar 2017
  • Location:
  • Posts: 482
  • Post Rating Ratio: +10/-1
  • █████ ▼ ♪ Best music ♫
    • @dj_iPhoenix
    • @UCytgMNPxAMDsxjimvxHf01w
    • @the-legend-of-iphoenix
  • Gender: Male
Re: 3D rendering of simple objects in TI-BASIC
« Reply #2 on: June 03, 2017, 12:33:11 am »
What you want to do is most likely triangle rasterisation. You can work with quadrilateral too but it is slighty harder. You'll two thing based on your program. First implement triangle support :it shouldnt be too hard. The algorithm to fill the triangle is based off the general idea to calculate new x endpoint and startpoint at each y coordinate. What is Nice is that you can compute by how much x coordinate vary when incrementing y by one and only deal with addition in inner loop. Drawing is a simple hline with whatever color you want (lightning ? :p)

That's a ton of help; thanks!

I have a semi-working algorithm, but memory leaks...

Of course this is the ONLY DAY IN ABOUT A YEAR I forgot to backup my calculator... which I usually do twice daily...

Silly me!
  • Calculators owned: A sentient TI-84+ CE, TI-85
  • Consoles, mobile devices and vintage computers owned: TI-99/4a home computer
Help me with a project by voting here! Thanks!

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me

Offline JWinslow23

  • Pi is the coolest number in the history of math. :\
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and Graham's Number
  • Posts: 751
  • Post Rating Ratio: +12/-1
  • Use pi! Pi is the absolute greatest! :(
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: 3D rendering of simple objects in TI-BASIC
« Reply #3 on: June 03, 2017, 12:38:21 am »
You know, Archive Undelete CE exists. Have you archived the program at least once?

Offline _iPhoenix_

  • Full User
  • Join Date: Mar 2017
  • Location:
  • Posts: 482
  • Post Rating Ratio: +10/-1
  • █████ ▼ ♪ Best music ♫
    • @dj_iPhoenix
    • @UCytgMNPxAMDsxjimvxHf01w
    • @the-legend-of-iphoenix
  • Gender: Male
Re: 3D rendering of simple objects in TI-BASIC
« Reply #4 on: June 03, 2017, 12:40:18 am »
No, I was working on it constantly for like 2 hours. I have the other programs in a group, so they are fine.
  • Calculators owned: A sentient TI-84+ CE, TI-85
  • Consoles, mobile devices and vintage computers owned: TI-99/4a home computer
Help me with a project by voting here! Thanks!

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games