Author Topic: What is wrong with my 3D code?  (Read 2123 times)

0 Members and 1 Guest are viewing this topic.

c4ooo

• Posts: 252
• Rating: +10/-1
• The impossible chemical compound.
What is wrong with my 3D code?
« on: February 06, 2016, 04:39:05 pm »
This code *should* draw a verticle line that rotates around the camera, but it does not.
Code: [Select]
.A0->ORepeate getKey(41)ClrDrawsin(O)->Scos(O)->CROT(0,0,3,L1)ROT(0,10,3,L1+4)Line({L1}^r,{L1+2}^r,{L1+4}^r,{L1+6}^r)O++Pause 15DispGraphEndReturn.Rotate (r1,r2,r3) around the Y axis by O degrees; then project the point into 3D and store it to r4 as two 16 bit (signed) numbers. Lbl ROT.Zr3*C-(r1*S)//128->D.Xr3*S+(r1*C)//128//D+48->{r4}^r.Yr2//D+32->{r4+2}^rReturn
-German Kuznetsov
The impossible chemical compound.

ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
Re: What is wrong with my 3D code?
« Reply #1 on: February 07, 2016, 08:36:59 pm »
I tried messing around with it, but I couldn't get your current algorithm to work, so I tried it with a different one.
Code: [Select]
Lbl ROTr1*C-(r3*S)//128->r5r1*S+(R3*C)//128->r3r5->r1r1*48//r3+48->{r4}^^rr2*48//r3+32->{r4}^^rReturnIf the sign bit of r3 is set, then the vertex was behind the camera and you shouldn't draw it. This code is just something that seemed to work for me, nothing more, so it's possible that it isn't the most optimized version and that there are still a few problems with it (especially since I programmed it at 2:00).
Keep in mind that a line of 10 units tall and only 3 units away from the camera requires a very wide field of view to be seen. I've tried a line of 10 units tall and 20 units away.

On irc, you also asked me what the 48 means at the start of the last 2 lines. This is a constant related to the screen's size and the FOV.
This is a sketch of the camera:

The angle between the black lines is the field of view (in this case 90°). The green line represents the screen, which is in our case 96 pixels wide. The blue distance, which is perpendicular to the screen, is the constant we need. With a field of view of 90°, this distance is equal to half of the screen width, which is 48.
I hope that this makes it clear. If not, feel free to ask and I'll try to improve my explanation tomorrow.
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated