An example of 3D data modeling based on VB6 + OpenGL

‘Draw n pieces of quadrilaterals to form a continuous color body (three-dimensional polar coordinates):

Dim vx(0 To 3), vy(0 To 3), vz(0 To 3) ‘four vertex coordinates

Dim AD (0 To 3), bd(0 To 3) ‘four-vertex factor

AD (0) = 0: AD (1) = 1: AD (2) = 1: AD (3) = 0.

bd (0) = 0: bd: (1) = 0 bd (2) = 1: bd (3) = 1:

gluLookAt 0, 0, 0.005, 0, 0, 0, 1, 0, 1 ‘perspective (eyes, center, vertex)

glScalef 0.35, 0.35, 0.35 ‘object zoom

Dim x, y, z1, z2, DLT, v As Single

DLT = 0.25

glLineWidth 0 ‘line thick

glpointSize 0

glPushName 6

For bk = -3.2 To 3.2step DLT

For ak = -3.2 To 3.2step DLT

glBegin GL. GL_QUADS

For I = 0 To 3

the av = ak + AD (I) * DLT: bv = bk + bd DLT (I) *

glColor3f (1 – Sin (bv))/2, (1 – Sin (av Xor bv))/2, (1 + Sin (bv))/2 ‘set the current color

‘v = Format(“0.00”, v)

‘bv = Format(“0.00”, bv)

‘use expressions: expr1 = “2 * sin (” & amp; bv & “) “” ‘EvaluateExpr (expr1)’

‘initial: lmda (0) = 1: lmda (1) = 1: lmda (2) = 1: lmda (3) = 1: lmda (4) = 1: lmda (5) = 1: lmda (6) = 1: lmda (7) = 1: lmda (8) = 1: lmda (9) = 1

‘= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

‘s vc1 = Tan (av/3.5 – bv/8) ‘& lt; < < = = = = = = = = = = = = =

vc2 = Tan (bv/3.5 av/8) ‘& lt; < < = = = = = = = = = = = = =

vc33 = 1 * Sin (av – bv) ‘& lt; < < = = = = = = = = = = =

ag (I) = Cos Cos (av) * *’s vc1 (bv)

vy (I) = Sin (av) * Cos * vc2 (bv)

vz(I) = Sin(bv) * vc3

‘= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Next



glVertex3f vx (0), vy (0), vz (0)

glVertex3f vx (1), vy (1), vz (1)

glVertex3f vx (2), vy (2), vz (2)

glVertex3f vx (3), vy (3), vz (3)


‘>

glVertex3f vx (3), vy (3), vz (3)

glVertex3f vx (2), vy (2), vz (2)

glVertex3f vx (1), vy (1), vz (1)

glVertex3f vx (0), vy (0), vz (0)

glEnd

‘”‘ — — — — — — — — — — — — — — — the product calculation, strives for the unit normal vector — — — — — — — — — — — — — — — — —

c = vx (0) – ag (1) : b = vy (0) – vy (1) : a = vz (0) – vz (1)

g = vx (2) – ag (1) : f = vy (2) – vy (1) : e = vz (2) – vz (1)

fx0 = (a * f – b * e)

fy0 = (e * c – a * g)

fz0 = (b * g-f * c)
fz0 = (b * g-f * c)

m = Sqr ((a – b * f * e) ^ 2 + (c – e * a * g) ^ 2 + (g – b * f * c) ^ 2)

fx = fx0/m: fy = fy0/m: fz = fz0/m

‘”‘ — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — –



“>

glBegin GL_LINES

glColor3f (1 + Sin (bv))/2, (1 – Sin (av) + bv)/2, (1 – Sin (bv))/2 ‘set the current color

glVertex3f vx (0), vy (0), vz (0)

glVertex3f vx (0), 1.05 * 1.05 * vy (0), 1.05 * vz (0) ‘unified toward the outside

glVertex3f vx(0) -0.12 * fx, vy(0) -0.12 * fy, vz(0) -0.12 * fz

glEnd

“>

‘glBegin GL_LINES

‘glColor3f (1 + Sin (av))/2, (1 + Sin (av Xor bv))/2, (1 – Sin (av))/2’ set the current color

‘glVertex3f vx(3), vy(3), vz(3)

‘glVertex3f vx(1), vy(1), vz(1)

‘glVertex3f vx(2), vy(2), vz(2)

‘glVertex3f vx(0), vy(0), vz(0)
‘ glVertex3f vx(0), vy(0), vz(0)

‘glEnd

Next

Next

glPopName

Read More: