public ConstantBuffer(SlimDX.Direct3D11.Device device) { _device = device; sizeInBytes = 4 * 4 * sizeof(float) * 2 + 4 * sizeof(float) * 3 + sizeof(float) * (4 + 4 + 4); BufferDescription constBufferDescription = new BufferDescription(); constBufferDescription.Usage = ResourceUsage.Default; constBufferDescription.SizeInBytes = sizeInBytes; constBufferDescription.BindFlags = BindFlags.ConstantBuffer; constBufferDescription.CpuAccessFlags = CpuAccessFlags.None; _constBuffer = new SlimDX.Direct3D11.Buffer(device, constBufferDescription); _wasChanged = true; _world = SlimDX.Matrix.Identity; _view = SlimDX.Matrix.Identity; _projection = SlimDX.Matrix.Identity; _material = new Material(new SlimDX.Vector4(0.6f, 0.6f, 0.6f, 1.0f), new SlimDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new SlimDX.Vector4(0.0f, 0.0f, 0.0f, 1.0f)); _lightDirection = new SlimDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f); _ambientLight = new SlimDX.Vector4(0.1f, 0.1f, 0.1f, 1.0f); _cameraPosition = new SlimDX.Vector4(0.0f, 0.0f, -1.0f, 1.0f); }
public R32G32B32A32F(SlimDX.Vector4 rgba) { this.r = rgba.X; this.g = rgba.Y; this.b = rgba.Z; this.a = rgba.W; }
public void Write(SlimDX.Vector4 data) { unsafe { SlimDX.Vector4 *pPtr = &data; Write((IntPtr)pPtr, sizeof(SlimDX.Vector4)); } }
public T Resolve <T>(IObjectWithID obj) where T : StyleObject { T res = (_styles.AllStyles.Find(styleObject => styleObject.GetType() == typeof(T)) as T).Clone() as T; SlimDX.Vector4 color = EncodeColor(obj).ToVector4(); Material mat = new Material(color, color, color); res.SetProperties(mat); return(res); }
public void Transform(SlimDX.Matrix rotation) { SlimDX.Vector4 coords = SlimDX.Vector4.Transform(new SlimDX.Vector4(X, Y, Z, 1.0f), rotation); SlimDX.Vector4 normals = SlimDX.Vector4.Transform(new SlimDX.Vector4(NX, NY, NZ, 1.0f), rotation); X = coords.X; Y = coords.Y; Z = coords.Z; NX = normals.X; NY = normals.Y; NZ = normals.Z; if (Math.Abs((float)Math.Sqrt(NX * NX + NY * NY + NZ * NZ) - 1.0f) > 1e-3) { throw new ApplicationException( "Internal error: rotation matrix also performs translation and/or scaling"); } }
private static Material LoadMaterialParameter(XmlNode xml) { SlimDX.Vector4 diffColor = new SlimDX.Vector4(); SlimDX.Vector4 specColor = new SlimDX.Vector4(); SlimDX.Vector4 rimColor = new SlimDX.Vector4(); Dictionary <String, bool> loadedFields = new Dictionary <string, bool>(); loadedFields["DiffColor"] = false; loadedFields["SpecColor"] = false; loadedFields["RimColor"] = false; foreach (XmlAttribute attr in xml.Attributes) { if (attr.Name == "DiffColor") { diffColor = ParseVector(attr.Value); loadedFields["DiffColor"] = true; } else if (attr.Name == "SpecColor") { specColor = ParseVector(attr.Value); loadedFields["SpecColor"] = true; } else if (attr.Name == "RimColor") { rimColor = ParseVector(attr.Value); loadedFields["RimColor"] = true; } } if (!(loadedFields["DiffColor"] && loadedFields["SpecColor"] && loadedFields["RimColor"])) { throw new ApplicationException("Internal error - failed to load some section"); } return(new Material(diffColor, specColor, rimColor)); }
/** Interpolates a single segment of the spline given a parametric value. * @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1 * @param t Parametric value */ public SlimDX.Vector3 Interpolate(UInt32 fromIndex, float t) { System.Diagnostics.Debug.Assert(fromIndex < mPoints.Count, "Point index is out of bounds!!"); if ((fromIndex + 1) == mPoints.Count) { // Duff request, cannot blend to nothing // Just return source return(mPoints[(int)fromIndex]); } // Fast special cases if (t == 0.0f) { return(mPoints[(int)fromIndex]); } else if (t == 1.0f) { return(mPoints[(int)fromIndex + 1]); } // Real interpolation // Form a vector of powers of t float t2, t3; t2 = t * t; t3 = t2 * t; SlimDX.Vector4 powers; powers.X = t3; powers.Y = t2; powers.Z = t; powers.W = 1; // Algorithm is ret = powers * mCoeffs * Matrix4(point1, point2, tangent1, tangent2) SlimDX.Vector3 point1 = mPoints[(int)fromIndex]; SlimDX.Vector3 point2 = mPoints[(int)fromIndex + 1]; SlimDX.Vector3 tan1 = mTangents[(int)fromIndex]; SlimDX.Vector3 tan2 = mTangents[(int)fromIndex + 1]; SlimDX.Matrix pt; pt.M11 = point1.X; pt.M12 = point1.Y; pt.M13 = point1.Z; pt.M14 = 1.0f; pt.M21 = point2.X; pt.M22 = point2.Y; pt.M23 = point2.Z; pt.M24 = 1.0f; pt.M31 = tan1.X; pt.M32 = tan1.Y; pt.M33 = tan1.Z; pt.M34 = 1.0f; pt.M41 = tan2.X; pt.M42 = tan2.Y; pt.M43 = tan2.Z; pt.M44 = 1.0f; SlimDX.Matrix tempM = mCoeffs * pt; SlimDX.Vector4 ret = SlimDX.Vector4.Transform(powers, tempM); return(new SlimDX.Vector3(ret.X, ret.Y, ret.Z)); }
public List<Pass.PassData> PaserObj(string objName) { List<Pass.PassData> datalist = new List<Pass.PassData>(); Dictionary<string, Material> matDic = new Dictionary<string,Material>(); foreach (string line in System.IO.File.ReadAllLines(objName)) { if (line.StartsWith("mtllib")) { string matLibName = line.Substring(7); matDic = parseMat("media/" + matLibName); } else if (line.StartsWith("vt")) { string[] tempAry = line.Split(new char[1] { ' ' }); tempAry = Array.FindAll<string>(tempAry, x => { float temp; return float.TryParse(x, out temp); }); SlimDX.Vector2 uv = new SlimDX.Vector2(); uv.X = System.Convert.ToSingle(tempAry[0]); uv.Y = 1.0f - System.Convert.ToSingle(tempAry[1]); uvList.Add(uv); } else if (line.StartsWith("vn")) { string[] tempAry = line.Split(new char[1] { ' ' }); tempAry = Array.FindAll<string>(tempAry, x => { float temp; return float.TryParse(x, out temp); }); SlimDX.Vector4 normal = new SlimDX.Vector4(); normal.X = System.Convert.ToSingle(tempAry[0]); normal.Y = System.Convert.ToSingle(tempAry[1]); normal.Z = System.Convert.ToSingle(tempAry[2])-1.0f; normalList.Add(normal); } else if (line.StartsWith("v")) { string[] tempAry = line.Split(new char[1] { ' ' }); tempAry = Array.FindAll<string>(tempAry, x => { float temp; return float.TryParse(x, out temp); }); SlimDX.Vector4 pos = new SlimDX.Vector4(); pos.X = System.Convert.ToSingle(tempAry[0]); pos.Y = System.Convert.ToSingle(tempAry[1]); pos.Z = System.Convert.ToSingle(tempAry[2])*(-1.0f); pos.W = 1.0f; posList.Add(pos); } } List<Vertex> vertexList = new List<Vertex>(); List<int[]> triangleIndexList = new List<int[]>(); Material m = null; Pass.PassData data = null; Dictionary<string, int> cache = new Dictionary<string, int>(); int dataCount = 0; foreach (string line in System.IO.File.ReadAllLines(objName)) { if (line.StartsWith("usemtl")) { if (data != null) { data.triangleIndexs = triangleIndexList; data.vertexs = vertexList.ToArray(); data.materail = m; datalist.Add(data); dataCount++; System.Console.WriteLine(dataCount); } data = new Pass.PassData(); string[] tempAry = line.Split(new char[1] { ' ' }); string matName = tempAry[1]; m = matDic[matName]; vertexList = new List<Vertex>(); triangleIndexList = new List<int[]>(); cache.Clear(); } else if (line.StartsWith("f")) { string[] tempAry = line.Split(new char[1] { ' ' }); int[] indexs = new int[3]; for (int i=3; i>=1; i--) { string s = tempAry[i]; if (string.IsNullOrWhiteSpace(s) || string.IsNullOrEmpty(s)) continue; string[] IndexAry = s.Split(new char[1] { '/' }); if (IndexAry.Length == 1) { int posIndex = Convert.ToInt32(IndexAry[0]) - 1; string cacheString = "pos" + posIndex.ToString(); if (cache.ContainsKey(cacheString)) { int index = cache[cacheString]; indexs[i] = index; } else { Vertex newVertex = new Vertex(); newVertex.pos = posList[posIndex]; vertexList.Add(newVertex); indexs[i] = vertexList.Count - 1; cache[cacheString] = vertexList.Count - 1; } //triangleIndexList.Add(indexs); } else if (IndexAry.Length == 2) { int posIndex = Convert.ToInt32(IndexAry[0]) - 1; int uvIndex = Convert.ToInt32(IndexAry[1]) - 1; string cacheString = "pos" + posIndex.ToString() + "uv" + uvIndex.ToString(); if (cache.ContainsKey(cacheString)) { int index = cache[cacheString]; indexs[i] = index; } else { Vertex newVertex = new Vertex(); newVertex.pos = posList[posIndex]; newVertex.uv = uvList[uvIndex]; vertexList.Add(newVertex); indexs[i] = vertexList.Count - 1; cache[cacheString] = vertexList.Count - 1; } //triangleIndexList.Add(indexs); } else if (IndexAry.Length == 3) { int posIndex = Convert.ToInt32(IndexAry[0]) - 1; int uvIndex = Convert.ToInt32(IndexAry[1]) - 1; int normalIndex = Convert.ToInt32(IndexAry[2]) - 1; string cacheString = "pos" + posIndex.ToString() + "uv" + uvIndex.ToString() + "normal"+normalIndex.ToString(); if (cache.ContainsKey(cacheString)) { int index = cache[cacheString]; indexs[i-1] = index; } else { Vertex newVertex = new Vertex(); newVertex.pos = posList[posIndex]; newVertex.uv = uvList[uvIndex]; newVertex.normal = normalList[normalIndex]; vertexList.Add(newVertex); indexs[i-1] = vertexList.Count - 1; cache[cacheString] = vertexList.Count - 1; } } } int index1 = indexs[0]; int index2 = indexs[1]; int index3 = indexs[2]; indexs[0] = index3; indexs[1] = index2; indexs[2] = index1; triangleIndexList.Add(indexs); } } if (data != null) { data.triangleIndexs = triangleIndexList; data.vertexs = vertexList.ToArray(); data.materail = m; datalist.Add(data); } return datalist; }
public void WritePODObject(System.Object obj) { System.Type type = obj.GetType(); if (type == typeof(System.SByte)) { Write(System.Convert.ToSByte(obj)); } else if (type == typeof(System.Int16)) { Write(System.Convert.ToInt16(obj)); } else if (type == typeof(System.Int32)) { Write(System.Convert.ToInt32(obj)); } else if (type == typeof(System.Int64)) { Write(System.Convert.ToInt64(obj)); } else if (type == typeof(System.Byte)) { Write(System.Convert.ToByte(obj)); } else if (type == typeof(System.UInt16)) { Write(System.Convert.ToUInt16(obj)); } else if (type == typeof(System.UInt32)) { Write(System.Convert.ToUInt32(obj)); } else if (type == typeof(System.UInt64)) { Write(System.Convert.ToUInt64(obj)); } else if (type == typeof(System.Single)) { Write(System.Convert.ToSingle(obj)); } else if (type == typeof(System.Double)) { Write(System.Convert.ToDouble(obj)); } else if (type == typeof(System.Guid)) { //Guid id = Guid.Parse(obj.ToString()); System.Guid id = (System.Guid)(obj); Write(id); } else if (type == typeof(SlimDX.Vector2)) { SlimDX.Vector2 v = (SlimDX.Vector2)(obj); Write(v); } else if (type == typeof(SlimDX.Vector3)) { //Guid id = Guid.Parse(obj.ToString()); SlimDX.Vector3 v = (SlimDX.Vector3)(obj); Write(v); } else if (type == typeof(SlimDX.Vector4)) { SlimDX.Vector4 v = (SlimDX.Vector4)(obj); Write(v); } else if (type == typeof(SlimDX.Quaternion)) { SlimDX.Quaternion q = (SlimDX.Quaternion)(obj); Write(q); } else if (type == typeof(SlimDX.Matrix)) { SlimDX.Matrix mat = (SlimDX.Matrix)(obj); Write(mat); } else if (type == typeof(System.String)) { System.String str = (System.String)(obj); Write(str); } else if (type == typeof(DataWriter)) { var dr = (DataWriter)(obj); Write(dr); } }
public static Microsoft.Xna.Framework.Vector4 xna(this SlimDX.Vector4 v) { return(new Microsoft.Xna.Framework.Vector4(v.X, v.Y, v.Z, v.W)); }
protected bool WritePkg(PackageWriter pkg, System.Reflection.PropertyInfo i) { var propType = i.PropertyType; if (propType == typeof(System.SByte)) { pkg.Write(System.Convert.ToSByte(i.GetValue(this, null))); } else if (propType == typeof(System.Int16)) { pkg.Write(System.Convert.ToInt16(i.GetValue(this, null))); } else if (propType == typeof(System.Int32)) { pkg.Write(System.Convert.ToInt32(i.GetValue(this, null))); } else if (propType == typeof(System.Int64)) { pkg.Write(System.Convert.ToInt64(i.GetValue(this, null))); } else if (propType == typeof(System.Byte)) { pkg.Write(System.Convert.ToByte(i.GetValue(this, null))); } else if (propType == typeof(System.UInt16)) { pkg.Write(System.Convert.ToUInt16(i.GetValue(this, null))); } else if (propType == typeof(System.UInt32)) { pkg.Write(System.Convert.ToUInt32(i.GetValue(this, null))); } else if (propType == typeof(System.UInt64)) { pkg.Write(System.Convert.ToUInt64(i.GetValue(this, null))); } else if (propType == typeof(System.Single)) { pkg.Write(System.Convert.ToSingle(i.GetValue(this, null))); } else if (propType == typeof(System.Double)) { pkg.Write(System.Convert.ToDouble(i.GetValue(this, null))); } else if (propType == typeof(System.Guid)) { System.Guid id = (System.Guid)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(SlimDX.Vector2)) { SlimDX.Vector2 id = (SlimDX.Vector2)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(SlimDX.Vector3)) { SlimDX.Vector3 id = (SlimDX.Vector3)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(SlimDX.Vector4)) { SlimDX.Vector4 id = (SlimDX.Vector4)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(SlimDX.Quaternion)) { SlimDX.Quaternion id = (SlimDX.Quaternion)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(SlimDX.Matrix)) { SlimDX.Matrix id = (SlimDX.Matrix)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(System.DateTime)) { System.DateTime id = (System.DateTime)(i.GetValue(this, null)); pkg.Write(id); } else if (propType == typeof(System.String)) { System.String str = (System.String)(i.GetValue(this, null)); pkg.Write(str); } else if (propType == typeof(System.Byte[])) { System.Byte[] str = (System.Byte[])(i.GetValue(this, null)); pkg.Write(str); } else { return(false); } return(true); }
public Material(SlimDX.Vector4 diffColor, SlimDX.Vector4 specColor, SlimDX.Vector4 rimColor) { DiffColor = diffColor; SpecColor = specColor; RimColor = rimColor; }
public Material() { DiffColor = new SlimDX.Vector4(1.0f); SpecColor = new SlimDX.Vector4(1.0f); RimColor = new SlimDX.Vector4(1.0f); }
internal static PositionBlock FromVector(SlimDX.Vector4 vector4) { return(new PositionBlock((int)vector4.X, (int)vector4.Y, (int)vector4.Z)); }