dev in the making

game development, maya and code by brainzizi

Posts Tagged ‘zCamera

zCamera on codeplex

with 4 comments

It’s all here: http://zcamera.codeplex.com.

Please post your feedback either here, on codeplex, or on my email.
Looking for XBOX developers for testing and rewriting the code for XBOX.

Written by brainzizizi

08.17.2009 at 07:31

Posted in xna

Tagged with , , , ,

zCamera: Extensibility

leave a comment »

I like to think zCamera is very extensible. Is it really? Maybe, you’ll have to try.
The whole project consists of a really small number of .cs files:

zCameraManager.cs

The main file, inherits from DrawableGameComponent, so I can get to Game.Content and Game.GraphicsDevice for debugging purposes. Most important thing in this file is a list of all cameras of type zBaseCamera.

zVectorRenderer.cs

Vector renderer I got from www.ziggyware.com, and reworked so it’s no longer a GameComponent, but the zCameraManager takes care of it. And added support for drawing bounding frustrums.

zCameraKey.cs

The data structure used for saving keyframes. Also inludes the zInterpolationType enum for choosing position and focal distance interpolation.

Cameras\\zBaseCamera.cs

Abstract class, stores the shared fields and methods of all cameras, like position, view, projection, aspect ratio, forward vector, name, set target method, etc. If you want to build your own camera and manage it through the manager, inherit from this class. Also it contains basic debug drawing code which might also be very handy and Save/Load functions where you can save a camera using the Intermediate Serializer, and load it later as an xml converted to xnb through the pipeline, and a load function which loads raw xml files structured like the file the Save method outputs.

Cameras\\zBaseKeyframedCamera.cs

Also an abstract class, inherits from zBaseCamera and has build in keyframe support using 2 lists: List<TimeSpan> Keys and List<zCameraKey> Values. I tried using a Dictionary for this, but it just didn’t work out, due to the inability of getting a value by index, and I think this is more C++ like. Not that that’s a good thing, but I don’t think it’s gonna be a problem.

This class has support for keyframes. That means interpolation and keyframe following. I have one known bug/feature here, and that’s a bit of a hiccup when translating between the last and the first keyframe when repeat is on. The last keyframe is in fact getting linear interpolation in and out of it, because I don’t pass in the keyframes from the beginning into the catmull rom function. Maybe a little annoyance, but no showstopper.

If you want to build a cinematic camera this is the class to inherit from. Also has support for waypoint debugging and save/load

Various Helper files

Containing some helpful extension methods and interpolation functions.

And that’s about it! I’d love to post some screens but as this project is not really eye candy I’ll refrain myself.

Written by brainzizizi

08.11.2009 at 17:11

Posted in xna

Tagged with , , ,

zCamera Save/Load

leave a comment »

Hi!

On my zCamera project, I’ve added basic support for saving and loading.
The zBaseCamera, the base class of every camera provides this interface:

public virtual SaveSettings(string path);
public virtual LoadSettings(string path);

Save is done using the IntermediateSerializer, and load is done using XmlReader to support raw .xml loading.
See, the IntermediateSerializer output needs to be compiled at runtime in order for you to load it during your game. So no save/load sessions using just the serializer.

        /// <summary>
        /// Saves the camera settings.
        /// </summary>
        /// <param name="path">The path of the file to write, without the extension.</param>
        public virtual void SaveSettings(string path)
        {
            XmlWriterSettings settings = new XmlWriterSettings { Indent = true };

            string fullPath = manager.Game.Content.RootDirectory + "\\" + path + ".xml";
            if (File.Exists(fullPath))
                File.Delete(fullPath);

            XmlWriter writer = XmlWriter.Create(fullPath, settings);
            IntermediateSerializer.Serialize(writer, this, null);
            writer.Close();
        }
        /// <summary>
        /// Loads the camera settings.
        /// </summary>
        /// <param name="path">The path of the file to read, without the extension.</param>
        public virtual void LoadSettings(string path)
        {
            XmlReader reader = XmlReader.Create(manager.Game.Content.RootDirectory + "\\" + path + ".xml");
            while (reader.Read())
            {
                if (reader.Name == "Name")
                    Name = reader.ReadElementContentAsString();

                if (reader.Name == "Debug")
                    Debug = reader.ReadElementContentAsBoolean();

                if (reader.Name == "FocalDistance")
                    FocalDistance = reader.ReadElementContentAsFloat();

                if (reader.Name == "FieldOfView")
                    FieldOfView = reader.ReadElementContentAsFloat();

                if (reader.Name == "AspectRatio")
                    AspectRatio = reader.ReadElementContentAsFloat();

                if (reader.Name == "NearPlaneDistance")
                    NearPlaneDistance = reader.ReadElementContentAsFloat();

                if (reader.Name == "FarPlaneDistance")
                    FarPlaneDistance = reader.ReadElementContentAsFloat();

                if (reader.Name == "Position")
                {
                    string vector = reader.ReadElementContentAsString();
                    Position = zCameraHelper.ParseFromIntermediateSerializer(vector);
                }
            }

I’ll release the complete source next week.

Written by brainzizizi

08.11.2009 at 07:09