some fun with planets

New to FreeBASIC? Post your questions here.
h4tt3n
Posts: 691
Joined: Oct 22, 2005 21:12
Location: Denmark

some fun with planets

Postby h4tt3n » Nov 02, 2005 21:11

Hi ppl,

Here goes my first real FB program! It's a simpe graphical simulation of a planet orbiting a sun. Eventually I'm planning on usin it both in a game and in some educational programs.

So far it's just a gui, the physics engine isn't up and running yet, so the planet speed is defined by a simple 1/distance to sun^2


Here's how to control the program:

Left mouse + move mouse left/right = mirror and change orbit size

Right mouse + move mouse left/right = change orbit eccentricity

middle mouse + move left/right = rotate orbit


Code: Select all

''      2-D Simulation of a planetary orbit (two-body problem) v.7.0

''  variables used to calculate the ellipse
dim storakse as double   '' major axis
dim a as double          '' semimajor axis
dim b as double          '' semiminor axis
dim e as double          '' eccentricity
dim BPafstand as double  '' distance betw. foci
dim F1x as integer       '' focus 1's x-value (the sun's coordinate)
dim F1y as integer       '' focus 1's y-value (the sun's coordinate)
dim F2x as integer       '' focus 2's x-value
dim F2y as integer       '' focus 2's y-value
dim vinkel as double     '' angle (degrees - NOT radians!!! ;-D)

''  some other variables
dim Xmus as integer
dim Ymus as integer
dim knap as integer
dim shared Xrec as integer
dim shared Yrec as integer
dim shared as integer P1, P2 = 1

''  variables used to calculate the planet's trajectory (same as ellipse... optimizing?)
dim cX As double
dim cY As double
dim Wid As double
dim Hgt As double
dim angle As double
Dim SinAngle As double
Dim CosAngle As double
Dim Theta As double
Dim DeltaTheta As double
Dim X As double          ''a point on the ellipse.
Dim Y As double
Dim rX As double         '' the point rotated.
Dim rY As double
dim r as double          ''distance between sun and planet

''  mathematical constants
const PI = 3.141592653589793
const toxpi = 2*PI
const radtodeg = toxpi/360

''  physical constants
const G = 6.673e-11
const Msol = 1.989e30
const Mplanet = 3.287e23
const Mtotal = Msol+Mplanet

''  some other constants
const Xellipse = 512     '' ellipse centre x-coordinate (screen centre)
const Yellipse = 384     '' ellipse centre y-coordinate (screen centre)
const farve = &h107010   '' color of the ellipse
const farve2 = &h380808  '' color of the lines intersecting the sun
const farve3 = &h083808  '' color of the crosshair and line connecting sun and planet
const hastighed = 200    '' planet speed

''  define function that calculates rectangular coordinates from polar coordinates (using degrees)
function Rec (Byval Rpol as double, Byval Tpol as double)
   
    Xrec = cos(Tpol*radtodeg)*Rpol
    Yrec = sin(Tpol*radtodeg)*Rpol
   
end function

''  define ellipse subroutine
Sub ellipse (ByVal cX As Single, ByVal cY As Single, ByVal Wid As Single, ByVal Hgt As Single, ByVal angle As Single)

    Dim SinAngle As Single
    Dim CosAngle As Single
    Dim Theta As Single
    Dim DeltaTheta As Single
    Dim X As Single
    Dim Y As Single
    Dim rX As Single
    Dim rY As Single
    Dim CurrentX As Single
    Dim CurrentY As Single

    Angle = Angle * pi / 180
    SinAngle = Sin(Angle)
    CosAngle = Cos(Angle)

    Theta = 0
    DeltaTheta = toxpi / 90

    X = Wid * Cos(Theta)
    Y = Hgt * Sin(Theta)

    rX = cX + X * CosAngle + Y * SinAngle
    rY = cY - X * SinAngle + Y * CosAngle
    CurrentX = rX
    CurrentY = rY
   
    Pset(CurrentX, CurrentY), farve

    Do While Theta < toxpi
       
        Theta = Theta + DeltaTheta
        X = Wid * Cos(Theta)
        Y = Hgt * Sin(Theta)

        rX = cX + X * CosAngle + Y * SinAngle
        rY = cY - X * SinAngle + Y * CosAngle

        Line -(rX, rY), farve
       
    Loop
   
