Posts: 3,616
Threads: 287
Joined: Jan 2003
Does anybody have a function that draws a circle and gradually increases/decreases the z-value of the columns of pixels in the circle? Kind of like, a z-tilted circle, or a circle at a 3D perspective (looking at it from the northeast). I tried to write one; miserably failed; laughed at the pixels that appeared; gave up; came here to ask.
It would be a neat thing.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 90
Threads: 8
Joined: Aug 2003
You may degrade the color with the coords, for example suppouse the radious is 10, the center is (100,200), plot the point normally but use the color 64 + (y-200+10), you have to update the colors in your palette(?), to make look better.
Posts: 3,616
Threads: 287
Joined: Jan 2003
You mean actually fade it to create shadows? I thought of that, but it's a pain if I want to have a different palette. Plus, it will just be an illusion - wouldn't work well in a "real" 3D game.
I'd prefer one that actually fades the Z-factor, but does it nicely, without coming up with a broken spiral (like I did).
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 1,439
Threads: 15
Joined: Apr 2003
How I would do it:
Start with a routine that can draw an ellipse and vary the aspect ratio to get the tilting effect, then use a gradient palette and lookup colors based on y value in inner pixel-plotting loop.
Posts: 3,288
Threads: 167
Joined: Nov 2001
The most flexible way that I can think of right now is to plot a circle on the XY axis and rotate it in 3d space, then projecting it onto the screen.
If you want a psudo3d tilted ellipse, you can tweak this:
Code: 'Okay I was bored ;*)
'SetVideoSeg by Plasma357(Jon Petrosky)
'Happy coding Relsoft
'Yes, unoptimized code. ;*)
DECLARE SUB WuPixel (x!, y!, col%)
DECLARE SUB SetVideoSeg (Segment%)
DEFINT A-Z
DIM coords%(5, 1)
'$DYNAMIC
DIM SHARED Vpage(32009) 'an extra 16 bytes are needed so that the image
Vpage(6) = 2560 'can be aligned evenly on a segment (the 4 bytes for
Vpage(7) = 200 'the x and y sprite size normally throw this off, so
Layer = VARSEG(Vpage(0)) + 1 'we have to shift everything over 12 bytes
PI! = 3.141593
Radius = 40 'Radius of the circle
TiltMag = 2
CLS
SCREEN 13
FOR I = 0 TO 255
OUT &H3C8, I
OUT &H3C9, I \ 4
OUT &H3C9, I \ 4
OUT &H3C9, I \ 4
NEXT I
SetVideoSeg Layer 'Set the Drawing to the buffer
DO
LINE (0, 0)-(319, 199), 0, BF
F& = (F& + 1) AND &H7FFFFFFF
x% = SIN(F& / 120) * 160
y% = COS(F& / 150) * 100
xlis% = x% + 160
ylis% = y% + 100
xlis2% = 320 - xlis%
ylis2% = 200 - ylis%
I = (I + TiltMag) MOD 360
aa2! = I * PI! / 180
FOR angle = 0 TO 359 STEP 5
a! = angle * PI! / 180
a2! = a! - aa2!
a2! = a! + I * 3.14153 / 180
x! = COS(angle * 3.141593 / 180 + a!) * Radius
y! = SIN((x!) * 3.141593 / 180 + a2!) * Radius
x! = COS(y! * 3.141593 / 180 + a!) * Radius
y! = SIN((x!) * 3.141593 / 180 + a2!) * Radius
x2! = -y!
y2! = x!
WuPixel xlis% + x!, ylis% + y!, 255
WuPixel xlis% + x2!, ylis% + y2!, 255
'''2nd
WuPixel xlis2% + x!, ylis2% + y!, 255
WuPixel xlis2% + x2!, ylis2% + y2!, 255
NEXT angle
SetVideoSeg &HA000 'Set draw to Screen
'WAIT &H3DA, 8
PUT (0, 0), Vpage(6), PSET 'Blit Dbuffer
SetVideoSeg Layer 'Restore Draw to buffer
LOOP UNTIL INKEY$ <> ""
END
REM $STATIC
SUB SetVideoSeg (Segment) STATIC
DEF SEG
IF VideoAddrOff& = 0 THEN ' First time the sub is called
' We need to find the location of b$AddrC, which holds the graphics
' offset (b$OffC) and segment (b$SegC). Since b$AddrC is in the default
' segment, we can find it by setting it to a certain value, and then
' searching for that value.
SCREEN 13 ' Set b$SegC to A000 (00A0 in memory)
PSET (160, 100), 0 ' Set b$OffC to 7DA0 (not needed in the IDE)
FOR Offset& = 0 TO 32764 ' Search for b$AddrC, which is
IF PEEK(Offset&) = &HA0 THEN ' in the default segment and
IF PEEK(Offset& + 1) = &H7D THEN ' should have a value of
IF PEEK(Offset& + 2) = &H0 THEN ' A0 7D 00 A0.
IF PEEK(Offset& + 3) = &HA0 THEN
VideoAddrOff& = Offset& + 2 ' If we found it, record the
EXIT FOR ' offset of b$SegC and quit
END IF ' looking. (Oddly, changing
END IF ' the b$OffC doesn't seem to
END IF ' do anything, so this is why
END IF ' this sub only changes b$SegC)
NEXT
END IF
' Change b$SegC to the specified Segment
POKE VideoAddrOff&, Segment AND &HFF
POKE VideoAddrOff& + 1, (Segment AND &HFF00&) \ &H100
END SUB
SUB WuPixel (x!, y!, col)
x1 = FIX(x!)
y1 = FIX(y!)
x2 = x1 + 1
y2 = y1 + 1
xm! = x! - x1
ym! = y! - y1
xm2! = (1 - xm!)
ym2! = (1 - ym!)
c1 = xm2! * ym2! * col
c2 = xm! * ym2! * col
c3 = xm2! * ym! * col
c4 = xm! * ym! * col
PSET (x1, y1), c1
PSET (x2, y1), c2
PSET (x1, y2), c3
PSET (x2, y2), c4
END SUB
Posts: 3,616
Threads: 287
Joined: Jan 2003
DrV - that could be it. But I tried that (simply without the shadowing) and got a wonky spiral instead.
Relsoft: and you said you aren't good at math. :roll: I couldn't tweak that to get what I wanted if I spent 3 years at it.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
|