/// <summary> /// Define a picking region. /// </summary> /// <param name="center">The center.</param> /// <param name="delta">The delta.</param> /// <param name="viewport">The viewport.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static mat4 pickMatrix(ivec2 center, ivec2 delta, ivec4 viewport) { if (delta.x <= 0 || delta.y <= 0) { throw new ArgumentOutOfRangeException(); } var Result = new mat4(1.0f); if (!(delta.x > (0f) && delta.y > (0f))) { return(Result); // Error } vec3 Temp = new vec3( ((viewport[2]) - (2f) * (center.x - (viewport[0]))) / delta.x, ((viewport[3]) - (2f) * (center.y - (viewport[1]))) / delta.y, (0f)); // Translate and scale the picked region to the entire window Result = translate(Result, Temp); return(scale(Result, new vec3((float)(viewport[2]) / delta.x, (float)(viewport[3]) / delta.y, (1)))); }
// <vertexbuffer count="13114" ctype="fff fff ff ff ff ffff hhhh" semantic="position normal texcoord1 texcoord2 texcoord3 blendweights blendindices"> /// <summary> /// /// </summary> /// <param name="xElement"></param> /// <returns></returns> public static unsafe EZMVertexbuffer Parse(System.Xml.Linq.XElement xElement) { EZMVertexbuffer result = null; if (xElement.Name == "vertexbuffer") { result = new EZMVertexbuffer(); int groupCount = int.Parse(xElement.Attribute("count").Value); result.Ctypes = xElement.Attribute("ctype").Value.Split(' '); result.Semantics = xElement.Attribute("semantic").Value.Split(' '); if (result.Ctypes.Length != result.Semantics.Length) { throw new Exception("EZMVertexbuffer.Ctypes.Length != EZMVertexbuffer.Semantics.Length"); } int groupSize = result.Ctypes.Length; // how many elements in a group. string[] parts = xElement.Value.Split(Separator.separators, StringSplitOptions.RemoveEmptyEntries); var lineLength = result.Ctypes[0].Length; var charCounts = new int[groupSize]; for (int i = 1; i < groupSize; i++) { charCounts[i] = charCounts[i - 1] + result.Ctypes[i - 1].Length; lineLength += result.Ctypes[i].Length; } var buffers = new Passbuffer[groupSize]; var pointers = new void *[groupSize]; for (int i = 0; i < groupSize; i++) { int index = charCounts[i]; buffers[i] = new Passbuffer(result.Ctypes[i], groupCount); pointers[i] = buffers[i].Mapbuffer().ToPointer(); switch (buffers[i].type) { case PassType.vec4: for (int t = 0; t < groupCount; t++) { float x = float.Parse(parts[t * lineLength + index + 0]); float y = float.Parse(parts[t * lineLength + index + 1]); float z = float.Parse(parts[t * lineLength + index + 2]); float w = float.Parse(parts[t * lineLength + index + 3]); var array = (vec4 *)pointers[i]; array[t] = new vec4(x, y, z, w); if (!(0 <= x && x <= 1)) { Console.WriteLine("Error"); } if (!(0 <= y && y <= 1)) { Console.WriteLine("Error"); } if (!(0 <= z && z <= 1)) { Console.WriteLine("Error"); } if (!(0 <= w && w <= 1)) { Console.WriteLine("Error"); } } break; case PassType.vec3: for (int t = 0; t < groupCount; t++) { float x = float.Parse(parts[t * lineLength + index + 0]); float y = float.Parse(parts[t * lineLength + index + 1]); float z = float.Parse(parts[t * lineLength + index + 2]); var array = (vec3 *)pointers[i]; array[t] = new vec3(x, y, z); } break; case PassType.vec2: var vec2xList = new List <float>(); var vec2yList = new List <float>(); for (int t = 0; t < groupCount; t++) { float x = float.Parse(parts[t * lineLength + index + 0]); if (x < 0) { x = 0; } if (1 < x) { x = 1; } float y = float.Parse(parts[t * lineLength + index + 1]); if (y < 0) { y = 0; } if (1 < y) { y = 1; } var array = (vec2 *)pointers[i]; array[t] = new vec2(x, y); if (!(0 <= x && x <= 1)) { vec2xList.Add(x); } if (!(0 <= y && y <= 1)) { vec2yList.Add(y); } } if (vec2xList.Count > 0 || vec2yList.Count > 0) { Console.WriteLine("Error"); } break; case PassType.ivec4: var list = new List <int>(); for (int t = 0; t < groupCount; t++) { int x = int.Parse(parts[t * lineLength + index + 0]); int y = int.Parse(parts[t * lineLength + index + 1]); int z = int.Parse(parts[t * lineLength + index + 2]); int w = int.Parse(parts[t * lineLength + index + 3]); var array = (ivec4 *)pointers[i]; array[t] = new ivec4(x, y, z, w); if (!list.Contains(x)) { list.Add(x); } if (!list.Contains(y)) { list.Add(y); } if (!list.Contains(z)) { list.Add(z); } if (!list.Contains(w)) { list.Add(w); } } break; default: break; } buffers[i].Unmapbuffer(); } result.Buffers = buffers; } return(result); }
/// <summary> /// /// </summary> /// <param name="v"></param> public ivec2(ivec4 v) { this.x = v.x; this.y = v.y; }
/// <summary> /// /// </summary> /// <param name="v"></param> public ivec3(ivec4 v) { this.x = v.x; this.y = v.y; this.z = v.z; }