CodeWalrus

Multimedia => Drawing & Animation => Topic started by: CKH4 on April 21, 2015, 09:35:36 PM

Title: CKH4's 3D plane program
Post by: CKH4 on April 21, 2015, 09:35:36 PM
Even though this is not pixel art I don't think that it deserves a new topic so here's the code for the 3d faked plane.
0->A
While 1
A-pi(K=26)+pi(K=24->A
6cos(.05A->B
sin(.05A->C
If K
ClrDraw
Line(~B,6-C,B,6+C
Line(~B,C-6,B,~6-C
Line(B,6+C,B,~C-6
Line(~B,6-C,~B,C-6
"Leave this out for untextured
For(D,0,6,.65
Line(B/6D-B/2,3+D/5C,B/6D-B/2,~3-D/5C
End
"
getKey->K
End

and here's the image:
Without texture
(http://i.imgur.com/TYBJXbt.gif)
With texture
(http://i.imgur.com/wizl79p.gif)
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 21, 2015, 09:48:41 PM
I like how fast this is despite being BASIC. :) I should try making an HP Prime version when I get a chance.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 21, 2015, 09:51:03 PM
Yeah, feel free to use any of this code if you need it. For basic I think it is pretty well optimized but I haven't tried to hard.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 21, 2015, 10:09:15 PM
Is it possible to modify that engine to use the screen pixel coordinates rather than graph window?

EDIT: This is what I got after modifying the code a bit by the way. Textures seem glitchy though:
EXPORT plane3D()
BEGIN
DIMGROB_P(G1,320,240,#9EAB88);
0▶A;
WHILE 1 DO
A-π*(ISKEYDOWN(8))+π*(ISKEYDOWN(7))▶A;
6*COS(.05*A)▶B;
SIN(.05*A)▶C;
RECT(G1,#9EAB88);
LINE(G1,−B,6-C,B,6+C,#1A1C16);
LINE(G1,−B,C-6,B,−6-C,#1A1C16);
LINE(G1,B,6+C,B,−C-6,#1A1C16);
LINE(G1,−B,6-C,−B,C-6,#1A1C16);
FOR D FROM 0 TO 6 STEP .65 DO
LINE(G1,−B/2+B/6*D,3+D/5*C,−B/2+B/6*D,−3-D/5*C,#1A1C16);
END;
BLIT_P(G0,G1);
WAIT(.1);
END;
END;

(https://img.ourl.ca/plane3D.gif)

I also tried with GETKEY but it only registers 10 keypresses per second.
Title: Re: CKH4's 3D plane program
Post by: alexgt on April 21, 2015, 10:21:41 PM
I want to learn the basics of 3D programming like that is there any good how to's out there (I want MinePrime to be 3D in the future!)

DJ I like the fake lcd color like the Z80 ;P
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 21, 2015, 10:23:25 PM
Most likely 3D tutorials on Google. IIRC there is a nice raycasting tutorial somewhere too and Critor made a 3D engine in HP PPL. The HP Prime also got FILLPOLY and TRIANGLE commands that can be handy. But yeah i bet that online tutorials can be re-used for calc stuff too.

They can probably be handy for TI-84+ too but much slower of course.

Also with BLIT instead of LINE one could replace the lines with an actual texture if the gaps were removed.
Title: Re: CKH4's 3D plane program
Post by: alexgt on April 21, 2015, 10:27:50 PM
PrimeCaster? Also FILLPOLY had a memory issue even when I used the example in the help menu. Thanks for the help :) !
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 21, 2015, 10:43:06 PM
Yeah the I had to hack the texture together do to lack of brain power. Anyways that looks really good. I have no idea how to make a less hacky texture. If you find any way to fix it that would be great. Also is there an hp prime boot free equivalent?
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 21, 2015, 10:49:48 PM
Quote from: alexgt on April 21, 2015, 10:27:50 PM
PrimeCaster? Also FILLPOLY had a memory issue even when I used the example in the help menu. Thanks for the help :) !
Oh it's because the example in the help menu is wrong. The syntax isn't even the right one. I forgot exactly what it is but I think you need to change brackets to parentheses or something else.

Also I think bitmap texture for CKH4 program would not work on the HP Prime because BLIT and DIMGROB don't appear to work at all (most likely the same issue that plagued the HP 39gII), while BLIT_P and DIMGROB_P works fine. So CKH4 engine would not be able to use real textures unless it was ported to pixel-based coordinates instead of window-based ones.
Quote from: CKH4 on April 21, 2015, 10:43:06 PM
Yeah the I had to hack the texture together do to lack of brain power. Anyways that looks really good. I have no idea how to make a less hacky texture. If you find any way to fix it that would be great. Also is there an hp prime boot free equivalent?
The official emulator by HP is free.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 21, 2015, 10:56:43 PM
I think that if you add 30 to each line argument you can use pixel based lines.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 21, 2015, 11:05:50 PM
Do you mean incrementing or multiplying? I tried adding 160 to X and 120 to Y and could get a Walrii centered, but I had to scale it up to 24 times its size. Of course it still has the glitch shown in my screenshot earlier but this is how it looks like and run on-calc:

(https://img.ourl.ca/plane3Dwalrii2.gif)

Each column of the sprite are scaled up horizontally to fill 6 pixels in width, which is why it looks weird.

I wonder if with textures that are 8 pixels in width, raycasting would run fast enough...
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 21, 2015, 11:15:56 PM
Cool effect but not to useful long term. I meant for each line to look like this instead:
Line(B+30,6+C+30,B+30,~C-6+30


also where do programs hide on hp prime? nvm I found it.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 22, 2015, 03:21:37 AM
Quote from: CKH4 on April 21, 2015, 11:15:56 PM
Cool effect but not to useful long term. I meant for each line to look like this instead:
Line(B+30,6+C+30,B+30,~C-6+30


also where do programs hide on hp prime? nvm I found it.
By not useful do you mean graphical textures are useless?? O.O
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 22, 2015, 10:20:03 AM
Whoa that looks quite cool
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 22, 2015, 11:57:53 AM
DJ that's not quite what I meant. That scaling method isn't helpful although it does look pretty cool. If I could see the code for it I might be able to fix it.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 22, 2015, 01:28:12 PM
Oh ok. I'll try to post the code later. Also I should try doing something with your avatar background. :P
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 22, 2015, 02:48:30 PM
If you want the individual tiles I can get you them this weekend I think. Maybe later today but I'm not sure.

Edit. This looks cool http://www.skytopia.com/project/cube/cube.html (http://www.skytopia.com/project/cube/cube.html)
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 22, 2015, 03:03:44 PM
wow, thats actually quite useful. Though i still miss some matrices :P
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 22, 2015, 03:08:00 PM
I haven't read it all the way yet but it did inspire me to try to make a cube with the engine thing that I made.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 22, 2015, 04:22:41 PM
Ooh that could be useful if it's really more user-friendly. :D

EDIT: @CKH4 Here's the source per your request by the way:

EXPORT plane3D()
BEGIN
DIMGROB_P(G1,320,240,#9EAB88);
0▶A;
WHILE 1 DO

A-π*(ISKEYDOWN(8))+π*(ISKEYDOWN(7))▶A;
6*COS(.05*A)▶B;
SIN(.05*A)▶C;
RECT(G1,#9EAB88);
TEXTOUT_P(−B/2+B/6*D,G1,0,0);
TEXTOUT_P(−3-D/5*C,G1,0,20);
TEXTOUT_P(11−B/2+B/6*D,G1,220,0);
TEXTOUT_P(3+D/5*C,G1,220,20);
LINE(G1,−B,6-C,B,6+C,#1A1C16);
LINE(G1,−B,C-6,B,−6-C,#1A1C16);
LINE(G1,B,6+C,B,−C-6,#1A1C16);
LINE(G1,−B,6-C,−B,C-6,#1A1C16);
FOR D FROM 0 TO 6 STEP .25 DO
// LINE(G1,−B/2+B/6*D,3+D/5*C,−B/2+B/6*D,−3-D/5*C,#1A1C16);
BLIT_P(G1,160+24*(−B/2+B/6*D),120+24*(−3-D/5*C),166+24*(−B/2+B/6*D),121+24*(D/5*C),"name",4*D,0,1+4*D,24,#A6DCFF);
BLIT_P(G1,D*4,120,1+D*4,144,"name",4*D,0,1+4*D,24,#A6DCFF);
END;
BLIT_P(G0,G1);
END;
END;

ICON name 89504E470D0A1A0A0000000D49484452000000180000003008030000003C564A91000000ED504C5445A6DCFF030303EEF0F1F6F6F6FAFAFAEAEAEBEDEFF1E3E5E7E7E7E7FFFFFFF3F4F6DCDEE13394E83191DFF2F4F60357FF0453F02986D79A9B9D2E8FE3EEEEEEAFAFAFAAADAE9B9E9F777A7E044FE3044CDB3193E8E4E4E48080808B8B8BB1B1B17B7B7B74767A6A6F7A0449D2D6D9DA7E7E7E868686A7A8A96D6D6D737373ADADADCACACA7A7A7A7F7F7FE8E8E8DFDFDFF0F0F0F8F8F8D7D7D7A8A8A8E3E3E3828282848484CECECEB7B7B7A8AAAC8989897D7D7DC3C3C5A2A2A2939393C5C5C5BEBEBEAAAAAA8383837171717676767878789E9E9E6E7071666768A7A7A76E6E6E787B7C71747776787A9B9B9B4FDB67010000004F74524E53000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002903720E0000017D494441547801EDD2DD56DA401440617680DA5414B5C5FA5386515BDA5423481BC02015249452D4F77F1CCF844948A4BDF3D259CB9BF391332B6617E20314FE75708A0E85759479A954C6719E09E537B0C15BD77D971736A96CC92DDBAEEBE4D641A5BAC36E45A4C85E46E0BDC04EB542F103B5FD54F878C0E11187D5633E51578D15E8FA099C72C667BE3495FA6A05BEE169AD05E3B9FA9EC0B94C2E3CB4AF7D3357B5042E5BB169951CBB8B769BCBAB4E067EACA0EDB633E093AECA83B6D08196FB13BF19C4772BD5B5D0939B5B5C049A6069FD6B2C983F1DA0C390819146FCAFE4469E1030BFEED7449A5D355C0ABFB8B5578CC6F83EDDE53BC2F88E4914C94366CB54335DBE23BFD56026EBFEE0F9A19AF377C642DF8BE02DEC4A78A83F9A604806996FF69F8ED6C37A0D2EDBD5CB07B7DE950DCE74C55A572DD355188A998D8D04E2AEA8F5956CD3D215C3F893F7181B1C8F948064B5EA4DB2BA8586CC355134CDF43680C95C85BE8700696F9295E863FDC11645D25B5A5BBE9927223B45CB11B69EBA0000000049454E44AE426082;
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 23, 2015, 02:17:41 AM
Cube!!! Aweful perspective but that's what I get for faking stuff.
(http://i.imgur.com/qcXEiDT.jpg)
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 23, 2015, 03:20:37 AM
Weird indeed lol. But I assume that can be solved somewhat easily, right? I really need to learn how to create rudimentary but more complex 3D models or maps so I can attempt at making some sort of 3D HP Prime game. Else I could just try raycasting.

One thing I had in mind was to cheat a bit and not really use true 3D for textures, but use a lower resolution to hide the display glitches :P. That could allow some super fast-paced 3D game and it would still look good per calc standards. Mode-7 is another thing I want to experiment with one day.
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 23, 2015, 07:25:45 AM
What do you guys mean with "raycasting", i mean i though raycasting was more for picking objects and such, not rendering.
Title: Re: CKH4's 3D plane program
Post by: Duke "Tape" Eiyeron on April 23, 2015, 07:35:25 AM
Raycasting can be also used for primitive 3D projection, like Doom or Wolfenstein, with the distance of the wall you hit with a ray, you can calculate the height the wall will take on the screen and display it correctly on this pixel row. I suggest you to search on Google about 3D with raycasting.
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 23, 2015, 07:42:31 AM
Seems like a pretty heavy rendering method. Then again, so are raytracing and raymarching :P
Title: Re: CKH4's 3D plane program
Post by: Duke "Tape" Eiyeron on April 23, 2015, 08:11:03 AM
Raycasting is definitely lighter than raytracing/marching. Basic raycasting only uses one ray per screen pixel row, thus Wolfenstein 3D could be the first FPS ever on computer not powerful enough for more advanced 3D rendering techniques as DOom or Quake will allow later.
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 23, 2015, 08:32:26 AM
But its still heavier than rasterizing, right?
Title: Re: CKH4's 3D plane program
Post by: Duke "Tape" Eiyeron on April 23, 2015, 08:37:23 AM
No, it's faster, else it wouldn't exist.
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 23, 2015, 08:39:31 AM
Oh thats interesting... But it has to have some drawbacks, else we wouldnt use rasterizing?
Title: Re: CKH4's 3D plane program
Post by: Duke "Tape" Eiyeron on April 23, 2015, 11:00:04 AM
Yes, walls are vertical and as it's grid based, you'll have some problems adding non linear walls, but that's possible, look at Doom's map, they're bitmaps and yet you even have things like stairs.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 23, 2015, 11:16:40 AM
DJ I think that it needs to be completely redone in source coder because I need like over 50 character rows. I really wish that there was a small font program editor for ti 84. I could in theory design one but saving the code as a program would be a problem.
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 23, 2015, 12:48:19 PM
I have a letter editor for the CSE but that's not what you want i think :P
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 23, 2015, 02:55:11 PM
Not what I want. If you understand not only small font but also small font spacing ( no letter outline, 3x5 font ). I wonder if ti os could be modified for 3x5 letters.
Title: Re: CKH4's 3D plane program
Post by: Snektron on April 23, 2015, 03:01:11 PM
Ehhh, no. Well, not if you don't want to make rom mods :P.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 23, 2015, 03:02:45 PM
It was more of a "is it possible" sort of thing.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 26, 2015, 04:03:14 AM
Quote from: CKH4 on April 23, 2015, 11:16:40 AM
DJ I think that it needs to be completely redone in source coder because I need like over 50 character rows. I really wish that there was a small font program editor for ti 84. I could in theory design one but saving the code as a program would be a problem.
I am confused by what you are refering to, because my program is for the HP Prime, so it cannot be edited in SourceCoder ???.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 26, 2015, 01:25:10 PM
I'm referring to my cube program because its just a mess right now. I'm afraid that I lost it when I accidentally reset wabbit on my phone. Right now the program is not set up like an engine, its pretty much all hard coded but I have no experience in engines like this. I started porting the old plane one to xlib but xlib appears to draw lines weirdly so I might need your xlib experience with that.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 26, 2015, 06:54:16 PM
Oh I see now. I never used xLIB lines so I will have to take a look at that.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 26, 2015, 09:34:43 PM
Here's the xlib code ( I may have typed it in wrong )
0->A
Repeat K=15
real(8->K
A-π(K=2)+π(K=3->A
cos(.05A->B
sin(.05A->C
real(0,0
real(12,0,24B+47,3C+10,-24B+47,-3C+10,0
real(12,0,24B+47,-3C+52,-24B+47,3C+52,0
real(12,0,24B+47,3C+10,24B+47,-3C+52,0
real(12,0,-24B+47,3C+52,-24B+47,-3C+10
End
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 26, 2015, 09:57:21 PM
Oh wait you meant xLIB for monochrome, not CSE. Mind using DCS7 instead? Because it's 99.9% similar syntax-wise and xLIB doesn't run on MathPrint OSes.I didn't use xLIB monochrome since early 2008 too.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 26, 2015, 10:00:45 PM
Xlib is integrated directly into dcs7 if I remember correctly so yes its compatible with dcs7. Also yeah it's monochrome but it wouldn't require much tweaking for cse.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 26, 2015, 10:03:15 PM
Yeah it was integrated. There are some issues like with Metroid and Bowling, but other than that most stuff works perfectly. Most issues are due to original xLIB games abusing xLIB glitchea to produce special effects and DC7 patches those.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 26, 2015, 10:56:02 PM
If you could try it and see if the lines look weird, that would be great.
Title: Re: CKH4's 3D plane program
Post by: Dream of Omnimaga on April 27, 2015, 05:34:40 AM
It appears fine for me in DCS7 (OS 2.53 MP):

(http://img.codewalr.us/xlibsquare.gif)

Do you refresh the screen on every line by the way? I forgot what was the argument to update the LCD by default in xLIB 83+. But I remember that only updating the LCD content when drawing the final element is much faster.
Title: Re: CKH4's 3D plane program
Post by: CKH4 on April 27, 2015, 11:30:39 AM
Nope that's the same bug I have, I guess that its an issue with the xlib line routine. It appears that the when you press left or right the vertical lines appear to grow but in reality I think its the horizontal ones.

To answer your question about updating the lcd, I wait until the final line. Real(0,0 clears the screen without updating it and the first 3 lines have ,0 at the end which doesn't update it either. The last line does update it though because I left off ,0.