示例#1
0
 protected override void OnEditorSelectionDebugRender( Camera camera, bool bigBorder,
     bool simpleGeometry)
 {
     Box box = GetBox();
     box.Expand( bigBorder ? .2f : .1f );
     camera.DebugGeometry.AddBox( box );
 }
示例#2
0
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            if (EntitySystemWorld.Instance.WorldSimulationType == WorldSimulationTypes.Editor ||
                EngineDebugSettings.DrawGameSpecificDebugGeometry)
            {
                camera.DebugGeometry.Color = new ColorValue(0, 0, 1);
                camera.DebugGeometry.AddBox(GetBox());
            }

            if (EntitySystemWorld.Instance.WorldSimulationType == WorldSimulationTypes.Editor ||
                EngineDebugSettings.DrawGameSpecificDebugGeometry)
            {
                Vec3 direction = -Rotation.GetForward();

                Vec3 point0 = Position + Rotation * new Vec3(0, -Scale.Y / 2, -Scale.Z / 2);
                Vec3 point1 = Position + Rotation * new Vec3(0, Scale.Y / 2, -Scale.Z / 2);
                Vec3 point2 = Position + Rotation * new Vec3(0, -Scale.Y / 2, Scale.Z / 2);
                Vec3 point3 = Position + Rotation * new Vec3(0, Scale.Y / 2, Scale.Z / 2);

                camera.DebugGeometry.Color = new ColorValue(0, 1, 0);
                camera.DebugGeometry.AddArrow(point0, point0 + direction);
                camera.DebugGeometry.AddArrow(point1, point1 + direction);
                camera.DebugGeometry.AddArrow(point2, point2 + direction);
                camera.DebugGeometry.AddArrow(point3, point3 + direction);
            }

            if (EngineDebugSettings.DrawGameSpecificDebugGeometry)
            {
                Line line = GetClimbingLine();
                camera.DebugGeometry.Color = new ColorValue(0, 1, 0);
                camera.DebugGeometry.AddLine(line);
            }
        }
示例#3
0
        void renderTargetUserControl1_Render( RenderTargetUserControl sender, Camera camera )
        {
            //update camera
            if( Map.Instance != null )
            {
                Vec3 position;
                Vec3 forward;
                Degree fov;

                //find "MapCamera_1"
                MapCamera mapCamera = Entities.Instance.GetByName( "MapCamera_1" ) as MapCamera;
                if( mapCamera != null )
                {
                    position = mapCamera.Position;
                    forward = mapCamera.Rotation * new Vec3( 1, 0, 0 );
                    fov = mapCamera.Fov;
                }
                else
                {
                    position = Map.Instance.EditorCameraPosition;
                    forward = Map.Instance.EditorCameraDirection.GetVector();
                    fov = Map.Instance.Fov;
                }

                if( fov == 0 )
                    fov = Map.Instance.Fov;

                renderTargetUserControl1.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance;
                renderTargetUserControl1.CameraFixedUp = Vec3.ZAxis;
                renderTargetUserControl1.CameraFov = fov;
                renderTargetUserControl1.CameraPosition = position;
                renderTargetUserControl1.CameraDirection = forward;
            }
        }
示例#4
0
        public override void Editor_RenderSelectionBorder( Camera camera, bool simpleGeometry, DynamicMeshManager manager, 
			DynamicMeshManager.MaterialData material )
        {
            DynamicMeshManager.Block block = manager.GetBlockFromCacheOrCreate( "CollisionVolume.Editor_RenderSelectionBorder: Box" );
            block.AddBox( false, new Box( Vec3.Zero, Vec3.One, Mat3.Identity ), null );

            Box box = GetBox();
            manager.AddBlockToScene( block, box.Center, box.Axis.ToQuat(), box.Extents, false, material );
        }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            if (EntitySystemWorld.Instance.IsEditor() && EditorLayer.Visible ||
                EngineDebugSettings.DrawGameSpecificDebugGeometry)
            {
                if (camera.Purpose == Camera.Purposes.MainCamera)
                {
                    camera.DebugGeometry.Color = new ColorValue(0, 0, 1);
                    camera.DebugGeometry.AddBox(GetBox());
                }
            }
        }
