public void Update(Microsoft.Xna.Framework.GameTime gameTime, SceneGraphManager sceneGraph)
        {
            //check collision
            foreach (Actor actor in sceneGraph.RootNode.Children)
            {
                if (actor.Properties.ContainsKey(ActorPropertyType.COLLIDEABLE) && actor.Visible)
                {

                    BoundingSphere transformedSphere = actor.BoundingSphere.Transform(actor.AbsoluteTransform);
                    BoundingSphere transformedLaserSphere = WorldManager.Instance.GetActor("testlaser").BoundingSphere.Transform(WorldManager.Instance.GetActor("testlaser").AbsoluteTransform);

                    if (WorldManager.Instance.GetActor("testlaser").Visible)
                    {
                        if (transformedSphere.Intersects(transformedLaserSphere))
                        {
                            WorldManager.Instance.GetActor("testlaser").Visible = false;
                            GameConsole.Instance.WriteLine("Collision!");

                            actor.Visible = false;
                            actor.Updateable = false;
                        }
                    }
                }
            }
        }
        public PrelightingRenderer(GraphicsDevice GraphicsDevice, SceneGraphManager sceneGraph)
        {
            //get sceneGraph
            this.sceneGraph = sceneGraph;

            viewWidth = GraphicsDevice.Viewport.Width;
            viewHeight = GraphicsDevice.Viewport.Height;

            // Create the three render targets
            depthTarg = new RenderTarget2D(GraphicsDevice, viewWidth,
                viewHeight, false, SurfaceFormat.Single, DepthFormat.Depth24);

            normalTarg = new RenderTarget2D(GraphicsDevice, viewWidth,
                viewHeight, false, SurfaceFormat.Color, DepthFormat.Depth24);

            lightTarg = new RenderTarget2D(GraphicsDevice, viewWidth,
                viewHeight, false, SurfaceFormat.Color, DepthFormat.Depth24);

            this.graphicsDevice = GraphicsDevice;

            Lights = new List<PointLight>();
        }
        /// <summary>
        /// Invoked after either control has created its graphics device.
        /// </summary>
        private void loadContent(object sender, GraphicsDeviceEventArgs e)
        {
            // Because this same event is hooked for both controls, we check if the Stopwatch
            // is running to avoid loading our content twice.
            if (!totalTime.IsRunning)
            {

                ServiceContainer = new ServiceContainer();
                contentBuilder = new ContentBuilder();
                ResourceBuilder.Instance.ContentBuilder = contentBuilder;

                resourceContent.Activate();

                errors = new List<Error>();
                outputTextBlock = output;
                EditorStatus = EditorStatus.STARTING;
                EditMode = AridiaEditor.EditMode.STANDARD;
                errorDataGrid.ItemsSource = errors;
                Output.AddToOutput("WELCOME TO ARIDIA WORLD EDITOR ------------");

                GameApplication.Instance.SetGraphicsDevice(e.GraphicsDevice);
                MouseDevice.Instance.ResetMouseAfterUpdate = false;
                ServiceContainer.AddService<IGraphicsDeviceService>(GraphicsDeviceService.AddRef(new IntPtr(), 100, 100));
                ResourceManager.Instance.Content = new ContentManager(ServiceContainer, contentBuilder.OutputDirectory);
                ResourceManager.Instance.Content.Unload();

                sceneGraph = new SceneGraphManager();
                sceneGraph.CullingActive = true;
                sceneGraph.LightingActive = false; //deactivate lighting on beginning!

                spriteBatch = new SpriteBatch(e.GraphicsDevice);
                grid = new GridComponent(e.GraphicsDevice, 2);

                e.GraphicsDevice.RasterizerState = RasterizerState.CullNone;

                var versionAttribute = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

                AssemblyBuild.Content = "Build: (Alpha) " + versionAttribute;
                if (File.Exists(Settings.Default.LayoutFile))
                    dockManager.RestoreLayout(Settings.Default.LayoutFile);

                // after we initialized everything we need start loading the content
                // in a new thread!
                StartContentBuilding();

                // Start the watch now that we're going to be starting our draw loop
                totalTime.Start();
            }
        }
