Exemple #1
0
		public PCZCamera( string name, SceneManager sceneManager )
			: base( name, sceneManager )
		{
			this.box = new AxisAlignedBox( new Vector3( -0.1f, -0.1f, -0.1f ), new Vector3( 0.1f, 0.1f, 0.1f ) );
			this.extraCullingFrustum = new PCZFrustum();
			this.extraCullingFrustum.SetUseOriginPlane( true );
		}
Exemple #2
0
 public PCZCamera(string name, SceneManager sceneManager)
     : base(name, sceneManager)
 {
     this.box = new AxisAlignedBox(new Vector3(-0.1f, -0.1f, -0.1f), new Vector3(0.1f, 0.1f, 0.1f));
     this.extraCullingFrustum = new PCZFrustum();
     this.extraCullingFrustum.SetUseOriginPlane(true);
 }
Exemple #3
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);
        }
Exemple #4
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;
						}
					}
				}
			}
		}
Exemple #5
0
		/** (recursive) check the given light against all portals in the zone
		*/

		public abstract void CheckLightAgainstPortals( PCZLight light, ulong frameCount, PCZFrustum portalFrustum,
		                                               Portal ignorePortal );
Exemple #6
0
        /** (recursive) check the given light against all portals in the zone
         */

        public abstract void CheckLightAgainstPortals(PCZLight light, ulong frameCount, PCZFrustum portalFrustum,
                                                      Portal ignorePortal);
Exemple #7
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 );
		}
Exemple #8
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;
                        }
                    }
                }
            }
        }