| |
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
|
|
| |
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. |
| |
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... |
| |
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. |
| |
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..
|
| |
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
|
| |
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. |
| |
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
|
| |
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
|
| |
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.
|
| |
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..
|
... 4 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 - Next |