Example #4
0
        public override void Update(SceneGraphManager sceneGraph)
        {
            //get mouse 3d-ray
            ray = CameraManager.Instance.GetCurrentCamera().GetMouseRay(MouseDevice.Instance.Position);

            //update time
            time += sceneGraph.GameTime.ElapsedGameTime.TotalMilliseconds;

            //calculate fireTarget (farPlane = max distance)
            fireTarget = ray.Position - ray.Direction * GameApplication.Instance.FarPlane ;

            //get current point on path
            Vector3 pathPosition = path.GetPointOnCurve((float)time);

            //get next point on curve to calculate the current direction
            Vector3 nextPathPosition = path.GetPointOnCurve((float)time+1);

            //calculate direction
            Vector3 currentDirection = nextPathPosition - pathPosition;

            //normalize direction
            currentDirection.Normalize();

            //calculate rotation "caused" by following the path
            yaw = (float)(Math.Atan2(currentDirection.X, currentDirection.Z));
            roll = (float)(Math.Atan2(-currentDirection.Y, currentDirection.Z));    // !!!! TODO

            //set rotation matrix
            Rotation = Quaternion.CreateFromYawPitchRoll(((float)yaw), (float)Math.PI-roll, pitch);

            //calculate right vector note: up vector stays the same every time
            this.right = Vector3.Cross(currentDirection, Vector3.Up);

            //reset offsetVelocity
            offsetVelocity = Vector3.Zero;

            //movement through keyboard input
            if (KeyboardDevice.Instance.IsKeyDown(Keys.A))
            {
                offsetVelocity.X = -offsetAcceleration;
            }
            else if (KeyboardDevice.Instance.IsKeyDown(Keys.D))
            {
                offsetVelocity.X = offsetAcceleration;
            }
            if (KeyboardDevice.Instance.IsKeyDown(Keys.S))
            {
                offsetVelocity.Y = -offsetAcceleration;
            }
            else if (KeyboardDevice.Instance.IsKeyDown(Keys.W))
            {
                offsetVelocity.Y = offsetAcceleration;
            }

            //update offsetPosition (for now just for movement along the x- and y- axis)
            offsetPosition += right * offsetVelocity.X + Vector3.Up * offsetVelocity.Y;

            //movement by mouse

             //   this.tempVelocity.X += 1000* MouseDevice.Instance.Delta.X / ((SpaceCommander)GameApplication.Instance.GetGame()).graphics.PreferredBackBufferWidth;
             //   this.tempVelocity.Y += -1000 * MouseDevice.Instance.Delta.Y / ((SpaceCommander)GameApplication.Instance.GetGame()).graphics.PreferredBackBufferHeight;
            //    this.tempVelocity.Z = velocity.Z;

            //velocity = Vector3.Lerp(velocity, tempVelocity,0.03f);
            //tempVelocity -= velocity;

            //move ship
               // this.Position += velocity;
            this.Position = path.GetPointOnCurve((float)time) + offsetPosition;

            base.Update(sceneGraph);
        }
Example #5
0
        public override void Render(SceneGraphManager sceneGraph)
        {
            if (model != null)
            {
                Camera camera = CameraManager.Instance.GetCurrentCamera();

                GameApplication.Instance.GetGraphics().BlendState = BlendState.AlphaBlend;

                Matrix[] transforms = new Matrix[model.Bones.Count];
                model.CopyAbsoluteBoneTransformsTo(transforms);

                // Draw the model. A model can have multiple meshes, so loop.
                foreach (ModelMesh mesh in model.Meshes)
                {
                    // This is where the mesh orientation is set, as well
                    // as our camera and projection.
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.EnableDefaultLighting();

                        effect.PreferPerPixelLighting = true;
                        effect.World =  transforms[mesh.ParentBone.Index] *
                                                       AbsoluteTransform;
                        effect.View = camera.View;
                        effect.Projection = camera.Projection;
                    }
                    // Draw the mesh, using the effects set above.
                    mesh.Draw();

                }
                GameApplication.Instance.GetGraphics().BlendState = BlendState.Opaque;
            }
            base.Render(sceneGraph);
        }
