基于VB6+OpenGL的三维数据建模实例

前端之家收集整理的这篇文章主要介绍了基于VB6+OpenGL的三维数据建模实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
'画n片四边形组成连续的彩色体(三维极坐标):
Dim vx(0 To 3),vy(0 To 3),vz(0 To 3) '四顶点坐标
Dim ad(0 To 3),bd(0 To 3) '四顶点因子
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.005,1,1 '视角(眼睛,中心,顶点)
glScalef 0.35,0.35,0.35 '对象缩放
Dim x,y,z1,z2,dlt,v As Single
dlt = 0.25
glLineWidth 0 '线粗
glPointSize 0 '点大小
glPushName 6
For bk = -3.2 To 3.2 Step dlt
For ak = -3.2 To 3.2 Step dlt


glBegin GL.GL_QUADS
For i = 0 To 3
av = ak + ad(i) * dlt: bv = bk + bd(i) * dlt
glColor3f (1 - Sin(bv)) / 2,(1 - Sin(av Xor bv)) / 2,(1 + Sin(bv)) / 2 ' 设置当前色
'av = Format("0.00",av)
'bv = Format("0.00",bv)
'使用表达式:expr1 = "2*sin(" & bv & ")" '''EvaluateExpr(expr1) '
'初始: 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
'=================================
vc1 = Tan(av / 3.5 - bv / 8) '<<<=============
vc2 = Tan(bv / 3.5 - av / 8) '<<<=============
vc3 = 1 * Sin(av - bv) '<<<===========


vx(i) = Cos(av) * Cos(bv) * vc1
vy(i) = Sin(av) * Cos(bv) * vc2
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),vz(3)
glVertex3f vx(2),vz(2)
glVertex3f vx(1),vz(1)
glVertex3f vx(0),vz(0) glEnd ' '''---------------外积计算,求单位法向量----------------- c = vx(0) - vx(1): b = vy(0) - vy(1): a = vz(0) - vz(1) g = vx(2) - vx(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) m = Sqr((a * f - b * e) ^ 2 + (e * c - a * g) ^ 2 + (b * g - 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 ' 设置当前色 glVertex3f vx(0),vz(0) glVertex3f 1.05 * vx(0),1.05 * vy(0),1.05 * vz(0) '统一朝外面 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 ' 设置当前色 ' glVertex3f vx(3),vz(3) ' glVertex3f vx(1),vz(1) ' glVertex3f vx(2),vz(2) ' glVertex3f vx(0),vz(0) ' glEnd Next Next glPopName 原文链接:https://www.f2er.com/vb/257534.html

猜你在找的VB相关文章