/// <summary>
        /// Constructor from parser.
        /// Please DO NOT change the parsing routine unless you know what you are doing).
        /// </summary>
        /// <param name="parser"></param>
        public RTLightType_Directional(CommandFileParser parser)
        {
            mLightSourceType = RTLightSourceType.RTLightSourceTypeDirection;

            while (!parser.IsEndElement("light"))
            {
                if (parser.IsElement() && (!parser.IsElement("light")))
                {
                    if (parser.IsElement("color"))
                    {
                        mColor = parser.ReadVector3();
                    }
                    else if (parser.IsElement("position"))
                    {
                        mPosition = parser.ReadVector3();
                    }
                    else if (parser.IsElement("direction"))
                    {
                        mDirection = parser.ReadVector3();
                    }
                    else
                    {
                        parser.ParserError("Light");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }

            mDirection = -Vector3.Normalize(mDirection);
        }
        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Noise(CommandFileParser parser)
        {
            if (null == mPermutation)
                InitPermutation();

            mColor1 = Vector3.One;
            mColor2 = Vector3.Zero;
            mFrequency = 1;
            mAmplitude = 1f;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("color1"))
                        mColor1 = parser.ReadVector3();
                    else if (parser.IsElement("color2"))
                        mColor2 = parser.ReadVector3();
                    else if (parser.IsElement("frequency"))
                        mFrequency = parser.ReadInt();
                    else if (parser.IsElement("amplitude"))
                        mAmplitude = parser.ReadFloat();
                    else
                        parser.ParserError("TextureType_Noise");
                }
                else
                    parser.ParserRead();
            }
        }
        private float mThetaRange; // range from 0 to this value (mPeroid * 2PI)

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Sine(CommandFileParser parser)
        {
            mPeriod = 1f;
            mDirection = Vector2.UnitX;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("period"))
                        mPeriod = parser.ReadFloat();
                    else if (parser.IsElement("direction"))
                        mDirection = parser.ReadVector2();
                    else if (parser.IsElement("color1"))
                        mColor1 = parser.ReadVector3();
                    else if (parser.IsElement("color2"))
                        mColor2 = parser.ReadVector3();
                    else
                        parser.ParserError("TextureType_Sine");
                }
                else
                    parser.ParserRead();
            }
            mThetaRange = mPeriod * (float) Math.PI * 2f;
            mDirection = Vector2.Normalize(mDirection);
        }
        private bool mUseDepthMap = false; // off

        /// <summary>
        /// Constructor from parser.
        /// Please DO NOT change the parsing routine unless you know what you are doing).
        /// </summary>
        /// <param name="parser"></param>
        public RTLightType_Spot(CommandFileParser parser)
        {
            mLightSourceType = RTLightSourceType.RTLightSourceTypeSpot;

            while (!parser.IsEndElement("light"))
            {
                if (parser.IsElement() && (!parser.IsElement("light")))
                {
                    if (parser.IsElement("color"))
                    {
                        mColor = parser.ReadVector3();
                    }
                    else if (parser.IsElement("position"))
                    {
                        mPosition = parser.ReadVector3();
                    }
                    else if (parser.IsElement("direction"))
                    {
                        mDirection = parser.ReadVector3();
                    }
                    else if (parser.IsElement("innerAngle"))
                    {
                        mInnerAngle = MathHelper.ToRadians(parser.ReadFloat());
                    }
                    else if (parser.IsElement("outerAngle"))
                    {
                        mOuterAngle = MathHelper.ToRadians(parser.ReadFloat());
                    }
                    else if (parser.IsElement("falloff"))
                    {
                        mFallOff = parser.ReadFloat();
                    }
                    else if (parser.IsElement("depthMap"))
                    {
                        mUseDepthMap = parser.ReadBool();
                    }
                    else if (parser.IsElement("depthMapResolution"))
                    {
                        mRes = parser.ReadInt();
                    }
                    else if (parser.IsElement("depthMapFilterRes"))
                    {
                        mFilterRes = parser.ReadInt();
                    }
                    else
                    {
                        parser.ParserError("Light");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }

            mDirection          = -Vector3.Normalize(mDirection);
            mCosInAngle         = (float)Math.Cos(mInnerAngle / 2);
            mCosOutAngle        = (float)Math.Cos(mOuterAngle / 2);
            mFallOffDenominator = 1f / (mCosInAngle - mCosOutAngle);
        }
Beispiel #5
0
        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Ramp(CommandFileParser parser)
        {
            mRepeat = 1f;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("repeat"))
                    {
                        mRepeat = parser.ReadFloat();
                    }
                    else if (parser.IsElement("color1"))
                    {
                        mColor1 = parser.ReadVector3();
                    }
                    else if (parser.IsElement("color2"))
                    {
                        mColor2 = parser.ReadVector3();
                    }
                    else
                    {
                        parser.ParserError("TextureType_Ramp");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            if (mRepeat <= 0)
            {
                mRepeat = 1f;
            }
        }
        /// <summary>
        /// Constructor from parser.
        /// Please DO NOT change the parsing routine unless you know what you are doing).
        /// </summary>
        /// <param name="parser"></param>
        public RTLightType_Point(CommandFileParser parser)
        {
            mLightSourceType = RTLightSourceType.RTLightSourceTypePoint;

            while (!parser.IsEndElement("light"))
            {
                if (parser.IsElement() && (!parser.IsElement("light")))
                {
                    if (parser.IsElement("color"))
                    {
                        mColor = parser.ReadVector3();
                    }
                    else if (parser.IsElement("position"))
                    {
                        mPosition = parser.ReadVector3();
                    }
                    else
                    {
                        parser.ParserError("Light");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Constrcuts from the commandfile.
 /// DO NOT change the pasing loop unless you know what you are doing.
 /// </summary>
 /// <param name="parser"></param>
 public RTTextureType_Checker(CommandFileParser parser)
 {
     while (!parser.IsEndElement("texture"))
     {
         if (parser.IsElement() && (!parser.IsElement("texture")))
         {
             if (parser.IsElement("urepeat"))
             {
                 mURepeat = parser.ReadInt();
             }
             else if (parser.IsElement("vrepeat"))
             {
                 mVRepeat = parser.ReadInt();
             }
             else if (parser.IsElement("color1"))
             {
                 mColor1 = parser.ReadVector3();
             }
             else if (parser.IsElement("color2"))
             {
                 mColor2 = parser.ReadVector3();
             }
             else
             {
                 parser.ParserError("TextureType_Checker");
             }
         }
         else
         {
             parser.ParserRead();
         }
     }
 }
        protected Vector3 mPixelOrigin; // lower left corner

        /// <summary>
        /// Construcs from parsing the command file.
        /// DO NOT CHANGE the parsing loop unless you know what you are doing.
        /// You can add in initialization computation after the loop
        /// </summary>
        /// <param name="parser"></param>
        public RTCamera(CommandFileParser parser)
        {
            mEye   = new Vector3(0f, 0f, 0f);
            mAt    = new Vector3(0f, 0f, 1f);
            mUp    = new Vector3(0f, 1f, 0f);
            mFOV   = 25f;
            mFocus = 1f;

            parser.ParserRead();
            while (!parser.IsEndElement("camera"))
            {
                if (parser.IsElement() && (!parser.IsElement("camera")))
                {
                    if (parser.IsElement("eye"))
                    {
                        mEye = parser.ReadVector3();
                    }
                    else if (parser.IsElement("lookat"))
                    {
                        mAt = parser.ReadVector3();
                    }
                    else if (parser.IsElement("upvector"))
                    {
                        mUp = parser.ReadVector3();
                    }
                    else if (parser.IsElement("fov"))
                    {
                        mFOV = parser.ReadFloat();
                    }
                    else if (parser.IsElement("focus"))
                    {
                        mFocus = parser.ReadFloat();
                    }
                    else
                    {
                        parser.ParserError("Camera");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }

            // You can add in your initialization computation after this line

            mViewDir = mAt - mEye;

            // now make sure ViewDir and Up are perpendicular
            mSideVec = Vector3.Cross(mUp, mViewDir);
            mUp      = Vector3.Cross(mViewDir, mSideVec);
            mSideVec.Normalize();
            mViewDir.Normalize();
            mUp.Normalize();
        }
Beispiel #9
0
        private float mThetaRange;  // range from 0 to this value (mPeroid * 2PI)

        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Marble(CommandFileParser parser)
        {
            // From super class:
            //      Color1/2
            //      Frequency and
            //      Amplitude

            mPeriod    = 1f;
            mDirection = Vector3.UnitY;
            mAmplitude = 1f;


            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("period"))
                    {
                        mPeriod = parser.ReadFloat();
                    }
                    else if (parser.IsElement("frequency"))
                    {
                        mFrequency = parser.ReadInt();
                    }
                    else if (parser.IsElement("amplitude"))
                    {
                        mAmplitude = parser.ReadFloat();
                    }
                    else if (parser.IsElement("direction"))
                    {
                        mDirection = parser.ReadVector3();
                    }
                    else if (parser.IsElement("color1"))
                    {
                        mColor1 = parser.ReadVector3();
                    }
                    else if (parser.IsElement("color2"))
                    {
                        mColor2 = parser.ReadVector3();
                    }
                    else
                    {
                        parser.ParserError("TextureType_Marble");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            mThetaRange = mPeriod * (float)Math.PI * 2f;
            mDirection  = Vector3.Normalize(mDirection);
        }
Beispiel #10
0
 public void Parse(CommandFileParser parser)
 {
     parser.ParserRead();
     while (!parser.IsEndElement("rtspec"))
     {
         if (parser.IsElement() && (!parser.IsElement("rtspec")))
         {
             if (parser.IsElement("generation"))
             {
                 mGeneration = parser.ReadInt();
             }
             else if (parser.IsElement("shadow"))
             {
                 mComputeShadow = parser.ReadBool();
             }
             else if (parser.IsElement("reflection"))
             {
                 mComputeReflection = parser.ReadBool();
             }
             else if (parser.IsElement("background"))
             {
                 mBgColor = parser.ReadVector3();
             }
             else
             {
                 parser.ParserError("RTWorld");
             }
         }
         else
         {
             parser.ParserRead();
         }
     }
 }
        /// <summary>
        /// Parse command line for <xform> </xform> that is embedeed inside
        /// Geometry.
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        static protected Matrix ParseTransform(CommandFileParser parser)
        {
            Matrix  xform       = Matrix.Identity;
            Vector3 translation = Vector3.Zero;
            Matrix  rotation    = Matrix.Identity;
            Vector3 scale       = Vector3.One;

            parser.ParserRead();
            while (!parser.IsEndElement("xform"))
            {
                if (parser.IsElement() && (!parser.IsElement("xform")))
                {
                    if (parser.IsElement("translation"))
                    {
                        translation = parser.ReadVector3();
                    }
                    else if (parser.IsElement("rotationX"))
                    {
                        float rotXInDegree = parser.ReadFloat();
                        rotation = rotation * Matrix.CreateRotationX(MathHelper.ToRadians(rotXInDegree));
                    }
                    else if (parser.IsElement("rotationY"))
                    {
                        float rotXInDegree = parser.ReadFloat();
                        rotation = rotation * Matrix.CreateRotationY(MathHelper.ToRadians(rotXInDegree));
                    }
                    else if (parser.IsElement("rotationZ"))
                    {
                        float rotXInDegree = parser.ReadFloat();
                        rotation = rotation * Matrix.CreateRotationZ(MathHelper.ToRadians(rotXInDegree));
                    }
                    else if (parser.IsElement("scale"))
                    {
                        scale = parser.ReadVector3();
                    }
                    else
                    {
                        parser.ParserError("xform");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            return(Matrix.CreateScale(scale) * rotation * Matrix.CreateTranslation(translation));
        }
        private float muSize, mvSize; // entire object size in the U and V direction

        /// <summary>
        /// Constructs from parsing file and then intialize for intersection computation.
        /// </summary>
        /// <param name="parser"></param>
        public RTRectangle(CommandFileParser parser)
        {
            mType = RTGeometryType.Rectangle;

            // do we have a transform?
            bool   hasTransform = false;
            Matrix xform        = Matrix.Identity;

            mVertices      = new Vector3[4];
            mMaterialIndex = 0;

            int count = 0;

            parser.ParserRead();
            while (!parser.IsEndElement("rectangle"))
            {
                if (parser.IsElement() && (!parser.IsElement("rectangle")))
                {
                    if (parser.IsElement("vertices"))
                    {
                        mVertices[count] = parser.ReadVector3();
                        count++;
                    }
                    else if (parser.IsElement("material"))
                    {
                        mMaterialIndex = parser.ReadInt();
                    }
                    else if (parser.IsElement("xform"))
                    {
                        hasTransform = true;
                        xform        = ParseTransform(parser);
                    }
                    else
                    {
                        parser.ParserError("Rectangle");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            if (count != 4)
            {
                parser.ParserError("Rectangle: vertex indexPtr = " + count);
            }
            else
            {
                if (hasTransform)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        mVertices[i] = Vector3.Transform(mVertices[i], xform);
                    }
                }
                InitializeRectangle();
            }
        }
        private Vector3[] mVertices; // always 3 vertices

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs from parsing file and then intialize for intersection computation.
        /// </summary>
        /// <param name="parser"></param>
        public RTTriangle(CommandFileParser parser)
        {
            mType = RTGeometryType.Triangle;

            // do we have a transform?
            bool hasTransform = false;
            Matrix xform = Matrix.Identity;

            mVertices = new Vector3[3];
            mVertexUV = new Vector2[3];
            mMaterialIndex = 0;

            int count = 0;
            parser.ParserRead();
            while (!parser.IsEndElement("triangle"))
            {
                if (parser.IsElement() && (!parser.IsElement("triangle")))
                {
                    if (parser.IsElement("vertices"))
                    {
                        mVertices[count] = parser.ReadVector3();
                    } else
                    if (parser.IsElement("uv"))
                    {
                        mVertexUV[count] = parser.ReadVector2();
                        count++;
                    }

                    else if (parser.IsElement("xform"))
                    {
                        hasTransform = true;
                        xform = ParseTransform(parser);
                    }
                    else if (parser.IsElement("material"))
                        mMaterialIndex = parser.ReadInt();
                    else
                        parser.ParserError("Triangle");
                }
                else
                    parser.ParserRead();
            }
            if (count != 3)
            {
                parser.ParserError("Triangle: vertex indexPtr = " + count);
            }
            else
            {
                if (hasTransform)
                {
                    mVertices[0] = Vector3.Transform(mVertices[0], xform);
                    mVertices[1] = Vector3.Transform(mVertices[1], xform);
                    mVertices[2] = Vector3.Transform(mVertices[2], xform);
                }

                InitializeTriangle();
            }
        }
Beispiel #14
0
        /// <summary>
        ///  constructs from parsing command file.
        /// </summary>
        /// <param name="parser"></param>
        public RTSphere(CommandFileParser parser)
        {
            mType = RTGeometryType.Sphere;

            // do we have a transform?
            bool   hasTransform = false;
            Matrix xform        = Matrix.Identity;

            mCenter        = new Vector3(0f, 0f, 0f);
            mRadius        = 1f;
            mMaterialIndex = 0;

            parser.ParserRead();
            while (!parser.IsEndElement("sphere"))
            {
                if (parser.IsElement() && (!parser.IsElement("sphere")))
                {
                    if (parser.IsElement("center"))
                    {
                        mCenter = parser.ReadVector3();
                    }
                    else if (parser.IsElement("radius"))
                    {
                        mRadius = parser.ReadFloat();
                    }
                    else if (parser.IsElement("material"))
                    {
                        mMaterialIndex = parser.ReadInt();
                    }
                    else if (parser.IsElement("xform"))
                    {
                        hasTransform = true;
                        xform        = ParseTransform(parser);
                    }
                    else
                    {
                        parser.ParserError("Sphere");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            if (hasTransform)
            {
                Vector3 p = mCenter + Vector3.One * mRadius;

                mCenter = Vector3.Transform(mCenter, xform);
                p       = Vector3.Transform(p, xform);

                // ****WARNING****: does not handle unporportional scaling!!
                mRadius = (mCenter - p).Length();
            }
            mRadiusSquared = mRadius * mRadius;
        }
        /// <summary>
        /// Constructor from parser. 
        /// Please DO NOT change the parsing routine unless you know what you are doing).
        /// </summary>
        /// <param name="parser"></param>
        public RTLightType_Point(CommandFileParser parser)
        {
            mLightSourceType = RTLightSourceType.RTLightSourceTypePoint;

            while (!parser.IsEndElement("light"))
            {
                if (parser.IsElement() && (!parser.IsElement("light")))
                {
                    if (parser.IsElement("color"))
                        mColor = parser.ReadVector3();
                    else if (parser.IsElement("position"))
                        mPosition = parser.ReadVector3();
                    else
                        parser.ParserError("Light");
                }
                else
                    parser.ParserRead();
            }
        }
        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Noise(CommandFileParser parser)
        {
            if (null == mPermutation)
            {
                InitPermutation();
            }

            mColor1    = Vector3.One;
            mColor2    = Vector3.Zero;
            mFrequency = 1;
            mAmplitude = 1f;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("color1"))
                    {
                        mColor1 = parser.ReadVector3();
                    }
                    else if (parser.IsElement("color2"))
                    {
                        mColor2 = parser.ReadVector3();
                    }
                    else if (parser.IsElement("frequency"))
                    {
                        mFrequency = parser.ReadInt();
                    }
                    else if (parser.IsElement("amplitude"))
                    {
                        mAmplitude = parser.ReadFloat();
                    }
                    else
                    {
                        parser.ParserError("TextureType_Noise");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
        }
        /// <summary>
        /// Construcs from parsing the command file. 
        /// DO NOT CHANGE the parsing loop unless you know what you are doing.
        /// You can add in initialization computation after the loop
        /// </summary>
        /// <param name="parser"></param>
        public RTCamera(CommandFileParser parser)
        {
            mEye = new Vector3(0f, 0f, 0f);
            mAt = new Vector3(0f, 0f, 1f);
            mUp = new Vector3(0f, 1f, 0f);
            mFOV = 25f;
            mFocus = 1f;

            parser.ParserRead();
            while (!parser.IsEndElement("camera"))
            {
                if (parser.IsElement() && (!parser.IsElement("camera")))
                {
                    if (parser.IsElement("eye"))
                        mEye = parser.ReadVector3();
                    else if (parser.IsElement("lookat"))
                        mAt = parser.ReadVector3();
                    else if (parser.IsElement("upvector"))
                        mUp = parser.ReadVector3();
                    else if (parser.IsElement("fov"))
                        mFOV = parser.ReadFloat();
                    else if (parser.IsElement("focus"))
                        mFocus = parser.ReadFloat();
                    else
                        parser.ParserError("Camera");
                }
                else
                    parser.ParserRead();
            }

            // You can add in your initialization computation after this line

            mViewDir = mAt - mEye;

            // now make sure ViewDir and Up are perpendicular
            mSideVec = Vector3.Cross(mUp, mViewDir);
            mUp = Vector3.Cross(mViewDir, mSideVec);
            mSideVec.Normalize();
            mViewDir.Normalize();
            mUp.Normalize();
        }
        private int mURepeat, mVRepeat; // UV Repeat from command file

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Checker(CommandFileParser parser)
        {
            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("urepeat"))
                        mURepeat = parser.ReadInt();
                    else if (parser.IsElement("vrepeat"))
                        mVRepeat = parser.ReadInt();
                    else if (parser.IsElement("color1"))
                        mColor1 = parser.ReadVector3();
                    else if (parser.IsElement("color2"))
                        mColor2 = parser.ReadVector3();
                    else
                        parser.ParserError("TextureType_Checker");
                }
                else
                    parser.ParserRead();
            }
        }
        /// <summary>
        /// Parse command line for <xform> </xform> that is embedeed inside 
        /// Geometry.
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        protected static Matrix ParseTransform(CommandFileParser parser)
        {
            Matrix xform = Matrix.Identity;
            Vector3 translation = Vector3.Zero;
            Matrix rotation = Matrix.Identity;
            Vector3 scale = Vector3.One;

            parser.ParserRead();
            while (!parser.IsEndElement("xform"))
            {
                if (parser.IsElement() && (!parser.IsElement("xform")))
                {
                    if (parser.IsElement("translation"))
                        translation = parser.ReadVector3();
                    else if (parser.IsElement("rotationX"))
                    {
                        float rotXInDegree = parser.ReadFloat();
                        rotation = rotation * Matrix.CreateRotationX(MathHelper.ToRadians(rotXInDegree));
                    }
                    else if (parser.IsElement("rotationY"))
                    {
                        float rotXInDegree = parser.ReadFloat();
                        rotation = rotation * Matrix.CreateRotationY(MathHelper.ToRadians(rotXInDegree));
                    }
                    else if (parser.IsElement("rotationZ"))
                    {
                        float rotXInDegree = parser.ReadFloat();
                        rotation = rotation * Matrix.CreateRotationZ(MathHelper.ToRadians(rotXInDegree));
                    }
                    else if (parser.IsElement("scale"))
                        scale = parser.ReadVector3();
                    else
                        parser.ParserError("xform");
                }
                else
                    parser.ParserRead();
            }
            return Matrix.CreateScale(scale) * rotation * Matrix.CreateTranslation(translation);
        }
        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Sine(CommandFileParser parser)
        {
            mPeriod    = 1f;
            mDirection = Vector2.UnitX;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("period"))
                    {
                        mPeriod = parser.ReadFloat();
                    }
                    else if (parser.IsElement("direction"))
                    {
                        mDirection = parser.ReadVector2();
                    }
                    else if (parser.IsElement("color1"))
                    {
                        mColor1 = parser.ReadVector3();
                    }
                    else if (parser.IsElement("color2"))
                    {
                        mColor2 = parser.ReadVector3();
                    }
                    else
                    {
                        parser.ParserError("TextureType_Sine");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            mThetaRange = mPeriod * (float)Math.PI * 2f;
            mDirection  = Vector2.Normalize(mDirection);
        }
        private bool mUseDepthMap = false; // off

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor from parser. 
        /// Please DO NOT change the parsing routine unless you know what you are doing).
        /// </summary>
        /// <param name="parser"></param>
        public RTLightType_Spot(CommandFileParser parser)
        {
            mLightSourceType = RTLightSourceType.RTLightSourceTypeSpot;

            while (!parser.IsEndElement("light"))
            {
                if (parser.IsElement() && (!parser.IsElement("light")))
                {
                    if (parser.IsElement("color"))
                        mColor = parser.ReadVector3();
                    else if (parser.IsElement("position"))
                        mPosition = parser.ReadVector3();
                    else if (parser.IsElement("direction"))
                        mDirection = parser.ReadVector3();
                    else if (parser.IsElement("innerAngle"))
                        mInnerAngle = MathHelper.ToRadians(parser.ReadFloat());
                    else if (parser.IsElement("outerAngle"))
                        mOuterAngle = MathHelper.ToRadians(parser.ReadFloat());
                    else if (parser.IsElement("falloff"))
                        mFallOff = parser.ReadFloat();
                    else if (parser.IsElement("depthMap"))
                        mUseDepthMap = parser.ReadBool();
                    else if (parser.IsElement("depthMapResolution"))
                        mRes = parser.ReadInt();
                    else if (parser.IsElement("depthMapFilterRes"))
                        mFilterRes = parser.ReadInt();
                    else
                        parser.ParserError("Light");
                }
                else
                    parser.ParserRead();
            }

            mDirection = -Vector3.Normalize(mDirection);
            mCosInAngle = (float) Math.Cos(mInnerAngle / 2);
            mCosOutAngle = (float)Math.Cos(mOuterAngle / 2);
            mFallOffDenominator = 1f / (mCosInAngle - mCosOutAngle);
        }
        /// <summary>
        /// Constructor from parser. 
        /// Please DO NOT change the parsing routine unless you know what you are doing).
        /// </summary>
        /// <param name="parser"></param>
        public RTLightType_Directional(CommandFileParser parser)
        {
            mLightSourceType = RTLightSourceType.RTLightSourceTypeDirection;

            while (!parser.IsEndElement("light"))
            {
                if (parser.IsElement() && (!parser.IsElement("light")))
                {
                    if (parser.IsElement("color"))
                        mColor = parser.ReadVector3();
                    else if (parser.IsElement("position"))
                        mPosition = parser.ReadVector3();
                    else if (parser.IsElement("direction"))
                        mDirection = parser.ReadVector3();
                    else
                        parser.ParserError("Light");
                }
                else
                    parser.ParserRead();
            }

            mDirection = -Vector3.Normalize(mDirection);
        }
        private float mRepeat; // how many periods to be fitted within 0 to 1 U

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Ramp(CommandFileParser parser)
        {
            mRepeat = 1f;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("repeat"))
                        mRepeat = parser.ReadFloat();
                    else if (parser.IsElement("color1"))
                        mColor1 = parser.ReadVector3();
                    else if (parser.IsElement("color2"))
                        mColor2 = parser.ReadVector3();
                    else
                        parser.ParserError("TextureType_Ramp");
                }
                else
                    parser.ParserRead();
            }
            if (mRepeat <= 0)
                mRepeat = 1f;
        }
        private float mThetaRange; // range from 0 to this value (mPeroid * 2PI)

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constrcuts from the commandfile.
        /// DO NOT change the pasing loop unless you know what you are doing.
        /// </summary>
        /// <param name="parser"></param>
        public RTTextureType_Marble(CommandFileParser parser)
        {
            // From super class:
            //      Color1/2
            //      Frequency and
            //      Amplitude

            mPeriod = 1f;
            mDirection = Vector3.UnitY;
            mAmplitude = 1f;

            while (!parser.IsEndElement("texture"))
            {
                if (parser.IsElement() && (!parser.IsElement("texture")))
                {
                    if (parser.IsElement("period"))
                        mPeriod = parser.ReadFloat();
                    else if (parser.IsElement("frequency"))
                        mFrequency = parser.ReadInt();
                    else if (parser.IsElement("amplitude"))
                        mAmplitude = parser.ReadFloat();
                    else if (parser.IsElement("direction"))
                        mDirection = parser.ReadVector3();
                    else if (parser.IsElement("color1"))
                        mColor1 = parser.ReadVector3();
                    else if (parser.IsElement("color2"))
                        mColor2 = parser.ReadVector3();
                    else
                        parser.ParserError("TextureType_Marble");
                }
                else
                    parser.ParserRead();
            }
            mThetaRange = mPeriod * (float) Math.PI * 2f;
            mDirection = Vector3.Normalize(mDirection);
        }
        private float mRadiusSquared; // r*r

        #endregion Fields

        #region Constructors

        /// <summary>
        ///  constructs from parsing command file.
        /// </summary>
        /// <param name="parser"></param>
        public RTSphere(CommandFileParser parser)
        {
            mType = RTGeometryType.Sphere;

            // do we have a transform?
            bool hasTransform = false;
            Matrix xform = Matrix.Identity;

            mCenter = new Vector3(0f, 0f, 0f);
            mRadius = 1f;
            mMaterialIndex = 0;

            parser.ParserRead();
            while (!parser.IsEndElement("sphere"))
            {
                if (parser.IsElement() && (!parser.IsElement("sphere")))
                {
                    if (parser.IsElement("center"))
                        mCenter = parser.ReadVector3();
                    else if (parser.IsElement("radius"))
                        mRadius = parser.ReadFloat();
                    else if (parser.IsElement("material"))
                        mMaterialIndex = parser.ReadInt();
                    else if (parser.IsElement("xform"))
                    {
                        hasTransform = true;
                        xform = ParseTransform(parser);
                    }
                    else
                        parser.ParserError("Sphere");
                }
                else
                    parser.ParserRead();
            }
            if (hasTransform)
            {
                Vector3 p = mCenter + Vector3.One * mRadius;

                mCenter = Vector3.Transform(mCenter, xform);
                p = Vector3.Transform(p, xform);

                // ****WARNING****: does not handle unporportional scaling!!
                mRadius = (mCenter - p).Length();
            }
            mRadiusSquared = mRadius * mRadius;
        }
 public void Parse(CommandFileParser parser)
 {
     parser.ParserRead();
     while (!parser.IsEndElement("rtspec"))
     {
         if (parser.IsElement() && (!parser.IsElement("rtspec")))
         {
             if (parser.IsElement("generation"))
                 mGeneration = parser.ReadInt();
             else if (parser.IsElement("shadow"))
                 mComputeShadow = parser.ReadBool();
             else if (parser.IsElement("reflection"))
                 mComputeReflection = parser.ReadBool();
             else if (parser.IsElement("background"))
                 mBgColor = parser.ReadVector3();
             else
                 parser.ParserError("RTWorld");
         }
         else
             parser.ParserRead();
     }
 }
Beispiel #27
0
        private Vector2 mD02, mD12; // delta UV between vertex-0 and 2; and vertex-1 and 2

        /// <summary>
        /// Constructs from parsing file and then intialize for intersection computation.
        /// </summary>
        /// <param name="parser"></param>
        public RTTriangle(CommandFileParser parser)
        {
            mType = RTGeometryType.Triangle;

            // do we have a transform?
            bool   hasTransform = false;
            Matrix xform        = Matrix.Identity;

            mVertices      = new Vector3[3];
            mVertexUV      = new Vector2[3];
            mMaterialIndex = 0;

            int count = 0;

            parser.ParserRead();
            while (!parser.IsEndElement("triangle"))
            {
                if (parser.IsElement() && (!parser.IsElement("triangle")))
                {
                    if (parser.IsElement("vertices"))
                    {
                        mVertices[count] = parser.ReadVector3();
                    }
                    else
                    if (parser.IsElement("uv"))
                    {
                        mVertexUV[count] = parser.ReadVector2();
                        count++;
                    }

                    else if (parser.IsElement("xform"))
                    {
                        hasTransform = true;
                        xform        = ParseTransform(parser);
                    }
                    else if (parser.IsElement("material"))
                    {
                        mMaterialIndex = parser.ReadInt();
                    }
                    else
                    {
                        parser.ParserError("Triangle");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
            if (count != 3)
            {
                parser.ParserError("Triangle: vertex indexPtr = " + count);
            }
            else
            {
                if (hasTransform)
                {
                    mVertices[0] = Vector3.Transform(mVertices[0], xform);
                    mVertices[1] = Vector3.Transform(mVertices[1], xform);
                    mVertices[2] = Vector3.Transform(mVertices[2], xform);
                }

                InitializeTriangle();
            }
        }
        public RTMaterial(CommandFileParser parser)
        {
            InitializeMaterial();

            parser.ParserRead();
            while (!parser.IsEndElement("material"))
            {
                if (parser.IsElement() && (!parser.IsElement("material")))
                {
                    if (parser.IsElement("index"))
                    {
                        int i = parser.ReadInt();
                        SetResourceIndex(i);
                    }
                    else if (parser.IsElement("ka"))
                    {
                        mKa.SetAttribute(parser.ReadVector3());
                    }
                    else if (parser.IsElement("ks"))
                    {
                        mKs.SetAttribute(parser.ReadVector3());
                    }
                    else if (parser.IsElement("kd"))
                    {
                        mKd.SetAttribute(parser.ReadVector3());
                    }
                    else if (parser.IsElement("n"))
                    {
                        mN = parser.ReadFloat();
                    }
                    else if (parser.IsElement("textureindex"))  // backward compatibility
                    {
                        mKd.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("kaIndex"))
                    {
                        mKa.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("kdIndex"))
                    {
                        mKd.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("ksIndex"))
                    {
                        mKs.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("tIndex"))
                    {
                        mTransparency.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("rIndex"))
                    {
                        mReflectivity.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("nIndex"))
                    {
                        mNormal.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("ptIndex"))
                    {
                        mPosition.SetTextureIndex(parser.ReadInt());
                    }
                    else if (parser.IsElement("reflectivity"))
                    {
                        mReflectivity.SetAttribute(parser.ReadFloat());
                    }
                    else if (parser.IsElement("transparency"))
                    {
                        mTransparency.SetAttribute(parser.ReadFloat());
                    }
                    else if (parser.IsElement("refractiveindex"))
                    {
                        mRefractiveIndex = parser.ReadFloat();
                    }
                    else
                    {
                        parser.ParserError("Material");
                    }
                }
                else
                {
                    parser.ParserRead();
                }
            }
        }