End Sub

screen 20, 16, 2, 1

''  starting values
    Xmus=250
    e=0.5
    vinkel=18
    Theta=4.2

gosub nyellipse

do
   
    SCREENSET P2, P1
    SWAP P2, P1
    CLS

    GETMOUSE Xmus,Ymus,,knap
    if knap=&b1 then gosub nyellipse
    if knap=&b10 then gosub nyeccentricitet
    if knap=&b100 then gosub nyvinkel

''  calculate the x and y values of the foci
    F1x=Xellipse+(cos(vinkel*radtodeg)*(0.5*BPafstand))
    F1y=Yellipse-(sin(vinkel*radtodeg)*(0.5*Bpafstand))
    F2x=Xellipse-(cos(vinkel*radtodeg)*(0.5*BPafstand))
    F2y=Yellipse+(sin(vinkel*radtodeg)*(0.5*Bpafstand))
   
''  calculate planet speed (temporary equation, not realistic)
    r=sqr(abs((Xellipse+rX)-F1x)^2+abs((Yellipse+rY)-F1y)^2)
    Theta=Theta+hastighed*(1/r^2)
    if Theta>=toxpi then Theta=Theta-toxpi
   
''  calculate planet trajectory (pretty much same as drawing ellipse... optimizing?)
    angle=vinkel
    wid=a
    Hgt=b

    Angle = Angle * Pi / 180
    SinAngle = Sin(Angle)
    CosAngle = Cos(Angle)
    X = Wid * Cos(Theta)
    Y = Hgt * Sin(Theta)
    rX = cX + X * CosAngle + Y * SinAngle
    rY = cY - X * SinAngle + Y * CosAngle
   
''  draw lines intersecting through the sun
    line (0, F1y)-(1024, F1y), farve2
    line (F1x, 0)-(F1x, 768), farve2

''  draw ellipse
    ellipse (Xellipse, Yellipse, a, b, vinkel)
   
''  draw line between sun and planet
    line (Xellipse+rX, Yellipse+rY)-(F1x, F1y), farve3
   
''  draw crosshair in focus 2

    ''use this code for static crosshair
    'line (F2x-7, F2y)-(F2x+7, F2y), farve3
    'line (F2x, F2y-7)-(F2x, F2y+7), farve3
   
    ''use this code for revolving crosshair
    Rec (7, vinkel)
    line (F2x, F2y)-(F2x-Xrec, F2y+Yrec), farve3
    line (F2x, F2y)-(F2x+Xrec, F2y-Yrec), farve3
    Rec (7, vinkel+90)
    line (F2x, F2y)-(F2x-Xrec, F2y+Yrec), farve3
    line (F2x, F2y)-(F2x+Xrec, F2y-Yrec), farve3
   
''  draw sun
    CIRCLE (F1x, F1y), 10, &hff6600,,,,f
    CIRCLE (F1x, F1y), 9, &hffee77,,,,f
    CIRCLE (F1x, F1y), 7, &hffffff,,,,f
   
''  draw planet
    circle (Xellipse+rX, Yellipse+rY), 3, &heeaa55,,,,f
   
    '' temporary code for shading far side of planet - just ignore
    'Rec (6, (atn((F1y-(Yellipse+rY))/(F1x-(Xellipse+rX))))/radtodeg+90)
    'line ((Xellipse+rX)-Xrec, (Yellipse+rY)-Yrec)-((Xellipse+rX)+Xrec, (Yellipse+rY)+Yrec),&h997733

