gfxgfxFreeBASIC Games Directory Forumgfxgfx
gfx gfx
gfx
Welcome, Guest. Please login or register. May 23, 2013, 07:16:44 AM

Login with username, password and session length
11.5.2013 - Added a webpage for the latest FBGD competition.

13.3.2013 - Members registrations temporary disabled. For all membership requests, please email me: lachie13@yahoo.com

30.11.2012 - The ninth issue of BASIC Gaming is out! Read it here: http://games.freebasic.net/forum/index.php?topic=560.0

22.11.2012 - Be sure to check our currently running annual FBGD game making competition. This year's theme is SEASONS OF THE YEAR, 300 $ first place prize, and the competition runs till 18th of February. Link: http://games.freebasic.net/forum/index.php?topic=559.0
gfx
gfx
*
gfxgfx
gfxgfx gfxgfx
gfxgfx Home Help Search Login Register   gfxgfx
gfx gfx
gfx
Pages: 1 [2] 3
Print
Author Topic: Blast The Roids [ Now Here! ]  (Read 2969 times)
Brick Break
Forum Sage
*****
Gender: Male
Posts: 412



View Profile
« Reply #15 on: September 15, 2010, 12:52:42 PM »

Rel's version is very similiar to the EXT version, and does not use any dependent vars. What's wrong with that?

Quote
Type Vect2D
        x As Double
        y As Double
End Type

Type Vect3D
        x As Double
        y As Double
        z As Double
End Type

Type Poly2D
        p1 As Vect2D
        p2 As Vect2D
        p3 As Vect2D
End Type

Type Poly3D
        p1 As Vect3D
        p2 As Vect3D
        p3 As Vect3D
End Type

Declare Sub InsidePoly(p As Poly2D, v As Vect2D, Byref inside As Integer = 0)
Declare Sub InsidePoly3D(p As Poly3D, v As Vect3D, Byref inside As Integer = 0)

Not gonna fly.
Logged

rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #16 on: September 17, 2010, 06:28:47 PM »

All you have to do is swap out the x,y with vect2d... etc... It would be a minutes worth of work...

Logged
rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #17 on: September 17, 2010, 06:30:05 PM »

Shoot a triangle into pieces demo!

www.imakegames.com/rolliebollocks/FlatlandDemo.zip
Logged
Brick Break
Forum Sage
*****
Gender: Male
Posts: 412



View Profile
« Reply #18 on: September 17, 2010, 07:40:50 PM »

That was a bit of a change of pace, but I get your point. I'll work on it. Do I have full rights to the source code? I take it you're declaring it public domain, right?
Logged

rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #19 on: September 18, 2010, 02:02:19 PM »

Yes, of course.

