|
Post by wallypog on Jul 29, 2015 14:17:31 GMT -5
Hi everyone; I am having problems translating from Cpp to basic4gl. Hereis what I came up with:
'globals dim c# = 2.0 dim r# = 0.5 dim p = 6 ' Number of grid columns. dim q = 4 ' Number of grid rows dim pi# = m_pi dim &vertices#() = NULL 'map sample to the torus.
'map sample to the torus. function f#(i,j) 'dim f# '(i,j) return ( ( c# + r# * cos( (-1 + 2* j/q) * PI# ) ) * cos( (-1 + 2* i/p) * PI# ) ) end function
function g#(i,j) 'dim g#(i,j) return ( ( c# + r# * cos( (-1 + 2* j/q) * PI# ) ) * sin( (-1 + 2* i/p) * PI# ) ) end function
function h#(i,j) 'dim h#(i,j) return ( r# * sin( (-1 + 2* j/q) * PI#) ) end function
' c#outine to fill the vertex array with ' co-ordinates of the mapped sample points. function fillVertexArray() k = 0 for j = 0 to q for i = 0 to p
k = k+1 :&vertices(k) = f#(i,j) k = k+1 :&vertices(k) = g#(i,j) k = k+1 :&vertices(k) = h#(i,j) next next end function
What am I doing wrong? John
|
|
|
Post by Adam on Jul 29, 2015 20:52:17 GMT -5
It has been a long time since I have written code in basic4gl, but I noticed that you had a couple issues, like your array ( you can't use an array pointer like that I don't believe. here is a revised version, with issues I noticed, it will get you on the right path
'globals dim c# = 2.0 dim r# = 0.5 dim p = 6 ' Number of grid columns. dim q = 4 ' Number of grid rows dim pi# = m_pi dim vertices#(10000)'map sample to the torus. dim k, j, i
'map sample to the torus. function f#(i,j) 'dim f# '(i,j) return ( ( c# + r# * cos( (-1 + 2* j/q) * PI# ) ) * cos( (-1 + 2* i/p) * PI# ) ) end function
function g#(i,j) 'dim g#(i,j) return ( ( c# + r# * cos( (-1 + 2* j/q) * PI# ) ) * sin( (-1 + 2* i/p) * PI# ) ) end function
function h#(i,j) 'dim h#(i,j) return ( r# * sin( (-1 + 2* j/q) * PI#) ) end function
' c#outine to fill the vertex array with ' co-ordinates of the mapped sample points. sub fillVertexArray() k = 0 for j = 0 to q for i = 0 to p k = k+1 :vertices#(k) = f#(i,j) k = k+1 :vertices#(k) = g#(i,j) k = k+1 :vertices#(k) = h#(i,j) next next end sub
fillVertexArray()
|
|
|
Post by wallypog on Jul 30, 2015 11:59:46 GMT -5
Thanks Adam. Silly me , I thought the problem was an array of pointers. Thanks again Adam, your help is much appreciated. Regards, John
|
|
|
Post by wallypog on Aug 2, 2015 11:00:04 GMT -5
Since Basic4gl does not support "glVertxPointer" is there a work around for the following function? Cheers, John ' Drawing routine. function drawScene() 'dim i,j '************************* 'Dynamic array allocation with new value of p and q. newfloat# = newfloat# + (3*(p+1)*(q+10)) vertices# = newfloat# glVertexPointer(3, GL_FLOAT, 0, &vertices#) glClear(GL_COLOR_BUFFER_BIT) glLoadIdentity() gluLookAt(0.0, 0.0, 6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glColor3f(0.0, 0.0, 0.0) ' Rotate scene. glRotatef(Zangle, 0.0, 0.0, 1.0) glRotatef(Yangle, 0.0, 1.0, 0.0); glRotatef(Xangle, 1.0, 0.0, 0.0) end function
|
|
|
Post by matthew on Aug 2, 2015 12:14:11 GMT -5
I believe that the OpenGLPlugin supports glVertexPointer. :-)
|
|
|
Post by wallypog on Aug 3, 2015 12:31:59 GMT -5
Thanks Maththew, I'll check it out.
|
|