/// <summary> /// Called when another component is added or removed from the entity. This method should /// be used by the component to aquire references to other components in the entity. /// </summary> public override void OnReset() { base.OnReset(); ISpatialComponent spatial = this.Owner.GetComponent <ISpatialComponent>(); if (spatial != null) { SceneNode oldNode = mSceneNode; mSceneNode = spatial.SceneNode; if (mSceneNode != oldNode) // Only attach/dettach if the node has changed. { // Dettach the component's node from the old scene node (if any). if (oldNode != null) { Dettach(oldNode); } // And attach it to the new scene node (if any). if (mSceneNode != null) { Attach(mSceneNode); } } } // If there is no spatial component, we dettach the quad. else { if (mSceneNode != null) { Dettach(mSceneNode); } } }
/// <summary> /// Called when another component is added or removed from the entity. This method should /// be used by the component to aquire references to other components in the entity. /// </summary> public override void OnReset() { base.OnReset(); ISpatialComponent spatial = this.Owner.GetComponent <ISpatialComponent>(); mSceneNode = spatial != null ? spatial.SceneNode : null; }
/// <summary> /// Constructor. /// </summary> /// <param name="root">Root object to which the entity belongs.</param> /// <param name="name">Name of the entity.</param> /// <param name="normal">Normal of the plane.</param> /// <param name="distance"> /// Distance along the normal to the plane. For instance, if the normal is (0,1,0), that /// is, the Y axis, the created plane will be y = distance. /// </param> public PhysicsPlane(Root root, string name, Vector3 normal, float distance) : base(root, name) { ISpatialComponent spatial = ComponentFactory.createSpatialComponent(this.Root, "spatial"); IPhysicsComponent physics = ComponentFactory.createPhysicsComponent(this.Root, "physicsComponent"); physics.BuildCollisionPlane(normal, distance); physics.Immovable = true; AddComponent(spatial); AddComponent(physics); }
/// <summary> /// Constructor. /// </summary> /// <param name="root">Root object to which the entity belongs.</param> /// <param name="name">Name of the entity.</param> public PhysicsPlane(Root root, string name) : base(root, name) { ISpatialComponent spatial = ComponentFactory.createSpatialComponent(this.Root, "spatial"); IPhysicsComponent physics = ComponentFactory.createPhysicsComponent(this.Root, "physicsComponent"); physics.BuildCollisionPlane(new Vector3(0.0f, 1.0f, 0.0f), 0.0f); physics.Immovable = true; AddComponent(spatial); AddComponent(physics); }
/// <summary> /// Adds an entity to the list of entities that are to be monitored by the component. /// </summary> /// <param name="entity">Entity which is to be added.</param> public void AddSensedEntity(Entity entity) { if (entity == null) { throw new ArgumentNullException("DefaultProximitySensorComponent.AddSensedEntity(): null entity."); } ISpatialComponent spatial = entity.GetComponent <ISpatialComponent>(); if (spatial == null || spatial.SceneNode == null) { string msg = "DefaultProximitySensorComponent.AddSensedEntity(): entity has no "; msg += "spatial component."; throw new ArgumentException(msg); } EntityEntry entry = new EntityEntry(); entry.SceneNode = spatial.SceneNode; entry.Entity = entity; mEntities.Add(entry); }