示例#6
0
 void renderTargetUserControl_Render(Camera camera)
 {
     _camera = camera;
     WorldView.UpdateFromWorldModel();
     Perspective.Check();
     renderTarget.CameraPosition = Perspective.Position.ToVec3();
     renderTarget.CameraDirection = Perspective.Rotation.ToQuat() * Vec3.XAxis;
     // TODO: what does it all mean?
     //new Angles(0f, 0f, MathFunctions.RadToDeg((float)_perspective.Heading)).ToQuat()
     //* new Angles(0f, MathFunctions.RadToDeg((float)_perspective.Tilt), 0f).ToQuat()
     //* Vec3.XAxis;
     if (SoundWorld.Instance != null)
         SoundWorld.Instance.SetListener(camera.Position, Vec3.Zero, camera.Direction, camera.Up);
     RenderEntityOverCursor(camera);
 }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            if (EntitySystemWorld.Instance.IsEditor() && EditorLayer.Visible ||
                EngineDebugSettings.DrawGameSpecificDebugGeometry)
            {
                if (camera.Purpose == Camera.Purposes.MainCamera)
                {
                    if (PhysicsModel != null)
                    {
                        foreach (Body body in PhysicsModel.Bodies)
                            body.DebugRender(camera.DebugGeometry, 0, 1, true, true, new ColorValue(1, 0, 0));
                    }
                }
            }
        }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            bool show = alwaysShowBorder;
            if (EntitySystemWorld.Instance.IsEditor() && !EditorLayer.Visible)
                show = false;
            if (MapEditorInterface.Instance != null && MapEditorInterface.Instance.IsEntitySelected(this))
                show = true;
            if (EngineDebugSettings.DrawGameSpecificDebugGeometry)
                show = true;

            if (show && camera.Purpose == Camera.Purposes.MainCamera)
            {
                camera.DebugGeometry.Color = new ColorValue(1, 0, 0);
                camera.DebugGeometry.AddBox(GetBox());
            }
        }
        public static void WalkForCamera( Camera camera, float farClipDistance,
            Set<SceneNode> outSceneNodes, Set<StaticMeshObject> outStaticMeshObjects)
        {
            Frustum frustum = FrustumUtils.GetFrustumByCamera( camera, farClipDistance );

            if( EngineDebugSettings.FrustumTest && camera.AllowFrustumTestMode )
            {
                frustum.HalfWidth *= .5f;
                frustum.HalfHeight *= .5f;
            }

            SceneManager.Instance._SceneGraph.GetObjects( ref frustum, false,
                _SceneObjectGroups.SceneNode | _SceneObjectGroups.StaticMeshObject,
                delegate( _ISceneObject sceneObject )
                {
                    _SceneObjectGroups objGroups = sceneObject._SceneData.Groups;

                    //StaticMeshObject
                    if( ( objGroups & _SceneObjectGroups.StaticMeshObject ) != 0 )
                    {
                        StaticMeshObject staticMeshObject = (StaticMeshObject)sceneObject;

                        if( !staticMeshObject.Visible )
                            return;
                        outStaticMeshObjects.Add( staticMeshObject );
                        return;
                    }

                    //SceneNode
                    if( ( objGroups & _SceneObjectGroups.SceneNode ) != 0 )
                    {
                        SceneNode sceneNode = (SceneNode)sceneObject;

                        if( !sceneNode.Visible )
                            return;
                        outSceneNodes.Add( sceneNode );
                        return;
                    }

                    Log.Fatal( "InternalSceneManagement: WalkForCamera: invalid sceneObject." );
                } );
        }
        public static void WalkForShadowGeneration( Camera camera, RenderLight light,
            float farClipDistance, Set<SceneNode> outSceneNodes,
            Set<StaticMeshObject> outStaticMeshObjects)
        {
            switch( light.Type )
            {
            case RenderLightType.Spot:
                WalkSpotLightShadowGeneration( camera, light, outSceneNodes,
                    outStaticMeshObjects );
                break;

            case RenderLightType.Point:
                WalkPointLightShadowGeneration( camera, light, outSceneNodes,
                    outStaticMeshObjects );
                break;

            case RenderLightType.Directional:
                WalkDirectionalLightShadowGeneration( camera, light, farClipDistance,
                    outSceneNodes, outStaticMeshObjects );
                break;
            }
        }
示例#11
0
        protected override void OnRender( Camera camera )
        {
            base.OnRender( camera );

            if( attachedMesh != null )
            {
                bool visible = camera.IsIntersectsFast( MapBounds );
                attachedMesh.Visible = visible;
                if( visible )
                {
                    //update mesh if needed
                    if( needUpdateVertices )
                    {
                        UpdateMeshVertices();
                        needUpdateVertices = false;
                    }
                    if( needUpdateIndices )
                    {
                        UpdateMeshIndices();
                        needUpdateIndices = false;
                    }
                }
            }
        }
示例#12
0
        void StaticMeshObject_AddToRenderQueue( StaticMeshObject staticMeshObject,
            Camera camera, ref bool allowRender)
        {
            if( needMaterialAlpha != 1 )
            {
                if( shaderBaseMaterial != null )
                {
                    //ShaderBase high level material

                    float diffusePower = shaderBaseMaterial.DiffusePower;
                    ColorValue diffuse = shaderBaseMaterial.DiffuseColor *
                        new ColorValue( diffusePower, diffusePower, diffusePower, 1 );
                    staticMeshObject.SetCustomGpuParameter(
                        (int)ShaderBaseMaterial.GpuParameters.dynamicDiffuseScale,
                        new Vec4( diffuse.Red, diffuse.Green, diffuse.Blue,
                        diffuse.Alpha * needMaterialAlpha ) );
                }
                else if( clonedStandardMaterial != null )
                {
                    //standard material

                    foreach( Technique technique in clonedStandardMaterial.Techniques )
                    {
                        foreach( Pass pass in technique.Passes )
                        {
                            ColorValue diffuse = pass.Diffuse;
                            pass.Diffuse = new ColorValue( diffuse.Red, diffuse.Green,
                                diffuse.Blue, needMaterialAlpha );
                        }
                    }
                }
            }
        }
