Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ function computeNewCenterOfRotation(
function getCameraMatrix(renderer, tempMatrix) {
const cam = renderer.getActiveCamera();
if (cam) {
mat4.copy(tempMatrix, cam.getViewMatrix());
return tempMatrix;
return cam.getViewMatrix(tempMatrix);
}
return null;
}
Expand Down
38 changes: 17 additions & 21 deletions Sources/Rendering/Core/Camera/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function vtkCamera(publicAPI, model) {
}

publicAPI.orthogonalizeViewUp = () => {
const vt = publicAPI.getViewMatrix();
model.viewUp[0] = vt[4];
model.viewUp[1] = vt[5];
model.viewUp[2] = vt[6];
publicAPI.getViewMatrix(tmpMatrix);
model.viewUp[0] = tmpMatrix[4];
model.viewUp[1] = tmpMatrix[5];
model.viewUp[2] = tmpMatrix[6];

publicAPI.modified();
};
Expand Down Expand Up @@ -231,8 +231,8 @@ function vtkCamera(publicAPI, model) {
const fp = model.focalPoint;

// get the eye / camera position from the viewMatrix
const vt = publicAPI.getViewMatrix();
const axis = [-vt[0], -vt[1], -vt[2]];
publicAPI.getViewMatrix(tmpMatrix);
const axis = [-tmpMatrix[0], -tmpMatrix[1], -tmpMatrix[2]];

mat4.identity(trans);

Expand All @@ -251,8 +251,8 @@ function vtkCamera(publicAPI, model) {
publicAPI.pitch = (angle) => {
const position = model.position;

const vt = publicAPI.getViewMatrix();
const axis = [vt[0], vt[1], vt[2]];
publicAPI.getViewMatrix(tmpMatrix);
const axis = [tmpMatrix[0], tmpMatrix[1], tmpMatrix[2]];

mat4.identity(trans);

Expand Down Expand Up @@ -388,7 +388,7 @@ function vtkCamera(publicAPI, model) {

publicAPI.computeCameraLightTransform = () => {
// not sure if this is the correct transformation, based on the same funciton in VTK
mat4.copy(tmpMatrix, publicAPI.getViewMatrix());
publicAPI.getViewMatrix(tmpMatrix);
mat4.invert(tmpMatrix, tmpMatrix);

mat4.fromScaling(tmpMatrix2, [
Expand Down Expand Up @@ -506,33 +506,29 @@ function vtkCamera(publicAPI, model) {
}
};

publicAPI.getViewMatrix = (out = undefined) => {
const result = out ?? new Float64Array(16);

publicAPI.getViewMatrix = (out = new Float64Array(16)) => {
if (model.viewMatrix) {
if (model.modelTransformMatrix) {
mat4.multiply(result, model.modelTransformMatrix, model.viewMatrix);
mat4.multiply(out, model.modelTransformMatrix, model.viewMatrix);
} else {
mat4.copy(result, model.viewMatrix);
mat4.copy(out, model.viewMatrix);
}
return result;
return out;
}

mat4.lookAt(
tmpMatrix,
out,
model.position, // eye
model.focalPoint, // at
model.viewUp // up
);

mat4.transpose(tmpMatrix, tmpMatrix);
mat4.transpose(out, out);

if (model.modelTransformMatrix) {
mat4.multiply(result, model.modelTransformMatrix, tmpMatrix);
} else {
mat4.copy(result, tmpMatrix);
mat4.multiply(out, model.modelTransformMatrix, out);
}
return result;
return out;
};

publicAPI.setProjectionMatrix = (mat) => {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Rendering/OpenGL/Camera/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function vtkOpenGLCamera(publicAPI, model) {
ren.getMTime() > model.keyMatrixTime.getMTime() ||
model.renderable.getMTime() > model.keyMatrixTime.getMTime()
) {
mat4.copy(model.keyMatrices.wcvc, model.renderable.getViewMatrix());
model.renderable.getViewMatrix(model.keyMatrices.wcvc);

mat3.fromMat4(model.keyMatrices.normalMatrix, model.keyMatrices.wcvc);
mat3.invert(
Expand Down
8 changes: 2 additions & 6 deletions Sources/Widgets/Widgets3D/LineWidget/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ export default function widgetBehavior(publicAPI, model) {
};

publicAPI.rotateHandlesToFaceCamera = () => {
model.representations[0].setViewMatrix(
Array.from(model._camera.getViewMatrix())
);
model.representations[1].setViewMatrix(
Array.from(model._camera.getViewMatrix())
);
model.representations[0].setViewMatrix(model._camera.getViewMatrix());
model.representations[1].setViewMatrix(model._camera.getViewMatrix());
};

// Handles visibility ---------------------------------------------------------
Expand Down
Loading