/// <summary>
        /// Initialization
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            try
            {
                // GPS sensor dimensions and relative position
                _shape = new BoxShape(new BoxShapeProperties(
                    "GPS Sensor", 
                    0.01f, 
                    new Pose(new Vector3(0,0.8f,0)), 
                    new Vector3(0.01f, 0.01f, 0.01f)));

                State.PhysicsPrimitives.Add(_shape);
                base.Initialize(device, physicsEngine);
                if (Parent == null)
                {
                    throw new Exception("GPS Sensor entity must be a child of another entity.");
                }
                CreateAndInsertPhysicsEntity(physicsEngine);
                Flags |= VisualEntityProperties.DisableRendering;
                AddShapeToPhysicsEntity(_shape, new VisualEntityMesh(device, 0.01f, 0.01f));       

            }
            catch (Exception ex)
            {
                HasBeenInitialized = false;
                InitError = ex.ToString();
            }
        }
		public XnaTextureManager( XFG.GraphicsDevice device )
            : base()
		{
			this._device = device;

			Is32Bit = true;
		}
		public XnaVertexDeclaration( XFG.GraphicsDevice device )
		{
			this._device = device;
		}
		///<summary>
		///    Call this to associate a Xna Texture3D with this pixel buffer
		///</summary>
		public void Bind( XFG.GraphicsDevice device, XFG.Texture3D volume, bool update )
		{
			this.device = device;
			this.volume = volume;

			Width = volume.Width;
			Height = volume.Height;
			Depth = volume.Depth;
			Format = XnaHelper.Convert( volume.Format );
			// Default
			RowPitch = Width;
			SlicePitch = Height * Width;
			sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format );

			if ( ( (int)usage & (int)TextureUsage.RenderTarget ) != 0 )
				CreateRenderTextures( update );
		}
		public void Bind( XFG.GraphicsDevice device, XFG.RenderTarget2D surface, bool update )
		{
			this.device = device;
			this.renderTarget = (XFG.RenderTarget2D)surface;

			Width = surface.Width / (int)Axiom.Math.Utility.Pow( 2, mipLevel );
			Height = surface.Height / (int)Axiom.Math.Utility.Pow( 2, mipLevel );
			Depth = 1;
			Format = XnaHelper.Convert( surface.Format );
			// Default
			RowPitch = Width;
			SlicePitch = Height * Width;
			sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format );

			if ( ( (int)usage & (int)TextureUsage.RenderTarget ) != 0 )
				CreateRenderTextures( update );
		}
        public TTDifferentialDriveEntity() { }  // TT - Notice the name change

        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            // TT May-2007
            // Could be initialized in the declarations above,
            // but here it is anyway
            IsRotating = false;
            IsTranslating = false;
            TurnStartDegrees = 0;
            TranslateStartX = 0;
            TranslateStartZ = 0;
            TranslateDistanceSquared = 0;

            try
            {
                InitError = string.Empty;
                ProgrammaticallyBuildModel(device, physicsEngine);
                _leftWheel.Parent = this;
                _rightWheel.Parent = this;
                _leftWheel.Initialize(device, physicsEngine);
                _rightWheel.Initialize(device, PhysicsEngine);
                // TT May-2007
                // Set the flag so that the pose is always updated
                //this.Flags |= VisualEntityProperties.DoCompletePhysicsShapeUpdate;
                base.Initialize(device, physicsEngine);
            }
            catch (Exception ex)
            {
                // clean up
                if (PhysicsEntity != null)
                    PhysicsEngine.DeleteEntity(PhysicsEntity);

                HasBeenInitialized = false;
                InitError = ex.ToString();
            }
        }
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            try
            {
                InitError = string.Empty;
                // set flag so rendering engine renders us last
                Flags |= VisualEntityProperties.UsesAlphaBlending;

                // creates effect, loads meshes, etc
                base.Initialize(device, physicsEngine);

                HeightFieldShapeProperties hf = new HeightFieldShapeProperties("height field", 2, 0.02f, 2, 0.02f, 0, 0, 1, 1);
                hf.HeightSamples = new HeightFieldSample[hf.RowCount * hf.ColumnCount];
                for (int i = 0; i < hf.HeightSamples.Length; i++)
                    hf.HeightSamples[i] = new HeightFieldSample();

                _particlePlane = new Shape(hf);
                _particlePlane.State.Name = "sonar impact plane";

                VisualEntityMesh sonarMesh = null;

                // we render on our own only the laser impact points. The laser Box is rendered as part of the parent.
                int index = Meshes.Count;
                Meshes.Add(SimulationEngine.ResourceCache.CreateMesh(device, _particlePlane.State));
                Meshes[0].Textures[0] = SimulationEngine.ResourceCache.CreateTextureFromFile(device, "particle.bmp");

                // we have a custom effect, with an additional global parameter. Get handle to it here
                if (Effect != null)
                    _timeAttenuationHandle = Effect.GetParameter("timeAttenuation");

                World = xna.Matrix.Identity;
                if (Meshes.Count > 1)
                    sonarMesh = Meshes[0];

                if (Parent == null)
                    throw new Exception("This entity must be a child of another entity.");

                Parent.AddShapeToPhysicsEntity(_sonarBox, sonarMesh);
            }
            catch (Exception ex)
            {
                HasBeenInitialized = false;
                InitError = ex.ToString();
            }
        }
		/// <summary>
		///		
		/// </summary>
		/// <param name="device"></param>
		public XnaHardwareBufferManagerBase( XFG.GraphicsDevice device )
			: base()
		{
			this._device = device;
		}
