Пример #1
0
        /** Update the zone data for the portals in the zone
         * NOTE: All portal spatial data must be up-to-date before calling this routine.
         */

        public override void UpdatePortalsZoneData()
        {
            var transferPortalList = new List <Portal>();

            // check each portal to see if it's intersecting another portal of greater size
            foreach (Portal p in mPortals)
            {
                Real pRadius = p.getRadius();
                // First we check against portals in the SAME zone (and only if they have a
                // target zone different from the home zone)
                foreach (Portal p2 in mPortals)
                {
                    // only check against bigger portals (this will also prevent checking against self)
                    // and only against portals which point to another zone
                    if (pRadius < p2.getRadius() && p2.getTargetZone() != this)
                    {
                        // Portal#2 is bigger than Portal1, check for crossing
                        if (p.crossedPortal(p2) && p.getCurrentHomeZone() != p2.getTargetZone())
                        {
                            // portal#1 crossed portal#2 - flag portal#1 to be moved to portal#2's target zone
                            p.setNewHomeZone(p2.getTargetZone());
                            transferPortalList.Add(p);
                            break;
                        }
                    }
                }

                // Second we check against portals in the target zone (and only if that target
                // zone is different from the home zone)
                PCZone tzone = p.getTargetZone();
                if (tzone != this)
                {
                    foreach (Portal p3 in mPortals)
                    {
                        // only check against bigger portals
                        if (pRadius < p3.getRadius())
                        {
                            // Portal#3 is bigger than Portal#1, check for crossing
                            if (p.crossedPortal(p3) && p.getCurrentHomeZone() != p3.getTargetZone())
                            {
                                // Portal#1 crossed Portal#3 - switch target zones for Portal#1
                                p.setTargetZone(p3.getTargetZone());
                                break;
                            }
                        }
                    }
                }
            }
            // transfer any portals to new zones that have been flagged
            foreach (Portal p in transferPortalList)
            {
                if (null != p.getNewHomeZone())
                {
                    RemovePortal(p);
                    p.getNewHomeZone().AddPortal(p);
                    p.setNewHomeZone(null);
                }
            }
            transferPortalList.Clear();
        }
Пример #2
0
 //-----------------------------------------------------------------------
 public void RemoveZoneFromAffectedZonesList(PCZone zone)
 {
     if (this.affectedZonesList.Contains(zone))
     {
         this.affectedZonesList.Remove(zone);
     }
 }
Пример #3
0
		public PCZSceneNode( SceneManager creator, string name )
			: base( creator, name )
		{
			homeZone = null;
			anchored = false;
			allowedToVisit = true;
			lastVisibleFrame = 0;
			lastVisibleFromCamera = null;
			enabled = true;
		}
Пример #4
0
 public PCZSceneNode(SceneManager creator, string name)
     : base(creator, name)
 {
     this.homeZone         = null;
     this.anchored         = false;
     AllowToVisit          = true;
     LastVisibleFrame      = 0;
     LastVisibleFromCamera = null;
     Enabled = true;
 }
Пример #5
0
		public PCZSceneNode( SceneManager creator, string name )
			: base( creator, name )
		{
			this.homeZone = null;
			this.anchored = false;
			AllowToVisit = true;
			LastVisibleFrame = 0;
			LastVisibleFromCamera = null;
			Enabled = true;
		}
Пример #6
0
        public void UpdateZones(PCZone defaultZone, ulong frameCount)
        {
            //update the zones this light affects
            PCZone homeZone;

            this.affectedZonesList.Clear();
            this.affectsVisibleZone = false;
            var sn = (PCZSceneNode)(ParentSceneNode);

            if (null != sn)
            {
                // start with the zone the light is in
                homeZone = sn.HomeZone;
                if (null != homeZone)
                {
                    this.affectedZonesList.Add(homeZone);
                    if (homeZone.LastVisibleFrame == frameCount)
                    {
                        this.affectsVisibleZone = true;
                    }
                }
                else
                {
                    // error - scene node has no homezone!
                    // just say it affects the default zone and leave it at that.
                    this.affectedZonesList.Add(defaultZone);
                    if (defaultZone.LastVisibleFrame == frameCount)
                    {
                        this.affectsVisibleZone = true;
                    }
                    return;
                }
            }
            else
            {
                // ERROR! not connected to a scene node,
                // just say it affects the default zone and leave it at that.
                this.affectedZonesList.Add(defaultZone);
                if (defaultZone.LastVisibleFrame == frameCount)
                {
                    this.affectsVisibleZone = true;
                }
                return;
            }

            // now check visibility of each portal in the home zone.  If visible to
            // the light then add the target zone of the portal to the list of
            // affected zones and recurse into the target zone
            var     portalFrustum = new PCZFrustum();
            Vector3 v             = GetDerivedPosition();

            portalFrustum.SetOrigin(v);
            homeZone.CheckLightAgainstPortals(this, frameCount, portalFrustum, null);
        }
