Posted: 10th Sep 2011 13:04
I cant wait for Lee to add the drawing commands to AppGameKit tier 1 (BASIC), so I kinda made them myself...

The drawback is that you have to use a very low resolution. I am using a 160x100 resolution "bitmap" for this test. That is 16000 sprites on screen at the same time.

There is no need for media, as I am generating the sprites by using a failsafe in AGK. (It makes a white sprite if no imagedata is found)

Copy and paste the code into a new project, and set the setup.agc to a resolution of 640x400 for best viewing experience on a PC.

Use C to clear the bitmap, and Q to quit the application



+ Code Snippet
//
// Custom made graphics subset
// By: ?ystein De Lumeau
// support@minportal.net
// version: 1.3.3.7

// Initialize display
SetVirtualResolution    (160,100)
SetClearColor           (0,0,0)
SetOrientationAllowed   (0,0,1,1)
SetResolutionMode       (1)
SetSyncRate             (60,1)
SetBorderColor          (100,100,200)

// Initialize "bitmap"
global dim pixel[159,99]
for l1=0 to 159
    for l2=0 to 99
        pixel[l1,l2]=createsprite(void)
        setspritesize(pixel[l1,l2],1,-1)
        setspriteposition(pixel[l1,l2],l1,l2)
        setspritecolor(pixel[l1,l2],random(0,150),random(0,150),random(0,150),255)
    next l2
next l1
// Display help
print("Press Q to exit program")
print("Press C to clear screen")
sync()
sleep(3000)

// Main loop (Press Q to exit, C to clear screed)
do
    // Draw random pixels
    for l1=0 to 4
        x=random(0,159)
        y=random(0,99)
        r=random(0,100)
        g=random(0,100)
        b=random(0,100)
        plot(x,y,r,g,b)
    next l1
    // Draw random lines
    for l1=0 to 2
        x1=random(0,159)
        y1=random(0,99)
        x2=random(0,159)
        y2=random(0,99)
        r=random(101,200)
        g=random(101,200)
        b=random(101,200)
        drawline(x1,y1,x2,y2,r,g,b)
    next l1
    // Draw random boxes
    x1=random(0,159)
    y1=random(0,99)
    x2=random(0,159)
    y2=random(0,99)
    r=random(51,120)
    g=random(51,120)
    b=random(51,120)
    drawbox(x1,y1,x2,y2,r,g,b)
    // Draw circles
    for r=0 to 200 step 10
        drawcircle(79,49,r,r,r,r)
    next r
    // Check for input
    if getrawkeypressed(67) then cls(0,0,0)
    if getrawkeypressed(81) then exit
    sync()
loop
// Safe exit in case of loop exit
end

function cls(r,g,b)
    for l1=0 to 159
        for l2=0 to 99
            plot(l1,l2,r,g,b)
        next l2
    next l1
endfunction

function plot(x,y,r,g,b)
    if x<0 or x>159 or y<0 or y>99 then return
    setspritecolor(pixel[x,y],r,g,b,255)
endfunction

function drawline(x1,y1,x2,y2,r,g,b)
    dx=abs(x2-x1)
    dy=abs(y2-y1)
    if x1<x2 then sx=1 else sx=-1
    if y1<y2 then sy=1 else sy=-1
    err=dx-dy
    do
        plot(x1,y1,r,g,b)
        if x1=x2 and y1=y2 then exit
        e2=2*err
        if e2>-dy
            err=err-dy
            x1=x1+sx
        endif
        if e2<dx
            err=err+dx
            y1=y1+sy
        endif
    loop
endfunction

function drawbox(x1,y1,x2,y2,r,g,b)
    drawline(x1,y1,x2,y1,r,g,b)
    drawline(x2,y1,x2,y2,r,g,b)
    drawline(x2,y2,x1,y2,r,g,b)
    drawline(x1,y2,x1,y1,r,g,b)
endfunction