示例#13
0
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            // Avoid some errors on destruction
            if (UniversalClock.Instance == null)
                return;

            UniversalClock.Instance.Update();
            float relDayTime = Convert.ToSingle(UniversalClock.Instance.JulianDay % 1d);

            // Updates each elements one by one
            foreach(CaelumBase element in mChildren)
                element.Update(relDayTime, camera);

            // Manages fog
            if (Fog.Instance != null && mManageFog)
            {
                Fog.Instance.ExpDensity = SkyColorModel.GetFogDensity() * FogDensityMultiplier;
                Fog.Instance.Color = SkyColorModel.GetFogColor();
            }
        }
            internal void DestroyViewport()
            {
                if (renderTargetListener != null)
                {
                    RenderTarget renderTarget = texture.GetBuffer().GetRenderTarget();
                    renderTarget.RemoveListener(renderTargetListener);
                    renderTargetListener.Dispose();
                    renderTargetListener = null;
                }
                if (viewport != null)
                {
                    viewport.Dispose();
                    viewport = null;
                }
                if (camera != null)
                {
                    camera.Dispose();
                    camera = null;
                }
                if (texture != null)
                {
                    texture.Dispose();
                    texture = null;
                    instance.preventTextureCreationRemainingFrames = 2;
                }

                initializedTextureSize = Vec2I.Zero;
            }
        protected override void OnControlledObjectRender( Camera camera )
        {
            base.OnControlledObjectRender( camera );

            if( camera != RendererWorld.Instance.DefaultCamera )
                return;

            //debug geometry
            if( EngineDebugSettings.DrawGameSpecificDebugGeometry )
            {
                //way
                if( generalTaskCurrentWayPoint != null )
                {
                    ReadOnlyCollection<MapCurvePoint> points = generalTaskWay.Points;

                    camera.DebugGeometry.Color = new ColorValue( 0, 1, 0, .5f );
                    int index = points.IndexOf( generalTaskCurrentWayPoint );
                    for( ; index < points.Count - 1; index++ )
                    {
                        camera.DebugGeometry.AddArrow(
                            points[ index ].Position, points[ index + 1 ].Position, 1 );
                    }
                }

                //view radius
                if( ControlledObject.ViewRadius != 0 )
                {
                    camera.DebugGeometry.Color = new ColorValue( 0, 1, 0, .5f );
                    Vec3 lastPos = Vec3.Zero;
                    for( float angle = 0; angle <= MathFunctions.PI * 2 + .001f;
                        angle += MathFunctions.PI / 16 )
                    {
                        Vec3 pos = ControlledObject.Position + new Vec3( MathFunctions.Cos( angle ),
                            MathFunctions.Sin( angle ), 0 ) * ControlledObject.ViewRadius;

                        if( angle != 0 )
                            camera.DebugGeometry.AddLine( lastPos, pos );

                        lastPos = pos;
                    }
                }

                if( unitWeapons == null )
                    FindUnitWeapons();

                //weapons
                foreach( Weapon weapon in unitWeapons )
                {
                    float radius = 0;

                    if( weapon.Type.WeaponNormalMode.IsInitialized )
                        radius = Math.Max( radius, weapon.Type.WeaponNormalMode.UseDistanceRange.Maximum );
                    if( weapon.Type.WeaponAlternativeMode.IsInitialized )
                        radius = Math.Max( radius, weapon.Type.WeaponAlternativeMode.UseDistanceRange.Maximum );

                    camera.DebugGeometry.Color = new ColorValue( 1, 0, 0, .5f );
                    Vec3 lastPos = Vec3.Zero;
                    for( float angle = 0; angle <= MathFunctions.PI * 2 + .001f;
                        angle += MathFunctions.PI / 16 )
                    {
                        Vec3 pos = weapon.Position +
                            new Vec3( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ), 0 ) * radius;

                        if( angle != 0 )
                            camera.DebugGeometry.AddLine( lastPos, pos );

                        lastPos = pos;
                    }
                }

                //move task
                if( moveTaskEnabled )
                {
                    camera.DebugGeometry.Color = new ColorValue( 0, 1, 0 );
                    camera.DebugGeometry.AddArrow( ControlledObject.Position, moveTaskPosition, 1 );
                }

                //attack tasks
                foreach( AttackTask attackTask in attackTasks )
                {
                    Vec3 targetPos = ( attackTask.TargetEntity != null ) ?
                        attackTask.TargetEntity.Position : attackTask.TargetPosition;

                    camera.DebugGeometry.Color = IsWeaponDirectedToTarget( attackTask ) ?
                        new ColorValue( 1, 1, 0 ) : new ColorValue( 1, 0, 0 );
                    camera.DebugGeometry.AddArrow( attackTask.Weapon.Position, targetPos, 1 );
                    camera.DebugGeometry.AddSphere( new Sphere( targetPos, 3 ), 10 );
                }
            }
        }
