第27天Microsoft-Robotics-Developer-Studio中文教程--Camer

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

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

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

资源描述

[RoboticsStudio]CameraSpriteinVSE--Day272009/1/1719:07|阅读数:4031|我要推荐|AddComment|订阅因为迷宫太难了,先来学其他比较简单的东西--话说Day21的时候为了看到机器人的Camera,费尽辛苦写了一个视窗,还要写一些code用来连接虚拟Camera送来的讯息以及将资料转成Image等等...但是有了CameraSprite就变成好简单...只要在虚拟的CameraEntity加上一个CameraSprite(一定要是CameraEntity的子物件),透过VSE你就可以在该Camera的某个相对位置上看到Camera的画面.就拿相扑机器人的SumoCompetition专案来作范例吧,首先打开该范例,切到SimulatedSumoReferee专案的SimulatedSumoReferee.cs,找到EntityManager.CreateRobot函式,在产生出CameraEntity的时候,生出一个CameraSprite在该Camera上方1公尺处,大小为50x50cm,如下面的四行code:01//Addacamera02CameraEntitysumoCam=newCameraEntity(176,144,(float)(27.0*Math.PI/180.0),CameraEntity.CameraModelType.AttachedChild);//20degreeFOV03sumoCam.State.Name=newRobot.State.Name+/SumoCam;04sumoCam.State.Pose.Position=newVector3(0,0.17f,0.005f);05sumoCam.Rotation=newxna.Vector3(-8.0f,0,0);06sumoCam.State.Assets.Mesh=WebCam.obj;07sumoCam.IsRealTimeCamera=true;08sumoCam.UpdateInterval=350;//updatelessthen3timespersecond0910//把CameraSprite加到CameraEntity的子物件当中11CameraSpritecamSprite=newCameraSprite(0.5f,0.5f,SpritePivotType.Center,0,newVector3(0,1,0));12camSprite.State.Name=newRobot.State.Name+/camSprite;13camSprite.Flags|=VisualEntityProperties.DisableBackfaceCulling;14sumoCam.InsertEntity(camSprite);1516newRobot.InsertEntity(sumoCam);恩,就这样,双方的机器人上面都有一个摄影机的画面啦!决斗过程也都可以看到...这么简单就混过一天,可能会被骂的,所以我再补一点关于SpriteEntity的东西好了,CameraSprite是继承自SpriteEntity的,如果我们要自己做一个简单的SpriteEntity,可以直接用SpriteEntity,或继承一个.假设我们要作一个TextSprite(我很奇怪为什么微软不帮我们做一个这样的?反而做EntityNameSprite,只会显示parent物件的名称?!这么狭隘的class?!)code如下:01publicclassTextSprite:SpriteEntity02{03privatestring_fontFamily;04privatefloat_fontSize;05privatestring_text;0607///summary08///Thefontfamilynameofthefonttouse09////summary10[DataMember]11publicstringFontFamily12{13get{return_fontFamily;}14set{_fontFamily=value;}15}1617///summary18///Thefontsizeofthefonttouse19////summary20[DataMember]21publicfloatFontSize22{23get{return_fontSize;}24set{_fontSize=value;}25}2627///summary28///Defaultconstructor29////summary30publicTextSprite(){}3132///summary33///Initializationconstructor34////summary35///paramname=width/param36///paramname=height/param37///paramname=textureWidth/param38///paramname=textureHeight/param39///paramname=pivot/param40///paramname=initialPos/param41///paramname=family/param42///paramname=fontSize/param43publicTextSprite(stringtext,floatwidth,floatheight,inttextureWidth,inttextureHeight,SpritePivotTypepivot,Vector3initialPos,stringfamily,floatfontSize)44:base(width,height,textureWidth,textureHeight,pivot,initialPos)45{46_text=text;47_fontFamily=family;48_fontSize=fontSize;49}5051///summary52///Initialize53////summary54///paramname=device/param55///paramname=physicsEngine/param56publicoverridevoidInitialize(Microsoft.Xna.Framework.Graphics.GraphicsDevicedevice,PhysicsEnginephysicsEngine)57{58try59{60InitError=string.Empty;61FontnameFont=newFont(_fontFamily,_fontSize);62base.Initialize(device,physicsEngine);63Bitmaptarget=GetBitmap();64Graphicsg=Graphics.FromImage(target);65g.FillRectangle(Brushes.DarkBlue,0,0,target.Width,target.Height);66StringFormatnameFormat=newStringFormat();67nameFormat.Alignment=StringAlignment.Center;68nameFormat.LineAlignment=StringAlignment.Center;69g.DrawString(_text,nameFont,Brushes.White,newRectangle(0,0,target.Width,target.Height),nameFormat);70SetBitmap(target);71}72catch(Exceptionex)73{74HasBeenInitialized=false;75InitError=ex.ToString();76}77}78}这样我们就可以在VSE当中产生一片文字(就像魔兽的人物上面都会挂一块名牌)透过在刚刚的AddCameraSprite之后再加上:1//加上TextSprite2TextSpritetxtSprite=newTextSprite(Hello!Iam+newRobot.State.Name,0.5f,0.0625f,512,64,SpritePivotType.Center,newVector3(0,0.25f,0),Courier,14);3txtSprite.State.Name=newRobot.State.Name+/txtSprite;4newRobot.InsertEntity(txtSprite);这个TextSprite比原本的EntityNameSprite好用多了,不但可以显示任何字(要考虑字型),还可以不限定要加在某个Entity当中(直接加到VSE).(因为原本的EntityNameSprite一定要挂在某个Entity下面,用来显示该Entity的名称)

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

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

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

×
保存成功