Skip to content

Commit b74186e

Browse files
committed
fix(camera): fix refactoring
remove undesired checks and document some choices
1 parent ad468f2 commit b74186e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Sources/Rendering/Core/Camera/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function vtkCamera(publicAPI, model) {
7777

7878
// Internal Functions that don't need to be public
7979
function computeViewPlaneNormal() {
80-
if (!model.viewPlaneNormal) model.viewPlaneNormal = [0, 0, 0];
8180
// VPN is -DOP
8281
model.viewPlaneNormal[0] = -model.directionOfProjection[0];
8382
model.viewPlaneNormal[1] = -model.directionOfProjection[1];
@@ -102,7 +101,8 @@ function vtkCamera(publicAPI, model) {
102101
) {
103102
return;
104103
}
105-
if (!model.position) {
104+
// Instanciation time
105+
if (model.position === undefined) {
106106
model.position = defaultValues().position;
107107
}
108108

@@ -124,7 +124,10 @@ function vtkCamera(publicAPI, model) {
124124
) {
125125
return;
126126
}
127-
127+
// Instanciation time
128+
if (model.focalPoint === undefined) {
129+
model.focalPoint = defaultValues().focalPoint;
130+
}
128131
model.focalPoint[0] = x;
129132
model.focalPoint[1] = y;
130133
model.focalPoint[2] = z;
@@ -159,10 +162,12 @@ function vtkCamera(publicAPI, model) {
159162
//----------------------------------------------------------------------------
160163
// This method must be called when the focal point or camera position changes
161164
publicAPI.computeDistance = () => {
162-
if (!model.position) {
165+
// Instanciation time : computeDistance can be called either when model.position
166+
// or model.focalPoint are undefined
167+
if (model.position === undefined) {
163168
model.position = defaultValues().position;
164169
}
165-
if (!model.focalPoint) {
170+
if (model.focalPoint === undefined) {
166171
model.focalPoint = defaultValues().focalPoint;
167172
}
168173
const dx = model.focalPoint[0] - model.position[0];
@@ -171,7 +176,7 @@ function vtkCamera(publicAPI, model) {
171176

172177
model.distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
173178

174-
if (!model.directionOfProjection) {
179+
if (model.directionOfProjection === undefined) {
175180
model.directionOfProjection = defaultValues().directionOfProjection;
176181
}
177182

@@ -233,7 +238,6 @@ function vtkCamera(publicAPI, model) {
233238
);
234239
vec4.transformMat4(viewUpVec4, viewUpVec4, rotateMatrix);
235240

236-
if (!model.viewUp) model.viewUp = defaultValues().viewUp;
237241
model.viewUp[0] = viewUpVec4[0];
238242
model.viewUp[1] = viewUpVec4[1];
239243
model.viewUp[2] = viewUpVec4[2];
@@ -242,21 +246,19 @@ function vtkCamera(publicAPI, model) {
242246
};
243247

244248
publicAPI.azimuth = (angle) => {
245-
const fp = model.focalPoint ? model.focalPoint : defaultValues().focalPoint;
249+
const fp = model.focalPoint;
246250

247251
mat4.identity(trans);
248252

249253
// translate the focal point to the origin,
250254
// rotate about view up,
251255
// translate back again
252256
mat4.translate(trans, trans, fp);
253-
const viewUp = model.viewUp ? model.viewUp : defaultValues().viewUp;
254-
mat4.rotate(trans, trans, vtkMath.radiansFromDegrees(angle), viewUp);
257+
mat4.rotate(trans, trans, vtkMath.radiansFromDegrees(angle), model.viewUp);
255258
mat4.translate(trans, trans, [-fp[0], -fp[1], -fp[2]]);
256259

257260
// apply the transform to the position
258-
const pos = model.position ? model.position : defaultValues().position;
259-
vec3.transformMat4(newPosition, pos, trans);
261+
vec3.transformMat4(newPosition, model.position, trans);
260262
publicAPI.setPosition(newPosition[0], newPosition[1], newPosition[2]);
261263
};
262264

@@ -736,9 +738,7 @@ function vtkCamera(publicAPI, model) {
736738
let vn = null;
737739
let position = null;
738740

739-
vn = model.viewPlaneNormal
740-
? model.viewPlaneNormal
741-
: defaultValues().viewPlaneNormal;
741+
vn = model.viewPlaneNormal;
742742
position = model.position;
743743

744744
const a = -vn[0];

0 commit comments

Comments
 (0)