private void AlignPlantToTerrain(Landscape terrain, PlantUnit plant) { var translation = new Vector3(plant.Translation.X, terrain.getLandscapeHeight(plant.Translation.X + _meshCenter.X, plant.Translation.Z + _meshCenter.Z), plant.Translation.Z); plant.Translation = translation; }
/// <summary> /// Constructor /// </summary> /// <param name="Translation">Value of grass translation </param> /// <param name="Rotation">Value of grass rotation </param> /// <param name="Scale">Value of grass scaling </param> /// <param name="textureID">Texture ID param</param> /// <param name="previous">Previous plant for wind loop value</param> public PlantUnit(Vector3 Translation, Vector3 Rotation, Vector3 Scale, uint textureID, PlantUnit previous) { this.Translation = Translation; this.Scale = Scale; this.WindLoop = previous != null ? previous.WindLoop : Convert.ToSingle(new Random().NextDouble() * 360.0f); this.textureID = textureID; }
public static void AddBuilderUserAttribute(PlantUnit plant, VAO buffer, Int32 plantsCountBeforeAddition) { float windS = 0.0f, tSampler = 0.0f; float[,] matrixColumn1 = new float[1, 4]; float[,] matrixColumn2 = new float[1, 4]; float[,] matrixColumn3 = new float[1, 4]; float[,] matrixColumn4 = new float[1, 4]; var modelMatrix = Matrix4.Identity; modelMatrix *= Matrix4.CreateRotationY(plant.Rotation.Y); modelMatrix *= Matrix4.CreateScale(plant.Scale); modelMatrix *= Matrix4.CreateTranslation(plant.Translation); matrixColumn1[0, 0] = modelMatrix[0, 0]; matrixColumn1[0, 1] = modelMatrix[0, 1]; matrixColumn1[0, 2] = modelMatrix[0, 2]; matrixColumn1[0, 3] = modelMatrix[0, 3]; matrixColumn2[0, 0] = modelMatrix[1, 0]; matrixColumn2[0, 1] = modelMatrix[1, 1]; matrixColumn2[0, 2] = modelMatrix[1, 2]; matrixColumn2[0, 3] = modelMatrix[1, 3]; matrixColumn3[0, 0] = modelMatrix[2, 0]; matrixColumn3[0, 1] = modelMatrix[2, 1]; matrixColumn3[0, 2] = modelMatrix[2, 2]; matrixColumn3[0, 3] = modelMatrix[2, 3]; matrixColumn4[0, 0] = modelMatrix[3, 0]; matrixColumn4[0, 1] = modelMatrix[3, 1]; matrixColumn4[0, 2] = modelMatrix[3, 2]; matrixColumn4[0, 3] = modelMatrix[3, 3]; windS = plant.WindLoop; tSampler = plant.textureID; IntPtr singleAttributeOffset = new IntPtr(sizeof(float) * plantsCountBeforeAddition); IntPtr singleAttributeValueSize = new IntPtr(sizeof(float)); IntPtr vectorAttributeOffset = new IntPtr(sizeof(float) * matrixColumn1.Length * plantsCountBeforeAddition); IntPtr vectorAttributeValueSize = new IntPtr(sizeof(float) * matrixColumn1.Length); VAOManager.AddUserSingleAttribute(buffer, 0, windS, singleAttributeOffset, singleAttributeValueSize); VAOManager.AddUserSingleAttribute(buffer, 1, tSampler, singleAttributeOffset, singleAttributeValueSize); VAOManager.AddUserVectorAttribute(buffer, 0, matrixColumn1, vectorAttributeOffset, vectorAttributeValueSize); VAOManager.AddUserVectorAttribute(buffer, 1, matrixColumn2, vectorAttributeOffset, vectorAttributeValueSize); VAOManager.AddUserVectorAttribute(buffer, 2, matrixColumn3, vectorAttributeOffset, vectorAttributeValueSize); VAOManager.AddUserVectorAttribute(buffer, 3, matrixColumn4, vectorAttributeOffset, vectorAttributeValueSize); }
public void add(PlantUnit plant, Landscape terrain = null) { //AlignPlantToTerrain(terrain, plant); // TODO : assemble buffer first or if it's already assembled just add new values to buffer if (_bufferAssembled) { //PlantUserAttributeBuilder.AddBuilderUserAttribute(plant, _buffer, _plants.Count); } else { this._bufferAssembled = true; } this._plants.Add(plant); }