• Create Account

## GL_POINTS Sphere

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Acer  Members

Posted 04 October 2001 - 12:25 PM

I have some code that if I dont touch it, it makes a Cube made up of GL_POINTS. Here is some of the code I remember. Const N = 10000 Dim G© as Double Dim X© as Double Dim Y© as Double .... The it has glVertex3D TmpX, TmpY, TmpZ I can alter that buy adding a * TmpZ * TmpX etc. I want to make a Sphere with the GL_POINTS. And maybe make it morph into a Cube and then maybe into a Pyramid. I really just care for the Sphere.

### #2Acer  Members

Posted 04 October 2001 - 02:29 PM

Here is the code to modify:
Const N = 1000

Dim D(N) As Double
Dim x(N) As Double
Dim Y(N) As Double
Dim Z(N) As Double
Dim G(N) As Byte
Dim TmpX As Double
Dim TmpY As Double
Dim TmpZ As Double
Dim C As Double

Private Sub Form_Click()
wglDeleteContext hRC
wglMakeCurrent 0, 0
End
End Sub

Me.Move 0, 0, Screen.Width, Screen.Height
On Error Resume Next
Dim RotX As Double
Dim RotY As Double

InitOpenGL
Me.Show: DoEvents

For C = 0 To N
Z© = Rnd * 360 '' C
Next C
glEnable GL_DEPTH_TEST
Do
RotX = RotX + 2 ''4
RotY = RotY + 2.5 ''5
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
glPushMatrix
glRotated RotX, 1, 0, 0
glRotated RotY, 0, 1, 1
glScalef 0.6, 0.6, 0.6 ''Size
glBegin GL_POINTS ''Object to make shape

For C = 0 To N

glColor3ub 200, 75, 100
glVertex3d TmpX, TmpY, TmpZ

Next C
glEnd
glPopMatrix
SwapBuffers Me.hDC
DoEvents
Loop

End Sub

Private Function InitOpenGL()
Dim PFD As PIXELFORMATDESCRIPTOR
PFD.nVersion = 1
PFD.nSize = Len(PFD)
PFD.dwFlags = PFD_DRAW_TO_WINDOW Or _
PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER
PFD.iLayerType = PFD_MAIN_PLANE
PFD.iPixelType = PFD_TYPE_RGBA
PFD.cColorBits = 16
PFD.cDepthBits = 16

Dim pixelformat As Long

pixelformat = ChoosePixelFormat(Me.hDC, PFD)
SetPixelFormat Me.hDC, pixelformat, PFD

hRC = wglCreateContext(Me.hDC)
wglMakeCurrent Me.hDC, hRC
End Function

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
''Render Y / 30, X / 30
End Sub

wglDeleteContext hRC
wglMakeCurrent 0, 0
End
End Sub

Private Sub Render(RotX As Double, RotY As Double)
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
glPushMatrix
glRotated RotX, 1, 2, 3
glRotated RotY, 2, 1, 1
glScalef 0.5, 0.6, 0.7
glBegin GL_LINES
For C = 0 To N
glColor3f 0, 1, 0

glVertex3d TmpX, TmpY, TmpX * TmpX * TmpZ * TmpY * TmpX * TmpZ
Next C
glEnd
glPopMatrix
SwapBuffers Me.hDC
DoEvents
End Sub

### #3TerranFury  Members

Posted 05 October 2001 - 12:12 PM

This will generate a whole bunch of random points on the surface of a sphere:

Const radius = 10Const numPoints = 1000Dim x As DoubleDim y As DoubleDim z As DoubleDim dist As DoubleFor i = 1 To numPoints      x = rand      y = rand      z = rand      dist = sqr(x ^ 2 + y ^ 2 + z ^ 2)      x = (x / dist) * radius      y = (y / dist) * radius      z = (z / dist) * radius      glVertex3f(x, y, z)Next i

If you want to morph from a cube to a sphere, just put a sixth of your sphere verteces at each cube vertex, then generate sphere positions for each, and linearly interpolate between the two. This only works with points.

Edited by - TerranFury on October 5, 2001 7:16:07 PM

### #4masonium  Members

Posted 05 October 2001 - 02:06 PM

You''ll have to convert it to BASIC, but...

// 0.0174532925199432 is just pi/180
// draws a sphere with tex coords
// lat_step - number of horizontal sections
// long_step - number of vertical sections
// draw_type - how the sphere is to be rendered
void DrawSphere(double radius, int lat_step, int long_step, bool lighting, int draw_type)
{
glPushMatrix();
glBegin(draw_type);

for (double i = 0; i < 180; i += 180/lat_step)
{
for (double j = 0; j < 360; j += 360/long_step)
{
if (lighting)
glNormal3d(cos(DEGTORAD * (j + 360/(long_step * 2))) * sin((i + 180/(lat_step * 2)) * DEGTORAD),
cos((i + 180/(lat_step * 2)) * DEGTORAD),
-sin(DEGTORAD * (j + 360/(long_step * 2))) * sin((i + 180/(lat_step * 2)) * DEGTORAD));

glTexCoord2d(j/360, i/180);

glTexCoord2d(j/360, (i + 180/lat_step)/180);

glTexCoord2d((j + 360/long_step)/360, (i + 180/lat_step)/180);

glTexCoord2d((j + 360/long_step)/360, i/180);
}
}

glEnd();
glPopMatrix();
}

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.