Author Topic: % Customising Syntax  (Read 2086 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
% Customising Syntax
« on: November 03, 2014, 12:15:35 PM »
% line glBegin GL_LINES : glVertex3f (%1) : glVertex3f (%3) : glEnd

line (0,0,-1) to (0,1,-1)

expands to:

glBegin GL_LINES : glVertex3f (0,0,-1) : glVertex3f (0,1,-1) : glEnd

Mike Lobanovsky

  • Guest
Re: % Customising Syntax
« Reply #1 on: November 03, 2014, 02:23:45 PM »
Can the same be done for Polygon, Circle, Arc, Point, etc. to obtain a standard set of BASIC-like graphics primitives? Noobs will be happy... :)

Charles Pegge

  • Guest
Re: % Customising Syntax
« Reply #2 on: November 03, 2014, 11:14:02 PM »
Possibly, Mike.

The underlying functions can be made poymorphic for additional flexibility:

for instance arcs (and fans) can be used for all arcs, circles and symmetrical polygons:

optional Radius, startAng, EndAng, step

Code: OxygenBasic
  1.   sub arc(optional float r,a,b,s)
  2.   ===============================
  3.   float ar,br,c
  4.   if not r then r=1.0
  5.   if a=0. and b=0. then b=360
  6.   if not s then s=5.0
  7.   if s<0. then s=-s
  8.   if b<a then c=a : a=b : b=c 'swap
  9.  glBegin GL_LINE_STRIP
  10.   do
  11.     ar=rad(a)
  12.     br=rad(b)
  13.     glVertex2f r*cos(ar),r*sin(ar)
  14.     a+=s
  15.     if a>=b
  16.       glVertex2f r*cos(br),r*sin(br)
  17.       exit do
  18.     end if
  19.   end do
  20.   glEnd
  21.   end sub
  22.