Moving mesh on the camera axe
HTML
<script src="http://hapticmedia.fr/demo/3d/_system/includes/thirdparty/babylon.1.12-beta.js"></script>
<canvas id="canvas"></canvas>
<button>Actualize !</button>
CSS
canvas
{
width : 100%;
height: : 350px;
}
JavaScript
//var viewMatrixRotationSubmatrix;
var _CAMERA;
(function(){
var canvas = document.getElementById("canvas");
var engine = new BABYLON.Engine(canvas, true);
scene = createSceneTuto(engine);
scene.activeCamera.attachControl(canvas);
engine.runRenderLoop(function () {
scene.render();
});
})()
var sphere = BABYLON.Mesh.CreateSphere("Sphere", 20, 1, scene);
var pos = new BABYLON.Vector3(0,0,10);
sphere.position = pos;
var newpos;
function actualize(){
// viewMatrixRotationSubmatrix = getCameraViewMatrixRotationSubmatrix(_CAMERA);
newpos = baseChangement(sphere.position,getCameraViewMatrixRotationSubmatrix(_CAMERA));
sphere.position.x = newpos.x + _CAMERA.position.x;
sphere.position.y = newpos.y + _CAMERA.position.y;
sphere.position.z = newpos.z + _CAMERA.position.z;
console.debug(sphere.position);
// console.debug(pos + '\n');
}
$('button').click(function(){
console.debug(pos);
sphere.position = new BABYLON.Vector3(0,0,10);
actualize();
});
function createSceneTuto(engine) {
var scene = new BABYLON.Scene(engine);
//Adding the light to the scene
var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, -100, -100), scene);
//Adding a Free Camera
var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0,0,0), scene);
camera.speed = 7;
_CAMERA = camera;
//Adding Meshes
var box = BABYLON.Mesh.CreateBox("Box", 6.0, scene);
//Adding Material
var materialSphere1 = new BABYLON.StandardMaterial("texture1", scene);
materialSphere1.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.7);
box.material = materialSphere1;
return scene;
}
function getCameraViewMatrixRotationSubmatrix(camera)
{
// var matrix = mesh.getWorldMatrix;
var matrix = [[],[],[]];
for (var i=0;i<3;i++)
{
for (var j=0;j<3;j++)
...