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


 
... 4 posts hidden. Click here to view all posts....
 
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
Previous - 1 | 2 - Next
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
Mike
rambo/Therapy/ Resou..
krissz
grass/LETHARGY
visionvortex
Holy Moses/Role
MWR/Visdom
Jammer
Hexhog
Guests online: 99
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 Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

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