如何显示3D旋转效果?

gougou6 2003-05-15 07:54:10
如上
...全文
68 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
LoveBH 2003-05-15
图形由九个点和点之间的连线构成,其中有一个点在旋转中不动,我们称这个点为基点。因此,本例的关键实际上就是显示出其他八个点相对于基点的位置关系



Private Sub DrawPart()
R = HScroll2.Value
X = HScroll1.Value
Y = VScroll1.Value
'转换为弧度
Angle1 = DTOR(R)
Angle2 = DTOR(Y)
Angle3 = DTOR(X)
Text1.Text = "A1= " & Format(X, "0.00000")
Text2.Text = "A2= " & Format(Y, "0.00000")
Text3.Text = "R1= " & Format(R, "0.00000")
'清除图片框
Pic1.Cls
'初始化各点的位置
d1x = -20: d1y = -20: d1z = 20
d2x = -20: d2y = 20: d2z = 20
d3x = 20: d3y = 20: d3z = 20
d4x = 20: d4y = -20: d4z = 20
d5x = -40: d5y = -40: d5z = -40
d6x = -40: d6y = 40: d6z = -40
d7x = 40: d7y = 40: d7z = -40
d8x = 40: d8y = -40: d8z = -40

'确定八个点与角度的关系
XROT = (d1x * Cos(Angle1)) - (d1y * Sin(Angle1))
YROT = (d1x * Sin(Angle1)) + (d1y * Cos(Angle1))
ZROT = d1z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p1x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p1y = YROT1
p1z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))


XROT = (d2x * Cos(Angle1)) - (d2y * Sin(Angle1))
YROT = (d2x * Sin(Angle1)) + (d2y * Cos(Angle1))
ZROT = d2z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p2x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p2y = YROT1
p2z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

XROT = (d3x * Cos(Angle1)) - (d3y * Sin(Angle1))
YROT = (d3x * Sin(Angle1)) + (d3y * Cos(Angle1))
ZROT = d3z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p3x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p3y = YROT1
p3z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

XROT = (d4x * Cos(Angle1)) - (d4y * Sin(Angle1))
YROT = (d4x * Sin(Angle1)) + (d4y * Cos(Angle1))
ZROT = d4z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p4x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p4y = YROT1
p4z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

XROT = (d5x * Cos(Angle1)) - (d5y * Sin(Angle1))
YROT = (d5x * Sin(Angle1)) + (d5y * Cos(Angle1))
ZROT = d5z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p5x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p5y = YROT1
p5z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

XROT = (d6x * Cos(Angle1)) - (d6y * Sin(Angle1))
YROT = (d6x * Sin(Angle1)) + (d6y * Cos(Angle1))
ZROT = d6z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p6x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p6y = YROT1
p6z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

XROT = (d7x * Cos(Angle1)) - (d7y * Sin(Angle1))
YROT = (d7x * Sin(Angle1)) + (d7y * Cos(Angle1))
ZROT = d7z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p7x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p7y = YROT1
p7z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

XROT = (d8x * Cos(Angle1)) - (d8y * Sin(Angle1))
YROT = (d8x * Sin(Angle1)) + (d8y * Cos(Angle1))
ZROT = d8z
XROT1 = XROT
YROT1 = (YROT * Cos(Angle2)) - (ZROT * Sin(Angle2))
ZROT1 = (YROT * Sin(Angle2)) + (ZROT * Cos(Angle2))
p8x = (XROT1 * Cos(Angle3)) - (ZROT1 * Sin(Angle3))
p8y = YROT1
p8z = (XROT1 * Sin(Angle3)) + (ZROT1 * Cos(Angle3))

'绘制底面
Pic1.Line (p1x, p1y)-(p2x, p2y), RGB(255, 0, 0)
Pic1.Line (p2x, p2y)-(p3x, p3y), RGB(255, 0, 0)
Pic1.Line (p3x, p3y)-(p4x, p4y), RGB(255, 0, 0)
Pic1.Line (p4x, p4y)-(p1x, p1y), RGB(255, 0, 0)

'绘制顶面
Pic1.Line (p5x, p5y)-(p6x, p6y), RGB(0, 255, 0)
Pic1.Line (p6x, p6y)-(p7x, p7y), RGB(0, 255, 0)
Pic1.Line (p7x, p7y)-(p8x, p8y), RGB(0, 255, 0)
Pic1.Line (p8x, p8y)-(p5x, p5y), RGB(0, 255, 0)

'绘制棱
Pic1.Line (p1x, p1y)-(p5x, p5y), RGB(0, 0, 255)
Pic1.Line (p2x, p2y)-(p6x, p6y), RGB(0, 0, 255)
Pic1.Line (p3x, p3y)-(p7x, p7y), RGB(0, 0, 255)
Pic1.Line (p4x, p4y)-(p8x, p8y), RGB(0, 0, 255)

'绘制到中心的八条线
Pic1.Line (p1x, p1y)-(0, 0), RGB(255, 0, 0)
Pic1.Line (p2x, p2y)-(0, 0), RGB(255, 0, 0)
Pic1.Line (p3x, p3y)-(0, 0), RGB(255, 0, 0)
Pic1.Line (p4x, p4y)-(0, 0), RGB(255, 0, 0)
Pic1.Line (p5x, p5y)-(0, 0), RGB(0, 255, 0)
Pic1.Line (p6x, p6y)-(0, 0), RGB(0, 255, 0)
Pic1.Line (p7x, p7y)-(0, 0), RGB(0, 255, 0)
Pic1.Line (p8x, p8y)-(0, 0), RGB(0, 255, 0)
'绘制中心线
Pic1.Line (0, 0)-(X, Y)
End Sub


'转换为弧度
Private Function DTOR(X)
DTOR = X * (3.1415926 / 180)
End Function

Private Sub Form_Load()
'定义坐标系统
Scale (-90, -90)-(90, 90)
'初始化各滚动条控件
HScroll1.Max = 90
HScroll1.Min = -90
HScroll1.LargeChange = 10
HScroll1.SmallChange = 1
HScroll2.Max = 90
HScroll2.Min = -90
HScroll2.LargeChange = 10
HScroll2.SmallChange = 1
VScroll1.Max = 90
VScroll1.Min = -90
VScroll1.LargeChange = 10
VScroll1.SmallChange = 1
End Sub

Private Sub HScroll1_Change()
DrawPart
End Sub

Private Sub HScroll1_Scroll()
DrawPart
End Sub


Private Sub HScroll2_Change()
DrawPart
End Sub

Private Sub HScroll2_Scroll()
DrawPart
End Sub


Private Sub Pic1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'按下左键
If Button = 1 Then
If X > 90 Then X = 90
If X < -90 Then X = -90
If Y > 90 Then Y = 90
If Y < -90 Then Y = -90
HScroll1.Value = X
VScroll1.Value = Y
End If
'按下右键
If Button = 2 Then
If X > 90 Then X = 90
If X < -90 Then X = -90
HScroll2.Value = X
End If
End Sub


Private Sub VScroll1_Change()
DrawPart
End Sub
Private Sub VScroll1_Scroll()
DrawPart
End Sub


回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-15 07:54
社区公告
暂无公告