Author Topic: C-Style Switch  (Read 3513 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
C-Style Switch
« on: May 23, 2011, 07:41:03 AM »
Two new keywords to support this feature: switch and break

Code: [Select]

  '==============
  'C STYLE SWITCH
  '==============

  for i=0 to 4

  switch i

    case 0
    case 1
    case 2
      print "A"
      break
    case 4
      print "B"
      break
    case else
    print "C"

  end switch

  next

  'RESULTS: 0:A  1:A  2:A  3:C  4:B




Charles
« Last Edit: May 23, 2011, 07:43:44 AM by Charles Pegge »

Peter

  • Guest
Re: C-Style Switch
« Reply #1 on: May 23, 2011, 12:23:48 PM »
Hi Charles,

Do we have no longer  "SELECT CASE"  ?

Here is another case, which makes me headache.    :-[

Code: [Select]
/* OxygenBasic version  o34 */

Long a=10,b=10,size,j
size = a*a*2

Dim Alpha(size) As Long   '<- What ??
For j=0 To size
Alpha(j)=255
Next

Print Alpha(10)

Charles Pegge

  • Guest
Re: C-Style Switch
« Reply #2 on: May 23, 2011, 01:24:06 PM »
Hi Peter,

Switch and break are extras to aid porting C programs into Oxygen :).

Standard Arrays have a fixed memory allocation at compile time so must be sized with a constant, not a variable. There are several ways of creating dynamic arrays. If you need them I can show you the best way depending on the needs of the program.

Code: [Select]

Long j

% a 10
% b 10
% size a*b*2


Dim Alpha(size) As Long

indexbase 0

For j=0 To size
Alpha(j)=255
Next

Print Alpha(10)



Charles

Peter

  • Guest
Re: C-Style Switch
« Reply #3 on: May 23, 2011, 02:30:36 PM »
Thanks Charles.

There are two thing ,which I find important for me.
How can I rotate an object to its centre point ?  OpenGl is in a 2D mode.

I got always 60 Frames , Why ?  I mean, Opengl is hardware!
Are "single's" so slow in OxygenBasic ?  Is there a horsefly ?



[attachment deleted by admin]

Charles Pegge

  • Guest
Re: C-Style Switch
« Reply #4 on: May 23, 2011, 07:08:01 PM »

Peter,

I would rotate individual objects about their z axis, assuming your 2D objects are defined in x y coordinates.


  glpushmatrix
  glTranslatef tra_x, tra_y, tra_z
  glRotatef rot_z, 0.0, 0.0, 1.0 'apply self rotation after any translation
 'plot object..
 glpopmatrix


I think the OS may be restricting your frame rate - this behaviour will not be the same on all platforms.

Charles

kryton9

  • Guest
Re: C-Style Switch
« Reply #5 on: May 23, 2011, 10:42:56 PM »
Check your opengl settings for your video card Peter. Vertical Sync is probably check marked on and it limits it to around 60 frames per second.
In my case it is in advanced 3d settings for my nvidia card.

[attachment deleted by admin]

Peter

  • Guest
Re: C-Style Switch
« Reply #6 on: May 24, 2011, 05:08:24 AM »
Thanks Charles, K9

I forgot that we have for our graphics card 3D settings .
My frame rates are now 500! For the beginning quite good.

My graphics card is an old relict by Nvidia. If I become 60 years old then will my wife buy a newer card for me. She is so nice to me !   :D  
« Last Edit: May 24, 2011, 05:10:24 AM by peter »