Exemple #9
0
		public XnaGpuProgram( ResourceManager parent, string name, ResourceHandle handle, string group, bool isManual, IManualResourceLoader loader, XFG.GraphicsDevice device )
			: base( parent, name, handle, group, isManual, loader )
		{
			this.device = device;
			this.shaderCode = null;
		}
 void DrawBitmapStringInternal(BitmapSpriteFont spriteFont, string text, Vector2 position, G.Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
 {
     DrawBitmapStringInternal(spriteFont, text, position, color, rotation, origin, new Vector2(scale, scale), effects, layerDepth);
 }
 void DrawBitmapStringInternal(BitmapSpriteFont spriteFont, string text, Vector2 position, G.Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     BitmapSpriteText d = GetBitmapSpriteText(spriteFont);
     if (d.ZIndex < zIndex)
     {
         d.ZIndex = zIndex;
     }
     else
     {
         zIndex = d.ZIndex;
     }
     zIndex++;
     d.InUse = true;
     d.Text = text;
     d.Color = color;
     d.PositionX = position.X;
     d.PositionY = position.Y;
     d.Scale = new Vector2((float)scale.X, (float)scale.Y);
     d.Rotation = rotation;
     d.Origin = origin;
     d.Effects = effects;
 }
 public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, G.Color color)
 {
     DrawString(spriteFont, text.ToString(), position, color);
 }
		public override Stream Open( XFG.CompilerIncludeHandlerType includeType, string filename )
		{
			return ResourceGroupManager.Instance.OpenResource( filename );
		}
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            try
            {
                InitError = string.Empty;

                // Create simulated P3DX front and rear bumper arrays
                _shapes = new BoxShape[_segments]; 

                // Bumper panel dimensions
                Vector3 segmentDimensions = new Vector3( 0.075f, 0.025f, 0.01f); // 10 cm width, 2.5 cm wide, 1.0 cm deep

                // Bumper names
                string[] bumperName = new string[] { "b9/rear", "b10/rear", "b11/rear", "b12/rear", "b13/rear",
                                                     "b1/front", "b2/front", "b3/front", "b4/front", "b5/front" 
                                                      };
                // Bumper panel angles
                float[] bumperAngle = new float[] { (float)-(38.0f * Math.PI) / 180,  // b1 is at -52 degrees.
                                                    (float)-(19.0f * Math.PI) / 180,  // b2 is at -19 degrees.
                                                    (float)(0.0f * Math.PI) / 180,   // b3 is centered front.
                                                    (float)(19.0f * Math.PI) / 180,  // b4 is at 19 degrees.
                                                    (float)(38.0f * Math.PI) / 180,  // b5 is at 52 degrees.
                                                    (float)(142.0f * Math.PI) / 180, // b9 is at 128 degrees.
                                                    (float)(161.0f * Math.PI) / 180, // b10 is at 161 degrees.
                                                    (float)(180.0f * Math.PI) / 180, // b11 is centered rear.
                                                    (float)-(161.0f * Math.PI) / 180, // b12 is at -162 degrees.
                                                    (float)-(142.0f * Math.PI) / 180 }; // b13 is at -128 degrees.
                                                    
                
                // P3DX Bumper segment poses
                Vector3[] bumperPose = new Vector3[_segments];   


                // Add frontal and rear bumper shapes
                for (int segment = 0; segment < _segments; segment++)
                {
                    // P3DX Bumper segment pose
                    bumperPose[segment] = new Vector3((float)(-0.25f * Math.Sin(bumperAngle[segment])),  // X
                                                      0.05f,                                             // Y
                                                      (float)(0.25f * Math.Cos(bumperAngle[segment])));  // Z

                    // Create current segment:
                    BoxShape bumper = new BoxShape(
                        new BoxShapeProperties(
                            bumperName[segment], // segment name
                            0.001f, // segment mass
                            new Pose(bumperPose[segment],          // segment position
                                     Quaternion.FromAxisAngle(0, 1, 0, -bumperAngle[segment])), // segment orientation
                            segmentDimensions)); // segment dimensions                    

                    bumper.BoxState.Material = new MaterialProperties("P3DX chassis", 0.0f, 0.25f, 0.5f);
                    bumper.Parent = this;
                    bumper.BoxState.EnableContactNotifications = true;

                    bumper.State.DiffuseColor = new Vector4(0.1f, 0.1f, 0.1f, 0.1f);

                    _shapes[segment] = bumper;

                }

                foreach (BoxShape b in _shapes)
                {
                    State.PhysicsPrimitives.Add(b);                    
                }

                base.Initialize(device, physicsEngine);

                if (Parent == null)
                    throw new Exception("This entity must be a child of another entity.");

                CreateAndInsertPhysicsEntity(physicsEngine);

                Flags |= VisualEntityProperties.DisableRendering;

                foreach (BoxShape shape in _shapes)
                    AddShapeToPhysicsEntity(shape, null);
            }
            catch (Exception ex)
            {
                HasBeenInitialized = false;
                InitError = ex.ToString();
            }
        }
        /// <summary>
        /// Builds the simulated robotic entity using local fields for positionm size, orientation
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public void ProgrammaticallyBuildModel(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            if (_casterWheelShape == null)
            {
                // add caster wheel as a basic sphere shape
                CasterWheelShape = new SphereShape(
                    new SphereShapeProperties("rear wheel", 0.001f,
                    new Pose(CASTER_WHEEL_POSITION), CASTER_WHEEL_RADIUS));
                CasterWheelShape.State.Name = "Caster wheel";

                // a fixed caster wheel has high friction when moving laterely, but low friction when it moves along the
                // body axis its aligned with. We use anisotropic friction to model this
                CasterWheelShape.State.Material = new MaterialProperties("small friction with anisotropy", 0.5f, 0.5f, 1);
                CasterWheelShape.State.Material.Advanced = new MaterialAdvancedProperties();
                CasterWheelShape.State.Material.Advanced.AnisotropicDynamicFriction = 0.3f;
                CasterWheelShape.State.Material.Advanced.AnisotropicStaticFriction = 0.4f;
                CasterWheelShape.State.Material.Advanced.AnisotropyDirection = new Vector3(0, 0, 1);
            }

            base.State.PhysicsPrimitives.Add(_casterWheelShape);

            if (_chassisShape != null)
                base.State.PhysicsPrimitives.Add(_chassisShape);
            
            base.CreateAndInsertPhysicsEntity(physicsEngine);
            // increase physics fidelity
            base.PhysicsEntity.SolverIterationCount = 64;

            // if we were created from xml the wheel entities would already be instantiated
            if (_leftWheel != null && _rightWheel != null)
                return;

            // front left wheel
            WheelShapeProperties w = new WheelShapeProperties("front left wheel", FRONT_WHEEL_MASS, FRONT_WHEEL_RADIUS);
            // Set this flag on both wheels if you want to use axle speed instead of torque
            w.Flags |= WheelShapeBehavior.OverrideAxleSpeed;
            w.InnerRadius = 0.7f * w.Radius;
            w.LocalPose = new Pose(LEFT_FRONT_WHEEL_POSITION);
            _leftWheel = new WheelEntity(w);
            _leftWheel.State.Name = State.Name + ":" + "Left wheel";
            _leftWheel.State.Assets.Mesh = _wheelMesh;
            _leftWheel.Parent = this;
            //_leftWheel.WheelShape.WheelState.Material = new MaterialProperties("wheel", 0.5f, 0f, 1f);
            // wheels must have zero friction material.The wheel model will do friction differently

            // front right wheel
            w = new WheelShapeProperties("front right wheel", FRONT_WHEEL_MASS, FRONT_WHEEL_RADIUS);
            w.Flags |= WheelShapeBehavior.OverrideAxleSpeed;
            w.InnerRadius = 0.7f * w.Radius;
            w.LocalPose = new Pose(RIGHT_FRONT_WHEEL_POSITION);
            _rightWheel = new WheelEntity(w);
            _rightWheel.State.Name = State.Name + ":" + "Right wheel";
            _rightWheel.State.Assets.Mesh = _wheelMesh;
            _rightWheel.Parent = this;
            //_rightWheel.WheelShape.WheelState.Material = _leftWheel.WheelShape.WheelState.Material;
        }