The ASM triangle code is property of FB_EXT which runs on a FreeBSD style license. Lachie's PolyDraw cannot be used to make money (according to the license). I don't make money on this, I provide it freely so that math students have access to a repository of useful and fun algorithms. Everything that isn't someone else's (and it's all clearly labeled with maybe the exception of a tip&tricks here and there) is copyright me, but free to use, distribute, to make something with and then sell, is all fine by me.

The new triangle stuff is going to be added in the next release. And I'm adding Cairo as a rendering option, though the base lib will still be FBGFX.



Logged
Lachie Dazdarian
Double dipper
Administrator
Forum Sage
*****
Gender: Male
Posts: 1195


lachie13
View Profile WWW Email
« Reply #20 on: September 18, 2010, 04:43:59 PM »

You cannot use PolyDraw code, extended or any other altered to make money...for example, create PolyDraw Ultra and sell it. You can use it to create commercial products of course. Maybe I wasn't clear in my "licence".
Logged

"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist
rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #21 on: September 18, 2010, 09:55:46 PM »

Here is your polydraw shape rendered in cairo:

Logged
Lachie Dazdarian
Double dipper
Administrator
Forum Sage
*****
Gender: Male
Posts: 1195


lachie13
View Profile WWW Email
« Reply #22 on: September 19, 2010, 09:54:03 AM »

You know, it took me 2 minutes to draw that shape. I wish FB devs were more incentive when it comes to that.
Logged

"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist
rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #23 on: September 19, 2010, 10:35:38 AM »

Same routine renders this:

Logged
Brick Break
Forum Sage
*****
Gender: Male
Posts: 412



View Profile
« Reply #24 on: September 20, 2010, 02:47:57 PM »

Yes, of course.

The ASM triangle code is property of FB_EXT which runs on a FreeBSD style license. Lachie's PolyDraw cannot be used to make money (according to the license). I don't make money on this, I provide it freely so that math students have access to a repository of useful and fun algorithms. Everything that isn't someone else's (and it's all clearly labeled with maybe the exception of a tip&tricks here and there) is copyright me, but free to use, distribute, to make something with and then sell, is all fine by me.

The new triangle stuff is going to be added in the next release. And I'm adding Cairo as a rendering option, though the base lib will still be FBGFX.


What's Rel's licensed under? Is Rel OK with it being public domain?
Logged

relsoft
Recruit
**
Posts: 48


View Profile Email
« Reply #25 on: September 20, 2010, 06:22:58 PM »

I believe I did not write those functions. LOL

Here's a very fast point inside triangle which would work in 3d and 2d (Just set z = 0 for a 2d test):

sub vector_cross (BYVAL v1 as vector3d, BYVAL v2 as vector3d, BYREF vout as vector3d)
    vout.x = (v1.y * v2.z) - (v2.y * v1.z)
    vout.y = (v1.z * v2.x) - (v2.z * v1.x)
    vout.z = (v1.x * v2.y) - (v2.x * v1.y)
end sub

function SameSide(p1 as vector3d,p2 as vector3d, a as vector3d,b as vector3d)
'     cp1
'    /
'   /
'  /\  angle(theta)
' / /
' --------- cp2
' angle should be 0<angle<90 to be on the same side
' of the triangle. Because: cos(a<90) = +; cos(a=90) = 0; cos(a>90) = -.
' So we only check for the dot between the 2 vectors as dot/(mag1*mag2)
' = cos(a).  No need for divide because we only check for sign. :*)
' Nifty huh? Blackpawn rules!!!

dim cp1 as vector3d, cp2 as vector3d
dim ba as vector3d, p1a as vector3d, p2a as vector3d
ba.x = b.x - a.x
ba.y = b.y - a.y
ba.z = b.z - a.z

p1a.x = p1.x - a.x
p1a.y = p1.y - a.y
p1a.z = p1.z - a.z

p2a.x = p2.x - a.x
p2a.y = p2.y - a.y
p2a.z = p2.z - a.z

vector_cross cp1, ba, p1a
vector_cross cp2, ba, p2a
dim dot as single
dot = vector_dot ( cp1, cp2 )
if dot >=0 then
       sameside = TRUE
else
   sameside = FALSE
end if
end function

function point_in_triangle(p as vector3d, a as vector3d,b as vector3d,c as vector3d)
    if SameSide(p,a, b,c) and SameSide(p,b, a,c) and SameSide(p,c, a,b) then
   collide3d_point_in_triangle = TRUE
    else
   collide3d_point_in_triangle = FALSE
end if
end function





For a straight 2d test you could read up back2basic since I have an inside poly demo there (The zooming demo).

An all integer flat triangle routine in just plain old FB code:

sub Rel_Tri_F(  byval x1 as integer, byval y1 as integer,_
                     byval x2 as integer, byval y2 as integer,_
                     byval x3 as integer,byval y3 as integer, byval col as integer)



    dim dx1 as integer, dy1 as integer
    dim dx2 as integer, dy2 as integer
    dim dx3 as integer, dy3 as integer
   

    dim delta1 as integer, delta2 as integer, delta3 as integer
    dim Lx as integer, Rx  as integer
   
    dim p_buffer as integer ptr
   
   
    IF y2 < y1 THEN
        SWAP y1, y2
        SWAP x1, x2
    END IF
    IF y3 < y1 THEN
        SWAP y3, y1
        SWAP x3, x1
    END IF
   
    IF y3 < y2 THEN
        SWAP y3, y2
        SWAP x3, x2
    END IF
   
    dx1 = x2 - x1
    dy1 = y2 - y1
    IF dy1 <> 0 THEN
        delta1 = (dx1 shl 16) \ dy1
    ELSE
        delta1 = 0
    END IF
   
    dx2 = x3 - x2
    dy2 = y3 - y2
    IF dy2 <> 0 THEN
        delta2 = (dx2 shl 16) \ dy2
    ELSE
        delta2 = 0
    END IF


    dx3 = x1 - x3
    dy3 = y1 - y3
    IF dy3 <> 0 THEN
        delta3 = (dx3 shl 16) \ dy3
    ELSE
        delta3 = 0
    END IF
   
   
    'Flat bottom
    'Top part of triangle

    dim y as integer
    dim Lxo as integer, Rxo as integer

    Lx = x1 shl 16
    Rx = Lx
   
    FOR y = y1 TO y2 - 1
        Lxo = Lx shr 16
        Rxo = Rx shr 16
        line(Lxo, y)-(Rxo,y),col
        Lx = Lx + delta1
        Rx = Rx + delta3
    NEXT y

    'Flat top
    'Lower part of triangle

    Lx = x2 shl 16
    FOR y = y2 TO y3
        Lxo = Lx shr 16
        Rxo = Rx shr 16
        line(Lxo, y)-(Rxo,y),col
        Lx = Lx + delta2
        Rx = Rx + delta3
    NEXT y

end sub


Code has the "use" or "abuse" license.
« Last Edit: September 20, 2010, 07:00:21 PM by relsoft » Logged
Brick Break
Forum Sage
*****
Gender: Male
Posts: 412



View Profile
« Reply #26 on: September 20, 2010, 09:37:19 PM »

That first code uses some strange black magic, but Rel_Tri_F is exactly what I need! Thank you! I will treat it as my own.

EDIT: Wait, you used the line() function! Cheater! How sad it is that nobody has made the perfect triangle function yet. It's gotten to the point where I'm considering using voxel graphics instead. It would probably be for the best.
« Last Edit: September 20, 2010, 09:41:06 PM by Brick Break » Logged

rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #27 on: September 21, 2010, 09:26:19 AM »

You can use direct buffer draws if you like but it will be slower than line (by a lot) since you have to perform the Breshenham in loop, and FBGFX has all the data aligned, so it's faster just to use line.

What's wrong with line? What exactly are you looking for?
Logged
Brick Break
Forum Sage
*****
Gender: Male
Posts: 412



View Profile
« Reply #28 on: September 21, 2010, 01:01:13 PM »

You can use direct buffer draws if you like but it will be slower than line (by a lot) since you have to perform the Breshenham in loop, and FBGFX has all the data aligned, so it's faster just to use line.

What's wrong with line? What exactly are you looking for?

Well, what I was looking for was speed, but I didn't know line was faster. Are you sure? Have you done tests?

Also, I thought vertex shading and stuff would be possible if I had per-pixel access, so it would probably be best to start on that level.
Logged

rolliebollocks
Novice
***
Posts: 75


View Profile Email
« Reply #29 on: September 21, 2010, 04:21:15 PM »

@Brick Break

Yes I have. Line wins by a smidge. I tested it when I was making this:


sub ThickLine ( byref screenbuffer as fb.image ptr, byval x1 as units, byval y1 as units, byval x2 as units, byval y2 as units, byval thickness as integer, byval clr as uinteger )
#DEFINE screenxsize 799
#DEFINE screenysize 599
    dim as ubyte ptr pixdata
   
    if screenbuffer = 0 then   
        pixdata = ScreenPtr()
    else
        pixdata =  Cast( Ubyte Ptr, screenbuffer ) + Sizeof( FB.IMAGE )
    endif
   
    dim as units dx(thickness), dy(thickness), l=0.0
   
    for i as integer = 1 to thickness
        dx(i) = ( x2 - (i-1) - x1 - (i-1) )
        dy(i) = ( y2 - (i-1) - y1 - (i-1) )
        l = SQR(dx(i)*dx(i)+dy(i)*dy(i))
        if l then
            dx(i)/=l:dy(i)/=l
        else
            exit sub
        endif
    next
   
    dim as integer xscreen=0, yscreen=0
    for i as units = 0 to l
        for ii as integer = 1 to thickness
            xscreen = x1+(i*dx(ii))
            yscreen = y1+(i*dy(ii))
            if xscreen > screenxsize then Continue For
            if yscreen > screenysize then Continue For
            if xscreen < 0 then Continue For
            if yscreen < 0 then Continue For
            Cast (uinteger ptr, pixdata + ( yscreen * screenbuffer->Pitch ))[ xscreen ] = clr
        next
    next
end sub
Logged
Pages: 1 [2] 3
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Cerberus design by Bloc
Valid XHTML 1.0! Valid CSS!
gfx
gfxgfx gfxgfx