Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

How to get camera position on Hololens 2 ?


How to get camera position on Hololens 2 ?


    I'm trying to get postion of my camera (On Hololens 2) with this code:

$scope.setVector= function() {
tml3dRenderer.setupTrackingEventsCommand (function(target,eyepos,eyedir,eyeup) {
$ = [eyepos[0].toFixed(2),eyepos[1].toFixed(2),eyepos[2].toFixed(2)];
$ = [eyedir[0].toFixed(2),eyedir[1].toFixed(2),eyedir[2].toFixed(2)];
$ = [eyeup[0].toFixed(2), eyeup[1].toFixed(2), eyeup[2].toFixed(2)];

$interval(function(){ $scope.setVector(); },100);


Obviously, the three values of "eyepos", "eyedir", "eyeup" are mapped with parametre which are linked to a "3DLabels" Widget to display values within my experience.

In the two tests, I'm using a "Thingmark" to activate my experiences.

And  I'm facing some issue, this code is working fine on "Mobile Project" but on "3D Eyewear"


Any ideas ?


Re: How to get camera position on Hololens 2 ?

Hi @Lionel_Brly ,


so far I remember in the post was metnioned the usage "How to get camera position?"

I have only the HoloLens1 but there is no principle difference from the studio side - so that eyewear project should work on both. I will check if I have such project as demo - so far I remember it was working fine when I tested it on the HoloLens 1 some week ago

What I do not think that is a good idea – is to call the setVector function in an interval. The tracking event has it own callback.


Re: How to get camera position on Hololens 2 ?

in the article "How can we make a 3D Widget on HoloLens visible in front of me every time ?"  I uploaded  an project which is handle  more complex but it used the requested functionality for tracking of the device postion - so you can check it 

Another info which could be helpful is this one : ""

In the both mentioned link I attached a project which should demonstrate the functionalit and it implies the requested functionality

In the last post , the more relevant information to your issue is this below:


when I open a project it is always there / HoloLens and Mobile/

- the option 'Enable tracking Events' is threre

I checked my Vuforia Studio builder-settings - at the end I added the following options:

 "enableDebugLogging": true,
  "publishPreview": true,
  "welcomeDismissed": true,
  "designTimeDropShadows": "HARD",
  "projectsListView": true,
  "annotationsEnabled": true,
  "serverMTG": true,
  "showTrackingEvents": true

So belive the option "showTrackingEvents": true has relevance for the mention  display in the 3d container widget UI.  but may be in combination with some of the other options. 

the code :


function magnitute(a1,a2,a3)

return Math.sqrt( Math.pow(a1, 2) + Math.pow(a2, 2)+ Math.pow(a3, 2));

function cross(a1,a2,a3, b1,b2,b3) 
 return [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1 ];
function normalizeVector(a1,a2,a3) {
    var mag = magnitute(a1,a2,a3)
    return new Vector(a1/mag, a2/mag, a3/mag);

$rootScope.$on('modelLoaded', function() { 
  console.log("now check again the setting of the envronment")
  //// end of modelLoaded
 $rootScope.$on('tracking', function( tracker,fargs  ) {
   $['eyepos'] ="eyepos=("+fargs.position[0].toFixed(2)+","+fargs.position[1].toFixed(2)+","+fargs.position[2].toFixed(2)+")";
   $['eyedir'] ="eyedir=("+fargs.gaze[0].toFixed(2)+","+fargs.gaze[1].toFixed(2)+","+fargs.gaze[2].toFixed(2)+")";
   $['eyeup' ] ="eyeup =("+fargs.up[0].toFixed(2)+","+ fargs.up[1].toFixed(2)+","+fargs.up[2].toFixed(2)+")";
   var scale=1.3;
   $scope.setWidgetProp('3DImage-1',  'x', ( fargs.position[0]+fargs.gaze[0]*scale));
   $scope.setWidgetProp('3DImage-1',  'y', ( fargs.position[1]+fargs.gaze[1]*scale));
   $scope.setWidgetProp('3DImage-1',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
  //3DLabel-1 no y
   $scope.setWidgetProp('label-distance-x',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-x',  'y', ( fargs.position[1]+fargs.gaze[1]*scale) -0.08*5);
   $scope.setWidgetProp('label-distance-x',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
   $scope.setWidgetProp('label-distance-y',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-y',  'y', ( fargs.position[1]+fargs.gaze[1]*scale)-0.08*4);
   $scope.setWidgetProp('label-distance-y',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
   $scope.setWidgetProp('label-distance-z',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-z',  'y', ( fargs.position[1]+fargs.gaze[1]*scale)-0.08*3);
   $scope.setWidgetProp('label-distance-z',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));"distance to 0,0,0 World CSYS = :: "+magnitute(fargs.position[0].toFixed(2),fargs.position[1].toFixed(2),fargs.position[2].toFixed(2)) )


In the parameter eyepos, eyedir and eyeup I created binding to the text property of the lables label-dinstance-x/y/z and are displayed there.

I attached the test project in the mentioned post

View solution in original post

Join an
AR Working Group!

Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection