|
|

楼主 |
发表于 2008-8-6 16:48:00
|
显示全部楼层
Re:请教数学问题
已经完全照你说的改了,但是还是不正确,这是一个普通model,里面类名称跟62略有出入。
茶壶仍在乱转。
Public engine1 As TVEngine
Public scene1 As TVScene
Public input1 As TVInputEngine
Public atmos1 As TVAtmosphere
Public fac1 As TVTextureFactory
Public mesh1 As TVMesh
Public imt1 As TVScreen2DImmediate
Public land1 As TVLandscape
Public bDoLoop As Boolean
Public sngWalk As Single
Public sngStrafe As Single
Public sngAngleX As Single
Public sngAngleY As Single
Public me_updown As Single
Public tea_rotx, tea_roty, tea_rotz As Single '茶壶转向
Public tea_posx, tea_posy, tea_posz As Single '茶壶位置
Public CamPos As TV_3DVECTOR
Public CamLookAt As TV_3DVECTOR
Public Function Init_Engine()
Set engine1 = New TVEngine
engine1.SetDebugMode False, False
engine1.Init3DWindowed FormMove.Pic1.hWnd, True
engine1.DisplayFPS True
engine1.SetAngleSystem TV_ANGLE_DEGREE
Set fac1 = New TVTextureFactory
Set scene1 = New TVScene
Set atmos1 = New TVAtmosphere
Set input1 = New TVInputEngine
Set mesh1 = New TVMesh
Set land1 = New TVLandscape
Set land1 = scene1.CreateLandscape("vv")
Set imt1 = New TVScreen2DImmediate
input1.Initialize True, True
fac1.LoadTexture "skybox\up.jpg", "up"
fac1.LoadTexture "skybox\dn.jpg", "down"
fac1.LoadTexture "skybox\lf.jpg", "left"
fac1.LoadTexture "skybox\rt.jpg", "right"
fac1.LoadTexture "skybox\ft.jpg", "front"
fac1.LoadTexture "skybox\bk.jpg", "back"
atmos1.SkyBox_Enable True
atmos1.SkyBox_SetTexture GetTex("front"), GetTex("back"), GetTex("left"), GetTex("right"), GetTex("up"), GetTex("down")
Set mesh1 = scene1.CreateMeshBuilder("cool")
mesh1.CreateTeapot
mesh1.SetPosition 0, 0, 3
mesh1.SetScale 10, 10, 10
mesh1.SetRotation 0, 0, 0
mesh1.SetPosition 0, 0, 0
scene1.SetCamera 0, 0, 0, 0, 0, 3
bDoLoop = True
End Function
Public Function Loop_Engine()
Dim i, j As Single
Do While bDoLoop
engine1.Clear False
scene1.RenderAllMeshes True
land1.Render
atmos1.SkyBox_Render
check_input
For i = 0 To 30
imt1.Action_Begin2D '网格画线
imt1.Draw_Line3D i * 50, 0, 0, (i + 1) * 50, 0, 1000
imt1.Draw_Line3D 0, 0, i * 50, 1000, 0, (i + 1) * 50
imt1.Action_End2D
Next
engine1.RenderToScreen
DoEvents
Loop
End Function
Public Function check_input()
Dim tmpMouseX As Long, tmpMouseY As Long
Dim tmpMouseB1 As Boolean, tmpMouseB2 As Boolean, tmpMouseB3 As Boolean, tmpMouseB4 As Boolean
Dim tmpMouseScrollOld As Long, tmpMouseScrollNew As Long
tmpMouseScrollOld = tmpMouseScrollNew
input1.GetMouseState tmpMouseX, tmpMouseY, tmpMouseB1, tmpMouseB2, tmpMouseB3, tmpMouseB4, tmpMouseScrollNew
sngAngleX = sngAngleX - (tmpMouseY / 100)
sngAngleY = sngAngleY - (tmpMouseX / 100)
sngAngleX = sngAngleX - (tmpMouseY / 100)
sngAngleY = sngAngleY - (tmpMouseX / 100)
If input1.IsKeyPressed(TV_KEY_ESCAPE) = True Then DoLoop = False
If input1.IsKeyPressed(TV_KEY_W) = True Then
sngWalk = 1
ElseIf input1.IsKeyPressed(TV_KEY_S) = True Then
sngWalk = -1
End If
If input1.IsKeyPressed(TV_KEY_A) = True Then
sngStrafe = 1
ElseIf input1.IsKeyPressed(TV_KEY_D) = True Then
sngStrafe = -1
End If
If input1.IsKeyPressed(TV_KEY_C) = True Then
me_updown = -1
End If
'以下为出错部分
If input1.IsKeyPressed(TV_KEY_LEFT) = True Then
tea_roty = tea_roty - engine1.TimeElapsed * 0.2
mesh1.SetRotation 0, tea_roty, 0
End If
If input1.IsKeyPressed(TV_KEY_RIGHT) = True Then
tea_roty = tea_roty + engine1.TimeElapsed * 0.2
mesh1.SetRotation 0, tea_roty, 0
End If
If input1.IsKeyPressed(TV_KEY_UP) = True Then
tea_posx = tea_posx + Cos(tea_roty) * engine1.TimeElapsed * 0.2
tea_posz = tea_posz + Sin(tea_roty) * engine1.TimeElapsed * 0.2
mesh1.SetPosition tea_posx, 0, tea_posz
End If
If input1.IsKeyPressed(TV_KEY_DOWN) = True Then
tea_posx = tea_posx - Cos(tea_roty) * engine1.TimeElapsed * 0.2
tea_posz = tea_posz - Sin(tea_roty) * engine1.TimeElapsed * 0.2
mesh1.SetPosition tea_posx, 0, tea_posz
End If
'以上为运算出错部分
If input1.IsKeyPressed(TV_KEY_ESCAPE) = True Then
bDoLoop = False
End If
If input1.IsKeyPressed(TV_KEY_SPACE) = True Then
me_updown = 1
End If
If sngAngleX > 1.3 Then sngAngleX = 1.3
If sngAngleX < -1.3 Then sngAngleX = -1.3
Select Case sngWalk
Case Is > 0
sngWalk = sngWalk - 0.005 * engine1.TimeElapsed
If sngWalk < 0 Then sngWalk = 0
Case Is < 0
sngWalk = sngWalk + 0.005 * engine1.TimeElapsed
If sngWalk > 0 Then sngWalk = 0
End Select
Select Case sngStrafe
Case Is > 0
sngStrafe = sngStrafe - 0.005 * engine1.TimeElapsed
If sngStrafe < 0 Then sngStrafe = 0
Case Is < 0
sngStrafe = sngStrafe + 0.005 * engine1.TimeElapsed
If sngStrafe > 0 Then sngStrafe = 0
End Select
CamPos.x = CamPos.x + (Cos(sngAngleY) * sngWalk / 2 * engine1.TimeElapsed) + (Cos(sngAngleY + 3.141596 / 2) * sngStrafe / 2 * engine1.TimeElapsed)
CamPos.z = CamPos.z + (Sin(sngAngleY) * sngWalk / 2 * engine1.TimeElapsed) + (Sin(sngAngleY + 3.141596 / 2) * sngStrafe / 2 * engine1.TimeElapsed)
CamPos.y = CamPos.y + me_updown * 10
me_updown = 0
CamLookAt.x = CamPos.x + Cos(sngAngleY)
CamLookAt.y = CamPos.y + Tan(sngAngleX)
CamLookAt.z = CamPos.z + Sin(sngAngleY)
scene1.SetCamera CamPos.x, CamPos.y, CamPos.z, CamLookAt.x, CamLookAt.y, CamLookAt.z
End Function
Public Function Unload_Engine()
Set engine1 = Nothing
End Function
|
|