Example #6
0
        /// <summary>
        /// Finally render the model to the screen with some basic effect
        /// </summary>
        /// <param name="sceneGraph">The scene graph responsible for this actor - <see cref="SceneGraphManager"/></param>
        public override void Render(SceneGraphManager sceneGraph)
        {
            if (CameraManager.Instance.GetCurrentCamera() != null)
            {
                if (model != null)
                {
                    GameApplication.Instance.GetGraphics().BlendState = BlendState.AlphaBlend;

                    Camera camera = CameraManager.Instance.GetCurrentCamera();
                    // Copy the model hierarchy transforms
                    Matrix[] transforms = new Matrix[model.Bones.Count];
                    model.CopyAbsoluteBoneTransformsTo(transforms);

                    // Render each mesh in the model
                    foreach (ModelMesh mesh in model.Meshes)
                    {
                        foreach (Effect effect in mesh.Effects)
                        {
                            BasicEffect basicEffect = effect as BasicEffect;

                            if (basicEffect == null)
                            {
                                throw new NotSupportedException("there is no basic effect");
                            }

                            //Set the matrices
                            basicEffect.World = Matrix.CreateScale(Scale) * transforms[mesh.ParentBone.Index] *// fireRotation *
                                                    AbsoluteTransform;
                            basicEffect.View = camera.View;
                            basicEffect.Projection = camera.Projection;
                            basicEffect.Alpha = 0.5f;
                            basicEffect.DiffuseColor = Color.Blue.ToVector3();
                            basicEffect.EmissiveColor = Color.Blue.ToVector3();

                            basicEffect.EnableDefaultLighting();
                        }

                        mesh.Draw();
                    }

                    GameApplication.Instance.GetGraphics().BlendState = BlendState.Opaque;
                }
            }
        }
Example #7
0
        public override void Update(SceneGraphManager sceneGraph)
        {
            if (!fired)
            {
            }
            else
            {
                this.Position -= firePower * fireDirection;

                //laser too far away ?
                if (Vector3.Distance(firePosition, Position) >= GameApplication.Instance.FarPlane)
                {
                    fired = false;
                    this.Visible = false;
                }
            }

            base.Update(sceneGraph);
        }
Example #8
0
        /// <summary>
        /// The render method. Renders the 
        /// vertices with the help of a vertex and index buffer
        /// onto the screen.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Render(SceneGraphManager sceneGraph)
        {
            Camera camera = CameraManager.Instance.GetCurrentCamera();

               // Matrix world =  Utils.CreateWorldMatrix(Position, Matrix.CreateFromQuaternion(Rotation), Scale);

            Effect.World = AbsoluteTransform;
            Effect.View = camera.View;
            Effect.Projection = camera.Projection;

            Effect.Time = (float)sceneGraph.GameTime.TotalGameTime.TotalSeconds * 3;

            Effect.LightDirection = LightPosition - Position;

            Effect.AmbientColor = AmbientColor.ToVector4();
            Effect.AmbientIntensity= AmbientIntensity;
            Effect.ColorMap = ColorMap;
            Effect.BumpMap = BumpMap;
            Effect.GlowMap = GlowMap;
            Effect.ReflectionMap = ReflectionMap;
            Effect.CloudMap = CloudMap;
            Effect.WaveMap = WaterMap;
            Effect.AtmosMap = AtmosphereMap;
            Effect.CloudSpeed = CloudSpeed;
            Effect.CloudHeight = CloudHeight;
            Effect.CloudShadowIntensity = CloudShadowIntensity;

            Effect.CameraPosition = camera.Position;

            for (int pass = 0; pass < Effect.CurrentTechnique.Passes.Count; pass++)
            {
                for (int msh = 0; msh < Model.Meshes.Count; msh++)
                {
                    ModelMesh mesh = Model.Meshes[msh];
                    for (int prt = 0; prt < mesh.MeshParts.Count; prt++)
                        mesh.MeshParts[prt].Effect = Effect;
                    mesh.Draw();
                }
            }

            GameApplication.Instance.GetGraphics().BlendState = new Microsoft.Xna.Framework.Graphics.BlendState()
            {
                AlphaSourceBlend = Blend.SourceAlpha
            };

            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.CullCounterClockwiseFace;
            GameApplication.Instance.GetGraphics().RasterizerState = rs;

            base.Render(sceneGraph);
        }
