void calcTexCoords(out Vector2 vert1Tc, out Vector2 vert2Tc, TrackPropsTex texProps, float stepFromNoteStart, float normStepFromNoteStart, float lineWidth, Vector3 worldPos1, Vector3 worldPos2, bool adjustingAspect = false) { double x1, y1, x2, y2; calcTexCoords(out x1, out y1, out x2, out y2, texProps, stepFromNoteStart, normStepFromNoteStart, lineWidth, worldPos1, worldPos2, false, false); vert1Tc = new Vector2((float)x1, (float)y1); vert2Tc = new Vector2((float)x2, (float)y2); }
void adjustAspect(ref double x1, ref double y1, ref double x2, ref double y2, TrackPropsTex texProps, double stepFromNoteStart, double normStepFromNoteStart, double lineWidth, Vector3 worldPos1, Vector3 worldPos2) { if ((bool)texProps.KeepAspect) { double tiledX1, tiledY1, tiledX2, tiledY2; double regularX1 = x1, regularY1 = y1, regularX2 = x2, regularY2 = y2; float intWorldPosX = (int)worldPos1.X; worldPos1.X -= intWorldPosX; worldPos2.X -= intWorldPosX; calcTexCoords(out regularX1, out regularY1, out regularX2, out regularY2, texProps, stepFromNoteStart, normStepFromNoteStart, lineWidth, worldPos1, worldPos2, true, false); calcTexCoords(out tiledX1, out tiledY1, out tiledX2, out tiledY2, texProps, stepFromNoteStart, normStepFromNoteStart, lineWidth, worldPos1, worldPos2, true, true); double xDiff = regularX1 - regularX2, yDiff = regularY1 - regularY2; double tiledXDiff = tiledX1 - tiledX2, tiledYDiff = tiledY1 - tiledY2; if ((bool)texProps.UTile && !(bool)texProps.VTile) { double ratio = yDiff / tiledYDiff; x1 *= ratio; x2 *= ratio; } else if (!(bool)texProps.UTile && (bool)texProps.VTile) { double ratio; if (tiledXDiff == 0) { ratio = x1 / tiledX1; } else { ratio = xDiff / tiledXDiff; } y1 *= ratio; y2 *= ratio; } } }
void calcTexCoords(out double x1, out double y1, out double x2, out double y2, TrackPropsTex texProps, double stepFromNoteStart, double normStepFromNoteStart, double lineWidth, Vector3 worldPos1, Vector3 worldPos2, bool adjustingAspect, bool forceTiling) { double vpSizeX = Project.Props.Camera.ViewportSize.X; double vpSizeY = Project.Props.Camera.ViewportSize.Y; double texSizeX = (double)texProps.Texture.Width * TexTileScale; double texSizeY = (double)texProps.Texture.Height * TexTileScale; TexAnchorEnum texUAnchor = (TexAnchorEnum)texProps.UAnchor; TexAnchorEnum texVAnchor = (TexAnchorEnum)texProps.VAnchor; bool uTile = true, vTile = true; if (!forceTiling) { uTile = (bool)texProps.UTile; vTile = (bool)texProps.VTile; } //UAnchor if (texUAnchor == TexAnchorEnum.Note) { if (!uTile) { x1 = x2 = normStepFromNoteStart; } else { x1 = x2 = stepFromNoteStart / texSizeX; } } else if (texUAnchor == TexAnchorEnum.Screen) { if (!uTile) { x1 = worldPos1.X / vpSizeX; x2 = worldPos2.X / vpSizeX; } else { x1 = worldPos1.X / texSizeX; x2 = worldPos2.X / texSizeX; } } else if (texUAnchor == TexAnchorEnum.Song) { if (!uTile) { x1 = (double)worldPos1.X / Project.SongLengthP; x2 = (double)worldPos2.X / Project.SongLengthP; } else { x1 = worldPos1.X / texSizeX; x2 = worldPos2.X / texSizeX; } } else { throw new NotImplementedException(); } //VAnchor if (texVAnchor == TexAnchorEnum.Note) { y1 = 0; if (!vTile) { y2 = 1; } else { y2 = lineWidth / texSizeY; } } else if (texVAnchor == TexAnchorEnum.Screen) { double worldPos1Y = worldPos1.Y + vpSizeY / 2; double worldPos2Y = worldPos2.Y + vpSizeY / 2; if (!vTile) { y1 = worldPos1Y / vpSizeY; y2 = worldPos2Y / vpSizeY; } else { y1 = worldPos1Y / texSizeY; y2 = worldPos2Y / texSizeY; } } else { throw new NotImplementedException(); } if (!adjustingAspect) { adjustAspect(ref x1, ref y1, ref x2, ref y2, texProps, stepFromNoteStart, normStepFromNoteStart, lineWidth, worldPos1, worldPos2); } y1 *= -1; y2 *= -1; }