I passed an integer from java to javascript, and now I want to use the value to change the altitude of an object.
I added a to RelativeLoction var location = new AR.RelativeLocation(null, 8, 0, a);
The problem is it ignores the value that I passed which is 10 and take a as 0. I know that the value passed correctly from this var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a;
which shows Altitude: 10.
Javascript code:
var World = {
loaded: false,
rotating: false,
init: function initFn() {
this.createModelAtLocation();
},
createModelAtLocation: function createModelAtLocationFn() {
/*
First a location where the model should be displayed will be defined. This location will be relativ to the user.
*/
var location = new AR.RelativeLocation(null, 8, 0, a);
/*
Next the model object is loaded.
*/
var modelArrow = new AR.Model("assets/arrow.wt3", {
onLoaded: this.worldLoaded,
scale: {
x: 0.005,
y: 0.005,
z: 0.003
},
rotate: {
x: 0.0,
y: 90.0,
z: 0.0
},
translate: {
x: 0,
y: 0,
z: 0
}
});
var indicatorImage = new AR.ImageResource("assets/indi.png");
var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, {
verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP
});
/*
Putting it all together the location and 3D model is added to an AR.GeoObject.
*/
var obj = new AR.GeoObject(location, {
drawables: {
cam: [modelArrow],
indicator: [indicatorDrawable]
}
});
},
worldLoaded: function worldLoadedFn() {
World.loaded = true;
var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a;
e.parentElement.removeChild(e);
}
};
var a = 0;
var altitude = 0;
function setAltitude(altitude){
a = altitude;
}
World.init();
Edit after Alex's answer:
Now the object and the altitude are not showing not sure if I'm missing something
var World = {
location: null,
loaded: false,
rotating: false,
init: function initFn() {
this.createModelAtLocation();
},
createModelAtLocation: function createModelAtLocationFn() {
/*
First a location where the model should be displayed will be defined. This location will be relativ to the user.
*/
//var location = new AR.RelativeLocation(null, 8, 0, a);
World.location = new AR.RelativeLocation(null, 8, 0, a);
/*
Next the model object is loaded.
*/
var modelArrow = new AR.Model("assets/arrow.wt3", {
onLoaded: this.worldLoaded,
scale: {
x: 0.005,
y: 0.005,
z: 0.003
},
rotate: {
x: 0.0,
y: 90.0,
z: 0.0
},
translate: {
x: 0,
y: 0,
z: 0
}
});
var indicatorImage = new AR.ImageResource("assets/indi.png");
var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, {
verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP
});
/*
Putting it all together the location and 3D model is added to an AR.GeoObject.
*/
var obj = new AR.GeoObject(location, {
drawables: {
cam: [modelArrow],
indicator: [indicatorDrawable]
}
});
},
worldLoaded: function worldLoadedFn() {
World.loaded = true;
var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a;
e.parentElement.removeChild(e);
}
};
var a = 0;
var altitude = 0;
function setAltitude(altitude){
//a = altitude;
//World.location.altitudeDelta = altitude;
World.location.a = altitude;
}
World.init();
I managed to fix the problem here is the answer if anyone is interested
var World = {
//location: null,
loaded: false,
rotating: false,
loadValuesFromJava: function loadValuesFromJavaFn(Altitude){
a = Altitude;
this.createModelAtLocation();
},
/*init: function initFn() {
this.createModelAtLocation();
},*/
createModelAtLocation: function createModelAtLocationFn() {
/*
First a location where the model should be displayed will be defined. This location will be relativ to the user.
*/
var location = new AR.RelativeLocation(null, 8, 0, a);
//World.location = new AR.RelativeLocation(null, 8, 0, a);
/*
Next the model object is loaded.
*/
var modelArrow = new AR.Model("assets/arrow.wt3", {
onLoaded: this.worldLoaded,
scale: {
x: 0.005,
y: 0.005,
z: 0.003
},
rotate: {
x: 0.0,
y: 90.0,
z: 0.0
},
translate: {
x: 0,
y: 0,
z: 0
}
});
var indicatorImage = new AR.ImageResource("assets/indi.png");
var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, {
verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP
});
/*
Putting it all together the location and 3D model is added to an AR.GeoObject.
*/
var obj = new AR.GeoObject(location, {
drawables: {
cam: [modelArrow],
indicator: [indicatorDrawable]
}
});
},
worldLoaded: function worldLoadedFn() {
World.loaded = true;
var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a;
e.parentElement.removeChild(e);
}
};
var a = 0;
var Altitude = 0;
/*var a = 0;
var altitude = 0;
function setAltitude(altitude){
a = altitude;
//World.location.altitudeDelta = altitude;
//World.location.altitudeDelta = altitude;
}*/
//World.init();
//World.loadValuesFromJava();