/* * Copyright 2006 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
#include"include/utils/SkCamera.h"
static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a, const SkScalar b[], int step_b,
SkScalar denom) {
SkScalar prod = 0; for (int i = 0; i < count; i++) {
prod += a[0] * b[0];
a += step_a;
b += step_b;
} return prod / denom;
}
{
SkMatrix* orien = &fOrientation; auto [x, y, z] = fObserver;
// Looking along the view axis we have: // // /|\ zenith // | // | // | * observer (projected on XY plane) // | // |____________\ cross // / // // So this does a z-shear along the view axis based on the observer's x and y values, // and scales in x and y relative to the negative of the observer's z value // (the observer is in the negative z direction).
orien->set(SkMatrix::kMScaleX, x * axis.x - z * cross.x);
orien->set(SkMatrix::kMSkewX, x * axis.y - z * cross.y);
orien->set(SkMatrix::kMTransX, x * axis.z - z * cross.z);
orien->set(SkMatrix::kMSkewY, y * axis.x - z * zenith.x);
orien->set(SkMatrix::kMScaleY, y * axis.y - z * zenith.y);
orien->set(SkMatrix::kMTransY, y * axis.z - z * zenith.z);
orien->set(SkMatrix::kMPersp0, axis.x);
orien->set(SkMatrix::kMPersp1, axis.y);
orien->set(SkMatrix::kMPersp2, axis.z);
}
}
// This multiplies fOrientation by the matrix [quilt.fU quilt.fV diff] -- U, V, and diff are // column vectors in the matrix -- then divides by the length of the projection of diff onto // the view axis (which is 'dot'). This transforms the patch (which transforms from local path // space to world space) into view space (since fOrientation transforms from world space to // view space). // // The divide by 'dot' isn't strictly necessary as the homogeneous divide would do much the // same thing (it's just scaling the entire matrix by 1/dot). It looks like it's normalizing // the matrix into some canonical space.
patchPtr = (const SkScalar*)&quilt;
matrix->set(SkMatrix::kMScaleX, SkScalarDotDiv(3, patchPtr, 1, mapPtr, 1, dot));
matrix->set(SkMatrix::kMSkewY, SkScalarDotDiv(3, patchPtr, 1, mapPtr+3, 1, dot));
matrix->set(SkMatrix::kMPersp0, SkScalarDotDiv(3, patchPtr, 1, mapPtr+6, 1, dot));
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK void Sk3DView::setCameraLocation(SkScalar x, SkScalar y, SkScalar z) { // the camera location is passed in inches, set in pt
SkScalar lz = z * 72.0f;
fCamera.fLocation = {x * 72.0f, y * 72.0f, lz};
fCamera.fObserver = {0, 0, lz};
fCamera.update();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.