Author Topic: COVID-19 in QB64  (Read 6648 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
COVID-19 in QB64
« on: June 01, 2020, 03:56:30 am »
WARNING : Use mask. Sanitize your hands after closing the program.

Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6.  
  7. _TITLE "I'm Covid-19"
  8. SCREEN _NEWIMAGE(600, 600, 32)
  9.  
  10.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  11.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  12.  
  13.  
  14. DIM SHARED glAllow AS _BYTE
  15. TYPE vec3
  16.     x AS SINGLE
  17.     y AS SINGLE
  18.     z AS SINGLE
  19.  
  20. TYPE COVID19
  21.     pos AS vec3
  22.     r AS SINGLE
  23.  
  24. DIM SHARED virus AS COVID19
  25.  
  26. virus.r = 0.3
  27.  
  28. glAllow = -1
  29.     _LIMIT 1
  30.  
  31. SUB _GL ()
  32.     STATIC init, aspect, rotY
  33.  
  34.     IF glAllow = 0 THEN EXIT SUB
  35.     IF init = 0 THEN
  36.         init = 1
  37.         aspect = _WIDTH / _HEIGHT
  38.         _glViewport 0, 0, _WIDTH, _HEIGHT
  39.     END IF
  40.  
  41.     _glEnable _GL_DEPTH_TEST
  42.     _glEnable _GL_LIGHTING
  43.     _glEnable _GL_LIGHT0
  44.  
  45.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  46.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  47.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  48.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  49.  
  50.  
  51.  
  52.     _glMatrixMode _GL_PROJECTION
  53.     _gluPerspective 50, aspect, 0.1, 10
  54.  
  55.     _glMatrixMode _GL_MODELVIEW
  56.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  57.  
  58.  
  59.     _glLineWidth 2.0
  60.     _glPointSize 10.0
  61.  
  62.     _glTranslatef virus.pos.x, virus.pos.y, virus.pos.z
  63.     _glRotatef rotY, 0.5, 1, 0
  64.     rotY = rotY + 1
  65.  
  66.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  67.  
  68.     glutSolidSphere virus.r, 20, 20
  69.  
  70.     _glDisable _GL_LIGHTING
  71.     _glColor3f 1, 0, 0
  72.     _glBegin _GL_LINES
  73.     FOR phi = 0.4 TO _PI(2) STEP .5
  74.         FOR theta = 0.3 TO _PI STEP .5
  75.             _glVertex3f virus.r * SIN(theta) * COS(phi), virus.r * SIN(theta) * SIN(phi), virus.r * COS(theta)
  76.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  77.         NEXT
  78.     NEXT
  79.     _glEnd
  80.     _glBegin _GL_POINTS
  81.     FOR phi = 0.4 TO _PI(2) STEP .5
  82.         FOR theta = 0.3 TO _PI STEP .5
  83.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  84.         NEXT
  85.     NEXT
  86.     _glEnd
  87.     _glEnable _GL_LIGHTING
  88.  
  89.  
  90.  
  91.  
  92. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  93.     STATIC internal_vec4(3)
  94.     internal_vec4(0) = x
  95.     internal_vec4(1) = y
  96.     internal_vec4(2) = z
  97.     internal_vec4(3) = w
  98.     glVec4%& = _OFFSET(internal_vec4())
  99.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: COVID-19 in QB64
« Reply #1 on: June 01, 2020, 08:49:25 am »
Nice work, ashishh. I made yours a little more efficient:

Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6.  
  7. _TITLE "I'm Covid-19"
  8. SCREEN _NEWIMAGE(600, 600, 32)
  9.  
  10.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  11.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  12.  
  13.  
  14. DIM SHARED glAllow AS _BYTE
  15. TYPE vec3
  16.     x AS SINGLE
  17.     y AS SINGLE
  18.     z AS SINGLE
  19.  
  20. TYPE COVID19
  21.     POS AS vec3
  22.     r AS SINGLE
  23.  
  24. DIM SHARED virus AS COVID19
  25.  
  26. virus.r = 0.3
  27.  
  28. glAllow = -1
  29.     _LIMIT 1
  30.  
  31. SUB _GL ()
  32.     STATIC init, aspect, rotY
  33.  
  34.     IF glAllow = 0 THEN EXIT SUB
  35.     IF init = 0 THEN
  36.         init = 1
  37.         aspect = _WIDTH / _HEIGHT
  38.         _glViewport 0, 0, _WIDTH, _HEIGHT
  39.     END IF
  40.  
  41.     _glEnable _GL_DEPTH_TEST
  42.     _glEnable _GL_LIGHTING
  43.     _glEnable _GL_LIGHT0
  44.  
  45.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  46.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  47.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  48.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  49.  
  50.  
  51.  
  52.     _glMatrixMode _GL_PROJECTION
  53.     _gluPerspective 50, aspect, 0.1, 10
  54.  
  55.     _glMatrixMode _GL_MODELVIEW
  56.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  57.  
  58.  
  59.     _glLineWidth 2.0
  60.     _glPointSize 10.0
  61.  
  62.     _glTranslatef virus.POS.x, virus.POS.y, virus.POS.z
  63.     _glRotatef rotY, 0.5, 1, 0
  64.     rotY = rotY + 1
  65.  
  66.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  67.  
  68.     glutSolidSphere virus.r, 20, 20
  69.  
  70.     _glDisable _GL_LIGHTING
  71.     _glColor3f 1, 0, 0
  72.     _glBegin _GL_LINES
  73.     'FOR phi = 0.4 TO _PI(2) STEP .5
  74.     'FOR theta = 0.3 TO _PI STEP .5
  75.  
  76.     rr = 0.18
  77.     a = _ASIN(rr / (0.1 + virus.r))
  78.     FOR theta = a TO _PI STEP a
  79.         aa = rr / ((0.1 + virus.r) * SIN(theta))
  80.         FOR phi = aa TO _PI(2) STEP aa
  81.             _glVertex3f virus.r * SIN(theta) * COS(phi), virus.r * SIN(theta) * SIN(phi), virus.r * COS(theta)
  82.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  83.         NEXT
  84.     NEXT
  85.  
  86.     _glEnd
  87.     _glBegin _GL_POINTS
  88.     FOR theta = a TO _PI STEP a
  89.         aa = rr / ((0.1 + virus.r) * SIN(theta))
  90.         FOR phi = aa TO _PI(2) STEP aa
  91.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  92.         NEXT
  93.     NEXT
  94.     _glEnd
  95.     _glEnable _GL_LIGHTING
  96.  
  97.  
  98.  
  99.  
  100. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  101.     STATIC internal_vec4(3)
  102.     internal_vec4(0) = x
  103.     internal_vec4(1) = y
  104.     internal_vec4(2) = z
  105.     internal_vec4(3) = w
  106.     glVec4%& = _OFFSET(internal_vec4())
  107.  

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: COVID-19 in QB64
« Reply #2 on: June 01, 2020, 09:30:13 am »
So Ashish - how would you invisage the cure? Would it be a large razor blade to shave off those stubbles or perhaps a blanket with perferations through which those antenna would fit but the rest of the blanket would encompas the green ball of the virus. Perhaps just a flood of chlorine to overwhelm it. It's actually hard to image something so innocuous is so deadly.

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: COVID-19 in QB64
« Reply #3 on: June 01, 2020, 09:36:09 am »
Nice work, ashishh. I made yours a little more efficient:

Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6.  
  7. _TITLE "I'm Covid-19"
  8. SCREEN _NEWIMAGE(600, 600, 32)
  9.  
  10.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  11.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  12.  
  13.  
  14. DIM SHARED glAllow AS _BYTE
  15. TYPE vec3
  16.     x AS SINGLE
  17.     y AS SINGLE
  18.     z AS SINGLE
  19.  
  20. TYPE COVID19
  21.     POS AS vec3
  22.     r AS SINGLE
  23.  
  24. DIM SHARED virus AS COVID19
  25.  
  26. virus.r = 0.3
  27.  
  28. glAllow = -1
  29.     _LIMIT 1
  30.  
  31. SUB _GL ()
  32.     STATIC init, aspect, rotY
  33.  
  34.     IF glAllow = 0 THEN EXIT SUB
  35.     IF init = 0 THEN
  36.         init = 1
  37.         aspect = _WIDTH / _HEIGHT
  38.         _glViewport 0, 0, _WIDTH, _HEIGHT
  39.     END IF
  40.  
  41.     _glEnable _GL_DEPTH_TEST
  42.     _glEnable _GL_LIGHTING
  43.     _glEnable _GL_LIGHT0
  44.  
  45.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  46.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  47.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  48.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  49.  
  50.  
  51.  
  52.     _glMatrixMode _GL_PROJECTION
  53.     _gluPerspective 50, aspect, 0.1, 10
  54.  
  55.     _glMatrixMode _GL_MODELVIEW
  56.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  57.  
  58.  
  59.     _glLineWidth 2.0
  60.     _glPointSize 10.0
  61.  
  62.     _glTranslatef virus.POS.x, virus.POS.y, virus.POS.z
  63.     _glRotatef rotY, 0.5, 1, 0
  64.     rotY = rotY + 1
  65.  
  66.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  67.  
  68.     glutSolidSphere virus.r, 20, 20
  69.  
  70.     _glDisable _GL_LIGHTING
  71.     _glColor3f 1, 0, 0
  72.     _glBegin _GL_LINES
  73.     'FOR phi = 0.4 TO _PI(2) STEP .5
  74.     'FOR theta = 0.3 TO _PI STEP .5
  75.  
  76.     rr = 0.18
  77.     a = _ASIN(rr / (0.1 + virus.r))
  78.     FOR theta = a TO _PI STEP a
  79.         aa = rr / ((0.1 + virus.r) * SIN(theta))
  80.         FOR phi = aa TO _PI(2) STEP aa
  81.             _glVertex3f virus.r * SIN(theta) * COS(phi), virus.r * SIN(theta) * SIN(phi), virus.r * COS(theta)
  82.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  83.         NEXT
  84.     NEXT
  85.  
  86.     _glEnd
  87.     _glBegin _GL_POINTS
  88.     FOR theta = a TO _PI STEP a
  89.         aa = rr / ((0.1 + virus.r) * SIN(theta))
  90.         FOR phi = aa TO _PI(2) STEP aa
  91.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  92.         NEXT
  93.     NEXT
  94.     _glEnd
  95.     _glEnable _GL_LIGHTING
  96.  
  97.  
  98.  
  99.  
  100. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  101.     STATIC internal_vec4(3)
  102.     internal_vec4(0) = x
  103.     internal_vec4(1) = y
  104.     internal_vec4(2) = z
  105.     internal_vec4(3) = w
  106.     glVec4%& = _OFFSET(internal_vec4())
  107.  

Why did you evolve the virus?

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: COVID-19 in QB64
« Reply #4 on: June 01, 2020, 07:54:32 pm »
Hy Guys

@  Ashish Cool your coronavirus' motion

@ Vince Yes the surface now is more regular... it is a mutant kind of coronavirus

I'm following Ashish tutorial on Opengl, but slowly!
So I decide to try a tip to get a second littler coronavirus together with the first showed by Ashish's code....
and for error of my presupponitions I get this MAD coronavirus
Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6.  
  7. _TITLE "I'm Covid-19"
  8. SCREEN _NEWIMAGE(600, 600, 32)
  9.  
  10.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  11.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  12.  
  13.  
  14. DIM SHARED glAllow AS _BYTE
  15. TYPE vec3
  16.     x AS SINGLE
  17.     y AS SINGLE
  18.     z AS SINGLE
  19.  
  20. TYPE COVID19
  21.     POS AS vec3
  22.     r AS SINGLE
  23.  
  24. DIM SHARED virus AS COVID19, viru AS COVID19
  25.  
  26. viru.r = 0.10
  27. viru.POS.x = .3
  28. viru.POS.y = .3
  29. viru.POS.z = .3
  30.  
  31. virus.r = 0.3
  32.  
  33. glAllow = -1
  34.     _LIMIT 1
  35.  
  36. SUB _GL ()
  37.     STATIC init, aspect, rotY
  38.  
  39.     IF glAllow = 0 THEN EXIT SUB
  40.     IF init = 0 THEN
  41.         init = 1
  42.         aspect = _WIDTH / _HEIGHT
  43.         _glViewport 0, 0, _WIDTH, _HEIGHT
  44.     END IF
  45.  
  46.     _glEnable _GL_DEPTH_TEST
  47.     _glEnable _GL_LIGHTING
  48.     _glEnable _GL_LIGHT0
  49.  
  50.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  51.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  52.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  53.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  54.  
  55.  
  56.  
  57.     _glMatrixMode _GL_PROJECTION
  58.     _gluPerspective 50, aspect, 0.1, 10
  59.  
  60.     _glMatrixMode _GL_MODELVIEW
  61.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  62.  
  63.  
  64.     _glLineWidth 2.0
  65.     _glPointSize 10.0
  66.  
  67.     _glTranslatef virus.POS.x, virus.POS.y, virus.POS.z
  68.     _glRotatef rotY, 0.5, 1, 0
  69.     rotY = rotY + 1
  70.  
  71.     _glTranslatef viru.POS.x, viru.POS.y, viru.POS.z
  72.     _glRotatef rotY, 0.5, 1, 0
  73.     rotY = rotY + 1
  74.  
  75.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  76.  
  77.     glutSolidSphere virus.r, 20, 20
  78.     glutSolidSphere viru.r, 20, 20
  79.  
  80.     _glDisable _GL_LIGHTING
  81.     _glColor3f 1, 0, 0
  82.     _glBegin _GL_LINES
  83.     FOR phi = 0.4 TO _PI(2) STEP .5
  84.         FOR theta = 0.3 TO _PI STEP .5
  85.             _glVertex3f virus.r * SIN(theta) * COS(phi), virus.r * SIN(theta) * SIN(phi), virus.r * COS(theta)
  86.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  87.  
  88.             _glVertex3f viru.r * SIN(theta) * COS(phi), viru.r * SIN(theta) * SIN(phi), viru.r * COS(theta)
  89.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  90.  
  91.         NEXT
  92.     NEXT
  93.     _glEnd
  94.     _glBegin _GL_POINTS
  95.     FOR phi = 0.4 TO _PI(2) STEP .5
  96.         FOR theta = 0.3 TO _PI STEP .5
  97.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  98.  
  99.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  100.         NEXT
  101.     NEXT
  102.     _glEnd
  103.     _glEnable _GL_LIGHTING
  104.  
  105.  
  106.  
  107.  
  108. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  109.     STATIC internal_vec4(3)
  110.     internal_vec4(0) = x
  111.     internal_vec4(1) = y
  112.     internal_vec4(2) = z
  113.     internal_vec4(3) = w
  114.     glVec4%& = _OFFSET(internal_vec4())
  115.  
  116.  

Thanks to look at
Programming isn't difficult, only it's  consuming time and coffee

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: COVID-19 in QB64
« Reply #5 on: June 02, 2020, 01:35:43 am »
@vince Thanks. You made the spikes to look more uniformly distributed.

@Dimster IDK. I think human will evolve from this. Not all are dying from this idiot virus. OR I think, the one who will be genetically fittest would survive this. I know little about biology, so my opinion may be wrong. :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: COVID-19 in QB64
« Reply #6 on: June 02, 2020, 02:10:29 am »
@TempodiBasic
Very nice try... Look like virus has become very angry. Ok, jokes apart.

You will soon learn all 3D in OpenGL. Its not that too hard.

Okay, so lets talk about your modification to the code.

1. You created another variable of the type COVID19 and initialize its property. Like (r, pos.x, etc). This is fine.

2. The real issue is in SUB _GL() : But why?
You know, I'm using a command _glTranslatef. But what this do? Well... The value you pass it to is added to the current origin.
In OpenGL, the initial origin is center of the screen. That is the reference point. In coordinates, you can say origin is (0,0,0).
Now, if you call _glTranslatef 0.5,0.5,0. Origin will become  (0+0.5,0+0.5,0) or (0.5,0.5,0).
If you again call _glTranslatef -0.5,0.5,0. Origin will become  (0.5+(-0.5),0.5+0.5,0+0) or (0,1,0).

You have clearly noticed that in second calling, the positions were not added in (0,0,0) but in (0.5,0.5,0). This is because
(0.5,0.5,0) was our current origin before calling _glTranslatef for second time. As you can see, I already said this above.

And in your code you are doing the same thing. The virus is being drawn, but it inside the my virus, because its radius is small.

In order to render 2 viruses, you need to do this -

(i) translate the origin to my virus position by _glTranslatef

(ii) Do all the drawing stuff

(iii) Return to the our original origin (0,0,0). You can return to the original origin by again calling _glTranslatef with negative sign on the position of my virus. This will make the values to cancel out and the origin is again (0,0,0)

(iv)Now, translate the origin to your virus as you did in your code with _glTranslatef

(v)Do all the drawing stuff for your virus, as you did in your code.

And this must work.
As an exercise, I'm waiting for your new code with above modification.



OMG: This is the longest post I've ever written.  :D

PS: About the weird movement of your virus. That's because, since the origin in your code neither matches virus nor viru, the rotation is done from other origin.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: COVID-19 in QB64
« Reply #7 on: June 02, 2020, 04:10:43 am »
Hi Ashish, thanks for time and energy to pass  me useful informations to do better code in OpenGl!

Last time I have imagined a my way to let see the 2 viruses but the code was uncomplete and I'm tired so I went to bed to get some rest.
Today morning I find your complete answer, but I see also that to complete my way I need to write just a color statement so for now I post this code.  Then I'll try to get the result in a more elegant way following your right suggestions.

COVID19 and its son
Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6. ' 2 Jun, 2020    added a little son of COVID-19  TDB
  7.  
  8. _TITLE "I'm Covid-19 with my little son"
  9. SCREEN _NEWIMAGE(600, 600, 32)
  10.  
  11.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  12.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  13.  
  14.  
  15. DIM SHARED glAllow AS _BYTE
  16. TYPE vec3
  17.     x AS SINGLE
  18.     y AS SINGLE
  19.     z AS SINGLE
  20.  
  21. TYPE COVID19
  22.     POS AS vec3
  23.     r AS SINGLE
  24.  
  25. DIM SHARED virus AS COVID19, viru AS COVID19
  26.  
  27. viru.r = 0.10
  28. viru.POS.x = .5
  29. viru.POS.y = .5
  30. viru.POS.z = .5
  31.  
  32. virus.r = 0.3
  33.  
  34. glAllow = -1
  35.     _LIMIT 1
  36.  
  37. SUB _GL ()
  38.     STATIC init, aspect, rotY
  39.  
  40.     IF glAllow = 0 THEN EXIT SUB
  41.     IF init = 0 THEN
  42.         init = 1
  43.         aspect = _WIDTH / _HEIGHT
  44.         _glViewport 0, 0, _WIDTH, _HEIGHT
  45.     END IF
  46.  
  47.     _glEnable _GL_DEPTH_TEST
  48.     _glEnable _GL_LIGHTING
  49.     _glEnable _GL_LIGHT0
  50.  
  51.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  52.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  53.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  54.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  55.  
  56.  
  57.  
  58.     _glMatrixMode _GL_PROJECTION
  59.     _gluPerspective 50, aspect, 0.1, 10
  60.  
  61.     _glMatrixMode _GL_MODELVIEW
  62.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  63.  
  64.  
  65.     _glLineWidth 2.0
  66.     _glPointSize 10.0
  67.  
  68.     _glTranslatef virus.POS.x, virus.POS.y, virus.POS.z
  69.     _glRotatef rotY, 0.5, 1, 0
  70.     rotY = rotY + 1
  71.  
  72.  
  73.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  74.  
  75.     glutSolidSphere virus.r, 20, 20
  76.  
  77.     _glDisable _GL_LIGHTING
  78.     _glColor3f 1, 0, 0
  79.     _glBegin _GL_LINES
  80.     FOR phi = 0.4 TO _PI(2) STEP .5
  81.         FOR theta = 0.3 TO _PI STEP .5
  82.             _glVertex3f virus.r * SIN(theta) * COS(phi), virus.r * SIN(theta) * SIN(phi), virus.r * COS(theta)
  83.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  84.         NEXT
  85.     NEXT
  86.     _glEnd
  87.     _glBegin _GL_POINTS
  88.     FOR phi = 0.4 TO _PI(2) STEP .5
  89.         FOR theta = 0.3 TO _PI STEP .5
  90.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  91.         NEXT
  92.     NEXT
  93.     _glEnd
  94.  
  95.     '----
  96.  
  97.  
  98.     _glTranslatef viru.POS.x, viru.POS.y, viru.POS.z
  99.     _glRotatef rotY, 0.5, 1, 0
  100.     rotY = rotY + 1
  101.     _glColor3f 0, 1, 0
  102.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  103.  
  104.  
  105.     glutSolidSphere viru.r, 10, 10
  106.  
  107.  
  108.     _glDisable _GL_LIGHTING
  109.     _glColor3f 1, 0, 0
  110.     _glBegin _GL_LINES
  111.     FOR phi = 0.4 TO _PI(2) STEP .5
  112.         FOR theta = 0.3 TO _PI STEP .5
  113.             _glVertex3f viru.r * SIN(theta) * COS(phi), viru.r * SIN(theta) * SIN(phi), viru.r * COS(theta)
  114.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  115.         NEXT
  116.     NEXT
  117.     _glEnd
  118.  
  119.     _glBegin _GL_POINTS
  120.     FOR phi = 0.4 TO _PI(2) STEP .5
  121.         FOR theta = 0.3 TO _PI STEP .5
  122.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  123.         NEXT
  124.     NEXT
  125.     _glEnd
  126.     _glEnable _GL_LIGHTING
  127.  
  128.  
  129. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  130.     STATIC internal_vec4(3)
  131.     internal_vec4(0) = x
  132.     internal_vec4(1) = y
  133.     internal_vec4(2) = z
  134.     internal_vec4(3) = w
  135.     glVec4%& = _OFFSET(internal_vec4())
  136.  

 
Covid19 and its son OpenGl.jpg

PS
https://ashishkingdom.github.io/OpenGL-Tutorials/
I find great this tutorial! But for me some lessons are too plenty of informations that I must take more time to go on.
For now I'm at Texture chapter and I'll coping with the Mask part.
Programming isn't difficult, only it's  consuming time and coffee

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: COVID-19 in QB64
« Reply #8 on: June 02, 2020, 04:26:41 am »
This is what you get if you randomly enter your nose into numbers you shouldn't enter your nose in variables you shouldn't enter your nose in noses which enter their nose in noses which enter noses in noses
Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6. ' 2 Jun, 2020    added a little son of COVID-19  TDB
  7.  
  8. _TITLE "I'm Covid-19 with my little son"
  9. SCREEN _NEWIMAGE(550, 600, 32)
  10.  
  11.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  12.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  13.  
  14.  
  15. DIM SHARED glAllow AS _BYTE
  16. TYPE vec3
  17.     x AS SINGLE
  18.     y AS SINGLE
  19.     z AS SINGLE
  20.  
  21. TYPE COVID19
  22.     POS AS vec3
  23.     r AS SINGLE
  24.  
  25. DIM SHARED virus AS COVID19, viru AS COVID19
  26.  
  27. viru.r = 0.5
  28. viru.POS.x = .75
  29. viru.POS.y = .75
  30. viru.POS.z = .75
  31.  
  32. virus.r = 0.5
  33.  
  34. glAllow = -1
  35.     _LIMIT 50
  36.  
  37. SUB _GL ()
  38.     STATIC init, aspect, rotY
  39.  
  40.     IF glAllow = 0 THEN EXIT SUB
  41.     IF init = 0 THEN
  42.         init = 2
  43.         aspect = _WIDTH / _HEIGHT + 1
  44.         _glViewport 0, 0, _WIDTH, _HEIGHT
  45.     END IF
  46.  
  47.     _glEnable _GL_DEPTH_TEST
  48.     _glEnable _GL_LIGHTING
  49.     _glEnable _GL_LIGHT0
  50.  
  51.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  52.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  53.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 10, 1, 1)
  54.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 5, 1)
  55.  
  56.  
  57.  
  58.     _glMatrixMode _GL_PROJECTION
  59.     _gluPerspective 50, aspect, 0.1, 10
  60.  
  61.     _glMatrixMode _GL_MODELVIEW
  62.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  63.  
  64.  
  65.     _glLineWidth 3.0
  66.     _glPointSize 10.0
  67.  
  68.     _glTranslatef virus.POS.x, virus.POS.y, virus.POS.z
  69.     _glRotatef rotY, 1, 1, 0
  70.     rotY = rotY + 1
  71.  
  72.  
  73.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 1.9, 0, 1)
  74.  
  75.     glutSolidSphere virus.r, 20, 20
  76.  
  77.     _glDisable _GL_LIGHTING
  78.     _glColor3f 1, 0, 0
  79.     _glBegin _GL_LINES
  80.     FOR phi = 0.4 TO _PI(2) STEP .5
  81.         FOR theta = 0.3 TO _PI STEP 5
  82.             _glVertex3f virus.r * SIN(theta) * COS(phi), virus.r * SIN(theta) * SIN(phi), virus.r * COS(theta)
  83.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  84.         NEXT
  85.     NEXT
  86.     _glEnd
  87.     _glBegin _GL_POINTS
  88.     FOR phi = 0.4 TO _PI(2) STEP 1
  89.         FOR theta = 0.3 TO _PI STEP .5
  90.             _glVertex3f (0.1 + virus.r) * SIN(theta) * COS(phi), (0.1 + virus.r) * SIN(theta) * SIN(phi), (0.1 + virus.r) * COS(theta)
  91.         NEXT
  92.     NEXT
  93.     _glEnd
  94.  
  95.     '----
  96.  
  97.  
  98.     _glTranslatef viru.POS.x, viru.POS.y, viru.POS.z
  99.     _glRotatef rotY, 0.5, 2, 0
  100.     rotY = rotY + 1
  101.     _glColor3f 0, 1, 0
  102.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  103.  
  104.  
  105.     glutSolidSphere viru.r, 10, 10
  106.  
  107.  
  108.     _glDisable _GL_LIGHTING
  109.     _glColor3f 1, 0, 5
  110.     _glBegin _GL_LINES
  111.     FOR phi = 0.4 TO _PI(2) STEP .5
  112.         FOR theta = 0.3 TO _PI STEP .5
  113.             _glVertex3f viru.r * SIN(theta) * COS(phi), viru.r * SIN(theta) * SIN(phi), viru.r * COS(theta)
  114.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  115.         NEXT
  116.     NEXT
  117.     _glEnd
  118.  
  119.     _glBegin _GL_POINTS
  120.     FOR phi = 0.4 TO _PI(2) STEP .5
  121.         FOR theta = 0.3 TO _PI STEP .5
  122.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  123.         NEXT
  124.     NEXT
  125.     _glEnd
  126.     _glEnable _GL_LIGHTING
  127.  
  128.  
  129. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  130.     STATIC internal_vec4(3)
  131.     internal_vec4(0) = x
  132.     internal_vec4(1) = y
  133.     internal_vec4(2) = z
  134.     internal_vec4(3) = w
  135.     glVec4%& = _OFFSET(internal_vec4())
  136.  
  137.  
