public Water(GraphicsDevice device, Texture2D particleTexture) { pb = new PrimitiveBatch(device); this.particleTexture = particleTexture; spriteBatch = new SpriteBatch(device); metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); drawTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); alphaTest = new AlphaTestEffect(device); alphaTest.ReferenceAlpha = 175; var view = device.Viewport; alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1); for (int i = 0; i < columns.Length; i++) { columns[i] = new WaterColumn() { Height = 240, TargetHeight = 240, Speed = 0 }; } }
public Water(GraphicsDevice device, Texture2D particleTexture) { ScreenManager.gameThread = new List <Task>(); pb = new PrimitiveBatch(device); this.particleTexture = particleTexture; spriteBatch = new SpriteBatch(device); metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); alphaTest = new AlphaTestEffect(device); alphaTest.ReferenceAlpha = 175; var view = device.Viewport; alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1); for (int i = 0; i < columns.Length; i++) { columns[i] = new WaterColumn() { Height = 100, TargetHeight = 100, Speed = 0 }; } }
private void Splash(float xPos, float speed) { int index = (int)xPos; WaterColumn col = colDic[index]; speed = Mathf.Clamp(speed, -5f, 5f); columns[col.Num].Speed = -speed; }
public bool JudgeWaterColumn(int row, int col) { WaterColumn waterColumn = GameConst.waterColumns[row, col]; if (waterColumn != null) { WaterColumnBox box = waterColumn.GetComponent <WaterColumnBox>(); if (box.BoxInline(behurtBox)) { return(true); } } return(false); }
public void CreateWaterColumn(int row, int col, WaterColumn.WaterType type) { GameObject obj = Instantiate(Resources.Load("Prefabs/waterColumn") as GameObject); Vector3 position = new Vector3(col * GameConst.tileWidth + GameConst.tileWidth / 2, -(row * GameConst.tileHeight + GameConst.tileHeight / 2), transform.position.z); obj.transform.position = position; WaterColumn waterColumn = obj.gameObject.GetComponent <WaterColumn>(); waterColumn.setType(type); waterColumn.col = col; waterColumn.row = row; GameConst.waterColumns[row, col] = waterColumn; }
private void InitializeWater() { //Cache mesh and material myMesh = GetComponent <MeshFilter>().mesh; myMesh.MarkDynamic(); myMaterial = renderer.material; surfaceLineRenderer = GetComponent <LineRenderer>(); myCollider = collider as BoxCollider; meshVertices = myMesh.vertices; //Store first up vertice for future calcs firstUpVertex = (int)(meshVertices.Length * 0.5f); //Initilize water physics. This is setting up each spring/column columns = new WaterColumn[waterSubdivisions + 1]; float topWaterIdlePosition = meshVertices[meshVertices.Length - 1].y; //Get the y coordinate of one of the top water vertex //Set properties for each spring for (int i = 0; i < columns.Length; i++) { columns[i] = new WaterColumn(); columns[i].Height = topWaterIdlePosition; columns[i].TargetHeight = topWaterIdlePosition; columns[i].Speed = 0; columns[i].lastHeight = topWaterIdlePosition; columns[i].water = this; columns[i].index = i; } //Get particles ready GameObject tempWaterSplash = Instantiate(waterSplash) as GameObject; instantiatedWaterSplash = tempWaterSplash.particleSystem; tempWaterSplash = Instantiate(afterPeakwaterSplash) as GameObject; instantiatedAfterPeakwaterSplash = tempWaterSplash.particleSystem; lDeltas = new float[columns.Length]; rDeltas = new float[columns.Length]; }
public Water(GraphicsDevice device, Map map, Rectangle dest, Color top, Color bottom, float scale)//, Texture2D particleTexture) { Scale = scale; pb = new PrimitiveBatch(device); //this.particleTexture = particleTexture; spriteBatch = new SpriteBatch(device); gameMap = map; topColor = top * 0.8f; bottomColor = bottom; bounds = dest; //metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); //particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); //alphaTest = new AlphaTestEffect(device); //alphaTest.ReferenceAlpha = 175; //var view = device.Viewport; //alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * // Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1); columns = new WaterColumn[bounds.Width / 30]; for (int i = 0; i < columns.Length; i++) { columns[i] = new WaterColumn() { Height = bounds.Height, TargetHeight = bounds.Height, Speed = 0 }; } rDeltas = new float[columns.Length]; lDeltas = new float[columns.Length]; }
//, Texture2D particleTexture) public Water(GraphicsDevice device, Map map, Rectangle dest, Color top, Color bottom, float scale) { Scale = scale; pb = new PrimitiveBatch(device); //this.particleTexture = particleTexture; spriteBatch = new SpriteBatch(device); gameMap = map; topColor = top * 0.8f; bottomColor = bottom; bounds = dest; //metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); //particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height); //alphaTest = new AlphaTestEffect(device); //alphaTest.ReferenceAlpha = 175; //var view = device.Viewport; //alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * // Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1); columns = new WaterColumn[bounds.Width / 30]; for (int i = 0; i < columns.Length; i++) { columns[i] = new WaterColumn() { Height = bounds.Height, TargetHeight = bounds.Height, Speed = 0 }; } rDeltas = new float[columns.Length]; lDeltas = new float[columns.Length]; }
private void Start() { colDic = new Dictionary <int, WaterColumn>(); columns = new WaterColumn[line.positionCount]; lDeltas = new float[line.positionCount]; rDeltas = new float[line.positionCount]; for (int i = 0; i < line.positionCount; i++) { float posX = Mathf.Lerp(LeftTrigger.position.x, RightTrigger.position.x, (float)i / (line.positionCount - 1)); int intPos = (int)posX; columns[i] = new WaterColumn() { Num = i, PosX = posX, IntPos = intPos }; colDic[intPos] = columns[i]; } points = new Vector3[line.positionCount]; points2D = new Vector2[line.positionCount]; line.startColor = Color.white; line.endColor = Color.red; SetLineColor(Color.white); }
public void RecomputeMesh() { //we recreate the mesh as we the previous one could come from prefab (and so every object would the same when they each need there...) //ref countign should take care of leaking, (and if it's a prefabed mesh, the prefab keep its mesh) m_Mesh = new Mesh(); m_Mesh.name = "WaterMesh"; m_Filter.sharedMesh = m_Mesh; m_LowerCorner = -(size * 0.5f - offset); m_Width = size.x; int count = Mathf.CeilToInt(size.x * (pointPerUnits - 1)) + 1; m_Columns = new WaterColumn[count + 1]; float step = size.x / count; Vector3[] pts = new Vector3[(count + 1) * 2]; Vector3[] normal = new Vector3[(count + 1) * 2]; Vector2[] uvs = new Vector2[(count + 1) * 2]; Vector2[] uvs2 = new Vector2[(count + 1) * 2]; int[] indices = new int[6 * count]; for (int i = 0; i <= count; ++i) { pts[i * 2 + 0].Set(m_LowerCorner.x + step * i, m_LowerCorner.y, 0); pts[i * 2 + 1].Set(m_LowerCorner.x + step * i, m_LowerCorner.y + size.y, 0); normal[i * 2 + 0].Set(0, 0, 1); normal[i * 2 + 1].Set(0, 0, 1); uvs[i * 2 + 0].Set(((float)i) / count, 0); uvs[i * 2 + 1].Set(((float)i) / count, 1); //Set the 2nd uv set to local position, allow for coherent tiling of normal map uvs2[i * 2 + 0].Set(pts[i * 2 + 0].x, pts[i * 2 + 0].y); uvs2[i * 2 + 1].Set(pts[i * 2 + 1].x, pts[i * 2 + 1].y); if (i > 0) { int arrayIdx = (i - 1) * 6; int startingIdx = (i - 1) * 2; indices[arrayIdx + 0] = startingIdx; indices[arrayIdx + 1] = startingIdx + 1; indices[arrayIdx + 2] = startingIdx + 3; indices[arrayIdx + 3] = startingIdx; indices[arrayIdx + 4] = startingIdx + 3; indices[arrayIdx + 5] = startingIdx + 2; } m_Columns[i] = new WaterColumn(); m_Columns[i].xPosition = pts[i * 2].x; m_Columns[i].baseHeight = pts[i * 2 + 1].y; m_Columns[i].velocity = 0; m_Columns[i].vertexIndex = i * 2 + 1; m_Columns[i].currentHeight = m_Columns[i].baseHeight; } m_Mesh.Clear(); m_Mesh.vertices = pts; m_Mesh.normals = normal; m_Mesh.uv = uvs; m_Mesh.uv2 = uvs2; m_Mesh.triangles = indices; meshVertices = m_Mesh.vertices; m_Mesh.UploadMeshData(false); }
private void InitializeWater() { //Cache mesh and material myMesh = GetComponent<MeshFilter>().mesh; myMesh.MarkDynamic(); myMaterial = renderer.material; surfaceLineRenderer = GetComponent<LineRenderer>(); myCollider = collider as BoxCollider; meshVertices = myMesh.vertices; //Store first up vertice for future calcs firstUpVertex = (int)(meshVertices.Length*0.5f); //Initilize water physics. This is setting up each spring/column columns = new WaterColumn[waterSubdivisions+1]; float topWaterIdlePosition = meshVertices[meshVertices.Length-1].y; //Get the y coordinate of one of the top water vertex //Set properties for each spring for (int i = 0; i < columns.Length ; i++) { columns[i] = new WaterColumn(); columns[i].Height = topWaterIdlePosition; columns[i].TargetHeight = topWaterIdlePosition; columns[i].Speed = 0; columns[i].lastHeight = topWaterIdlePosition; columns[i].water = this; columns[i].index = i; } //Get particles ready GameObject tempWaterSplash = Instantiate(waterSplash) as GameObject; instantiatedWaterSplash = tempWaterSplash.particleSystem; tempWaterSplash = Instantiate(afterPeakwaterSplash) as GameObject; instantiatedAfterPeakwaterSplash = tempWaterSplash.particleSystem; lDeltas = new float[columns.Length]; rDeltas = new float[columns.Length]; }