[Robotics Studio]开始建造迷宫-- Day25
sqlyog连接不上编辑整理<;杜毓聪duyucong@gmail www.yucongdu>api免费调用平台
话说教会机器人走迷宫是我学习Robotics Studio的小小梦想之一.
next studio要学习走迷宫,第一步需要有迷宫才行.
无奈,之前的Visual Simulation Enviroment Express version的64个实体对象吓到我了...
如何用64个实体来建造伟大的迷宫,我一直是觉得很困难的一件事情...
直到,我发现这个64个Entities的限制是--直接放入VSE World的实体数量.
也就是说,如果我把整个迷宫看成是一个Entity对象,不就解决这样的问题了吗?!
所以,可以透过实做MultiShapeEntity这个class来达成梦想的第一步了!
view plaincopy to clipboardprint?
1. using System;
2. using System.Collections.Generic;免费网站大黄免费
3. using System.ComponentModel;
modifydate4. using Microsoft.Ccr.Core;c语言程序设计基础知识点总结
5. using Microsoft.Dss.Core.Attributes;
6. using Microsoft.Dss.ServiceModel.Dssp;
7. using Microsoft.Dss.ServiceModel.DsspServiceBase;
8. using W3C.Soap;
9. using submgr = Microsoft.Dss.Services.SubscriptionManager; 10.using engine =
Microsoft.Robotics.Simulation.Engine.Proxy; 11.using Microsoft.Robotics.Simulation.Engine; 12.using Microsoft.Robotics.Simulation.Physics; 13.using Microsoft.Robotics.PhysicalModel;
14.
15. 16.namespace MazeGenerator 17.{
18. public class MazeEntity : MultiShapeEntity
19. {
20. /// <summary>
21. /// Default constructor
22. /// </summary>
23. public MazeEntity() { }
24.
25. /// <summary>
26. /// Initialization constructor
27. /// </summary>
28. /// <param name="shape"></param>
29. /// <param name="initialPos"></param>
30. public MazeEntity(Vector3 initialPos, byte[,] blocks, float mazeheight, float blocksize)
31. {
32. for (int x = 0; x < blocks.GetLength(0); x++)
33. {
34. for (int y = 0; y < blocks.GetLength(1); y++)
35. {
36. if (blocks[x,y] == 0)
37. continue;
38.
39. var boxshape = new BoxShape(
40. new BoxShapeProperties(
41. 1, // mass in kilograms.
42. new Pose(new Vector3(initialPos.X + x * blocksize, initialPos.Y + mazeheight / 2, initialPos.Z -y*blocksize)), // relative pose
43. new Vector3(blocksize, mazeheight, blocksize)));
44.
45. this.BoxShapes.Add(boxshape); // dimensions
46. }
47. }
48.
49. this.State.MassDensity.Mass = blocks.GetLength(0)*blocks.GetLength(1);
50. }
51. } 52.}
using System;using System.Collections.Generic;using
System.ComponentModel;using Microsoft.Ccr.Core;using
Microsoft.Dss.Core.Attributes;using
Microsoft.Dss.ServiceModel.Dssp;using
Microsoft.Dss.ServiceModel.DsspServiceBase;using
W3C.Soap;using submgr =
Microsoft.Dss.Services.SubscriptionManager;using engine =
Microsoft.Robotics.Simulation.Engine.Proxy;using
Microsoft.Robotics.Simulation.Engine;using
Microsoft.Robotics.Simulation.Physics;using
Microsoft.Robotics.PhysicalModel;
namespace MazeGenerator
{ public class MazeEntity : MultiShapeEntity{
/// <summary>/// Default constructor/// </summary>public MazeEntity() { }
/// <summary>/// Initialization constructor/// </summary>/// <param
name="shape"></param>/// <param name="initialPos"></param>public
MazeEntity(Vector3 initialPos, byte[,] blocks, float mazeheight, float blocksize)
{ for (int x = 0; x < blocks.GetLength(0); x++){
for (int y = 0; y < blocks.GetLength(1); y++){ if (blocks[x,y] == 0)continue;
var boxshape = new BoxShape(
new BoxShapeProperties(
1, // mass in kilograms.
new Pose(new Vector3(initialPos.X + x * blocksize,initialPos.Y + mazeheight / 2, initialPos.Z - y*blocksize)), // relative pose
new Vector3(blocksize, mazeheight, blocksize)));
this.BoxShapes.Add(boxshape); // dimensions}}
this.State.MassDensity.Mass = blocks.GetLength(0)*blocks.GetLength(1);}}}
上面这个迷宫需要传入一个2维byte阵列,主要的想法当然还是参考自古早的RPG Game都是利用block的方式来
产生世界的.
然后写一个DSS Service (参考之前的DSS with VSE吧),这次我们加入一个MazeEntity :
view plaincopy to clipboardprint?
1. void AddMaze()
2. {
3. // create simple movable entity, with a single shape
4. maze = new MazeEntity(
5. new Vector3(3f, 0f, 3f), new byte[,] {
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. // Name the entity. All entities must have unique names
28. maze.State.Name = "maze";
29.
30. // Insert entity in simulation.
31. SimulationEngine.GlobalInstancePort.Insert(maze); 32.}
void AddMaze()
{ // create simple movable entity, with a single shapemaze = new MazeEntity(new Vector3(3f, 0f, 3f), new byte[,]
{{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,0,1},{1,0,1,0,0,1,1,0,0,0,0,0,0,0,1 ,1,0,1,0,1},{1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,1},{1,0,1,1,1,0,0,0,0,0,0,1,0,1 ,0,0,0,1,0,1},{1,0,1,0,0,0,0,1,1,1,0,0,0,0,1,1,0,1,1,1},{1,0,0,0,1,1,0,0,0,0,0,1,0 ,0,0,0,0,0,0,0},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, }, 3.0f, 3.0f);
// Name the entity. All entities must have unique namesmaze.State.Name = "maze";
// Insert entity in
simulation.SimulationEngine.GlobalInstancePort.Insert(maze);}
这样我们就有一个迷宫了耶...
但是这样自己做迷宫会爽吗? --不会!!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论