Пример #7
0
        public void SetZoneData(PCZone zone, ZoneData zoneData)
        {
            // first make sure that the data doesn't already exist
            if (this.zoneData.ContainsKey(zone.Name))
            {
                throw new AxiomException("A ZoneData associated with zone " + zone.Name +
                                         " already exists. PCZSceneNode::setZoneData");
            }

            //mZoneData[zone->getName()] = zoneData;
            // is this equivalent? i think so...
            this.zoneData.Add(zone.Name, zoneData);
        }
Пример #8
0
 // Set the zone this portal is in.
 public void setCurrentHomeZone(PCZone z)
 {
     // do this here since more than one function calls setCurrentHomeZone
     // also _addPortal is abstract, so easier to do it here.
     if (null != z)
     {
         // inform old zone of portal change.
         if (null != this.mCurrentHomeZone)
         {
             this.mCurrentHomeZone.PortalsUpdated = true;
         }
         z.PortalsUpdated = true; // inform new zone of portal change
     }
     this.mCurrentHomeZone = z;
 }
Пример #9
0
        public override void Execute(ISceneQueryListener listener)
        {
            var list         = new List <PCZSceneNode>();
            var checkedNodes = new List <PCZSceneNode>();

            foreach (PlaneBoundedVolume volume in volumes)
            {
                //find the nodes that intersect the AAB
                ((PCZSceneManager)creator).FindNodesIn(volume, ref list, this.startZone, (PCZSceneNode)this.excludeNode);

                //grab all moveables from the node that intersect...
                foreach (PCZSceneNode node in list)
                {
                    // avoid double-check same scene node
                    if (!checkedNodes.Contains(node))
                    {
                        continue;
                    }

                    checkedNodes.Add(node);

                    foreach (MovableObject m in node.Objects)
                    {
                        if ((m.QueryFlags & queryMask) != 0 && (m.TypeFlags & this.queryTypeMask) != 0 && m.IsAttached &&
                            volume.Intersects(m.GetWorldBoundingBox()))
                        {
                            listener.OnQueryResult(m);
                            // deal with attached objects, since they are not directly attached to nodes
                            if (m.MovableType == "Entity")
                            {
                                //Check: not sure here...
                                var e = (Entity)m;
                                foreach (MovableObject c in e.SubEntities)
                                {
                                    if ((c.QueryFlags & queryMask) > 0 && volume.Intersects(c.GetWorldBoundingBox()))
                                    {
                                        listener.OnQueryResult(c);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // reset startzone and exclude node
            this.startZone   = null;
            this.excludeNode = null;
        }
Пример #10
0
        /* returns true if zone is in the node's visiting zones map
         * false otherwise.
         */

        public bool IsVisitingZone(PCZone zone)
        {
            if (this.visitingZones.ContainsKey(zone.Name))
            {
                return(true);
            }

            return(false);

            //ZoneMap::iterator i;
            //i = mVisitingZones.find(zone->getName());
            //if (i != mVisitingZones.end())
            //{
            //    return true;
            //}
            //return false;
        }
Пример #11
0
        /* The following function checks if a node has left it's current home zone.
         * This is done by checking each portal in the zone.  If the node has crossed
         * the portal, then the current zone is no longer the home zone of the node.  The
         * function then recurses into the connected zones.  Once a zone is found where
         * the node does NOT cross out through a portal, that zone is the new home zone.
         *      NOTE: For this function to work, the node must start out in the proper zone to
         *                begin with!
         */

        public override PCZone UpdateNodeHomeZone(PCZSceneNode pczsn, bool allowBackTouches)
        {
            // default to newHomeZone being the current home zone
            PCZone newHomeZone = pczsn.HomeZone;

            // Check all portals of the start zone for crossings!
            foreach (Portal portal in mPortals)
            {
                PortalIntersectResult pir = portal.intersects(pczsn);
                switch (pir)
                {
                default:
                case PortalIntersectResult.NO_INTERSECT:       // node does not intersect portal - do nothing
                case PortalIntersectResult.INTERSECT_NO_CROSS: // node intersects but does not cross portal - do nothing
                    break;

                case PortalIntersectResult.INTERSECT_BACK_NO_CROSS:     // node intersects but on the back of the portal
                    if (allowBackTouches)
                    {
                        // node is on wrong side of the portal - fix if we're allowing backside touches
                        if (portal.getTargetZone() != this && portal.getTargetZone() != pczsn.HomeZone)
                        {
                            // set the home zone of the node to the target zone of the portal
                            pczsn.HomeZone = portal.getTargetZone();
                            // continue checking for portal crossings in the new zone
                            newHomeZone = portal.getTargetZone().UpdateNodeHomeZone(pczsn, false);
                        }
                    }
                    break;

                case PortalIntersectResult.INTERSECT_CROSS:
                    // node intersects and crosses the portal - recurse into that zone as new home zone
                    if (portal.getTargetZone() != this && portal.getTargetZone() != pczsn.HomeZone)
                    {
                        // set the home zone of the node to the target zone of the portal
                        pczsn.HomeZone = portal.getTargetZone();
                        // continue checking for portal crossings in the new zone
                        newHomeZone = portal.getTargetZone().UpdateNodeHomeZone(pczsn, true);
                    }
                    break;
                }
            }

            // return the new home zone
            return(newHomeZone);
        }
Пример #12
0
        public override void Execute(IIntersectionSceneQueryListener listener)
        {
            var set = new Dictionary <MovableObject, MovableObject>();

            // Iterate over all movable types
            foreach (Core.MovableObjectFactory factory in Root.Instance.MovableObjectFactories.Values)
            {
                MovableObjectCollection col = creator.GetMovableObjectCollection(factory.Type);
                foreach (MovableObject e in col.Values)
                {
                    PCZone zone = ((PCZSceneNode)(e.ParentSceneNode)).HomeZone;
                    var    list = new List <PCZSceneNode>();
                    //find the nodes that intersect the AAB
                    ((PCZSceneManager)creator).FindNodesIn(e.GetWorldBoundingBox(), ref list, zone, null);
                    //grab all moveables from the node that intersect...
                    foreach (PCZSceneNode node in list)
                    {
                        foreach (MovableObject m in node.Objects)
                        {
                            // MovableObject m =
                            if (m != e && !set.ContainsKey(m) && !set.ContainsKey(e) && (m.QueryFlags & queryMask) != 0 &&
                                (m.TypeFlags & this.queryTypeMask) != 0 && m.IsAttached &&
                                e.GetWorldBoundingBox().Intersects(m.GetWorldBoundingBox()))
                            {
                                listener.OnQueryResult(e, m);
                                // deal with attached objects, since they are not directly attached to nodes
                                if (m.MovableType == "Entity")
                                {
                                    var e2 = (Entity)m;
                                    foreach (MovableObject c in e2.SubEntities)
                                    {
                                        if ((c.QueryFlags & queryMask) != 0 && e.GetWorldBoundingBox().Intersects(c.GetWorldBoundingBox()))
                                        {
                                            listener.OnQueryResult(e, c);
                                        }
                                    }
                                }
                            }
                            set.Add(e, m);
                        }
                    }
                }
            }
        }
Пример #13
0
        public override void Execute(IRaySceneQueryListener listener)
        {
            var list = new List <PCZSceneNode>();

            //find the nodes that intersect the AAB
            ((PCZSceneManager)creator).FindNodesIn(ray, ref list, this.startZone, (PCZSceneNode)this.excludeNode);

            //grab all moveables from the node that intersect...

            foreach (PCZSceneNode node in list)
            {
                foreach (MovableObject m in node.Objects)
                {
                    if ((m.QueryFlags & queryMask) != 0 && (m.TypeFlags & this.queryTypeMask) != 0 && m.IsAttached)
                    {
                        IntersectResult result = ray.Intersects(m.GetWorldBoundingBox());
                        if (result.Hit)
                        {
                            listener.OnQueryResult(m, result.Distance);
                            // deal with attached objects, since they are not directly attached to nodes
                            if (m.MovableType == "Entity")
                            {
                                //Check: not sure here...
                                var e = (Entity)m;
                                foreach (MovableObject c in e.SubEntities)
                                {
                                    if ((c.QueryFlags & queryMask) > 0)
                                    {
                                        result = ray.Intersects(c.GetWorldBoundingBox());
                                        if (result.Hit)
                                        {
                                            listener.OnQueryResult(c, result.Distance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // reset startzone and exclude node
            this.startZone   = null;
            this.excludeNode = null;
        }
Пример #14
0
        /* Remove all references that the node has to the given zone
         */

        public void RemoveReferencesToZone(PCZone zone)
        {
            if (this.homeZone == zone)
            {
                this.homeZone = null;
            }

            if (this.visitingZones.ContainsKey(zone.Name))
            {
                this.visitingZones.Remove(zone.Name);
            }

            // search the map of visiting zones and remove
            //ZoneMap::iterator i;
            //i = mVisitingZones.find(zone->getName());
            //if (i != mVisitingZones.end())
            //{
            //    mVisitingZones.erase(i);
            //}
        }
Пример #15
0
        public PCZone CreatePCZone(PCZSceneManager pczsm, string zoneType, string zoneName)
        {
            //find a factory that supports this zone type and then call createPCZone() on it
            PCZone inst = null;

            foreach (PCZoneFactory factory in this.pCZoneFactories.Values)
            {
                if (factory.SupportsPCZoneType(zoneType))
                {
                    // use this factory
                    inst = factory.CreatePCZone(pczsm, zoneName);
                }
            }
            if (null == inst)
            {
                // Error!
                throw new AxiomException("No factory found for zone of type '" + zoneType + "' PCZoneFactoryManager.CreatePCZone");
            }
            return(inst);
        }
Пример #16
0
        public Portal(string name, PORTAL_TYPE type)
        {
            this.mType            = type;
            this.mName            = name;
            this.mTargetZone      = null;
            this.mCurrentHomeZone = null;
            this.mNewHomeZone     = null;
            this.mTargetPortal    = null;
            this.mNode            = null;
            this.mRadius          = 0.0;
            this.mDirection       = Math.Vector3.UnitZ;
            this.mLocalsUpToDate  = false;
            this.mDerivedSphere   = new Sphere();
            this.mDerivedPlane    = new Plane();
            // set prevWorldTransform to a zero'd out matrix
            this.prevWorldTransform = Math.Matrix4.Zero;
            // default to open
            this.mOpen = true;
            switch (this.mType)
            {
            default:
            case PORTAL_TYPE.PORTAL_TYPE_QUAD:
                this.mCorners        = new Vector3[4];
                this.mDerivedCorners = new Vector3[4];
                break;

            case PORTAL_TYPE.PORTAL_TYPE_AABB:
                this.mCorners        = new Vector3[2];
                this.mDerivedCorners = new Vector3[2];
                break;

            case PORTAL_TYPE.PORTAL_TYPE_SPHERE:
                this.mCorners        = new Vector3[2];
                this.mDerivedCorners = new Vector3[2];
                break;
            }
        }
Пример #17
0
		public OctreeZoneData( PCZSceneNode node, PCZone zone )
			: base( node, zone )
		{
			this.mOctant = null;
			this.mOctreeWorldAABB = AxisAlignedBox.Null;
		}
Пример #18
0
		public void FindNodesIn( Sphere sphere,
								 ref List<PCZSceneNode> list,
								 PCZone startZone,
								 PCZSceneNode exclude )
		{
			List<Portal> visitedPortals = new List<Portal>();
			if ( null != startZone )
			{
				// start in startzone, and recurse through portals if necessary
				startZone.FindNodes( sphere, ref list, visitedPortals, true, true, exclude );
			}
			else
			{
				// no start zone specified, so check all zones
				foreach ( PCZone zone in zones )
				{
					zone.FindNodes( sphere, ref list, visitedPortals, false, false, exclude );
				}
			}
		}
Пример #19
0
		/// <summary>
		///     Finds any entities that intersect the AAB for the query.
		/// </summary>
		/// <param name="listener">
		///     The listener to call when we find the results.
		/// </param>
		public override void Execute( ISceneQueryListener listener )
		{
			var list = new List<PCZSceneNode>();
			//find the nodes that intersect the AAB
			( (PCZSceneManager)creator ).FindNodesIn( box, ref list, this.startZone, (PCZSceneNode)this.excludeNode );

			//grab all moveables from the node that intersect...

			foreach ( PCZSceneNode node in list )
			{
				foreach ( MovableObject m in node.Objects )
				{
					if ( ( m.QueryFlags & queryMask ) != 0 && ( m.TypeFlags & this.queryTypeMask ) != 0 && m.IsAttached &&
					     box.Intersects( m.GetWorldBoundingBox() ) )
					{
						listener.OnQueryResult( m );
						// deal with attached objects, since they are not directly attached to nodes
						if ( m.MovableType == "Entity" )
						{
							//Check: not sure here...
							var e = (Entity)m;
							foreach ( MovableObject c in e.SubEntities )
							{
								if ( ( c.QueryFlags & queryMask ) > 0 )
								{
									listener.OnQueryResult( c );
								}
							}
						}
					}
				}
			}
			// reset startzone and exclude node
			this.startZone = null;
			this.excludeNode = null;
		}
Пример #20
0
		public void AddZoneToVisitingZonesMap( PCZone zone )
		{
			visitingZones[ zone.Name ] = zone;
		}
Пример #21
0
 // Set the zone this portal should be moved to
 public void setNewHomeZone(PCZone z)
 {
     this.mNewHomeZone = z;
 }
Пример #22
0
		/* Remove all references that the node has to the given zone
		*/
		public void RemoveReferencesToZone( PCZone zone )
		{
			if ( homeZone == zone )
			{
				homeZone = null;
			}

			if ( visitingZones.ContainsKey( zone.Name ) )
			{
				visitingZones.Remove( zone.Name );
			}

			// search the map of visiting zones and remove
			//ZoneMap::iterator i;
			//i = mVisitingZones.find(zone->getName());
			//if (i != mVisitingZones.end())
			//{
			//    mVisitingZones.erase(i);
			//}
		}
Пример #23
0
 public void AnchorToHomeZone(PCZone zone)
 {
     this.homeZone = zone;
     this.anchored = true;
 }
Пример #24
0
		public void FindNodesIn( Ray r, ref List<PCZSceneNode> list, PCZone startZone, PCZSceneNode exclude )
		{
			var visitedPortals = new List<Portal>();
			if ( null != startZone )
			{
				// start in startzone, and recurse through portals if necessary
				startZone.FindNodes( r, ref list, visitedPortals, true, true, exclude );
			}
			else
			{
				foreach ( PCZone zone in this.zones )
				{
					zone.FindNodes( r, ref list, visitedPortals, false, false, exclude );
				}
			}
		}
Пример #25
0
		public PCZSceneManager( string name )
			: base( name )
		{
			this.defaultZone = null;
			this.activeCameraZone = null;
			this.zoneFactoryManager = null;
			this.showPortals = false;
			this.defaultZoneTypeName = "ZoneType_Default";
			this.defaultZoneFileName = "none";
			rootSceneNode = new PCZSceneNode( this, "Root" );
			defaultRootNode = rootSceneNode;
		}
Пример #26
0
		//---------------------------------------------------------------------
		protected override void PrepareShadowTextures( Camera cam, Viewport vp )
		{
			if ( ( (PCZSceneNode)cam.ParentSceneNode ) != null )
			{
				this.activeCameraZone = ( (PCZSceneNode)cam.ParentSceneNode ).HomeZone;
			}
			base.PrepareShadowTextures( cam, vp );
		}
Пример #27
0
		public void FindNodesIn( PlaneBoundedVolume volumes, ref List<PCZSceneNode> list, PCZone startZone,
		                         PCZSceneNode exclude )
		{
			var visitedPortals = new List<Portal>();
			if ( null != startZone )
			{
				// start in startzone, and recurse through portals if necessary
				startZone.FindNodes( volumes, ref list, visitedPortals, true, true, exclude );
			}
			else
			{
				// no start zone specified, so check all zones
				foreach ( PCZone zone in this.zones )
				{
					zone.FindNodes( volumes, ref list, visitedPortals, false, false, exclude );
				}
			}
		}
Пример #28
0
		//-----------------------------------------------------------------------
		/** Add a zone to the zones affected list
		*/

		public void AddZoneToAffectedZonesList( PCZone zone )
		{
			this.affectedZonesList.Add( zone );
		}
Пример #29
0
		//-----------------------------------------------------------------------
		public void RemoveZoneFromAffectedZonesList( PCZone zone )
		{
			if ( this.affectedZonesList.Contains( zone ) )
			{
				this.affectedZonesList.Remove( zone );
			}
		}
Пример #30
0
		public void UpdateZones( PCZone defaultZone, ulong frameCount )
		{
			//update the zones this light affects
			PCZone homeZone;
			this.affectedZonesList.Clear();
			this.affectsVisibleZone = false;
			var sn = (PCZSceneNode)( ParentSceneNode );
			if ( null != sn )
			{
				// start with the zone the light is in
				homeZone = sn.HomeZone;
				if ( null != homeZone )
				{
					this.affectedZonesList.Add( homeZone );
					if ( homeZone.LastVisibleFrame == frameCount )
					{
						this.affectsVisibleZone = true;
					}
				}
				else
				{
					// error - scene node has no homezone!
					// just say it affects the default zone and leave it at that.
					this.affectedZonesList.Add( defaultZone );
					if ( defaultZone.LastVisibleFrame == frameCount )
					{
						this.affectsVisibleZone = true;
					}
					return;
				}
			}
			else
			{
				// ERROR! not connected to a scene node,
				// just say it affects the default zone and leave it at that.
				this.affectedZonesList.Add( defaultZone );
				if ( defaultZone.LastVisibleFrame == frameCount )
				{
					this.affectsVisibleZone = true;
				}
				return;
			}

			// now check visibility of each portal in the home zone.  If visible to
			// the light then add the target zone of the portal to the list of
			// affected zones and recurse into the target zone
			var portalFrustum = new PCZFrustum();
			Vector3 v = GetDerivedPosition();
			portalFrustum.SetOrigin( v );
			homeZone.CheckLightAgainstPortals( this, frameCount, portalFrustum, null );
		}
Пример #31
0
		/** check if a zone is in the list of zones affected by the light */

		public bool AffectsZone( PCZone zone )
		{
			return this.affectedZonesList.Contains( zone );
		}
Пример #32
0
		public void Init( string defaultZoneTypeName, string filename )
		{
			// delete ALL portals
			this.portals.Clear();

			// delete all the zones
			this.zones.Clear();

			this.frameCount = 0;

			this.defaultZoneTypeName = defaultZoneTypeName;
			this.defaultZoneFileName = filename;

			// create a new default zone
			this.zoneFactoryManager = PCZoneFactoryManager.Instance;
			this.defaultZone = CreateZoneFromFile( this.defaultZoneTypeName, "Default_Zone", RootSceneNode as PCZSceneNode,
			                                       this.defaultZoneFileName );
		}
Пример #33
0
		/* returns true if zone is in the node's visiting zones map
		   false otherwise.
		*/
		public bool IsVisitingZone( PCZone zone )
		{
			if ( visitingZones.ContainsKey( zone.Name ) )
			{
				return true;
			}

			return false;

			//ZoneMap::iterator i;
			//i = mVisitingZones.find(zone->getName());
			//if (i != mVisitingZones.end())
			//{
			//    return true;
			//}
			//return false;
		}
Пример #34
0
        /** (recursive) check the given light against all portals in the zone
         * NOTE: This is the default implementation, which doesn't take advantage
         *       of any zone-specific optimizations for checking portal visibility
         */

        public override void CheckLightAgainstPortals(PCZLight light, ulong frameCount, PCZFrustum portalFrustum,
                                                      Portal ignorePortal)
        {
            foreach (Portal p in mPortals)
            {
                //Portal * p = *it;
                if (p != ignorePortal)
                {
                    // calculate the direction vector from light to portal
                    Vector3 lightToPortal = p.getDerivedCP() - light.GetDerivedPosition();
                    if (portalFrustum.IsObjectVisible(p))
                    {
                        // portal is facing the light, but some light types need to
                        // check illumination radius too.
                        PCZone targetZone = p.getTargetZone();
                        switch (light.Type)
                        {
                        case LightType.Point:
                            // point lights - just check if within illumination range
                            if (lightToPortal.Length <= light.AttenuationRange)
                            {
                                // if portal is quad portal it must be pointing towards the light
                                if ((p.Type == PORTAL_TYPE.PORTAL_TYPE_QUAD && lightToPortal.Dot(p.getDerivedDirection()) < 0.0) ||
                                    (p.Type != PORTAL_TYPE.PORTAL_TYPE_QUAD))
                                {
                                    if (!light.AffectsZone(targetZone))
                                    {
                                        light.AddZoneToAffectedZonesList(targetZone);
                                        if (targetZone.LastVisibleFrame == frameCount)
                                        {
                                            light.AffectsVisibleZone = true;
                                        }
                                        // set culling frustum from the portal
                                        portalFrustum.AddPortalCullingPlanes(p);
                                        // recurse into the target zone of the portal
                                        p.getTargetZone().CheckLightAgainstPortals(light, frameCount, portalFrustum, p.getTargetPortal());
                                        // remove the planes added by this portal
                                        portalFrustum.RemovePortalCullingPlanes(p);
                                    }
                                }
                            }
                            break;

                        case LightType.Directional:
                            // directionals have infinite range, so just make sure
                            // the direction is facing the portal
                            if (lightToPortal.Dot(light.DerivedDirection) >= 0.0)
                            {
                                // if portal is quad portal it must be pointing towards the light
                                if ((p.Type == PORTAL_TYPE.PORTAL_TYPE_QUAD && lightToPortal.Dot(p.getDerivedDirection()) < 0.0) ||
                                    (p.Type == PORTAL_TYPE.PORTAL_TYPE_QUAD))
                                {
                                    if (!light.AffectsZone(targetZone))
                                    {
                                        light.AddZoneToAffectedZonesList(targetZone);
                                        if (targetZone.LastVisibleFrame == frameCount)
                                        {
                                            light.AffectsVisibleZone = true;
                                        }
                                        // set culling frustum from the portal
                                        portalFrustum.AddPortalCullingPlanes(p);
                                        // recurse into the target zone of the portal
                                        p.getTargetZone().CheckLightAgainstPortals(light, frameCount, portalFrustum, p.getTargetPortal());
                                        // remove the planes added by this portal
                                        portalFrustum.RemovePortalCullingPlanes(p);
                                    }
                                }
                            }
                            break;

                        case LightType.Spotlight:
                            // spotlights - just check if within illumination range
                            // Technically, we should check if the portal is within
                            // the cone of illumination, but for now, we'll leave that
                            // as a future optimisation.
                            if (lightToPortal.Length <= light.AttenuationRange)
                            {
                                // if portal is quad portal it must be pointing towards the light
                                if ((p.Type == PORTAL_TYPE.PORTAL_TYPE_QUAD && lightToPortal.Dot(p.getDerivedDirection()) < 0.0) ||
                                    (p.Type != PORTAL_TYPE.PORTAL_TYPE_QUAD))
                                {
                                    if (!light.AffectsZone(targetZone))
                                    {
                                        light.AddZoneToAffectedZonesList(targetZone);
                                        if (targetZone.LastVisibleFrame == frameCount)
                                        {
                                            light.AffectsVisibleZone = true;
                                        }
                                        // set culling frustum from the portal
                                        portalFrustum.AddPortalCullingPlanes(p);
                                        // recurse into the target zone of the portal
                                        p.getTargetZone().CheckLightAgainstPortals(light, frameCount, portalFrustum, p.getTargetPortal());
                                        // remove the planes added by this portal
                                        portalFrustum.RemovePortalCullingPlanes(p);
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
Пример #35
0
 /// <summary>
 ///     Creates a custom PCZ AAB query
 /// </summary>
 /// <param name="creator">
 ///     The SceneManager that creates the query.
 /// </param>
 public PCZAxisAlignedBoxSceneQuery(SceneManager creator)
     : base(creator)
 {
     this.startZone   = null;
     this.excludeNode = null;
 }
Пример #36
0
 public ZoneData(PCZSceneNode node, PCZone zone)
 {
     this.mAssociatedZone = zone;
     this.mAssociatedNode = node;
 }
Пример #37
0
 public void AddZoneToVisitingZonesMap(PCZone zone)
 {
     this.visitingZones[zone.Name] = zone;
 }
Пример #38
0
        /** check if a zone is in the list of zones affected by the light */

        public bool AffectsZone(PCZone zone)
        {
            return(this.affectedZonesList.Contains(zone));
        }
Пример #39
0
		public void AnchorToHomeZone( PCZone zone )
		{
			homeZone = zone;
			anchored = true;
		}
Пример #40
0
 // Set the 1st Zone the Portal connects to
 public void setTargetZone(PCZone z)
 {
     this.mTargetZone = z;
 }
Пример #41
0
 // get zone data for this node for given zone
 // NOTE: This routine assumes that the zone data is present!
 public ZoneData GetZoneData(PCZone zone)
 {
     return(this.zoneData[zone.Name]);
 }
Пример #42
0
		// create any zone-specific data necessary for all nodes for the given zone
		public void CreateZoneSpecificNodeData( PCZone zone )
		{
			if ( zone.RequiresZoneSpecificNodeData )
			{
				foreach ( PCZSceneNode node in sceneNodeList.Values )
				{
					zone.CreateNodeZoneData( node );
				}
			}
		}
Пример #43
0
		/// <summary>
		///     Creates a custom PCZ AAB query
		/// </summary>
		/// <param name="creator">
		///     The SceneManager that creates the query.
		/// </param>
		public PCZAxisAlignedBoxSceneQuery( SceneManager creator )
			: base( creator )
		{
			this.startZone = null;
			this.excludeNode = null;
		}
Пример #44
0
		// set the home zone for a scene node
		public void SetNodeHomeZone( SceneNode node, PCZone zone )
		{
			// cast the SceneNode to a PCZSceneNode
			var pczsn = (PCZSceneNode)node;
			pczsn.HomeZone = zone;
		}
Пример #45
0
		public Octree( PCZone zone, Octree parent )
		{
			this.wireBoundingBox = null;
			HalfSize = new Vector3();

			this.parent = parent;
			NunodeList = 0;
			this.zone = zone;

			//initialize all children to null.
			for ( int i = 0; i < 2; i++ )
			{
				for ( int j = 0; j < 2; j++ )
				{
					for ( int k = 0; k < 2; k++ )
					{
						this.Children[ i, j, k ] = null;
					}
				}
			}
		}
Пример #46
0
		public void SetZoneData( PCZone zone, ZoneData zoneData )
		{

			// first make sure that the data doesn't already exist
			if ( this.zoneData.ContainsKey( zone.Name ) )
			{
				throw new AxiomException( "A ZoneData associated with zone " + zone.Name + " already exists. PCZSceneNode::setZoneData" );
			}

			//mZoneData[zone->getName()] = zoneData;
			// is this equivalent? i think so...
			this.zoneData.Add( zone.Name, zoneData );
		}
Пример #47
0
		// Create portals for every door
		public void createPortals( SceneManager scene,
									   Entity room,
									   SceneNode roomNode,
									   PCZone zone,
									   short doorFlags,
									   bool isEnclosure )
		{
			string portalName;
			Vector3[] corners = new Vector3[ 4 ];

			if ( isEnclosure )
			{
				if ( ( doorFlags & (short)RoomDoors.DOOR_FRONT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 8 ];
					corners[ 1 ] = points[ 9 ];
					corners[ 2 ] = points[ 10 ];
					corners[ 3 ] = points[ 11 ];
					// create the portal
					portalName = room.Name + ( "_FrontDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_BACK ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 15 ];
					corners[ 1 ] = points[ 14 ];
					corners[ 2 ] = points[ 13 ];
					corners[ 3 ] = points[ 12 ];
					// create the portal
					portalName = room.Name + ( "_BackDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_TOP ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 16 ];
					corners[ 1 ] = points[ 17 ];
					corners[ 2 ] = points[ 18 ];
					corners[ 3 ] = points[ 19 ];
					// create the portal
					portalName = room.Name + ( "_TopDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_BOT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 23 ];
					corners[ 1 ] = points[ 22 ];
					corners[ 2 ] = points[ 21 ];
					corners[ 3 ] = points[ 20 ];
					// create the portal
					portalName = room.Name + ( "_BottomDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_LEFT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 27 ];
					corners[ 1 ] = points[ 26 ];
					corners[ 2 ] = points[ 25 ];
					corners[ 3 ] = points[ 24 ];
					// create the portal
					portalName = room.Name + ( "_LeftDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_RIGHT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 28 ];
					corners[ 1 ] = points[ 29 ];
					corners[ 2 ] = points[ 30 ];
					corners[ 3 ] = points[ 31 ];
					// create the portal
					portalName = room.Name + ( "_RightDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
			}
			else
			{
				if ( ( doorFlags & (short)RoomDoors.DOOR_FRONT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 11 ];
					corners[ 1 ] = points[ 10 ];
					corners[ 2 ] = points[ 9 ];
					corners[ 3 ] = points[ 8 ];
					// create the portal
					portalName = room.Name + ( "_FrontDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_BACK ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 12 ];
					corners[ 1 ] = points[ 13 ];
					corners[ 2 ] = points[ 14 ];
					corners[ 3 ] = points[ 15 ];
					// create the portal
					portalName = room.Name + ( "_BackDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_TOP ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 19 ];
					corners[ 1 ] = points[ 18 ];
					corners[ 2 ] = points[ 17 ];
					corners[ 3 ] = points[ 16 ];
					// create the portal
					portalName = room.Name + ( "_TopDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_BOT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 20 ];
					corners[ 1 ] = points[ 21 ];
					corners[ 2 ] = points[ 22 ];
					corners[ 3 ] = points[ 23 ];
					// create the portal
					portalName = room.Name + ( "_BottomDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_LEFT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 24 ];
					corners[ 1 ] = points[ 25 ];
					corners[ 2 ] = points[ 26 ];
					corners[ 3 ] = points[ 27 ];
					// create the portal
					portalName = room.Name + ( "_LeftDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
				if ( ( doorFlags & (short)RoomDoors.DOOR_RIGHT ) != 0 )
				{
					// set the corners to the front door corners
					corners[ 0 ] = points[ 31 ];
					corners[ 1 ] = points[ 30 ];
					corners[ 2 ] = points[ 29 ];
					corners[ 3 ] = points[ 28 ];
					// create the portal
					portalName = room.Name + ( "_RightDoorPortal" );
					Portal p = ( (PCZSceneManager)scene ).CreatePortal( portalName, PORTAL_TYPE.PORTAL_TYPE_QUAD );
					p.setCorners( corners );
					// associate the portal with the roomnode
					p.setNode( roomNode );
					// add the portal to the zone
					zone.AddPortal( p );
					// update derived values for the portal
					p.updateDerivedValues();
				}
			}
		}
Пример #48
0
		// get zone data for this node for given zone
		// NOTE: This routine assumes that the zone data is present!
		public ZoneData GetZoneData( PCZone zone )
		{
			return zoneData[ zone.Name ];
		}
Пример #49
0
		public ZoneData( PCZSceneNode node, PCZone zone )
		{
			this.mAssociatedZone = zone;
			this.mAssociatedNode = node;
		}
Пример #50
0
		// Set the home zone for a node
		public void AddPCZSceneNode( PCZSceneNode sn, PCZone homeZone )
		{
			// set the home zone
			sn.HomeZone = homeZone;
			// add the node
			homeZone.AddNode( sn );
		}
Пример #51
0
		//-----------------------------------------------------------------------
		public override void ClearScene()
		{
			DestroyAllStaticGeometry();

			// Clear root node of all children
			RootSceneNode.RemoveAllChildren();
			RootSceneNode.DetachAllObjects();

			sceneNodeList.Clear();
			autoTrackingSceneNodes.Clear();

			// delete all the zones
			this.zones.Clear();
			this.defaultZone = null;

			// Clear animations
			DestroyAllAnimations();

			// Remove sky nodes since they've been deleted
			skyBoxNode = skyPlaneNode = skyDomeNode = null;
			isSkyBoxEnabled = isSkyPlaneEnabled = isSkyDomeEnabled = false;

			// Clear render queue, empty completely
			if ( null != renderQueue )
			{
				renderQueue.Clear();
			}

			// re-initialize
			Init( this.defaultZoneTypeName, this.defaultZoneFileName );
		}
Пример #52
0
		// destroy an existing zone within the scene
		//if destroySceneNodes is true, then all nodes which have the destroyed
		//zone as their homezone are desroyed too.  If destroySceneNodes is false
		//then all scene nodes which have the zone as their homezone will have
		//their homezone pointer set to 0, which will allow them to be re-assigned
		//either by the user or via the automatic re-assignment routine
		public void DestroyZone( PCZone zone, bool destroySceneNodes )
		{
			// need to remove this zone from all lights affected zones list,
			// otherwise next frame _calcZonesAffectedByLights will call PCZLight::getNeedsUpdate()
			// which will try to access the zone pointer and will cause an access violation
			//HACK: again...
			MovableObjectCollection lightList = GetMovableObjectCollection( LightFactory.TypeName );
			lock ( lightList )
			{
				foreach ( PCZLight l in lightList.Values )
				{
					if ( l.NeedsUpdate )
					{
						// no need to check, this function does that anyway. if exists, is erased.
						l.RemoveZoneFromAffectedZonesList( zone );
					}
				}
			}

			// if not destroying scene nodes, then make sure any nodes who have
			foreach ( PCZSceneNode pczsn in sceneNodeList.Values )
			{
				if ( !destroySceneNodes )
				{
					if ( pczsn.HomeZone == zone )
					{
						pczsn.HomeZone = null;
					}
				}
				// reset all node visitor lists
				// note, it might be more efficient to only do this to nodes which
				// are actually visiting the zone being destroyed, but visitor lists
				// get cleared every frame anyway, so it's not THAT big a deal.
				pczsn.ClearNodeFromVisitedZones();
			}

			this.zones.Remove( zone );
		}
Пример #53
0
        //-----------------------------------------------------------------------

        /** Add a zone to the zones affected list
         */

        public void AddZoneToAffectedZonesList(PCZone zone)
        {
            this.affectedZonesList.Add(zone);
        }
Пример #54
0
		// Set the zone which contains the sky node
		public void SetSkyZone( PCZone zone )
		{
			if ( null == zone )
			{
				// if no zone specified, use default zone
				zone = this.defaultZone;
			}
			if ( null != skyBoxNode )
			{
				( (PCZSceneNode)skyBoxNode ).HomeZone = zone;
				( (PCZSceneNode)skyBoxNode ).AnchorToHomeZone( zone );
				zone.HasSky = true;
			}
			if ( null != skyDomeNode )
			{
				( (PCZSceneNode)skyDomeNode ).HomeZone = zone;
				( (PCZSceneNode)skyDomeNode ).AnchorToHomeZone( zone );
				zone.HasSky = true;
			}
			if ( null != skyPlaneNode )
			{
				( (PCZSceneNode)skyPlaneNode ).HomeZone = zone;
				( (PCZSceneNode)skyPlaneNode ).AnchorToHomeZone( zone );
				zone.HasSky = true;
			}
		}