示例#16
0
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            if ((EngineDebugSettings.DrawGameSpecificDebugGeometry ||
                EngineApp.Instance.ApplicationType == EngineApp.ApplicationTypes.ResourceEditor) &&
                camera.Purpose == Camera.Purposes.MainCamera)
            {
                if (Active)
                {
                    float height = Type.ActiveAreaHeight;
                    float radius = Type.ActiveAreaRadius;
                    int segments = 32;

                    camera.DebugGeometry.Color = new ColorValue(0, 1, 0, .5f);

                    float angleStep = MathFunctions.PI * 2 / (float)segments;
                    for (float angle = 0; angle < MathFunctions.PI * 2 - angleStep * .5f; angle += angleStep)
                    {
                        float sin1 = MathFunctions.Sin(angle);
                        float cos1 = MathFunctions.Cos(angle);
                        float sin2 = MathFunctions.Sin(angle + angleStep);
                        float cos2 = MathFunctions.Cos(angle + angleStep);
                        Vec3 bottom1 = Position + new Vec3(cos1 * radius, sin1 * radius, 0);
                        Vec3 top1 = Position + new Vec3(cos1 * radius, sin1 * radius, height);
                        Vec3 bottom2 = Position + new Vec3(cos2 * radius, sin2 * radius, 0);
                        Vec3 top2 = Position + new Vec3(cos2 * radius, sin2 * radius, height);

                        camera.DebugGeometry.AddLine(bottom1, top1);
                        camera.DebugGeometry.AddLine(top1, top2);
                        camera.DebugGeometry.AddLine(bottom1, bottom2);
                    }
                }
            }
        }
            private void CreateViewport()
            {
                int index = instance.views.IndexOf(this);

                DestroyViewport();

                Vec2I textureSize = GetNeededTextureSize();

                string textureName = TextureManager.Instance.GetUniqueName(
                    string.Format("MultiViewRendering{0}", index));
                PixelFormat format = PixelFormat.R8G8B8;

                int fsaa;
                if (!int.TryParse(RendererWorld.InitializationOptions.FullSceneAntialiasing, out fsaa))
                    fsaa = 0;

                texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D,
                    textureSize, 1, 0, format, Texture.Usage.RenderTarget, false, fsaa);
                if (texture == null)
                {
                    Log.Fatal("MultiViewRenderingManager: Unable to create texture.");
                    return;
                }

                RenderTarget renderTarget = texture.GetBuffer().GetRenderTarget();
                renderTarget.AutoUpdate = true;
                renderTarget.AllowAdditionalMRTs = true;

                //create camera
                camera = SceneManager.Instance.CreateCamera(
                    SceneManager.Instance.GetUniqueCameraName(string.Format("MultiViewRendering{0}", index)));
                camera.Purpose = Camera.Purposes.MainCamera;

                //add viewport
                viewport = renderTarget.AddViewport(camera, 0);
                viewport.ShadowsEnabled = true;

                //Create compositor for HDR render technique
                bool hdrCompositor =
                    RendererWorld.Instance.DefaultViewport.GetCompositorInstance("HDR") != null;
                if (hdrCompositor)
                {
                    viewport.AddCompositor("HDR");
                    viewport.SetCompositorEnabled("HDR", true);
                }

                //FXAA antialiasing post effect
                bool fxaaCompositor =
                    RendererWorld.Instance.DefaultViewport.GetCompositorInstance("FXAA") != null;
                if (fxaaCompositor)
                {
                    viewport.AddCompositor("FXAA");
                    viewport.SetCompositorEnabled("FXAA", true);
                }

                //add listener
                renderTargetListener = new ViewRenderTargetListener(this);
                renderTarget.AddListener(renderTargetListener);

                initializedTextureSize = textureSize;
            }
