Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
any idea how to get this custom controller animator to work with the engine in webgl target, currently when i run it theres no errors but the camera still wont move or rotate. in onXRFrame() i call camera.addAnimator(new CL3D.AnimatorXRCameraFPS(session, camera, engine)); and handleController(inputSource); function handleController(inputSource) { this is my Animator so far:: [code]CL3D.AnimatorXRCameraFPS = function(session, camera, engine) { this.Type = 'xrcamerafps'; // Store the XR session and the reference space for local movement this.xrSession = session; this.xrReferenceSpace = 'local'; // Initialize XR controllers this.xrControllers = [null, null]; // Two controllers (left and right) // Movement and rotation speeds this.moveSpeed = 0.06; this.rotateSpeed = 2.0; // Vertical rotation limit this.verticalLimit = 88.0; // Camera position and target setup this.originalPosition = camera ? camera.Pos.clone() : new CL3D.Vect3d(0, 0, 0); this.originalTarget = camera ? camera.getTarget().clone() : new CL3D.Vect3d(0, 0, 1); // Relative rotations to keep track of camera pitch and yaw this.relativeRotationX = 0; this.relativeRotationY = 0; // Zooming capabilities this.zoomSpeed = 0.05; this.targetZoomValue = 90; this.minZoom = 20; this.maxZoom = 100; // Handling key states (for teleports or additional inputs) this.jumpKeyDown = false; this.lastAnimTime = CL3D.CLTimer.getTime(); this.Camera = engine.getScene().getActiveCamera(); this.CursorControl = engine; if (camera) camera.setTarget(this.originalTarget); this.lastMoveVector = new CL3D.Vect3d(0, 0, 0); this.lastMoveTime = 0; this.moveSmoothing = 0; // You can use smoothing here if needed }; // Extending the Animator prototype CL3D.AnimatorXRCameraFPS.prototype = new CL3D.Animator(); // Get the type of the animator CL3D.AnimatorXRCameraFPS.prototype.getType = function() { return 'xrcamerafps'; }; // Animate the node (i.e., handle the camera movement and update each frame) CL3D.AnimatorXRCameraFPS.prototype.animateNode = function(n, timeMs) { if (!this.Camera) return false; const now = CL3D.CLTimer.getTime(); const timeDiff = now - this.lastAnimTime; if (timeDiff === 0) return false; if (timeDiff > 250) timeDiff = 250; this.lastAnimTime = now; // Handle movement based on XR controllers (left and right) const moveVect = new CL3D.Vect3d(0, 0, 0); // Using controller axes (joystick) data for movement i |
||||
|
[code]CL3D.AnimatorXRCameraFPS = function(session, camera, engine) { this.Type = 'xrcamerafps'; // Store the XR session and the reference space for local movement this.xrSession = session; this.xrReferenceSpace = 'local'; // Initialize XR controllers this.xrControllers = [null, null]; // Two controllers (left and right) // Movement and rotation speeds this.moveSpeed = 0.06; this.rotateSpeed = 2.0; // Vertical rotation limit this.verticalLimit = 88.0; // Camera position and target setup this.originalPosition = camera ? camera.Pos.clone() : new CL3D.Vect3d(0, 0, 0); this.originalTarget = camera ? camera.getTarget().clone() : new CL3D.Vect3d(0, 0, 1); // Relative rotations to keep track of camera pitch and yaw this.relativeRotationX = 0; this.relativeRotationY = 0; // Zooming capabilities this.zoomSpeed = 0.05; this.targetZoomValue = 90; this.minZoom = 20; this.maxZoom = 100; // Handling key states (for teleports or additional inputs) this.jumpKeyDown = false; this.lastAnimTime = CL3D.CLTimer.getTime(); this.Camera = engine.getScene().getActiveCamera(); this.CursorControl = engine; if (camera) camera.setTarget(this.originalTarget); this.lastMoveVector = new CL3D.Vect3d(0, 0, 0); this.lastMoveTime = 0; this.moveSmoothing = 0; // You can use smoothing here if needed }; // Extending the Animator prototype CL3D.AnimatorXRCameraFPS.prototype = new CL3D.Animator(); // Get the type of the animator CL3D.AnimatorXRCameraFPS.prototype.getType = function() { return 'xrcamerafps'; }; // Animate the node (i.e., handle the camera movement and update each frame) CL3D.AnimatorXRCameraFPS.prototype.animateNode = function(n, timeMs) { if (!this.Camera) return false; const now = CL3D.CLTimer.getTime(); const timeDiff = now - this.lastAnimTime; if (timeDiff === 0) return false; if (timeDiff > 250) timeDiff = 250; this.lastAnimTime = now; // Handle movement based on XR controllers (left and right) const moveVect = new CL3D.Vect3d(0, 0, 0); // Using controller axes (joystick) data for movement if (this.xrControllers[0]) { const gamepad = this.xrControllers[0].gamepad; if (gamepad) { const [xAxis, yAxis] = gamepad.axes; if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) { moveVect.X += xAxis * this.moveSpeed * timeDiff; moveVect.Z += yAxis * this.moveSpeed * timeDiff; } } } if (this.xrControllers[1]) { const gamepad = this.xrControllers[1].gamepad; if (gamepad) { const [xAxis, yAxis] = gamepad.axes; if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) { moveVect.X += xAxis * this.moveSpeed * timeDiff; moveVect.Z += yAxis * this.moveSpeed * timeDiff; } } } // Apply the movement to the camera this.Camera.Pos.addToThis(moveVect); this.Camera.setTarget(this.Camera.Pos.add(moveVect)); // Rotation based on controller rotation (can be modified based on your needs) if (this.xrControllers[0] && this.xrControllers[1]) { const rotation = new CL3D.Vect3d( this.xrControllers[0].rotation.x + this.xrControllers[1].rotation.x, this.xrControllers[0].rotation.y + this.xrControllers[1].rotation.y, 0 ); this.relativeRotationX += rotation.x * this.rotateSpeed * timeDiff; this.relativeRotationY += rotation.y * this.rotateSpeed * timeDiff; if (this.relativeRotationX > this.verticalLimit) this.relativeRotationX = this.verticalLimit; if (this.relativeRotationX < -this.verticalLimit) this.relativeRotationX = -this.verticalLimit; } // Zoom handling (adjust as needed) const fo |
||||
|
[code]CL3D.AnimatorXRCameraFPS = function(session, camera, engine) { this.Type = 'xrcamerafps'; // Store the XR session and the reference space for local movement this.xrSession = session; this.xrReferenceSpace = 'local'; // Initialize XR controllers this.xrControllers = [null, null]; // Two controllers (left and right) // Movement and rotation speeds this.moveSpeed = 0.06; this.rotateSpeed = 2.0; // Vertical rotation limit this.verticalLimit = 88.0; // Camera position and target setup this.originalPosition = camera ? camera.Pos.clone() : new CL3D.Vect3d(0, 0, 0); this.originalTarget = camera ? camera.getTarget().clone() : new CL3D.Vect3d(0, 0, 1); // Relative rotations to keep track of camera pitch and yaw this.relativeRotationX = 0; this.relativeRotationY = 0; // Zooming capabilities this.zoomSpeed = 0.05; this.targetZoomValue = 90; this.minZoom = 20; this.maxZoom = 100; // Handling key states (for teleports or additional inputs) this.jumpKeyDown = false; this.lastAnimTime = CL3D.CLTimer.getTime(); this.Camera = engine.getScene().getActiveCamera(); this.CursorControl = engine; if (camera) camera.setTarget(this.originalTarget); this.lastMoveVector = new CL3D.Vect3d(0, 0, 0); this.lastMoveTime = 0; this.moveSmoothing = 0; // You can use smoothing here if needed }; CL3D.AnimatorXRCameraFPS.prototype = new CL3D.Animator(); CL3D.AnimatorXRCameraFPS.prototype.getType = function() { return 'xrcamerafps'; }; CL3D.AnimatorXRCameraFPS.prototype.animateNode = function(n, timeMs) { if (!this.Camera) return false; const now = CL3D.CLTimer.getTime(); const timeDiff = now - this.lastAnimTime; if (timeDiff === 0) return false; if (timeDiff > 250) timeDiff = 250; this.lastAnimTime = now; const moveVect = new CL3D.Vect3d(0, 0, 0); if (this.xrControllers[0]) { const gamepad = this.xrControllers[0].gamepad; if (gamepad) { const [xAxis, yAxis] = gamepad.axes; if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) { moveVect.X += xAxis * this.moveSpeed * timeDiff; moveVect.Z += yAxis * this.moveSpeed * timeDiff; } } } if (this.xrControllers[1]) { const gamepad = this.xrControllers[1].gamepad; if (gamepad) { const [xAxis, yAxis] = gamepad.axes; if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) { moveVect.X += xAxis * this.moveSpeed * timeDiff; moveVect.Z += yAxis * this.moveSpeed * timeDiff; } } } this.Camera.Pos.addToThis(moveVect); this.Camera.setTarget(this.Camera.Pos.add(moveVect)); if (this.xrControllers[0] && this.xrControllers[1]) { const rotation = new CL3D.Vect3d( this.xrControllers[0].rotation.x + this.xrControllers[1].rotation.x, this.xrControllers[0].rotation.y + this.xrControllers[1].rotation.y, 0 ); this.relativeRotationX += rotation.x * this.rotateSpeed * timeDiff; this.relativeRotationY += rotation.y * this.rotateSpeed * timeDiff; if (this.relativeRotationX > this.verticalLimit) this.relativeRotationX = this.verticalLimit; if (this.relativeRotationX < -this.verticalLimit) this.relativeRotationX = -this.verticalLimit; } const fov = this.Camera.getFov(); this.targetZoomValue += this.getAdditionalZoomDiff() * timeDiff; if (this.targetZoomValue < this.minZoom) this.targetZoomValue = this.minZoom; if (this.targetZoomValue > this.maxZoom) this.targetZoomValue = this.maxZoom; this.Camera.setFov(CL3D.degToRad(this.targetZoomValue)); const target = new CL3D.Vect3d(0, 0, 1); const mat = new CL3D.Matrix4(); mat.setRotationDegrees(new CL3D.Vect3d(thi |
||||
|
sorry the animator wont upload correctly |
|