public SceneElement insertElement(BoundingBox bb, GameObject gameObject) { ContainmentType t = m_root.BoundingBox.Contains(bb); if (t == ContainmentType.Contains) { SceneElement se; if (!m_sceneElements.TryGetValue(gameObject, out se)) { se = new SceneElement(bb, gameObject); m_root.insertElement(se); } return se; } return null; }
/// <summary> /// Update the values of a scene element and reinsert it, if necessary /// </summary> /// <param name="se">The scenelement to update</param> /// <param name="position">new position</param> /// <param name="orientation">new orientation</param> /// <param name="scale">new scaling</param> public void updateElement(SceneElement se, Vector3 position, Quaternion orientation, Vector3 scale) { }
/// <summary> /// Remove a SceneElement from the scenemanager. /// </summary> /// <param name="se"></param> public void removeElementVisual(SceneElement se) { m_octreeVisual.removeElement(se); }
/// <summary> /// Remove a SceneElement from the scenemanager. /// </summary> /// <param name="se"></param> public void removeElementCollision(SceneElement se) { m_octreeCollision.removeElement(se); }
public override void doInitialize() { setModel(); setMaterial(); // add to rendermanager RenderManager renderMan = Owner.Game.Services.GetService(typeof(RenderManager)) as RenderManager; renderMan.addRenderable(this, Layer); // get position IPosition3D pos = Owner.getFirst(typeof(IPosition3D)) as IPosition3D; if (pos != null) { m_position = pos.Position; pos.PositionChanged += new XnaScrapCore.Core.Delegates.Position3DChangedEventHandler(PositionChanged); } // get orientation IOrientation3D orientation = Owner.getFirst(typeof(IOrientation3D)) as IOrientation3D; if (orientation != null) { m_orientation = orientation.Orientation; orientation.OrientationChanged += new XnaScrapCore.Core.Delegates.OrientationChangedEventHandler(OrientationChanged); } // get dimension IScale3D scale = Owner.getFirst(typeof(IScale3D)) as IScale3D; if (scale != null) { m_scale = scale.Scale; scale.Changed += new Scale3DChangedEventHandler(scale_Changed); } // add to scenemanagement ISceneManager sceneManager = Owner.Game.Services.GetService(typeof(ISceneManager)) as ISceneManager; if (sceneManager != null) { BoundingBox bb = new BoundingBox(); if (m_model != null) { m_ModelBoundingBox = BoundingBox.CreateFromSphere(m_model.BoundingSphere); } bb.Min = m_ModelBoundingBox.Min + m_position; bb.Max = m_ModelBoundingBox.Max + m_position; m_sceneElement = sceneManager.insertElementVisual(bb, Owner); } base.doInitialize(); }
public override void doDestroy() { IPosition3D pos = Owner.getFirst(typeof(IPosition3D)) as IPosition3D; if (pos != null) { pos.PositionChanged -= new XnaScrapCore.Core.Delegates.Position3DChangedEventHandler(PositionChanged); } IOrientation3D orientation = Owner.getFirst(typeof(IOrientation3D)) as IOrientation3D; if (orientation != null) { orientation.OrientationChanged -= new XnaScrapCore.Core.Delegates.OrientationChangedEventHandler(OrientationChanged); } // remove from scenemanagement ISceneManager sceneManager = Owner.Game.Services.GetService(typeof(ISceneManager)) as ISceneManager; if (sceneManager != null) { sceneManager.removeElementVisual(m_sceneElement); m_sceneElement = null; } // add to rendermanager RenderManager renderMan = Owner.Game.Services.GetService(typeof(RenderManager)) as RenderManager; renderMan.removeRenderable(this, Layer); base.doDestroy(); }
public override void doInitialize() { setModel(); setMaterial(); AnimationService animService = Owner.Game.Services.GetService(typeof(AnimationService)) as AnimationService; if (animService != null) { // test this should be done while loading the mesh //SkinningData skinData = m_model.Tag as SkinningData; //animService.addAnimation(new XnaScrapId(m_modelName), new AnimationPlayer.AnimationPlayerFactory(skinData)); // end test m_animation = animService.getAnimation(new XnaScrapId(m_modelName)) as AnimationPlayer; //animService.animateMe(new XnaScrapId("template_run"), m_animation, new TimeSpan(),loop, animationChanged); //animService.animateMe(new XnaScrapId("template_fire_gun"), m_animation, new TimeSpan(),loop, animationChanged); } else { throw new ServiceNotFoundException("AnimationService not found", typeof(AnimationService)); } // add to rendermanager RenderManager renderMan = Owner.Game.Services.GetService(typeof(RenderManager)) as RenderManager; renderMan.addRenderable(this, m_layer); // get position IPosition3D pos = Owner.getFirst(typeof(IPosition3D)) as IPosition3D; if (pos != null) { m_position = pos.Position; pos.PositionChanged += new XnaScrapCore.Core.Delegates.Position3DChangedEventHandler(PositionChanged); } // get orientation IOrientation3D orientation = Owner.getFirst(typeof(IOrientation3D)) as IOrientation3D; if (orientation != null) { m_orientation = orientation.Orientation; orientation.OrientationChanged += new XnaScrapCore.Core.Delegates.OrientationChangedEventHandler(OrientationChanged); } else { m_orientation = Quaternion.Identity; } // get dimension IScale3D scale = Owner.getFirst(typeof(IScale3D)) as IScale3D; if (scale != null) { m_scale = scale.Scale; scale.Changed += new Scale3DChangedEventHandler(scale_Changed); } // add to scenemanagement ISceneManager sceneManager = Owner.Game.Services.GetService(typeof(ISceneManager)) as ISceneManager; if (sceneManager != null) { BoundingBox bb = new BoundingBox(); if (m_model != null) { m_ModelBoundingBox = BoundingBox.CreateFromSphere(m_model.BoundingSphere); } bb.Min = m_ModelBoundingBox.Min + m_position; bb.Max = m_ModelBoundingBox.Max + m_position; m_sceneElement = sceneManager.insertElementVisual(bb, Owner); } base.doInitialize(); }
/// <summary> /// Handle an element, that is selected within a selection query /// </summary> /// <param name="element"></param> public void execute(SceneElement element) { m_selected.Add(element); }
public void removeElement(SceneElement se) { m_root.removeElement(se); }
private void insertHere(SceneElement se) { if (!m_elements.Contains(se)) { m_elements.Add(se); se.Node = this; } }
public void updateElement(SceneElement se) { // remove the element from it's current node if (se.Node != null) { removeElement(se); se.Node = null; } // is the element still inside this node if (se.BoundingBox.Intersects(BoundingBox)) { insertElement(se); } else { // no? give it to parent if (m_parent != null) { m_parent.updateElement(se); } else // top node { insertElement(se); } } }
/// <summary> /// /// </summary> /// <param name="element"></param> public void removeElement(SceneElement element) { if (m_elements.Contains(element)) { m_elements.Remove(element); } if (m_children != null) { foreach (OctreeNode node in m_children) { node.removeElement(element); } } }
/// <summary> /// /// </summary> /// <param name="element"></param> public bool insertElement(SceneElement element) { bool inserted = false; //if (element.BoundingBox.Intersects(BoundingBox)) { if (m_children != null) { // we only want to insert the object in one node. // if more then one child contains the node we insert it in the current node short nodeCount = 0; OctreeNode target = null; foreach (OctreeNode node in m_children) { if (element.BoundingBox.Intersects(node.BoundingBox)) { ++nodeCount; target = node; } } if (nodeCount == 1) { inserted = target.insertElement(element); } else { insertHere(element); inserted = true; } } else { if (m_level < MaxLevel) { split(); foreach (OctreeNode node in m_children) { inserted = inserted || node.insertElement(element); } } else { insertHere(element); inserted = true; } } } return inserted; }
/// <summary> /// Gathers all colliders in the gameobject. /// </summary> public override void doInitialize() { // get position IPosition3D pos = Owner.getFirst(typeof(IPosition3D)) as IPosition3D; if (pos != null) { m_position = pos.Position; m_lastPosition = pos.Position; m_canMove = pos.Moves; pos.PositionChanged += new XnaScrapCore.Core.Delegates.Position3DChangedEventHandler(PositionChanged); } // get orientation IOrientation3D orientation = Owner.getFirst(typeof(IOrientation3D)) as IOrientation3D; if (orientation != null) { m_orientation = orientation.Orientation; orientation.OrientationChanged += new XnaScrapCore.Core.Delegates.OrientationChangedEventHandler(OrientationChanged); } //TODO gather colliders and add all to the bounding box List<AbstractElement> colliders = Owner.getAll(typeof(AbstractCollider)); BoundingBox bb = new BoundingBox(); if (colliders.Count > 0) { AbstractCollider firstCollider = colliders[0] as AbstractCollider; firstCollider.update(m_position); bb = firstCollider.BoundingBox; m_colliders.Add(firstCollider); for (int i = 1; i < colliders.Count; ++i) { AbstractCollider ac = colliders[i] as AbstractCollider; ac.update(m_position); m_colliders.Add(ac); bb = Microsoft.Xna.Framework.BoundingBox.CreateMerged(bb, ac.BoundingBox); } } // add to scenemanagement ISceneManager sceneManager = Owner.Game.Services.GetService(typeof(ISceneManager)) as ISceneManager; if (sceneManager != null) { m_sceneElement = sceneManager.insertElementCollision(bb, Owner); } // add to collisionmanagement m_manager.addCollider(this); base.doInitialize(); }