示例#18
0
		protected override void OnRender( Camera camera )
		{
			base.OnRender( camera );

			//update visiblity of attached objects. hide car for First Person mode.
			{
				bool show = true;
				PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
				if( playerIntellect != null && playerIntellect.FPSCamera )
					show = false;
				foreach( MapObjectAttachedObject attachedObject in AttachedObjects )
					attachedObject.Visible = show;
			}

			//draw debug data
			if( camera.Purpose == Camera.Purposes.MainCamera && EngineDebugSettings.DrawDynamicPhysics && physicsVehicle != null )
			{
				float distanceSqr = MapBounds.GetPointDistanceSqr( camera.Position );
				float farClipDistance = camera.FarClipDistance;
				if( distanceSqr < farClipDistance * farClipDistance )
				{
					float renderTime = RendererWorld.Instance.FrameRenderTime;
					float timeInterpolate = ( renderTime - Entities.Instance.TickTime ) * EntitySystemWorld.Instance.GameFPS;
					MathFunctions.Clamp( ref timeInterpolate, 0, 1 );

					camera.DebugGeometry.SetSpecialDepthSettings( false, true );
					physicsVehicle.DebugRender( camera.DebugGeometry, timeInterpolate, 1, false, true, new ColorValue( 1, 0, 0 ) );
					camera.DebugGeometry.RestoreDefaultDepthSettings();
				}
			}
		}
        protected override void OnRender( Camera camera )
        {
            base.OnRender( camera );

            //update background area image
            if( backgroundImageMeshObject != null )
            {
                Rect area = GetDestinationArea();
                backgroundImageSceneNode.Position = new Vec3(
                    ( area.Maximum.X + area.Minimum.X ) / 2,
                    ( area.Maximum.Y + area.Minimum.Y ) / 2, -.04f );
                backgroundImageSceneNode.Scale = new Vec3( area.Size.X, area.Size.Y, 1 );
            }

            //render destination area
            {
                Rect area = GetDestinationArea();
                area.Expand( .1f );
                Bounds b = new Bounds(
                    area.Minimum.X, area.Minimum.Y, 0,
                    area.Maximum.X, area.Maximum.Y, 0 );
                camera.DebugGeometry.Color = new ColorValue( 0, 1, 0 );
                camera.DebugGeometry.AddBounds( b );
            }

            //render game area
            {
                Rect area = GetGameArea();
                area.Expand( .1f );
                Bounds b = new Bounds(
                    area.Minimum.X, area.Minimum.Y, 0,
                    area.Maximum.X, area.Maximum.Y, 0 );
                camera.DebugGeometry.Color = new ColorValue( 0, 1, 0 );
                camera.DebugGeometry.AddBounds( b );
            }
        }
示例#20
0
		void workAreaControl_Render( MultiViewRenderTargetControl sender, int viewIndex, Camera camera )
		{
			//update camera
			if( Map.Instance != null )
			{
				Vec3 position;
				Vec3 forward;
				Vec3 up;
				Degree fov;

				if( !freeCameraEnabled )
				{
					//usual camera mode

					//add here your special camera management code and set "freeCameraEnabled = false;"

					position = Vec3.Zero;
					forward = new Vec3( 1, 0, 0 );
					up = Vec3.ZAxis;
					fov = Map.Instance.Fov;

					//MapCamera mapCamera = Entities.Instance.GetByName( "MapCamera_0" ) as MapCamera;
					//if( mapCamera != null )
					//{
					//   position = mapCamera.Position;
					//   forward = mapCamera.Rotation * new Vec3( 1, 0, 0 );
					//   fov = mapCamera.Fov;
					//}
				}
				else
				{
					//free camera mode
					position = freeCameraPosition;
					forward = freeCameraDirection.GetVector();
					up = Vec3.ZAxis;
					fov = Map.Instance.Fov;
				}

				//update control
				RenderTargetUserControl control = workAreaControl.Views[ viewIndex ].Control;

				if( viewIndex == 0 )
				{
					//first view
					control.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance;
					control.CameraFixedUp = up;
					control.CameraFov = fov;
					control.CameraPosition = position;
					control.CameraDirection = forward;
				}
				else
				{
					//all views except first view. set orthographic camera projection.
					control.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance;
					control.CameraProjectionType = ProjectionTypes.Orthographic;
					control.CameraOrthoWindowHeight = 30;

					Vec3 lookAt = position;

					switch( viewIndex )
					{
					case 1:
						control.CameraFixedUp = Vec3.ZAxis;
						control.CameraDirection = -Vec3.XAxis;
						control.CameraPosition = lookAt - control.CameraDirection * 100;
						break;
					case 2:
						control.CameraFixedUp = Vec3.ZAxis;
						control.CameraDirection = -Vec3.YAxis;
						control.CameraPosition = lookAt - control.CameraDirection * 100;
						break;
					case 3:
						control.CameraFixedUp = Vec3.YAxis;
						control.CameraDirection = -Vec3.ZAxis;
						control.CameraPosition = lookAt - control.CameraDirection * 100;
						break;
					}
				}
			}

			//update sound listener
			if( viewIndex == 0 && SoundWorld.Instance != null )
				SoundWorld.Instance.SetListener( camera.Position, Vec3.Zero, camera.Direction, camera.Up );

			//draw 2D graphics as 3D by means DebugGeometry
			if( workAreaViewsConfiguration == ViewsConfigurations.FourViews && viewIndex == 3 )
			{
				const float cameraOffset = 10;
				Vec3 center = camera.Position + camera.Direction * cameraOffset;

				//draw box
				Vec3[] positions;
				int[] indices;
				GeometryGenerator.GenerateBox( new Vec3( 10, 4, 1 ), out positions, out indices );
				Mat4 transform = new Mat4( Mat3.Identity, center );
				camera.DebugGeometry.Color = new ColorValue( .5f, 0, 0 );
				camera.DebugGeometry.AddVertexIndexBuffer( positions, indices, transform, false, true );
				camera.DebugGeometry.Color = new ColorValue( 1, 1, 0 );
				camera.DebugGeometry.AddVertexIndexBuffer( positions, indices, transform, true, true );

				//draw axes
				camera.DebugGeometry.Color = new ColorValue( 1, 0, 0 );
				camera.DebugGeometry.AddArrow( center, center + new Vec3( 5, 0, 0 ) );
				camera.DebugGeometry.Color = new ColorValue( 0, 1, 0 );
				camera.DebugGeometry.AddArrow( center, center + new Vec3( 0, 5, 0 ) );
				camera.DebugGeometry.Color = new ColorValue( 0, 0, 1 );
				camera.DebugGeometry.AddArrow( center, center + new Vec3( 0, 0, 5 ) );
			}
		}
