a nicer <lookAt> command
parent
54cb9b6fcd
commit
b5a6b7cbd8
|
@ -323,15 +323,9 @@
|
|||
<xsd:attribute name="angle" type="doubleType" use="required"/>
|
||||
</xsd:complexType>
|
||||
<xsd:complexType name="lookAt">
|
||||
<xsd:attribute name="ox" type="doubleType" use="required"/>
|
||||
<xsd:attribute name="oy" type="doubleType" use="required"/>
|
||||
<xsd:attribute name="oz" type="doubleType" use="required"/>
|
||||
<xsd:attribute name="tx" type="doubleType" use="required"/>
|
||||
<xsd:attribute name="ty" type="doubleType" use="required"/>
|
||||
<xsd:attribute name="tz" type="doubleType" use="required"/>
|
||||
<xsd:attribute name="ux" type="doubleType"/>
|
||||
<xsd:attribute name="uy" type="doubleType"/>
|
||||
<xsd:attribute name="uz" type="doubleType"/>
|
||||
<xsd:attribute name="origin" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="target" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="up" type="xsd:string" use="optional"/>
|
||||
</xsd:complexType>
|
||||
<xsd:complexType name="point">
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||
|
|
|
@ -271,10 +271,12 @@ choices are available:
|
|||
\begin{xml}
|
||||
<matrix value="0 -0.53 0 -1.79 0.92 0 0 8.03 0 0 0.53 0 0 0 0 1"/>
|
||||
\end{xml}
|
||||
\item LookAt transformations --- this is useful for setting up the camera. The \textbf{o} coordinates
|
||||
provide the camera origin, \textbf{t} specifies the target and \textbf{u} is the ``up'' direction.
|
||||
\item LookAt transformations --- this is primarily useful for setting up cameras (and spot lights). The \code{origin} coordinates
|
||||
specify the camera origin, \code{target} is the point that the camera will look at, and the
|
||||
(optional) \code{up} parameter determines the ``upward'' direction in the final rendered image.
|
||||
The \code{up} parameter is not needed for spot lights.
|
||||
\begin{xml}
|
||||
<lookAt ox="10" oy="50" oz="-800" tx="0" ty="0" tz="0" ux="0" uy="1" uz="0"/>
|
||||
<lookAt origin="10, 50, -800" target="0, 0, 0" up="0, 1, 0"/>
|
||||
\end{xml}
|
||||
\end{itemize}
|
||||
Cordinates that are zero (for \code{translate} and \code{rotate}) or one (for \code{scale})
|
||||
|
|
|
@ -987,7 +987,7 @@ void loadLight(ColladaContext &ctx, Transform transform, domLight &light) {
|
|||
ctx.os << "\t<luminaire id=\"" << identifier << "\" type=\"directional\">" << endl;
|
||||
ctx.os << "\t\t<rgb name=\"intensity\" value=\"" << color[0]*intensity << " " << color[1]*intensity << " " << color[2]*intensity << "\"/>" << endl << endl;
|
||||
ctx.os << "\t\t<transform name=\"toWorld\">" << endl;
|
||||
ctx.os << "\t\t\t<lookAt ox=\"" << pos.x << "\" oy=\"" << pos.y << "\" oz=\"" << pos.z << "\" tx=\"" << target.x << "\" ty=\"" << target.y << "\" tz=\"" << target.z << "\"/>" << endl;
|
||||
ctx.os << "\t\t\t<lookAt origin=\"" << pos.x << ", " << pos.y << ", " << pos.z << "\" target=\"" << target.x << ", " << target.y << ", " << target.z << "\"/>" << endl;
|
||||
ctx.os << "\t\t</transform>" << endl << endl;
|
||||
ctx.os << "\t</luminaire>" << endl << endl;
|
||||
}
|
||||
|
@ -1011,7 +1011,7 @@ void loadLight(ColladaContext &ctx, Transform transform, domLight &light) {
|
|||
ctx.os << "\t\t<rgb name=\"intensity\" value=\"" << color[0]*intensity << " " << color[1]*intensity << " " << color[2]*intensity << "\"/>" << endl;
|
||||
ctx.os << "\t\t<float name=\"cutoffAngle\" value=\"" << falloffAngle/2 << "\"/>" << endl << endl;
|
||||
ctx.os << "\t\t<transform name=\"toWorld\">" << endl;
|
||||
ctx.os << "\t\t\t<lookAt ox=\"" << pos.x << "\" oy=\"" << pos.y << "\" oz=\"" << pos.z << "\" tx=\"" << target.x << "\" ty=\"" << target.y << "\" tz=\"" << target.z << "\"/>" << endl;
|
||||
ctx.os << "\t\t\t<lookAt origin=\"" << pos.x << ", " << pos.y << ", " << pos.z << "\" target=\"" << target.x << ", " << target.y << ", " << target.z << "\"/>" << endl;
|
||||
ctx.os << "\t\t</transform>" << endl;
|
||||
ctx.os << "\t</luminaire>" << endl << endl;
|
||||
}
|
||||
|
|
|
@ -225,17 +225,31 @@ void SceneHandler::endElement(const XMLCh* const xmlName) {
|
|||
Float angle = parseFloat(name, context.attributes["angle"]);
|
||||
m_transform = Transform::rotate(Vector(x, y, z), angle) * m_transform;
|
||||
} else if (name == "lookAt") {
|
||||
Float ox = parseFloat(name, context.attributes["ox"]);
|
||||
Float oy = parseFloat(name, context.attributes["oy"]);
|
||||
Float oz = parseFloat(name, context.attributes["oz"]);
|
||||
Float tx = parseFloat(name, context.attributes["tx"]);
|
||||
Float ty = parseFloat(name, context.attributes["ty"]);
|
||||
Float tz = parseFloat(name, context.attributes["tz"]);
|
||||
Float ux = parseFloat(name, context.attributes["ux"], 0);
|
||||
Float uy = parseFloat(name, context.attributes["uy"], 0);
|
||||
Float uz = parseFloat(name, context.attributes["uz"], 0);
|
||||
Point o(ox, oy, oz), t(tx, ty, tz);
|
||||
Vector u(ux, uy, uz);
|
||||
std::vector<std::string> tokens = tokenize(context.attributes["origin"], ", ");
|
||||
if (tokens.size() != 3)
|
||||
XMLLog(EError, "<lookAt>: invalid 'origin' argument");
|
||||
Point o(
|
||||
parseFloat(name, tokens[0]),
|
||||
parseFloat(name, tokens[1]),
|
||||
parseFloat(name, tokens[2]));
|
||||
tokens = tokenize(context.attributes["target"], ", ");
|
||||
if (tokens.size() != 3)
|
||||
XMLLog(EError, "<lookAt>: invalid 'target' argument");
|
||||
Point t(
|
||||
parseFloat(name, tokens[0]),
|
||||
parseFloat(name, tokens[1]),
|
||||
parseFloat(name, tokens[2]));
|
||||
Vector u(0.0f);
|
||||
tokens = tokenize(context.attributes["up"], ", ");
|
||||
if (tokens.size() == 3)
|
||||
u = Vector(
|
||||
parseFloat(name, tokens[0]),
|
||||
parseFloat(name, tokens[1]),
|
||||
parseFloat(name, tokens[2]));
|
||||
else if (tokens.size() == 0)
|
||||
;
|
||||
else
|
||||
XMLLog(EError, "<lookAt>: invalid 'up' argument");
|
||||
|
||||
if (u.lengthSquared() == 0) {
|
||||
/* If 'up' was not specified, use an arbitrary axis */
|
||||
|
|
|
@ -172,15 +172,9 @@ void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
|
|||
}
|
||||
t = p + direction;
|
||||
|
||||
lookAt.setAttribute("ox", QString::number(p.x));
|
||||
lookAt.setAttribute("oy", QString::number(p.y));
|
||||
lookAt.setAttribute("oz", QString::number(p.z));
|
||||
lookAt.setAttribute("tx", QString::number(t.x));
|
||||
lookAt.setAttribute("ty", QString::number(t.y));
|
||||
lookAt.setAttribute("tz", QString::number(t.z));
|
||||
lookAt.setAttribute("ux", QString::number(u.x));
|
||||
lookAt.setAttribute("uy", QString::number(u.y));
|
||||
lookAt.setAttribute("uz", QString::number(u.z));
|
||||
lookAt.setAttribute("origin", QString("%1, %2, %3").arg(p.x).arg(p.y).arg(p.z));
|
||||
lookAt.setAttribute("up", QString("%1, %2, %3").arg(u.x).arg(u.y).arg(u.z));
|
||||
lookAt.setAttribute("target", QString("%1, %2, %3").arg(t.x).arg(t.y).arg(t.z));
|
||||
|
||||
// ====================================================================
|
||||
// Serialize the sampler configuration
|
||||
|
@ -331,7 +325,6 @@ void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
|
|||
Beware: the code below is tailored to Qt's
|
||||
output and won't work on arbitrary XML files */
|
||||
QString textContent = doc.toString();
|
||||
cout << qPrintable(textContent) << endl;
|
||||
QTextStream input(&textContent);
|
||||
QTextStream output(&file);
|
||||
QRegExp
|
||||
|
|
Loading…
Reference in New Issue