''  draw menu in left side of screen
    line (0,0)-(159, 240),&h303030, bf

''  write data in menu
    color &hf0f0f0, &h404040
    print"  SUN               "
    color &hd0d0d0, &h303030
    print"  m:"; Msol
    color &hf0f0f0, &h404040
    print"  PLANET            "
    color &hd0d0d0, &h303030
    print"  m:"; Mplanet
    print"  r:"; int(r)
    print"  v:"; int(hastighed*sqr((1/a)*((2/r)-(1/a)))*100)
    color &hf0f0f0, &h404040
    print"  ELLIPSE           "
    color &hd0d0d0, &h303030
    print"      a:"; a
    print"      b:"; int(b)
    print"      e:"; int(100*e)/100
    print"  f1-f2:"; int(abs(BPafstand))
    print"  angle:"; int(vinkel)
    color &hf0f0f0, &h404040
    print"  MAP SCALE         "
    color &hd0d0d0, &h303030
    print"   size:"
    print"   time:"
    color , &h000000
   
loop until inkey$<>""

end

nyeccentricitet:    ''  calculate ellipse eccentricity

    e=-(0.5*(2*Xellipse-Xmus)/Xellipse)+1
    BPafstand=storakse*e
    a=abs(0.5*storakse)
    b=a*sqr(1-e^2)
   
return

nyellipse:  ''  calculate ellipse size

    storakse=2*(Xellipse-Xmus)
    BPafstand=storakse*e
    a=abs(0.5*storakse)
    b=a*sqr(1-e^2)
   
return

nyvinkel:   ''  calculate ellipse angle
   
   vinkel=abs(((Xmus+Xellipse)/Xellipse)-1)*180

return


Since I'm not too good at either math or programming, I'd like your comments on how to improve this snippet.

regards,
h4tt3n
Dr_D
Posts: 2391
Joined: May 27, 2005 4:59
Contact:

Postby Dr_D » Nov 03, 2005 0:45

It looks cool! :D

If you wanted, you could add some gravitational interaction. FB is plenty fast enough to do it. Here's something I made a while back when I was bored... If you wanna take a look.


Code: Select all

'$STATIC
Option Explicit
Const Pi = 3.1415926535897932, _
Gravity = 6.673 , _
False = 0, _
True = Not False, _
ResX = 1024, _
ResY = 768, _
MidX = ResX\2, _
MidY = ResY\2, _
Bpp = 32


Screenres ResX, ResY, Bpp, 2,1
Screenset 0,1
Randomize Timer



Dim As Single _
Distance, _
Mag, _
Mass_Factor, _
Dx, _
Dy, _
Px, _
Py, _
Mx, _
My, _
Vel

Dim As Integer _
i, i2, R, G, B

Dim As String X


Type PlanetType
    X As Single
    Y As Single
    XVec As Single
    YVec As Single
    Tx As Single
    Ty As Single
    Velocity As Single
    Mass As Single
    Radius As Single
    Orbit_Radius As Single
    Col As Integer
    R As Single
    G As Single
    B As Single
End Type

Dim Body(100) As PlanetType

With Body(0)
    .X = MidX
    .Y = MidY
    .XVec = 0
    .YVec = 0
    .Mass = 1000
    .Radius = 25
    .R = 255
    .G = 255
    .B = 0
End With


With Body(1)
    .Orbit_Radius = 80
    .X = MidX
    .Y = MidY+.Orbit_Radius
    .Mass = 5
    .Radius = 2
    .XVec = Sqr(Gravity*(Body(0).Mass/.Mass)/.Orbit_Radius)
    .YVec = 0
    .R = 128
    .G = 255
    .B = 32
End With

With Body(2)
    .Orbit_Radius = 120
    .X = MidX
    .Y = MidY-.Orbit_Radius
    .Radius = 5
    .Mass = 4
    .XVec = Sqr(Gravity*(Body(0).Mass/.Mass)/.Orbit_Radius)
    .YVec = 0
    .R = 0
    .G = 0
    .B = 255