示例#21
0
        public void DebugDrawNavMesh( Camera camera )
        {
            if( recastWorld == IntPtr.Zero )
                return;

            if( debugNavigationMeshVertices == null )
            {
                if( !GetDebugNavigationMeshGeometry( out debugNavigationMeshVertices ) )
                    return;

                debugNavigationMeshIndices = new int[ debugNavigationMeshVertices.Length ];
                for( int n = 0; n < debugNavigationMeshIndices.Length; n++ )
                    debugNavigationMeshIndices[ n ] = n;
            }

            //Render NavMesh
            {
                Mat4 transform = new Mat4( Mat3.Identity, new Vec3( 0, 0, .1f ) );

                //draw without depth test
                {
                    camera.DebugGeometry.SetSpecialDepthSettings( false, false );

                    camera.DebugGeometry.Color = new ColorValue( 0, 1, 0, .1f );
                    camera.DebugGeometry.AddVertexIndexBuffer( debugNavigationMeshVertices,
                        debugNavigationMeshIndices, transform, false, true );

                    camera.DebugGeometry.Color = new ColorValue( 1, 1, 0, .1f );
                    camera.DebugGeometry.AddVertexIndexBuffer( debugNavigationMeshVertices,
                        debugNavigationMeshIndices, transform, true, true );

                    camera.DebugGeometry.RestoreDefaultDepthSettings();
                }

                //draw with depth test
                {
                    camera.DebugGeometry.Color = new ColorValue( 0, 1, 0, .3f );
                    camera.DebugGeometry.AddVertexIndexBuffer( debugNavigationMeshVertices,
                        debugNavigationMeshIndices, transform, false, true );
                    camera.DebugGeometry.Color = new ColorValue( 1, 1, 0, .3f );
                    camera.DebugGeometry.AddVertexIndexBuffer( debugNavigationMeshVertices,
                        debugNavigationMeshIndices, transform, true, true );
                }
            }
        }
