MCPcopy Index your code
hub / github.com/bgstaal/multipleWindow3dScene / render

Function render

main.js:148–184  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146
147
148 function render ()
149 {
150 let t = getTime();
151
152 windowManager.update();
153
154
155 // calculate the new position based on the delta between current offset and new offset times a falloff value (to create the nice smoothing effect)
156 let falloff = .05;
157 sceneOffset.x = sceneOffset.x + ((sceneOffsetTarget.x - sceneOffset.x) * falloff);
158 sceneOffset.y = sceneOffset.y + ((sceneOffsetTarget.y - sceneOffset.y) * falloff);
159
160 // set the world position to the offset
161 world.position.x = sceneOffset.x;
162 world.position.y = sceneOffset.y;
163
164 let wins = windowManager.getWindows();
165
166
167 // loop through all our cubes and update their positions based on current window positions
168 for (let i = 0; i < cubes.length; i++)
169 {
170 let cube = cubes[i];
171 let win = wins[i];
172 let _t = t;// + i * .2;
173
174 let posTarget = {x: win.shape.x + (win.shape.w * .5), y: win.shape.y + (win.shape.h * .5)}
175
176 cube.position.x = cube.position.x + (posTarget.x - cube.position.x) * falloff;
177 cube.position.y = cube.position.y + (posTarget.y - cube.position.y) * falloff;
178 cube.rotation.x = _t * .5;
179 cube.rotation.y = _t * .3;
180 };
181
182 renderer.render(scene, camera);
183 requestAnimationFrame(render);
184 }
185
186
187 // resize the renderer to fit the window size

Callers 1

initFunction · 0.85

Calls 3

getTimeFunction · 0.85
updateMethod · 0.80
getWindowsMethod · 0.80

Tested by

no test coverage detected