% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom-text-3d.R
\name{camera_facing}
\alias{camera_facing}
\title{Compute camera-facing direction for 3D text}
\usage{
camera_facing(
  coord = NULL,
  pitch = 0,
  roll = -60,
  yaw = -30,
  dist = 2,
  mode = c("plane", "point")
)
}
\arguments{
\item{coord}{Optional objected created by \code{coord_3d}. If provided, coord
parameters are drawn from this and the \code{pitch}, \code{roll}, \code{yaw}, \code{dist} arguments
are ignored.}

\item{pitch, roll, yaw}{Rotation angles in degrees, matching the values
you'll use in \code{coord_3d()}.}

\item{dist}{Distance from viewer to center of the data cube, matching
the value you'll use in \code{coord_3d()}. Default is 2. Only used when
\code{mode = "point"}.}

\item{mode}{Character string specifying how labels should face the camera:
\itemize{
\item \code{"plane"} (default): All labels face parallel to the view plane,
like billboards. This is typically easier to read.
\item \code{"point"}: Each label faces toward the camera position. Labels
at the edges will angle inward, giving perspective-correct orientation.
}}
}
\value{
A \code{camera_facing_spec} object to pass to the \code{facing} parameter
of \code{geom_text_3d()}.
}
\description{
Creates a specification for camera-facing "billboard" text that will compute
the appropriate facing direction for each label position.
}
\details{
With \code{mode = "plane"}, all text labels face the same direction (parallel
to the viewing plane), similar to traditional billboard rendering. This
produces clean, readable labels.

With \code{mode = "point"}, each label faces directly toward the camera's
position in 3D space. Labels near the edges of the plot will angle inward,
which is geometrically correct but can look less clean.

Since \code{geom_text_3d()} computes vertex positions before the view is known,
you must specify the view parameters here and use the same values in
\code{coord_3d()}.
}
\examples{
\donttest{
# Parallel billboard text (default) - all labels face same direction
df <- expand.grid(x = c("H", "B"), y = c("a", "o", "u"), z = c("g", "t"))
df$label <- paste0(df$x, df$y, df$z)

ggplot(df, aes(x, y, z = z, label = label)) +
  geom_text_3d(method = "polygon",
               facing = camera_facing(pitch = 20, roll = -60, yaw = -30)) +
  coord_3d(pitch = 20, roll = -60, yaw = -30)

# Point-facing text - labels angle toward camera position
ggplot(df, aes(x, y, z = z, label = label)) +
  geom_text_3d(method = "polygon",
               facing = camera_facing(pitch = 20, roll = -60, yaw = -30,
                                      mode = "point")) +
  coord_3d(pitch = 20, roll = -60, yaw = -30)
}

}
\seealso{
\code{\link[=geom_text_3d]{geom_text_3d()}} for rendering 3D text labels
}