示例#22
0
        protected override void OnRender( Camera camera )
        {
            base.OnRender( camera );

            if( camera.Purpose == Camera.Purposes.MainCamera )
            {
                //if( drawTileGrid )
                //   DebugRenderTileGrid( camera );

                bool drawMapEditor = false;
                if( MapEditorInterface.Instance != null )
                {
                    //bool allow
                    try
                    {
                        bool v = (bool)MapEditorInterface.Instance.SendCustomMessage( this, "IsAllowToRenderNavigationMesh", null );
                        if( v )
                            drawMapEditor = true;
                    }
                    catch { }
                }

                if( alwaysDrawNavMesh || drawMapEditor )
                    DebugDrawNavMesh( camera );

                //draw global bounds
                bool mapEditorIsSelected = MapEditorInterface.Instance != null &&
                    MapEditorInterface.Instance.IsEntitySelected( this );
                if( mapEditorIsSelected )
                {
                    camera.DebugGeometry.Color = new ColorValue( 0, 0, 1 );
                    Bounds bounds = new Bounds( boundsMin, boundsMax );
                    camera.DebugGeometry.AddBounds( bounds );
                }

                //bool mapEditorIsSelected = false;
                //if( MapEditorInterface.Instance != null && MapEditorInterface.Instance.IsEntitySelected( this ) )
                //   mapEditorIsSelected = true;

                //if( alwaysDrawNavMesh || mapEditorIsSelected )
                //   DebugDrawNavMesh( camera );

                ////draw global bounds
                //if( mapEditorIsSelected )
                //{
                //   camera.DebugGeometry.Color = new ColorValue( 0, 0, 1 );

                //   Bounds bounds = new Bounds( boundsMin, boundsMax );
                //   camera.DebugGeometry.AddBounds( bounds );
                //}
            }
        }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender( Camera camera )
        {
            base.OnRender( camera );

            //no update in cubemap generation mode
            if( Map.Instance.CubemapGenerationMode )
                return;

            bool playerIntellectFPSCamera = false;
            {
                PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                if( playerIntellect != null )
                    playerIntellectFPSCamera = playerIntellect.FPSCamera;
            }
            bool fpsCamera = playerIntellectFPSCamera && RendererWorld.Instance.DefaultCamera == camera;

            if( activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade )
            {
                //FPS mesh material
                activeWeapon.FPSMeshMaterialNameEnabled =
                    fpsCamera && !camera.IsForShadowMapGeneration();

                //update weapon vertical orientation
                if( activeWeaponAttachedObject.MapObject is Gun )
                {
                    //for guns
                    if( fpsCamera )
                    {
                        Vec3 p = camera.Position + camera.Rotation * Type.WeaponFPSAttachPosition;
                        Quat r = camera.Rotation;
                        Vec3 s = new Vec3( 1, 1, 1 );
                        activeWeaponAttachedObject.MapObject.SetTransform( p, r, s );
                        activeWeaponAttachedObject.MapObject.SetOldTransform( p, r, s );

                        //Vec3 diff = playerIntellect.LookDirection.GetVector();
                        //float dirV = -MathFunctions.ATan( diff.Z, diff.ToVec2().Length() );
                        //float halfDirV = dirV * .5f;
                        //Quat rot = new Quat( 0, MathFunctions.Sin( halfDirV ), 0,
                        //   MathFunctions.Cos( halfDirV ) );
                        //activeWeaponAttachedObject.RotationOffset = rot;
                        //activeWeaponAttachedObject.PositionOffset =
                        //   Type.FPSCameraOffset + Type.WeaponFPSAttachPosition * rot;
                    }
                    else
                    {
                        float dirV;

                        if( EntitySystemWorld.Instance.IsClientOnly() )
                        {
                            //client specific
                            dirV = client_weaponVerticalAngle;
                        }
                        else
                        {
                            Vec3 diff = TurnToPosition - Position;
                            dirV = -MathFunctions.ATan( diff.Z, diff.ToVec2().Length() );
                        }

                        float halfDirV = dirV * .5f;
                        Quat rot = new Quat( 0, MathFunctions.Sin( halfDirV ), 0,
                            MathFunctions.Cos( halfDirV ) );

                        activeWeaponAttachedObject.RotationOffset = rot;
                        activeWeaponAttachedObject.PositionOffset = Type.WeaponAttachPosition;
                    }
                }
                else
                {
                    //for melee weapons
                    activeWeaponAttachedObject.RotationOffset = Quat.Identity;
                    activeWeaponAttachedObject.PositionOffset = Vec3.Zero;
                }

                //no cast shadows from active weapon in the FPS mode
                foreach( MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects )
                {
                    MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh;
                    if( weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null )
                    {
                        if( weaponAttachedMesh.RemainingTime == 0 )
                            weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera;
                    }
                }
            }

            //only weapon visible in the FPS mode
            foreach( MapObjectAttachedObject attachedObject in AttachedObjects )
                attachedObject.Visible = !fpsCamera || attachedObject == activeWeaponAttachedObject;

            //no cast shadows in the FPS mode
            if( camera.IsForShadowMapGeneration() && playerIntellectFPSCamera )
            {
                foreach( MapObjectAttachedObject attachedObject in AttachedObjects )
                    attachedObject.Visible = false;
            }
        }
示例#24
0
 protected override void OnRender( Camera camera )
 {
     base.OnRender( camera );
     UpdateThreads();
 }
		public override void OnUpdateCameraSettings( Camera camera )
		{
			base.OnUpdateCameraSettings( camera );

			if( overrideCameraSettings )
			{
				//camera.ProjectionType = ProjectionTypes.Perspective;
				//camera.NearClipDistance = nearClipDistance;
				//camera.FarClipDistance = farClipDistance;				
				//camera.Fov = fov;

				float time = EngineApp.Instance.Time * cameraWavingSpeed;
				Vec2 offset = new Vec2( MathFunctions.Cos( time ), MathFunctions.Sin( time ) ) * cameraWavingAmplitude;
				camera.FixedUp = ( new Vec3( offset.X, offset.Y, 1 ) ).GetNormalize();

				//need update Position, Direction after updating FixedUp
				camera.Position = camera.Position;
				camera.Direction = camera.Direction;
			}
		}
