Configuring Krypton lights to "stick" to scenery...

Jun 28, 2012 at 10:29 PM
Edited Jun 28, 2012 at 10:30 PM

Hello, I'm very new to XNA still but have been learnign as I go. I'm a sophomore CS student in college and I learn fast. I originally found implementing the Krypton Engine very easy, until I tried creating a stationary light that doesn't move with the player. I know I have to feed Krypton a translation matrix but I'm very confused on how to do that. The current camera that i'm using works great but doesn't seem to use the same variables that I see others using to feed into Krypton. I have tried to implement the solutions from other discussions on this issue with no success.

this is my Camera class

 

    public class Camera
    {
        protected float cameraZoomValue; // Camera Zoom
        public Matrix cameraTransformValue; // Matrix Transform
        public Vector2 cameraPosition; // Camera Position
        protected float cameraRotationValue; // Camera Rotation
 
        public Camera()
        {
            cameraZoomValue = 1.0f;
            cameraRotationValue = 0.0f;
            cameraPosition = Vector2.Zero;
        }

        public float Zoom
        {
            get { return cameraZoomValue; }
            set { cameraZoomValue = value; if (cameraZoomValue < 0.1f) cameraZoomValue = 0.1f; } // Negative zoom will flip image
        }

        public float Rotation
        {
            get { return cameraRotationValue; }
            set { cameraRotationValue = value; }
        }

        // Auxiliary function to move the camera
        public void Move(Vector2 amount)
        {
            cameraPosition += amount;
        }
        // Get set position
        public Vector2 Position
        {
            get { return cameraPosition; }
            set { cameraPosition = value; }
        }

        public Matrix get_transformation(GraphicsDevice graphicsDevice)
        {
            cameraTransformValue =
              Matrix.CreateTranslation(new Vector3(-cameraPosition.X, -cameraPosition.Y, 0)) *
                                         Matrix.CreateRotationZ(Rotation) *
                                         Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
                                         Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
            return cameraTransformValue;
        }
    }
}

 

Following the testbed example I'm using this currently:

 

            Matrix world = Matrix.Identity;
            Matrix view = Matrix.CreateTranslation(new Vector3(0, 0, 0) * -1f);
            Matrix projection = Matrix.CreateOrthographic(this.mVerticalUnits * this.GraphicsDevice.Viewport.AspectRatio, this.mVerticalUnits, 0, 1);

Which doesn't work when Id like to have a Hull/Light NOT relative to the current screen but the world rather. Creating a hull causes it to appear at a certain point but move with the character as the camera moves. 

 

This is my first post on a code forum, so if i didn't provide enough code/information please tell me and ill post more! 

Thank you so much, i hope that people can help me fix this issue. I'm very excited to continue working on my game, and am comfortable with all the other features I plan to implement, the Lighting is my big obstacle. 

Jul 8, 2012 at 6:06 PM
Edited Jul 8, 2012 at 6:09 PM

Hi i see you used the camera from http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/

I use the same and solved it by using:

 this.krypton.Matrix = camera.get_transformation(GraphicsDevice);
            this.krypton.SpriteBatchCompatablityEnabled = true;
            this.krypton.CullMode = CullMode.None;

            this.krypton.LightMapPrepare();


            GraphicsDevice.Clear(Color.White);

 

then proceed with drawing my game and after i called spriteBatch.End() i call this.krypton.draw()

you need to remove the testbed stuff cause there is no camera in there;