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); }
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(); }
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); }
private Bitmap mTextureImage; // the bitmap image file. #endregion Fields #region Constructors /// <summary> /// Constructs from parsing the command file. /// DO NOT change the parser loop unless you know what you are doing. /// </summary> /// <param name="parser"></param> public RTTextureType_Bump(CommandFileParser parser) { mGain = 1.0f; while (!parser.IsEndElement("texture")) { if (parser.IsElement() && (!parser.IsElement("texture"))) { if (parser.IsElement("filename")) { String name = parser.ReadString(); name = parser.FullPath() + "\\" + name; if (System.IO.File.Exists(name)) mTextureImage = new Bitmap(name, true); else parser.ParserError("TextureType_Bump filename"); } else if (parser.IsElement("gain")) mGain = parser.ReadFloat(); else parser.ParserError("TextureType_Bump"); } else parser.ParserRead(); } mInvWidth = 1f / (float)(mTextureImage.Width - 1); mInvHeight = 1f / (float)(mTextureImage.Height - 1); }
/// <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_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); }
/// <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> /// 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)); }
/// <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> /// 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(); }
/// <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); }
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); }
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 mVRepeat; // inverse of repeat #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_Grid(CommandFileParser parser) { mURepeat = 1f; mVRepeat = 1f; while (!parser.IsEndElement("texture")) { if (parser.IsElement() && (!parser.IsElement("texture"))) { if (parser.IsElement("urepeat")) mURepeat = parser.ReadFloat(); if (parser.IsElement("vrepeat")) mVRepeat = 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(); } }
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; }
/// <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> /// Constructs from parsing the command file. /// DO NOT change the parser loop unless you know what you are doing. /// </summary> /// <param name="parser"></param> public RTTextureType_Bump(CommandFileParser parser) { mGain = 1.0f; while (!parser.IsEndElement("texture")) { if (parser.IsElement() && (!parser.IsElement("texture"))) { if (parser.IsElement("filename")) { String name = parser.ReadString(); name = parser.FullPath() + "\\" + name; if (System.IO.File.Exists(name)) { mTextureImage = new Bitmap(name, true); } else { parser.ParserError("TextureType_Bump filename"); } } else if (parser.IsElement("gain")) { mGain = parser.ReadFloat(); } else { parser.ParserError("TextureType_Bump"); } } else { parser.ParserRead(); } } mInvWidth = 1f / (float)(mTextureImage.Width - 1); mInvHeight = 1f / (float)(mTextureImage.Height - 1); }
/// <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); }
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(); } } }