End With

With Body(3)
    .Orbit_Radius = 200
    .X = MidX
    .Y = MidY+.Orbit_Radius
    .Radius = 10
    .Mass = 15
    .XVec = Sqr(Gravity*(Body(0).Mass/.Mass)/.Orbit_Radius)
    .YVec = 0
    .R = 0
    .G = 255
    .B = 0
End With

If Ubound(Body)>=4 Then
    Dim RandAng As Single, RandOrb As Single
    For i = 4 To Ubound(Body)
        With Body(i)
            RandAng=Rnd*(Pi*2)
            .Orbit_Radius = 300+Rnd*100
            .Mass = .1+Rnd*.25
            .X = MidX-.Orbit_Radius*Sin(RandAng)
            .Y = MidY-.Orbit_Radius*Cos(RandAng)
            .XVec = Sqr(Gravity*(Body(0).Mass/.Mass)/.Orbit_Radius)*Cos(RandAng)
            .YVec = Sqr(Gravity*(Body(0).Mass/.Mass)/.Orbit_Radius)*Sin(-RandAng)
            If Int(Rnd*2)= 0 Then
                .XVec=-.XVec
                .YVec=-.YVec
            End If   
            .Radius = Rnd*1.5
            .R = Rnd*255
            .G = Rnd*255
            .B = Rnd*255
        End With
    Next
End If



Do
    X = Inkey$
    For i = 0 To Ubound(Body)
        Body(i).Tx = Body(i).XVec
        Body(i).Ty = Body(i).YVec
        For i2 = 0 To Ubound(Body)
            If i<>i2 Then
                Distance = ((Body(i).Y-Body(i2).Y)^2) + ((Body(i).X-Body(i2).X)^2)
                Mag = Sqr(Distance)
                If Mag = 0 Then Mag = 1
                Mass_Factor = Gravity*(((Body(i).Mass) * Body(i2).Mass)) / (Distance^2)
               
                Body(i).Tx -= ((Body(i).X-Body(i2).X)/Mag) * (Mass_Factor/(Body(i).Mass/ Mag)^2)
                Body(i).Ty -= ((Body(i).Y-Body(i2).Y)/Mag) * (Mass_Factor/(Body(i).Mass/ Mag)^2)
            End If
        Next
        Body(i).XVec = Body(i).Tx
        Body(i).YVec = Body(i).Ty       
    Next
   
   
    For i = 0 To Ubound(Body)
        Body(i).X+=Body(i).XVec
        Body(i).Y+=Body(i).YVec
        R = Body(i).R
        G = Body(i).G
        B = Body(i).B
        Circle(Body(i).X, Body(i).Y),Body(i).Radius, Rgb(R,G,B),,,,F
    Next
   
    Sleep 1
    Flip
    Cls
Loop Until X=CHR$(27)
rdc
Posts: 1713
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Postby rdc » Nov 03, 2005 2:08

Both programs are awesome. Dr_D, I noticed that there were some dinosaur killers in your program. :)
jupiter3888
Posts: 103
Joined: Jun 30, 2005 3:54
Location: adelaide, australia
Contact:

Postby jupiter3888 » Nov 03, 2005 8:04

hey, well done to both of you for the great programs.
ive been into this kind of things for a while now, just loving reading about mean anomolies and perterberations :D
where did you find out how to make those programs? i would love a link or something similar.
h4tt3n
Posts: 691
Joined: Oct 22, 2005 21:12
Location: Denmark

Postby h4tt3n » Nov 03, 2005 18:10

Thanks Dr_D, that was just what I was looking for! ^^

I cant wait to merge those two programs. The result has to be pretty sweet. I take it, you don't mind that I modify your code and use it?


Jupiter3888,

I'm totally new with FB, and I'm surprised I even managed to get this far in a week or so. I made my program from basic knowledge about Kepler's and Newton's laws and about how an ellipse is constructed. The nice ppl here on the forum has helped me along a lot when I got stuck, so just ask! :D

