Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > line vector cube/parallel lines
2008-08-31 15:48
Testa
Account closed

Registered: Oct 2004
Posts: 197
line vector cube/parallel lines

hello,

i have a question about line vectors (3d projections) lets take for example a cube with 8 corners rotating around in 3d perspective.. each line of the cube got his parallel line(s). the question i have: does this paralell line use the same line patern as the line it is parallel too, so i only have to calculate (linedrawing) this line only one time and reuse the table for the other (parallel) lines.

a friend of my says that this called a orthogon projecttion and not a perspective projection: when you draw for example a house you see in perspective projection that the lines comes closer when farer away and touch at some point in infinity, becoz of this, each line has i own linepatern,
and so you must calculate each line..

i hope you understand my question
mcd


2008-08-31 15:53
Oswald

Registered: Apr 2002
Posts: 5094
your line routine probably doesnt follows the fastest solutions, since those use only one lda # to get the line pattern, as the line-loop is unrolled.

edit: check the c=hacking series on codebase, in the "different perspective.." article series there are various lineroutines discussed.
2008-08-31 16:04
Testa
Account closed

Registered: Oct 2004
Posts: 197
oswald: i don't know what you mean. i use a unrolled routine to calculate lines and store it into a tabel
so i use two separate routines. one for calulating lines and the other for pasting them... thanks anyway... i know
you are a master in vectors...
2008-08-31 16:11
Oswald

Registered: Apr 2002
Posts: 5094
maybe if you paste your line "pasting" source we can be more of a help. I guess you want to save time by reusing slopes.
2008-08-31 17:34
Testa
Account closed

Registered: Oct 2004
Posts: 197
well.

the line calculation routine looks like this:

ldx #0
lda #0

clc
adc $40
cmp $41
bmi con
inx
sec
sbc $41
con stx $0f00
clc
adc $40
cmp $41
bmi con2
inx
sec
sbc $41
con2 stx $0f01

enz


you can skip al the clc and sec when the resuls are never
higher dan $ff (the carry doesn't change in this case)
you also can skip the cmp $41 and just test if the number becomes a negative or positive number..





2008-08-31 17:47
Testa
Account closed

Registered: Oct 2004
Posts: 197
oops i forgot the write down the paste routine
it is nothing special but here it comes.

ldx #0
lda lobyte kolum,x
sta $a0
lda hibyte kolom,x
sta $a1
lda pixel,x
ldy $0f00 (the tabel with the linedrawing data)
ora ($a0),y
sta ($a0),y

enz
2008-08-31 18:26
Oswald

Registered: Apr 2002
Posts: 5094
you can skip both clc and sec:

you start with height in the accu and carry set:

sbc $width
bcs con ; no underflow skip (result>0)
adc $height ;underflow carry CLEAR now
inx ;adc will set carry high again because overflow (result>255)
con stx $0f00

big slope case:

con sbc $width
inx
bcs con
adc $height
stx $0f00

$width and $height may be to be swapped (incl. accu initialisation), I have now just thrown them in without thinking about their orders.

line drawing, can be more precalculated:

ldy $0f0x
lda $currentcolumn,y
ora #pixel
sta $currentcolumn,y
ldy $0f0x
lda $currentcolumn,y
ora #pixel
sta $currentcolumn,y
ldy $0f0x
lda $currentcolumn,y
ora #pixel
sta $currentcolumn,y
...

you simply jump into the above speedcode at you desired "xstart" coordinate, and selfmod it to an rts to exit at the desired "xend" coordinate.
2008-08-31 19:26
Testa
Account closed

Registered: Oct 2004
Posts: 197
hell yeah! very cool! thanks a lot! i hope you don't mind asking you something again but: do you also have a clear answer about parallel lines using the same line-drawn patern... or is it an stopid question..

mcd
2008-08-31 20:07
Oswald

Registered: Apr 2002
Posts: 5094
how about:

lda $0f0x,y ;adjust slope for the needed shift horizontally with Y
adc $offset ;adjust slope for the needed shift vertically
tax
lda actcolumn,x
ora #pixel
sta acrcolumn,x
iny

tho if you count the cycles carefully, it will be clear that its faster to calculate the slope each time :)

like this:

lda actcolumn,y
ora #pixels
sta actcolumn,y
txa
sbc $width
bcs con
iny
adc $height
con tax


even faster, but only if you can come up with a division based on log/exp:

lda actcolumn,y
ora #pixels
sta actcolumn,y
txa
adc $slope ;=widht/height or vice versa depending on the case
bcc con
iny
con tax
2008-09-01 06:09
Martin Piper