function drawcircle(x1,y1,ra,r,g,b)
    x=ra
    y=0
    xc=1-2*ra
    yc=1
    re=0
    while x=>y
        plot(x1+x,y1+y,r,g,b) // Point in octant 1
        plot(x1-x,y1+y,r,g,b) // Point in octant 4
        plot(x1-x,y1-y,r,g,b) // Point in octant 5
        plot(x1+x,y1-y,r,g,b) // Point in octant 8
        plot(x1+y,y1+x,r,g,b) // Point in octant 2
        plot(x1-y,y1+x,r,g,b) // Point in octant 3
        plot(x1-y,y1-x,r,g,b) // Point in octant 6
        plot(x1+y,y1-x,r,g,b) // Point in octant 7
        y=y+1
        re=re+yc
        yc=yc+2
        if 2*re+xc>0
            x=x-1
            re=re+xc
            xc=xc+2
        endif
    endwhile
endfunction
Posted: 10th Sep 2011 16:03
There is no need for media, as I am generating the sprites by using a failsafe in AGK. (It makes a white sprite if no imagedata is found)

Good one
Another out of the box thinker.
Posted: 10th Sep 2011 16:18
Cool. I think it makes sense to prepare for different types of line and dot drawing. I mean, we might never get a DOT or LINE command, but rather we might get direct access to the images, so more like using a memblock image perhaps.
The way AppGameKit works with OpenGL sprites, makes me think that having direct screen access commands might be a stretch... Instead I can see use making a full screen sprite and directly modifying that for drawing commands.
Posted: 10th Sep 2011 17:01
Yes Van B, that would be great, since I am limited now to 16384 sprites (read pixels) so anything above 160x100 pixels, is not possible.

I made a small demo to show the speed of AppGameKit (atleast on the PC) when showing 16000 sprites on the screen at the same time, and doing manipulations on them to simulate pixels.



Full source attached. No media needed
Posted: 11th Sep 2011 0:30
That's a LOT of sprites I also commend some really blue sky coding there!
Posted: 11th Sep 2011 1:06
That vector box looks uber cool
I like it!
Posted: 11th Sep 2011 3:20
What about stretching and rotating sprites to make lines, that way you only need a few sprites and you get high resolution too.
Posted: 11th Sep 2011 4:01
Or perhaps each shape is a super high resolution image, and the sprites render those images in order to the specified position, scale, alpha, colour, e.t.c. The draw commands would be identical to DBP, but they would be created using sprites. This would have the benefit of being able to dynamically change the art on screen, take advantage of acceleration, would not require any 'writes' to any slower-than-mud pipeline memory and might allow some effects standard dot plotting would not allow. You could also offer extra shapes like filled in circles which are notoriously windy to do with dot/line commands. The ultimate test of this approach is a thin line circle the size of the screen. It would require a few images, one for the thickness of the line which can be selected based on the relative density of the resolution and the source image size. I can almost see an AppGameKit module idea forming here
Posted: 11th Sep 2011 10:08
lol, I have no idea what "blue sky coding" means, but I guess you like it Lee I'm Norwegian, and there is alot of english idioms and cultural references I have not heard of.

Yes Diggsey, I am aware of that approach, and I am going to remake the vector demo using that technique. I just did not know how to generate circles with that one. I guess Lee is on to something with the bigger than screen scaled sprites, that you stretch and shrink to your needs. You could even make elipses by shrinking it unevenly on width and height. I'll try it out too. Can even make archs, by placing dark sprites over parts of the circle and use the sprite depht function in a clever way.

Cliff, yes it's uber cool, the perspective is abit wrong, just to make it look cooler

