Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


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.

  • You cannot reply to this topic
3 replies to this topic

#1 Acer   Members   -  Reputation: 122

Like
Likes
Like

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.

Sponsor:

#2 Acer   Members   -  Reputation: 122

Like
Likes
Like

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

Private Sub Form_Load()
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
x© = Rnd * 360
Y© = Rnd * 360
Z© = Rnd * 360 '' C
D© = 1
G© = Rnd * 250
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

TmpX = Cos(x© * (100.14 / 280)) * D©
TmpY = -Sin(Y© * (100.14 / 280)) * D©
TmpZ = Cos(Z© * (100.14 / 280)) * D©

''X© = X© + 1
''Y© = Y© + 1
''Z© = Z© + 1
glColor3ub 200, 75, 100
glVertex3d TmpX, TmpY, TmpZ

''D© = D© + ((Rnd / 10) - (0.5 / 10))
''X© = X© + 1
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

Private Sub Form_Unload(Cancel As Integer)
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
TmpX = Cos(x© * (3.14 / 180)) * D©
TmpY = -Sin(Y© * (3.14 / 180)) * D©
TmpZ = Cos(Z© * (3.14 / 180)) * D©
''X© = X© + 1
''Y© = Y© + 1
''Z© = Z© + 1
glColor3f 0, 1, 0

glColor3ub 0, G©, G©
glVertex3d TmpX, TmpY, TmpX * TmpX * TmpZ * TmpY * TmpX * TmpZ
''D© = D© + ((Rnd / 100) - (0.5 / 100))
x© = x© + 1
Next C
glEnd
glPopMatrix
SwapBuffers Me.hDC
DoEvents
End Sub

#3 TerranFury   Members   -  Reputation: 142

Like
Likes
Like

Posted 05 October 2001 - 12:12 PM

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


Const radius = 10
Const numPoints = 1000

Dim x As Double
Dim y As Double
Dim z As Double
Dim dist As Double

For 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

#4 masonium   Members   -  Reputation: 118

Like
Likes
Like

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
// radius - radius
// 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)
{
double DEGTORAD = 0.0174532925199432;
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);
glVertex3d(cos(DEGTORAD * j) * radius * sin(i * DEGTORAD),
cos(i * DEGTORAD) * radius,
-sin(DEGTORAD * j) * radius * sin(i * DEGTORAD));

glTexCoord2d(j/360, (i + 180/lat_step)/180);
glVertex3d(cos(DEGTORAD * j) * radius * sin((i + 180/lat_step) * DEGTORAD),
cos((i + 180/lat_step) * DEGTORAD) * radius,
-sin(DEGTORAD * j) * radius * sin((i + 180/lat_step) * DEGTORAD));

glTexCoord2d((j + 360/long_step)/360, (i + 180/lat_step)/180);
glVertex3d(cos(DEGTORAD * (j + 360/long_step)) * radius * sin((i + 180/lat_step) * DEGTORAD),
cos((i + 180/lat_step) * DEGTORAD) * radius,
-sin(DEGTORAD * (j + 360/long_step)) * radius * sin((i + 180/lat_step) * DEGTORAD));

glTexCoord2d((j + 360/long_step)/360, i/180);
glVertex3d(cos(DEGTORAD * (j + 360/long_step)) * radius * sin(i * DEGTORAD),
cos(i * DEGTORAD) * radius,
-sin(DEGTORAD * (j + 360/long_step)) * radius * sin(i * DEGTORAD));
}
}

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.



PARTNERS