/// <summary> /// 更新数据 /// </summary> /// <param name="cacheValue"></param> /// <param name="value">更新后的数据</param> /// <param name="oldValue">更新前的数据</param> /// <param name="memberMap"></param> protected void onUpdated(valueType cacheValue, valueType value, valueType oldValue, MemberMap <modelType> memberMap) { keyType key = getKey(value), oldKey = getKey(oldValue); if (key.Equals(oldKey)) { targetType target = getValue(key); if (target == null) { cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString()); } else { ListArray <valueType> list = getMember(target); if (list == null) { cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Fatal, typeof(valueType).FullName + " 缓存同步错误"); } else { setMember(target, new ListArray <valueType>(sorter(list.ToLeftArray()))); } } } else { onInserted(cacheValue, key); onDeleted(cacheValue, oldKey); } }
[TestMethod] //Поиск в пустом списке public void FindInEmptyListTest() { int n = 3; ListArray <object> data = new ListArray <object>(n); data.Find(11); }
/// <summary> /// Constructs a <see cref="UIManager"/> instance using an existing grayscale region. /// </summary> /// <param name="grayscaleRegion"> /// A <see cref="TextureRegion2D"/> containing at least 1x1 white pixel /// at (X:0,Y:0) and a 1x1 gray pixel at (X:0,Y:1) /// (this can be larger as linear filtering can stretch the texture). /// This texture is mostly used for better shading on elements. /// </param> public UIManager(GraphicsDevice device, TextureRegion2D grayscaleRegion, TextureRegion2D whitePixelRegion) { GrayscaleRegion = grayscaleRegion ?? throw new ArgumentNullException(nameof(grayscaleRegion)); if (GrayscaleRegion.Width < 1) { throw new ArgumentException(nameof(grayscaleRegion)); } if (GrayscaleRegion.Height < 2) { throw new ArgumentException(nameof(grayscaleRegion)); } WhitePixelRegion = whitePixelRegion ?? throw new ArgumentNullException(nameof(whitePixelRegion)); if (WhitePixelRegion.Width < 1) { throw new ArgumentException(nameof(whitePixelRegion)); } if (WhitePixelRegion.Height < 1) { throw new ArgumentException(nameof(whitePixelRegion)); } GraphicsDevice = device ?? throw new ArgumentNullException(nameof(device)); Transforms = new ListArray <UITransform>(); Transforms.Changed += Transforms_Changed; PreferredSampling = SamplingMode.LinearClamp; Input.TextInput += Input_TextInput; }
internal Font(string id, int lineHeight, int fontBase, ListArray<CharacterSprite> characters) { _id = id; _lineHeight = lineHeight; _base = fontBase; _characterDatum = characters; }
/// <summary> /// 读取数据库数据列表 /// </summary> /// <param name="connection"></param> /// <param name="key">关键字</param> /// <returns>数据列表</returns> private ListArray <valueType> createList(ref DbConnection connection, keyType key) { ListArray <valueType> list = new ListArray <valueType>(counter.SqlTable.Select(ref connection, getWhere(key), counter.MemberMap)); if (list != null) { if (list.Length != 0) { int index = 0, count = list.Length; valueType[] array = list.Array; foreach (valueType value in array) { array[index] = counter.Add(value); if (++index == count) { break; } } } } else { list = new ListArray <valueType>(); } queueCache[key] = list; if (queueCache.Count > maxCount) { foreach (valueType value in queueCache.UnsafePopValue()) { counter.Remove(value); } } return(list); }
public void Visit(ListArray array) { _buffers.Add(CreateBuffer(array.NullBitmapBuffer)); _buffers.Add(CreateBuffer(array.ValueOffsetsBuffer)); array.Values.Accept(this); }
/// <summary> /// 拓扑排序 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <param name="edges">边集合</param> /// <param name="points">无边点集合</param> /// <param name="isDesc">是否反向排序</param> /// <returns>排序结果</returns> public static valueType[] Sort <valueType>(ICollection <KeyValue <valueType, valueType> > edges, HashSet <valueType> points, bool isDesc = false) { if (edges.count() == 0) { return(points.getArray()); } Dictionary <valueType, ListArray <valueType> > graph = DictionaryCreator.CreateAny <valueType, ListArray <valueType> >(); if (points == null) { points = HashSetCreator.CreateAny <valueType>(); } ListArray <valueType> values; foreach (KeyValue <valueType, valueType> edge in edges) { if (!graph.TryGetValue(edge.Key, out values)) { graph.Add(edge.Key, values = new ListArray <valueType>()); } values.Add(edge.Value); points.Add(edge.Value); } LeftArray <valueType> pointList = new LeftArray <valueType>(points.Count); foreach (valueType point in points) { if (!graph.ContainsKey(point)) { pointList.UnsafeAdd(point); } } return(new Sorter <valueType>(graph, ref pointList, isDesc).Sort()); }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getIndex">数组索引获取器</param> /// <param name="arraySize">数组容器大小</param> /// <param name="isRemoveEnd">移除数据并使用最后一个数据移动到当前位置</param> /// <param name="isReset">是否绑定事件并重置数据</param> public ArrayList(Event.Cache <valueType, modelType> cache, Func <valueType, int> getIndex, int arraySize, bool isRemoveEnd, bool isReset) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getIndex == null) { throw new ArgumentNullException("getIndex is null"); } array = new ListArray <valueType> [arraySize]; this.cache = cache; this.getIndex = getIndex; this.isRemoveEnd = isRemoveEnd; if (isReset) { foreach (valueType value in cache.Values) { int index = getIndex(value); ListArray <valueType> list = array[index]; if (list == null) { array[index] = list = new ListArray <valueType>(); } list.Add(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 添加数据 /// </summary> /// <param name="value">数据对象</param> /// <param name="key"></param> private void onInserted(valueType value, keyType key) { targetType target = getValue(key); if (target == null) { cache.SqlTable.Log.add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString()); } else { memberKeyType memberKey = getMemberKey(value); Dictionary <RandomKey <memberKeyType>, ListArray <valueType> > dictionary = getMember(target); ListArray <valueType> list; if (dictionary == null) { setMember(target, dictionary = DictionaryCreator <RandomKey <memberKeyType> > .Create <ListArray <valueType> >()); dictionary.Add(memberKey, list = new ListArray <valueType>()); } else if (!dictionary.TryGetValue(memberKey, out list)) { dictionary.Add(memberKey, list = new ListArray <valueType>()); } list.Add(value); } }
public override IValue Eval(IValue[] parameters) { var mode = this.Validate(parameters); switch (mode) { case Mode.Set: var res = new ListArray() as IArray; foreach (var parameter in parameters) { res = res.Combine(parameter.AsSet); } return(new ArrayValue(res)); case Mode.String: var sb = new StringBuilder(); foreach (var parameter in parameters) { sb.Append(parameter.AsString); } return(new StringValue(sb.ToString())); default: throw new System.NotSupportedException(); } }
/// <summary> /// 删除数据 /// </summary> /// <param name="value">被删除的数据</param> /// <param name="key">被删除的数据关键字</param> protected void onDeleted(valueType value, keyType key) { targetType target = getValue(key); if (target == null) { cache.SqlTable.Log.Debug(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer); } else { ListArray <valueType> list = getMember(target); if (list != null) { int index = Array.LastIndexOf(list.Array.Array, value, list.Array.Length - 1); if (index != -1) { if (isRemoveEnd) { list.Array.TryRemoveAtToEnd(index); } else { list.RemoveAt(index); } return; } } cache.SqlTable.Log.Fatal(typeof(valueType).FullName + " 缓存同步错误", LogLevel.Fatal | LogLevel.AutoCSer); } }
public Enumerator(ListArray <T> list) { _list = list; _index = 0; _version = _list.__version; Current = default; }
/// <summary> /// 添加数据 /// </summary> /// <param name="value">数据对象</param> /// <param name="key"></param> /// <param name="index"></param> private void onInserted(valueType value, keyType key, int index) { targetType target = getValue(key); if (target == null) { cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString()); } else { ListArray <valueType>[] lists = getMember(target); ListArray <valueType> list; if (lists == null) { setMember(target, lists = new ListArray <valueType> [arraySize]); list = null; } else { list = lists[index]; } if (list == null) { lists[index] = list = new ListArray <valueType>(); } list.Add(value); } }
/// <summary> /// 删除数据 /// </summary> /// <param name="value">被删除的数据</param> /// <param name="key">被删除的数据关键字</param> /// <param name="index"></param> protected void onDeleted(valueType value, keyType key, int index) { targetType target = getValue(key); if (target == null) { cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString()); } else { ListArray <valueType>[] lists = getMember(target); if (lists != null) { ListArray <valueType> list = lists[index]; if (list != null) { index = Array.LastIndexOf(list.Array, value, list.Length - 1); if (index != -1) { if (isRemoveEnd) { list.RemoveAtEnd(index); } else { list.RemoveAt(index); } return; } } } cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Fatal, typeof(valueType).FullName + " 缓存同步错误"); } }
public UIContainer(UIManager manager) : base(manager) { _transforms = new ListArray <UITransform>(); Children = new ReadOnlyWrapper <UITransform>(_transforms); IsIntercepting = false; IsDrawable = false; }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Конструктор инициализирует объект класса указанными параметрами /// </summary> /// <param name="name">Имя объекта</param> //--------------------------------------------------------------------------------------------------------- public FinancingEntityManager(String name) : base(name) { mModels = new ListArray <ICubeXModelHierarchyView>(); mModels.IsNotify = true; mEntities = new ListArray <TFinanceItem>(); }
public void GetValuesTest(int[] val, int[] expected) { ListArray la = new ListArray(val); la.GetValues(); Assert.AreEqual(expected, la.GetValues()); }
public void MinIndexTest(int[] array, int expected) { ListArray a = new ListArray(array); int actual = a.MinIndex(); Assert.AreEqual(expected, actual); }
public void AddAllOnIndexTest(int[] arr, int index, int[] val, int[] expected) { ListArray la = new ListArray(arr); la.AddAllOnIndex(index, val); Assert.AreEqual(expected, la.GetValues()); }
public void GetValExceptionTest(int[] arr, int index) { ListArray la = new ListArray(arr); var ex = Assert.Throws <ArgumentException>(() => la.GetVal(index)); Assert.That(ex.Message, Is.EqualTo($"Не верно задан индекс")); }
public void IndexOfTest(int[] arr, int value, int expected) { ListArray la = new ListArray(arr); int actual = la.IndexOf(value); Assert.AreEqual(actual, expected); }
public void ContainsTest(int[] arr, int value, bool expected) { ListArray la = new ListArray(arr); bool actual = la.Contains(value); Assert.AreEqual(actual, expected); }
public void RemoveAllTest(int[] arr, int value, int[] expected) { ListArray la = new ListArray(arr); la.RemoveAll(value); Assert.AreEqual(expected, la.GetValues()); }
public void RemoveAtTest(int[] arr, int index, int[] expected) { ListArray la = new ListArray(arr); la.RemoveAt(index); Assert.AreEqual(expected, la.GetValues()); }
public void GetValTest(int[] val, int index, int expected) { ListArray la = new ListArray(val); int actual = la.GetVal(index); Assert.AreEqual(expected, actual); }
public void ArrayReductionTest(int[] arr, int[] expected) { ListArray la = new ListArray(arr); int[] actual = la.ArrayReduction(); Assert.AreEqual(expected, actual); }
public void SetValTest(int[] val, int index, int value, int expected) { ListArray la = new ListArray(val); la.SetVal(index, value); Assert.AreEqual(expected, la.GetVal(index)); }
//public void GetExceptionTest(int index, int expected) public void SetValExceptionTest(int[] val, int index, int value) { ListArray la = new ListArray(val); var ex = Assert.Throws <ArgumentException>(() => la.SetVal(index, value)); Assert.That(ex.Message, Is.EqualTo($"Не верно задан индекс")); }
public void AddTest(int[] arr, int val, int[] expected) { ListArray la = new ListArray(arr); la.Add(val); Assert.AreEqual(expected, la.GetValues()); }
public void SizeTest(int[] value, int expected) { ListArray la = new ListArray(value); int actual = la.Size(); Assert.AreEqual(actual, expected); }
public void SearchTest(int[] arr, int value, int[] expected) { ListArray la = new ListArray(arr); int[] actual = la.Search(value); Assert.AreEqual(actual, expected); }
[TestMethod] //Поиск существующего элемента public void FindItemTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Add(8); data.Add(6); data.Add(10); data.Find(10); }
[TestMethod] //Поиск не существующего элемента public void FindNotExistItemTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Append(8); data.Append(6); data.Append(10); data.Find(11); }
[TestMethod] //Тест заполнения с использованием Insert public void InsertTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Append(8); data.Append(6); data.Insert(4, 1); }
[TestMethod] //Тест заполнения списка public void AppendTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Append(8); data.Append(6); data.Append(10); }
[TestMethod] //получение первого элемента public void GetFirstItemTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Append(8); data.Append(6); data.Append(10); data.Get(2); }
[TestMethod] //Удаление элемента из списка public void DeleteTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Add(8); data.Add(6); data.Add(10); data.Remove(2); }
[TestMethod] //Добавление элемента в заполненный список public void AppendInFullListTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Add(8); data.Add(6); data.Add(4); data.Add(10); }
/// <summary>Creates an instance of a sprite.</summary> /// <param name="texture">The texture to have this sprite mapped to.</param> /// <param name="textureMappings">The texture mappings for this sprite.</param> public CharacterSprite(Texture texture, int id, int xAdvance, int x, int y, int width, int height, int xOffset, int yOffset) { _texture = texture; _id = id; _xAdvance = xAdvance; _xOffset = xOffset; _yOffset = yOffset; _originalWidth = width; _originalHeight = height; _kearnings = new ListArray<Link2<int, int>>(1); if (_gpuVertexBufferHandle == 0) GenerateVertexBuffer(_verteces); GenerateTextureCoordinateBuffer( new float[] { (x + width) / (float)_texture.Width, y / (float)_texture.Height, x / (float)_texture.Width, y / (float)_texture.Height, (x + width) / (float)_texture.Width, (y + height) / (float)_texture.Height, x / (float)_texture.Width, (y + height) / (float)_texture.Height, (x + width) / (float)_texture.Width, (y + height) / (float)_texture.Height, x / (float)_texture.Width, y / (float)_texture.Height }); }
[TestMethod] //IEnumerable public void EnumerableTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Append(8); data.Append(6); data.Append(10); data.GetEnumerator(); }
[TestMethod] //Удаление несуществующего элемента public void DeleteNotExistItemTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Append(8); data.Append(6); data.Append(10); data.Delete(5); }
private static StaticMeshInstance LoadObj(string staticMeshId, string filePath) { // These are temporarily needed lists for storing the parsed data as you read it. // Its better to use "ListArrays" vs "Lists" because they will be accessed by indeces // by the faces of the obj file. ListArray<float> fileVerteces = new ListArray<float>(10000); ListArray<float> fileNormals = new ListArray<float>(10000); ListArray<float> fileTextureCoordinates = new ListArray<float>(10000); ListArray<int> fileIndeces = new ListArray<int>(10000); // Obj files are not required to include texture coordinates or normals bool hasTextureCoordinates = true; bool hasNormals = true; // Lets read the file and handle each line separately for ".obj" files using (StreamReader reader = new StreamReader(filePath)) { int lineNumber = 1; while (!reader.EndOfStream) { try { string[] parameters = reader.ReadLine().Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); switch (parameters[0]) { // Vertex case "v": fileVerteces.Add(float.Parse(parameters[1], CultureInfo.InvariantCulture)); fileVerteces.Add(float.Parse(parameters[2], CultureInfo.InvariantCulture)); fileVerteces.Add(float.Parse(parameters[3], CultureInfo.InvariantCulture)); break; // Texture Coordinate case "vt": fileTextureCoordinates.Add(float.Parse(parameters[1], CultureInfo.InvariantCulture)); fileTextureCoordinates.Add(float.Parse(parameters[2], CultureInfo.InvariantCulture)); break; // Normal case "vn": fileNormals.Add(float.Parse(parameters[1], CultureInfo.InvariantCulture)); fileNormals.Add(float.Parse(parameters[2], CultureInfo.InvariantCulture)); fileNormals.Add(float.Parse(parameters[3], CultureInfo.InvariantCulture)); break; // Face case "f": //if (parameters.Length < 4) // throw new StaticModelManagerException("obj file corrupt."); int first = fileIndeces.Count; for (int i = 1; i < parameters.Length; i++) { if (i > 3) { // Triangulate using the previous two verteces // NOTE: THIS MAY BE INCORRECT! I COULD NOT YET FIND DOCUMENTATION // ON THE TRIANGULATION DONE BY BLENDER (WORKS FOR QUADS AT LEAST) //// Last two (triangle strip) //fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); //fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); //fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); //fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); //fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); //fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); // First then previous (triangle fan) fileIndeces.Add(fileIndeces[first]); fileIndeces.Add(fileIndeces[first + 1]); fileIndeces.Add(fileIndeces[first + 2]); fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); fileIndeces.Add(fileIndeces[fileIndeces.Count - 6]); } // Now include the new vertex string[] indexReferences = parameters[i].Split('/'); //if (indexReferences[0] == "") // throw new StaticModelManagerException("ERROR: obj file corrupted (missing vertex possition):" + filePath); fileIndeces.Add(int.Parse(indexReferences[0], CultureInfo.InvariantCulture)); if (hasNormals && indexReferences.Length < 3) hasNormals = false; if (hasTextureCoordinates && (indexReferences.Length < 2 || indexReferences[1] == "")) hasTextureCoordinates = false; if (hasTextureCoordinates && indexReferences[1] != "") fileIndeces.Add(int.Parse(indexReferences[1], CultureInfo.InvariantCulture)); else fileIndeces.Add(0); if (hasNormals && indexReferences[2] != "") fileIndeces.Add(int.Parse(indexReferences[2], CultureInfo.InvariantCulture)); else fileIndeces.Add(0); } break; } } catch { string[] pathSplit = filePath.Split('\\'); throw new StaticModelManagerException("Could not load model " + pathSplit[pathSplit.Length - 1] + ". There is a corruption on line " + lineNumber +"."); } lineNumber++; } } // Pull the final vertex order out of the indexed references // Note, arrays start at 0 but the index references start at 1 float[] verteces = new float[fileIndeces.Count]; for (int i = 0; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 3; verteces[i] = fileVerteces[index]; verteces[i + 1] = fileVerteces[index + 1]; verteces[i + 2] = fileVerteces[index + 2]; } float[] textureCoordinates = null; if (hasTextureCoordinates) { // Pull the final texture coordinates order out of the indexed references // Note, arrays start at 0 but the index references start at 1 // Note, every other value needs to be inverse (not sure why but it works :P) textureCoordinates = new float[fileIndeces.Count / 3 * 2]; for (int i = 1; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 2; int offset = (i - 1) / 3; textureCoordinates[i - 1 - offset] = fileTextureCoordinates[index]; textureCoordinates[i - offset] = 1 - fileTextureCoordinates[(index + 1)]; } } float[] normals = null; if (hasNormals) { // Pull the final normal order out of the indexed references // Note, arrays start at 0 but the index references start at 1 normals = new float[fileIndeces.Count]; for (int i = 2; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 3; normals[i - 2] = fileNormals[index]; normals[i - 1] = fileNormals[(index + 1)]; normals[i] = fileNormals[(index + 2)]; } } int vertexBufferId; if (verteces != null) { // Make the vertex buffer on the GPU GL.GenBuffers(1, out vertexBufferId); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferId); GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(verteces.Length * sizeof(float)), verteces, BufferUsageHint.StaticDraw); int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (verteces.Length * sizeof(float) != bufferSize) throw new StaticModelManagerException("Vertex array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { vertexBufferId = 0; } int textureCoordinateBufferId; if (hasTextureCoordinates && textureCoordinates != null) { // Make the texture coordinate buffer on the GPU GL.GenBuffers(1, out textureCoordinateBufferId); GL.BindBuffer(BufferTarget.ArrayBuffer, textureCoordinateBufferId); GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(textureCoordinates.Length * sizeof(float)), textureCoordinates, BufferUsageHint.StaticDraw); int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (textureCoordinates.Length * sizeof(float) != bufferSize) throw new StaticModelManagerException("TexCoord array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { textureCoordinateBufferId = 0; } int normalBufferId; if (hasNormals && normals != null) { // Make the normal buffer on the GPU GL.GenBuffers(1, out normalBufferId); GL.BindBuffer(BufferTarget.ArrayBuffer, normalBufferId); GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(normals.Length * sizeof(float)), normals, BufferUsageHint.StaticDraw); int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (normals.Length * sizeof(float) != bufferSize) throw new StaticModelManagerException("Normal array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { normalBufferId = 0; } return new StaticMeshInstance( filePath, staticMeshId, vertexBufferId, 0, // Obj files don't support vertex colors textureCoordinateBufferId, normalBufferId, 0, // I don't support an index buffer at this time verteces.Length); }
private void GenerateUnits() { _powerRangerCount = _rangedCount + _meleeCount + _kamakaziCount; _tuxCount = _rangedCount + _meleeCount + _kamakaziCount; _octree = new OctreeLinked<Unit, string>(0, 0, 0, 1000000, 10, Unit.CompareTo, Unit.CompareTo); lines = new AvlTreeLinked<Link3<Vector, Vector, Color>>( (Link3<Vector, Vector, Color> link, Link3<Vector, Vector, Color> link2) => { if (link.First == link2.First && link.Second == link2.Second) return 0; else return 1; } ); explosions = new ListArray<Explosion>(1); _zackMelee = new Unit[_meleeCount]; _zackRanged = new Unit[_rangedCount]; _zackKamakazi = new Unit[_kamakaziCount]; _killemMelee = new Unit[_meleeCount]; _killemRanged = new Unit[_rangedCount]; _killemKamakazi = new Unit[_kamakaziCount]; Random random = new Random(); string[] colors = new string[] { "YellowRanger", "RedRanger", "BlueRanger", "BlackRanger", "PinkRanger" }; #region Map 0 if (_map == 0) { int maxXZack = -1500; int minXZack = -2000; int maxZZack = 0; int minZZack = -1500; int maxXKillem = 2000; int minXKillem = 1500; int maxZKillem = 0; int minZKillem = -1500; for (int i = 0; i < _meleeCount; i++) { _zackMelee[i] = new ZackMelee("ZackMelee" + i, StaticModelManager.GetModel("BlackRanger")); _zackMelee[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackMelee[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackMelee[i].StaticModel.Scale = new Vector(5, 5, 5); _zackMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackMelee[i]); _killemMelee[i] = new KillemMelee("KillemMelee" + i, StaticModelManager.GetModel("Tux")); _killemMelee[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemMelee[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemMelee[i].StaticModel.Scale = new Vector(20, 20, 20); _killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemMelee[i]); } for (int i = 0; i < _rangedCount; i++) { _zackRanged[i] = new ZackRanged("ZackRanged" + i, StaticModelManager.GetModel("BlueRanger")); _zackRanged[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackRanged[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackRanged[i].StaticModel.Scale = new Vector(5, 5, 5); _zackRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackRanged[i]); _killemRanged[i] = new KillemRanged("KillemRanged" + i, StaticModelManager.GetModel("TuxGreen")); _killemRanged[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemRanged[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemRanged[i].StaticModel.Scale = new Vector(20, 20, 20); _killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _killemRanged[i].Id = "Ranger" + i; _octree.Add(_killemRanged[i]); } for (int i = 0; i < _kamakaziCount; i++) { _zackKamakazi[i] = new ZackKamakazi("ZackKamakazi" + i, StaticModelManager.GetModel("RedRanger")); _zackKamakazi[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackKamakazi[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackKamakazi[i].StaticModel.Scale = new Vector(5, 5, 5); _zackKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackKamakazi[i]); _killemKamakazi[i] = new KillemKamakazi("KillemKamakazi" + i, StaticModelManager.GetModel("TuxRed")); _killemKamakazi[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemKamakazi[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemKamakazi[i].StaticModel.Scale = new Vector(20, 20, 20); _killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemKamakazi[i]); } } #endregion #region Map 1 else if (_map == 1) { int maxXZack = -800; int minXZack = -1300; int maxZZack = -800; int minZZack = -1300; int maxXZack2 = 1300; int minXZack2 = 800; int maxZZack2 = 1300; int minZZack2 = 800; int maxXKillem = -800; int minXKillem = -1300; int maxZKillem = 1300; int minZKillem = 800; int maxXKillem2 = 1300; int minXKillem2 = 800; int maxZKillem2 = -800; int minZKillem2 = -1300; for (int i = 0; i < _meleeCount; i++) { if (i < _meleeCount / 2) { _zackMelee[i] = new ZackMelee("ZackMelee" + i, StaticModelManager.GetModel("BlackRanger")); _zackMelee[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackMelee[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackMelee[i].StaticModel.Scale = new Vector(5, 5, 5); _zackMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackMelee[i]); _killemMelee[i] = new KillemMelee("KillemMelee" + i, StaticModelManager.GetModel("Tux")); _killemMelee[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemMelee[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemMelee[i].StaticModel.Scale = new Vector(20, 20, 20); _killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemMelee[i]); } else { _zackMelee[i] = new ZackMelee("ZackMelee" + i, StaticModelManager.GetModel("BlackRanger")); _zackMelee[i].StaticModel.Position.X = random.Next(minXZack2, maxXZack2); if (_3d) _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackMelee[i].StaticModel.Position.Z = random.Next(minZZack2, maxZZack2); _zackMelee[i].StaticModel.Scale = new Vector(5, 5, 5); _zackMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackMelee[i]); _killemMelee[i] = new KillemMelee("KillemMelee" + i, StaticModelManager.GetModel("Tux")); _killemMelee[i].StaticModel.Position.X = random.Next(minXKillem2, maxXKillem2); if (_3d) _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemMelee[i].StaticModel.Position.Z = random.Next(minZKillem2, maxZKillem2); _killemMelee[i].StaticModel.Scale = new Vector(20, 20, 20); _killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemMelee[i]); } } for (int i = 0; i < _rangedCount; i++) { if (i < _rangedCount / 2) { _zackRanged[i] = new ZackRanged("ZackRanged" + i, StaticModelManager.GetModel("BlueRanger")); _zackRanged[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackRanged[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackRanged[i].StaticModel.Scale = new Vector(5, 5, 5); _zackRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackRanged[i]); _killemRanged[i] = new KillemRanged("KillemRanged" + i, StaticModelManager.GetModel("TuxGreen")); _killemRanged[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemRanged[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemRanged[i].StaticModel.Scale = new Vector(20, 20, 20); _killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _killemRanged[i].Id = "Ranger" + i; _octree.Add(_killemRanged[i]); } else { _zackRanged[i] = new ZackRanged("ZackRanged" + i, StaticModelManager.GetModel("BlueRanger")); _zackRanged[i].StaticModel.Position.X = random.Next(minXZack2, maxXZack2); if (_3d) _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackRanged[i].StaticModel.Position.Z = random.Next(minZZack2, maxZZack2); _zackRanged[i].StaticModel.Scale = new Vector(5, 5, 5); _zackRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackRanged[i]); _killemRanged[i] = new KillemRanged("KillemRanged" + i, StaticModelManager.GetModel("TuxGreen")); _killemRanged[i].StaticModel.Position.X = random.Next(minXKillem2, maxXKillem2); if (_3d) _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemRanged[i].StaticModel.Position.Z = random.Next(minZKillem2, maxZKillem2); _killemRanged[i].StaticModel.Scale = new Vector(20, 20, 20); _killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _killemRanged[i].Id = "Ranger" + i; _octree.Add(_killemRanged[i]); } } for (int i = 0; i < _kamakaziCount; i++) { if (i < _kamakaziCount / 2) { _zackKamakazi[i] = new ZackKamakazi("ZackKamakazi" + i, StaticModelManager.GetModel("RedRanger")); _zackKamakazi[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackKamakazi[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackKamakazi[i].StaticModel.Scale = new Vector(5, 5, 5); _zackKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackKamakazi[i]); _killemKamakazi[i] = new KillemKamakazi("KillemKamakazi" + i, StaticModelManager.GetModel("TuxRed")); _killemKamakazi[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemKamakazi[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemKamakazi[i].StaticModel.Scale = new Vector(20, 20, 20); _killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemKamakazi[i]); } else { _zackKamakazi[i] = new ZackKamakazi("ZackKamakazi" + i, StaticModelManager.GetModel("RedRanger")); _zackKamakazi[i].StaticModel.Position.X = random.Next(minXZack2, maxXZack2); if (_3d) _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackKamakazi[i].StaticModel.Position.Z = random.Next(minZZack2, maxZZack2); _zackKamakazi[i].StaticModel.Scale = new Vector(5, 5, 5); _zackKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackKamakazi[i]); _killemKamakazi[i] = new KillemKamakazi("KillemKamakazi" + i, StaticModelManager.GetModel("TuxRed")); _killemKamakazi[i].StaticModel.Position.X = random.Next(minXKillem2, maxXKillem2); if (_3d) _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemKamakazi[i].StaticModel.Position.Z = random.Next(minZKillem2, maxZKillem2); _killemKamakazi[i].StaticModel.Scale = new Vector(20, 20, 20); _killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemKamakazi[i]); } } } #endregion #region Map 2 if (_map == 2) { int maxXZack = 250; int minXZack = -250; int maxZZack = 250; int minZZack = -250; int maxXKillem = 250; int minXKillem = -250; int maxZKillem = 250; int minZKillem = -250; for (int i = 0; i < _meleeCount; i++) { _zackMelee[i] = new ZackMelee("ZackMelee" + i, StaticModelManager.GetModel("BlackRanger")); _zackMelee[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackMelee[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackMelee[i].StaticModel.Scale = new Vector(5, 5, 5); _zackMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackMelee[i]); _killemMelee[i] = new KillemMelee("KillemMelee" + i, StaticModelManager.GetModel("Tux")); _killemMelee[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemMelee[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemMelee[i].StaticModel.Scale = new Vector(20, 20, 20); _killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemMelee[i]); } for (int i = 0; i < _rangedCount; i++) { _zackRanged[i] = new ZackRanged("ZackRanged" + i, StaticModelManager.GetModel("BlueRanger")); _zackRanged[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackRanged[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackRanged[i].StaticModel.Scale = new Vector(5, 5, 5); _zackRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackRanged[i]); _killemRanged[i] = new KillemRanged("KillemRanged" + i, StaticModelManager.GetModel("TuxGreen")); _killemRanged[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemRanged[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemRanged[i].StaticModel.Scale = new Vector(20, 20, 20); _killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _killemRanged[i].Id = "Ranger" + i; _octree.Add(_killemRanged[i]); } // CIRCLE: radius ^ 2 = x ^ 2 + z ^ 2 float radiusSquared = 1000000f; for (int i = 0; i < _kamakaziCount; i++) { float x = random.Next(-1000, 1000); _zackKamakazi[i] = new ZackKamakazi("ZackKamakazi" + i, StaticModelManager.GetModel("RedRanger")); _zackKamakazi[i].StaticModel.Position.X = x; if (_3d) _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackKamakazi[i].StaticModel.Position.Z = Calc.SquareRoot(radiusSquared - x * x); _zackKamakazi[i].StaticModel.Scale = new Vector(5, 5, 5); _zackKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackKamakazi[i]); _killemKamakazi[i] = new KillemKamakazi("KillemKamakazi" + i, StaticModelManager.GetModel("TuxRed")); _killemKamakazi[i].StaticModel.Position.X = x; if (_3d) _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemKamakazi[i].StaticModel.Position.Z = -Calc.SquareRoot(radiusSquared - x * x); _killemKamakazi[i].StaticModel.Scale = new Vector(20, 20, 20); _killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemKamakazi[i]); } } #endregion #region Map 3 if (_map == 3) { int maxXZack = 2000; int minXZack = -2000; int maxZZack = 2000; int minZZack = -2000; int maxXKillem = 2000; int minXKillem = -2000; int maxZKillem = 2000; int minZKillem = -2000; for (int i = 0; i < _meleeCount; i++) { _zackMelee[i] = new ZackMelee("ZackMelee" + i, StaticModelManager.GetModel("BlackRanger")); _zackMelee[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackMelee[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackMelee[i].StaticModel.Scale = new Vector(5, 5, 5); _zackMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackMelee[i]); _killemMelee[i] = new KillemMelee("KillemMelee" + i, StaticModelManager.GetModel("Tux")); _killemMelee[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemMelee[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemMelee[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemMelee[i].StaticModel.Scale = new Vector(20, 20, 20); _killemMelee[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemMelee[i]); } for (int i = 0; i < _rangedCount; i++) { _zackRanged[i] = new ZackRanged("ZackRanged" + i, StaticModelManager.GetModel("BlueRanger")); _zackRanged[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackRanged[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackRanged[i].StaticModel.Scale = new Vector(5, 5, 5); _zackRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackRanged[i]); _killemRanged[i] = new KillemRanged("KillemRanged" + i, StaticModelManager.GetModel("TuxGreen")); _killemRanged[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemRanged[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemRanged[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemRanged[i].StaticModel.Scale = new Vector(20, 20, 20); _killemRanged[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _killemRanged[i].Id = "Ranger" + i; _octree.Add(_killemRanged[i]); } for (int i = 0; i < _kamakaziCount; i++) { _zackKamakazi[i] = new ZackKamakazi("ZackKamakazi" + i, StaticModelManager.GetModel("RedRanger")); _zackKamakazi[i].StaticModel.Position.X = random.Next(minXZack, maxXZack); if (_3d) _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _zackKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _zackKamakazi[i].StaticModel.Position.Z = random.Next(minZZack, maxZZack); _zackKamakazi[i].StaticModel.Scale = new Vector(5, 5, 5); _zackKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, 0); _octree.Add(_zackKamakazi[i]); _killemKamakazi[i] = new KillemKamakazi("KillemKamakazi" + i, StaticModelManager.GetModel("TuxRed")); _killemKamakazi[i].StaticModel.Position.X = random.Next(minXKillem, maxXKillem); if (_3d) _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10 + random.Next(0, 1000); else _killemKamakazi[i].StaticModel.Position.Y = _terrain.Position.Y + 10; _killemKamakazi[i].StaticModel.Position.Z = random.Next(minZKillem, maxZKillem); _killemKamakazi[i].StaticModel.Scale = new Vector(20, 20, 20); _killemKamakazi[i].StaticModel.Orientation = new Quaternion(0, 1, 0, -Calc.PiOverTwo); _octree.Add(_killemKamakazi[i]); } } #endregion }
public static void LoadFontFile(string id, string filePath, string textureLocations) { ListArray<CharacterSprite> characters = new ListArray<CharacterSprite>(255); ListArray<string> textures = new ListArray<string>(1); int lineHeight = -1, fontBase = int.MinValue; using (StreamReader reader = new StreamReader(filePath)) { int lineNumber = 1; while (!reader.EndOfStream) { string line = reader.ReadLine(); string[] parameters = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); switch (parameters[0].ToLower()) { case "common": for (int i = 1; i < parameters.Length; i++) { string[] attributes = parameters[i].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); switch (attributes[0].ToLower()) { case "lineheight": if (!int.TryParse(attributes[1], out lineHeight)) throw new TextManagerException("The line height value of the font file is corrupt on line " + lineNumber + "."); break; case "base": if (!int.TryParse(attributes[1], out fontBase)) throw new TextManagerException("The base value of the font file is corrupt on line " + lineNumber + "."); break; } } break; case "page": string[] textureFile = parameters[2].Split("\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); try { TextureManager.LoadTexture(textureFile[1], textureLocations + textureFile[1]); } catch { throw new TextManagerException("The font file is using a non-supported image file on line " + lineNumber + "."); } textures.Add(textureFile[1]); break; case "char": int charId = -1, x = -1, y = -1, width = -1, height = -1, xOffset = int.MinValue, yOffset = int.MinValue, xAdvance = -1, page = -1; // channel=-1; // Lets get all the attributes of the character for (int i = 1; i < parameters.Length; i++) { string[] attribute = parameters[i].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (attribute.Length < 2) throw new TextManagerException("Font file has a corrupted character attribute on line " + lineNumber + "."); switch (attribute[0].ToLower()) { case "id": if (!int.TryParse(attribute[1], out charId)) throw new TextManagerException("An id value in font file is corrupted on line " + lineNumber + "."); break; case "x": if (!int.TryParse(attribute[1], out x)) throw new TextManagerException("A x value in font file is corrupted on line " + lineNumber + "."); break; case "y": if (!int.TryParse(attribute[1], out y)) throw new TextManagerException("A y value in font file is corrupted on line " + lineNumber + "."); break; case "width": if (!int.TryParse(attribute[1], out width)) throw new TextManagerException("A width value in font file is corrupted on line " + lineNumber + "."); break; case "height": if (!int.TryParse(attribute[1], out height)) throw new TextManagerException("A height value in font file is corrupted on line " + lineNumber + "."); break; case "xoffset": if (!int.TryParse(attribute[1], out xOffset)) throw new TextManagerException("A xoffset value in font file is corrupted on line " + lineNumber + "."); break; case "yoffset": if (!int.TryParse(attribute[1], out yOffset)) throw new TextManagerException("A yoffset value in font file is corrupted on line " + lineNumber + "."); break; case "xadvance": if (!int.TryParse(attribute[1], out xAdvance)) throw new TextManagerException("A xadvance value in font file is corrupted on line " + lineNumber + "."); break; case "page": if (!int.TryParse(attribute[1], out page)) throw new TextManagerException("A page value in font file is corrupted on line " + lineNumber + "."); break; //// This check is most likely unnecessary, an error will be thrown during image loading attempt. //case "chnl": // if (!int.TryParse(attribute[1], out channel)) // throw new TextManagerException("A chnl value in font file is corrupted on line " + lineNumber + "."); // if (channel != 15) // throw new TextManagerException("The font file is using a non-supported image file."); } } // Make sure all the necessary values were imported and are valid if (charId == -1) throw new TextManagerException("Font file is corrupt/missing on a char id on line " + lineNumber + "."); if (x < 0) throw new TextManagerException("Font file has corrupt/missing on x value on line " + lineNumber + "."); if (y < 0) throw new TextManagerException("Font file has a corrupt/missing y value on line " + lineNumber + "."); if (width < 0) throw new TextManagerException("Font file has a corrupt/missing width value on line " + lineNumber + "."); if (height == -1) throw new TextManagerException("Font file has a corrupt/missing height value on line " + lineNumber + "."); if (xOffset == int.MinValue) throw new TextManagerException("Font file is missing a xoffset value on line " + lineNumber + "."); if (yOffset == int.MinValue) throw new TextManagerException("Font file is missing a yoffset value on line " + lineNumber + "."); if (xAdvance < 0) throw new TextManagerException("Font file has a corrupt/missing xadvance value on line " + lineNumber + "."); if (page < 0 || page > textures.Count) throw new TextManagerException("Font file has a corrupt/missing page value on line " + lineNumber + "."); //// This check is most likely unnecessary, an error will be thrown during image loading attempt. //if (channel == -1) // throw new TextManagerException("Font file is missing a channel value on line " + lineNumber + "."); characters.Add( new CharacterSprite( TextureManager.Get(textures[page]), charId, xAdvance, x, y, width, height, xOffset, yOffset)); break; #region OLD CODE (I'll delete this when I'm done debugging the newer version) // THIS WAS MY INITIAL PARSER JUST TO GET THINGS WORKING // characters.Add(new CharacterSprite( // // Texture // TextureManager.Get(textures[int.Parse(parameters[9].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture)]), // // Id // int.Parse(parameters[1].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // X Advance // int.Parse(parameters[8].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // X // int.Parse(parameters[2].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // Y // int.Parse(parameters[3].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // Width // int.Parse(parameters[4].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // Height // int.Parse(parameters[5].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // X Offset // int.Parse(parameters[6].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // // Y Offset // int.Parse(parameters[7].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture))); // break; //case "kerning": // int first = int.Parse(parameters[1].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture); // for (int i = 0; i < characters.Count; i++) // if (characters[i].Id == first) // characters[i].AddKearning( // int.Parse(parameters[2].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture), // int.Parse(parameters[3].Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1], CultureInfo.InvariantCulture)); // break; #endregion } lineNumber++; } } if (lineHeight < 0) throw new TextManagerException("Font file has a corrupt/missing line height value."); _fontDatabase.Add(new Font(id, lineHeight, fontBase, characters)); string[] pathSplit = filePath.Split('\\'); Output.WriteLine("Font file loaded: \"" + pathSplit[pathSplit.Length - 1] + "\"."); }
[TestMethod] //IDisposable public void DisposeTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Add(8); data.Add(6); data.Add(10); data.Dispose(); }
private static StaticMesh LoadObj(string staticMeshId, string filePath) { // These are temporarily needed lists for storing the parsed data as you read it. // Its better to use "ListArrays" vs "Lists" because they will be accessed by indeces // by the faces of the obj file. ListArray<float> fileVerteces = new ListArray<float>(10000); ListArray<float> fileNormals = new ListArray<float>(10000); ListArray<float> fileTextureCoordinates = new ListArray<float>(10000); ListArray<int> fileIndeces = new ListArray<int>(10000); // Lets read the file and handle each line separately for ".obj" files using (StreamReader reader = new StreamReader(filePath)) { while (!reader.EndOfStream) { string[] parameters = reader.ReadLine().Trim().Split(' '); switch (parameters[0]) { // Vertex case "v": fileVerteces.Add(float.Parse(parameters[1])); fileVerteces.Add(float.Parse(parameters[2])); fileVerteces.Add(float.Parse(parameters[3])); break; // Texture Coordinate case "vt": fileTextureCoordinates.Add(float.Parse(parameters[1])); fileTextureCoordinates.Add(float.Parse(parameters[2])); break; // Normal case "vn": fileNormals.Add(float.Parse(parameters[1])); fileNormals.Add(float.Parse(parameters[2])); fileNormals.Add(float.Parse(parameters[3])); break; // Face case "f": // NOTE! This does not yet triangulate faces // NOTE! This needs all possible values (position, texture mapping, and normal). for (int i = 1; i < parameters.Length; i++) { string[] indexReferences = parameters[i].Split('/'); fileIndeces.Add(int.Parse(indexReferences[0])); if (indexReferences[1] != "") fileIndeces.Add(int.Parse(indexReferences[1])); else fileIndeces.Add(0); if (indexReferences[2] != "") fileIndeces.Add(int.Parse(indexReferences[2])); else fileIndeces.Add(0); } break; } } } // Pull the final vertex order out of the indexed references // Note, arrays start at 0 but the index references start at 1 float[] verteces = new float[fileIndeces.Count]; for (int i = 0; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 3; verteces[i] = fileVerteces[index]; verteces[i + 1] = fileVerteces[index + 1]; verteces[i + 2] = fileVerteces[index + 2]; } // Pull the final texture coordinates order out of the indexed references // Note, arrays start at 0 but the index references start at 1 // Note, every other value needs to be inverse (not sure why but it works :P) float[] textureCoordinates = new float[fileIndeces.Count / 3 * 2]; for (int i = 1; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 2; int offset = (i - 1) / 3; textureCoordinates[i - 1 - offset] = fileTextureCoordinates[index]; textureCoordinates[i - offset] = 1 - fileTextureCoordinates[(index + 1)]; } // Pull the final normal order out of the indexed references // Note, arrays start at 0 but the index references start at 1 float[] normals = new float[fileIndeces.Count]; for (int i = 2; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 3; normals[i - 2] = fileNormals[index]; normals[i - 1] = fileNormals[(index + 1)]; normals[i] = fileNormals[(index + 2)]; } int vertexBufferId; if (verteces != null) { // Declare the buffer GL.GenBuffers(1, out vertexBufferId); // Select the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferId); // Initialize the buffer values GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(verteces.Length * sizeof(float)), verteces, BufferUsageHint.StaticDraw); // Quick error checking int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (verteces.Length * sizeof(float) != bufferSize) throw new ApplicationException("Vertex array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { vertexBufferId = 0; } int textureCoordinateBufferId; if (textureCoordinates != null) { // Declare the buffer GL.GenBuffers(1, out textureCoordinateBufferId); // Select the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, textureCoordinateBufferId); // Initialize the buffer values GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(textureCoordinates.Length * sizeof(float)), textureCoordinates, BufferUsageHint.StaticDraw); // Quick error checking int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (textureCoordinates.Length * sizeof(float) != bufferSize) throw new ApplicationException("TexCoord array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { textureCoordinateBufferId = 0; } int normalBufferId; if (normals != null) { // Declare the buffer GL.GenBuffers(1, out normalBufferId); // Select the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, normalBufferId); // Initialize the buffer values GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(normals.Length * sizeof(float)), normals, BufferUsageHint.StaticDraw); // Quick error checking int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (normals.Length * sizeof(float) != bufferSize) throw new ApplicationException("Normal array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { normalBufferId = 0; } return new StaticMesh( filePath, staticMeshId, vertexBufferId, 0, // Obj files don't support vertex colors textureCoordinateBufferId, normalBufferId, 0, // I don't support an index buffer at this time verteces.Length); }
/// <summary> /// Creates a result value set of the size specified /// </summary> /// <returns>A Value set of the correct size.</returns> public static TimeSpaceValueSet<double> CreateResultValueSet(int numtimes, int numElements) { ListArray<double> outValues = new ListArray<double>(numtimes); for (int i = 0; i < numtimes; i++) { outValues.Add(new double[numElements]); } return new TimeSpaceValueSet<double>(outValues); }
[TestMethod] //Поиск в пустом списке public void FindInEmptyListTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Find(11); }
/// <summary>DONT USE THIS FUNCTION!!! This is an experimental file type I may use in the future.</summary> public static StaticModel LoadSevenModelFromDisk(string staticModelId, string filePath) { // These are temporarily needed lists for storing the parsed data as you read it. ListArray<float> fileVerteces = new ListArray<float>(1000); ListArray<float> fileNormals = new ListArray<float>(1000); ListArray<float> fileTextureCoordinates = new ListArray<float>(1000); ListArray<int> fileIndeces = new ListArray<int>(1000); Texture texture = null; string meshName = "defaultMeshName"; AvlTreeLinked<StaticMesh, string> meshes = new AvlTreeLinked<StaticMesh, string> ( (StaticMesh left, StaticMesh right) => { return left.Id.CompareTo(right.Id); }, (StaticMesh left, string right) => { return left.Id.CompareTo(right); } ); // Lets read the file and handle each line separately for ".obj" files using (StreamReader reader = new StreamReader(filePath)) { while (!reader.EndOfStream) { string[] parameters = reader.ReadLine().Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); switch (parameters[0]) { // MeshName case "m": meshName = parameters[1]; break; // Texture case "t": if (!TextureManager.TextureExists(parameters[1])) TextureManager.LoadTexture(parameters[1], parameters[2]); texture = TextureManager.Get(parameters[1]); break; // Vertex case "v": fileVerteces.Add(float.Parse(parameters[1], CultureInfo.InvariantCulture)); fileVerteces.Add(float.Parse(parameters[2], CultureInfo.InvariantCulture)); fileVerteces.Add(float.Parse(parameters[3], CultureInfo.InvariantCulture)); break; // Texture Coordinate case "vt": fileTextureCoordinates.Add(float.Parse(parameters[1], CultureInfo.InvariantCulture)); fileTextureCoordinates.Add(float.Parse(parameters[2], CultureInfo.InvariantCulture)); break; // Normal case "vn": fileNormals.Add(float.Parse(parameters[1], CultureInfo.InvariantCulture)); fileNormals.Add(float.Parse(parameters[2], CultureInfo.InvariantCulture)); fileNormals.Add(float.Parse(parameters[3], CultureInfo.InvariantCulture)); break; // Face case "f": // DEVELOPMENT NOTE: The following triangulation algorithm works, but it // could be optimized beyond its current state. // The following variables are used for triangulation of a polygon // with greater than three verteces. int firstPosition, firstTextureCoordinates, firstNormal, secondPosition, secondTextureCoordinates, secondNormal; if (parameters.Length > 3) { // First Vertex (we have to store it this way for possible triangulation) string[] indexReferences = parameters[1].Split('/'); if (indexReferences[0] == "") throw new StaticModelManagerException("ERROR: obj file corrupted (missing vertex possition): " + filePath); firstPosition = int.Parse(indexReferences[0], CultureInfo.InvariantCulture); if (indexReferences[1] != "") firstTextureCoordinates = int.Parse(indexReferences[1], CultureInfo.InvariantCulture); else firstTextureCoordinates = 0; if (indexReferences[2] != "") firstNormal = int.Parse(indexReferences[2], CultureInfo.InvariantCulture); else firstNormal = 0; // Second Vertex (we have to store it this way for possible triangulation) indexReferences = parameters[2].Split('/'); if (indexReferences[0] == "") throw new StaticModelManagerException("ERROR: obj file corrupted (missing vertex possition): " + filePath); secondPosition = int.Parse(indexReferences[0], CultureInfo.InvariantCulture); if (indexReferences[1] != "") secondTextureCoordinates = int.Parse(indexReferences[1], CultureInfo.InvariantCulture); else secondTextureCoordinates = 0; if (indexReferences[2] != "") secondNormal = int.Parse(indexReferences[2], CultureInfo.InvariantCulture); else secondNormal = 0; } else throw new StaticModelManagerException("ERROR: obj file corrupted:" + filePath); // Verteces past the first two for (int i = 3; i < parameters.Length; i++) { // Triangulate using the first two verteces fileIndeces.Add(firstPosition); fileIndeces.Add(firstTextureCoordinates); fileIndeces.Add(firstNormal); fileIndeces.Add(secondPosition); fileIndeces.Add(secondTextureCoordinates); fileIndeces.Add(secondNormal); // Now include the new vertex string[] indexReferences = parameters[i].Split('/'); if (indexReferences[0] == "") throw new StaticModelManagerException("ERROR: obj file corrupted (missing vertex possition): " + filePath); fileIndeces.Add(int.Parse(indexReferences[0], CultureInfo.InvariantCulture)); if (indexReferences[1] != "") fileIndeces.Add(int.Parse(indexReferences[1], CultureInfo.InvariantCulture)); else fileIndeces.Add(0); if (indexReferences[2] != "") fileIndeces.Add(int.Parse(indexReferences[2], CultureInfo.InvariantCulture)); else fileIndeces.Add(0); } break; //// OLD VERSION OF THE FACE PARSING //// NOTE! This does not yet triangulate faces //// NOTE! This needs all possible values (position, texture mapping, and normal). //for (int i = 1; i < parameters.Length; i++) //{ // string[] indexReferences = parameters[i].Split('/'); // fileIndeces.Add(int.Parse(indexReferences[0], CultureInfo.InvariantCulture)); // if (indexReferences[1] != "") // fileIndeces.Add(int.Parse(indexReferences[1], CultureInfo.InvariantCulture)); // else // fileIndeces.Add(0); // if (indexReferences[2] != "") // fileIndeces.Add(int.Parse(indexReferences[2], CultureInfo.InvariantCulture)); // else // fileIndeces.Add(0); //} //break; // End Current Mesh case "7": // Pull the final vertex order out of the indexed references // Note, arrays start at 0 but the index references start at 1 float[] verteces = new float[fileIndeces.Count]; for (int i = 0; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 3; verteces[i] = fileVerteces[index]; verteces[i + 1] = fileVerteces[index + 1]; verteces[i + 2] = fileVerteces[index + 2]; } // Pull the final texture coordinates order out of the indexed references // Note, arrays start at 0 but the index references start at 1 // Note, every other value needs to be inverse (not sure why but it works :P) float[] textureCoordinates = new float[fileIndeces.Count / 3 * 2]; for (int i = 1; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 2; int offset = (i - 1) / 3; textureCoordinates[i - 1 - offset] = fileTextureCoordinates[index]; textureCoordinates[i - offset] = 1 - fileTextureCoordinates[(index + 1)]; } // Pull the final normal order out of the indexed references // Note, arrays start at 0 but the index references start at 1 float[] normals = new float[fileIndeces.Count]; for (int i = 2; i < fileIndeces.Count; i += 3) { int index = (fileIndeces[i] - 1) * 3; normals[i - 2] = fileNormals[index]; normals[i - 1] = fileNormals[(index + 1)]; normals[i] = fileNormals[(index + 2)]; } int vertexBufferId; if (verteces != null) { // Declare the buffer GL.GenBuffers(1, out vertexBufferId); // Select the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferId); // Initialize the buffer values GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(verteces.Length * sizeof(float)), verteces, BufferUsageHint.StaticDraw); // Quick error checking int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (verteces.Length * sizeof(float) != bufferSize) throw new StaticModelManagerException("Vertex array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { vertexBufferId = 0; } int textureCoordinateBufferId; if (textureCoordinates != null) { // Declare the buffer GL.GenBuffers(1, out textureCoordinateBufferId); // Select the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, textureCoordinateBufferId); // Initialize the buffer values GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(textureCoordinates.Length * sizeof(float)), textureCoordinates, BufferUsageHint.StaticDraw); // Quick error checking int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (textureCoordinates.Length * sizeof(float) != bufferSize) throw new StaticModelManagerException("TexCoord array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { textureCoordinateBufferId = 0; } int normalBufferId; if (normals != null) { // Declare the buffer GL.GenBuffers(1, out normalBufferId); // Select the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, normalBufferId); // Initialize the buffer values GL.BufferData<float>(BufferTarget.ArrayBuffer, (IntPtr)(normals.Length * sizeof(float)), normals, BufferUsageHint.StaticDraw); // Quick error checking int bufferSize; GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out bufferSize); if (normals.Length * sizeof(float) != bufferSize) throw new StaticModelManagerException("Normal array not uploaded correctly"); // Deselect the new buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } else { normalBufferId = 0; } meshes.Add( new StaticMesh( meshName, texture, new StaticMeshInstance( filePath, staticModelId + "sub" + meshes.Count, vertexBufferId, 0, // Obj files don't support vertex colors textureCoordinateBufferId, normalBufferId, 0, // I don't support an index buffer at this time verteces.Length))); fileVerteces.Clear(); fileNormals.Clear(); fileTextureCoordinates.Clear(); fileIndeces.Clear(); texture = null; break; } } } return new StaticModel(staticModelId, meshes); }
[TestMethod] //ICloneable public void CloneTest() { int n = 3; ListArray<object> data = new ListArray<object>(n); data.Add(8); data.Add(6); data.Add(10); data.Clone(); }