Example #9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            sceneGraph = new SceneGraphManager();
            sceneGraph.CullingActive = false;
            sceneGraph.LightingActive = true;

            #region RESOURCES
            List<Resource> resources = new List<Resource>()
            {
                new Resource() {
                    Name = "crate",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "DefaultEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "TextureMappingEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "NormalMappingEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "FogEffect",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "PPModel",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "PPLight",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "PPDepthNormal",
                    Path = GameApplication.Instance.EffectPath,
                    Type = ResourceType.Effect
                },
                new Resource() {
                    Name = "chunkheightmap",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "PPLightMesh",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "brick_normal_map",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "Spaceship_nor_hälfte_fertig_NRM",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "wedge_p1_diff_v1",
                    Path = GameApplication.Instance.TexturePath + "SpaceShip\\",
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "wedge_p1_diff_v1_normal",
                    Path = GameApplication.Instance.TexturePath + "SpaceShip\\",
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "Kachel2_bump",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "Checker",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "masonry-wall-normal-map",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "level1_skymap",
                    Path = GameApplication.Instance.TexturePath,
                    Type = ResourceType.Texture2D
                },
                new Resource() {
                    Name = "p1_wedge",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "Raumschiff_tex",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "Ground",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "brick_wall",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "sphere",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "raumschiff7",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "wall",
                    Path = GameApplication.Instance.ModelPath,
                    Type = ResourceType.Model
                },
                new Resource() {
                    Name = "Arial",
                    Path = GameApplication.Instance.FontPath,
                    Type = ResourceType.SpriteFont
                }
            };

            ResourceManager.Instance.LoadResources(resources);

            sceneGraph.Lighting.Lights.Add(new PointLight("pointLight01", null, new Vector3(2, 1, 0), Color.Red * .85f, 5000));
            sceneGraph.Lighting.Lights.Add(new PointLight("pointLight02", null, new Vector3(-2, 2, 0), Color.Green * .85f, 5000));
            sceneGraph.Lighting.Lights.Add(new PointLight("pointLight02", null, new Vector3(10, 1, 0), Color.White * .85f, 5000));
            sceneGraph.Lighting.LoadContent();
            #endregion

            #region CAMERA
            FPSCamera cam = new FPSCamera("fps", new Vector3(0, 5, -5), new Vector3(0, 3, 0));
            cam.LoadContent();
            CameraManager.Instance.CurrentCamera = "fps";
            #endregion

            #region ACTORS
            FogMaterial mat = new FogMaterial();
            mat.FogStart = 2000;
            mat.LightDirection = new Vector3(1f, 1f, 1);
            mat.LightColor = Vector3.One;

            NormalMapMaterial normal = new NormalMapMaterial();
            normal.NormalMap = ResourceManager.Instance.GetResource<Texture2D>("Spaceship_nor_hälfte_fertig_NRM");
            normal.LightDirection = new Vector3(1f, 1f, .5f);
            normal.LightColor = Vector3.One;
            normal.SpecularPower = 32;

            LightingMaterial lighting = new LightingMaterial();
            lighting.LightDirection = new Vector3(.5f, .5f, .5f);
            //lighting.LightColor = Color.Aqua.ToVector3();

            lighting.SpecularPower = 1;

            MeshObject mesh = new MeshObject("ship", "p1_wedge", 0.01f);
            mesh.Position = new Vector3(0, 3, 0);
            mesh.Scale = new Vector3(0.01f);
            mesh.LoadContent();
            mesh.SetModelEffect(ResourceManager.Instance.GetResource<Effect>("PPModel"), true);
            mesh.Material = lighting;
            sceneGraph.RootNode.Children.Add(mesh);

            MeshObject plane = new MeshObject("plane", "Ground", 0.01f);
            plane.Position = new Vector3(0, 0, 0);
            plane.Scale = new Vector3(0.01f);
            plane.LoadContent();
            plane.Material = lighting;
            plane.SetModelEffect(ResourceManager.Instance.GetResource<Effect>("PPModel"), true);
            sceneGraph.RootNode.Children.Add(plane);

            TextElement element = new TextElement("text", new Vector2(1, 1), Color.Black, "Test", ResourceManager.Instance.GetResource<SpriteFont>("Arial"));
            element.LoadContent();
            UIManager.Instance.AddActor(element);
            #endregion

            MouseDevice.Instance.ResetMouseAfterUpdate = false;
        }