There's a FB manual lying around somewhere on the net you might want to download, but I cant find a link just now...

regards,
h4tt3n
Dr_D
Posts: 2391
Joined: May 27, 2005 4:59
Contact:

Postby Dr_D » Nov 03, 2005 22:02

No, I don't mind at all. Actually, that's why I posted it. ;)
h4tt3n
Posts: 691
Joined: Oct 22, 2005 21:12
Location: Denmark

Postby h4tt3n » Nov 15, 2005 21:41

Here's an improved version of Dr_D's cool gravity simulation. Now it runs smoother and it has more realistic interaction since I've entirely rewritten the physics part of it.

This version simulates the inner solar system, which is quite boring ;-D. Try to meddle around with the masses and distances to get some fun effects!

Code: Select all

''      Real-time gravity simulator

Option Explicit

Randomize Timer

Const Pi = 3.1415926535897932, _
Gravity = 6.673e-11 , _
ResX = 1024, _
ResY = 768, _
MidX = ResX/2, _
MidY = ResY/2

dim as integer _
i, i2, R, G, B, _
P1, P2 = 1

Dim As single _
Distance, _
Gforce

Type PlanetType
    X As Single
    Y As Single
    XVec As Single
    YVec As Single
    Velocity As Single
    Mass As Single
    Radius As Single
    Orbit_Radius As Single
    Angle as single
    R As Single
    G As Single
    B As Single
End Type

Dim Body(200) As PlanetType

'' The Sun
With Body(0)
    .X = MidX
    .Y = MidY
    .Mass = 6e12
End With

'' Mercury
With Body(1)
    .Orbit_Radius = 40
    .Angle = Rnd*(Pi*2)
    .X = MidX-.Orbit_Radius*Sin(.Angle)
    .Y = MidY-.Orbit_Radius*Cos(.Angle)
    .Mass = 3e9
    .Radius = 2.5
    .XVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 255
    .G = 192
    .B = 96
End With

'' Venus
With Body(2)
    .Orbit_Radius = 90
    .Angle = Rnd*(Pi*2)
    .X = MidX-.Orbit_Radius*Sin(.Angle)
    .Y = MidY-.Orbit_Radius*Cos(.Angle) 
    .Mass = 2e10
    .Radius = 3.5
    .XVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 255
    .G = 255
    .B = 128
End With

'' Earth
With Body(3)
    .Orbit_Radius = 140
    .Angle = Rnd*(Pi*2)
    .X = MidX-.Orbit_Radius*Sin(.Angle)
    .Y = MidY-.Orbit_Radius*Cos(.Angle)
    .Mass = 2e10
    .Radius = 4
    .XVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 32
    .G = 160
    .B = 255
End With

