/// <summary> /// The dispose method gets called, when the entity is removed /// </summary> public override void Dispose() { // Remove the physic shapes from the simulation engine if (Parent != null) { ((VisualEntity)Parent).RemoveShapeFromPhysicsEntity(propellerShape, propellerVisualMesh); propellerVisualMesh = null; } base.Dispose(); }
/// <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> /// Called, when the new propeller entity /// </summary> /// <param name="device">The graphics device on which the entity is displayed</param> /// <param name="physicsEngine">The physics engine handling the entity physics</param> public override void Initialize(xnagfx.GraphicsDevice device, PhysicsEngine physicsEngine) { try { InitError = string.Empty; AddsShapeToParent = true; base.Initialize(device, physicsEngine); // Set the mesh for the propeller State.Assets.Mesh = PROPELLER_MESH_FILE; MeshScale = new Vector3(0.01f, 0.01f, 0.01f); MeshRotation = new Vector3(0.0f, (float)(Globals.RandomGenerator.NextDouble() * 1000.0), 0.0f); // TODO Transparente Propeller-Texture ab gewisser Drehgeschwindigkeit //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(); //Shape _particlePlane = new Shape(hf); //_particlePlane.State.Name = "Propeller plane"; //Meshes.Add(SimulationEngine.ResourceCache.CreateMesh(device, _particlePlane.State)); //Meshes[0].Textures[0] = SimulationEngine.ResourceCache.CreateTextureFromFile(device, "A-Eye/prop_rot.png"); if (Parent == null) { throw new Exception("This entity must be a child of another entity."); } // Add to parent propellerShape = new BoxShape(propellerShapeProperties); Meshes.Add(SimulationEngine.ResourceCache.CreateMeshFromFile(device, State.Assets.Mesh)); propellerVisualMesh = Parent.AddShapeToPhysicsEntity(propellerShape, null); } catch (Exception ex) { HasBeenInitialized = false; InitError = ex.ToString(); } }