void DrawCloudsY(int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, VertexPos3fTex2fCol4b[] vertices) { int endX = x2, endZ = z2, startZ = z1; // adjust range so that largest negative uv coordinate is shifted to 0 or above. float offset = Utils.CeilDiv(-x1, 2048); int i = 0; for ( ; x1 < endX; x1 += axisSize) { x2 = x1 + axisSize; if (x2 > endX) { x2 = endX; } z1 = startZ; for ( ; z1 < endZ; z1 += axisSize) { z2 = z1 + axisSize; if (z2 > endZ) { z2 = endZ; } vertices[i++] = new VertexPos3fTex2fCol4b(x1, y + 0.1f, z1, x1 / 2048f + offset, z1 / 2048f + offset, col); vertices[i++] = new VertexPos3fTex2fCol4b(x1, y + 0.1f, z2, x1 / 2048f + offset, z2 / 2048f + offset, col); vertices[i++] = new VertexPos3fTex2fCol4b(x2, y + 0.1f, z2, x2 / 2048f + offset, z2 / 2048f + offset, col); vertices[i++] = new VertexPos3fTex2fCol4b(x2, y + 0.1f, z1, x2 / 2048f + offset, z1 / 2048f + offset, col); } } }
protected void DrawRotate(float x, float y, float z, float angleX, float angleY, float angleZ, ModelPart part) { float cosX = (float)Math.Cos(-angleX), sinX = (float)Math.Sin(-angleX); float cosY = (float)Math.Cos(-angleY), sinY = (float)Math.Sin(-angleY); float cosZ = (float)Math.Cos(-angleZ), sinZ = (float)Math.Sin(-angleZ); float vScale = _64x64 ? 64f : 32f; for (int i = 0; i < part.Count; i++) { ModelVertex model = vertices[part.Offset + i]; Vector3 loc = new Vector3(model.X - x, model.Y - y, model.Z - z); if (Rotate == RotateOrder.ZYX) { loc = Utils.RotateZ(loc.X, loc.Y, loc.Z, cosZ, sinZ); loc = Utils.RotateY(loc.X, loc.Y, loc.Z, cosY, sinY); loc = Utils.RotateX(loc.X, loc.Y, loc.Z, cosX, sinX); } else if (Rotate == RotateOrder.XZY) { loc = Utils.RotateX(loc.X, loc.Y, loc.Z, cosX, sinX); loc = Utils.RotateZ(loc.X, loc.Y, loc.Z, cosZ, sinZ); loc = Utils.RotateY(loc.X, loc.Y, loc.Z, cosY, sinY); } FastColour col = GetCol(i, part.Count); VertexPos3fTex2fCol4b vertex = default(VertexPos3fTex2fCol4b); Vector3 newPos = Utils.RotateY(loc.X + x, loc.Y + y, loc.Z + z, cosA, sinA) + pos; vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255; AdjustUV(model.U, model.V, vScale, i, ref vertex); cache.vertices[index++] = vertex; } }
public void InitCache() { vertices = new VertexPos3fTex2fCol4b[24 * 12]; vb = api.CreateDynamicVb(VertexFormat.Pos3fTex2fCol4b, vertices.Length); cache["humanoid"] = new HumanoidModel(game); cache["human"] = cache["humanoid"]; }
void TransformVertices() { for (int i = 0; i < index; i++) { VertexPos3fTex2fCol4b vertex = cache.vertices[i]; Vector3 newPos = Utils.RotateY(vertex.X, vertex.Y, vertex.Z, cosYaw, sinYaw) + pos; vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; cache.vertices[i] = vertex; } }
void ResetClouds(int extent, int axisSize) { extent = Utils.AdjViewDist(extent); int x1 = -extent, x2 = map.Width + extent; int z1 = -extent, z2 = map.Length + extent; cloudVertices = Utils.CountVertices(x2 - x1, z2 - z1, axisSize); VertexPos3fTex2fCol4b[] vertices = new VertexPos3fTex2fCol4b[cloudVertices]; DrawCloudsY(x1, z1, x2, z2, map.CloudHeight, axisSize, map.CloudsCol, vertices); cloudsVb = graphics.CreateVb(vertices, VertexFormat.Pos3fTex2fCol4b, cloudVertices); }
public override void Render( double delta, float t, VertexPos3fTex2fCol4b[] vertices, ref int index ) { Position = Vector3.Lerp( lastPos, nextPos, t ); Vector3 p111, p121, p212, p222; Size = terrainSize; TranslatePoints( out p111, out p121, out p212, out p222 ); Map map = game.Map; FastColour col = map.IsLit( Vector3I.Floor( Position ) ) ? map.Sunlight : map.Shadowlight; vertices[index++] = new VertexPos3fTex2fCol4b( p111, Rectangle.U1, Rectangle.V2, col ); vertices[index++] = new VertexPos3fTex2fCol4b( p121, Rectangle.U1, Rectangle.V1, col ); vertices[index++] = new VertexPos3fTex2fCol4b( p222, Rectangle.U2, Rectangle.V1, col ); vertices[index++] = new VertexPos3fTex2fCol4b( p212, Rectangle.U2, Rectangle.V2, col ); }
void AdjustUV(ushort u, ushort v, float vScale, int i, ref VertexPos3fTex2fCol4b vertex) { vertex.U = u / 64f; vertex.V = v / vScale; int quadIndex = i % 4; if (quadIndex == 0 || quadIndex == 3) { vertex.V -= 0.01f / vScale; } if (quadIndex == 2 || quadIndex == 3) { vertex.U -= 0.01f / 64f; } }
public static void Make2DQuad(TextureRec xy, TextureRec uv, VertexPos3fTex2fCol4b[] vertices, ref int index) { float x1 = xy.U1, y1 = xy.V1, x2 = xy.U2, y2 = xy.V2; #if USE_DX x1 -= 0.5f; x2 -= 0.5f; y1 -= 0.5f; y2 -= 0.5f; #endif vertices[index++] = new VertexPos3fTex2fCol4b(x1, y1, 0, uv.U1, uv.V1, FastColour.White); vertices[index++] = new VertexPos3fTex2fCol4b(x2, y1, 0, uv.U2, uv.V1, FastColour.White); vertices[index++] = new VertexPos3fTex2fCol4b(x2, y2, 0, uv.U2, uv.V2, FastColour.White); vertices[index++] = new VertexPos3fTex2fCol4b(x1, y2, 0, uv.U1, uv.V2, FastColour.White); }
public override void Render(double delta, float t, VertexPos3fTex2fCol4b[] vertices, ref int index) { Position = Vector3.Lerp(lastPos, nextPos, t); Vector3 p111, p121, p212, p222; Utils.CalcBillboardPoints(terrainSize, Position, ref game.View, out p111, out p121, out p212, out p222); Map map = game.Map; FastColour col = map.IsLit(Vector3I.Floor(Position)) ? map.Sunlight : map.Shadowlight; vertices[index++] = new VertexPos3fTex2fCol4b(p111, rec.U1, rec.V2, col); vertices[index++] = new VertexPos3fTex2fCol4b(p121, rec.U1, rec.V1, col); vertices[index++] = new VertexPos3fTex2fCol4b(p222, rec.U2, rec.V1, col); vertices[index++] = new VertexPos3fTex2fCol4b(p212, rec.U2, rec.V2, col); }
protected void DrawPart(ModelPart part) { float vScale = _64x64 ? 64f : 32f; for (int i = 0; i < part.Count; i++) { ModelVertex model = vertices[part.Offset + i]; Vector3 newPos = Utils.RotateY(model.X, model.Y, model.Z, cosA, sinA) + pos; FastColour col = GetCol(i, part.Count); VertexPos3fTex2fCol4b vertex = default(VertexPos3fTex2fCol4b); vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255; AdjustUV(model.U, model.V, vScale, i, ref vertex); cache.vertices[index++] = vertex; } }
public virtual void Draw2DTexture(ref Texture tex, FastColour col) { float x1 = tex.X1, y1 = tex.Y1, x2 = tex.X2, y2 = tex.Y2; #if USE_DX // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx", // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this. x1 -= 0.5f; x2 -= 0.5f; y1 -= 0.5f; y2 -= 0.5f; #endif texVerts[0] = new VertexPos3fTex2fCol4b(x1, y1, 0, tex.U1, tex.V1, col); texVerts[1] = new VertexPos3fTex2fCol4b(x2, y1, 0, tex.U2, tex.V1, col); texVerts[2] = new VertexPos3fTex2fCol4b(x2, y2, 0, tex.U2, tex.V2, col); texVerts[3] = new VertexPos3fTex2fCol4b(x1, y2, 0, tex.U1, tex.V2, col); SetBatchFormat(VertexFormat.Pos3fTex2fCol4b); UpdateDynamicIndexedVb(DrawMode.Triangles, texVb, texVerts, 4, 6); }
void AdjustUV( ushort u, ushort v, float vScale, int i, ref VertexPos3fTex2fCol4b vertex ) { vertex.U = u / 64f; vertex.V = v / vScale; int quadIndex = i % 4; if( quadIndex == 0 || quadIndex == 3 ) vertex.V -= 0.01f / vScale; if( quadIndex == 2 || quadIndex == 3 ) vertex.U -= 0.01f / 64f; }
void DrawCloudsY( int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, VertexPos3fTex2fCol4b* vertices ) { int endX = x2, endZ = z2, startZ = z1; for( ; x1 < endX; x1 += axisSize ) { x2 = x1 + axisSize; if( x2 > endX ) x2 = endX; z1 = startZ; for( ; z1 < endZ; z1 += axisSize ) { z2 = z1 + axisSize; if( z2 > endZ ) z2 = endZ; *vertices++ = new VertexPos3fTex2fCol4b( x1, y, z1, x1 / 2048f, z1 / 2048f, col ); *vertices++ = new VertexPos3fTex2fCol4b( x1, y, z2, x1 / 2048f, z2 / 2048f, col ); *vertices++ = new VertexPos3fTex2fCol4b( x2, y, z2, x2 / 2048f, z2 / 2048f, col ); *vertices++ = new VertexPos3fTex2fCol4b( x2, y, z1, x2 / 2048f, z1 / 2048f, col ); } } }
public abstract void Render( double delta, float t, VertexPos3fTex2fCol4b[] vertices, ref int index );