I can theoretically make a filled textured box with hidded surfaces, but it would take weeks to program it all, and a million dim textureline$[128,0]=["0","0","0","2","1","1","5","0","1","0","1"... `s for the texures alone.
Posted: 11th Sep 2011 11:04
Why not use scanlines like in raycasting to do filled boxes?

Here is my line intersect code if you would find it usefull for that?

I converted it because iam planning on doing some kind of raycast engine later on with the agk.

And uses it for simple sprite collision when iam only neaded to know if sprites colides head on.

If you can speed that code up let me know

This code should also return the screen cordinates of where the lines intersect.

This is originally an sample i modified from ianM in the code bas that i later on converted to agk.


+ Code Snippet
Initiate_Linecast:

type sLinecast
	Intersect as integer
    X as float
    Y as float
endtype

global Linecast as sLinecast

return


function FullLineIntersection(Ax#,Ay#,Bx#,By#,Cx#,Cy#,Dx#,Dy#)

   Linecast.Intersect = 0
   Linecast.X = 0.0
   Linecast.Y = 0.0

   n# = ((Ay#-Cy#)*(Dx#-Cx#))-((Ax#-Cx#)*(Dy#-Cy#))
   d# = ((Bx#-Ax#)*(Dy#-Cy#))-((By#-Ay#)*(Dx#-Cx#))

   if d# = 0.0 then goto endlinecast
      r# = n# / d#
      s# = ( ((Ay#-Cy#)*(Bx#-Ax#))-((Ax#-Cx#)*(By#-Ay#)) ) / d#

   if r# <= 0.0 then goto endlinecast
   if r# >= 1.0 then goto endlinecast
   if s# <= 0.0 then goto endlinecast
   if s# >= 1.0 then goto endlinecast
   Linecast.X = Ax# + (r# * (Bx# - Ax#) )
   Linecast.Y = Ay# + (r# * (By# - Ay#) )
   Linecast.Intersect = 1
endlinecast:
endfunction Linecast.Intersect


Posted: 11th Sep 2011 14:28
I guess I could do that Cliff, but I have shifted my focus to sprite lines for the moment.

Here is a smal demo, to stretch a sprite between two points in the X,Y plane.

+ Code Snippet
//
// Sprite Lines test
// By: ?ystein De Lumeau
// support@minportal.net
// version: 1.3.3.7

// Initialize display
SetVirtualResolution    (1280,800)
SetClearColor           (0,0,0)
SetOrientationAllowed   (0,0,1,1)
SetResolutionMode       (1)
SetSyncRate             (60,1)

// Make diagnortics sprites
createsprite(1000,0)
setspritesize(1000,3,3)
setspritecolor(1000,255,0,0,255)
createsprite(1001,0)
setspritesize(1001,3,3)
setspritecolor(1001,0,255,0,255)

// Make linesprite 1
// th = thikness of line in pixels
createsprite(1,0)
th=2
setspritesize(1,200,th)
setspriteoffset(1,0,th/2)

// Demo loop
do
    // Loop timer for random line positions
    t=t+1
    if t=50 then t=0
    if t=1
        x1#=random(10,1270)
        y1#=random(10,790)
        x2#=random(10,1270)
        y2#=random(10,790)
    endif

    // Diagnostics reference points
    // Start coordinate = Red
    // Stop coordinate = Green
    setspritepositionbyoffset(1000,x1#,y1#)
    setspritepositionbyoffset(1001,x2#,y2#)

    // Math of sprite angle and width between points
    // w# = sprite width   a# = sprite rotation angle
    w#=sqrt((x2#-x1#)^2+(y2#-y1#)^2)
    a#=atan((y2#-y1#)/(x2#-x1#))

    // Calculate angle ofsett
    if x2#=>x1# then ao#=0
    if x2#<x1# then ao#=180

    // Draw sprite line
    setspriteangle(1,a#+ao#)
    setspritesize(1,w#,th)
    setspritepositionbyoffset(1,x1#,y1#)

    // Check for ESC
    if getrawkeypressed(27) then exit
    sync()
loop
end


No media needed, paste in new project, set setup.agc to 1280x800
Posted: 11th Sep 2011 15:15
My rotating vector box with spritelines.



+ Code Snippet
//
// Sprite Lines 3D box
// By: ?ystein De Lumeau
// support@minportal.net

// Initialize display
SetVirtualResolution    (1280,800)
SetClearColor           (0,0,0)
SetOrientationAllowed   (0,0,1,1)
SetResolutionMode       (1)
SetSyncRate             (60,1)

// Define center coordinates
XMID#=640
YMID#=400
DIST#=50
ZOOM#=800

// Set up the vector XYZ positions relative to the center coordinates XMID# and YMID#
dim XP#[8]
dim YP#[8]
dim ZP#[8]
dim XP2#[8]
dim YP2#[8]
dim ZP2#[8]
dim xt#[8]
dim yt#[8]

// Virtual size of the vector
I=12

// XYZ Data
XP#[1]=-I
YP#[1]=-I
ZP#[1]=-I
 XP#[2]=I
 YP#[2]=-I
 ZP#[2]=-I
XP#[3]=I
YP#[3]=I
ZP#[3]=-I
 XP#[4]=-I
 YP#[4]=I
 ZP#[4]=-I
XP#[5]=-I
YP#[5]=-I
ZP#[5]=I
 XP#[6]=I
 YP#[6]=-I
 ZP#[6]=I
XP#[7]=I
YP#[7]=I
ZP#[7]=I
 XP#[8]=-I
 YP#[8]=I
 ZP#[8]=I

// Demo loop
do
    // Rotate the X Y Z axises, change to get different rotation patterns
    S1#=S1#+0.6
    if S1#>360 then S1#=S1#-360
    S2#=S2#+0.4
    if S2#>360 then S2#=S2#-360
    S3#=S3#+0.8
    if S3#>360 then S3#=S3#-360
    // 3D vector math and draw cube
    for I=1 To 8
        ZA#=(ZP#[I]*cos(S3#)-XP#[I]*sin(S3#))
        XA#=(XP#[I]*cos(S3#)+ZP#[I]*sin(S3#))
        YA#=(YP#[I]*cos(S2#)-ZA#*sin(S2#))
        XP2#[I]=(XA#*cos(S1#)-YA#*sin(S1#))
        YP2#[I]=(XA#*sin(S1#)+YA#*cos(S1#))
        ZP2#[I]=(YP#[I]*sin(S2#)+ZA#*cos(S2#))
        xt#[I]=XMID#+(XP2#[I]*ZOOM#)/(ZP2#[I]+DIST#)
        yt#[I]=YMID#+(YP2#[I]*ZOOM#)/(ZP2#[I]+DIST#)
    next I
    thick#=2
    spriteline(1,xt#[1],yt#[1],xt#[2],yt#[2],thick#,255,255,0)
    spriteline(2,xt#[2],yt#[2],xt#[3],yt#[3],thick#,255,255,0)
    spriteline(3,xt#[3],yt#[3],xt#[4],yt#[4],thick#,255,255,0)
    spriteline(4,xt#[4],yt#[4],xt#[1],yt#[1],thick#,255,255,0)
    spriteline(5,xt#[5],yt#[5],xt#[6],yt#[6],thick#,255,255,0)
    spriteline(6,xt#[6],yt#[6],xt#[7],yt#[7],thick#,255,255,0)
    spriteline(7,xt#[7],yt#[7],xt#[8],yt#[8],thick#,255,255,0)
    spriteline(8,xt#[8],yt#[8],xt#[5],yt#[5],thick#,255,255,0)
    spriteline(9,xt#[1],yt#[1],xt#[5],yt#[5],thick#,255,255,0)
    spriteline(10,xt#[2],yt#[2],xt#[6],yt#[6],thick#,255,255,0)
    spriteline(11,xt#[3],yt#[3],xt#[7],yt#[7],thick#,255,255,0)
    spriteline(12,xt#[4],yt#[4],xt#[8],yt#[8],thick#,255,255,0)

    // Check for ESC
    if getrawkeypressed(27) then exit
    sync()
loop
end

// Function for drawing line:
//     id = sprite number
//  x1,y1 = Start coordinates of the line
//  x2,y2 = End coordinates of the line
//     th = Thickness of the line in pixels
//  r,g,b = Color of the line in RGB values
function spriteline(id,x1#,y1#,x2#,y2#,th#,r,g,b)
    // Create the line sprite
    if getspriteexists(id)=0
        createsprite(id,0)
        setspriteoffset(id,0,0)
    endif
    // w# = sprite width   a# = sprite rotation angle
    w#=sqrt((x2#-x1#)^2+(y2#-y1#)^2)
    a#=atan((y2#-y1#)/(x2#-x1#))
    // Calculate angle ofsett
    if x2#=>x1# then ao#=0
    if x2#<x1# then ao#=180
    // Draw sprite line
    setspriteangle(id,a#+ao#)
    setspritesize(id,w#,th#)
    setspritepositionbyoffset(id,x1#,y1#)
    setspritecolor(id,r,g,b,255)
endfunction

No media needed, paste in new project, set setup.agc to 1280x800

I found a horrible AppGameKit error, posted it on the google list, as issue 39. I can not have more than 9 variables passed to my function, tried to add alpha, but it ended up with 16777215 as the number always, and therefore making the sprite invisible.
Posted: 11th Sep 2011 16:36
I found a horrible AppGameKit error, posted it on the google list, as issue 39. I can not have more than 9 variables passed to my function, tried to add alpha, but it ended up with 16777215 as the number always, and therefore making the sprite invisible.

Its not an error but an agk limit!

If you check the documentation online.

I hope they remove it in later releases

Looks awesome by the way!