Exemple #16
0
		/// <summary>
		///
		/// </summary>
		/// <param name="driver">The root driver</param>
		/// <param name="deviceIfSwapChain"></param>
		public XnaRenderWindow( Driver driver, XFG.GraphicsDevice deviceIfSwapChain )
			: this( driver )
		{
			_isSwapChain = ( deviceIfSwapChain != null );
		}
Exemple #17
0
        internal XnaFragmentProgram( ResourceManager parent, string name, ResourceHandle handle, string group, bool isManual, IManualResourceLoader loader, XFG.GraphicsDevice device )
			: base( parent, name, handle, group, isManual, loader, device )
		{
		}
        public void DrawString(SpriteFont spriteFont, string text, Vector2 position, G.Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
        {
            if (text == null) return;
            if (spriteFont is BitmapSpriteFont)
            {
                DrawBitmapStringInternal((BitmapSpriteFont)spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth);
                return;
            }
            SpriteList l;
            long key = spriteFont.AssetId;
            if (texts.ContainsKey(key))
            {
                l = texts[key];
            }
            else
            {
                l = new SpriteList(this, SpriteList.SpriteType.SpriteText);
                l.SpriteFont = spriteFont;
                l.ParentCanvas = Canvas;
                texts.Add(key, l);
            }
            SpriteText t = l.GetSprite() as SpriteText;
            if (t.ZIndex < zIndex)
            {
                t.ZIndex = zIndex;
            }
            else
            {
                zIndex = t.ZIndex;
            }
            Vector2 vscale = new Vector2(scale, scale);

            zIndex++;
            t.InUse = true;
            t.PositionX = position.X;
            t.PositionY = position.Y;
            t.Color = color;
            t.Text = text;
            t.Scale = vscale;
            t.Rotation = rotation;
            t.Origin = origin;
            t.Effects = effects;
        }
		public XnaHardwareBufferManager( XFG.GraphicsDevice device )
			: base( new XnaHardwareBufferManagerBase( device ) )
		{
		}
 public void DrawString(SpriteFont font, string text, Vector2 position, G.Color color)
 {
     DrawString(font, text, position, color, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
 }
 public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, G.Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     if (sourceRectangle == null || sourceRectangle.Value.IsEmpty)
     {
         SpriteImage d = GetSprite(texture);
         if (d.ZIndex < zIndex)
         {
             d.ZIndex = zIndex;
         }
         else
         {
             zIndex = d.ZIndex;
         }
         zIndex++;
         d.InUse = true;
         if (color != d.color) d.Color = color;
         d.PositionX = position.X;
         d.PositionY = position.Y;
         d.Scale = new Vector2((float)scale.X, (float)scale.Y);
         d.Rotation = rotation;
         d.SetOriginAndEffects(origin, effects);
         d.CustomEffect = null; // this needs to get reset in case it's left-over from another call
     }
     else
     {
         ClippedSpriteImage d = GetClippedSprite(texture);
         if (d.ZIndex < zIndex)
         {
             d.ZIndex = zIndex;
         }
         else
         {
             zIndex = d.ZIndex;
         }
         zIndex++;
         d.InUse = true;
         if (color != d.color) d.Color = color;
         d.SourceRectangle = sourceRectangle.Value;
         d.PositionX = position.X;
         d.PositionY = position.Y;
         d.Scale = new Vector2((float)scale.X, (float)scale.Y);
         d.Rotation = rotation;
         d.SetOriginAndEffects(origin, effects);
         d.CustomEffect = null; // this needs to get reset in case it's left-over from another call
     }
 }
Exemple #22
0
public override void Initialize(xnagrfx.GraphicsDevice 
device, PhysicsEngine physicsEngine)
{
base.ServiceContract = drive.Contract.Identifier;
base.Initialize(device, physicsEngine);
}
 public override void Clear(G.Color color)
 {
     if (color != backgroundColor)
     {
         Canvas.Background = new SolidColorBrush(color.ToSilverlightColor());
         backgroundColor = color;
     }
 }
Exemple #24
0
		/// <summary>
		///		Accepts a existing Direct3D.DisplayMode object.
		/// </summary>
		public VideoMode( XFG.DisplayMode videoMode )
		{
			modeNum = ++modeCount;
			displayMode = videoMode;
		}