第25天Microsoft-Robotics-Developer-Studio中文教程--开始建造迷

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

[RoboticsStudio]开始建造迷宫--Day25编辑整理杜毓聪duyucong@gmail.com的小小梦想之一.要学习走迷宫,第一步需要有迷宫才行.无奈,之前的VisualSimulationEnviromentExpressversion的64个实体物件吓到我了...如何用64个实体来建造伟大的迷宫,我一直是觉得很困难的一件事情...直到,我发现这个64个Entities的限制是--直接放入VSEWorld的实体数量.也就是说,如果我把整个迷宫看成是一个Entity物件,不就解决这样的问题了吗?!所以,可以透过实做MultiShapeEntity这个class来达成梦想的第一步了!viewplaincopytoclipboardprint?1.usingSystem;2.usingSystem.Collections.Generic;3.usingSystem.ComponentModel;4.usingMicrosoft.Ccr.Core;5.usingMicrosoft.Dss.Core.Attributes;6.usingMicrosoft.Dss.ServiceModel.Dssp;7.usingMicrosoft.Dss.ServiceModel.DsspServiceBase;8.usingW3C.Soap;9.usingsubmgr=Microsoft.Dss.Services.SubscriptionManager;10.usingengine=Microsoft.Robotics.Simulation.Engine.Proxy;11.usingMicrosoft.Robotics.Simulation.Engine;12.usingMicrosoft.Robotics.Simulation.Physics;13.usingMicrosoft.Robotics.PhysicalModel;14.15.16.namespaceMazeGenerator17.{18.publicclassMazeEntity:MultiShapeEntity19.{20.///summary21.///Defaultconstructor22.////summary23.publicMazeEntity(){}24.25.///summary26.///Initializationconstructor27.////summary28.///paramname=shape/param29.///paramname=initialPos/param30.publicMazeEntity(Vector3initialPos,byte[,]blocks,floatmazeheight,floatblocksize)31.{32.for(intx=0;xblocks.GetLength(0);x++)33.{34.for(inty=0;yblocks.GetLength(1);y++)35.{36.if(blocks[x,y]==0)37.continue;38.39.varboxshape=newBoxShape(40.newBoxShapeProperties(41.1,//massinkilograms.42.newPose(newVector3(initialPos.X+x*blocksize,initialPos.Y+mazeheight/2,initialPos.Z-y*blocksize)),//relativepose43.newVector3(blocksize,mazeheight,blocksize)));44.45.this.BoxShapes.Add(boxshape);//dimensions46.}47.}48.49.this.State.MassDensity.Mass=blocks.GetLength(0)*blocks.GetLength(1);50.}51.}52.}usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingMicrosoft.Ccr.Core;usingMicrosoft.Dss.Core.Attributes;usingMicrosoft.Dss.ServiceModel.Dssp;usingMicrosoft.Dss.ServiceModel.DsspServiceBase;usingW3C.Soap;usingsubmgr=Microsoft.Dss.Services.SubscriptionManager;usingengine=Microsoft.Robotics.Simulation.Engine.Proxy;usingMicrosoft.Robotics.Simulation.Engine;usingMicrosoft.Robotics.Simulation.Physics;usingMicrosoft.Robotics.PhysicalModel;namespaceMazeGenerator{publicclassMazeEntity:MultiShapeEntity{///summary///Defaultconstructor////summarypublicMazeEntity(){}///summary///Initializationconstructor////summary///paramname=shape/param///paramname=initialPos/parampublicMazeEntity(Vector3initialPos,byte[,]blocks,floatmazeheight,floatblocksize){for(intx=0;xblocks.GetLength(0);x++){for(inty=0;yblocks.GetLength(1);y++){if(blocks[x,y]==0)continue;varboxshape=newBoxShape(newBoxShapeProperties(1,//massinkilograms.newPose(newVector3(initialPos.X+x*blocksize,initialPos.Y+mazeheight/2,initialPos.Z-y*blocksize)),//relativeposenewVector3(blocksize,mazeheight,blocksize)));this.BoxShapes.Add(boxshape);//dimensions}}this.State.MassDensity.Mass=blocks.GetLength(0)*blocks.GetLength(1);}}}上面这个迷宫需要传入一个2维byte阵列,主要的想法当然还是参考自古早的RPGGame都是利用block的方式来产生世界的.然后写一个DSSService(参考之前的DSSwithVSE吧),这次我们加入一个MazeEntity:viewplaincopytoclipboardprint?1.voidAddMaze()2.{3.//createsimplemovableentity,withasingleshape4.maze=newMazeEntity(5.newVector3(3f,0f,3f),newbyte[,]{6.{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},7.{0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1},8.{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},9.{1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,1,0,1},10.{1,0,1,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,0,1},11.{1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1},12.{1,1,1,1,0,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1},13.{1,0,0,1,0,1,0,0,0,0,1,0,1,1,0,1,0,1,0,1},14.{1,0,0,1,0,1,1,1,1,0,1,0,1,0,0,1,0,1,0,1},15.{1,0,0,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,1},16.{1,0,0,1,1,1,1,0,1,0,1,0,1,1,1,1,0,1,0,1},17.{1,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,1},18.{1,0,1,1,0,1,1,0,1,0,1,0,1,0,0,1,1,1,0,1},19.{1,0,1,0,0,1,1,0,1,1,1,1,1,0,0,0,0,1,0,1},20.{1,0,1,0,0,1,1,0,0,0,0,0,0,0,1,1,0,1,0,1},21.{1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,1},22.{1,0,1,1,1,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1},23.{1,0,1,0,0,0,0,1,1,1,0,0,0,0,1,1,0,1,1,1},24.{1,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0},25.{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},},3.0f,3.0f);26.27.//Nametheentity.Allentitiesmusthaveuniquenames28.maze.State.Name=maze;29.30.//Insertentityinsimulation.31.SimulationEngine.GlobalInstancePort.Insert(maze);32.}voidAddMaze(){//createsimplemovableentity,withasingleshapemaze=newMazeEntity(newVector3(3f,0f,3f),newbyte[,]{{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},{1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,1,0,1},{1,0,1,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,0,1},{1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1},{1,1,1,1,0,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1},{1,0,0,1,0,1,0,0,0,0,1,0,1,1,0,1,0,1,0,1},{1,0,0,1,0,1,1,1,1,0,1,0,1,0,0,1,0,1,0,1},{1,0,0,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,1},{1,0,0,1,1,1,1,0,1,0,1,0,1,1,1,1,0,1,0,1},{1,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,1},{1,0,1,1,0,1,1,0,1,0,1,0,1,0,0,1,1,1,0,1},{1,0,1,0,0,1,1,0,1,1,1,1,1,0,0,0,0,1

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功