Author Topic: glLines + stars + flight simulation  (Read 1919 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Guest
glLines + stars + flight simulation
« on: May 16, 2013, 04:13:43 AM »
here's a rude openGL example for lines. the idea is however to generate stars coming from the deep. but I don't know why the starLines coming all from one point. perhaps anybody can help. thanks in advance.

Code: [Select]
  '
  '-- experimental openGL example for generating stars, 16.5.2013
  '-- by frankolinox, version 1.0
  '
  includepath "$\inc\"
  $ FileName "t.exe"
  'include "RTL32.inc"
  'include "RTL64.inc"
  title="Lines & Stars.."
  include "OpenglSceneFrame.inc"

  type theStars
    x as double
    y as double
    z as double
  end type
 
  %maxStars=500
  dim stars(%MaxStars) as theStars
 
  sys seed=0x12345678
  function Randy(sys z1,z2) as sys
    pushad
    z1=z1/64
    sys  rnd
    mov  eax,z2
    sub  eax,z1
    inc  eax
    imul edx,seed,0x8088405
    inc  edx
    mov  seed,edx
    mul  edx
    add  edx,z1
    mov  rnd,edx
    popad
    return rnd
  end function

  sub generateStars( sys index ) as long
    stars(index).x = randy(-25, 25)
    stars(index).y = randy(-25, 25)
    stars(index).z = randy(-30, -60)
  end sub
 
  '-----------------------
    sub Staros
  '=======================
    sys vv
    for vv = 1 to %maxStars
    generateStars(vv)           
    next
    glLineWidth 3.0
    glBegin GL_Lines

      for vv = 1 to %maxStars           
        'glColor4ub randy(0, 255),randy(0, 255),randy(0, 255),randy(0,100)
        glColor3f randy(0, 255),randy(0, 255),randy(0, 255)
        glVertex3f stars(vv).x,stars(vv).y,stars(vv).z

        glColor3f 0,0,0
        glVertex3f stars(vv).x,stars(vv).y,stars(vv).z-5

        stars(vv).z += 20
        if stars(vv).z > 5 then generateStars(vv)
      next
    glEnd   
    end sub

  sub initialize(sys hWnd)
  '=======================
  SetTimer hWnd,1,10,NULL
  end sub
  '

  sub scene(sys hWnd)
  '==================
  '
  static single s1,s2,s3,s4,ang1,angi1=1,ra,ri,i
  '
  glLoadIdentity
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  glClearColor 0.5, 0, 0, 0
  '
  '
  glrotatef    ang1, 0,0,1
  gltranslatef 0,0,-1
  'glscalef     0.001,0.001,0.001
  glscalef     0.01,0.01,0.01
  '
  glLineWidth 1.5
  '
  ri=0
  glBegin GL_LINE_LOOP
  'for i=0 to 360 step 20
  for i=0 to 360 step 10
    'ra=rad(i)
    'glVertex2f cos(ra)*(170+ri),sin(ra)*(170+ri)
    'ri=30-ri
  next
  '------------------------------ //
  staros() ' stars generatings
  glEnd
  '
  '------------------------------ //
  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub

  sub Release(sys hwnd)
  '====================
  killTimer hwnd, 1
  end sub

best regards, frank

X

Charles Pegge

  • Guest
Re: glLines + stars + flight simulation
« Reply #1 on: May 16, 2013, 07:48:03 AM »
Hi Frank

I have extended the particle attributes to include color, velocity, tail length.

Alpha lines make good shooting stars :)

