vb tv3d 如何在鼠标点击地图(TVMesh)时获得鼠标点击的坐标?
tv3d吧
全部回复
仅看楼主
level 2
xzqsr2010 楼主
Dim result As TVCollisionResult
Set result = Scene.MousePick(MxAbs, MyAbs, 0, TV_TESTTYPE_ACCURATETESTING)
If result.IsCollision Then
Dim MoveTarget As TV_3DVECTOR
MoveTarget = result.GetCollisionImpact
End if
我把一个箱子设定到 MoveTarget 位置,但箱子的位置总是不对。我看了下 MoveTarget 的值,发现 .z 的值总是一个很大的定值,似乎不是鼠标与地面碰撞的坐标呀!求解!
2014年07月12日 13点07分 1
level 10
我已经很久没碰了,这方面的细节都忘了[狂汗]
2014年07月12日 23点07分 2
level 2
xzqsr2010 楼主
我找了下, 这是6.3的SDK里给的<TV3D - Mouse picking + cursor>里面有如下这一段
显然, 他用了Pick.GetImpactPoint以后用计算了一下用方向,得到Direction,再用Direction进行移动,不过这里貌似还是不能获得鼠标点击的位置.
'Terrain Picking
If b1 <> 0 Then
Set Pick = Scene.MousePicking(Mx, My, TV_COLLIDE_LANDSCAPE, TV_TESTTYPE_ACCURATETESTING)
If Pick.IsCollision = True Then
'You can get the picked point with the ImpactPoint method
Destination = Pick.GetImpactPoint
Direction = VNormalize(VSubtract(Destination, Vector(PosX, PosY, PosZ)))
'Obtain the angle with trigo maths
angle = Direction2Ang(Direction.x, Direction.z)
'If Direction.x > 0 Then
' angle = Rad2Deg(Atn(Direction.z / Direction.x))
'Else
' angle = Rad2Deg(Atn(Direction.z / Direction.x)) + 180
'End If
Actor.SetRotation 0, 90 + angle, 0
Walk = True
Actor.SetAnimationName "walk"
End If
End If
'Makes the scientist walking
If Walk = True Then
Dim p As D3DVECTOR
p = VAdd(Vector(PosX, PosY, PosZ), VScale(Direction, TV.TimeElapsed * 0.05))
PosX = p.x
PosZ = p.z
If Int(PosX * 2) = Int(Destination.x * 2) And Int(PosZ * 2) = Int(Destination.z * 2) Then
'If he's reached his destination, stop it !
Walk = False
Actor.SetAnimationName "idle"
End If
End If
2014年07月13日 05点07分 3
level 10
我觉得问题还是出在你那个0上
2014年07月15日 07点07分 4
level 2
xzqsr2010 楼主
0代表所有物体 1代表TVMesh 2好像是TVActor 4好像是TVLandspace等等
这个我特意查过的,应该不会错。况且这种办法有时是好使的,有时不行
(仅对于TVMesh),相同的代码对TVLandspace就非常好使。
嗯...我已改用别的办法了,也可以凑合着用。
另外,也感谢吧主对本帖的大力帮助和支持!
2014年07月17日 09点07分 5
level 1
挖坟[滑稽]
2020年05月13日 15点05分 6
[惊讶]
2020年09月26日 05点09分
2020年09月26日 08点09分
level 1

2020年06月12日 04点06分 7
[惊哭]
2020年09月26日 05点09分
1