Registered: Nov 2007
Posts: 722
Quote: hello,

i have a question about line vectors (3d projections) lets take for example a cube with 8 corners rotating around in 3d perspective.. each line of the cube got his parallel line(s). the question i have: does this paralell line use the same line patern as the line it is parallel too, so i only have to calculate (linedrawing) this line only one time and reuse the table for the other (parallel) lines.

a friend of my says that this called a orthogon projecttion and not a perspective projection: when you draw for example a house you see in perspective projection that the lines comes closer when farer away and touch at some point in infinity, becoz of this, each line has i own linepatern,
and so you must calculate each line..

i hope you understand my question
mcd




Sounds like orthographic projection.
2008-09-01 10:50
Testa
Account closed

Registered: Oct 2004
Posts: 197
martin piper, do you know if it is possible to make a nice 3d projection with this so called 'orthograpics' or do i miss something here... anyway this week i'am gonna study the different perspective articles in c=hacking..
2008-09-01 11:07
chatGPZ

Registered: Dec 2001
Posts: 11386
look here: http://en.wikipedia.org/wiki/Orthographic_projection

you might know this as "isometric" (it's not, but it works similar)
2008-09-01 11:16
Oswald

Registered: Apr 2002
Posts: 5094
orthographic projection basically means, that after 3d rotation you simply throw away the z coord (you might not even need to 3d rotate it), and use x,y to draw your cube. in this case pairs of lines will be parallel of a cube and you will have no perspective.

perspective will need the Z coord too, and one multiplication for each coordinate.
2008-09-01 11:20
Testa
Account closed

Registered: Oct 2004
Posts: 197
ok boys! thanks a lot for the help and info..
2009-07-29 05:19
TWW

Registered: Jul 2009
Posts: 545
I would like to investigate this a little furter. I will take a little closer look @ Oswalds code-lines earlier in this thread;

First Routine:

txa
sbc $DX
bcs *+5
iny
adc $DY
tax

This totalt to 14 or 10 cycles depending on branch.

Second Routine:

txa
adc $+-slope
bcc *+3
iny
tax

Totals of 11 or 10 cycles depending on Branch.

This means that these two routines at their best potential are same-same and the log/exp-div would cost you more then calculating on the fly. However at their worst (and if you can calculate the slope constant within 3-384 cycles(Depending how long the line is)) the 2nd alternative would be better.

I am unsure about this but how is the accuracy of a log/exp div constant vs. calculating the slope on the fly!? (mayhaps the same i dunno).

So for shorter and more vertical lines 'the on the fly'-method would pay off. Longer and more Diagonal lines the 'slope constant' would pay. Perhaps in the long run it doesent really make much difference(!?)

However I came up with a more elegant solution a while back. This requiers you to splitt a line in 2 and draw them simultaniously one from Y2 -> DX/2 and one from DY/2 -> Y1 using the same slope (Naturally since it's the same frigging line).

Ofcourse this give bigger gain on longer lines and no or negative gain on short lines due to aditional pre-calculations.


ldx $DX
ldy $DY/2
sec
bit1 lda #$00
ora ($fb),y
sta ($fb),y
bit2 lda #$00
ora ($fd),y
sta ($fd),y

dey
bmi end

txa
sbc #DX
tax ;extra due to the loop
bcs bit1
adc #DY
tax
;---------------------------
;-pointers and bitmask calc-
;---------------------------
asl bit1+1
bcc tjo
lda #$01
sta bit1+1
lda $fb
adc #$7f
sta $fb
bcs *+4
dec $fc
tjo asl bit2+1
bcc bit1-1
lda #$01
sta bit2+1
lda $fd
adc #$7f
sta $fd
bcs bit1
dec $fe
jmp bit1-1
end rts


This is a extract from my routine. It is not optimized (hell it's probably buggy too). Though if unrolled the 'slope-algorithm' cycle count would be the same as the first routine above giving an effective 5/7 cycles gain each pixel.




TWW/Creators
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Rub_0201
DanPhillips
TheRyk/MYD!
Alakran_64
LKP/CFN
megasoftargentina
Kakka/Extend, Damone..
Francois Prijt/Audia..
wil
Laddh
tlr
psenough
Peacemaker/CENSOR/Hi..
Guests online: 97
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Graphicians
1 Mirage  (9.8)
2 Archmage  (9.7)
3 Pal  (9.6)
4 Carrion  (9.6)
5 Sulevi  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.084 sec.