Silverlight5实现类似3DsMax多视图效果

参考XNA利用Viewport实现分屏的思路进行绘制,最终效果:

关键代码如下:

View Code
        private Viewport topViewport;//顶视图
private Viewport frontViewport; //前视图
private Viewport sideViewport;//左视图
private Viewport perspectiveViewport; //透视图

//设置四个不同角度的视图矩阵
private Matrix topView = Matrix.CreateLookAt(new Vector3(0, 5.0f, 0), Vector3.Zero, Vector3.UnitZ);
private Matrix frontView = Matrix.CreateLookAt(new Vector3(0, 0, -5.0f), Vector3.Zero, Vector3.Up);
private Matrix sideView = Matrix.CreateLookAt(new Vector3(-5.0f, 0, 0), Vector3.Zero, Vector3.Up);
private Matrix perspectiveView = Matrix.CreateLookAt(new Vector3(-3.0f, 3.0f, -3.0f), Vector3.Zero, new Vector3(1.0f, 2.0f, 1.0f));

//在DrawingSurface控件的Draw事件里进行绘制
Viewport originalViewport = graphicsDevice.Viewport;//记录原始视图

graphicsDevice.Viewport = topViewport;
currentPrimitive.Draw(world, topView, projection, color);
//gridComponent.Draw(world, topView, projection);

graphicsDevice.Viewport = frontViewport;
currentPrimitive.Draw(world, frontView, projection, color);
//gridComponent.Draw(world, topView, projection);

graphicsDevice.Viewport = sideViewport;
currentPrimitive.Draw(world, sideView, projection, color);
//gridComponent.Draw(world, topView, projection);

graphicsDevice.Viewport = perspectiveViewport;
currentPrimitive.Draw(world, perspectiveView, projection, color);
gridComponent.Draw(world, perspectiveView, projection);

graphicsDevice.Viewport = originalViewport;//还原全屏视图

目前存在的一个问题是:当页面SizeChanged事件改变后会出现视图区域大于或超出当前呈现器目标界限的错误,尚未找到解决方案。

 

代码下载:https://files.cnblogs.com/dfxj/SilverlightApplication3.rar

posted on 2012-02-14 14:56  今天明天  阅读(1870)  评论(6)    收藏  举报