private static void AddBillboard(ref QuadBoard qb, ref CroppedQuad crop) { MyTransparentGeometry.AddTriangleBillboard ( crop.quad.Point0, crop.quad.Point1, crop.quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, crop.matBounds.Min, (crop.matBounds.Min + new Vector2(0f, crop.matBounds.Size.Y)), crop.matBounds.Max, qb.textureID, 0, Vector3D.Zero, qb.bbColor, BlendTypeEnum.PostPP ); MyTransparentGeometry.AddTriangleBillboard ( crop.quad.Point0, crop.quad.Point2, crop.quad.Point3, Vector3.Zero, Vector3.Zero, Vector3.Zero, crop.matBounds.Min, crop.matBounds.Max, (crop.matBounds.Min + new Vector2(crop.matBounds.Size.X, 0f)), qb.textureID, 0, Vector3D.Zero, qb.bbColor, BlendTypeEnum.PostPP ); }
/// <summary> /// Draws a cropped billboard in world space facing the +Z direction of the matrix specified. Cropping is /// performed s.t. any parts outside the box defined by maskMin and maskMax are not rendered and WITHOUT /// warping the texture or displacing the billboard. Units in meters, matrix transform notwithstanding. /// </summary> public void DrawCroppedTex(ref CroppedBox box, ref MatrixD matrix) { Vector2 size = box.bounds.Size, pos = box.bounds.Center; box.bounds = box.bounds.Intersect(box.mask.Value); Vector2 clipSize = box.bounds.Size; CroppedQuad crop = default(CroppedQuad); crop.matBounds = texCoords; // Normalized cropped size and offset Vector2 clipScale = clipSize / size, clipOffset = (box.bounds.Center - pos) / size, uvScale = crop.matBounds.Size, uvOffset = crop.matBounds.Center; pos += clipOffset * size; // Offset billboard to compensate for changes in size size = clipSize; // Use cropped billboard size clipOffset *= uvScale * new Vector2(1f, -1f); // Scale offset to fit material and flip Y-axis // Recalculate texture coordinates to simulate clipping without affecting material alignment crop.matBounds.Min = ((crop.matBounds.Min - uvOffset) * clipScale) + (uvOffset + clipOffset); crop.matBounds.Max = ((crop.matBounds.Max - uvOffset) * clipScale) + (uvOffset + clipOffset); Vector3D worldPos = new Vector3D(pos.X, pos.Y, 0d); Vector3D.TransformNoProjection(ref worldPos, ref matrix, out worldPos); MyUtils.GenerateQuad(out crop.quad, ref worldPos, size.X * .5f, size.Y * .5f, ref matrix); if (skewRatio != 0f) { Vector3D start = crop.quad.Point0, end = crop.quad.Point3, offset = (end - start) * skewRatio * .5; crop.quad.Point0 = Vector3D.Lerp(start, end, skewRatio) - offset; crop.quad.Point3 = Vector3D.Lerp(start, end, 1d + skewRatio) - offset; crop.quad.Point1 -= offset; crop.quad.Point2 -= offset; } AddBillboard(ref this, ref crop); }