basically i randomly picked numbers then changed them

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: COVID-19 in QB64
« Reply #9 on: June 02, 2020, 05:47:31 am »
@TempodiBasic Cool! A very nice start. Oh, before drawing your virus, you forgot to turn on lights effect.
Insert this
Code: QB64: [Select]
  1. _glEnable _GL_LIGHTING
before drawing your sphere. This will turn on lighting effects. :)

Oh, I see, you have completed colors section of OpenGL. You know, the glVec4() I'm using before drawing sphere and its spike is
actually defining its color. ;)) Feel free to modify the color of the son of the virus. :P

@qbkiller101 bruh, man you have changed the aspect. Also, you are passing color value which is greater than 1 using glVec4()
Playing hard with numbers.
Do you really want to play with numbers.... I have a puzzle for you then
Create a 10 digit number so that the first digit is the number of zeros in the number, the second digit is the number of ones in the number, the third digit is the number of twos, etc.
« Last Edit: June 02, 2020, 05:48:50 am by Ashish »
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: COVID-19 in QB64
« Reply #10 on: June 02, 2020, 09:49:11 am »
Hi Ashish,
yes going on with practice I can learn more about _GLcommands
thanks for feedback but please take a look to this new example in which I try to modularize the SUB _GL()

Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6. ' 2 Jun, 2020    added a little son of COVID-19  TDB
  7. ' 2 Jun, 2020    modularizing  the _GL actions   TDB
  8. _TITLE "I'm Covid-19 with my little son"
  9.  
  10. SCREEN _NEWIMAGE(600, 600, 32)
  11.  
  12.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  13.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  14.  
  15. DIM SHARED glAllow AS _BYTE
  16. TYPE vec3
  17.     x AS SINGLE
  18.     y AS SINGLE
  19.     z AS SINGLE
  20.  
  21. TYPE COVID19
  22.     POS AS vec3
  23.     r AS SINGLE
  24.     rotY AS SINGLE
  25.     rotX AS SINGLE
  26.     Vxz AS SINGLE
  27.     Vyz AS SINGLE
  28.  
  29. DIM SHARED virus AS COVID19, viru AS COVID19
  30.  
  31. Initialize
  32.     _LIMIT 1
  33. END ' a logical end to the flow
  34.  
  35. '------------ SUBs and FUNCTIONs----------------------------
  36. SUB Initialize
  37.     viru.r = 0.10
  38.     viru.POS.x = .5
  39.     viru.POS.y = .5
  40.     viru.POS.z = .5
  41.     viru.Vxz = 10
  42.     viru.Vyz = 10
  43.  
  44.     virus.r = 0.3
  45.     virus.POS.y = 0
  46.     virus.POS.x = 0
  47.     virus.POS.z = 0
  48.     virus.Vxz = 20
  49.     virus.Vyz = 20
  50.  
  51.     glAllow = -1
  52.  
  53.  
  54. SUB InitGL (in, aspe)
  55.     IF in = 0 THEN
  56.         in = 1
  57.         aspe = _WIDTH / _HEIGHT
  58.         _glViewport 0, 0, _WIDTH, _HEIGHT
  59.     END IF
  60.  
  61. SUB DrawLines (viru AS COVID19)
  62.     _glColor3f 1, 0, 0
  63.     _glBegin _GL_LINES
  64.     FOR phi = 0.4 TO _PI(2) STEP .5
  65.         FOR theta = 0.3 TO _PI STEP .5
  66.             _glVertex3f viru.r * SIN(theta) * COS(phi), viru.r * SIN(theta) * SIN(phi), viru.r * COS(theta)
  67.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  68.         NEXT
  69.     NEXT
  70.     _glEnd
  71.  
  72.  
  73. SUB DrawPoints (viru AS COVID19)
  74.     _glBegin _GL_POINTS
  75.     FOR phi = 0.4 TO _PI(2) STEP .5
  76.         FOR theta = 0.3 TO _PI STEP .5
  77.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  78.         NEXT
  79.     NEXT
  80.     _glEnd
  81.  
  82. SUB DrawVirus (v AS COVID19)
  83.     ' setting  position and rotation
  84.     _glTranslatef v.POS.x, v.POS.y, v.POS.z
  85.     _glRotatef v.rotY, 0.5, 1, 0
  86.     v.rotY = v.rotY + 1
  87.     _glColor3f 0, 1, 0
  88.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(0, 0.9, 0, 1)
  89.  
  90.     ' make the sphere
  91.     glutSolidSphere v.r, v.Vxz, v.Vyz
  92.  
  93.     _glDisable _GL_LIGHTING
  94.     ' make lines
  95.     DrawLines v
  96.     ' make points
  97.     DrawPoints v
  98.     _glEnable _GL_LIGHTING
  99.  
  100. SUB _GL ()
  101.     STATIC init, aspect, rotY
  102.  
  103.     IF glAllow = 0 THEN EXIT SUB
  104.  
  105.     InitGL init, aspect
  106.  
  107.     _glEnable _GL_DEPTH_TEST
  108.     _glEnable _GL_LIGHTING
  109.     _glEnable _GL_LIGHT0
  110.  
  111.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  112.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  113.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  114.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  115.  
  116.  
  117.  
  118.     _glMatrixMode _GL_PROJECTION
  119.     _gluPerspective 50, aspect, 0.1, 10
  120.  
  121.     _glMatrixMode _GL_MODELVIEW
  122.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  123.  
  124.  
  125.     _glLineWidth 2.0
  126.     _glPointSize 10.0
  127.  
  128.     DrawVirus virus
  129.     DrawVirus viru
  130.  
  131.  
  132. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  133.     STATIC internal_vec4(3)
  134.     internal_vec4(0) = x
  135.     internal_vec4(1) = y
  136.     internal_vec4(2) = z
  137.     internal_vec4(3) = w
  138.     glVec4%& = _OFFSET(internal_vec4())
  139.  