Code: [Select]
 '
  '-- experimental openGL example for generating stars, 16.5.2013
  '-- by frankolinox, version 1.0
  '
  includepath "$\inc\"
  $ FileName "t.exe"
  'include "RTL32.inc"
  'include "RTL64.inc"
  title="Lines & Stars.."
  %ExplicitMain
  include "OpenglSceneFrame.inc"

  type theStars
    float  x,y,z    'position
    float  r,g,b,a  'color
    float  vx,vy,vz 'velocity
    float  l        'length
  end type
  
  %maxStars=1000
  dim stars(%MaxStars) as theStars
  
  sys seed=0x12345678
  function Randy(sys z1,z2) as sys
    pushad
    z1=z1/64
    sys  rnd
    mov  eax,z2
    sub  eax,z1
    inc  eax
    imul edx,seed,0x8088405
    inc  edx
    mov  seed,edx
    mul  edx
    add  edx,z1
    mov  rnd,edx
    popad
    return rnd
  end function

  sub generateStars( sys index )
    stars(index).x = randy(0, 100)-50
    stars(index).y = randy(0, 100)-50
    stars(index).z = randy(0, 10)-110
    stars(index).r = randy(0, 255)*.004
    stars(index).g = randy(0, 255)*.004
    stars(index).b = randy(0, 255)*.004
    stars(index).a = 1.0
    stars(index).vz = randy(0, 255)*.002+.1
    stars(index).l  = randy(0, 255)*.04+1
  end sub
  
  '-----------------------
    sub Staros
  '=======================
    sys vv
    glLineWidth 3.0
    glBegin GL_LINES
      for vv = 1 to %maxStars
        thestars s at (@stars(vv))                
        glColor4f s.r,s.g,s.b,0.0 : glVertex3f s.x,s.y,s.z
        glColor4f s.r,s.g,s.b,s.a : glVertex3f s.x,s.y,s.z+s.l
        if s.z >= 0
          generateStars(vv)
        else
          s.z += s.vz
        end if
      next
    glEnd    
    end sub

  sub initialize(sys hWnd)
  '=======================
  '
  SetTimer hWnd,1,10,NULL
  end sub
  '

  sub scene(sys hWnd)
  '==================
  '
  static single s1,s2,s3,s4,ang1,angi1=.1,ra,ri,i
  '
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  glEnable GL_DEPTH_TEST
  glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
  glEnable GL_BLEND
  glLoadIdentity
  '
  glClearColor 0.1, 0.0, 0.1, 0
  '
  '
  '------------------------------ //
  glRotatef ang1,0,0,1.
  staros() ' stars generatings
  '------------------------------ //
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  '
  end sub

  sub Release(sys hwnd)
  '====================
  killTimer hwnd, 1
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW


Charles

Frankolinox

  • Guest
Re: openGL "keys()" question + glLines + stars + flight simulation
« Reply #2 on: May 17, 2013, 12:29:00 AM »
thanks charles for fixing my example, that's working here now perfect ! :-)

topic "key(s)": I've a question about keys or keystroke concerning openGL..

Code: [Select]
a) question how to handle keystrokes and chars in openGL ?

if key[%VK_SPACE] = 0  then
...
end if

if key[%VK_L] = 1 then
...
end if

if Key(30) < 0 and pic[abc+1]=64 'how I can get the Keycode for chars ?
...
end if

b)
'-------------------- // how to convert keys (arrows and chars) in openGL ? ------------
      case %VK_UP
      ' key [%VK_UP]
         if ISTRUE bKeyDown then
            xpos = xpos - SIN(heading * 0.0174532925) * 0.05
            zpos = zpos - COS(heading * 0.0174532925) * 0.05
            if walkbiasangle >= 359.0 then
               walkbiasangle = 0.0
            else
               walkbiasangle = walkbiasangle + 10
            end if
            walkbias = SIN(walkbiasangle * 0.0174532925) / 20.0
         end if

  

what's the right way for arrow keys (up,down,left,right)  and keyboard chars like "%VK_B or %VK_F" abbrevation for Filter or Blending functions ?

best regards, frank

Charles Pegge

  • Guest
Re: glLines + stars + flight simulation
« Reply #3 on: May 17, 2013, 01:37:41 AM »
Hi Frank,

key[vk_??] gives the state of the key:  down=1 up=0
lastkey holds the VK keycode of the most recent key-press

The best way to monitor key for control purposes, is to use key[..]. Minwin does not have equates for numbers or alphabetics: these are:

0..9 0x30..0x39  | 48..57
A..Z  0x41..0x5A | 65..90

some defined keys:

 % VK_ESCAPE         0x1B
  % VK_SPACE          0x20
  % VK_END            0x23
  % VK_HOME           0x24
  % VK_LEFT           0x25
  % VK_UP             0x26
  % VK_RIGHT          0x27
  % VK_DOWN           0x28
   % VK_INSERT         0x2D
  % VK_DELETE         0x2E

  % VK_F1             0x70
  % VK_F2             0x71
  % VK_F3             0x72
  % VK_F4             0x73
  % VK_F5             0x74
  % VK_F6             0x75
  % VK_F7             0x76
  % VK_F8             0x77
  % VK_F9             0x78
  % VK_F10            0x79
  % VK_F11            0x7A
  % VK_F12            0x7B

  % VK_BACK           0x08
  % VK_TAB            0x09
  % VK_CLEAR          0x0C
  % VK_RETURN         0x0D

  % VK_SHIFT          0x10
  % VK_CONTROL        0x11
  % VK_MENU           0x12
  % VK_PAUSE          0x13
  % VK_CAPITAL        0x14


Charles