XNA模型变长了?

清晨曦月 元老
博客专家认证
2012-01-19 05:14:42
是酱紫滴:
圆柱体底面中心(0,0,0),顶面中心(0,0,1),半径0.5。我在3DS MAX里面用10个半径0.5,高度0.1的圆柱体垒起来(轴都对齐到原点)。然后放到场景里,并且旋转120。这时候问题来了:
Dim transforms = New Matrix(model.Bones.Count - 1) {}
model.CopyAbsoluteBoneTransformsTo(transforms)
For Each mesh As ModelMesh In model.Meshes
For Each be As BasicEffect In mesh.Effects
be.EnableDefaultLighting()
be.Projection = camera.projection
be.View = camera.view
be.World = transforms(mesh.ParentBone.Index) * _World
Next
mesh.Draw()
Next
创建的摄影机:
view = Matrix.CreateLookAt(New Vector3(0, 0, 10), Vector3.Zero, Vector3.Up)
红色那句,应该就是根源了。这样写的话,不经任何旋转缩放操作的时候,圆柱体用上面函数显示出来竟然底面中心(0,0,0),顶面中心(0,1,0),本来沿着Z轴的,怎么就沿着Y轴了?

当我旋转的时候还没其他问题,但是当我进行pick的时候,竟然发现本应该在(0,0,1)那里的那个BoundingSphere的中心跑到了(0,0,2)那里去,难道我的圆柱体变长了?!

很奇怪的问题,反复尝试很多次,发现只有红色那句像现在这么写还将就着能旋转,但我还要在柱头上加其他模型,还要平移操作,总不能不知所谓的就*2啊。。

求解!


注:PICK的代码用的XNA网站上的示例。红色那行写法也一致啊。。我的_World是这样计算的:
_World = _ScaleWorld * _RotationWorld1 * _TranslationWorld * _RotationWorld2
第一个是缩放操作,第二个是类似自转的旋转,第三个是平移,第四个是类似公转的旋转。感觉没什么问题,把代码贴上:
Protected Friend Overridable Sub Translation(offset As Vector3)
_TranslationWorld *= Matrix.CreateTranslation(offset)
_World = _ScaleWorld * _RotationWorld1 * _TranslationWorld * _RotationWorld2
End Sub
Protected Friend Overridable Sub Rotation1(v3 As Vector3, angle As Single)
_RotationWorld1 *= Matrix.CreateFromAxisAngle(v3, angle)
_World = _ScaleWorld * _RotationWorld1 * _TranslationWorld * _RotationWorld2
End Sub
Protected Friend Overridable Sub Rotation2(v3 As Vector3, angle As Single)
_RotationWorld2 *= Matrix.CreateFromAxisAngle(v3, angle)
_World = _ScaleWorld * _RotationWorld1 * _TranslationWorld * _RotationWorld2
End Sub
Protected Friend Overridable Sub Scale(i As Single)
_ScaleWorld *= Matrix.CreateScale(i)
_World = _ScaleWorld * _RotationWorld1 * _TranslationWorld * _RotationWorld2
End Sub
...全文
102 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
铜臂阿铁木 2012-01-20
  • 打赏
  • 举报
回复
我搞不明白xna啊
josephSC 2012-01-20
  • 打赏
  • 举报
回复
那谢谢了,加个塞接点分~
清晨曦月 元老 2012-01-19
  • 打赏
  • 举报
回复
放这放着吧,啥时候想起来啥时候结了
清晨曦月 元老 2012-01-19
  • 打赏
  • 举报
回复
哎,本想散分,可没有有爱心的童鞋啊。FBX和X的问题。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