示例#26
0
        void renderTargetUserControl1_Render( RenderTargetUserControl sender, Camera camera )
        {
            //update camera
            if( Map.Instance != null )
            {
                Vec3 position;
                Vec3 forward;
                Vec3 up;
                Degree fov;

                if( !freeCameraEnabled )
                {
                    //usual camera

                    position = Vec3.Zero;
                    forward = new Vec3( 1, 0, 0 );
                    up = Vec3.ZAxis;
                    fov = Map.Instance.Fov;

                    //MapCamera mapCamera = Entities.Instance.GetByName( "MapCamera_0" ) as MapCamera;
                    //if( mapCamera != null )
                    //{
                    //   position = mapCamera.Position;
                    //   forward = mapCamera.Rotation * new Vec3( 1, 0, 0 );
                    //   fov = mapCamera.Fov;
                    //}
                }
                else
                {
                    //free camera

                    position = freeCameraPosition;
                    forward = freeCameraDirection.GetVector();
                    up = Vec3.ZAxis;
                    fov = Map.Instance.Fov;
                }

                renderTargetUserControl1.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance;
                renderTargetUserControl1.CameraFixedUp = up;
                renderTargetUserControl1.CameraFov = fov;
                renderTargetUserControl1.CameraPosition = position;
                renderTargetUserControl1.CameraDirection = forward;
            }

            //update sound listener
            if( SoundWorld.Instance != null )
                SoundWorld.Instance.SetListener( camera.Position, Vec3.Zero, camera.Direction, camera.Up );

            //if( Map.Instance != null && !renderTargetUserControl1.MouseRelativeMode )
            //	RenderEntityOverCursor( camera );
        }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            if (path.Count != 0 && GridPathFindSystem.Instance.DebugDraw)
            {
                GridPathFindSystem.Instance.DebugDrawPath(camera,
                    Position.ToVec2(), path, new ColorValue(0, 0, 1));
            }
        }
示例#28
0
文件: Fan.cs 项目: Eneth/GAO
        protected override void OnRender( Camera camera )
        {
            base.OnRender( camera );

            UpdateAttachedParticleSystem();
        }
示例#29
0
        protected override void OnControlledObjectRender( Camera camera )
        {
            base.OnControlledObjectRender( camera );

            if( camera != RendererWorld.Instance.DefaultCamera )
                return;

            //debug geometry
            if( EngineDebugSettings.DrawGameSpecificDebugGeometry )
            {
                //view radius
                if( ControlledObject.ViewRadius != 0 )
                {
                    camera.DebugGeometry.Color = new ColorValue( 0, 1, 0, .5f );
                    Vec3 lastPos = Vec3.Zero;
                    for( float angle = 0; angle <= MathFunctions.PI * 2 + .001f;
                        angle += MathFunctions.PI / 16 )
                    {
                        Vec3 pos = ControlledObject.Position +
                            new Vec3( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ), 0 ) *
                            ControlledObject.ViewRadius;

                        if( angle != 0 )
                            camera.DebugGeometry.AddLine( lastPos, pos );

                        lastPos = pos;
                    }
                }

                //weapons
                foreach( Weapon weapon in unitWeapons )
                {
                    float radius = 0;

                    if( weapon.Type.WeaponNormalMode.IsInitialized )
                        radius = Math.Max( radius, weapon.Type.WeaponNormalMode.UseDistanceRange.Maximum );
                    if( weapon.Type.WeaponAlternativeMode.IsInitialized )
                        radius = Math.Max( radius, weapon.Type.WeaponAlternativeMode.UseDistanceRange.Maximum );

                    camera.DebugGeometry.Color = new ColorValue( 1, 0, 0, .5f );
                    Vec3 lastPos = Vec3.Zero;
                    for( float angle = 0; angle <= MathFunctions.PI * 2 + .001f;
                        angle += MathFunctions.PI / 16 )
                    {
                        Vec3 pos = weapon.Position +
                            new Vec3( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ), 0 ) * radius;

                        if( angle != 0 )
                            camera.DebugGeometry.AddLine( lastPos, pos );

                        lastPos = pos;
                    }
                }

                //target task
                if( targetTask != null )
                {
                    Vec3 targetPos = targetTask.Position;
                    camera.DebugGeometry.AddArrow( ControlledObject.Position, targetPos, 1 );
                    camera.DebugGeometry.AddSphere( new Sphere( targetPos, 3 ), 10 );
                }
            }
        }
示例#30
0
        void RenderEntityOverCursor( Camera camera )
        {
            Vec2 mouse = renderTargetUserControl1.GetFloatMousePosition();

            Ray ray = camera.GetCameraToViewportRay( mouse );

            MapObject mapObject = null;

            Map.Instance.GetObjects( ray, delegate( MapObject obj, float scale )
            {
                if( obj is StaticMesh )
                    return true;
                mapObject = obj;
                return false;
            } );

            if( mapObject != null )
            {
                camera.DebugGeometry.Color = new ColorValue( 1, 1, 0 );
                camera.DebugGeometry.AddBounds( mapObject.MapBounds );
            }
        }