the next step is an array of virus COVID19  :-)
each with its color ;)
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: COVID-19 in QB64
« Reply #11 on: June 02, 2020, 09:56:48 am »
@qbkiller101 
fine evolution of the theme, but its title must be changed into "COVID19 fights COVID20" because it seems that 2 different viruses are competing for the same place!
Programming isn't difficult, only it's  consuming time and coffee

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: COVID-19 in QB64
« Reply #12 on: June 02, 2020, 10:02:32 am »
It's not meant to be anything and btw I don't know 3d graphics at all
I just randomly messed with nubers :\

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: COVID-19 in QB64
« Reply #13 on: June 02, 2020, 10:57:54 am »
Hi guys

see here :-) the task is performed! Here is a family of viruses...LOL thanks to Ashish to start this thread and the tips!

Code: QB64: [Select]
  1. 'COVID-19 in QB64
  2. 'By Ashish
  3. '1 Jun, 2020
  4. '
  5. 'WARNING:Use mask. Apply santizer after closing the program.
  6. ' 2 Jun, 2020    added a little son of COVID-19  TDB
  7. ' 2 Jun, 2020    modularizing  the _GL actions   TDB
  8. '2 Jun, 2020     an array of virus and a continuous restarting by Enter and quit by Space TDB
  9. _TITLE "We are all Covid-19 :-)"
  10.  
  11. SCREEN _NEWIMAGE(600, 600, 32)
  12.  
  13.     SUB glutSolidSphere (BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stack AS LONG)
  14.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
  15.  
  16. DIM SHARED glAllow AS _BYTE
  17. TYPE vec3
  18.     x AS SINGLE
  19.     y AS SINGLE
  20.     z AS SINGLE
  21. TYPE colorRGBA
  22.     R AS SINGLE
  23.     G AS SINGLE
  24.     B AS SINGLE
  25.     A AS SINGLE
  26.  
  27. TYPE COVID19
  28.     POS AS vec3
  29.     r AS SINGLE
  30.     rotY AS SINGLE
  31.     rotX AS SINGLE
  32.     Vxz AS SINGLE
  33.     Vyz AS SINGLE
  34.     C AS colorRGBA
  35.  
  36. DIM SHARED virus(1 TO 10) AS COVID19
  37. Initialize
  38.     k = _KEYHIT
  39.     LOCATE 1, 1: PRINT "Space to quit, Enter to change viruses"
  40.     _LIMIT 1
  41.     IF k = 13 THEN Initialize
  42. LOOP UNTIL k = 32
  43. END ' a logical end to the flow
  44.  
  45. '------------ SUBs and FUNCTIONs----------------------------
  46. SUB Initialize
  47.     FOR z = 1 TO 10 STEP 1
  48.         virus(z).r = 0.1 + (RND / 5)
  49.         virus(z).POS.y = 1 - (RND * 2)
  50.         virus(z).POS.x = 1 - (RND * 2)
  51.         virus(z).POS.z = 0
  52.         virus(z).Vxz = 20 - (RND * 10)
  53.         virus(z).Vyz = 20 - (RND * 10)
  54.         virus(z).C.R = 1 - (RND * 1)
  55.         virus(z).C.G = 1 - (RND * 1)
  56.         virus(z).C.B = 1 - (RND * 1)
  57.         virus(z).C.A = 1 - (RND * 1)
  58.     NEXT z
  59.     glAllow = -1
  60.  
  61.  
  62. SUB InitGL (in, aspe)
  63.     IF in = 0 THEN
  64.         in = 1
  65.         aspe = _WIDTH / _HEIGHT
  66.         _glViewport 0, 0, _WIDTH, _HEIGHT
  67.     END IF
  68.  
  69. SUB DrawLines (viru AS COVID19)
  70.     _glColor3f 1, 0, 0
  71.     _glBegin _GL_LINES
  72.     FOR phi = 0.4 TO _PI(2) STEP .5
  73.         FOR theta = 0.3 TO _PI STEP .5
  74.             _glVertex3f viru.r * SIN(theta) * COS(phi), viru.r * SIN(theta) * SIN(phi), viru.r * COS(theta)
  75.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  76.         NEXT
  77.     NEXT
  78.     _glEnd
  79.  
  80.  
  81. SUB DrawPoints (viru AS COVID19)
  82.     _glBegin _GL_POINTS
  83.     FOR phi = 0.4 TO _PI(2) STEP .5
  84.         FOR theta = 0.3 TO _PI STEP .5
  85.             _glVertex3f (0.1 + viru.r) * SIN(theta) * COS(phi), (0.1 + viru.r) * SIN(theta) * SIN(phi), (0.1 + viru.r) * COS(theta)
  86.         NEXT
  87.     NEXT
  88.     _glEnd
  89.  
  90. SUB DrawVirus (v AS COVID19)
  91.     ' setting  position and rotation
  92.     _glTranslatef v.POS.x, v.POS.y, v.POS.z
  93.     _glRotatef v.rotY, 0.5, 1, 0
  94.     v.rotY = v.rotY + 1
  95.  
  96.     _glEnable _GL_LIGHTING ' thanks to Ashish
  97.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_DIFFUSE, glVec4(v.C.R, v.C.G, v.C.B, v.C.A)
  98.  
  99.     ' make the sphere
  100.     glutSolidSphere v.r, v.Vxz, v.Vyz
  101.  
  102.     _glDisable _GL_LIGHTING
  103.     ' make lines
  104.     DrawLines v
  105.     ' make points
  106.     DrawPoints v
  107.     _glEnable _GL_LIGHTING
  108.  
  109. SUB _GL ()
  110.     STATIC init, aspect
  111.  
  112.     IF glAllow = 0 THEN EXIT SUB
  113.  
  114.     InitGL init, aspect
  115.  
  116.     _glEnable _GL_DEPTH_TEST
  117.     _glEnable _GL_LIGHTING
  118.     _glEnable _GL_LIGHT0
  119.  
  120.     _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(0.0, 0.0, 0.0, 1)
  121.     _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(0.8, 0.8, 0.8, 1)
  122.     _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(1, 1, 1, 1)
  123.     _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(0, 0, 10, 1)
  124.  
  125.  
  126.  
  127.     _glMatrixMode _GL_PROJECTION
  128.     _gluPerspective 50, aspect, 0.1, 10
  129.  
  130.     _glMatrixMode _GL_MODELVIEW
  131.     gluLookAt 0, 0, 2, 0, 0, 0, 0, 1, 0
  132.  
  133.  
  134.     _glLineWidth 2.0
  135.     _glPointSize 10.0
  136.     FOR z = 1 TO 10 STEP 1
  137.         DrawVirus virus(z)
  138.     NEXT z
  139.  
  140.  
  141. FUNCTION glVec4%& (x, y, z, w) 'give the offset of the given vector
  142.     STATIC internal_vec4(3)
  143.     internal_vec4(0) = x
  144.     internal_vec4(1) = y
  145.     internal_vec4(2) = z
  146.     internal_vec4(3) = w
  147.     glVec4%& = _OFFSET(internal_vec4())
  148.  

here a screenshot 
Covid19 we are all viruses OpenGl.jpg

Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: COVID-19 in QB64
« Reply #14 on: June 02, 2020, 11:17:54 am »
@qbkiller101
hey man

your good luck with numbers, also when you have messed them, is clear!
Have you tried at casinò in Las Vegas?
 The nature  makes mutations by messing our inner data! Those mutations sometime  are bad (see genetic illness) some time they are good (see Xmen)!


@vince
I find very interesting how you have uniformed the distribution of spikes on the surface of the virus, I have used the original code of Ashish because on 2 opposite pole it draws a crown.
Programming isn't difficult, only it's  consuming time and coffee