'' The Moon
With Body(4)
    .Orbit_Radius = 10
    .Angle = Rnd*(Pi*2)
    .X = Body(3).X-.Orbit_Radius*Sin(.Angle)
    .Y = Body(3).Y-.Orbit_Radius*Cos(.Angle)
    .Mass = 1e5
    .Radius = 1
    .XVec = Body(3).Xvec-sqr((Gravity*Body(3).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = Body(3).Yvec-sqr((Gravity*Body(3).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 192
    .G = 192
    .B = 192
End With

'' Mars
With Body(5)
    .Orbit_Radius = 250
    .Angle = Rnd*(Pi*2)
    .X = MidX-.Orbit_Radius*Sin(.Angle)
    .Y = MidY-.Orbit_Radius*Cos(.Angle)
    .Mass = 5e9
    .Radius = 2.5
    .XVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 255
    .G = 140
    .B = 64
End With

'' Phobos
With Body(6)
    .Orbit_Radius = 5
    .Angle = Rnd*(Pi*2)
    .X = Body(5).X-.Orbit_Radius*Sin(.Angle)
    .Y = Body(5).Y-.Orbit_Radius*Cos(.Angle)
    .Mass = 1e5
    .Radius = 0.5
    .XVec = Body(5).Xvec-sqr((Gravity*Body(5).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = Body(5).Yvec-sqr((Gravity*Body(5).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 192
    .G = 192
    .B = 192
End With

'' Deimos
With Body(7)
    .Orbit_Radius = 8
    .Angle = Rnd*(Pi*2)
    .X = Body(5).X-.Orbit_Radius*Sin(.Angle)
    .Y = Body(5).Y-.Orbit_Radius*Cos(.Angle)
    .Mass = 5e5
    .Radius = 0.5
    .XVec = Body(5).Xvec-sqr((Gravity*Body(5).Mass)/.Orbit_Radius)*Cos(.Angle)
    .YVec = Body(5).Yvec-sqr((Gravity*Body(5).Mass)/.Orbit_Radius)*Sin(-.Angle)
    .R = 192
    .G = 192
    .B = 192
End With

'' Asteroid belt
For i = 8 To Ubound(Body)
    With Body(i)
        .Angle = Rnd*(Pi*2)
        .Orbit_Radius = 330+Rnd*40
        .Mass = 1e5+rnd*10e5
        .X = MidX-.Orbit_Radius*Sin(.Angle)
        .Y = MidY-.Orbit_Radius*Cos(.Angle)
        .XVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Cos(.Angle)
        .YVec = sqr((Gravity*Body(0).Mass)/.Orbit_Radius)*Sin(-.Angle)
        If Int(Rnd*42) = 0 Then
            .XVec =- .XVec
            .YVec =- .YVec
        End If
        .Radius = .mass/6e5
        .R = 64+Rnd*191
        .G = .R-48+Rnd*48
        .B = .G-48+Rnd*48
    End With
Next

screen 20, 16, 2, 1

setmouse ,,0

Do
   
    SCREENSET P2, P1
    SWAP P2, P1
    CLS

    For i = 0 To Ubound(Body)
        For i2 = 0 To Ubound(Body)
            If i2 <> i Then
            Distance = sqr((Body(i).Y-Body(i2).Y)^2+(Body(i).X-Body(i2).X)^2)
            Gforce = Gravity*((Body(i).Mass*Body(i2).Mass)/Distance^2)
            Body(i).Xvec -= ((Body(i).X-Body(i2).X)/Distance)*(Gforce/Body(i).Mass)
            Body(i).Yvec -= ((Body(i).Y-Body(i2).Y)/Distance)*(Gforce/Body(i).Mass)
            End If
        Next
    Next
   
    'Body(0).X += Body(0).XVec  ''uncomment to make the sun react on gravitiational influence
    'Body(0).Y += Body(0).YVec
    Circle (Body(0).X, Body(0).Y), 13, &hff6600,,,,f
    Circle (Body(0).X, Body(0).Y), 12, &hffee77,,,,f
    Circle (Body(0).X, Body(0).Y), 10, &hffffff,,,,f
   
    For i = 1 To Ubound(Body)
        Body(i).X += Body(i).XVec
        Body(i).Y += Body(i).YVec
        R = Body(i).R
        G = Body(i).G
        B = Body(i).B
        Circle(Body(i).X, Body(i).Y), Body(i).Radius, Rgb(R, G, B),,,,F
    Next
   
Loop Until Inkey$=CHR$(27)

end


Have fun!
Regards, h4tt3n
jupiter3888
Posts: 103
Joined: Jun 30, 2005 3:54
Location: adelaide, australia
Contact:

good work!

Postby jupiter3888 » Nov 16, 2005 9:24

Nice work man! I especially like it that you also included the moons of each of the planets shown plus the asteroid belt.
Although i happened to notice that around 4 of your asteroids in the belt were orbiting in a retrograde motion, that is opposite to the direction of the main group. Most of the asteroids were orbiting in a clockwise fashion but around 4 were orbiting in an anti-clockwise way. Is this an error or was it intentionally put in?
h4tt3n
Posts: 691
Joined: Oct 22, 2005 21:12
Location: Denmark

Postby h4tt3n » Nov 16, 2005 12:09

Hi Jupiter3888,

It was put there intentionally. Here's the snippet that takes care of it. It's about 2/3 down in the part called asteroid belt.


Code: Select all

If Int(Rnd*42) = 0 Then 
            .XVec =- .XVec
            .YVec =- .YVec
        End If


Basically it flips a 42 sided dice. If the result is zero the vectors are changed from positive to negative value ie retrograde motion. You can change the ratio by putting in another number - 2 will result in equal retrograde and "normal" orbits.

Best regards,
h4tt3n
jupiter3888
Posts: 103
Joined: Jun 30, 2005 3:54
Location: adelaide, australia
Contact:

Postby jupiter3888 » Nov 16, 2005 23:03

oohhhhh so thats what that part of the code does. thanks for the explanation h4tt3n.
Dr_D
Posts: 2391
Joined: May 27, 2005 4:59
Contact:

Postby Dr_D » Jan 30, 2008 6:23

HI! :p

I was just messing around, and I decided to update this code to use fbext. I've added the code and an exe, just in case anyone wanted to take a peek but can't compile. ;)


http://dave-stanley.dyndns.org/programs/gravity.zip
h4tt3n
Posts: 691
Joined: Oct 22, 2005 21:12
Location: Denmark

Postby h4tt3n » Jan 30, 2008 22:52

LOL!

Dr_D, I cant believe you revived a 2 year old thread. Fun to look back, though - man I've learned a lot since then... ^^

This vector library thing that aparently is built into fbext reminds me that I've made a pretty decent such library too recently but never got around posting it.

I call it FB_vector, and it works with 2d and 3d vectors. It uses operator overloading and comes with a huge pile of versatile vector functions too.

So, here it is - applied to a gravity program similar to my old one (use mouse to navigate) (sorry about the square planets... havent gotten around to texturing them 8-/).

http://www.jernmager.dk/stuff/advanced_gravity.zip

best regards,
Michael
Dr_D
Posts: 2391
Joined: May 27, 2005 4:59
Contact:

Postby Dr_D » Jan 30, 2008 23:01

hehehe... it bothers some people, but i don't care. :p

i can't actually see any gfx in your demo. :\

also, your vector lib looks good.. very similar to fbext. we've gone a step further and added matrices to the mix though. nice work. :)

Also, I don't know if you've ever seen this: http://aapproj.phatcode.net/fbgfx/demos/Planets.zip

It's old now, but it's still pretty cool, i think. ;)
integer
Posts: 380
Joined: Feb 01, 2007 16:54
Location: usa

Postby integer » Jan 31, 2008 15:13

Nice work!
I'm glad you revived the thread.

Question: Since the system uses discrete steps which degenerates into a chaotic system (after a long period), how can this be re-written to use a continuous function?

Since all variables are constantly changing all the time, it just appears to be an impossible task.

How can the discrete bumps be smoothed out?
h4tt3n
Posts: 691
Joined: Oct 22, 2005 21:12
Location: Denmark

Postby h4tt3n » Jan 31, 2008 15:37

Dr_D wrote:i can't actually see any gfx in your demo. :\


Strange... works fine for me. Maybe my general ogl initiation code is buggy. You should be able to see ~ 1000 objects orbiting a central sun.

Dr_D wrote:also, your vector lib looks good.. very similar to fbext. we've gone a step further and added matrices to the mix though. nice work. :)


Thx man. The matrice thing was my next step too. I'll get around to it sometime, I guess :-/

Dr_D wrote:Also, I don't know if you've ever seen this: http://aapproj.phatcode.net/fbgfx/demos/Planets.zip


You bet I have, very nice lil' demo!

best regards

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest